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 *
| 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 *
|
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
| 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
|
56 57/* Global CC vars. */ 58extern STAILQ_HEAD(cc_head, cc_algo) cc_list; 59extern const int tcprexmtthresh; 60extern struct cc_algo newreno_cc_algo; 61 62/* Per-netstack bits. */ 63VNET_DECLARE(struct cc_algo *, default_cc_ptr); 64#define V_default_cc_ptr VNET(default_cc_ptr) 65 66/* Define the new net.inet.tcp.cc sysctl tree. */ 67SYSCTL_DECL(_net_inet_tcp_cc); 68 69/* CC housekeeping functions. */ 70int cc_register_algo(struct cc_algo *add_cc); 71int cc_deregister_algo(struct cc_algo *remove_cc); 72 73/* 74 * Wrapper around transport structs that contain same-named congestion 75 * control variables. Allows algos to be shared amongst multiple CC aware 76 * transprots. 77 */ 78struct cc_var { 79 void *cc_data; /* Per-connection private CC algorithm data. */ 80 int bytes_this_ack; /* # bytes acked by the current ACK. */ 81 tcp_seq curack; /* Most recent ACK. */ 82 uint32_t flags; /* Flags for cc_var (see below) */ 83 int type; /* Indicates which ptr is valid in ccvc. */ 84 union ccv_container { 85 struct tcpcb *tcp; 86 struct sctp_nets *sctp; 87 } ccvc; 88}; 89 90/* cc_var flags. */ 91#define CCF_ABC_SENTAWND 0x0001 /* ABC counted cwnd worth of bytes? */ 92#define CCF_CWND_LIMITED 0x0002 /* Are we currently cwnd limited? */ 93#define CCF_DELACK 0x0004 /* Is this ack delayed? */ 94#define CCF_ACKNOW 0x0008 /* Will this ack be sent now? */ 95#define CCF_IPHDR_CE 0x0010 /* Does this packet set CE bit? */ 96#define CCF_TCPHDR_CWR 0x0020 /* Does this packet set CWR bit? */ 97 98/* ACK types passed to the ack_received() hook. */ 99#define CC_ACK 0x0001 /* Regular in sequence ACK. */ 100#define CC_DUPACK 0x0002 /* Duplicate ACK. */ 101#define CC_PARTIALACK 0x0004 /* Not yet. */ 102#define CC_SACK 0x0008 /* Not yet. */ 103 104/* 105 * Congestion signal types passed to the cong_signal() hook. The highest order 8 106 * bits (0x01000000 - 0x80000000) are reserved for CC algos to declare their own 107 * congestion signal types. 108 */ 109#define CC_ECN 0x00000001 /* ECN marked packet received. */ 110#define CC_RTO 0x00000002 /* RTO fired. */ 111#define CC_RTO_ERR 0x00000004 /* RTO fired in error. */ 112#define CC_NDUPACK 0x00000008 /* Threshold of dupack's reached. */ 113 114#define CC_SIGPRIVMASK 0xFF000000 /* Mask to check if sig is private. */ 115 116/* 117 * Structure to hold data and function pointers that together represent a 118 * congestion control algorithm. 119 */ 120struct cc_algo { 121 char name[TCP_CA_NAME_MAX]; 122 123 /* Init global module state on kldload. */ 124 int (*mod_init)(void); 125 126 /* Cleanup global module state on kldunload. */ 127 int (*mod_destroy)(void); 128 129 /* Init CC state for a new control block. */ 130 int (*cb_init)(struct cc_var *ccv); 131 132 /* Cleanup CC state for a terminating control block. */ 133 void (*cb_destroy)(struct cc_var *ccv); 134 135 /* Init variables for a newly established connection. */ 136 void (*conn_init)(struct cc_var *ccv); 137 138 /* Called on receipt of an ack. */ 139 void (*ack_received)(struct cc_var *ccv, uint16_t type); 140 141 /* Called on detection of a congestion signal. */ 142 void (*cong_signal)(struct cc_var *ccv, uint32_t type); 143 144 /* Called after exiting congestion recovery. */ 145 void (*post_recovery)(struct cc_var *ccv); 146 147 /* Called when data transfer resumes after an idle period. */ 148 void (*after_idle)(struct cc_var *ccv); 149 150 /* Called for an additional ECN processing apart from RFC3168. */ 151 void (*ecnpkt_handler)(struct cc_var *ccv); 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 159/* Macro to obtain the CC algo's data ptr. */ 160#define CC_DATA(tp) ((tp)->ccv->cc_data) 161 162/* Macro to obtain the system default CC algo's struct ptr. */ 163#define CC_DEFAULT() V_default_cc_ptr 164 165extern struct rwlock cc_list_lock; 166#define CC_LIST_LOCK_INIT() rw_init(&cc_list_lock, "cc_list") 167#define CC_LIST_LOCK_DESTROY() rw_destroy(&cc_list_lock) 168#define CC_LIST_RLOCK() rw_rlock(&cc_list_lock) 169#define CC_LIST_RUNLOCK() rw_runlock(&cc_list_lock) 170#define CC_LIST_WLOCK() rw_wlock(&cc_list_lock) 171#define CC_LIST_WUNLOCK() rw_wunlock(&cc_list_lock) 172#define CC_LIST_LOCK_ASSERT() rw_assert(&cc_list_lock, RA_LOCKED) 173
| 57 58/* Global CC vars. */ 59extern STAILQ_HEAD(cc_head, cc_algo) cc_list; 60extern const int tcprexmtthresh; 61extern struct cc_algo newreno_cc_algo; 62 63/* Per-netstack bits. */ 64VNET_DECLARE(struct cc_algo *, default_cc_ptr); 65#define V_default_cc_ptr VNET(default_cc_ptr) 66 67/* Define the new net.inet.tcp.cc sysctl tree. */ 68SYSCTL_DECL(_net_inet_tcp_cc); 69 70/* CC housekeeping functions. */ 71int cc_register_algo(struct cc_algo *add_cc); 72int cc_deregister_algo(struct cc_algo *remove_cc); 73 74/* 75 * Wrapper around transport structs that contain same-named congestion 76 * control variables. Allows algos to be shared amongst multiple CC aware 77 * transprots. 78 */ 79struct cc_var { 80 void *cc_data; /* Per-connection private CC algorithm data. */ 81 int bytes_this_ack; /* # bytes acked by the current ACK. */ 82 tcp_seq curack; /* Most recent ACK. */ 83 uint32_t flags; /* Flags for cc_var (see below) */ 84 int type; /* Indicates which ptr is valid in ccvc. */ 85 union ccv_container { 86 struct tcpcb *tcp; 87 struct sctp_nets *sctp; 88 } ccvc; 89}; 90 91/* cc_var flags. */ 92#define CCF_ABC_SENTAWND 0x0001 /* ABC counted cwnd worth of bytes? */ 93#define CCF_CWND_LIMITED 0x0002 /* Are we currently cwnd limited? */ 94#define CCF_DELACK 0x0004 /* Is this ack delayed? */ 95#define CCF_ACKNOW 0x0008 /* Will this ack be sent now? */ 96#define CCF_IPHDR_CE 0x0010 /* Does this packet set CE bit? */ 97#define CCF_TCPHDR_CWR 0x0020 /* Does this packet set CWR bit? */ 98 99/* ACK types passed to the ack_received() hook. */ 100#define CC_ACK 0x0001 /* Regular in sequence ACK. */ 101#define CC_DUPACK 0x0002 /* Duplicate ACK. */ 102#define CC_PARTIALACK 0x0004 /* Not yet. */ 103#define CC_SACK 0x0008 /* Not yet. */ 104 105/* 106 * Congestion signal types passed to the cong_signal() hook. The highest order 8 107 * bits (0x01000000 - 0x80000000) are reserved for CC algos to declare their own 108 * congestion signal types. 109 */ 110#define CC_ECN 0x00000001 /* ECN marked packet received. */ 111#define CC_RTO 0x00000002 /* RTO fired. */ 112#define CC_RTO_ERR 0x00000004 /* RTO fired in error. */ 113#define CC_NDUPACK 0x00000008 /* Threshold of dupack's reached. */ 114 115#define CC_SIGPRIVMASK 0xFF000000 /* Mask to check if sig is private. */ 116 117/* 118 * Structure to hold data and function pointers that together represent a 119 * congestion control algorithm. 120 */ 121struct cc_algo { 122 char name[TCP_CA_NAME_MAX]; 123 124 /* Init global module state on kldload. */ 125 int (*mod_init)(void); 126 127 /* Cleanup global module state on kldunload. */ 128 int (*mod_destroy)(void); 129 130 /* Init CC state for a new control block. */ 131 int (*cb_init)(struct cc_var *ccv); 132 133 /* Cleanup CC state for a terminating control block. */ 134 void (*cb_destroy)(struct cc_var *ccv); 135 136 /* Init variables for a newly established connection. */ 137 void (*conn_init)(struct cc_var *ccv); 138 139 /* Called on receipt of an ack. */ 140 void (*ack_received)(struct cc_var *ccv, uint16_t type); 141 142 /* Called on detection of a congestion signal. */ 143 void (*cong_signal)(struct cc_var *ccv, uint32_t type); 144 145 /* Called after exiting congestion recovery. */ 146 void (*post_recovery)(struct cc_var *ccv); 147 148 /* Called when data transfer resumes after an idle period. */ 149 void (*after_idle)(struct cc_var *ccv); 150 151 /* Called for an additional ECN processing apart from RFC3168. */ 152 void (*ecnpkt_handler)(struct cc_var *ccv); 153 154 STAILQ_ENTRY (cc_algo) entries; 155}; 156 157/* Macro to obtain the CC algo's struct ptr. */ 158#define CC_ALGO(tp) ((tp)->cc_algo) 159 160/* Macro to obtain the CC algo's data ptr. */ 161#define CC_DATA(tp) ((tp)->ccv->cc_data) 162 163/* Macro to obtain the system default CC algo's struct ptr. */ 164#define CC_DEFAULT() V_default_cc_ptr 165 166extern struct rwlock cc_list_lock; 167#define CC_LIST_LOCK_INIT() rw_init(&cc_list_lock, "cc_list") 168#define CC_LIST_LOCK_DESTROY() rw_destroy(&cc_list_lock) 169#define CC_LIST_RLOCK() rw_rlock(&cc_list_lock) 170#define CC_LIST_RUNLOCK() rw_runlock(&cc_list_lock) 171#define CC_LIST_WLOCK() rw_wlock(&cc_list_lock) 172#define CC_LIST_WUNLOCK() rw_wunlock(&cc_list_lock) 173#define CC_LIST_LOCK_ASSERT() rw_assert(&cc_list_lock, RA_LOCKED) 174
|