michael@0: /*- michael@0: * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * a) Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * michael@0: * b) Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the distribution. michael@0: * michael@0: * c) Neither the name of Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 240158 2012-09-06 07:03:56Z tuexen $"); michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: #include michael@0: #endif michael@0: michael@0: #define SHIFT_MPTCP_MULTI_N 40 michael@0: #define SHIFT_MPTCP_MULTI_Z 16 michael@0: #define SHIFT_MPTCP_MULTI 8 michael@0: michael@0: static void michael@0: sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: struct sctp_association *assoc; michael@0: uint32_t cwnd_in_mtu; michael@0: michael@0: assoc = &stcb->asoc; michael@0: cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); michael@0: if (cwnd_in_mtu == 0) { michael@0: /* Using 0 means that the value of RFC 4960 is used. */ michael@0: net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); michael@0: } else { michael@0: /* michael@0: * We take the minimum of the burst limit and the michael@0: * initial congestion window. michael@0: */ michael@0: if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst)) michael@0: cwnd_in_mtu = assoc->max_burst; michael@0: net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; michael@0: } michael@0: if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || michael@0: (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { michael@0: /* In case of resource pooling initialize appropriately */ michael@0: net->cwnd /= assoc->numnets; michael@0: if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) { michael@0: net->cwnd = net->mtu - sizeof(struct sctphdr); michael@0: } michael@0: } michael@0: net->ssthresh = assoc->peers_rwnd; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, init, michael@0: stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, michael@0: 0, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & michael@0: (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { michael@0: sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_fr(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc) michael@0: { michael@0: struct sctp_nets *net; michael@0: uint32_t t_ssthresh, t_cwnd; michael@0: uint64_t t_ucwnd_sbw; michael@0: michael@0: /* MT FIXME: Don't compute this over and over again */ michael@0: t_ssthresh = 0; michael@0: t_cwnd = 0; michael@0: t_ucwnd_sbw = 0; michael@0: if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || michael@0: (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: t_ssthresh += net->ssthresh; michael@0: t_cwnd += net->cwnd; michael@0: if (net->lastsa > 0) { michael@0: t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa; michael@0: } michael@0: } michael@0: if (t_ucwnd_sbw == 0) { michael@0: t_ucwnd_sbw = 1; michael@0: } michael@0: } michael@0: michael@0: /*- michael@0: * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && michael@0: * (net->fast_retran_loss_recovery == 0))) michael@0: */ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: if ((asoc->fast_retran_loss_recovery == 0) || michael@0: (asoc->sctp_cmt_on_off > 0)) { michael@0: /* out of a RFC2582 Fast recovery window? */ michael@0: if (net->net_ack > 0) { michael@0: /* michael@0: * per section 7.2.3, are there any michael@0: * destinations that had a fast retransmit michael@0: * to them. If so what we need to do is michael@0: * adjust ssthresh and cwnd. michael@0: */ michael@0: struct sctp_tmit_chunk *lchk; michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || michael@0: (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { michael@0: if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) { michael@0: net->ssthresh = (uint32_t)(((uint64_t)4 * michael@0: (uint64_t)net->mtu * michael@0: (uint64_t)net->ssthresh) / michael@0: (uint64_t)t_ssthresh); michael@0: michael@0: } michael@0: if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) { michael@0: uint32_t srtt; michael@0: michael@0: srtt = net->lastsa; michael@0: /* lastsa>>3; we don't need to devide ...*/ michael@0: if (srtt == 0) { michael@0: srtt = 1; michael@0: } michael@0: /* Short Version => Equal to Contel Version MBe */ michael@0: net->ssthresh = (uint32_t) (((uint64_t)4 * michael@0: (uint64_t)net->mtu * michael@0: (uint64_t)net->cwnd) / michael@0: ((uint64_t)srtt * michael@0: t_ucwnd_sbw)); michael@0: /* INCREASE FACTOR */; michael@0: } michael@0: if ((net->cwnd > t_cwnd / 2) && michael@0: (net->ssthresh < net->cwnd - t_cwnd / 2)) { michael@0: net->ssthresh = net->cwnd - t_cwnd / 2; michael@0: } michael@0: if (net->ssthresh < net->mtu) { michael@0: net->ssthresh = net->mtu; michael@0: } michael@0: } else { michael@0: net->ssthresh = net->cwnd / 2; michael@0: if (net->ssthresh < (net->mtu * 2)) { michael@0: net->ssthresh = 2 * net->mtu; michael@0: } michael@0: } michael@0: net->cwnd = net->ssthresh; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, fr, michael@0: stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), michael@0: SCTP_CWND_LOG_FROM_FR); michael@0: } michael@0: lchk = TAILQ_FIRST(&asoc->send_queue); michael@0: michael@0: net->partial_bytes_acked = 0; michael@0: /* Turn on fast recovery window */ michael@0: asoc->fast_retran_loss_recovery = 1; michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: asoc->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: /* michael@0: * CMT fast recovery -- per destination michael@0: * recovery variable. michael@0: */ michael@0: net->fast_retran_loss_recovery = 1; michael@0: michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: net->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32 ); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net); michael@0: } michael@0: } else if (net->net_ack > 0) { michael@0: /* michael@0: * Mark a peg that we WOULD have done a cwnd michael@0: * reduction but RFC2582 prevented this action. michael@0: */ michael@0: SCTP_STAT_INCR(sctps_fastretransinrtt); michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* Defines for instantaneous bw decisions */ michael@0: #define SCTP_INST_LOOSING 1 /* Loosing to other flows */ michael@0: #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */ michael@0: #define SCTP_INST_GAINING 3 /* Gaining, step down possible */ michael@0: michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: static int michael@0: cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, michael@0: uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind) michael@0: #else michael@0: static int michael@0: cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, michael@0: uint64_t rtt_offset, uint8_t inst_ind) michael@0: #endif michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t oth, probepoint; michael@0: #endif michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: #endif michael@0: if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { michael@0: /* michael@0: * rtt increased michael@0: * we don't update bw.. so we don't michael@0: * update the rtt either. michael@0: */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 5 */ michael@0: probepoint |= ((5 << 16) | 1); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { michael@0: if (net->cc_mod.rtcc.last_step_state == 5) michael@0: net->cc_mod.rtcc.step_cnt++; michael@0: else michael@0: net->cc_mod.rtcc.step_cnt = 1; michael@0: net->cc_mod.rtcc.last_step_state = 5; michael@0: if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || michael@0: ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && michael@0: ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { michael@0: /* Try a step down */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: if (net->cwnd > (4 * net->mtu)) { michael@0: net->cwnd -= net->mtu; michael@0: net->cc_mod.rtcc.vol_reduce++; michael@0: } else { michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: } michael@0: } michael@0: return (1); michael@0: } michael@0: if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { michael@0: /* michael@0: * rtt decreased, there could be more room. michael@0: * we update both the bw and the rtt here to michael@0: * lock this in as a good step down. michael@0: */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 6 */ michael@0: probepoint |= ((6 << 16) | 0); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: if ((net->cc_mod.rtcc.last_step_state == 5) && michael@0: (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) { michael@0: /* Step down worked */ michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: return (1); michael@0: } else { michael@0: net->cc_mod.rtcc.last_step_state = 6; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: } michael@0: net->cc_mod.rtcc.lbw = nbw; michael@0: net->cc_mod.rtcc.lbw_rtt = net->rtt; michael@0: net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; michael@0: if (inst_ind == SCTP_INST_GAINING) michael@0: return (1); michael@0: else if (inst_ind == SCTP_INST_NEUTRAL) michael@0: return (1); michael@0: else michael@0: return (0); michael@0: } michael@0: /* Ok bw and rtt remained the same .. no update to any michael@0: */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 7 */ michael@0: probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { michael@0: if (net->cc_mod.rtcc.last_step_state == 5) michael@0: net->cc_mod.rtcc.step_cnt++; michael@0: else michael@0: net->cc_mod.rtcc.step_cnt = 1; michael@0: net->cc_mod.rtcc.last_step_state = 5; michael@0: if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || michael@0: ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && michael@0: ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { michael@0: /* Try a step down */ michael@0: if (net->cwnd > (4 * net->mtu)) { michael@0: net->cwnd -= net->mtu; michael@0: net->cc_mod.rtcc.vol_reduce++; michael@0: return (1); michael@0: } else { michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: } michael@0: } michael@0: if (inst_ind == SCTP_INST_GAINING) michael@0: return (1); michael@0: else if (inst_ind == SCTP_INST_NEUTRAL) michael@0: return (1); michael@0: else michael@0: return ((int)net->cc_mod.rtcc.ret_from_eq); michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: static int michael@0: cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, michael@0: uint64_t vtag, uint8_t inst_ind) michael@0: #else michael@0: static int michael@0: cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, michael@0: uint8_t inst_ind) michael@0: #endif michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t oth, probepoint; michael@0: #endif michael@0: michael@0: /* Bandwidth decreased.*/ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: #endif michael@0: if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) { michael@0: /* rtt increased */ michael@0: /* Did we add more */ michael@0: if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) && michael@0: (inst_ind != SCTP_INST_LOOSING)) { michael@0: /* We caused it maybe.. back off? */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* PROBE POINT 1 */ michael@0: probepoint |= ((1 << 16) | 1); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if (net->cc_mod.rtcc.ret_from_eq) { michael@0: /* Switch over to CA if we are less aggressive */ michael@0: net->ssthresh = net->cwnd-1; michael@0: net->partial_bytes_acked = 0; michael@0: } michael@0: return (1); michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 2 */ michael@0: probepoint |= ((2 << 16) | 0); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: /* Someone else - fight for more? */ michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: /* Did we voluntarily give up some? if so take michael@0: * one back please michael@0: */ michael@0: if ((net->cc_mod.rtcc.vol_reduce) && michael@0: (inst_ind != SCTP_INST_GAINING)) { michael@0: net->cwnd += net->mtu; michael@0: net->cc_mod.rtcc.vol_reduce--; michael@0: } michael@0: net->cc_mod.rtcc.last_step_state = 2; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: goto out_decision; michael@0: } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { michael@0: /* bw & rtt decreased */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 3 */ michael@0: probepoint |= ((3 << 16) | 0); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: if ((net->cc_mod.rtcc.vol_reduce) && michael@0: (inst_ind != SCTP_INST_GAINING)) { michael@0: net->cwnd += net->mtu; michael@0: net->cc_mod.rtcc.vol_reduce--; michael@0: } michael@0: net->cc_mod.rtcc.last_step_state = 3; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: goto out_decision; michael@0: } michael@0: /* The bw decreased but rtt stayed the same */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Probe point 4 */ michael@0: probepoint |= ((4 << 16) | 0); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: if ((net->cc_mod.rtcc.vol_reduce) && michael@0: (inst_ind != SCTP_INST_GAINING)) { michael@0: net->cwnd += net->mtu; michael@0: net->cc_mod.rtcc.vol_reduce--; michael@0: } michael@0: net->cc_mod.rtcc.last_step_state = 4; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: } michael@0: out_decision: michael@0: net->cc_mod.rtcc.lbw = nbw; michael@0: net->cc_mod.rtcc.lbw_rtt = net->rtt; michael@0: net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; michael@0: if (inst_ind == SCTP_INST_GAINING) { michael@0: return (1); michael@0: } else { michael@0: return (0); michael@0: } michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: static int michael@0: cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag) michael@0: #else michael@0: static int michael@0: cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw) michael@0: #endif michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t oth, probepoint; michael@0: michael@0: #endif michael@0: /* BW increased, so update and michael@0: * return 0, since all actions in michael@0: * our table say to do the normal CC michael@0: * update. Note that we pay no attention to michael@0: * the inst_ind since our overall sum is increasing. michael@0: */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* PROBE POINT 0 */ michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: oth = net->cc_mod.rtcc.vol_reduce; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.step_cnt; michael@0: oth <<= 16; michael@0: oth |= net->cc_mod.rtcc.last_step_state; michael@0: SDT_PROBE(sctp, cwnd, net, rttstep, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | nbw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: oth, michael@0: probepoint); michael@0: #endif michael@0: net->cc_mod.rtcc.last_step_state = 0; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: net->cc_mod.rtcc.vol_reduce = 0; michael@0: } michael@0: net->cc_mod.rtcc.lbw = nbw; michael@0: net->cc_mod.rtcc.lbw_rtt = net->rtt; michael@0: net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; michael@0: return (0); michael@0: } michael@0: michael@0: /* RTCC Algoritm to limit growth of cwnd, return michael@0: * true if you want to NOT allow cwnd growth michael@0: */ michael@0: static int michael@0: cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) michael@0: { michael@0: uint64_t bw_offset, rtt_offset; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t probepoint, rtt, vtag; michael@0: #endif michael@0: uint64_t bytes_for_this_rtt, inst_bw; michael@0: uint64_t div, inst_off; michael@0: int bw_shift; michael@0: uint8_t inst_ind; michael@0: int ret; michael@0: /*- michael@0: * Here we need to see if we want michael@0: * to limit cwnd growth due to increase michael@0: * in overall rtt but no increase in bw. michael@0: * We use the following table to figure michael@0: * out what we should do. When we return michael@0: * 0, cc update goes on as planned. If we michael@0: * return 1, then no cc update happens and cwnd michael@0: * stays where it is at. michael@0: * ---------------------------------- michael@0: * BW | RTT | Action michael@0: * ********************************* michael@0: * INC | INC | return 0 michael@0: * ---------------------------------- michael@0: * INC | SAME | return 0 michael@0: * ---------------------------------- michael@0: * INC | DECR | return 0 michael@0: * ---------------------------------- michael@0: * SAME | INC | return 1 michael@0: * ---------------------------------- michael@0: * SAME | SAME | return 1 michael@0: * ---------------------------------- michael@0: * SAME | DECR | return 0 michael@0: * ---------------------------------- michael@0: * DECR | INC | return 0 or 1 based on if we caused. michael@0: * ---------------------------------- michael@0: * DECR | SAME | return 0 michael@0: * ---------------------------------- michael@0: * DECR | DECR | return 0 michael@0: * ---------------------------------- michael@0: * michael@0: * We are a bit fuzz on what an increase or michael@0: * decrease is. For BW it is the same if michael@0: * it did not change within 1/64th. For michael@0: * RTT it stayed the same if it did not michael@0: * change within 1/32nd michael@0: */ michael@0: bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw); michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: rtt = stcb->asoc.my_vtag; michael@0: vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: rtt = net->rtt; michael@0: #endif michael@0: if (net->cc_mod.rtcc.rtt_set_this_sack) { michael@0: net->cc_mod.rtcc.rtt_set_this_sack = 0; michael@0: bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc; michael@0: net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; michael@0: if (net->rtt) { michael@0: div = net->rtt / 1000; michael@0: if (div) { michael@0: inst_bw = bytes_for_this_rtt / div; michael@0: inst_off = inst_bw >> bw_shift; michael@0: if (inst_bw > nbw) michael@0: inst_ind = SCTP_INST_GAINING; michael@0: else if ((inst_bw+inst_off) < nbw) michael@0: inst_ind = SCTP_INST_LOOSING; michael@0: else michael@0: inst_ind = SCTP_INST_NEUTRAL; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: probepoint |= ((0xb << 16) | inst_ind); michael@0: #endif michael@0: } else { michael@0: inst_ind = net->cc_mod.rtcc.last_inst_ind; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt); michael@0: /* Can't determine do not change */ michael@0: probepoint |= ((0xc << 16) | inst_ind); michael@0: #endif michael@0: } michael@0: } else { michael@0: inst_ind = net->cc_mod.rtcc.last_inst_ind; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: inst_bw = bytes_for_this_rtt; michael@0: /* Can't determine do not change */ michael@0: probepoint |= ((0xd << 16) | inst_ind); michael@0: #endif michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((nbw << 32) | inst_bw), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: } else { michael@0: /* No rtt measurement, use last one */ michael@0: inst_ind = net->cc_mod.rtcc.last_inst_ind; michael@0: } michael@0: bw_offset = net->cc_mod.rtcc.lbw >> bw_shift; michael@0: if (nbw > net->cc_mod.rtcc.lbw + bw_offset) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: ret = cc_bw_increase(stcb, net, nbw, vtag); michael@0: #else michael@0: ret = cc_bw_increase(stcb, net, nbw); michael@0: #endif michael@0: goto out; michael@0: } michael@0: rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt); michael@0: if (nbw < net->cc_mod.rtcc.lbw - bw_offset) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind); michael@0: #else michael@0: ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind); michael@0: #endif michael@0: goto out; michael@0: } michael@0: /* If we reach here then michael@0: * we are in a situation where michael@0: * the bw stayed the same. michael@0: */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind); michael@0: #else michael@0: ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind); michael@0: #endif michael@0: out: michael@0: net->cc_mod.rtcc.last_inst_ind = inst_ind; michael@0: return (ret); michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc, michael@0: int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc) michael@0: { michael@0: struct sctp_nets *net; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: int old_cwnd; michael@0: #endif michael@0: uint32_t t_ssthresh, t_cwnd, incr; michael@0: uint64_t t_ucwnd_sbw; michael@0: uint64_t t_path_mptcp; michael@0: uint64_t mptcp_like_alpha; michael@0: uint32_t srtt; michael@0: uint64_t max_path; michael@0: michael@0: /* MT FIXME: Don't compute this over and over again */ michael@0: t_ssthresh = 0; michael@0: t_cwnd = 0; michael@0: t_ucwnd_sbw = 0; michael@0: t_path_mptcp = 0; michael@0: mptcp_like_alpha = 1; michael@0: if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || michael@0: (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) || michael@0: (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) { michael@0: max_path = 0; michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: t_ssthresh += net->ssthresh; michael@0: t_cwnd += net->cwnd; michael@0: /* lastsa>>3; we don't need to devide ...*/ michael@0: srtt = net->lastsa; michael@0: if (srtt > 0) { michael@0: uint64_t tmp; michael@0: michael@0: t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt; michael@0: t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) / michael@0: (((uint64_t)net->mtu) * (uint64_t)srtt); michael@0: tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) / michael@0: ((uint64_t)net->mtu * (uint64_t)(srtt * srtt)); michael@0: if (tmp > max_path) { michael@0: max_path = tmp; michael@0: } michael@0: } michael@0: } michael@0: if (t_path_mptcp > 0) { michael@0: mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp); michael@0: } else { michael@0: mptcp_like_alpha = 1; michael@0: } michael@0: } michael@0: if (t_ssthresh == 0) { michael@0: t_ssthresh = 1; michael@0: } michael@0: if (t_ucwnd_sbw == 0) { michael@0: t_ucwnd_sbw = 1; michael@0: } michael@0: /******************************/ michael@0: /* update cwnd and Early FR */ michael@0: /******************************/ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* michael@0: * CMT fast recovery code. Need to debug. michael@0: */ michael@0: if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { michael@0: if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || michael@0: SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { michael@0: net->will_exit_fast_recovery = 1; michael@0: } michael@0: } michael@0: #endif michael@0: /* if nothing was acked on this destination skip it */ michael@0: if (net->net_ack == 0) { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); michael@0: } michael@0: continue; michael@0: } michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* CMT fast recovery code michael@0: */ michael@0: /* michael@0: if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { michael@0: @@@ Do something michael@0: } michael@0: else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { michael@0: */ michael@0: #endif michael@0: michael@0: if (asoc->fast_retran_loss_recovery && michael@0: (will_exit == 0) && michael@0: (asoc->sctp_cmt_on_off == 0)) { michael@0: /* michael@0: * If we are in loss recovery we skip any cwnd michael@0: * update michael@0: */ michael@0: return; michael@0: } michael@0: /* michael@0: * Did any measurements go on for this network? michael@0: */ michael@0: if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) { michael@0: uint64_t nbw; michael@0: /* michael@0: * At this point our bw_bytes has been updated michael@0: * by incoming sack information. michael@0: * michael@0: * But our bw may not yet be set. michael@0: * michael@0: */ michael@0: if ((net->cc_mod.rtcc.new_tot_time/1000) > 0) { michael@0: nbw = net->cc_mod.rtcc.bw_bytes/(net->cc_mod.rtcc.new_tot_time/1000); michael@0: } else { michael@0: nbw = net->cc_mod.rtcc.bw_bytes; michael@0: } michael@0: if (net->cc_mod.rtcc.lbw) { michael@0: if (cc_bw_limit(stcb, net, nbw)) { michael@0: /* Hold here, no update */ michael@0: continue; michael@0: } michael@0: } else { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t vtag, probepoint; michael@0: michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: probepoint |= ((0xa << 16) | 0); michael@0: vtag = (net->rtt << 32) | michael@0: (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | michael@0: (stcb->rport); michael@0: michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: nbw, michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: net->cc_mod.rtcc.lbw = nbw; michael@0: net->cc_mod.rtcc.lbw_rtt = net->rtt; michael@0: if (net->cc_mod.rtcc.rtt_set_this_sack) { michael@0: net->cc_mod.rtcc.rtt_set_this_sack = 0; michael@0: net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; michael@0: } michael@0: } michael@0: } michael@0: /* michael@0: * CMT: CUC algorithm. Update cwnd if pseudo-cumack has michael@0: * moved. michael@0: */ michael@0: if (accum_moved || michael@0: ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { michael@0: /* If the cumulative ack moved we can proceed */ michael@0: if (net->cwnd <= net->ssthresh) { michael@0: /* We are in slow start */ michael@0: if (net->flight_size + net->net_ack >= net->cwnd) { michael@0: uint32_t limit; michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: old_cwnd = net->cwnd; michael@0: #endif michael@0: switch (asoc->sctp_cmt_on_off) { michael@0: case SCTP_CMT_RPV1: michael@0: limit = (uint32_t)(((uint64_t)net->mtu * michael@0: (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * michael@0: (uint64_t)net->ssthresh) / michael@0: (uint64_t)t_ssthresh); michael@0: incr = (uint32_t)(((uint64_t)net->net_ack * michael@0: (uint64_t)net->ssthresh) / michael@0: (uint64_t)t_ssthresh); michael@0: if (incr > limit) { michael@0: incr = limit; michael@0: } michael@0: if (incr == 0) { michael@0: incr = 1; michael@0: } michael@0: break; michael@0: case SCTP_CMT_RPV2: michael@0: /* lastsa>>3; we don't need to divide ...*/ michael@0: srtt = net->lastsa; michael@0: if (srtt == 0) { michael@0: srtt = 1; michael@0: } michael@0: limit = (uint32_t)(((uint64_t)net->mtu * michael@0: (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * michael@0: (uint64_t)net->cwnd) / michael@0: ((uint64_t)srtt * t_ucwnd_sbw)); michael@0: /* INCREASE FACTOR */ michael@0: incr = (uint32_t)(((uint64_t)net->net_ack * michael@0: (uint64_t)net->cwnd) / michael@0: ((uint64_t)srtt * t_ucwnd_sbw)); michael@0: /* INCREASE FACTOR */ michael@0: if (incr > limit) { michael@0: incr = limit; michael@0: } michael@0: if (incr == 0) { michael@0: incr = 1; michael@0: } michael@0: break; michael@0: case SCTP_CMT_MPTCP: michael@0: limit = (uint32_t)(((uint64_t)net->mtu * michael@0: mptcp_like_alpha * michael@0: (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >> michael@0: SHIFT_MPTCP_MULTI); michael@0: incr = (uint32_t)(((uint64_t)net->net_ack * michael@0: mptcp_like_alpha) >> michael@0: SHIFT_MPTCP_MULTI); michael@0: if (incr > limit) { michael@0: incr = limit; michael@0: } michael@0: if (incr > net->net_ack) { michael@0: incr = net->net_ack; michael@0: } michael@0: if (incr > net->mtu) { michael@0: incr = net->mtu; michael@0: } michael@0: break; michael@0: default: michael@0: incr = net->net_ack; michael@0: if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) { michael@0: incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable); michael@0: } michael@0: break; michael@0: } michael@0: net->cwnd += incr; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, incr, michael@0: SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, ack, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_SS); michael@0: } michael@0: } michael@0: } else { michael@0: /* We are in congestion avoidance */ michael@0: /* michael@0: * Add to pba michael@0: */ michael@0: net->partial_bytes_acked += net->net_ack; michael@0: michael@0: if ((net->flight_size + net->net_ack >= net->cwnd) && michael@0: (net->partial_bytes_acked >= net->cwnd)) { michael@0: net->partial_bytes_acked -= net->cwnd; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: old_cwnd = net->cwnd; michael@0: #endif michael@0: switch (asoc->sctp_cmt_on_off) { michael@0: case SCTP_CMT_RPV1: michael@0: incr = (uint32_t)(((uint64_t)net->mtu * michael@0: (uint64_t)net->ssthresh) / michael@0: (uint64_t)t_ssthresh); michael@0: if (incr == 0) { michael@0: incr = 1; michael@0: } michael@0: break; michael@0: case SCTP_CMT_RPV2: michael@0: /* lastsa>>3; we don't need to divide ... */ michael@0: srtt = net->lastsa; michael@0: if (srtt == 0) { michael@0: srtt = 1; michael@0: } michael@0: incr = (uint32_t)((uint64_t)net->mtu * michael@0: (uint64_t)net->cwnd / michael@0: ((uint64_t)srtt * michael@0: t_ucwnd_sbw)); michael@0: /* INCREASE FACTOR */ michael@0: if (incr == 0) { michael@0: incr = 1; michael@0: } michael@0: break; michael@0: case SCTP_CMT_MPTCP: michael@0: incr = (uint32_t)((mptcp_like_alpha * michael@0: (uint64_t) net->cwnd) >> michael@0: SHIFT_MPTCP_MULTI); michael@0: if (incr > net->mtu) { michael@0: incr = net->mtu; michael@0: } michael@0: break; michael@0: default: michael@0: incr = net->mtu; michael@0: break; michael@0: } michael@0: net->cwnd += incr; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, ack, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_FROM_CA); michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_CA); michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_NO_CUMACK); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: static void michael@0: sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: #else michael@0: static void michael@0: sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net) michael@0: #endif michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: int old_cwnd; michael@0: michael@0: old_cwnd = net->cwnd; michael@0: #endif michael@0: net->cwnd = net->mtu; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, ack, michael@0: stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n", michael@0: (void *)net, net->cwnd); michael@0: } michael@0: michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: int old_cwnd = net->cwnd; michael@0: uint32_t t_ssthresh, t_cwnd; michael@0: uint64_t t_ucwnd_sbw; michael@0: michael@0: /* MT FIXME: Don't compute this over and over again */ michael@0: t_ssthresh = 0; michael@0: t_cwnd = 0; michael@0: if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || michael@0: (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { michael@0: struct sctp_nets *lnet; michael@0: uint32_t srtt; michael@0: michael@0: t_ucwnd_sbw = 0; michael@0: TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) { michael@0: t_ssthresh += lnet->ssthresh; michael@0: t_cwnd += lnet->cwnd; michael@0: srtt = lnet->lastsa; michael@0: /* lastsa>>3; we don't need to divide ... */ michael@0: if (srtt > 0) { michael@0: t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt; michael@0: } michael@0: } michael@0: if (t_ssthresh < 1) { michael@0: t_ssthresh = 1; michael@0: } michael@0: if (t_ucwnd_sbw < 1) { michael@0: t_ucwnd_sbw = 1; michael@0: } michael@0: if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) { michael@0: net->ssthresh = (uint32_t)(((uint64_t)4 * michael@0: (uint64_t)net->mtu * michael@0: (uint64_t)net->ssthresh) / michael@0: (uint64_t)t_ssthresh); michael@0: } else { michael@0: uint64_t cc_delta; michael@0: michael@0: srtt = net->lastsa; michael@0: /* lastsa>>3; we don't need to divide ... */ michael@0: if (srtt == 0) { michael@0: srtt = 1; michael@0: } michael@0: cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2; michael@0: if (cc_delta < t_cwnd) { michael@0: net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta); michael@0: } else { michael@0: net->ssthresh = net->mtu; michael@0: } michael@0: } michael@0: if ((net->cwnd > t_cwnd / 2) && michael@0: (net->ssthresh < net->cwnd - t_cwnd / 2)) { michael@0: net->ssthresh = net->cwnd - t_cwnd / 2; michael@0: } michael@0: if (net->ssthresh < net->mtu) { michael@0: net->ssthresh = net->mtu; michael@0: } michael@0: } else { michael@0: net->ssthresh = max(net->cwnd / 2, 4 * net->mtu); michael@0: } michael@0: net->cwnd = net->mtu; michael@0: net->partial_bytes_acked = 0; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, to, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net, michael@0: int in_window, int num_pkt_lost, int use_rtcc) michael@0: { michael@0: int old_cwnd = net->cwnd; michael@0: if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) { michael@0: /* Data center Congestion Control */ michael@0: if (in_window == 0) { michael@0: /* Go to CA with the cwnd at the point we sent michael@0: * the TSN that was marked with a CE. michael@0: */ michael@0: if (net->ecn_prev_cwnd < net->cwnd) { michael@0: /* Restore to prev cwnd */ michael@0: net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost); michael@0: } else { michael@0: /* Just cut in 1/2 */ michael@0: net->cwnd /= 2; michael@0: } michael@0: /* Drop to CA */ michael@0: net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu); michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); michael@0: } michael@0: } else { michael@0: /* Further tuning down required over the drastic orginal cut */ michael@0: net->ssthresh -= (net->mtu * num_pkt_lost); michael@0: net->cwnd -= (net->mtu * num_pkt_lost); michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); michael@0: } michael@0: michael@0: } michael@0: SCTP_STAT_INCR(sctps_ecnereducedcwnd); michael@0: } else { michael@0: if (in_window == 0) { michael@0: SCTP_STAT_INCR(sctps_ecnereducedcwnd); michael@0: net->ssthresh = net->cwnd / 2; michael@0: if (net->ssthresh < net->mtu) { michael@0: net->ssthresh = net->mtu; michael@0: /* here back off the timer as well, to slow us down */ michael@0: net->RTO <<= 1; michael@0: } michael@0: net->cwnd = net->ssthresh; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, ecn, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); michael@0: } michael@0: } michael@0: } michael@0: michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, struct sctp_pktdrop_chunk *cp, michael@0: uint32_t *bottle_bw, uint32_t *on_queue) michael@0: { michael@0: uint32_t bw_avail; michael@0: int rtt; michael@0: unsigned int incr; michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: /* need real RTT in msd for this calc */ michael@0: rtt = net->rtt / 1000; michael@0: /* get bottle neck bw */ michael@0: *bottle_bw = ntohl(cp->bottle_bw); michael@0: /* and whats on queue */ michael@0: *on_queue = ntohl(cp->current_onq); michael@0: /* michael@0: * adjust the on-queue if our flight is more it could be michael@0: * that the router has not yet gotten data "in-flight" to it michael@0: */ michael@0: if (*on_queue < net->flight_size) michael@0: *on_queue = net->flight_size; michael@0: /* calculate the available space */ michael@0: bw_avail = (*bottle_bw * rtt) / 1000; michael@0: if (bw_avail > *bottle_bw) { michael@0: /* michael@0: * Cap the growth to no more than the bottle neck. michael@0: * This can happen as RTT slides up due to queues. michael@0: * It also means if you have more than a 1 second michael@0: * RTT with a empty queue you will be limited to the michael@0: * bottle_bw per second no matter if other points michael@0: * have 1/2 the RTT and you could get more out... michael@0: */ michael@0: bw_avail = *bottle_bw; michael@0: } michael@0: if (*on_queue > bw_avail) { michael@0: /* michael@0: * No room for anything else don't allow anything michael@0: * else to be "added to the fire". michael@0: */ michael@0: int seg_inflight, seg_onqueue, my_portion; michael@0: net->partial_bytes_acked = 0; michael@0: michael@0: /* how much are we over queue size? */ michael@0: incr = *on_queue - bw_avail; michael@0: if (stcb->asoc.seen_a_sack_this_pkt) { michael@0: /* michael@0: * undo any cwnd adjustment that the sack michael@0: * might have made michael@0: */ michael@0: net->cwnd = net->prev_cwnd; michael@0: } michael@0: /* Now how much of that is mine? */ michael@0: seg_inflight = net->flight_size / net->mtu; michael@0: seg_onqueue = *on_queue / net->mtu; michael@0: my_portion = (incr * seg_inflight) / seg_onqueue; michael@0: michael@0: /* Have I made an adjustment already */ michael@0: if (net->cwnd > net->flight_size) { michael@0: /* michael@0: * for this flight I made an adjustment we michael@0: * need to decrease the portion by a share michael@0: * our previous adjustment. michael@0: */ michael@0: int diff_adj; michael@0: michael@0: diff_adj = net->cwnd - net->flight_size; michael@0: if (diff_adj > my_portion) michael@0: my_portion = 0; michael@0: else michael@0: my_portion -= diff_adj; michael@0: } michael@0: /* michael@0: * back down to the previous cwnd (assume we have michael@0: * had a sack before this packet). minus what ever michael@0: * portion of the overage is my fault. michael@0: */ michael@0: net->cwnd -= my_portion; michael@0: michael@0: /* we will NOT back down more than 1 MTU */ michael@0: if (net->cwnd <= net->mtu) { michael@0: net->cwnd = net->mtu; michael@0: } michael@0: /* force into CA */ michael@0: net->ssthresh = net->cwnd - 1; michael@0: } else { michael@0: /* michael@0: * Take 1/4 of the space left or max burst up .. michael@0: * whichever is less. michael@0: */ michael@0: incr = (bw_avail - *on_queue) >> 2; michael@0: if ((stcb->asoc.max_burst > 0) && michael@0: (stcb->asoc.max_burst * net->mtu < incr)) { michael@0: incr = stcb->asoc.max_burst * net->mtu; michael@0: } michael@0: net->cwnd += incr; michael@0: } michael@0: if (net->cwnd > bw_avail) { michael@0: /* We can't exceed the pipe size */ michael@0: net->cwnd = bw_avail; michael@0: } michael@0: if (net->cwnd < net->mtu) { michael@0: /* We always have 1 MTU */ michael@0: net->cwnd = net->mtu; michael@0: } michael@0: michael@0: if (net->cwnd - old_cwnd != 0) { michael@0: /* log only changes */ michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, pd, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), michael@0: SCTP_CWND_LOG_FROM_SAT); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_output(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, int burst_limit) michael@0: { michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: if (net->ssthresh < net->cwnd) michael@0: net->ssthresh = net->cwnd; michael@0: if (burst_limit) { michael@0: net->cwnd = (net->flight_size + (burst_limit * net->mtu)); michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: SDT_PROBE(sctp, cwnd, net, bl, michael@0: stcb->asoc.my_vtag, michael@0: ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), michael@0: net, michael@0: old_cwnd, net->cwnd); michael@0: #endif michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_sack(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc, michael@0: int accum_moved, int reneged_all, int will_exit) michael@0: { michael@0: /* Passing a zero argument in last disables the rtcc algoritm */ michael@0: sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0); michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, michael@0: int in_window, int num_pkt_lost) michael@0: { michael@0: /* Passing a zero argument in last disables the rtcc algoritm */ michael@0: sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0); michael@0: } michael@0: michael@0: /* Here starts the RTCCVAR type CC invented by RRS which michael@0: * is a slight mod to RFC2581. We reuse a common routine or michael@0: * two since these algoritms are so close and need to michael@0: * remain the same. michael@0: */ michael@0: static void michael@0: sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, michael@0: int in_window, int num_pkt_lost) michael@0: { michael@0: sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1); michael@0: } michael@0: michael@0: michael@0: static michael@0: void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net, michael@0: struct sctp_tmit_chunk *tp1) michael@0: { michael@0: net->cc_mod.rtcc.bw_bytes += tp1->send_size; michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED, michael@0: struct sctp_nets *net) michael@0: { michael@0: if (net->cc_mod.rtcc.tls_needs_set > 0) { michael@0: /* We had a bw measurment going on */ michael@0: struct timeval ltls; michael@0: SCTP_GETPTIME_TIMEVAL(<ls); michael@0: timevalsub(<ls, &net->cc_mod.rtcc.tls); michael@0: net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec; michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t vtag, probepoint; michael@0: michael@0: #endif michael@0: if (net->cc_mod.rtcc.lbw) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: /* Clear the old bw.. we went to 0 in-flight */ michael@0: vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | michael@0: (stcb->rport); michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: /* Probe point 8 */ michael@0: probepoint |= ((8 << 16) | 0); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: ((net->cc_mod.rtcc.lbw << 32) | 0), michael@0: ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), michael@0: net->flight_size, michael@0: probepoint); michael@0: #endif michael@0: net->cc_mod.rtcc.lbw_rtt = 0; michael@0: net->cc_mod.rtcc.cwnd_at_bw_set = 0; michael@0: net->cc_mod.rtcc.lbw = 0; michael@0: net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; michael@0: net->cc_mod.rtcc.vol_reduce = 0; michael@0: net->cc_mod.rtcc.bw_tot_time = 0; michael@0: net->cc_mod.rtcc.bw_bytes = 0; michael@0: net->cc_mod.rtcc.tls_needs_set = 0; michael@0: if (net->cc_mod.rtcc.steady_step) { michael@0: net->cc_mod.rtcc.vol_reduce = 0; michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: net->cc_mod.rtcc.last_step_state = 0; michael@0: } michael@0: if (net->cc_mod.rtcc.ret_from_eq) { michael@0: /* less aggressive one - reset cwnd too */ michael@0: uint32_t cwnd_in_mtu, cwnd; michael@0: michael@0: cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); michael@0: if (cwnd_in_mtu == 0) { michael@0: /* Using 0 means that the value of RFC 4960 is used. */ michael@0: cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); michael@0: } else { michael@0: /* michael@0: * We take the minimum of the burst limit and the michael@0: * initial congestion window. michael@0: */ michael@0: if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst)) michael@0: cwnd_in_mtu = stcb->asoc.max_burst; michael@0: cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; michael@0: } michael@0: if (net->cwnd > cwnd) { michael@0: /* Only set if we are not a timeout (i.e. down to 1 mtu) */ michael@0: net->cwnd = cwnd; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: uint64_t vtag, probepoint; michael@0: michael@0: #endif michael@0: sctp_set_initial_cc_param(stcb, net); michael@0: stcb->asoc.use_precise_time = 1; michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 michael@0: probepoint = (((uint64_t)net->cwnd) << 32); michael@0: probepoint |= ((9 << 16) | 0); michael@0: vtag = (net->rtt << 32) | michael@0: (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | michael@0: (stcb->rport); michael@0: SDT_PROBE(sctp, cwnd, net, rttvar, michael@0: vtag, michael@0: 0, michael@0: 0, michael@0: 0, michael@0: probepoint); michael@0: #endif michael@0: net->cc_mod.rtcc.lbw_rtt = 0; michael@0: net->cc_mod.rtcc.cwnd_at_bw_set = 0; michael@0: net->cc_mod.rtcc.vol_reduce = 0; michael@0: net->cc_mod.rtcc.lbw = 0; michael@0: net->cc_mod.rtcc.vol_reduce = 0; michael@0: net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; michael@0: net->cc_mod.rtcc.bw_tot_time = 0; michael@0: net->cc_mod.rtcc.bw_bytes = 0; michael@0: net->cc_mod.rtcc.tls_needs_set = 0; michael@0: net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret); michael@0: net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step); michael@0: net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn); michael@0: net->cc_mod.rtcc.step_cnt = 0; michael@0: net->cc_mod.rtcc.last_step_state = 0; michael@0: michael@0: michael@0: } michael@0: michael@0: static int michael@0: sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget, michael@0: struct sctp_cc_option *cc_opt) michael@0: { michael@0: struct sctp_nets *net; michael@0: if (setorget == 1) { michael@0: /* a set */ michael@0: if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { michael@0: if ((cc_opt->aid_value.assoc_value != 0) && michael@0: (cc_opt->aid_value.assoc_value != 1)) { michael@0: return (EINVAL); michael@0: } michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value; michael@0: } michael@0: } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { michael@0: if ((cc_opt->aid_value.assoc_value != 0) && michael@0: (cc_opt->aid_value.assoc_value != 1)) { michael@0: return (EINVAL); michael@0: } michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value; michael@0: } michael@0: } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value; michael@0: } michael@0: } else { michael@0: return (EINVAL); michael@0: } michael@0: } else { michael@0: /* a get */ michael@0: if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { michael@0: net = TAILQ_FIRST(&stcb->asoc.nets); michael@0: if (net == NULL) { michael@0: return (EFAULT); michael@0: } michael@0: cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq; michael@0: } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { michael@0: net = TAILQ_FIRST(&stcb->asoc.nets); michael@0: if (net == NULL) { michael@0: return (EFAULT); michael@0: } michael@0: cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn; michael@0: } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { michael@0: net = TAILQ_FIRST(&stcb->asoc.nets); michael@0: if (net == NULL) { michael@0: return (EFAULT); michael@0: } michael@0: cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step; michael@0: } else { michael@0: return (EINVAL); michael@0: } michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED, michael@0: struct sctp_nets *net) michael@0: { michael@0: if (net->cc_mod.rtcc.tls_needs_set == 0) { michael@0: SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls); michael@0: net->cc_mod.rtcc.tls_needs_set = 2; michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc, michael@0: int accum_moved, int reneged_all, int will_exit) michael@0: { michael@0: /* Passing a one argument at the last enables the rtcc algoritm */ michael@0: sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1); michael@0: } michael@0: michael@0: static void michael@0: sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED, michael@0: struct sctp_nets *net, michael@0: struct timeval *now SCTP_UNUSED) michael@0: { michael@0: net->cc_mod.rtcc.rtt_set_this_sack = 1; michael@0: } michael@0: michael@0: /* Here starts Sally Floyds HS-TCP */ michael@0: michael@0: struct sctp_hs_raise_drop { michael@0: int32_t cwnd; michael@0: int32_t increase; michael@0: int32_t drop_percent; michael@0: }; michael@0: michael@0: #define SCTP_HS_TABLE_SIZE 73 michael@0: michael@0: struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = { michael@0: {38, 1, 50}, /* 0 */ michael@0: {118, 2, 44}, /* 1 */ michael@0: {221, 3, 41}, /* 2 */ michael@0: {347, 4, 38}, /* 3 */ michael@0: {495, 5, 37}, /* 4 */ michael@0: {663, 6, 35}, /* 5 */ michael@0: {851, 7, 34}, /* 6 */ michael@0: {1058, 8, 33}, /* 7 */ michael@0: {1284, 9, 32}, /* 8 */ michael@0: {1529, 10, 31}, /* 9 */ michael@0: {1793, 11, 30}, /* 10 */ michael@0: {2076, 12, 29}, /* 11 */ michael@0: {2378, 13, 28}, /* 12 */ michael@0: {2699, 14, 28}, /* 13 */ michael@0: {3039, 15, 27}, /* 14 */ michael@0: {3399, 16, 27}, /* 15 */ michael@0: {3778, 17, 26}, /* 16 */ michael@0: {4177, 18, 26}, /* 17 */ michael@0: {4596, 19, 25}, /* 18 */ michael@0: {5036, 20, 25}, /* 19 */ michael@0: {5497, 21, 24}, /* 20 */ michael@0: {5979, 22, 24}, /* 21 */ michael@0: {6483, 23, 23}, /* 22 */ michael@0: {7009, 24, 23}, /* 23 */ michael@0: {7558, 25, 22}, /* 24 */ michael@0: {8130, 26, 22}, /* 25 */ michael@0: {8726, 27, 22}, /* 26 */ michael@0: {9346, 28, 21}, /* 27 */ michael@0: {9991, 29, 21}, /* 28 */ michael@0: {10661, 30, 21}, /* 29 */ michael@0: {11358, 31, 20}, /* 30 */ michael@0: {12082, 32, 20}, /* 31 */ michael@0: {12834, 33, 20}, /* 32 */ michael@0: {13614, 34, 19}, /* 33 */ michael@0: {14424, 35, 19}, /* 34 */ michael@0: {15265, 36, 19}, /* 35 */ michael@0: {16137, 37, 19}, /* 36 */ michael@0: {17042, 38, 18}, /* 37 */ michael@0: {17981, 39, 18}, /* 38 */ michael@0: {18955, 40, 18}, /* 39 */ michael@0: {19965, 41, 17}, /* 40 */ michael@0: {21013, 42, 17}, /* 41 */ michael@0: {22101, 43, 17}, /* 42 */ michael@0: {23230, 44, 17}, /* 43 */ michael@0: {24402, 45, 16}, /* 44 */ michael@0: {25618, 46, 16}, /* 45 */ michael@0: {26881, 47, 16}, /* 46 */ michael@0: {28193, 48, 16}, /* 47 */ michael@0: {29557, 49, 15}, /* 48 */ michael@0: {30975, 50, 15}, /* 49 */ michael@0: {32450, 51, 15}, /* 50 */ michael@0: {33986, 52, 15}, /* 51 */ michael@0: {35586, 53, 14}, /* 52 */ michael@0: {37253, 54, 14}, /* 53 */ michael@0: {38992, 55, 14}, /* 54 */ michael@0: {40808, 56, 14}, /* 55 */ michael@0: {42707, 57, 13}, /* 56 */ michael@0: {44694, 58, 13}, /* 57 */ michael@0: {46776, 59, 13}, /* 58 */ michael@0: {48961, 60, 13}, /* 59 */ michael@0: {51258, 61, 13}, /* 60 */ michael@0: {53677, 62, 12}, /* 61 */ michael@0: {56230, 63, 12}, /* 62 */ michael@0: {58932, 64, 12}, /* 63 */ michael@0: {61799, 65, 12}, /* 64 */ michael@0: {64851, 66, 11}, /* 65 */ michael@0: {68113, 67, 11}, /* 66 */ michael@0: {71617, 68, 11}, /* 67 */ michael@0: {75401, 69, 10}, /* 68 */ michael@0: {79517, 70, 10}, /* 69 */ michael@0: {84035, 71, 10}, /* 70 */ michael@0: {89053, 72, 10}, /* 71 */ michael@0: {94717, 73, 9} /* 72 */ michael@0: }; michael@0: michael@0: static void michael@0: sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: int cur_val, i, indx, incr; michael@0: michael@0: cur_val = net->cwnd >> 10; michael@0: indx = SCTP_HS_TABLE_SIZE - 1; michael@0: michael@0: if (cur_val < sctp_cwnd_adjust[0].cwnd) { michael@0: /* normal mode */ michael@0: if (net->net_ack > net->mtu) { michael@0: net->cwnd += net->mtu; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: } else { michael@0: net->cwnd += net->net_ack; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: } michael@0: } else { michael@0: for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) { michael@0: if (cur_val < sctp_cwnd_adjust[i].cwnd) { michael@0: indx = i; michael@0: break; michael@0: } michael@0: } michael@0: net->last_hs_used = indx; michael@0: incr = ((sctp_cwnd_adjust[indx].increase) << 10); michael@0: net->cwnd += incr; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: int cur_val, i, indx; michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: cur_val = net->cwnd >> 10; michael@0: if (cur_val < sctp_cwnd_adjust[0].cwnd) { michael@0: /* normal mode */ michael@0: net->ssthresh = net->cwnd / 2; michael@0: if (net->ssthresh < (net->mtu * 2)) { michael@0: net->ssthresh = 2 * net->mtu; michael@0: } michael@0: net->cwnd = net->ssthresh; michael@0: } else { michael@0: /* drop by the proper amount */ michael@0: net->ssthresh = net->cwnd - (int)((net->cwnd / 100) * michael@0: sctp_cwnd_adjust[net->last_hs_used].drop_percent); michael@0: net->cwnd = net->ssthresh; michael@0: /* now where are we */ michael@0: indx = net->last_hs_used; michael@0: cur_val = net->cwnd >> 10; michael@0: /* reset where we are in the table */ michael@0: if (cur_val < sctp_cwnd_adjust[0].cwnd) { michael@0: /* feel out of hs */ michael@0: net->last_hs_used = 0; michael@0: } else { michael@0: for (i = indx; i >= 1; i--) { michael@0: if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) { michael@0: break; michael@0: } michael@0: } michael@0: net->last_hs_used = indx; michael@0: } michael@0: } michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc) michael@0: { michael@0: struct sctp_nets *net; michael@0: /* michael@0: * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && michael@0: * (net->fast_retran_loss_recovery == 0))) michael@0: */ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: if ((asoc->fast_retran_loss_recovery == 0) || michael@0: (asoc->sctp_cmt_on_off > 0)) { michael@0: /* out of a RFC2582 Fast recovery window? */ michael@0: if (net->net_ack > 0) { michael@0: /* michael@0: * per section 7.2.3, are there any michael@0: * destinations that had a fast retransmit michael@0: * to them. If so what we need to do is michael@0: * adjust ssthresh and cwnd. michael@0: */ michael@0: struct sctp_tmit_chunk *lchk; michael@0: michael@0: sctp_hs_cwnd_decrease(stcb, net); michael@0: michael@0: lchk = TAILQ_FIRST(&asoc->send_queue); michael@0: michael@0: net->partial_bytes_acked = 0; michael@0: /* Turn on fast recovery window */ michael@0: asoc->fast_retran_loss_recovery = 1; michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: asoc->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: /* michael@0: * CMT fast recovery -- per destination michael@0: * recovery variable. michael@0: */ michael@0: net->fast_retran_loss_recovery = 1; michael@0: michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: net->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net); michael@0: } michael@0: } else if (net->net_ack > 0) { michael@0: /* michael@0: * Mark a peg that we WOULD have done a cwnd michael@0: * reduction but RFC2582 prevented this action. michael@0: */ michael@0: SCTP_STAT_INCR(sctps_fastretransinrtt); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc, michael@0: int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) michael@0: { michael@0: struct sctp_nets *net; michael@0: /******************************/ michael@0: /* update cwnd and Early FR */ michael@0: /******************************/ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* michael@0: * CMT fast recovery code. Need to debug. michael@0: */ michael@0: if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { michael@0: if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || michael@0: SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { michael@0: net->will_exit_fast_recovery = 1; michael@0: } michael@0: } michael@0: #endif michael@0: /* if nothing was acked on this destination skip it */ michael@0: if (net->net_ack == 0) { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); michael@0: } michael@0: continue; michael@0: } michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* CMT fast recovery code michael@0: */ michael@0: /* michael@0: if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { michael@0: @@@ Do something michael@0: } michael@0: else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { michael@0: */ michael@0: #endif michael@0: michael@0: if (asoc->fast_retran_loss_recovery && michael@0: (will_exit == 0) && michael@0: (asoc->sctp_cmt_on_off == 0)) { michael@0: /* michael@0: * If we are in loss recovery we skip any cwnd michael@0: * update michael@0: */ michael@0: return; michael@0: } michael@0: /* michael@0: * CMT: CUC algorithm. Update cwnd if pseudo-cumack has michael@0: * moved. michael@0: */ michael@0: if (accum_moved || michael@0: ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { michael@0: /* If the cumulative ack moved we can proceed */ michael@0: if (net->cwnd <= net->ssthresh) { michael@0: /* We are in slow start */ michael@0: if (net->flight_size + net->net_ack >= net->cwnd) { michael@0: michael@0: sctp_hs_cwnd_increase(stcb, net); michael@0: michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_SS); michael@0: } michael@0: } michael@0: } else { michael@0: /* We are in congestion avoidance */ michael@0: net->partial_bytes_acked += net->net_ack; michael@0: if ((net->flight_size + net->net_ack >= net->cwnd) && michael@0: (net->partial_bytes_acked >= net->cwnd)) { michael@0: net->partial_bytes_acked -= net->cwnd; michael@0: net->cwnd += net->mtu; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_FROM_CA); michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_CA); michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_NO_CUMACK); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * H-TCP congestion control. The algorithm is detailed in: michael@0: * R.N.Shorten, D.J.Leith: michael@0: * "H-TCP: TCP for high-speed and long-distance networks" michael@0: * Proc. PFLDnet, Argonne, 2004. michael@0: * http://www.hamilton.ie/net/htcp3.pdf michael@0: */ michael@0: michael@0: michael@0: static int use_rtt_scaling = 1; michael@0: static int use_bandwidth_switch = 1; michael@0: michael@0: static inline int michael@0: between(uint32_t seq1, uint32_t seq2, uint32_t seq3) michael@0: { michael@0: return (seq3 - seq2 >= seq1 - seq2); michael@0: } michael@0: michael@0: static inline uint32_t michael@0: htcp_cong_time(struct htcp *ca) michael@0: { michael@0: return (sctp_get_tick_count() - ca->last_cong); michael@0: } michael@0: michael@0: static inline uint32_t michael@0: htcp_ccount(struct htcp *ca) michael@0: { michael@0: return (htcp_cong_time(ca)/ca->minRTT); michael@0: } michael@0: michael@0: static inline void michael@0: htcp_reset(struct htcp *ca) michael@0: { michael@0: ca->undo_last_cong = ca->last_cong; michael@0: ca->undo_maxRTT = ca->maxRTT; michael@0: ca->undo_old_maxB = ca->old_maxB; michael@0: ca->last_cong = sctp_get_tick_count(); michael@0: } michael@0: michael@0: #ifdef SCTP_NOT_USED michael@0: michael@0: static uint32_t michael@0: htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong; michael@0: net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT; michael@0: net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB; michael@0: return (max(net->cwnd, ((net->ssthresh/net->mtu<<7)/net->cc_mod.htcp_ca.beta)*net->mtu)); michael@0: } michael@0: michael@0: #endif michael@0: michael@0: static inline void michael@0: measure_rtt(struct sctp_nets *net) michael@0: { michael@0: uint32_t srtt = net->lastsa>>SCTP_RTT_SHIFT; michael@0: michael@0: /* keep track of minimum RTT seen so far, minRTT is zero at first */ michael@0: if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT) michael@0: net->cc_mod.htcp_ca.minRTT = srtt; michael@0: michael@0: /* max RTT */ michael@0: if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) { michael@0: if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT) michael@0: net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT; michael@0: if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20)) michael@0: net->cc_mod.htcp_ca.maxRTT = srtt; michael@0: } michael@0: } michael@0: michael@0: static void michael@0: measure_achieved_throughput(struct sctp_nets *net) michael@0: { michael@0: uint32_t now = sctp_get_tick_count(); michael@0: michael@0: if (net->fast_retran_ip == 0) michael@0: net->cc_mod.htcp_ca.bytes_acked = net->net_ack; michael@0: michael@0: if (!use_bandwidth_switch) michael@0: return; michael@0: michael@0: /* achieved throughput calculations */ michael@0: /* JRS - not 100% sure of this statement */ michael@0: if (net->fast_retran_ip == 1) { michael@0: net->cc_mod.htcp_ca.bytecount = 0; michael@0: net->cc_mod.htcp_ca.lasttime = now; michael@0: return; michael@0: } michael@0: michael@0: net->cc_mod.htcp_ca.bytecount += net->net_ack; michael@0: 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)) && michael@0: (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) && michael@0: (net->cc_mod.htcp_ca.minRTT > 0)) { michael@0: uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount/net->mtu*hz/(now - net->cc_mod.htcp_ca.lasttime); michael@0: michael@0: if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) { michael@0: /* just after backoff */ michael@0: net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi; michael@0: } else { michael@0: net->cc_mod.htcp_ca.Bi = (3*net->cc_mod.htcp_ca.Bi + cur_Bi)/4; michael@0: if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB) michael@0: net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi; michael@0: if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB) michael@0: net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB; michael@0: } michael@0: net->cc_mod.htcp_ca.bytecount = 0; michael@0: net->cc_mod.htcp_ca.lasttime = now; michael@0: } michael@0: } michael@0: michael@0: static inline void michael@0: htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT) michael@0: { michael@0: if (use_bandwidth_switch) { michael@0: uint32_t maxB = ca->maxB; michael@0: uint32_t old_maxB = ca->old_maxB; michael@0: ca->old_maxB = ca->maxB; michael@0: michael@0: if (!between(5*maxB, 4*old_maxB, 6*old_maxB)) { michael@0: ca->beta = BETA_MIN; michael@0: ca->modeswitch = 0; michael@0: return; michael@0: } michael@0: } michael@0: michael@0: if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) { michael@0: ca->beta = (minRTT<<7)/maxRTT; michael@0: if (ca->beta < BETA_MIN) michael@0: ca->beta = BETA_MIN; michael@0: else if (ca->beta > BETA_MAX) michael@0: ca->beta = BETA_MAX; michael@0: } else { michael@0: ca->beta = BETA_MIN; michael@0: ca->modeswitch = 1; michael@0: } michael@0: } michael@0: michael@0: static inline void michael@0: htcp_alpha_update(struct htcp *ca) michael@0: { michael@0: uint32_t minRTT = ca->minRTT; michael@0: uint32_t factor = 1; michael@0: uint32_t diff = htcp_cong_time(ca); michael@0: michael@0: if (diff > (uint32_t)hz) { michael@0: diff -= hz; michael@0: factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/hz))/hz; michael@0: } michael@0: michael@0: if (use_rtt_scaling && minRTT) { michael@0: uint32_t scale = (hz<<3)/(10*minRTT); michael@0: scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */ michael@0: factor = (factor<<3)/scale; michael@0: if (!factor) michael@0: factor = 1; michael@0: } michael@0: michael@0: ca->alpha = 2*factor*((1<<7)-ca->beta); michael@0: if (!ca->alpha) michael@0: ca->alpha = ALPHA_BASE; michael@0: } michael@0: michael@0: /* After we have the rtt data to calculate beta, we'd still prefer to wait one michael@0: * rtt before we adjust our beta to ensure we are working from a consistent michael@0: * data. michael@0: * michael@0: * This function should be called when we hit a congestion event since only at michael@0: * that point do we really have a real sense of maxRTT (the queues en route michael@0: * were getting just too full now). michael@0: */ michael@0: static void michael@0: htcp_param_update(struct sctp_nets *net) michael@0: { michael@0: uint32_t minRTT = net->cc_mod.htcp_ca.minRTT; michael@0: uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT; michael@0: michael@0: htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT); michael@0: htcp_alpha_update(&net->cc_mod.htcp_ca); michael@0: michael@0: /* add slowly fading memory for maxRTT to accommodate routing changes etc */ michael@0: if (minRTT > 0 && maxRTT > minRTT) michael@0: net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT-minRTT)*95)/100; michael@0: } michael@0: michael@0: static uint32_t michael@0: htcp_recalc_ssthresh(struct sctp_nets *net) michael@0: { michael@0: htcp_param_update(net); michael@0: return (max(((net->cwnd/net->mtu * net->cc_mod.htcp_ca.beta) >> 7)*net->mtu, 2U*net->mtu)); michael@0: } michael@0: michael@0: static void michael@0: htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: /*- michael@0: * How to handle these functions? michael@0: * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question. michael@0: * return; michael@0: */ michael@0: if (net->cwnd <= net->ssthresh) { michael@0: /* We are in slow start */ michael@0: if (net->flight_size + net->net_ack >= net->cwnd) { michael@0: if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) { michael@0: net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)); michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: michael@0: } else { michael@0: net->cwnd += net->net_ack; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_FROM_SS); michael@0: } michael@0: michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_SS); michael@0: } michael@0: } michael@0: } else { michael@0: measure_rtt(net); michael@0: michael@0: /* In dangerous area, increase slowly. michael@0: * In theory this is net->cwnd += alpha / net->cwnd michael@0: */ michael@0: /* What is snd_cwnd_cnt?? */ michael@0: if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) { michael@0: /*- michael@0: * Does SCTP have a cwnd clamp? michael@0: * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS). michael@0: */ michael@0: net->cwnd += net->mtu; michael@0: net->partial_bytes_acked = 0; michael@0: htcp_alpha_update(&net->cc_mod.htcp_ca); michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_FROM_CA); michael@0: } michael@0: } else { michael@0: net->partial_bytes_acked += net->net_ack; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->net_ack, michael@0: SCTP_CWND_LOG_NOADV_CA); michael@0: } michael@0: } michael@0: michael@0: net->cc_mod.htcp_ca.bytes_acked = net->mtu; michael@0: } michael@0: } michael@0: michael@0: #ifdef SCTP_NOT_USED michael@0: /* Lower bound on congestion window. */ michael@0: static uint32_t michael@0: htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: return (net->ssthresh); michael@0: } michael@0: #endif michael@0: michael@0: static void michael@0: htcp_init(struct sctp_nets *net) michael@0: { michael@0: memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp)); michael@0: net->cc_mod.htcp_ca.alpha = ALPHA_BASE; michael@0: net->cc_mod.htcp_ca.beta = BETA_MIN; michael@0: net->cc_mod.htcp_ca.bytes_acked = net->mtu; michael@0: net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count(); michael@0: } michael@0: michael@0: static void michael@0: sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: /* michael@0: * We take the max of the burst limit times a MTU or the michael@0: * INITIAL_CWND. We then limit this to 4 MTU's of sending. michael@0: */ michael@0: net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); michael@0: net->ssthresh = stcb->asoc.peers_rwnd; michael@0: htcp_init(net); michael@0: michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { michael@0: sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc, michael@0: int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) michael@0: { michael@0: struct sctp_nets *net; michael@0: michael@0: /******************************/ michael@0: /* update cwnd and Early FR */ michael@0: /******************************/ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* michael@0: * CMT fast recovery code. Need to debug. michael@0: */ michael@0: if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { michael@0: if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || michael@0: SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { michael@0: net->will_exit_fast_recovery = 1; michael@0: } michael@0: } michael@0: #endif michael@0: /* if nothing was acked on this destination skip it */ michael@0: if (net->net_ack == 0) { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); michael@0: } michael@0: continue; michael@0: } michael@0: #ifdef JANA_CMT_FAST_RECOVERY michael@0: /* CMT fast recovery code michael@0: */ michael@0: /* michael@0: if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { michael@0: @@@ Do something michael@0: } michael@0: else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { michael@0: */ michael@0: #endif michael@0: michael@0: if (asoc->fast_retran_loss_recovery && michael@0: will_exit == 0 && michael@0: (asoc->sctp_cmt_on_off == 0)) { michael@0: /* michael@0: * If we are in loss recovery we skip any cwnd michael@0: * update michael@0: */ michael@0: return; michael@0: } michael@0: /* michael@0: * CMT: CUC algorithm. Update cwnd if pseudo-cumack has michael@0: * moved. michael@0: */ michael@0: if (accum_moved || michael@0: ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { michael@0: htcp_cong_avoid(stcb, net); michael@0: measure_achieved_throughput(net); michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->mtu, michael@0: SCTP_CWND_LOG_NO_CUMACK); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb, michael@0: struct sctp_association *asoc) michael@0: { michael@0: struct sctp_nets *net; michael@0: /* michael@0: * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && michael@0: * (net->fast_retran_loss_recovery == 0))) michael@0: */ michael@0: TAILQ_FOREACH(net, &asoc->nets, sctp_next) { michael@0: if ((asoc->fast_retran_loss_recovery == 0) || michael@0: (asoc->sctp_cmt_on_off > 0)) { michael@0: /* out of a RFC2582 Fast recovery window? */ michael@0: if (net->net_ack > 0) { michael@0: /* michael@0: * per section 7.2.3, are there any michael@0: * destinations that had a fast retransmit michael@0: * to them. If so what we need to do is michael@0: * adjust ssthresh and cwnd. michael@0: */ michael@0: struct sctp_tmit_chunk *lchk; michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: /* JRS - reset as if state were changed */ michael@0: htcp_reset(&net->cc_mod.htcp_ca); michael@0: net->ssthresh = htcp_recalc_ssthresh(net); michael@0: net->cwnd = net->ssthresh; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), michael@0: SCTP_CWND_LOG_FROM_FR); michael@0: } michael@0: lchk = TAILQ_FIRST(&asoc->send_queue); michael@0: michael@0: net->partial_bytes_acked = 0; michael@0: /* Turn on fast recovery window */ michael@0: asoc->fast_retran_loss_recovery = 1; michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: asoc->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: /* michael@0: * CMT fast recovery -- per destination michael@0: * recovery variable. michael@0: */ michael@0: net->fast_retran_loss_recovery = 1; michael@0: michael@0: if (lchk == NULL) { michael@0: /* Mark end of the window */ michael@0: net->fast_recovery_tsn = asoc->sending_seq - 1; michael@0: } else { michael@0: net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; michael@0: } michael@0: michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, michael@0: stcb->sctp_ep, stcb, net); michael@0: } michael@0: } else if (net->net_ack > 0) { michael@0: /* michael@0: * Mark a peg that we WOULD have done a cwnd michael@0: * reduction but RFC2582 prevented this action. michael@0: */ michael@0: SCTP_STAT_INCR(sctps_fastretransinrtt); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: int old_cwnd = net->cwnd; michael@0: michael@0: /* JRS - reset as if the state were being changed to timeout */ michael@0: htcp_reset(&net->cc_mod.htcp_ca); michael@0: net->ssthresh = htcp_recalc_ssthresh(net); michael@0: net->cwnd = net->mtu; michael@0: net->partial_bytes_acked = 0; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED) michael@0: { michael@0: int old_cwnd; michael@0: old_cwnd = net->cwnd; michael@0: michael@0: /* JRS - reset hctp as if state changed */ michael@0: if (in_window == 0) { michael@0: htcp_reset(&net->cc_mod.htcp_ca); michael@0: SCTP_STAT_INCR(sctps_ecnereducedcwnd); michael@0: net->ssthresh = htcp_recalc_ssthresh(net); michael@0: if (net->ssthresh < net->mtu) { michael@0: net->ssthresh = net->mtu; michael@0: /* here back off the timer as well, to slow us down */ michael@0: net->RTO <<= 1; michael@0: } michael@0: net->cwnd = net->ssthresh; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); michael@0: } michael@0: } michael@0: } michael@0: michael@0: struct sctp_cc_functions sctp_cc_functions[] = { michael@0: { michael@0: #if defined(__Windows__) || defined(__Userspace_os_Windows) michael@0: sctp_set_initial_cc_param, michael@0: sctp_cwnd_update_after_sack, michael@0: sctp_cwnd_update_exit_pf_common, michael@0: sctp_cwnd_update_after_fr, michael@0: sctp_cwnd_update_after_timeout, michael@0: sctp_cwnd_update_after_ecn_echo, michael@0: sctp_cwnd_update_after_packet_dropped, michael@0: sctp_cwnd_update_after_output, michael@0: #else michael@0: .sctp_set_initial_cc_param = sctp_set_initial_cc_param, michael@0: .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack, michael@0: .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, michael@0: .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, michael@0: .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, michael@0: .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, michael@0: .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, michael@0: .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, michael@0: #endif michael@0: }, michael@0: { michael@0: #if defined(__Windows__) || defined(__Userspace_os_Windows) michael@0: sctp_set_initial_cc_param, michael@0: sctp_hs_cwnd_update_after_sack, michael@0: sctp_cwnd_update_exit_pf_common, michael@0: sctp_hs_cwnd_update_after_fr, michael@0: sctp_cwnd_update_after_timeout, michael@0: sctp_cwnd_update_after_ecn_echo, michael@0: sctp_cwnd_update_after_packet_dropped, michael@0: sctp_cwnd_update_after_output, michael@0: #else michael@0: .sctp_set_initial_cc_param = sctp_set_initial_cc_param, michael@0: .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack, michael@0: .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, michael@0: .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr, michael@0: .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, michael@0: .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, michael@0: .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, michael@0: .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, michael@0: #endif michael@0: }, michael@0: { michael@0: #if defined(__Windows__) || defined(__Userspace_os_Windows) michael@0: sctp_htcp_set_initial_cc_param, michael@0: sctp_htcp_cwnd_update_after_sack, michael@0: sctp_cwnd_update_exit_pf_common, michael@0: sctp_htcp_cwnd_update_after_fr, michael@0: sctp_htcp_cwnd_update_after_timeout, michael@0: sctp_htcp_cwnd_update_after_ecn_echo, michael@0: sctp_cwnd_update_after_packet_dropped, michael@0: sctp_cwnd_update_after_output, michael@0: #else michael@0: .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param, michael@0: .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack, michael@0: .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, michael@0: .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr, michael@0: .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout, michael@0: .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo, michael@0: .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, michael@0: .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, michael@0: #endif michael@0: }, michael@0: { michael@0: #if defined(__Windows__) || defined(__Userspace_os_Windows) michael@0: sctp_set_rtcc_initial_cc_param, michael@0: sctp_cwnd_update_rtcc_after_sack, michael@0: sctp_cwnd_update_exit_pf_common, michael@0: sctp_cwnd_update_after_fr, michael@0: sctp_cwnd_update_after_timeout, michael@0: sctp_cwnd_update_rtcc_after_ecn_echo, michael@0: sctp_cwnd_update_after_packet_dropped, michael@0: sctp_cwnd_update_after_output, michael@0: sctp_cwnd_update_rtcc_packet_transmitted, michael@0: sctp_cwnd_update_rtcc_tsn_acknowledged, michael@0: sctp_cwnd_new_rtcc_transmission_begins, michael@0: sctp_cwnd_prepare_rtcc_net_for_sack, michael@0: sctp_cwnd_rtcc_socket_option, michael@0: sctp_rtt_rtcc_calculated michael@0: #else michael@0: .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param, michael@0: .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack, michael@0: .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, michael@0: .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, michael@0: .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, michael@0: .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo, michael@0: .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, michael@0: .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, michael@0: .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted, michael@0: .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged, michael@0: .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins, michael@0: .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack, michael@0: .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option, michael@0: .sctp_rtt_calculated = sctp_rtt_rtcc_calculated michael@0: #endif michael@0: } michael@0: };