1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/sctp/src/netinet/sctp_cc_functions.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2483 @@ 1.4 +/*- 1.5 + * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 1.6 + * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 1.7 + * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions are met: 1.11 + * 1.12 + * a) Redistributions of source code must retain the above copyright notice, 1.13 + * this list of conditions and the following disclaimer. 1.14 + * 1.15 + * b) Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in 1.17 + * the documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * c) Neither the name of Cisco Systems, Inc. nor the names of its 1.20 + * contributors may be used to endorse or promote products derived 1.21 + * from this software without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 1.25 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.27 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.28 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.29 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.30 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.31 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.32 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 1.33 + * THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 + 1.36 +#ifdef __FreeBSD__ 1.37 +#include <sys/cdefs.h> 1.38 +__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 240158 2012-09-06 07:03:56Z tuexen $"); 1.39 +#endif 1.40 + 1.41 +#include <netinet/sctp_os.h> 1.42 +#include <netinet/sctp_var.h> 1.43 +#include <netinet/sctp_sysctl.h> 1.44 +#include <netinet/sctp_pcb.h> 1.45 +#include <netinet/sctp_header.h> 1.46 +#include <netinet/sctputil.h> 1.47 +#include <netinet/sctp_output.h> 1.48 +#include <netinet/sctp_input.h> 1.49 +#include <netinet/sctp_indata.h> 1.50 +#include <netinet/sctp_uio.h> 1.51 +#include <netinet/sctp_timer.h> 1.52 +#include <netinet/sctp_auth.h> 1.53 +#include <netinet/sctp_asconf.h> 1.54 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.55 +#include <netinet/sctp_dtrace_declare.h> 1.56 +#endif 1.57 + 1.58 +#define SHIFT_MPTCP_MULTI_N 40 1.59 +#define SHIFT_MPTCP_MULTI_Z 16 1.60 +#define SHIFT_MPTCP_MULTI 8 1.61 + 1.62 +static void 1.63 +sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) 1.64 +{ 1.65 + struct sctp_association *assoc; 1.66 + uint32_t cwnd_in_mtu; 1.67 + 1.68 + assoc = &stcb->asoc; 1.69 + cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); 1.70 + if (cwnd_in_mtu == 0) { 1.71 + /* Using 0 means that the value of RFC 4960 is used. */ 1.72 + net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); 1.73 + } else { 1.74 + /* 1.75 + * We take the minimum of the burst limit and the 1.76 + * initial congestion window. 1.77 + */ 1.78 + if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst)) 1.79 + cwnd_in_mtu = assoc->max_burst; 1.80 + net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; 1.81 + } 1.82 + if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || 1.83 + (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { 1.84 + /* In case of resource pooling initialize appropriately */ 1.85 + net->cwnd /= assoc->numnets; 1.86 + if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) { 1.87 + net->cwnd = net->mtu - sizeof(struct sctphdr); 1.88 + } 1.89 + } 1.90 + net->ssthresh = assoc->peers_rwnd; 1.91 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.92 + SDT_PROBE(sctp, cwnd, net, init, 1.93 + stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, 1.94 + 0, net->cwnd); 1.95 +#endif 1.96 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & 1.97 + (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { 1.98 + sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); 1.99 + } 1.100 +} 1.101 + 1.102 +static void 1.103 +sctp_cwnd_update_after_fr(struct sctp_tcb *stcb, 1.104 + struct sctp_association *asoc) 1.105 +{ 1.106 + struct sctp_nets *net; 1.107 + uint32_t t_ssthresh, t_cwnd; 1.108 + uint64_t t_ucwnd_sbw; 1.109 + 1.110 + /* MT FIXME: Don't compute this over and over again */ 1.111 + t_ssthresh = 0; 1.112 + t_cwnd = 0; 1.113 + t_ucwnd_sbw = 0; 1.114 + if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || 1.115 + (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { 1.116 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.117 + t_ssthresh += net->ssthresh; 1.118 + t_cwnd += net->cwnd; 1.119 + if (net->lastsa > 0) { 1.120 + t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa; 1.121 + } 1.122 + } 1.123 + if (t_ucwnd_sbw == 0) { 1.124 + t_ucwnd_sbw = 1; 1.125 + } 1.126 + } 1.127 + 1.128 + /*- 1.129 + * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && 1.130 + * (net->fast_retran_loss_recovery == 0))) 1.131 + */ 1.132 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.133 + if ((asoc->fast_retran_loss_recovery == 0) || 1.134 + (asoc->sctp_cmt_on_off > 0)) { 1.135 + /* out of a RFC2582 Fast recovery window? */ 1.136 + if (net->net_ack > 0) { 1.137 + /* 1.138 + * per section 7.2.3, are there any 1.139 + * destinations that had a fast retransmit 1.140 + * to them. If so what we need to do is 1.141 + * adjust ssthresh and cwnd. 1.142 + */ 1.143 + struct sctp_tmit_chunk *lchk; 1.144 + int old_cwnd = net->cwnd; 1.145 + 1.146 + if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || 1.147 + (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { 1.148 + if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) { 1.149 + net->ssthresh = (uint32_t)(((uint64_t)4 * 1.150 + (uint64_t)net->mtu * 1.151 + (uint64_t)net->ssthresh) / 1.152 + (uint64_t)t_ssthresh); 1.153 + 1.154 + } 1.155 + if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) { 1.156 + uint32_t srtt; 1.157 + 1.158 + srtt = net->lastsa; 1.159 + /* lastsa>>3; we don't need to devide ...*/ 1.160 + if (srtt == 0) { 1.161 + srtt = 1; 1.162 + } 1.163 + /* Short Version => Equal to Contel Version MBe */ 1.164 + net->ssthresh = (uint32_t) (((uint64_t)4 * 1.165 + (uint64_t)net->mtu * 1.166 + (uint64_t)net->cwnd) / 1.167 + ((uint64_t)srtt * 1.168 + t_ucwnd_sbw)); 1.169 + /* INCREASE FACTOR */; 1.170 + } 1.171 + if ((net->cwnd > t_cwnd / 2) && 1.172 + (net->ssthresh < net->cwnd - t_cwnd / 2)) { 1.173 + net->ssthresh = net->cwnd - t_cwnd / 2; 1.174 + } 1.175 + if (net->ssthresh < net->mtu) { 1.176 + net->ssthresh = net->mtu; 1.177 + } 1.178 + } else { 1.179 + net->ssthresh = net->cwnd / 2; 1.180 + if (net->ssthresh < (net->mtu * 2)) { 1.181 + net->ssthresh = 2 * net->mtu; 1.182 + } 1.183 + } 1.184 + net->cwnd = net->ssthresh; 1.185 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.186 + SDT_PROBE(sctp, cwnd, net, fr, 1.187 + stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, 1.188 + old_cwnd, net->cwnd); 1.189 +#endif 1.190 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.191 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), 1.192 + SCTP_CWND_LOG_FROM_FR); 1.193 + } 1.194 + lchk = TAILQ_FIRST(&asoc->send_queue); 1.195 + 1.196 + net->partial_bytes_acked = 0; 1.197 + /* Turn on fast recovery window */ 1.198 + asoc->fast_retran_loss_recovery = 1; 1.199 + if (lchk == NULL) { 1.200 + /* Mark end of the window */ 1.201 + asoc->fast_recovery_tsn = asoc->sending_seq - 1; 1.202 + } else { 1.203 + asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.204 + } 1.205 + 1.206 + /* 1.207 + * CMT fast recovery -- per destination 1.208 + * recovery variable. 1.209 + */ 1.210 + net->fast_retran_loss_recovery = 1; 1.211 + 1.212 + if (lchk == NULL) { 1.213 + /* Mark end of the window */ 1.214 + net->fast_recovery_tsn = asoc->sending_seq - 1; 1.215 + } else { 1.216 + net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.217 + } 1.218 + 1.219 + sctp_timer_stop(SCTP_TIMER_TYPE_SEND, 1.220 + stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32 ); 1.221 + sctp_timer_start(SCTP_TIMER_TYPE_SEND, 1.222 + stcb->sctp_ep, stcb, net); 1.223 + } 1.224 + } else if (net->net_ack > 0) { 1.225 + /* 1.226 + * Mark a peg that we WOULD have done a cwnd 1.227 + * reduction but RFC2582 prevented this action. 1.228 + */ 1.229 + SCTP_STAT_INCR(sctps_fastretransinrtt); 1.230 + } 1.231 + } 1.232 +} 1.233 + 1.234 +/* Defines for instantaneous bw decisions */ 1.235 +#define SCTP_INST_LOOSING 1 /* Loosing to other flows */ 1.236 +#define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */ 1.237 +#define SCTP_INST_GAINING 3 /* Gaining, step down possible */ 1.238 + 1.239 + 1.240 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.241 +static int 1.242 +cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, 1.243 + uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind) 1.244 +#else 1.245 +static int 1.246 +cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, 1.247 + uint64_t rtt_offset, uint8_t inst_ind) 1.248 +#endif 1.249 +{ 1.250 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.251 + uint64_t oth, probepoint; 1.252 +#endif 1.253 + 1.254 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.255 + probepoint = (((uint64_t)net->cwnd) << 32); 1.256 +#endif 1.257 + if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { 1.258 + /* 1.259 + * rtt increased 1.260 + * we don't update bw.. so we don't 1.261 + * update the rtt either. 1.262 + */ 1.263 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.264 + /* Probe point 5 */ 1.265 + probepoint |= ((5 << 16) | 1); 1.266 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.267 + vtag, 1.268 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.269 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.270 + net->flight_size, 1.271 + probepoint); 1.272 +#endif 1.273 + if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { 1.274 + if (net->cc_mod.rtcc.last_step_state == 5) 1.275 + net->cc_mod.rtcc.step_cnt++; 1.276 + else 1.277 + net->cc_mod.rtcc.step_cnt = 1; 1.278 + net->cc_mod.rtcc.last_step_state = 5; 1.279 + if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || 1.280 + ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && 1.281 + ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { 1.282 + /* Try a step down */ 1.283 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.284 + oth = net->cc_mod.rtcc.vol_reduce; 1.285 + oth <<= 16; 1.286 + oth |= net->cc_mod.rtcc.step_cnt; 1.287 + oth <<= 16; 1.288 + oth |= net->cc_mod.rtcc.last_step_state; 1.289 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.290 + vtag, 1.291 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.292 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.293 + oth, 1.294 + probepoint); 1.295 +#endif 1.296 + if (net->cwnd > (4 * net->mtu)) { 1.297 + net->cwnd -= net->mtu; 1.298 + net->cc_mod.rtcc.vol_reduce++; 1.299 + } else { 1.300 + net->cc_mod.rtcc.step_cnt = 0; 1.301 + } 1.302 + } 1.303 + } 1.304 + return (1); 1.305 + } 1.306 + if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { 1.307 + /* 1.308 + * rtt decreased, there could be more room. 1.309 + * we update both the bw and the rtt here to 1.310 + * lock this in as a good step down. 1.311 + */ 1.312 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.313 + /* Probe point 6 */ 1.314 + probepoint |= ((6 << 16) | 0); 1.315 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.316 + vtag, 1.317 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.318 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.319 + net->flight_size, 1.320 + probepoint); 1.321 +#endif 1.322 + if (net->cc_mod.rtcc.steady_step) { 1.323 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.324 + oth = net->cc_mod.rtcc.vol_reduce; 1.325 + oth <<= 16; 1.326 + oth |= net->cc_mod.rtcc.step_cnt; 1.327 + oth <<= 16; 1.328 + oth |= net->cc_mod.rtcc.last_step_state; 1.329 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.330 + vtag, 1.331 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.332 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.333 + oth, 1.334 + probepoint); 1.335 +#endif 1.336 + if ((net->cc_mod.rtcc.last_step_state == 5) && 1.337 + (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) { 1.338 + /* Step down worked */ 1.339 + net->cc_mod.rtcc.step_cnt = 0; 1.340 + return (1); 1.341 + } else { 1.342 + net->cc_mod.rtcc.last_step_state = 6; 1.343 + net->cc_mod.rtcc.step_cnt = 0; 1.344 + } 1.345 + } 1.346 + net->cc_mod.rtcc.lbw = nbw; 1.347 + net->cc_mod.rtcc.lbw_rtt = net->rtt; 1.348 + net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; 1.349 + if (inst_ind == SCTP_INST_GAINING) 1.350 + return (1); 1.351 + else if (inst_ind == SCTP_INST_NEUTRAL) 1.352 + return (1); 1.353 + else 1.354 + return (0); 1.355 + } 1.356 + /* Ok bw and rtt remained the same .. no update to any 1.357 + */ 1.358 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.359 + /* Probe point 7 */ 1.360 + probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq); 1.361 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.362 + vtag, 1.363 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.364 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.365 + net->flight_size, 1.366 + probepoint); 1.367 +#endif 1.368 + if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { 1.369 + if (net->cc_mod.rtcc.last_step_state == 5) 1.370 + net->cc_mod.rtcc.step_cnt++; 1.371 + else 1.372 + net->cc_mod.rtcc.step_cnt = 1; 1.373 + net->cc_mod.rtcc.last_step_state = 5; 1.374 + if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || 1.375 + ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && 1.376 + ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { 1.377 + /* Try a step down */ 1.378 + if (net->cwnd > (4 * net->mtu)) { 1.379 + net->cwnd -= net->mtu; 1.380 + net->cc_mod.rtcc.vol_reduce++; 1.381 + return (1); 1.382 + } else { 1.383 + net->cc_mod.rtcc.step_cnt = 0; 1.384 + } 1.385 + } 1.386 + } 1.387 + if (inst_ind == SCTP_INST_GAINING) 1.388 + return (1); 1.389 + else if (inst_ind == SCTP_INST_NEUTRAL) 1.390 + return (1); 1.391 + else 1.392 + return ((int)net->cc_mod.rtcc.ret_from_eq); 1.393 +} 1.394 + 1.395 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.396 +static int 1.397 +cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, 1.398 + uint64_t vtag, uint8_t inst_ind) 1.399 +#else 1.400 +static int 1.401 +cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, 1.402 + uint8_t inst_ind) 1.403 +#endif 1.404 +{ 1.405 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.406 + uint64_t oth, probepoint; 1.407 +#endif 1.408 + 1.409 + /* Bandwidth decreased.*/ 1.410 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.411 + probepoint = (((uint64_t)net->cwnd) << 32); 1.412 +#endif 1.413 + if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) { 1.414 + /* rtt increased */ 1.415 + /* Did we add more */ 1.416 + if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) && 1.417 + (inst_ind != SCTP_INST_LOOSING)) { 1.418 + /* We caused it maybe.. back off? */ 1.419 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.420 + /* PROBE POINT 1 */ 1.421 + probepoint |= ((1 << 16) | 1); 1.422 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.423 + vtag, 1.424 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.425 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.426 + net->flight_size, 1.427 + probepoint); 1.428 +#endif 1.429 + if (net->cc_mod.rtcc.ret_from_eq) { 1.430 + /* Switch over to CA if we are less aggressive */ 1.431 + net->ssthresh = net->cwnd-1; 1.432 + net->partial_bytes_acked = 0; 1.433 + } 1.434 + return (1); 1.435 + } 1.436 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.437 + /* Probe point 2 */ 1.438 + probepoint |= ((2 << 16) | 0); 1.439 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.440 + vtag, 1.441 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.442 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.443 + net->flight_size, 1.444 + probepoint); 1.445 +#endif 1.446 + /* Someone else - fight for more? */ 1.447 + if (net->cc_mod.rtcc.steady_step) { 1.448 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.449 + oth = net->cc_mod.rtcc.vol_reduce; 1.450 + oth <<= 16; 1.451 + oth |= net->cc_mod.rtcc.step_cnt; 1.452 + oth <<= 16; 1.453 + oth |= net->cc_mod.rtcc.last_step_state; 1.454 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.455 + vtag, 1.456 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.457 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.458 + oth, 1.459 + probepoint); 1.460 +#endif 1.461 + /* Did we voluntarily give up some? if so take 1.462 + * one back please 1.463 + */ 1.464 + if ((net->cc_mod.rtcc.vol_reduce) && 1.465 + (inst_ind != SCTP_INST_GAINING)) { 1.466 + net->cwnd += net->mtu; 1.467 + net->cc_mod.rtcc.vol_reduce--; 1.468 + } 1.469 + net->cc_mod.rtcc.last_step_state = 2; 1.470 + net->cc_mod.rtcc.step_cnt = 0; 1.471 + } 1.472 + goto out_decision; 1.473 + } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { 1.474 + /* bw & rtt decreased */ 1.475 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.476 + /* Probe point 3 */ 1.477 + probepoint |= ((3 << 16) | 0); 1.478 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.479 + vtag, 1.480 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.481 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.482 + net->flight_size, 1.483 + probepoint); 1.484 +#endif 1.485 + if (net->cc_mod.rtcc.steady_step) { 1.486 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.487 + oth = net->cc_mod.rtcc.vol_reduce; 1.488 + oth <<= 16; 1.489 + oth |= net->cc_mod.rtcc.step_cnt; 1.490 + oth <<= 16; 1.491 + oth |= net->cc_mod.rtcc.last_step_state; 1.492 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.493 + vtag, 1.494 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.495 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.496 + oth, 1.497 + probepoint); 1.498 +#endif 1.499 + if ((net->cc_mod.rtcc.vol_reduce) && 1.500 + (inst_ind != SCTP_INST_GAINING)) { 1.501 + net->cwnd += net->mtu; 1.502 + net->cc_mod.rtcc.vol_reduce--; 1.503 + } 1.504 + net->cc_mod.rtcc.last_step_state = 3; 1.505 + net->cc_mod.rtcc.step_cnt = 0; 1.506 + } 1.507 + goto out_decision; 1.508 + } 1.509 + /* The bw decreased but rtt stayed the same */ 1.510 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.511 + /* Probe point 4 */ 1.512 + probepoint |= ((4 << 16) | 0); 1.513 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.514 + vtag, 1.515 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.516 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.517 + net->flight_size, 1.518 + probepoint); 1.519 +#endif 1.520 + if (net->cc_mod.rtcc.steady_step) { 1.521 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.522 + oth = net->cc_mod.rtcc.vol_reduce; 1.523 + oth <<= 16; 1.524 + oth |= net->cc_mod.rtcc.step_cnt; 1.525 + oth <<= 16; 1.526 + oth |= net->cc_mod.rtcc.last_step_state; 1.527 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.528 + vtag, 1.529 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.530 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.531 + oth, 1.532 + probepoint); 1.533 +#endif 1.534 + if ((net->cc_mod.rtcc.vol_reduce) && 1.535 + (inst_ind != SCTP_INST_GAINING)) { 1.536 + net->cwnd += net->mtu; 1.537 + net->cc_mod.rtcc.vol_reduce--; 1.538 + } 1.539 + net->cc_mod.rtcc.last_step_state = 4; 1.540 + net->cc_mod.rtcc.step_cnt = 0; 1.541 + } 1.542 +out_decision: 1.543 + net->cc_mod.rtcc.lbw = nbw; 1.544 + net->cc_mod.rtcc.lbw_rtt = net->rtt; 1.545 + net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; 1.546 + if (inst_ind == SCTP_INST_GAINING) { 1.547 + return (1); 1.548 + } else { 1.549 + return (0); 1.550 + } 1.551 +} 1.552 + 1.553 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.554 +static int 1.555 +cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag) 1.556 +#else 1.557 +static int 1.558 +cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw) 1.559 +#endif 1.560 +{ 1.561 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.562 + uint64_t oth, probepoint; 1.563 + 1.564 +#endif 1.565 + /* BW increased, so update and 1.566 + * return 0, since all actions in 1.567 + * our table say to do the normal CC 1.568 + * update. Note that we pay no attention to 1.569 + * the inst_ind since our overall sum is increasing. 1.570 + */ 1.571 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.572 + /* PROBE POINT 0 */ 1.573 + probepoint = (((uint64_t)net->cwnd) << 32); 1.574 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.575 + vtag, 1.576 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.577 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.578 + net->flight_size, 1.579 + probepoint); 1.580 +#endif 1.581 + if (net->cc_mod.rtcc.steady_step) { 1.582 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.583 + oth = net->cc_mod.rtcc.vol_reduce; 1.584 + oth <<= 16; 1.585 + oth |= net->cc_mod.rtcc.step_cnt; 1.586 + oth <<= 16; 1.587 + oth |= net->cc_mod.rtcc.last_step_state; 1.588 + SDT_PROBE(sctp, cwnd, net, rttstep, 1.589 + vtag, 1.590 + ((net->cc_mod.rtcc.lbw << 32) | nbw), 1.591 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.592 + oth, 1.593 + probepoint); 1.594 +#endif 1.595 + net->cc_mod.rtcc.last_step_state = 0; 1.596 + net->cc_mod.rtcc.step_cnt = 0; 1.597 + net->cc_mod.rtcc.vol_reduce = 0; 1.598 + } 1.599 + net->cc_mod.rtcc.lbw = nbw; 1.600 + net->cc_mod.rtcc.lbw_rtt = net->rtt; 1.601 + net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; 1.602 + return (0); 1.603 +} 1.604 + 1.605 +/* RTCC Algoritm to limit growth of cwnd, return 1.606 + * true if you want to NOT allow cwnd growth 1.607 + */ 1.608 +static int 1.609 +cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) 1.610 +{ 1.611 + uint64_t bw_offset, rtt_offset; 1.612 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.613 + uint64_t probepoint, rtt, vtag; 1.614 +#endif 1.615 + uint64_t bytes_for_this_rtt, inst_bw; 1.616 + uint64_t div, inst_off; 1.617 + int bw_shift; 1.618 + uint8_t inst_ind; 1.619 + int ret; 1.620 + /*- 1.621 + * Here we need to see if we want 1.622 + * to limit cwnd growth due to increase 1.623 + * in overall rtt but no increase in bw. 1.624 + * We use the following table to figure 1.625 + * out what we should do. When we return 1.626 + * 0, cc update goes on as planned. If we 1.627 + * return 1, then no cc update happens and cwnd 1.628 + * stays where it is at. 1.629 + * ---------------------------------- 1.630 + * BW | RTT | Action 1.631 + * ********************************* 1.632 + * INC | INC | return 0 1.633 + * ---------------------------------- 1.634 + * INC | SAME | return 0 1.635 + * ---------------------------------- 1.636 + * INC | DECR | return 0 1.637 + * ---------------------------------- 1.638 + * SAME | INC | return 1 1.639 + * ---------------------------------- 1.640 + * SAME | SAME | return 1 1.641 + * ---------------------------------- 1.642 + * SAME | DECR | return 0 1.643 + * ---------------------------------- 1.644 + * DECR | INC | return 0 or 1 based on if we caused. 1.645 + * ---------------------------------- 1.646 + * DECR | SAME | return 0 1.647 + * ---------------------------------- 1.648 + * DECR | DECR | return 0 1.649 + * ---------------------------------- 1.650 + * 1.651 + * We are a bit fuzz on what an increase or 1.652 + * decrease is. For BW it is the same if 1.653 + * it did not change within 1/64th. For 1.654 + * RTT it stayed the same if it did not 1.655 + * change within 1/32nd 1.656 + */ 1.657 + bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw); 1.658 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.659 + rtt = stcb->asoc.my_vtag; 1.660 + vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); 1.661 + probepoint = (((uint64_t)net->cwnd) << 32); 1.662 + rtt = net->rtt; 1.663 +#endif 1.664 + if (net->cc_mod.rtcc.rtt_set_this_sack) { 1.665 + net->cc_mod.rtcc.rtt_set_this_sack = 0; 1.666 + bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc; 1.667 + net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; 1.668 + if (net->rtt) { 1.669 + div = net->rtt / 1000; 1.670 + if (div) { 1.671 + inst_bw = bytes_for_this_rtt / div; 1.672 + inst_off = inst_bw >> bw_shift; 1.673 + if (inst_bw > nbw) 1.674 + inst_ind = SCTP_INST_GAINING; 1.675 + else if ((inst_bw+inst_off) < nbw) 1.676 + inst_ind = SCTP_INST_LOOSING; 1.677 + else 1.678 + inst_ind = SCTP_INST_NEUTRAL; 1.679 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.680 + probepoint |= ((0xb << 16) | inst_ind); 1.681 +#endif 1.682 + } else { 1.683 + inst_ind = net->cc_mod.rtcc.last_inst_ind; 1.684 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.685 + inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt); 1.686 + /* Can't determine do not change */ 1.687 + probepoint |= ((0xc << 16) | inst_ind); 1.688 +#endif 1.689 + } 1.690 + } else { 1.691 + inst_ind = net->cc_mod.rtcc.last_inst_ind; 1.692 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.693 + inst_bw = bytes_for_this_rtt; 1.694 + /* Can't determine do not change */ 1.695 + probepoint |= ((0xd << 16) | inst_ind); 1.696 +#endif 1.697 + } 1.698 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.699 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.700 + vtag, 1.701 + ((nbw << 32) | inst_bw), 1.702 + ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt), 1.703 + net->flight_size, 1.704 + probepoint); 1.705 +#endif 1.706 + } else { 1.707 + /* No rtt measurement, use last one */ 1.708 + inst_ind = net->cc_mod.rtcc.last_inst_ind; 1.709 + } 1.710 + bw_offset = net->cc_mod.rtcc.lbw >> bw_shift; 1.711 + if (nbw > net->cc_mod.rtcc.lbw + bw_offset) { 1.712 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.713 + ret = cc_bw_increase(stcb, net, nbw, vtag); 1.714 +#else 1.715 + ret = cc_bw_increase(stcb, net, nbw); 1.716 +#endif 1.717 + goto out; 1.718 + } 1.719 + rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt); 1.720 + if (nbw < net->cc_mod.rtcc.lbw - bw_offset) { 1.721 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.722 + ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind); 1.723 +#else 1.724 + ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind); 1.725 +#endif 1.726 + goto out; 1.727 + } 1.728 + /* If we reach here then 1.729 + * we are in a situation where 1.730 + * the bw stayed the same. 1.731 + */ 1.732 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.733 + ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind); 1.734 +#else 1.735 + ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind); 1.736 +#endif 1.737 +out: 1.738 + net->cc_mod.rtcc.last_inst_ind = inst_ind; 1.739 + return (ret); 1.740 +} 1.741 + 1.742 +static void 1.743 +sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, 1.744 + struct sctp_association *asoc, 1.745 + int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc) 1.746 +{ 1.747 + struct sctp_nets *net; 1.748 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.749 + int old_cwnd; 1.750 +#endif 1.751 + uint32_t t_ssthresh, t_cwnd, incr; 1.752 + uint64_t t_ucwnd_sbw; 1.753 + uint64_t t_path_mptcp; 1.754 + uint64_t mptcp_like_alpha; 1.755 + uint32_t srtt; 1.756 + uint64_t max_path; 1.757 + 1.758 + /* MT FIXME: Don't compute this over and over again */ 1.759 + t_ssthresh = 0; 1.760 + t_cwnd = 0; 1.761 + t_ucwnd_sbw = 0; 1.762 + t_path_mptcp = 0; 1.763 + mptcp_like_alpha = 1; 1.764 + if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || 1.765 + (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) || 1.766 + (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) { 1.767 + max_path = 0; 1.768 + TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1.769 + t_ssthresh += net->ssthresh; 1.770 + t_cwnd += net->cwnd; 1.771 + /* lastsa>>3; we don't need to devide ...*/ 1.772 + srtt = net->lastsa; 1.773 + if (srtt > 0) { 1.774 + uint64_t tmp; 1.775 + 1.776 + t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt; 1.777 + t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) / 1.778 + (((uint64_t)net->mtu) * (uint64_t)srtt); 1.779 + tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) / 1.780 + ((uint64_t)net->mtu * (uint64_t)(srtt * srtt)); 1.781 + if (tmp > max_path) { 1.782 + max_path = tmp; 1.783 + } 1.784 + } 1.785 + } 1.786 + if (t_path_mptcp > 0) { 1.787 + mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp); 1.788 + } else { 1.789 + mptcp_like_alpha = 1; 1.790 + } 1.791 + } 1.792 + if (t_ssthresh == 0) { 1.793 + t_ssthresh = 1; 1.794 + } 1.795 + if (t_ucwnd_sbw == 0) { 1.796 + t_ucwnd_sbw = 1; 1.797 + } 1.798 + /******************************/ 1.799 + /* update cwnd and Early FR */ 1.800 + /******************************/ 1.801 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.802 + 1.803 +#ifdef JANA_CMT_FAST_RECOVERY 1.804 + /* 1.805 + * CMT fast recovery code. Need to debug. 1.806 + */ 1.807 + if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { 1.808 + if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || 1.809 + SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { 1.810 + net->will_exit_fast_recovery = 1; 1.811 + } 1.812 + } 1.813 +#endif 1.814 + /* if nothing was acked on this destination skip it */ 1.815 + if (net->net_ack == 0) { 1.816 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.817 + sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); 1.818 + } 1.819 + continue; 1.820 + } 1.821 +#ifdef JANA_CMT_FAST_RECOVERY 1.822 + /* CMT fast recovery code 1.823 + */ 1.824 + /* 1.825 + if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { 1.826 + @@@ Do something 1.827 + } 1.828 + else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { 1.829 + */ 1.830 +#endif 1.831 + 1.832 + if (asoc->fast_retran_loss_recovery && 1.833 + (will_exit == 0) && 1.834 + (asoc->sctp_cmt_on_off == 0)) { 1.835 + /* 1.836 + * If we are in loss recovery we skip any cwnd 1.837 + * update 1.838 + */ 1.839 + return; 1.840 + } 1.841 + /* 1.842 + * Did any measurements go on for this network? 1.843 + */ 1.844 + if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) { 1.845 + uint64_t nbw; 1.846 + /* 1.847 + * At this point our bw_bytes has been updated 1.848 + * by incoming sack information. 1.849 + * 1.850 + * But our bw may not yet be set. 1.851 + * 1.852 + */ 1.853 + if ((net->cc_mod.rtcc.new_tot_time/1000) > 0) { 1.854 + nbw = net->cc_mod.rtcc.bw_bytes/(net->cc_mod.rtcc.new_tot_time/1000); 1.855 + } else { 1.856 + nbw = net->cc_mod.rtcc.bw_bytes; 1.857 + } 1.858 + if (net->cc_mod.rtcc.lbw) { 1.859 + if (cc_bw_limit(stcb, net, nbw)) { 1.860 + /* Hold here, no update */ 1.861 + continue; 1.862 + } 1.863 + } else { 1.864 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.865 + uint64_t vtag, probepoint; 1.866 + 1.867 + probepoint = (((uint64_t)net->cwnd) << 32); 1.868 + probepoint |= ((0xa << 16) | 0); 1.869 + vtag = (net->rtt << 32) | 1.870 + (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | 1.871 + (stcb->rport); 1.872 + 1.873 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.874 + vtag, 1.875 + nbw, 1.876 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.877 + net->flight_size, 1.878 + probepoint); 1.879 +#endif 1.880 + net->cc_mod.rtcc.lbw = nbw; 1.881 + net->cc_mod.rtcc.lbw_rtt = net->rtt; 1.882 + if (net->cc_mod.rtcc.rtt_set_this_sack) { 1.883 + net->cc_mod.rtcc.rtt_set_this_sack = 0; 1.884 + net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; 1.885 + } 1.886 + } 1.887 + } 1.888 + /* 1.889 + * CMT: CUC algorithm. Update cwnd if pseudo-cumack has 1.890 + * moved. 1.891 + */ 1.892 + if (accum_moved || 1.893 + ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { 1.894 + /* If the cumulative ack moved we can proceed */ 1.895 + if (net->cwnd <= net->ssthresh) { 1.896 + /* We are in slow start */ 1.897 + if (net->flight_size + net->net_ack >= net->cwnd) { 1.898 + uint32_t limit; 1.899 + 1.900 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.901 + old_cwnd = net->cwnd; 1.902 +#endif 1.903 + switch (asoc->sctp_cmt_on_off) { 1.904 + case SCTP_CMT_RPV1: 1.905 + limit = (uint32_t)(((uint64_t)net->mtu * 1.906 + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * 1.907 + (uint64_t)net->ssthresh) / 1.908 + (uint64_t)t_ssthresh); 1.909 + incr = (uint32_t)(((uint64_t)net->net_ack * 1.910 + (uint64_t)net->ssthresh) / 1.911 + (uint64_t)t_ssthresh); 1.912 + if (incr > limit) { 1.913 + incr = limit; 1.914 + } 1.915 + if (incr == 0) { 1.916 + incr = 1; 1.917 + } 1.918 + break; 1.919 + case SCTP_CMT_RPV2: 1.920 + /* lastsa>>3; we don't need to divide ...*/ 1.921 + srtt = net->lastsa; 1.922 + if (srtt == 0) { 1.923 + srtt = 1; 1.924 + } 1.925 + limit = (uint32_t)(((uint64_t)net->mtu * 1.926 + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * 1.927 + (uint64_t)net->cwnd) / 1.928 + ((uint64_t)srtt * t_ucwnd_sbw)); 1.929 + /* INCREASE FACTOR */ 1.930 + incr = (uint32_t)(((uint64_t)net->net_ack * 1.931 + (uint64_t)net->cwnd) / 1.932 + ((uint64_t)srtt * t_ucwnd_sbw)); 1.933 + /* INCREASE FACTOR */ 1.934 + if (incr > limit) { 1.935 + incr = limit; 1.936 + } 1.937 + if (incr == 0) { 1.938 + incr = 1; 1.939 + } 1.940 + break; 1.941 + case SCTP_CMT_MPTCP: 1.942 + limit = (uint32_t)(((uint64_t)net->mtu * 1.943 + mptcp_like_alpha * 1.944 + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >> 1.945 + SHIFT_MPTCP_MULTI); 1.946 + incr = (uint32_t)(((uint64_t)net->net_ack * 1.947 + mptcp_like_alpha) >> 1.948 + SHIFT_MPTCP_MULTI); 1.949 + if (incr > limit) { 1.950 + incr = limit; 1.951 + } 1.952 + if (incr > net->net_ack) { 1.953 + incr = net->net_ack; 1.954 + } 1.955 + if (incr > net->mtu) { 1.956 + incr = net->mtu; 1.957 + } 1.958 + break; 1.959 + default: 1.960 + incr = net->net_ack; 1.961 + if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) { 1.962 + incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable); 1.963 + } 1.964 + break; 1.965 + } 1.966 + net->cwnd += incr; 1.967 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.968 + sctp_log_cwnd(stcb, net, incr, 1.969 + SCTP_CWND_LOG_FROM_SS); 1.970 + } 1.971 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.972 + SDT_PROBE(sctp, cwnd, net, ack, 1.973 + stcb->asoc.my_vtag, 1.974 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.975 + net, 1.976 + old_cwnd, net->cwnd); 1.977 +#endif 1.978 + } else { 1.979 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.980 + sctp_log_cwnd(stcb, net, net->net_ack, 1.981 + SCTP_CWND_LOG_NOADV_SS); 1.982 + } 1.983 + } 1.984 + } else { 1.985 + /* We are in congestion avoidance */ 1.986 + /* 1.987 + * Add to pba 1.988 + */ 1.989 + net->partial_bytes_acked += net->net_ack; 1.990 + 1.991 + if ((net->flight_size + net->net_ack >= net->cwnd) && 1.992 + (net->partial_bytes_acked >= net->cwnd)) { 1.993 + net->partial_bytes_acked -= net->cwnd; 1.994 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.995 + old_cwnd = net->cwnd; 1.996 +#endif 1.997 + switch (asoc->sctp_cmt_on_off) { 1.998 + case SCTP_CMT_RPV1: 1.999 + incr = (uint32_t)(((uint64_t)net->mtu * 1.1000 + (uint64_t)net->ssthresh) / 1.1001 + (uint64_t)t_ssthresh); 1.1002 + if (incr == 0) { 1.1003 + incr = 1; 1.1004 + } 1.1005 + break; 1.1006 + case SCTP_CMT_RPV2: 1.1007 + /* lastsa>>3; we don't need to divide ... */ 1.1008 + srtt = net->lastsa; 1.1009 + if (srtt == 0) { 1.1010 + srtt = 1; 1.1011 + } 1.1012 + incr = (uint32_t)((uint64_t)net->mtu * 1.1013 + (uint64_t)net->cwnd / 1.1014 + ((uint64_t)srtt * 1.1015 + t_ucwnd_sbw)); 1.1016 + /* INCREASE FACTOR */ 1.1017 + if (incr == 0) { 1.1018 + incr = 1; 1.1019 + } 1.1020 + break; 1.1021 + case SCTP_CMT_MPTCP: 1.1022 + incr = (uint32_t)((mptcp_like_alpha * 1.1023 + (uint64_t) net->cwnd) >> 1.1024 + SHIFT_MPTCP_MULTI); 1.1025 + if (incr > net->mtu) { 1.1026 + incr = net->mtu; 1.1027 + } 1.1028 + break; 1.1029 + default: 1.1030 + incr = net->mtu; 1.1031 + break; 1.1032 + } 1.1033 + net->cwnd += incr; 1.1034 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1035 + SDT_PROBE(sctp, cwnd, net, ack, 1.1036 + stcb->asoc.my_vtag, 1.1037 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.1038 + net, 1.1039 + old_cwnd, net->cwnd); 1.1040 +#endif 1.1041 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1042 + sctp_log_cwnd(stcb, net, net->mtu, 1.1043 + SCTP_CWND_LOG_FROM_CA); 1.1044 + } 1.1045 + } else { 1.1046 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1047 + sctp_log_cwnd(stcb, net, net->net_ack, 1.1048 + SCTP_CWND_LOG_NOADV_CA); 1.1049 + } 1.1050 + } 1.1051 + } 1.1052 + } else { 1.1053 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1054 + sctp_log_cwnd(stcb, net, net->mtu, 1.1055 + SCTP_CWND_LOG_NO_CUMACK); 1.1056 + } 1.1057 + } 1.1058 + } 1.1059 +} 1.1060 + 1.1061 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1062 +static void 1.1063 +sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net) 1.1064 +#else 1.1065 +static void 1.1066 +sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net) 1.1067 +#endif 1.1068 +{ 1.1069 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1070 + int old_cwnd; 1.1071 + 1.1072 + old_cwnd = net->cwnd; 1.1073 +#endif 1.1074 + net->cwnd = net->mtu; 1.1075 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1076 + SDT_PROBE(sctp, cwnd, net, ack, 1.1077 + stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, 1.1078 + old_cwnd, net->cwnd); 1.1079 +#endif 1.1080 + SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n", 1.1081 + (void *)net, net->cwnd); 1.1082 +} 1.1083 + 1.1084 + 1.1085 +static void 1.1086 +sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) 1.1087 +{ 1.1088 + int old_cwnd = net->cwnd; 1.1089 + uint32_t t_ssthresh, t_cwnd; 1.1090 + uint64_t t_ucwnd_sbw; 1.1091 + 1.1092 + /* MT FIXME: Don't compute this over and over again */ 1.1093 + t_ssthresh = 0; 1.1094 + t_cwnd = 0; 1.1095 + if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || 1.1096 + (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { 1.1097 + struct sctp_nets *lnet; 1.1098 + uint32_t srtt; 1.1099 + 1.1100 + t_ucwnd_sbw = 0; 1.1101 + TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) { 1.1102 + t_ssthresh += lnet->ssthresh; 1.1103 + t_cwnd += lnet->cwnd; 1.1104 + srtt = lnet->lastsa; 1.1105 + /* lastsa>>3; we don't need to divide ... */ 1.1106 + if (srtt > 0) { 1.1107 + t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt; 1.1108 + } 1.1109 + } 1.1110 + if (t_ssthresh < 1) { 1.1111 + t_ssthresh = 1; 1.1112 + } 1.1113 + if (t_ucwnd_sbw < 1) { 1.1114 + t_ucwnd_sbw = 1; 1.1115 + } 1.1116 + if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) { 1.1117 + net->ssthresh = (uint32_t)(((uint64_t)4 * 1.1118 + (uint64_t)net->mtu * 1.1119 + (uint64_t)net->ssthresh) / 1.1120 + (uint64_t)t_ssthresh); 1.1121 + } else { 1.1122 + uint64_t cc_delta; 1.1123 + 1.1124 + srtt = net->lastsa; 1.1125 + /* lastsa>>3; we don't need to divide ... */ 1.1126 + if (srtt == 0) { 1.1127 + srtt = 1; 1.1128 + } 1.1129 + cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2; 1.1130 + if (cc_delta < t_cwnd) { 1.1131 + net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta); 1.1132 + } else { 1.1133 + net->ssthresh = net->mtu; 1.1134 + } 1.1135 + } 1.1136 + if ((net->cwnd > t_cwnd / 2) && 1.1137 + (net->ssthresh < net->cwnd - t_cwnd / 2)) { 1.1138 + net->ssthresh = net->cwnd - t_cwnd / 2; 1.1139 + } 1.1140 + if (net->ssthresh < net->mtu) { 1.1141 + net->ssthresh = net->mtu; 1.1142 + } 1.1143 + } else { 1.1144 + net->ssthresh = max(net->cwnd / 2, 4 * net->mtu); 1.1145 + } 1.1146 + net->cwnd = net->mtu; 1.1147 + net->partial_bytes_acked = 0; 1.1148 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1149 + SDT_PROBE(sctp, cwnd, net, to, 1.1150 + stcb->asoc.my_vtag, 1.1151 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.1152 + net, 1.1153 + old_cwnd, net->cwnd); 1.1154 +#endif 1.1155 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1156 + sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); 1.1157 + } 1.1158 +} 1.1159 + 1.1160 +static void 1.1161 +sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net, 1.1162 + int in_window, int num_pkt_lost, int use_rtcc) 1.1163 +{ 1.1164 + int old_cwnd = net->cwnd; 1.1165 + if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) { 1.1166 + /* Data center Congestion Control */ 1.1167 + if (in_window == 0) { 1.1168 + /* Go to CA with the cwnd at the point we sent 1.1169 + * the TSN that was marked with a CE. 1.1170 + */ 1.1171 + if (net->ecn_prev_cwnd < net->cwnd) { 1.1172 + /* Restore to prev cwnd */ 1.1173 + net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost); 1.1174 + } else { 1.1175 + /* Just cut in 1/2 */ 1.1176 + net->cwnd /= 2; 1.1177 + } 1.1178 + /* Drop to CA */ 1.1179 + net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu); 1.1180 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1181 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); 1.1182 + } 1.1183 + } else { 1.1184 + /* Further tuning down required over the drastic orginal cut */ 1.1185 + net->ssthresh -= (net->mtu * num_pkt_lost); 1.1186 + net->cwnd -= (net->mtu * num_pkt_lost); 1.1187 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1188 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); 1.1189 + } 1.1190 + 1.1191 + } 1.1192 + SCTP_STAT_INCR(sctps_ecnereducedcwnd); 1.1193 + } else { 1.1194 + if (in_window == 0) { 1.1195 + SCTP_STAT_INCR(sctps_ecnereducedcwnd); 1.1196 + net->ssthresh = net->cwnd / 2; 1.1197 + if (net->ssthresh < net->mtu) { 1.1198 + net->ssthresh = net->mtu; 1.1199 + /* here back off the timer as well, to slow us down */ 1.1200 + net->RTO <<= 1; 1.1201 + } 1.1202 + net->cwnd = net->ssthresh; 1.1203 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1204 + SDT_PROBE(sctp, cwnd, net, ecn, 1.1205 + stcb->asoc.my_vtag, 1.1206 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.1207 + net, 1.1208 + old_cwnd, net->cwnd); 1.1209 +#endif 1.1210 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1211 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); 1.1212 + } 1.1213 + } 1.1214 + } 1.1215 + 1.1216 +} 1.1217 + 1.1218 +static void 1.1219 +sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb, 1.1220 + struct sctp_nets *net, struct sctp_pktdrop_chunk *cp, 1.1221 + uint32_t *bottle_bw, uint32_t *on_queue) 1.1222 +{ 1.1223 + uint32_t bw_avail; 1.1224 + int rtt; 1.1225 + unsigned int incr; 1.1226 + int old_cwnd = net->cwnd; 1.1227 + 1.1228 + /* need real RTT in msd for this calc */ 1.1229 + rtt = net->rtt / 1000; 1.1230 + /* get bottle neck bw */ 1.1231 + *bottle_bw = ntohl(cp->bottle_bw); 1.1232 + /* and whats on queue */ 1.1233 + *on_queue = ntohl(cp->current_onq); 1.1234 + /* 1.1235 + * adjust the on-queue if our flight is more it could be 1.1236 + * that the router has not yet gotten data "in-flight" to it 1.1237 + */ 1.1238 + if (*on_queue < net->flight_size) 1.1239 + *on_queue = net->flight_size; 1.1240 + /* calculate the available space */ 1.1241 + bw_avail = (*bottle_bw * rtt) / 1000; 1.1242 + if (bw_avail > *bottle_bw) { 1.1243 + /* 1.1244 + * Cap the growth to no more than the bottle neck. 1.1245 + * This can happen as RTT slides up due to queues. 1.1246 + * It also means if you have more than a 1 second 1.1247 + * RTT with a empty queue you will be limited to the 1.1248 + * bottle_bw per second no matter if other points 1.1249 + * have 1/2 the RTT and you could get more out... 1.1250 + */ 1.1251 + bw_avail = *bottle_bw; 1.1252 + } 1.1253 + if (*on_queue > bw_avail) { 1.1254 + /* 1.1255 + * No room for anything else don't allow anything 1.1256 + * else to be "added to the fire". 1.1257 + */ 1.1258 + int seg_inflight, seg_onqueue, my_portion; 1.1259 + net->partial_bytes_acked = 0; 1.1260 + 1.1261 + /* how much are we over queue size? */ 1.1262 + incr = *on_queue - bw_avail; 1.1263 + if (stcb->asoc.seen_a_sack_this_pkt) { 1.1264 + /* 1.1265 + * undo any cwnd adjustment that the sack 1.1266 + * might have made 1.1267 + */ 1.1268 + net->cwnd = net->prev_cwnd; 1.1269 + } 1.1270 + /* Now how much of that is mine? */ 1.1271 + seg_inflight = net->flight_size / net->mtu; 1.1272 + seg_onqueue = *on_queue / net->mtu; 1.1273 + my_portion = (incr * seg_inflight) / seg_onqueue; 1.1274 + 1.1275 + /* Have I made an adjustment already */ 1.1276 + if (net->cwnd > net->flight_size) { 1.1277 + /* 1.1278 + * for this flight I made an adjustment we 1.1279 + * need to decrease the portion by a share 1.1280 + * our previous adjustment. 1.1281 + */ 1.1282 + int diff_adj; 1.1283 + 1.1284 + diff_adj = net->cwnd - net->flight_size; 1.1285 + if (diff_adj > my_portion) 1.1286 + my_portion = 0; 1.1287 + else 1.1288 + my_portion -= diff_adj; 1.1289 + } 1.1290 + /* 1.1291 + * back down to the previous cwnd (assume we have 1.1292 + * had a sack before this packet). minus what ever 1.1293 + * portion of the overage is my fault. 1.1294 + */ 1.1295 + net->cwnd -= my_portion; 1.1296 + 1.1297 + /* we will NOT back down more than 1 MTU */ 1.1298 + if (net->cwnd <= net->mtu) { 1.1299 + net->cwnd = net->mtu; 1.1300 + } 1.1301 + /* force into CA */ 1.1302 + net->ssthresh = net->cwnd - 1; 1.1303 + } else { 1.1304 + /* 1.1305 + * Take 1/4 of the space left or max burst up .. 1.1306 + * whichever is less. 1.1307 + */ 1.1308 + incr = (bw_avail - *on_queue) >> 2; 1.1309 + if ((stcb->asoc.max_burst > 0) && 1.1310 + (stcb->asoc.max_burst * net->mtu < incr)) { 1.1311 + incr = stcb->asoc.max_burst * net->mtu; 1.1312 + } 1.1313 + net->cwnd += incr; 1.1314 + } 1.1315 + if (net->cwnd > bw_avail) { 1.1316 + /* We can't exceed the pipe size */ 1.1317 + net->cwnd = bw_avail; 1.1318 + } 1.1319 + if (net->cwnd < net->mtu) { 1.1320 + /* We always have 1 MTU */ 1.1321 + net->cwnd = net->mtu; 1.1322 + } 1.1323 + 1.1324 + if (net->cwnd - old_cwnd != 0) { 1.1325 + /* log only changes */ 1.1326 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1327 + SDT_PROBE(sctp, cwnd, net, pd, 1.1328 + stcb->asoc.my_vtag, 1.1329 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.1330 + net, 1.1331 + old_cwnd, net->cwnd); 1.1332 +#endif 1.1333 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1334 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), 1.1335 + SCTP_CWND_LOG_FROM_SAT); 1.1336 + } 1.1337 + } 1.1338 +} 1.1339 + 1.1340 +static void 1.1341 +sctp_cwnd_update_after_output(struct sctp_tcb *stcb, 1.1342 + struct sctp_nets *net, int burst_limit) 1.1343 +{ 1.1344 + int old_cwnd = net->cwnd; 1.1345 + 1.1346 + if (net->ssthresh < net->cwnd) 1.1347 + net->ssthresh = net->cwnd; 1.1348 + if (burst_limit) { 1.1349 + net->cwnd = (net->flight_size + (burst_limit * net->mtu)); 1.1350 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1351 + SDT_PROBE(sctp, cwnd, net, bl, 1.1352 + stcb->asoc.my_vtag, 1.1353 + ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), 1.1354 + net, 1.1355 + old_cwnd, net->cwnd); 1.1356 +#endif 1.1357 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1358 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST); 1.1359 + } 1.1360 + } 1.1361 +} 1.1362 + 1.1363 +static void 1.1364 +sctp_cwnd_update_after_sack(struct sctp_tcb *stcb, 1.1365 + struct sctp_association *asoc, 1.1366 + int accum_moved, int reneged_all, int will_exit) 1.1367 +{ 1.1368 + /* Passing a zero argument in last disables the rtcc algoritm */ 1.1369 + sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0); 1.1370 +} 1.1371 + 1.1372 +static void 1.1373 +sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, 1.1374 + int in_window, int num_pkt_lost) 1.1375 +{ 1.1376 + /* Passing a zero argument in last disables the rtcc algoritm */ 1.1377 + sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0); 1.1378 +} 1.1379 + 1.1380 +/* Here starts the RTCCVAR type CC invented by RRS which 1.1381 + * is a slight mod to RFC2581. We reuse a common routine or 1.1382 + * two since these algoritms are so close and need to 1.1383 + * remain the same. 1.1384 + */ 1.1385 +static void 1.1386 +sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, 1.1387 + int in_window, int num_pkt_lost) 1.1388 +{ 1.1389 + sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1); 1.1390 +} 1.1391 + 1.1392 + 1.1393 +static 1.1394 +void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net, 1.1395 + struct sctp_tmit_chunk *tp1) 1.1396 +{ 1.1397 + net->cc_mod.rtcc.bw_bytes += tp1->send_size; 1.1398 +} 1.1399 + 1.1400 +static void 1.1401 +sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED, 1.1402 + struct sctp_nets *net) 1.1403 +{ 1.1404 + if (net->cc_mod.rtcc.tls_needs_set > 0) { 1.1405 + /* We had a bw measurment going on */ 1.1406 + struct timeval ltls; 1.1407 + SCTP_GETPTIME_TIMEVAL(<ls); 1.1408 + timevalsub(<ls, &net->cc_mod.rtcc.tls); 1.1409 + net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec; 1.1410 + } 1.1411 +} 1.1412 + 1.1413 +static void 1.1414 +sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, 1.1415 + struct sctp_nets *net) 1.1416 +{ 1.1417 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1418 + uint64_t vtag, probepoint; 1.1419 + 1.1420 +#endif 1.1421 + if (net->cc_mod.rtcc.lbw) { 1.1422 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1423 + /* Clear the old bw.. we went to 0 in-flight */ 1.1424 + vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | 1.1425 + (stcb->rport); 1.1426 + probepoint = (((uint64_t)net->cwnd) << 32); 1.1427 + /* Probe point 8 */ 1.1428 + probepoint |= ((8 << 16) | 0); 1.1429 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.1430 + vtag, 1.1431 + ((net->cc_mod.rtcc.lbw << 32) | 0), 1.1432 + ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), 1.1433 + net->flight_size, 1.1434 + probepoint); 1.1435 +#endif 1.1436 + net->cc_mod.rtcc.lbw_rtt = 0; 1.1437 + net->cc_mod.rtcc.cwnd_at_bw_set = 0; 1.1438 + net->cc_mod.rtcc.lbw = 0; 1.1439 + net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; 1.1440 + net->cc_mod.rtcc.vol_reduce = 0; 1.1441 + net->cc_mod.rtcc.bw_tot_time = 0; 1.1442 + net->cc_mod.rtcc.bw_bytes = 0; 1.1443 + net->cc_mod.rtcc.tls_needs_set = 0; 1.1444 + if (net->cc_mod.rtcc.steady_step) { 1.1445 + net->cc_mod.rtcc.vol_reduce = 0; 1.1446 + net->cc_mod.rtcc.step_cnt = 0; 1.1447 + net->cc_mod.rtcc.last_step_state = 0; 1.1448 + } 1.1449 + if (net->cc_mod.rtcc.ret_from_eq) { 1.1450 + /* less aggressive one - reset cwnd too */ 1.1451 + uint32_t cwnd_in_mtu, cwnd; 1.1452 + 1.1453 + cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); 1.1454 + if (cwnd_in_mtu == 0) { 1.1455 + /* Using 0 means that the value of RFC 4960 is used. */ 1.1456 + cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); 1.1457 + } else { 1.1458 + /* 1.1459 + * We take the minimum of the burst limit and the 1.1460 + * initial congestion window. 1.1461 + */ 1.1462 + if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst)) 1.1463 + cwnd_in_mtu = stcb->asoc.max_burst; 1.1464 + cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; 1.1465 + } 1.1466 + if (net->cwnd > cwnd) { 1.1467 + /* Only set if we are not a timeout (i.e. down to 1 mtu) */ 1.1468 + net->cwnd = cwnd; 1.1469 + } 1.1470 + } 1.1471 + } 1.1472 +} 1.1473 + 1.1474 +static void 1.1475 +sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb, 1.1476 + struct sctp_nets *net) 1.1477 +{ 1.1478 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1479 + uint64_t vtag, probepoint; 1.1480 + 1.1481 +#endif 1.1482 + sctp_set_initial_cc_param(stcb, net); 1.1483 + stcb->asoc.use_precise_time = 1; 1.1484 +#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 1.1485 + probepoint = (((uint64_t)net->cwnd) << 32); 1.1486 + probepoint |= ((9 << 16) | 0); 1.1487 + vtag = (net->rtt << 32) | 1.1488 + (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | 1.1489 + (stcb->rport); 1.1490 + SDT_PROBE(sctp, cwnd, net, rttvar, 1.1491 + vtag, 1.1492 + 0, 1.1493 + 0, 1.1494 + 0, 1.1495 + probepoint); 1.1496 +#endif 1.1497 + net->cc_mod.rtcc.lbw_rtt = 0; 1.1498 + net->cc_mod.rtcc.cwnd_at_bw_set = 0; 1.1499 + net->cc_mod.rtcc.vol_reduce = 0; 1.1500 + net->cc_mod.rtcc.lbw = 0; 1.1501 + net->cc_mod.rtcc.vol_reduce = 0; 1.1502 + net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; 1.1503 + net->cc_mod.rtcc.bw_tot_time = 0; 1.1504 + net->cc_mod.rtcc.bw_bytes = 0; 1.1505 + net->cc_mod.rtcc.tls_needs_set = 0; 1.1506 + net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret); 1.1507 + net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step); 1.1508 + net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn); 1.1509 + net->cc_mod.rtcc.step_cnt = 0; 1.1510 + net->cc_mod.rtcc.last_step_state = 0; 1.1511 + 1.1512 + 1.1513 +} 1.1514 + 1.1515 +static int 1.1516 +sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget, 1.1517 + struct sctp_cc_option *cc_opt) 1.1518 +{ 1.1519 + struct sctp_nets *net; 1.1520 + if (setorget == 1) { 1.1521 + /* a set */ 1.1522 + if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { 1.1523 + if ((cc_opt->aid_value.assoc_value != 0) && 1.1524 + (cc_opt->aid_value.assoc_value != 1)) { 1.1525 + return (EINVAL); 1.1526 + } 1.1527 + TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1.1528 + net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value; 1.1529 + } 1.1530 + } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { 1.1531 + if ((cc_opt->aid_value.assoc_value != 0) && 1.1532 + (cc_opt->aid_value.assoc_value != 1)) { 1.1533 + return (EINVAL); 1.1534 + } 1.1535 + TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1.1536 + net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value; 1.1537 + } 1.1538 + } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { 1.1539 + TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1.1540 + net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value; 1.1541 + } 1.1542 + } else { 1.1543 + return (EINVAL); 1.1544 + } 1.1545 + } else { 1.1546 + /* a get */ 1.1547 + if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { 1.1548 + net = TAILQ_FIRST(&stcb->asoc.nets); 1.1549 + if (net == NULL) { 1.1550 + return (EFAULT); 1.1551 + } 1.1552 + cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq; 1.1553 + } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { 1.1554 + net = TAILQ_FIRST(&stcb->asoc.nets); 1.1555 + if (net == NULL) { 1.1556 + return (EFAULT); 1.1557 + } 1.1558 + cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn; 1.1559 + } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { 1.1560 + net = TAILQ_FIRST(&stcb->asoc.nets); 1.1561 + if (net == NULL) { 1.1562 + return (EFAULT); 1.1563 + } 1.1564 + cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step; 1.1565 + } else { 1.1566 + return (EINVAL); 1.1567 + } 1.1568 + } 1.1569 + return (0); 1.1570 +} 1.1571 + 1.1572 +static void 1.1573 +sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED, 1.1574 + struct sctp_nets *net) 1.1575 +{ 1.1576 + if (net->cc_mod.rtcc.tls_needs_set == 0) { 1.1577 + SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls); 1.1578 + net->cc_mod.rtcc.tls_needs_set = 2; 1.1579 + } 1.1580 +} 1.1581 + 1.1582 +static void 1.1583 +sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb, 1.1584 + struct sctp_association *asoc, 1.1585 + int accum_moved, int reneged_all, int will_exit) 1.1586 +{ 1.1587 + /* Passing a one argument at the last enables the rtcc algoritm */ 1.1588 + sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1); 1.1589 +} 1.1590 + 1.1591 +static void 1.1592 +sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED, 1.1593 + struct sctp_nets *net, 1.1594 + struct timeval *now SCTP_UNUSED) 1.1595 +{ 1.1596 + net->cc_mod.rtcc.rtt_set_this_sack = 1; 1.1597 +} 1.1598 + 1.1599 +/* Here starts Sally Floyds HS-TCP */ 1.1600 + 1.1601 +struct sctp_hs_raise_drop { 1.1602 + int32_t cwnd; 1.1603 + int32_t increase; 1.1604 + int32_t drop_percent; 1.1605 +}; 1.1606 + 1.1607 +#define SCTP_HS_TABLE_SIZE 73 1.1608 + 1.1609 +struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = { 1.1610 + {38, 1, 50}, /* 0 */ 1.1611 + {118, 2, 44}, /* 1 */ 1.1612 + {221, 3, 41}, /* 2 */ 1.1613 + {347, 4, 38}, /* 3 */ 1.1614 + {495, 5, 37}, /* 4 */ 1.1615 + {663, 6, 35}, /* 5 */ 1.1616 + {851, 7, 34}, /* 6 */ 1.1617 + {1058, 8, 33}, /* 7 */ 1.1618 + {1284, 9, 32}, /* 8 */ 1.1619 + {1529, 10, 31}, /* 9 */ 1.1620 + {1793, 11, 30}, /* 10 */ 1.1621 + {2076, 12, 29}, /* 11 */ 1.1622 + {2378, 13, 28}, /* 12 */ 1.1623 + {2699, 14, 28}, /* 13 */ 1.1624 + {3039, 15, 27}, /* 14 */ 1.1625 + {3399, 16, 27}, /* 15 */ 1.1626 + {3778, 17, 26}, /* 16 */ 1.1627 + {4177, 18, 26}, /* 17 */ 1.1628 + {4596, 19, 25}, /* 18 */ 1.1629 + {5036, 20, 25}, /* 19 */ 1.1630 + {5497, 21, 24}, /* 20 */ 1.1631 + {5979, 22, 24}, /* 21 */ 1.1632 + {6483, 23, 23}, /* 22 */ 1.1633 + {7009, 24, 23}, /* 23 */ 1.1634 + {7558, 25, 22}, /* 24 */ 1.1635 + {8130, 26, 22}, /* 25 */ 1.1636 + {8726, 27, 22}, /* 26 */ 1.1637 + {9346, 28, 21}, /* 27 */ 1.1638 + {9991, 29, 21}, /* 28 */ 1.1639 + {10661, 30, 21}, /* 29 */ 1.1640 + {11358, 31, 20}, /* 30 */ 1.1641 + {12082, 32, 20}, /* 31 */ 1.1642 + {12834, 33, 20}, /* 32 */ 1.1643 + {13614, 34, 19}, /* 33 */ 1.1644 + {14424, 35, 19}, /* 34 */ 1.1645 + {15265, 36, 19}, /* 35 */ 1.1646 + {16137, 37, 19}, /* 36 */ 1.1647 + {17042, 38, 18}, /* 37 */ 1.1648 + {17981, 39, 18}, /* 38 */ 1.1649 + {18955, 40, 18}, /* 39 */ 1.1650 + {19965, 41, 17}, /* 40 */ 1.1651 + {21013, 42, 17}, /* 41 */ 1.1652 + {22101, 43, 17}, /* 42 */ 1.1653 + {23230, 44, 17}, /* 43 */ 1.1654 + {24402, 45, 16}, /* 44 */ 1.1655 + {25618, 46, 16}, /* 45 */ 1.1656 + {26881, 47, 16}, /* 46 */ 1.1657 + {28193, 48, 16}, /* 47 */ 1.1658 + {29557, 49, 15}, /* 48 */ 1.1659 + {30975, 50, 15}, /* 49 */ 1.1660 + {32450, 51, 15}, /* 50 */ 1.1661 + {33986, 52, 15}, /* 51 */ 1.1662 + {35586, 53, 14}, /* 52 */ 1.1663 + {37253, 54, 14}, /* 53 */ 1.1664 + {38992, 55, 14}, /* 54 */ 1.1665 + {40808, 56, 14}, /* 55 */ 1.1666 + {42707, 57, 13}, /* 56 */ 1.1667 + {44694, 58, 13}, /* 57 */ 1.1668 + {46776, 59, 13}, /* 58 */ 1.1669 + {48961, 60, 13}, /* 59 */ 1.1670 + {51258, 61, 13}, /* 60 */ 1.1671 + {53677, 62, 12}, /* 61 */ 1.1672 + {56230, 63, 12}, /* 62 */ 1.1673 + {58932, 64, 12}, /* 63 */ 1.1674 + {61799, 65, 12}, /* 64 */ 1.1675 + {64851, 66, 11}, /* 65 */ 1.1676 + {68113, 67, 11}, /* 66 */ 1.1677 + {71617, 68, 11}, /* 67 */ 1.1678 + {75401, 69, 10}, /* 68 */ 1.1679 + {79517, 70, 10}, /* 69 */ 1.1680 + {84035, 71, 10}, /* 70 */ 1.1681 + {89053, 72, 10}, /* 71 */ 1.1682 + {94717, 73, 9} /* 72 */ 1.1683 +}; 1.1684 + 1.1685 +static void 1.1686 +sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net) 1.1687 +{ 1.1688 + int cur_val, i, indx, incr; 1.1689 + 1.1690 + cur_val = net->cwnd >> 10; 1.1691 + indx = SCTP_HS_TABLE_SIZE - 1; 1.1692 + 1.1693 + if (cur_val < sctp_cwnd_adjust[0].cwnd) { 1.1694 + /* normal mode */ 1.1695 + if (net->net_ack > net->mtu) { 1.1696 + net->cwnd += net->mtu; 1.1697 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1698 + sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS); 1.1699 + } 1.1700 + } else { 1.1701 + net->cwnd += net->net_ack; 1.1702 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1703 + sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS); 1.1704 + } 1.1705 + } 1.1706 + } else { 1.1707 + for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) { 1.1708 + if (cur_val < sctp_cwnd_adjust[i].cwnd) { 1.1709 + indx = i; 1.1710 + break; 1.1711 + } 1.1712 + } 1.1713 + net->last_hs_used = indx; 1.1714 + incr = ((sctp_cwnd_adjust[indx].increase) << 10); 1.1715 + net->cwnd += incr; 1.1716 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1717 + sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS); 1.1718 + } 1.1719 + } 1.1720 +} 1.1721 + 1.1722 +static void 1.1723 +sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net) 1.1724 +{ 1.1725 + int cur_val, i, indx; 1.1726 + int old_cwnd = net->cwnd; 1.1727 + 1.1728 + cur_val = net->cwnd >> 10; 1.1729 + if (cur_val < sctp_cwnd_adjust[0].cwnd) { 1.1730 + /* normal mode */ 1.1731 + net->ssthresh = net->cwnd / 2; 1.1732 + if (net->ssthresh < (net->mtu * 2)) { 1.1733 + net->ssthresh = 2 * net->mtu; 1.1734 + } 1.1735 + net->cwnd = net->ssthresh; 1.1736 + } else { 1.1737 + /* drop by the proper amount */ 1.1738 + net->ssthresh = net->cwnd - (int)((net->cwnd / 100) * 1.1739 + sctp_cwnd_adjust[net->last_hs_used].drop_percent); 1.1740 + net->cwnd = net->ssthresh; 1.1741 + /* now where are we */ 1.1742 + indx = net->last_hs_used; 1.1743 + cur_val = net->cwnd >> 10; 1.1744 + /* reset where we are in the table */ 1.1745 + if (cur_val < sctp_cwnd_adjust[0].cwnd) { 1.1746 + /* feel out of hs */ 1.1747 + net->last_hs_used = 0; 1.1748 + } else { 1.1749 + for (i = indx; i >= 1; i--) { 1.1750 + if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) { 1.1751 + break; 1.1752 + } 1.1753 + } 1.1754 + net->last_hs_used = indx; 1.1755 + } 1.1756 + } 1.1757 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1758 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR); 1.1759 + } 1.1760 +} 1.1761 + 1.1762 +static void 1.1763 +sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb, 1.1764 + struct sctp_association *asoc) 1.1765 +{ 1.1766 + struct sctp_nets *net; 1.1767 + /* 1.1768 + * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && 1.1769 + * (net->fast_retran_loss_recovery == 0))) 1.1770 + */ 1.1771 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.1772 + if ((asoc->fast_retran_loss_recovery == 0) || 1.1773 + (asoc->sctp_cmt_on_off > 0)) { 1.1774 + /* out of a RFC2582 Fast recovery window? */ 1.1775 + if (net->net_ack > 0) { 1.1776 + /* 1.1777 + * per section 7.2.3, are there any 1.1778 + * destinations that had a fast retransmit 1.1779 + * to them. If so what we need to do is 1.1780 + * adjust ssthresh and cwnd. 1.1781 + */ 1.1782 + struct sctp_tmit_chunk *lchk; 1.1783 + 1.1784 + sctp_hs_cwnd_decrease(stcb, net); 1.1785 + 1.1786 + lchk = TAILQ_FIRST(&asoc->send_queue); 1.1787 + 1.1788 + net->partial_bytes_acked = 0; 1.1789 + /* Turn on fast recovery window */ 1.1790 + asoc->fast_retran_loss_recovery = 1; 1.1791 + if (lchk == NULL) { 1.1792 + /* Mark end of the window */ 1.1793 + asoc->fast_recovery_tsn = asoc->sending_seq - 1; 1.1794 + } else { 1.1795 + asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.1796 + } 1.1797 + 1.1798 + /* 1.1799 + * CMT fast recovery -- per destination 1.1800 + * recovery variable. 1.1801 + */ 1.1802 + net->fast_retran_loss_recovery = 1; 1.1803 + 1.1804 + if (lchk == NULL) { 1.1805 + /* Mark end of the window */ 1.1806 + net->fast_recovery_tsn = asoc->sending_seq - 1; 1.1807 + } else { 1.1808 + net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.1809 + } 1.1810 + 1.1811 + sctp_timer_stop(SCTP_TIMER_TYPE_SEND, 1.1812 + stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); 1.1813 + sctp_timer_start(SCTP_TIMER_TYPE_SEND, 1.1814 + stcb->sctp_ep, stcb, net); 1.1815 + } 1.1816 + } else if (net->net_ack > 0) { 1.1817 + /* 1.1818 + * Mark a peg that we WOULD have done a cwnd 1.1819 + * reduction but RFC2582 prevented this action. 1.1820 + */ 1.1821 + SCTP_STAT_INCR(sctps_fastretransinrtt); 1.1822 + } 1.1823 + } 1.1824 +} 1.1825 + 1.1826 +static void 1.1827 +sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb, 1.1828 + struct sctp_association *asoc, 1.1829 + int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) 1.1830 +{ 1.1831 + struct sctp_nets *net; 1.1832 + /******************************/ 1.1833 + /* update cwnd and Early FR */ 1.1834 + /******************************/ 1.1835 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.1836 + 1.1837 +#ifdef JANA_CMT_FAST_RECOVERY 1.1838 + /* 1.1839 + * CMT fast recovery code. Need to debug. 1.1840 + */ 1.1841 + if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { 1.1842 + if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || 1.1843 + SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { 1.1844 + net->will_exit_fast_recovery = 1; 1.1845 + } 1.1846 + } 1.1847 +#endif 1.1848 + /* if nothing was acked on this destination skip it */ 1.1849 + if (net->net_ack == 0) { 1.1850 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1851 + sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); 1.1852 + } 1.1853 + continue; 1.1854 + } 1.1855 +#ifdef JANA_CMT_FAST_RECOVERY 1.1856 + /* CMT fast recovery code 1.1857 + */ 1.1858 + /* 1.1859 + if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { 1.1860 + @@@ Do something 1.1861 + } 1.1862 + else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { 1.1863 + */ 1.1864 +#endif 1.1865 + 1.1866 + if (asoc->fast_retran_loss_recovery && 1.1867 + (will_exit == 0) && 1.1868 + (asoc->sctp_cmt_on_off == 0)) { 1.1869 + /* 1.1870 + * If we are in loss recovery we skip any cwnd 1.1871 + * update 1.1872 + */ 1.1873 + return; 1.1874 + } 1.1875 + /* 1.1876 + * CMT: CUC algorithm. Update cwnd if pseudo-cumack has 1.1877 + * moved. 1.1878 + */ 1.1879 + if (accum_moved || 1.1880 + ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { 1.1881 + /* If the cumulative ack moved we can proceed */ 1.1882 + if (net->cwnd <= net->ssthresh) { 1.1883 + /* We are in slow start */ 1.1884 + if (net->flight_size + net->net_ack >= net->cwnd) { 1.1885 + 1.1886 + sctp_hs_cwnd_increase(stcb, net); 1.1887 + 1.1888 + } else { 1.1889 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1890 + sctp_log_cwnd(stcb, net, net->net_ack, 1.1891 + SCTP_CWND_LOG_NOADV_SS); 1.1892 + } 1.1893 + } 1.1894 + } else { 1.1895 + /* We are in congestion avoidance */ 1.1896 + net->partial_bytes_acked += net->net_ack; 1.1897 + if ((net->flight_size + net->net_ack >= net->cwnd) && 1.1898 + (net->partial_bytes_acked >= net->cwnd)) { 1.1899 + net->partial_bytes_acked -= net->cwnd; 1.1900 + net->cwnd += net->mtu; 1.1901 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.1902 + sctp_log_cwnd(stcb, net, net->mtu, 1.1903 + SCTP_CWND_LOG_FROM_CA); 1.1904 + } 1.1905 + } else { 1.1906 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1907 + sctp_log_cwnd(stcb, net, net->net_ack, 1.1908 + SCTP_CWND_LOG_NOADV_CA); 1.1909 + } 1.1910 + } 1.1911 + } 1.1912 + } else { 1.1913 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.1914 + sctp_log_cwnd(stcb, net, net->mtu, 1.1915 + SCTP_CWND_LOG_NO_CUMACK); 1.1916 + } 1.1917 + } 1.1918 + } 1.1919 +} 1.1920 + 1.1921 + 1.1922 +/* 1.1923 + * H-TCP congestion control. The algorithm is detailed in: 1.1924 + * R.N.Shorten, D.J.Leith: 1.1925 + * "H-TCP: TCP for high-speed and long-distance networks" 1.1926 + * Proc. PFLDnet, Argonne, 2004. 1.1927 + * http://www.hamilton.ie/net/htcp3.pdf 1.1928 + */ 1.1929 + 1.1930 + 1.1931 +static int use_rtt_scaling = 1; 1.1932 +static int use_bandwidth_switch = 1; 1.1933 + 1.1934 +static inline int 1.1935 +between(uint32_t seq1, uint32_t seq2, uint32_t seq3) 1.1936 +{ 1.1937 + return (seq3 - seq2 >= seq1 - seq2); 1.1938 +} 1.1939 + 1.1940 +static inline uint32_t 1.1941 +htcp_cong_time(struct htcp *ca) 1.1942 +{ 1.1943 + return (sctp_get_tick_count() - ca->last_cong); 1.1944 +} 1.1945 + 1.1946 +static inline uint32_t 1.1947 +htcp_ccount(struct htcp *ca) 1.1948 +{ 1.1949 + return (htcp_cong_time(ca)/ca->minRTT); 1.1950 +} 1.1951 + 1.1952 +static inline void 1.1953 +htcp_reset(struct htcp *ca) 1.1954 +{ 1.1955 + ca->undo_last_cong = ca->last_cong; 1.1956 + ca->undo_maxRTT = ca->maxRTT; 1.1957 + ca->undo_old_maxB = ca->old_maxB; 1.1958 + ca->last_cong = sctp_get_tick_count(); 1.1959 +} 1.1960 + 1.1961 +#ifdef SCTP_NOT_USED 1.1962 + 1.1963 +static uint32_t 1.1964 +htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net) 1.1965 +{ 1.1966 + net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong; 1.1967 + net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT; 1.1968 + net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB; 1.1969 + return (max(net->cwnd, ((net->ssthresh/net->mtu<<7)/net->cc_mod.htcp_ca.beta)*net->mtu)); 1.1970 +} 1.1971 + 1.1972 +#endif 1.1973 + 1.1974 +static inline void 1.1975 +measure_rtt(struct sctp_nets *net) 1.1976 +{ 1.1977 + uint32_t srtt = net->lastsa>>SCTP_RTT_SHIFT; 1.1978 + 1.1979 + /* keep track of minimum RTT seen so far, minRTT is zero at first */ 1.1980 + if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT) 1.1981 + net->cc_mod.htcp_ca.minRTT = srtt; 1.1982 + 1.1983 + /* max RTT */ 1.1984 + if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) { 1.1985 + if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT) 1.1986 + net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT; 1.1987 + if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20)) 1.1988 + net->cc_mod.htcp_ca.maxRTT = srtt; 1.1989 + } 1.1990 +} 1.1991 + 1.1992 +static void 1.1993 +measure_achieved_throughput(struct sctp_nets *net) 1.1994 +{ 1.1995 + uint32_t now = sctp_get_tick_count(); 1.1996 + 1.1997 + if (net->fast_retran_ip == 0) 1.1998 + net->cc_mod.htcp_ca.bytes_acked = net->net_ack; 1.1999 + 1.2000 + if (!use_bandwidth_switch) 1.2001 + return; 1.2002 + 1.2003 + /* achieved throughput calculations */ 1.2004 + /* JRS - not 100% sure of this statement */ 1.2005 + if (net->fast_retran_ip == 1) { 1.2006 + net->cc_mod.htcp_ca.bytecount = 0; 1.2007 + net->cc_mod.htcp_ca.lasttime = now; 1.2008 + return; 1.2009 + } 1.2010 + 1.2011 + net->cc_mod.htcp_ca.bytecount += net->net_ack; 1.2012 + if ((net->cc_mod.htcp_ca.bytecount >= net->cwnd - (((net->cc_mod.htcp_ca.alpha >> 7) ? (net->cc_mod.htcp_ca.alpha >> 7) : 1) * net->mtu)) && 1.2013 + (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) && 1.2014 + (net->cc_mod.htcp_ca.minRTT > 0)) { 1.2015 + uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount/net->mtu*hz/(now - net->cc_mod.htcp_ca.lasttime); 1.2016 + 1.2017 + if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) { 1.2018 + /* just after backoff */ 1.2019 + net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi; 1.2020 + } else { 1.2021 + net->cc_mod.htcp_ca.Bi = (3*net->cc_mod.htcp_ca.Bi + cur_Bi)/4; 1.2022 + if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB) 1.2023 + net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi; 1.2024 + if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB) 1.2025 + net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB; 1.2026 + } 1.2027 + net->cc_mod.htcp_ca.bytecount = 0; 1.2028 + net->cc_mod.htcp_ca.lasttime = now; 1.2029 + } 1.2030 +} 1.2031 + 1.2032 +static inline void 1.2033 +htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT) 1.2034 +{ 1.2035 + if (use_bandwidth_switch) { 1.2036 + uint32_t maxB = ca->maxB; 1.2037 + uint32_t old_maxB = ca->old_maxB; 1.2038 + ca->old_maxB = ca->maxB; 1.2039 + 1.2040 + if (!between(5*maxB, 4*old_maxB, 6*old_maxB)) { 1.2041 + ca->beta = BETA_MIN; 1.2042 + ca->modeswitch = 0; 1.2043 + return; 1.2044 + } 1.2045 + } 1.2046 + 1.2047 + if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) { 1.2048 + ca->beta = (minRTT<<7)/maxRTT; 1.2049 + if (ca->beta < BETA_MIN) 1.2050 + ca->beta = BETA_MIN; 1.2051 + else if (ca->beta > BETA_MAX) 1.2052 + ca->beta = BETA_MAX; 1.2053 + } else { 1.2054 + ca->beta = BETA_MIN; 1.2055 + ca->modeswitch = 1; 1.2056 + } 1.2057 +} 1.2058 + 1.2059 +static inline void 1.2060 +htcp_alpha_update(struct htcp *ca) 1.2061 +{ 1.2062 + uint32_t minRTT = ca->minRTT; 1.2063 + uint32_t factor = 1; 1.2064 + uint32_t diff = htcp_cong_time(ca); 1.2065 + 1.2066 + if (diff > (uint32_t)hz) { 1.2067 + diff -= hz; 1.2068 + factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/hz))/hz; 1.2069 + } 1.2070 + 1.2071 + if (use_rtt_scaling && minRTT) { 1.2072 + uint32_t scale = (hz<<3)/(10*minRTT); 1.2073 + scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */ 1.2074 + factor = (factor<<3)/scale; 1.2075 + if (!factor) 1.2076 + factor = 1; 1.2077 + } 1.2078 + 1.2079 + ca->alpha = 2*factor*((1<<7)-ca->beta); 1.2080 + if (!ca->alpha) 1.2081 + ca->alpha = ALPHA_BASE; 1.2082 +} 1.2083 + 1.2084 +/* After we have the rtt data to calculate beta, we'd still prefer to wait one 1.2085 + * rtt before we adjust our beta to ensure we are working from a consistent 1.2086 + * data. 1.2087 + * 1.2088 + * This function should be called when we hit a congestion event since only at 1.2089 + * that point do we really have a real sense of maxRTT (the queues en route 1.2090 + * were getting just too full now). 1.2091 + */ 1.2092 +static void 1.2093 +htcp_param_update(struct sctp_nets *net) 1.2094 +{ 1.2095 + uint32_t minRTT = net->cc_mod.htcp_ca.minRTT; 1.2096 + uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT; 1.2097 + 1.2098 + htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT); 1.2099 + htcp_alpha_update(&net->cc_mod.htcp_ca); 1.2100 + 1.2101 + /* add slowly fading memory for maxRTT to accommodate routing changes etc */ 1.2102 + if (minRTT > 0 && maxRTT > minRTT) 1.2103 + net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT-minRTT)*95)/100; 1.2104 +} 1.2105 + 1.2106 +static uint32_t 1.2107 +htcp_recalc_ssthresh(struct sctp_nets *net) 1.2108 +{ 1.2109 + htcp_param_update(net); 1.2110 + return (max(((net->cwnd/net->mtu * net->cc_mod.htcp_ca.beta) >> 7)*net->mtu, 2U*net->mtu)); 1.2111 +} 1.2112 + 1.2113 +static void 1.2114 +htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net) 1.2115 +{ 1.2116 + /*- 1.2117 + * How to handle these functions? 1.2118 + * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question. 1.2119 + * return; 1.2120 + */ 1.2121 + if (net->cwnd <= net->ssthresh) { 1.2122 + /* We are in slow start */ 1.2123 + if (net->flight_size + net->net_ack >= net->cwnd) { 1.2124 + if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) { 1.2125 + net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)); 1.2126 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2127 + sctp_log_cwnd(stcb, net, net->mtu, 1.2128 + SCTP_CWND_LOG_FROM_SS); 1.2129 + } 1.2130 + 1.2131 + } else { 1.2132 + net->cwnd += net->net_ack; 1.2133 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2134 + sctp_log_cwnd(stcb, net, net->net_ack, 1.2135 + SCTP_CWND_LOG_FROM_SS); 1.2136 + } 1.2137 + 1.2138 + } 1.2139 + } else { 1.2140 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.2141 + sctp_log_cwnd(stcb, net, net->net_ack, 1.2142 + SCTP_CWND_LOG_NOADV_SS); 1.2143 + } 1.2144 + } 1.2145 + } else { 1.2146 + measure_rtt(net); 1.2147 + 1.2148 + /* In dangerous area, increase slowly. 1.2149 + * In theory this is net->cwnd += alpha / net->cwnd 1.2150 + */ 1.2151 + /* What is snd_cwnd_cnt?? */ 1.2152 + if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) { 1.2153 + /*- 1.2154 + * Does SCTP have a cwnd clamp? 1.2155 + * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS). 1.2156 + */ 1.2157 + net->cwnd += net->mtu; 1.2158 + net->partial_bytes_acked = 0; 1.2159 + htcp_alpha_update(&net->cc_mod.htcp_ca); 1.2160 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2161 + sctp_log_cwnd(stcb, net, net->mtu, 1.2162 + SCTP_CWND_LOG_FROM_CA); 1.2163 + } 1.2164 + } else { 1.2165 + net->partial_bytes_acked += net->net_ack; 1.2166 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.2167 + sctp_log_cwnd(stcb, net, net->net_ack, 1.2168 + SCTP_CWND_LOG_NOADV_CA); 1.2169 + } 1.2170 + } 1.2171 + 1.2172 + net->cc_mod.htcp_ca.bytes_acked = net->mtu; 1.2173 + } 1.2174 +} 1.2175 + 1.2176 +#ifdef SCTP_NOT_USED 1.2177 +/* Lower bound on congestion window. */ 1.2178 +static uint32_t 1.2179 +htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net) 1.2180 +{ 1.2181 + return (net->ssthresh); 1.2182 +} 1.2183 +#endif 1.2184 + 1.2185 +static void 1.2186 +htcp_init(struct sctp_nets *net) 1.2187 +{ 1.2188 + memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp)); 1.2189 + net->cc_mod.htcp_ca.alpha = ALPHA_BASE; 1.2190 + net->cc_mod.htcp_ca.beta = BETA_MIN; 1.2191 + net->cc_mod.htcp_ca.bytes_acked = net->mtu; 1.2192 + net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count(); 1.2193 +} 1.2194 + 1.2195 +static void 1.2196 +sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) 1.2197 +{ 1.2198 + /* 1.2199 + * We take the max of the burst limit times a MTU or the 1.2200 + * INITIAL_CWND. We then limit this to 4 MTU's of sending. 1.2201 + */ 1.2202 + net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); 1.2203 + net->ssthresh = stcb->asoc.peers_rwnd; 1.2204 + htcp_init(net); 1.2205 + 1.2206 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { 1.2207 + sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); 1.2208 + } 1.2209 +} 1.2210 + 1.2211 +static void 1.2212 +sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb, 1.2213 + struct sctp_association *asoc, 1.2214 + int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) 1.2215 +{ 1.2216 + struct sctp_nets *net; 1.2217 + 1.2218 + /******************************/ 1.2219 + /* update cwnd and Early FR */ 1.2220 + /******************************/ 1.2221 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.2222 + 1.2223 +#ifdef JANA_CMT_FAST_RECOVERY 1.2224 + /* 1.2225 + * CMT fast recovery code. Need to debug. 1.2226 + */ 1.2227 + if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { 1.2228 + if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || 1.2229 + SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { 1.2230 + net->will_exit_fast_recovery = 1; 1.2231 + } 1.2232 + } 1.2233 +#endif 1.2234 + /* if nothing was acked on this destination skip it */ 1.2235 + if (net->net_ack == 0) { 1.2236 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.2237 + sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); 1.2238 + } 1.2239 + continue; 1.2240 + } 1.2241 +#ifdef JANA_CMT_FAST_RECOVERY 1.2242 + /* CMT fast recovery code 1.2243 + */ 1.2244 + /* 1.2245 + if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { 1.2246 + @@@ Do something 1.2247 + } 1.2248 + else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { 1.2249 + */ 1.2250 +#endif 1.2251 + 1.2252 + if (asoc->fast_retran_loss_recovery && 1.2253 + will_exit == 0 && 1.2254 + (asoc->sctp_cmt_on_off == 0)) { 1.2255 + /* 1.2256 + * If we are in loss recovery we skip any cwnd 1.2257 + * update 1.2258 + */ 1.2259 + return; 1.2260 + } 1.2261 + /* 1.2262 + * CMT: CUC algorithm. Update cwnd if pseudo-cumack has 1.2263 + * moved. 1.2264 + */ 1.2265 + if (accum_moved || 1.2266 + ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { 1.2267 + htcp_cong_avoid(stcb, net); 1.2268 + measure_achieved_throughput(net); 1.2269 + } else { 1.2270 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { 1.2271 + sctp_log_cwnd(stcb, net, net->mtu, 1.2272 + SCTP_CWND_LOG_NO_CUMACK); 1.2273 + } 1.2274 + } 1.2275 + } 1.2276 +} 1.2277 + 1.2278 +static void 1.2279 +sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb, 1.2280 + struct sctp_association *asoc) 1.2281 +{ 1.2282 + struct sctp_nets *net; 1.2283 + /* 1.2284 + * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && 1.2285 + * (net->fast_retran_loss_recovery == 0))) 1.2286 + */ 1.2287 + TAILQ_FOREACH(net, &asoc->nets, sctp_next) { 1.2288 + if ((asoc->fast_retran_loss_recovery == 0) || 1.2289 + (asoc->sctp_cmt_on_off > 0)) { 1.2290 + /* out of a RFC2582 Fast recovery window? */ 1.2291 + if (net->net_ack > 0) { 1.2292 + /* 1.2293 + * per section 7.2.3, are there any 1.2294 + * destinations that had a fast retransmit 1.2295 + * to them. If so what we need to do is 1.2296 + * adjust ssthresh and cwnd. 1.2297 + */ 1.2298 + struct sctp_tmit_chunk *lchk; 1.2299 + int old_cwnd = net->cwnd; 1.2300 + 1.2301 + /* JRS - reset as if state were changed */ 1.2302 + htcp_reset(&net->cc_mod.htcp_ca); 1.2303 + net->ssthresh = htcp_recalc_ssthresh(net); 1.2304 + net->cwnd = net->ssthresh; 1.2305 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2306 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), 1.2307 + SCTP_CWND_LOG_FROM_FR); 1.2308 + } 1.2309 + lchk = TAILQ_FIRST(&asoc->send_queue); 1.2310 + 1.2311 + net->partial_bytes_acked = 0; 1.2312 + /* Turn on fast recovery window */ 1.2313 + asoc->fast_retran_loss_recovery = 1; 1.2314 + if (lchk == NULL) { 1.2315 + /* Mark end of the window */ 1.2316 + asoc->fast_recovery_tsn = asoc->sending_seq - 1; 1.2317 + } else { 1.2318 + asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.2319 + } 1.2320 + 1.2321 + /* 1.2322 + * CMT fast recovery -- per destination 1.2323 + * recovery variable. 1.2324 + */ 1.2325 + net->fast_retran_loss_recovery = 1; 1.2326 + 1.2327 + if (lchk == NULL) { 1.2328 + /* Mark end of the window */ 1.2329 + net->fast_recovery_tsn = asoc->sending_seq - 1; 1.2330 + } else { 1.2331 + net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; 1.2332 + } 1.2333 + 1.2334 + sctp_timer_stop(SCTP_TIMER_TYPE_SEND, 1.2335 + stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); 1.2336 + sctp_timer_start(SCTP_TIMER_TYPE_SEND, 1.2337 + stcb->sctp_ep, stcb, net); 1.2338 + } 1.2339 + } else if (net->net_ack > 0) { 1.2340 + /* 1.2341 + * Mark a peg that we WOULD have done a cwnd 1.2342 + * reduction but RFC2582 prevented this action. 1.2343 + */ 1.2344 + SCTP_STAT_INCR(sctps_fastretransinrtt); 1.2345 + } 1.2346 + } 1.2347 +} 1.2348 + 1.2349 +static void 1.2350 +sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb, 1.2351 + struct sctp_nets *net) 1.2352 +{ 1.2353 + int old_cwnd = net->cwnd; 1.2354 + 1.2355 + /* JRS - reset as if the state were being changed to timeout */ 1.2356 + htcp_reset(&net->cc_mod.htcp_ca); 1.2357 + net->ssthresh = htcp_recalc_ssthresh(net); 1.2358 + net->cwnd = net->mtu; 1.2359 + net->partial_bytes_acked = 0; 1.2360 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2361 + sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); 1.2362 + } 1.2363 +} 1.2364 + 1.2365 +static void 1.2366 +sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, 1.2367 + struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED) 1.2368 +{ 1.2369 + int old_cwnd; 1.2370 + old_cwnd = net->cwnd; 1.2371 + 1.2372 + /* JRS - reset hctp as if state changed */ 1.2373 + if (in_window == 0) { 1.2374 + htcp_reset(&net->cc_mod.htcp_ca); 1.2375 + SCTP_STAT_INCR(sctps_ecnereducedcwnd); 1.2376 + net->ssthresh = htcp_recalc_ssthresh(net); 1.2377 + if (net->ssthresh < net->mtu) { 1.2378 + net->ssthresh = net->mtu; 1.2379 + /* here back off the timer as well, to slow us down */ 1.2380 + net->RTO <<= 1; 1.2381 + } 1.2382 + net->cwnd = net->ssthresh; 1.2383 + if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { 1.2384 + sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); 1.2385 + } 1.2386 + } 1.2387 +} 1.2388 + 1.2389 +struct sctp_cc_functions sctp_cc_functions[] = { 1.2390 +{ 1.2391 +#if defined(__Windows__) || defined(__Userspace_os_Windows) 1.2392 + sctp_set_initial_cc_param, 1.2393 + sctp_cwnd_update_after_sack, 1.2394 + sctp_cwnd_update_exit_pf_common, 1.2395 + sctp_cwnd_update_after_fr, 1.2396 + sctp_cwnd_update_after_timeout, 1.2397 + sctp_cwnd_update_after_ecn_echo, 1.2398 + sctp_cwnd_update_after_packet_dropped, 1.2399 + sctp_cwnd_update_after_output, 1.2400 +#else 1.2401 + .sctp_set_initial_cc_param = sctp_set_initial_cc_param, 1.2402 + .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack, 1.2403 + .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, 1.2404 + .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, 1.2405 + .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, 1.2406 + .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, 1.2407 + .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, 1.2408 + .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, 1.2409 +#endif 1.2410 +}, 1.2411 +{ 1.2412 +#if defined(__Windows__) || defined(__Userspace_os_Windows) 1.2413 + sctp_set_initial_cc_param, 1.2414 + sctp_hs_cwnd_update_after_sack, 1.2415 + sctp_cwnd_update_exit_pf_common, 1.2416 + sctp_hs_cwnd_update_after_fr, 1.2417 + sctp_cwnd_update_after_timeout, 1.2418 + sctp_cwnd_update_after_ecn_echo, 1.2419 + sctp_cwnd_update_after_packet_dropped, 1.2420 + sctp_cwnd_update_after_output, 1.2421 +#else 1.2422 + .sctp_set_initial_cc_param = sctp_set_initial_cc_param, 1.2423 + .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack, 1.2424 + .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, 1.2425 + .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr, 1.2426 + .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, 1.2427 + .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, 1.2428 + .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, 1.2429 + .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, 1.2430 +#endif 1.2431 +}, 1.2432 +{ 1.2433 +#if defined(__Windows__) || defined(__Userspace_os_Windows) 1.2434 + sctp_htcp_set_initial_cc_param, 1.2435 + sctp_htcp_cwnd_update_after_sack, 1.2436 + sctp_cwnd_update_exit_pf_common, 1.2437 + sctp_htcp_cwnd_update_after_fr, 1.2438 + sctp_htcp_cwnd_update_after_timeout, 1.2439 + sctp_htcp_cwnd_update_after_ecn_echo, 1.2440 + sctp_cwnd_update_after_packet_dropped, 1.2441 + sctp_cwnd_update_after_output, 1.2442 +#else 1.2443 + .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param, 1.2444 + .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack, 1.2445 + .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, 1.2446 + .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr, 1.2447 + .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout, 1.2448 + .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo, 1.2449 + .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, 1.2450 + .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, 1.2451 +#endif 1.2452 +}, 1.2453 +{ 1.2454 +#if defined(__Windows__) || defined(__Userspace_os_Windows) 1.2455 + sctp_set_rtcc_initial_cc_param, 1.2456 + sctp_cwnd_update_rtcc_after_sack, 1.2457 + sctp_cwnd_update_exit_pf_common, 1.2458 + sctp_cwnd_update_after_fr, 1.2459 + sctp_cwnd_update_after_timeout, 1.2460 + sctp_cwnd_update_rtcc_after_ecn_echo, 1.2461 + sctp_cwnd_update_after_packet_dropped, 1.2462 + sctp_cwnd_update_after_output, 1.2463 + sctp_cwnd_update_rtcc_packet_transmitted, 1.2464 + sctp_cwnd_update_rtcc_tsn_acknowledged, 1.2465 + sctp_cwnd_new_rtcc_transmission_begins, 1.2466 + sctp_cwnd_prepare_rtcc_net_for_sack, 1.2467 + sctp_cwnd_rtcc_socket_option, 1.2468 + sctp_rtt_rtcc_calculated 1.2469 +#else 1.2470 + .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param, 1.2471 + .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack, 1.2472 + .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, 1.2473 + .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, 1.2474 + .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, 1.2475 + .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo, 1.2476 + .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, 1.2477 + .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, 1.2478 + .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted, 1.2479 + .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged, 1.2480 + .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins, 1.2481 + .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack, 1.2482 + .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option, 1.2483 + .sctp_rtt_calculated = sctp_rtt_rtcc_calculated 1.2484 +#endif 1.2485 +} 1.2486 +};