FreeBSD kernel IPv4 code
cc.h
Go to the documentation of this file.
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#ifndef _NETINET_CC_CC_H_
52#define _NETINET_CC_CC_H_
53
54#ifdef _KERNEL
55
57
58/* Global CC vars. */
59extern STAILQ_HEAD(cc_head, cc_algo) cc_list;
60extern const int tcprexmtthresh;
61
62/* Per-netstack bits. */
63VNET_DECLARE(struct cc_algo *, default_cc_ptr);
64#define V_default_cc_ptr VNET(default_cc_ptr)
65
66VNET_DECLARE(int, cc_do_abe);
67#define V_cc_do_abe VNET(cc_do_abe)
68
69VNET_DECLARE(int, cc_abe_frlossreduce);
70#define V_cc_abe_frlossreduce VNET(cc_abe_frlossreduce)
71
72/* Define the new net.inet.tcp.cc sysctl tree. */
73SYSCTL_DECL(_net_inet_tcp_cc);
74
75/* For CC modules that use hystart++ */
83
84/* CC housekeeping functions. */
85int cc_register_algo(struct cc_algo *add_cc);
86int cc_deregister_algo(struct cc_algo *remove_cc);
87
88/*
89 * Wrapper around transport structs that contain same-named congestion
90 * control variables. Allows algos to be shared amongst multiple CC aware
91 * transprots.
92 */
93struct cc_var {
94 void *cc_data; /* Per-connection private CC algorithm data. */
95 int bytes_this_ack; /* # bytes acked by the current ACK. */
96 tcp_seq curack; /* Most recent ACK. */
97 uint32_t flags; /* Flags for cc_var (see below) */
98 int type; /* Indicates which ptr is valid in ccvc. */
100 struct tcpcb *tcp;
103 uint16_t nsegs; /* # segments coalesced into current chain. */
104 uint8_t labc; /* Dont use system abc use passed in */
105};
106
107/* cc_var flags. */
108#define CCF_ABC_SENTAWND 0x0001 /* ABC counted cwnd worth of bytes? */
109#define CCF_CWND_LIMITED 0x0002 /* Are we currently cwnd limited? */
110#define CCF_USE_LOCAL_ABC 0x0004 /* Dont use the system l_abc val */
111#define CCF_ACKNOW 0x0008 /* Will this ack be sent now? */
112#define CCF_IPHDR_CE 0x0010 /* Does this packet set CE bit? */
113#define CCF_TCPHDR_CWR 0x0020 /* Does this packet set CWR bit? */
114#define CCF_MAX_CWND 0x0040 /* Have we reached maximum cwnd? */
115#define CCF_CHG_MAX_CWND 0x0080 /* Cubic max_cwnd changed, for K */
116#define CCF_USR_IWND 0x0100 /* User specified initial window */
117#define CCF_USR_IWND_INIT_NSEG 0x0200 /* Convert segs to bytes on conn init */
118#define CCF_HYSTART_ALLOWED 0x0400 /* If the CC supports it Hystart is allowed */
119#define CCF_HYSTART_CAN_SH_CWND 0x0800 /* Can hystart when going CSS -> CA slam the cwnd */
120#define CCF_HYSTART_CONS_SSTH 0x1000 /* Should hystart use the more conservative ssthresh */
121
122/* ACK types passed to the ack_received() hook. */
123#define CC_ACK 0x0001 /* Regular in sequence ACK. */
124#define CC_DUPACK 0x0002 /* Duplicate ACK. */
125#define CC_PARTIALACK 0x0004 /* Not yet. */
126#define CC_SACK 0x0008 /* Not yet. */
127#endif /* _KERNEL */
128
129/*
130 * Congestion signal types passed to the cong_signal() hook. The highest order 8
131 * bits (0x01000000 - 0x80000000) are reserved for CC algos to declare their own
132 * congestion signal types.
133 */
134#define CC_ECN 0x00000001 /* ECN marked packet received. */
135#define CC_RTO 0x00000002 /* RTO fired. */
136#define CC_RTO_ERR 0x00000004 /* RTO fired in error. */
137#define CC_NDUPACK 0x00000008 /* Threshold of dupack's reached. */
138
139#define CC_SIGPRIVMASK 0xFF000000 /* Mask to check if sig is private. */
140
141#ifdef _KERNEL
142/*
143 * Structure to hold data and function pointers that together represent a
144 * congestion control algorithm.
145 */
146struct cc_algo {
147 char name[TCP_CA_NAME_MAX];
148
149 /* Init global module state on kldload. */
150 int (*mod_init)(void);
151
152 /* Cleanup global module state on kldunload. */
153 int (*mod_destroy)(void);
154
155 /* Return the size of the void pointer the CC needs for state */
156 size_t (*cc_data_sz)(void);
157
158 /*
159 * Init CC state for a new control block. The CC
160 * module may be passed a NULL ptr indicating that
161 * it must allocate the memory. If it is passed a
162 * non-null pointer it is pre-allocated memory by
163 * the caller and the cb_init is expected to use that memory.
164 * It is not expected to fail if memory is passed in and
165 * all currently defined modules do not.
166 */
167 int (*cb_init)(struct cc_var *ccv, void *ptr);
168
169 /* Cleanup CC state for a terminating control block. */
170 void (*cb_destroy)(struct cc_var *ccv);
171
172 /* Init variables for a newly established connection. */
173 void (*conn_init)(struct cc_var *ccv);
174
175 /* Called on receipt of an ack. */
176 void (*ack_received)(struct cc_var *ccv, uint16_t type);
177
178 /* Called on detection of a congestion signal. */
179 void (*cong_signal)(struct cc_var *ccv, uint32_t type);
180
181 /* Called after exiting congestion recovery. */
182 void (*post_recovery)(struct cc_var *ccv);
183
184 /* Called when data transfer resumes after an idle period. */
185 void (*after_idle)(struct cc_var *ccv);
186
187 /* Called for an additional ECN processing apart from RFC3168. */
188 void (*ecnpkt_handler)(struct cc_var *ccv);
189
190 /* Called when a new "round" begins, if the transport is tracking rounds. */
191 void (*newround)(struct cc_var *ccv, uint32_t round_cnt);
192
193 /*
194 * Called when a RTT sample is made (fas = flight at send, if you dont have it
195 * send the cwnd in).
196 */
197 void (*rttsample)(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas);
198
199 /* Called for {get|set}sockopt() on a TCP socket with TCP_CCALGOOPT. */
200 int (*ctl_output)(struct cc_var *, struct sockopt *, void *);
201
205};
206
207#define CC_MODULE_BEING_REMOVED 0x01 /* The module is being removed */
208
209/* Macro to obtain the CC algo's struct ptr. */
210#define CC_ALGO(tp) ((tp)->cc_algo)
211
212/* Macro to obtain the CC algo's data ptr. */
213#define CC_DATA(tp) ((tp)->ccv->cc_data)
214
215/* Macro to obtain the system default CC algo's struct ptr. */
216#define CC_DEFAULT_ALGO() V_default_cc_ptr
217
218extern struct rwlock cc_list_lock;
219#define CC_LIST_LOCK_INIT() rw_init(&cc_list_lock, "cc_list")
220#define CC_LIST_LOCK_DESTROY() rw_destroy(&cc_list_lock)
221#define CC_LIST_RLOCK() rw_rlock(&cc_list_lock)
222#define CC_LIST_RUNLOCK() rw_runlock(&cc_list_lock)
223#define CC_LIST_WLOCK() rw_wlock(&cc_list_lock)
224#define CC_LIST_WUNLOCK() rw_wunlock(&cc_list_lock)
225#define CC_LIST_LOCK_ASSERT() rw_assert(&cc_list_lock, RA_LOCKED)
226
227#define CC_ALGOOPT_LIMIT 2048
228
229/*
230 * These routines give NewReno behavior to the caller
231 * they require no state and can be used by any other CC
232 * module that wishes to use NewReno type behaviour (along
233 * with anything else they may add on, pre or post call).
234 */
235void newreno_cc_post_recovery(struct cc_var *);
236void newreno_cc_after_idle(struct cc_var *);
237void newreno_cc_cong_signal(struct cc_var *, uint32_t );
239
240/* Called to temporarily keep an algo from going away during change */
241void cc_refer(struct cc_algo *algo);
242/* Called to release the temporary hold */
243void cc_release(struct cc_algo *algo);
244
245/* Called to attach a CC algorithm to a tcpcb */
246void cc_attach(struct tcpcb *, struct cc_algo *);
247/* Called to detach a CC algorithm from a tcpcb */
248void cc_detach(struct tcpcb *);
249
250#endif /* _KERNEL */
251#endif /* _NETINET_CC_CC_H_ */
struct cc_head cc_list
Definition: cc.c:100
VNET_DECLARE(struct cc_algo *, default_cc_ptr)
void newreno_cc_ack_received(struct cc_var *, uint16_t)
Definition: cc.c:493
uint32_t hystart_css_growth_div
Definition: cc.c:90
uint32_t hystart_maxrtt_thresh
Definition: cc.c:88
int cc_deregister_algo(struct cc_algo *remove_cc)
Definition: cc.c:284
void cc_refer(struct cc_algo *algo)
Definition: cc.c:111
uint32_t hystart_css_rounds
Definition: cc.c:91
void newreno_cc_post_recovery(struct cc_var *)
Definition: cc.c:384
uint32_t hystart_bblogs
Definition: cc.c:92
int cc_register_algo(struct cc_algo *add_cc)
Definition: cc.c:322
MALLOC_DECLARE(M_CC_MEM)
void newreno_cc_after_idle(struct cc_var *)
Definition: cc.c:415
STAILQ_HEAD(cc_head, cc_algo) cc_list
uint32_t hystart_minrtt_thresh
Definition: cc.c:87
void cc_detach(struct tcpcb *)
Definition: cc.c:138
void newreno_cc_cong_signal(struct cc_var *, uint32_t)
Definition: cc.c:447
struct rwlock cc_list_lock
Definition: cc.c:103
void cc_release(struct cc_algo *algo)
Definition: cc.c:118
uint32_t hystart_n_rttsamples
Definition: cc.c:89
void cc_attach(struct tcpcb *, struct cc_algo *)
Definition: cc.c:126
const int tcprexmtthresh
Definition: tcp_input.c:135
uint32_t hystart_lowcwnd
SYSCTL_DECL(_net_inet_tcp_cc)
__uint32_t uint32_t
Definition: in.h:62
__uint16_t uint16_t
Definition: in.h:57
__uint8_t uint8_t
Definition: in.h:52
Definition: cc.h:146
void(* after_idle)(struct cc_var *ccv)
Definition: cc.h:185
void(* post_recovery)(struct cc_var *ccv)
Definition: cc.h:182
u_int cc_refcount
Definition: cc.h:203
void(* cb_destroy)(struct cc_var *ccv)
Definition: cc.h:170
int(* ctl_output)(struct cc_var *, struct sockopt *, void *)
Definition: cc.h:200
STAILQ_ENTRY(cc_algo) entries
int(* mod_destroy)(void)
Definition: cc.h:153
void(* ack_received)(struct cc_var *ccv, uint16_t type)
Definition: cc.h:176
uint8_t flags
Definition: cc.h:204
size_t(* cc_data_sz)(void)
Definition: cc.h:156
void(* conn_init)(struct cc_var *ccv)
Definition: cc.h:173
int(* mod_init)(void)
Definition: cc.h:150
void(* newround)(struct cc_var *ccv, uint32_t round_cnt)
Definition: cc.h:191
char name[TCP_CA_NAME_MAX]
Definition: cc.h:147
void(* cong_signal)(struct cc_var *ccv, uint32_t type)
Definition: cc.h:179
void(* rttsample)(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas)
Definition: cc.h:197
int(* cb_init)(struct cc_var *ccv, void *ptr)
Definition: cc.h:167
void(* ecnpkt_handler)(struct cc_var *ccv)
Definition: cc.h:188
Definition: cc.h:93
union cc_var::ccv_container ccvc
void * cc_data
Definition: cc.h:94
int bytes_this_ack
Definition: cc.h:95
uint8_t labc
Definition: cc.h:104
uint16_t nsegs
Definition: cc.h:103
int type
Definition: cc.h:98
tcp_seq curack
Definition: cc.h:96
uint32_t flags
Definition: cc.h:97
Definition: tcp_var.h:132
struct tcpcb * tcp
Definition: cc.h:100
struct sctp_nets * sctp
Definition: cc.h:101