Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /*- |
michael@0 | 2 | * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. |
michael@0 | 3 | * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. |
michael@0 | 4 | * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. |
michael@0 | 5 | * |
michael@0 | 6 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | * modification, are permitted provided that the following conditions are met: |
michael@0 | 8 | * |
michael@0 | 9 | * a) Redistributions of source code must retain the above copyright notice, |
michael@0 | 10 | * this list of conditions and the following disclaimer. |
michael@0 | 11 | * |
michael@0 | 12 | * b) Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in |
michael@0 | 14 | * the documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * c) Neither the name of Cisco Systems, Inc. nor the names of its |
michael@0 | 17 | * contributors may be used to endorse or promote products derived |
michael@0 | 18 | * from this software without specific prior written permission. |
michael@0 | 19 | * |
michael@0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
michael@0 | 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
michael@0 | 30 | * THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | #ifdef __FreeBSD__ |
michael@0 | 34 | #include <sys/cdefs.h> |
michael@0 | 35 | __FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 240158 2012-09-06 07:03:56Z tuexen $"); |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | #include <netinet/sctp_os.h> |
michael@0 | 39 | #include <netinet/sctp_var.h> |
michael@0 | 40 | #include <netinet/sctp_sysctl.h> |
michael@0 | 41 | #include <netinet/sctp_pcb.h> |
michael@0 | 42 | #include <netinet/sctp_header.h> |
michael@0 | 43 | #include <netinet/sctputil.h> |
michael@0 | 44 | #include <netinet/sctp_output.h> |
michael@0 | 45 | #include <netinet/sctp_input.h> |
michael@0 | 46 | #include <netinet/sctp_indata.h> |
michael@0 | 47 | #include <netinet/sctp_uio.h> |
michael@0 | 48 | #include <netinet/sctp_timer.h> |
michael@0 | 49 | #include <netinet/sctp_auth.h> |
michael@0 | 50 | #include <netinet/sctp_asconf.h> |
michael@0 | 51 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 52 | #include <netinet/sctp_dtrace_declare.h> |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | #define SHIFT_MPTCP_MULTI_N 40 |
michael@0 | 56 | #define SHIFT_MPTCP_MULTI_Z 16 |
michael@0 | 57 | #define SHIFT_MPTCP_MULTI 8 |
michael@0 | 58 | |
michael@0 | 59 | static void |
michael@0 | 60 | sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 61 | { |
michael@0 | 62 | struct sctp_association *assoc; |
michael@0 | 63 | uint32_t cwnd_in_mtu; |
michael@0 | 64 | |
michael@0 | 65 | assoc = &stcb->asoc; |
michael@0 | 66 | cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); |
michael@0 | 67 | if (cwnd_in_mtu == 0) { |
michael@0 | 68 | /* Using 0 means that the value of RFC 4960 is used. */ |
michael@0 | 69 | net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); |
michael@0 | 70 | } else { |
michael@0 | 71 | /* |
michael@0 | 72 | * We take the minimum of the burst limit and the |
michael@0 | 73 | * initial congestion window. |
michael@0 | 74 | */ |
michael@0 | 75 | if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst)) |
michael@0 | 76 | cwnd_in_mtu = assoc->max_burst; |
michael@0 | 77 | net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; |
michael@0 | 78 | } |
michael@0 | 79 | if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || |
michael@0 | 80 | (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { |
michael@0 | 81 | /* In case of resource pooling initialize appropriately */ |
michael@0 | 82 | net->cwnd /= assoc->numnets; |
michael@0 | 83 | if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) { |
michael@0 | 84 | net->cwnd = net->mtu - sizeof(struct sctphdr); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | net->ssthresh = assoc->peers_rwnd; |
michael@0 | 88 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 89 | SDT_PROBE(sctp, cwnd, net, init, |
michael@0 | 90 | stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, |
michael@0 | 91 | 0, net->cwnd); |
michael@0 | 92 | #endif |
michael@0 | 93 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & |
michael@0 | 94 | (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { |
michael@0 | 95 | sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | static void |
michael@0 | 100 | sctp_cwnd_update_after_fr(struct sctp_tcb *stcb, |
michael@0 | 101 | struct sctp_association *asoc) |
michael@0 | 102 | { |
michael@0 | 103 | struct sctp_nets *net; |
michael@0 | 104 | uint32_t t_ssthresh, t_cwnd; |
michael@0 | 105 | uint64_t t_ucwnd_sbw; |
michael@0 | 106 | |
michael@0 | 107 | /* MT FIXME: Don't compute this over and over again */ |
michael@0 | 108 | t_ssthresh = 0; |
michael@0 | 109 | t_cwnd = 0; |
michael@0 | 110 | t_ucwnd_sbw = 0; |
michael@0 | 111 | if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || |
michael@0 | 112 | (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { |
michael@0 | 113 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 114 | t_ssthresh += net->ssthresh; |
michael@0 | 115 | t_cwnd += net->cwnd; |
michael@0 | 116 | if (net->lastsa > 0) { |
michael@0 | 117 | t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa; |
michael@0 | 118 | } |
michael@0 | 119 | } |
michael@0 | 120 | if (t_ucwnd_sbw == 0) { |
michael@0 | 121 | t_ucwnd_sbw = 1; |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | /*- |
michael@0 | 126 | * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && |
michael@0 | 127 | * (net->fast_retran_loss_recovery == 0))) |
michael@0 | 128 | */ |
michael@0 | 129 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 130 | if ((asoc->fast_retran_loss_recovery == 0) || |
michael@0 | 131 | (asoc->sctp_cmt_on_off > 0)) { |
michael@0 | 132 | /* out of a RFC2582 Fast recovery window? */ |
michael@0 | 133 | if (net->net_ack > 0) { |
michael@0 | 134 | /* |
michael@0 | 135 | * per section 7.2.3, are there any |
michael@0 | 136 | * destinations that had a fast retransmit |
michael@0 | 137 | * to them. If so what we need to do is |
michael@0 | 138 | * adjust ssthresh and cwnd. |
michael@0 | 139 | */ |
michael@0 | 140 | struct sctp_tmit_chunk *lchk; |
michael@0 | 141 | int old_cwnd = net->cwnd; |
michael@0 | 142 | |
michael@0 | 143 | if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || |
michael@0 | 144 | (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { |
michael@0 | 145 | if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) { |
michael@0 | 146 | net->ssthresh = (uint32_t)(((uint64_t)4 * |
michael@0 | 147 | (uint64_t)net->mtu * |
michael@0 | 148 | (uint64_t)net->ssthresh) / |
michael@0 | 149 | (uint64_t)t_ssthresh); |
michael@0 | 150 | |
michael@0 | 151 | } |
michael@0 | 152 | if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) { |
michael@0 | 153 | uint32_t srtt; |
michael@0 | 154 | |
michael@0 | 155 | srtt = net->lastsa; |
michael@0 | 156 | /* lastsa>>3; we don't need to devide ...*/ |
michael@0 | 157 | if (srtt == 0) { |
michael@0 | 158 | srtt = 1; |
michael@0 | 159 | } |
michael@0 | 160 | /* Short Version => Equal to Contel Version MBe */ |
michael@0 | 161 | net->ssthresh = (uint32_t) (((uint64_t)4 * |
michael@0 | 162 | (uint64_t)net->mtu * |
michael@0 | 163 | (uint64_t)net->cwnd) / |
michael@0 | 164 | ((uint64_t)srtt * |
michael@0 | 165 | t_ucwnd_sbw)); |
michael@0 | 166 | /* INCREASE FACTOR */; |
michael@0 | 167 | } |
michael@0 | 168 | if ((net->cwnd > t_cwnd / 2) && |
michael@0 | 169 | (net->ssthresh < net->cwnd - t_cwnd / 2)) { |
michael@0 | 170 | net->ssthresh = net->cwnd - t_cwnd / 2; |
michael@0 | 171 | } |
michael@0 | 172 | if (net->ssthresh < net->mtu) { |
michael@0 | 173 | net->ssthresh = net->mtu; |
michael@0 | 174 | } |
michael@0 | 175 | } else { |
michael@0 | 176 | net->ssthresh = net->cwnd / 2; |
michael@0 | 177 | if (net->ssthresh < (net->mtu * 2)) { |
michael@0 | 178 | net->ssthresh = 2 * net->mtu; |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | net->cwnd = net->ssthresh; |
michael@0 | 182 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 183 | SDT_PROBE(sctp, cwnd, net, fr, |
michael@0 | 184 | stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, |
michael@0 | 185 | old_cwnd, net->cwnd); |
michael@0 | 186 | #endif |
michael@0 | 187 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 188 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), |
michael@0 | 189 | SCTP_CWND_LOG_FROM_FR); |
michael@0 | 190 | } |
michael@0 | 191 | lchk = TAILQ_FIRST(&asoc->send_queue); |
michael@0 | 192 | |
michael@0 | 193 | net->partial_bytes_acked = 0; |
michael@0 | 194 | /* Turn on fast recovery window */ |
michael@0 | 195 | asoc->fast_retran_loss_recovery = 1; |
michael@0 | 196 | if (lchk == NULL) { |
michael@0 | 197 | /* Mark end of the window */ |
michael@0 | 198 | asoc->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 199 | } else { |
michael@0 | 200 | asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | /* |
michael@0 | 204 | * CMT fast recovery -- per destination |
michael@0 | 205 | * recovery variable. |
michael@0 | 206 | */ |
michael@0 | 207 | net->fast_retran_loss_recovery = 1; |
michael@0 | 208 | |
michael@0 | 209 | if (lchk == NULL) { |
michael@0 | 210 | /* Mark end of the window */ |
michael@0 | 211 | net->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 212 | } else { |
michael@0 | 213 | net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, |
michael@0 | 217 | stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32 ); |
michael@0 | 218 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
michael@0 | 219 | stcb->sctp_ep, stcb, net); |
michael@0 | 220 | } |
michael@0 | 221 | } else if (net->net_ack > 0) { |
michael@0 | 222 | /* |
michael@0 | 223 | * Mark a peg that we WOULD have done a cwnd |
michael@0 | 224 | * reduction but RFC2582 prevented this action. |
michael@0 | 225 | */ |
michael@0 | 226 | SCTP_STAT_INCR(sctps_fastretransinrtt); |
michael@0 | 227 | } |
michael@0 | 228 | } |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | /* Defines for instantaneous bw decisions */ |
michael@0 | 232 | #define SCTP_INST_LOOSING 1 /* Loosing to other flows */ |
michael@0 | 233 | #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */ |
michael@0 | 234 | #define SCTP_INST_GAINING 3 /* Gaining, step down possible */ |
michael@0 | 235 | |
michael@0 | 236 | |
michael@0 | 237 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 238 | static int |
michael@0 | 239 | cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, |
michael@0 | 240 | uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind) |
michael@0 | 241 | #else |
michael@0 | 242 | static int |
michael@0 | 243 | cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, |
michael@0 | 244 | uint64_t rtt_offset, uint8_t inst_ind) |
michael@0 | 245 | #endif |
michael@0 | 246 | { |
michael@0 | 247 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 248 | uint64_t oth, probepoint; |
michael@0 | 249 | #endif |
michael@0 | 250 | |
michael@0 | 251 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 252 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 253 | #endif |
michael@0 | 254 | if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { |
michael@0 | 255 | /* |
michael@0 | 256 | * rtt increased |
michael@0 | 257 | * we don't update bw.. so we don't |
michael@0 | 258 | * update the rtt either. |
michael@0 | 259 | */ |
michael@0 | 260 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 261 | /* Probe point 5 */ |
michael@0 | 262 | probepoint |= ((5 << 16) | 1); |
michael@0 | 263 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 264 | vtag, |
michael@0 | 265 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 266 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 267 | net->flight_size, |
michael@0 | 268 | probepoint); |
michael@0 | 269 | #endif |
michael@0 | 270 | if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { |
michael@0 | 271 | if (net->cc_mod.rtcc.last_step_state == 5) |
michael@0 | 272 | net->cc_mod.rtcc.step_cnt++; |
michael@0 | 273 | else |
michael@0 | 274 | net->cc_mod.rtcc.step_cnt = 1; |
michael@0 | 275 | net->cc_mod.rtcc.last_step_state = 5; |
michael@0 | 276 | if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || |
michael@0 | 277 | ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && |
michael@0 | 278 | ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { |
michael@0 | 279 | /* Try a step down */ |
michael@0 | 280 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 281 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 282 | oth <<= 16; |
michael@0 | 283 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 284 | oth <<= 16; |
michael@0 | 285 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 286 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 287 | vtag, |
michael@0 | 288 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 289 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 290 | oth, |
michael@0 | 291 | probepoint); |
michael@0 | 292 | #endif |
michael@0 | 293 | if (net->cwnd > (4 * net->mtu)) { |
michael@0 | 294 | net->cwnd -= net->mtu; |
michael@0 | 295 | net->cc_mod.rtcc.vol_reduce++; |
michael@0 | 296 | } else { |
michael@0 | 297 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 298 | } |
michael@0 | 299 | } |
michael@0 | 300 | } |
michael@0 | 301 | return (1); |
michael@0 | 302 | } |
michael@0 | 303 | if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { |
michael@0 | 304 | /* |
michael@0 | 305 | * rtt decreased, there could be more room. |
michael@0 | 306 | * we update both the bw and the rtt here to |
michael@0 | 307 | * lock this in as a good step down. |
michael@0 | 308 | */ |
michael@0 | 309 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 310 | /* Probe point 6 */ |
michael@0 | 311 | probepoint |= ((6 << 16) | 0); |
michael@0 | 312 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 313 | vtag, |
michael@0 | 314 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 315 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 316 | net->flight_size, |
michael@0 | 317 | probepoint); |
michael@0 | 318 | #endif |
michael@0 | 319 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 320 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 321 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 322 | oth <<= 16; |
michael@0 | 323 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 324 | oth <<= 16; |
michael@0 | 325 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 326 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 327 | vtag, |
michael@0 | 328 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 329 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 330 | oth, |
michael@0 | 331 | probepoint); |
michael@0 | 332 | #endif |
michael@0 | 333 | if ((net->cc_mod.rtcc.last_step_state == 5) && |
michael@0 | 334 | (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) { |
michael@0 | 335 | /* Step down worked */ |
michael@0 | 336 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 337 | return (1); |
michael@0 | 338 | } else { |
michael@0 | 339 | net->cc_mod.rtcc.last_step_state = 6; |
michael@0 | 340 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 341 | } |
michael@0 | 342 | } |
michael@0 | 343 | net->cc_mod.rtcc.lbw = nbw; |
michael@0 | 344 | net->cc_mod.rtcc.lbw_rtt = net->rtt; |
michael@0 | 345 | net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; |
michael@0 | 346 | if (inst_ind == SCTP_INST_GAINING) |
michael@0 | 347 | return (1); |
michael@0 | 348 | else if (inst_ind == SCTP_INST_NEUTRAL) |
michael@0 | 349 | return (1); |
michael@0 | 350 | else |
michael@0 | 351 | return (0); |
michael@0 | 352 | } |
michael@0 | 353 | /* Ok bw and rtt remained the same .. no update to any |
michael@0 | 354 | */ |
michael@0 | 355 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 356 | /* Probe point 7 */ |
michael@0 | 357 | probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq); |
michael@0 | 358 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 359 | vtag, |
michael@0 | 360 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 361 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 362 | net->flight_size, |
michael@0 | 363 | probepoint); |
michael@0 | 364 | #endif |
michael@0 | 365 | if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { |
michael@0 | 366 | if (net->cc_mod.rtcc.last_step_state == 5) |
michael@0 | 367 | net->cc_mod.rtcc.step_cnt++; |
michael@0 | 368 | else |
michael@0 | 369 | net->cc_mod.rtcc.step_cnt = 1; |
michael@0 | 370 | net->cc_mod.rtcc.last_step_state = 5; |
michael@0 | 371 | if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) || |
michael@0 | 372 | ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) && |
michael@0 | 373 | ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { |
michael@0 | 374 | /* Try a step down */ |
michael@0 | 375 | if (net->cwnd > (4 * net->mtu)) { |
michael@0 | 376 | net->cwnd -= net->mtu; |
michael@0 | 377 | net->cc_mod.rtcc.vol_reduce++; |
michael@0 | 378 | return (1); |
michael@0 | 379 | } else { |
michael@0 | 380 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 381 | } |
michael@0 | 382 | } |
michael@0 | 383 | } |
michael@0 | 384 | if (inst_ind == SCTP_INST_GAINING) |
michael@0 | 385 | return (1); |
michael@0 | 386 | else if (inst_ind == SCTP_INST_NEUTRAL) |
michael@0 | 387 | return (1); |
michael@0 | 388 | else |
michael@0 | 389 | return ((int)net->cc_mod.rtcc.ret_from_eq); |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 393 | static int |
michael@0 | 394 | cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, |
michael@0 | 395 | uint64_t vtag, uint8_t inst_ind) |
michael@0 | 396 | #else |
michael@0 | 397 | static int |
michael@0 | 398 | cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, |
michael@0 | 399 | uint8_t inst_ind) |
michael@0 | 400 | #endif |
michael@0 | 401 | { |
michael@0 | 402 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 403 | uint64_t oth, probepoint; |
michael@0 | 404 | #endif |
michael@0 | 405 | |
michael@0 | 406 | /* Bandwidth decreased.*/ |
michael@0 | 407 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 408 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 409 | #endif |
michael@0 | 410 | if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) { |
michael@0 | 411 | /* rtt increased */ |
michael@0 | 412 | /* Did we add more */ |
michael@0 | 413 | if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) && |
michael@0 | 414 | (inst_ind != SCTP_INST_LOOSING)) { |
michael@0 | 415 | /* We caused it maybe.. back off? */ |
michael@0 | 416 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 417 | /* PROBE POINT 1 */ |
michael@0 | 418 | probepoint |= ((1 << 16) | 1); |
michael@0 | 419 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 420 | vtag, |
michael@0 | 421 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 422 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 423 | net->flight_size, |
michael@0 | 424 | probepoint); |
michael@0 | 425 | #endif |
michael@0 | 426 | if (net->cc_mod.rtcc.ret_from_eq) { |
michael@0 | 427 | /* Switch over to CA if we are less aggressive */ |
michael@0 | 428 | net->ssthresh = net->cwnd-1; |
michael@0 | 429 | net->partial_bytes_acked = 0; |
michael@0 | 430 | } |
michael@0 | 431 | return (1); |
michael@0 | 432 | } |
michael@0 | 433 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 434 | /* Probe point 2 */ |
michael@0 | 435 | probepoint |= ((2 << 16) | 0); |
michael@0 | 436 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 437 | vtag, |
michael@0 | 438 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 439 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 440 | net->flight_size, |
michael@0 | 441 | probepoint); |
michael@0 | 442 | #endif |
michael@0 | 443 | /* Someone else - fight for more? */ |
michael@0 | 444 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 445 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 446 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 447 | oth <<= 16; |
michael@0 | 448 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 449 | oth <<= 16; |
michael@0 | 450 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 451 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 452 | vtag, |
michael@0 | 453 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 454 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 455 | oth, |
michael@0 | 456 | probepoint); |
michael@0 | 457 | #endif |
michael@0 | 458 | /* Did we voluntarily give up some? if so take |
michael@0 | 459 | * one back please |
michael@0 | 460 | */ |
michael@0 | 461 | if ((net->cc_mod.rtcc.vol_reduce) && |
michael@0 | 462 | (inst_ind != SCTP_INST_GAINING)) { |
michael@0 | 463 | net->cwnd += net->mtu; |
michael@0 | 464 | net->cc_mod.rtcc.vol_reduce--; |
michael@0 | 465 | } |
michael@0 | 466 | net->cc_mod.rtcc.last_step_state = 2; |
michael@0 | 467 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 468 | } |
michael@0 | 469 | goto out_decision; |
michael@0 | 470 | } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { |
michael@0 | 471 | /* bw & rtt decreased */ |
michael@0 | 472 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 473 | /* Probe point 3 */ |
michael@0 | 474 | probepoint |= ((3 << 16) | 0); |
michael@0 | 475 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 476 | vtag, |
michael@0 | 477 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 478 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 479 | net->flight_size, |
michael@0 | 480 | probepoint); |
michael@0 | 481 | #endif |
michael@0 | 482 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 483 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 484 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 485 | oth <<= 16; |
michael@0 | 486 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 487 | oth <<= 16; |
michael@0 | 488 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 489 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 490 | vtag, |
michael@0 | 491 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 492 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 493 | oth, |
michael@0 | 494 | probepoint); |
michael@0 | 495 | #endif |
michael@0 | 496 | if ((net->cc_mod.rtcc.vol_reduce) && |
michael@0 | 497 | (inst_ind != SCTP_INST_GAINING)) { |
michael@0 | 498 | net->cwnd += net->mtu; |
michael@0 | 499 | net->cc_mod.rtcc.vol_reduce--; |
michael@0 | 500 | } |
michael@0 | 501 | net->cc_mod.rtcc.last_step_state = 3; |
michael@0 | 502 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 503 | } |
michael@0 | 504 | goto out_decision; |
michael@0 | 505 | } |
michael@0 | 506 | /* The bw decreased but rtt stayed the same */ |
michael@0 | 507 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 508 | /* Probe point 4 */ |
michael@0 | 509 | probepoint |= ((4 << 16) | 0); |
michael@0 | 510 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 511 | vtag, |
michael@0 | 512 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 513 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 514 | net->flight_size, |
michael@0 | 515 | probepoint); |
michael@0 | 516 | #endif |
michael@0 | 517 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 518 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 519 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 520 | oth <<= 16; |
michael@0 | 521 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 522 | oth <<= 16; |
michael@0 | 523 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 524 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 525 | vtag, |
michael@0 | 526 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 527 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 528 | oth, |
michael@0 | 529 | probepoint); |
michael@0 | 530 | #endif |
michael@0 | 531 | if ((net->cc_mod.rtcc.vol_reduce) && |
michael@0 | 532 | (inst_ind != SCTP_INST_GAINING)) { |
michael@0 | 533 | net->cwnd += net->mtu; |
michael@0 | 534 | net->cc_mod.rtcc.vol_reduce--; |
michael@0 | 535 | } |
michael@0 | 536 | net->cc_mod.rtcc.last_step_state = 4; |
michael@0 | 537 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 538 | } |
michael@0 | 539 | out_decision: |
michael@0 | 540 | net->cc_mod.rtcc.lbw = nbw; |
michael@0 | 541 | net->cc_mod.rtcc.lbw_rtt = net->rtt; |
michael@0 | 542 | net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; |
michael@0 | 543 | if (inst_ind == SCTP_INST_GAINING) { |
michael@0 | 544 | return (1); |
michael@0 | 545 | } else { |
michael@0 | 546 | return (0); |
michael@0 | 547 | } |
michael@0 | 548 | } |
michael@0 | 549 | |
michael@0 | 550 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 551 | static int |
michael@0 | 552 | cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag) |
michael@0 | 553 | #else |
michael@0 | 554 | static int |
michael@0 | 555 | cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw) |
michael@0 | 556 | #endif |
michael@0 | 557 | { |
michael@0 | 558 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 559 | uint64_t oth, probepoint; |
michael@0 | 560 | |
michael@0 | 561 | #endif |
michael@0 | 562 | /* BW increased, so update and |
michael@0 | 563 | * return 0, since all actions in |
michael@0 | 564 | * our table say to do the normal CC |
michael@0 | 565 | * update. Note that we pay no attention to |
michael@0 | 566 | * the inst_ind since our overall sum is increasing. |
michael@0 | 567 | */ |
michael@0 | 568 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 569 | /* PROBE POINT 0 */ |
michael@0 | 570 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 571 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 572 | vtag, |
michael@0 | 573 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 574 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 575 | net->flight_size, |
michael@0 | 576 | probepoint); |
michael@0 | 577 | #endif |
michael@0 | 578 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 579 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 580 | oth = net->cc_mod.rtcc.vol_reduce; |
michael@0 | 581 | oth <<= 16; |
michael@0 | 582 | oth |= net->cc_mod.rtcc.step_cnt; |
michael@0 | 583 | oth <<= 16; |
michael@0 | 584 | oth |= net->cc_mod.rtcc.last_step_state; |
michael@0 | 585 | SDT_PROBE(sctp, cwnd, net, rttstep, |
michael@0 | 586 | vtag, |
michael@0 | 587 | ((net->cc_mod.rtcc.lbw << 32) | nbw), |
michael@0 | 588 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 589 | oth, |
michael@0 | 590 | probepoint); |
michael@0 | 591 | #endif |
michael@0 | 592 | net->cc_mod.rtcc.last_step_state = 0; |
michael@0 | 593 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 594 | net->cc_mod.rtcc.vol_reduce = 0; |
michael@0 | 595 | } |
michael@0 | 596 | net->cc_mod.rtcc.lbw = nbw; |
michael@0 | 597 | net->cc_mod.rtcc.lbw_rtt = net->rtt; |
michael@0 | 598 | net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd; |
michael@0 | 599 | return (0); |
michael@0 | 600 | } |
michael@0 | 601 | |
michael@0 | 602 | /* RTCC Algoritm to limit growth of cwnd, return |
michael@0 | 603 | * true if you want to NOT allow cwnd growth |
michael@0 | 604 | */ |
michael@0 | 605 | static int |
michael@0 | 606 | cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) |
michael@0 | 607 | { |
michael@0 | 608 | uint64_t bw_offset, rtt_offset; |
michael@0 | 609 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 610 | uint64_t probepoint, rtt, vtag; |
michael@0 | 611 | #endif |
michael@0 | 612 | uint64_t bytes_for_this_rtt, inst_bw; |
michael@0 | 613 | uint64_t div, inst_off; |
michael@0 | 614 | int bw_shift; |
michael@0 | 615 | uint8_t inst_ind; |
michael@0 | 616 | int ret; |
michael@0 | 617 | /*- |
michael@0 | 618 | * Here we need to see if we want |
michael@0 | 619 | * to limit cwnd growth due to increase |
michael@0 | 620 | * in overall rtt but no increase in bw. |
michael@0 | 621 | * We use the following table to figure |
michael@0 | 622 | * out what we should do. When we return |
michael@0 | 623 | * 0, cc update goes on as planned. If we |
michael@0 | 624 | * return 1, then no cc update happens and cwnd |
michael@0 | 625 | * stays where it is at. |
michael@0 | 626 | * ---------------------------------- |
michael@0 | 627 | * BW | RTT | Action |
michael@0 | 628 | * ********************************* |
michael@0 | 629 | * INC | INC | return 0 |
michael@0 | 630 | * ---------------------------------- |
michael@0 | 631 | * INC | SAME | return 0 |
michael@0 | 632 | * ---------------------------------- |
michael@0 | 633 | * INC | DECR | return 0 |
michael@0 | 634 | * ---------------------------------- |
michael@0 | 635 | * SAME | INC | return 1 |
michael@0 | 636 | * ---------------------------------- |
michael@0 | 637 | * SAME | SAME | return 1 |
michael@0 | 638 | * ---------------------------------- |
michael@0 | 639 | * SAME | DECR | return 0 |
michael@0 | 640 | * ---------------------------------- |
michael@0 | 641 | * DECR | INC | return 0 or 1 based on if we caused. |
michael@0 | 642 | * ---------------------------------- |
michael@0 | 643 | * DECR | SAME | return 0 |
michael@0 | 644 | * ---------------------------------- |
michael@0 | 645 | * DECR | DECR | return 0 |
michael@0 | 646 | * ---------------------------------- |
michael@0 | 647 | * |
michael@0 | 648 | * We are a bit fuzz on what an increase or |
michael@0 | 649 | * decrease is. For BW it is the same if |
michael@0 | 650 | * it did not change within 1/64th. For |
michael@0 | 651 | * RTT it stayed the same if it did not |
michael@0 | 652 | * change within 1/32nd |
michael@0 | 653 | */ |
michael@0 | 654 | bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw); |
michael@0 | 655 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 656 | rtt = stcb->asoc.my_vtag; |
michael@0 | 657 | vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); |
michael@0 | 658 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 659 | rtt = net->rtt; |
michael@0 | 660 | #endif |
michael@0 | 661 | if (net->cc_mod.rtcc.rtt_set_this_sack) { |
michael@0 | 662 | net->cc_mod.rtcc.rtt_set_this_sack = 0; |
michael@0 | 663 | bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc; |
michael@0 | 664 | net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; |
michael@0 | 665 | if (net->rtt) { |
michael@0 | 666 | div = net->rtt / 1000; |
michael@0 | 667 | if (div) { |
michael@0 | 668 | inst_bw = bytes_for_this_rtt / div; |
michael@0 | 669 | inst_off = inst_bw >> bw_shift; |
michael@0 | 670 | if (inst_bw > nbw) |
michael@0 | 671 | inst_ind = SCTP_INST_GAINING; |
michael@0 | 672 | else if ((inst_bw+inst_off) < nbw) |
michael@0 | 673 | inst_ind = SCTP_INST_LOOSING; |
michael@0 | 674 | else |
michael@0 | 675 | inst_ind = SCTP_INST_NEUTRAL; |
michael@0 | 676 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 677 | probepoint |= ((0xb << 16) | inst_ind); |
michael@0 | 678 | #endif |
michael@0 | 679 | } else { |
michael@0 | 680 | inst_ind = net->cc_mod.rtcc.last_inst_ind; |
michael@0 | 681 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 682 | inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt); |
michael@0 | 683 | /* Can't determine do not change */ |
michael@0 | 684 | probepoint |= ((0xc << 16) | inst_ind); |
michael@0 | 685 | #endif |
michael@0 | 686 | } |
michael@0 | 687 | } else { |
michael@0 | 688 | inst_ind = net->cc_mod.rtcc.last_inst_ind; |
michael@0 | 689 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 690 | inst_bw = bytes_for_this_rtt; |
michael@0 | 691 | /* Can't determine do not change */ |
michael@0 | 692 | probepoint |= ((0xd << 16) | inst_ind); |
michael@0 | 693 | #endif |
michael@0 | 694 | } |
michael@0 | 695 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 696 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 697 | vtag, |
michael@0 | 698 | ((nbw << 32) | inst_bw), |
michael@0 | 699 | ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt), |
michael@0 | 700 | net->flight_size, |
michael@0 | 701 | probepoint); |
michael@0 | 702 | #endif |
michael@0 | 703 | } else { |
michael@0 | 704 | /* No rtt measurement, use last one */ |
michael@0 | 705 | inst_ind = net->cc_mod.rtcc.last_inst_ind; |
michael@0 | 706 | } |
michael@0 | 707 | bw_offset = net->cc_mod.rtcc.lbw >> bw_shift; |
michael@0 | 708 | if (nbw > net->cc_mod.rtcc.lbw + bw_offset) { |
michael@0 | 709 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 710 | ret = cc_bw_increase(stcb, net, nbw, vtag); |
michael@0 | 711 | #else |
michael@0 | 712 | ret = cc_bw_increase(stcb, net, nbw); |
michael@0 | 713 | #endif |
michael@0 | 714 | goto out; |
michael@0 | 715 | } |
michael@0 | 716 | rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt); |
michael@0 | 717 | if (nbw < net->cc_mod.rtcc.lbw - bw_offset) { |
michael@0 | 718 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 719 | ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind); |
michael@0 | 720 | #else |
michael@0 | 721 | ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind); |
michael@0 | 722 | #endif |
michael@0 | 723 | goto out; |
michael@0 | 724 | } |
michael@0 | 725 | /* If we reach here then |
michael@0 | 726 | * we are in a situation where |
michael@0 | 727 | * the bw stayed the same. |
michael@0 | 728 | */ |
michael@0 | 729 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 730 | ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind); |
michael@0 | 731 | #else |
michael@0 | 732 | ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind); |
michael@0 | 733 | #endif |
michael@0 | 734 | out: |
michael@0 | 735 | net->cc_mod.rtcc.last_inst_ind = inst_ind; |
michael@0 | 736 | return (ret); |
michael@0 | 737 | } |
michael@0 | 738 | |
michael@0 | 739 | static void |
michael@0 | 740 | sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, |
michael@0 | 741 | struct sctp_association *asoc, |
michael@0 | 742 | int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc) |
michael@0 | 743 | { |
michael@0 | 744 | struct sctp_nets *net; |
michael@0 | 745 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 746 | int old_cwnd; |
michael@0 | 747 | #endif |
michael@0 | 748 | uint32_t t_ssthresh, t_cwnd, incr; |
michael@0 | 749 | uint64_t t_ucwnd_sbw; |
michael@0 | 750 | uint64_t t_path_mptcp; |
michael@0 | 751 | uint64_t mptcp_like_alpha; |
michael@0 | 752 | uint32_t srtt; |
michael@0 | 753 | uint64_t max_path; |
michael@0 | 754 | |
michael@0 | 755 | /* MT FIXME: Don't compute this over and over again */ |
michael@0 | 756 | t_ssthresh = 0; |
michael@0 | 757 | t_cwnd = 0; |
michael@0 | 758 | t_ucwnd_sbw = 0; |
michael@0 | 759 | t_path_mptcp = 0; |
michael@0 | 760 | mptcp_like_alpha = 1; |
michael@0 | 761 | if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || |
michael@0 | 762 | (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) || |
michael@0 | 763 | (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) { |
michael@0 | 764 | max_path = 0; |
michael@0 | 765 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
michael@0 | 766 | t_ssthresh += net->ssthresh; |
michael@0 | 767 | t_cwnd += net->cwnd; |
michael@0 | 768 | /* lastsa>>3; we don't need to devide ...*/ |
michael@0 | 769 | srtt = net->lastsa; |
michael@0 | 770 | if (srtt > 0) { |
michael@0 | 771 | uint64_t tmp; |
michael@0 | 772 | |
michael@0 | 773 | t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt; |
michael@0 | 774 | t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) / |
michael@0 | 775 | (((uint64_t)net->mtu) * (uint64_t)srtt); |
michael@0 | 776 | tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) / |
michael@0 | 777 | ((uint64_t)net->mtu * (uint64_t)(srtt * srtt)); |
michael@0 | 778 | if (tmp > max_path) { |
michael@0 | 779 | max_path = tmp; |
michael@0 | 780 | } |
michael@0 | 781 | } |
michael@0 | 782 | } |
michael@0 | 783 | if (t_path_mptcp > 0) { |
michael@0 | 784 | mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp); |
michael@0 | 785 | } else { |
michael@0 | 786 | mptcp_like_alpha = 1; |
michael@0 | 787 | } |
michael@0 | 788 | } |
michael@0 | 789 | if (t_ssthresh == 0) { |
michael@0 | 790 | t_ssthresh = 1; |
michael@0 | 791 | } |
michael@0 | 792 | if (t_ucwnd_sbw == 0) { |
michael@0 | 793 | t_ucwnd_sbw = 1; |
michael@0 | 794 | } |
michael@0 | 795 | /******************************/ |
michael@0 | 796 | /* update cwnd and Early FR */ |
michael@0 | 797 | /******************************/ |
michael@0 | 798 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 799 | |
michael@0 | 800 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 801 | /* |
michael@0 | 802 | * CMT fast recovery code. Need to debug. |
michael@0 | 803 | */ |
michael@0 | 804 | if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { |
michael@0 | 805 | if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || |
michael@0 | 806 | SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { |
michael@0 | 807 | net->will_exit_fast_recovery = 1; |
michael@0 | 808 | } |
michael@0 | 809 | } |
michael@0 | 810 | #endif |
michael@0 | 811 | /* if nothing was acked on this destination skip it */ |
michael@0 | 812 | if (net->net_ack == 0) { |
michael@0 | 813 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 814 | sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); |
michael@0 | 815 | } |
michael@0 | 816 | continue; |
michael@0 | 817 | } |
michael@0 | 818 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 819 | /* CMT fast recovery code |
michael@0 | 820 | */ |
michael@0 | 821 | /* |
michael@0 | 822 | if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { |
michael@0 | 823 | @@@ Do something |
michael@0 | 824 | } |
michael@0 | 825 | else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { |
michael@0 | 826 | */ |
michael@0 | 827 | #endif |
michael@0 | 828 | |
michael@0 | 829 | if (asoc->fast_retran_loss_recovery && |
michael@0 | 830 | (will_exit == 0) && |
michael@0 | 831 | (asoc->sctp_cmt_on_off == 0)) { |
michael@0 | 832 | /* |
michael@0 | 833 | * If we are in loss recovery we skip any cwnd |
michael@0 | 834 | * update |
michael@0 | 835 | */ |
michael@0 | 836 | return; |
michael@0 | 837 | } |
michael@0 | 838 | /* |
michael@0 | 839 | * Did any measurements go on for this network? |
michael@0 | 840 | */ |
michael@0 | 841 | if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) { |
michael@0 | 842 | uint64_t nbw; |
michael@0 | 843 | /* |
michael@0 | 844 | * At this point our bw_bytes has been updated |
michael@0 | 845 | * by incoming sack information. |
michael@0 | 846 | * |
michael@0 | 847 | * But our bw may not yet be set. |
michael@0 | 848 | * |
michael@0 | 849 | */ |
michael@0 | 850 | if ((net->cc_mod.rtcc.new_tot_time/1000) > 0) { |
michael@0 | 851 | nbw = net->cc_mod.rtcc.bw_bytes/(net->cc_mod.rtcc.new_tot_time/1000); |
michael@0 | 852 | } else { |
michael@0 | 853 | nbw = net->cc_mod.rtcc.bw_bytes; |
michael@0 | 854 | } |
michael@0 | 855 | if (net->cc_mod.rtcc.lbw) { |
michael@0 | 856 | if (cc_bw_limit(stcb, net, nbw)) { |
michael@0 | 857 | /* Hold here, no update */ |
michael@0 | 858 | continue; |
michael@0 | 859 | } |
michael@0 | 860 | } else { |
michael@0 | 861 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 862 | uint64_t vtag, probepoint; |
michael@0 | 863 | |
michael@0 | 864 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 865 | probepoint |= ((0xa << 16) | 0); |
michael@0 | 866 | vtag = (net->rtt << 32) | |
michael@0 | 867 | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | |
michael@0 | 868 | (stcb->rport); |
michael@0 | 869 | |
michael@0 | 870 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 871 | vtag, |
michael@0 | 872 | nbw, |
michael@0 | 873 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 874 | net->flight_size, |
michael@0 | 875 | probepoint); |
michael@0 | 876 | #endif |
michael@0 | 877 | net->cc_mod.rtcc.lbw = nbw; |
michael@0 | 878 | net->cc_mod.rtcc.lbw_rtt = net->rtt; |
michael@0 | 879 | if (net->cc_mod.rtcc.rtt_set_this_sack) { |
michael@0 | 880 | net->cc_mod.rtcc.rtt_set_this_sack = 0; |
michael@0 | 881 | net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes; |
michael@0 | 882 | } |
michael@0 | 883 | } |
michael@0 | 884 | } |
michael@0 | 885 | /* |
michael@0 | 886 | * CMT: CUC algorithm. Update cwnd if pseudo-cumack has |
michael@0 | 887 | * moved. |
michael@0 | 888 | */ |
michael@0 | 889 | if (accum_moved || |
michael@0 | 890 | ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { |
michael@0 | 891 | /* If the cumulative ack moved we can proceed */ |
michael@0 | 892 | if (net->cwnd <= net->ssthresh) { |
michael@0 | 893 | /* We are in slow start */ |
michael@0 | 894 | if (net->flight_size + net->net_ack >= net->cwnd) { |
michael@0 | 895 | uint32_t limit; |
michael@0 | 896 | |
michael@0 | 897 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 898 | old_cwnd = net->cwnd; |
michael@0 | 899 | #endif |
michael@0 | 900 | switch (asoc->sctp_cmt_on_off) { |
michael@0 | 901 | case SCTP_CMT_RPV1: |
michael@0 | 902 | limit = (uint32_t)(((uint64_t)net->mtu * |
michael@0 | 903 | (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * |
michael@0 | 904 | (uint64_t)net->ssthresh) / |
michael@0 | 905 | (uint64_t)t_ssthresh); |
michael@0 | 906 | incr = (uint32_t)(((uint64_t)net->net_ack * |
michael@0 | 907 | (uint64_t)net->ssthresh) / |
michael@0 | 908 | (uint64_t)t_ssthresh); |
michael@0 | 909 | if (incr > limit) { |
michael@0 | 910 | incr = limit; |
michael@0 | 911 | } |
michael@0 | 912 | if (incr == 0) { |
michael@0 | 913 | incr = 1; |
michael@0 | 914 | } |
michael@0 | 915 | break; |
michael@0 | 916 | case SCTP_CMT_RPV2: |
michael@0 | 917 | /* lastsa>>3; we don't need to divide ...*/ |
michael@0 | 918 | srtt = net->lastsa; |
michael@0 | 919 | if (srtt == 0) { |
michael@0 | 920 | srtt = 1; |
michael@0 | 921 | } |
michael@0 | 922 | limit = (uint32_t)(((uint64_t)net->mtu * |
michael@0 | 923 | (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * |
michael@0 | 924 | (uint64_t)net->cwnd) / |
michael@0 | 925 | ((uint64_t)srtt * t_ucwnd_sbw)); |
michael@0 | 926 | /* INCREASE FACTOR */ |
michael@0 | 927 | incr = (uint32_t)(((uint64_t)net->net_ack * |
michael@0 | 928 | (uint64_t)net->cwnd) / |
michael@0 | 929 | ((uint64_t)srtt * t_ucwnd_sbw)); |
michael@0 | 930 | /* INCREASE FACTOR */ |
michael@0 | 931 | if (incr > limit) { |
michael@0 | 932 | incr = limit; |
michael@0 | 933 | } |
michael@0 | 934 | if (incr == 0) { |
michael@0 | 935 | incr = 1; |
michael@0 | 936 | } |
michael@0 | 937 | break; |
michael@0 | 938 | case SCTP_CMT_MPTCP: |
michael@0 | 939 | limit = (uint32_t)(((uint64_t)net->mtu * |
michael@0 | 940 | mptcp_like_alpha * |
michael@0 | 941 | (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >> |
michael@0 | 942 | SHIFT_MPTCP_MULTI); |
michael@0 | 943 | incr = (uint32_t)(((uint64_t)net->net_ack * |
michael@0 | 944 | mptcp_like_alpha) >> |
michael@0 | 945 | SHIFT_MPTCP_MULTI); |
michael@0 | 946 | if (incr > limit) { |
michael@0 | 947 | incr = limit; |
michael@0 | 948 | } |
michael@0 | 949 | if (incr > net->net_ack) { |
michael@0 | 950 | incr = net->net_ack; |
michael@0 | 951 | } |
michael@0 | 952 | if (incr > net->mtu) { |
michael@0 | 953 | incr = net->mtu; |
michael@0 | 954 | } |
michael@0 | 955 | break; |
michael@0 | 956 | default: |
michael@0 | 957 | incr = net->net_ack; |
michael@0 | 958 | if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) { |
michael@0 | 959 | incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable); |
michael@0 | 960 | } |
michael@0 | 961 | break; |
michael@0 | 962 | } |
michael@0 | 963 | net->cwnd += incr; |
michael@0 | 964 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 965 | sctp_log_cwnd(stcb, net, incr, |
michael@0 | 966 | SCTP_CWND_LOG_FROM_SS); |
michael@0 | 967 | } |
michael@0 | 968 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 969 | SDT_PROBE(sctp, cwnd, net, ack, |
michael@0 | 970 | stcb->asoc.my_vtag, |
michael@0 | 971 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 972 | net, |
michael@0 | 973 | old_cwnd, net->cwnd); |
michael@0 | 974 | #endif |
michael@0 | 975 | } else { |
michael@0 | 976 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 977 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 978 | SCTP_CWND_LOG_NOADV_SS); |
michael@0 | 979 | } |
michael@0 | 980 | } |
michael@0 | 981 | } else { |
michael@0 | 982 | /* We are in congestion avoidance */ |
michael@0 | 983 | /* |
michael@0 | 984 | * Add to pba |
michael@0 | 985 | */ |
michael@0 | 986 | net->partial_bytes_acked += net->net_ack; |
michael@0 | 987 | |
michael@0 | 988 | if ((net->flight_size + net->net_ack >= net->cwnd) && |
michael@0 | 989 | (net->partial_bytes_acked >= net->cwnd)) { |
michael@0 | 990 | net->partial_bytes_acked -= net->cwnd; |
michael@0 | 991 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 992 | old_cwnd = net->cwnd; |
michael@0 | 993 | #endif |
michael@0 | 994 | switch (asoc->sctp_cmt_on_off) { |
michael@0 | 995 | case SCTP_CMT_RPV1: |
michael@0 | 996 | incr = (uint32_t)(((uint64_t)net->mtu * |
michael@0 | 997 | (uint64_t)net->ssthresh) / |
michael@0 | 998 | (uint64_t)t_ssthresh); |
michael@0 | 999 | if (incr == 0) { |
michael@0 | 1000 | incr = 1; |
michael@0 | 1001 | } |
michael@0 | 1002 | break; |
michael@0 | 1003 | case SCTP_CMT_RPV2: |
michael@0 | 1004 | /* lastsa>>3; we don't need to divide ... */ |
michael@0 | 1005 | srtt = net->lastsa; |
michael@0 | 1006 | if (srtt == 0) { |
michael@0 | 1007 | srtt = 1; |
michael@0 | 1008 | } |
michael@0 | 1009 | incr = (uint32_t)((uint64_t)net->mtu * |
michael@0 | 1010 | (uint64_t)net->cwnd / |
michael@0 | 1011 | ((uint64_t)srtt * |
michael@0 | 1012 | t_ucwnd_sbw)); |
michael@0 | 1013 | /* INCREASE FACTOR */ |
michael@0 | 1014 | if (incr == 0) { |
michael@0 | 1015 | incr = 1; |
michael@0 | 1016 | } |
michael@0 | 1017 | break; |
michael@0 | 1018 | case SCTP_CMT_MPTCP: |
michael@0 | 1019 | incr = (uint32_t)((mptcp_like_alpha * |
michael@0 | 1020 | (uint64_t) net->cwnd) >> |
michael@0 | 1021 | SHIFT_MPTCP_MULTI); |
michael@0 | 1022 | if (incr > net->mtu) { |
michael@0 | 1023 | incr = net->mtu; |
michael@0 | 1024 | } |
michael@0 | 1025 | break; |
michael@0 | 1026 | default: |
michael@0 | 1027 | incr = net->mtu; |
michael@0 | 1028 | break; |
michael@0 | 1029 | } |
michael@0 | 1030 | net->cwnd += incr; |
michael@0 | 1031 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1032 | SDT_PROBE(sctp, cwnd, net, ack, |
michael@0 | 1033 | stcb->asoc.my_vtag, |
michael@0 | 1034 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 1035 | net, |
michael@0 | 1036 | old_cwnd, net->cwnd); |
michael@0 | 1037 | #endif |
michael@0 | 1038 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1039 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 1040 | SCTP_CWND_LOG_FROM_CA); |
michael@0 | 1041 | } |
michael@0 | 1042 | } else { |
michael@0 | 1043 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1044 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 1045 | SCTP_CWND_LOG_NOADV_CA); |
michael@0 | 1046 | } |
michael@0 | 1047 | } |
michael@0 | 1048 | } |
michael@0 | 1049 | } else { |
michael@0 | 1050 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1051 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 1052 | SCTP_CWND_LOG_NO_CUMACK); |
michael@0 | 1053 | } |
michael@0 | 1054 | } |
michael@0 | 1055 | } |
michael@0 | 1056 | } |
michael@0 | 1057 | |
michael@0 | 1058 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1059 | static void |
michael@0 | 1060 | sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 1061 | #else |
michael@0 | 1062 | static void |
michael@0 | 1063 | sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net) |
michael@0 | 1064 | #endif |
michael@0 | 1065 | { |
michael@0 | 1066 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1067 | int old_cwnd; |
michael@0 | 1068 | |
michael@0 | 1069 | old_cwnd = net->cwnd; |
michael@0 | 1070 | #endif |
michael@0 | 1071 | net->cwnd = net->mtu; |
michael@0 | 1072 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1073 | SDT_PROBE(sctp, cwnd, net, ack, |
michael@0 | 1074 | stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, |
michael@0 | 1075 | old_cwnd, net->cwnd); |
michael@0 | 1076 | #endif |
michael@0 | 1077 | SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n", |
michael@0 | 1078 | (void *)net, net->cwnd); |
michael@0 | 1079 | } |
michael@0 | 1080 | |
michael@0 | 1081 | |
michael@0 | 1082 | static void |
michael@0 | 1083 | sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 1084 | { |
michael@0 | 1085 | int old_cwnd = net->cwnd; |
michael@0 | 1086 | uint32_t t_ssthresh, t_cwnd; |
michael@0 | 1087 | uint64_t t_ucwnd_sbw; |
michael@0 | 1088 | |
michael@0 | 1089 | /* MT FIXME: Don't compute this over and over again */ |
michael@0 | 1090 | t_ssthresh = 0; |
michael@0 | 1091 | t_cwnd = 0; |
michael@0 | 1092 | if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) || |
michael@0 | 1093 | (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) { |
michael@0 | 1094 | struct sctp_nets *lnet; |
michael@0 | 1095 | uint32_t srtt; |
michael@0 | 1096 | |
michael@0 | 1097 | t_ucwnd_sbw = 0; |
michael@0 | 1098 | TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) { |
michael@0 | 1099 | t_ssthresh += lnet->ssthresh; |
michael@0 | 1100 | t_cwnd += lnet->cwnd; |
michael@0 | 1101 | srtt = lnet->lastsa; |
michael@0 | 1102 | /* lastsa>>3; we don't need to divide ... */ |
michael@0 | 1103 | if (srtt > 0) { |
michael@0 | 1104 | t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt; |
michael@0 | 1105 | } |
michael@0 | 1106 | } |
michael@0 | 1107 | if (t_ssthresh < 1) { |
michael@0 | 1108 | t_ssthresh = 1; |
michael@0 | 1109 | } |
michael@0 | 1110 | if (t_ucwnd_sbw < 1) { |
michael@0 | 1111 | t_ucwnd_sbw = 1; |
michael@0 | 1112 | } |
michael@0 | 1113 | if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) { |
michael@0 | 1114 | net->ssthresh = (uint32_t)(((uint64_t)4 * |
michael@0 | 1115 | (uint64_t)net->mtu * |
michael@0 | 1116 | (uint64_t)net->ssthresh) / |
michael@0 | 1117 | (uint64_t)t_ssthresh); |
michael@0 | 1118 | } else { |
michael@0 | 1119 | uint64_t cc_delta; |
michael@0 | 1120 | |
michael@0 | 1121 | srtt = net->lastsa; |
michael@0 | 1122 | /* lastsa>>3; we don't need to divide ... */ |
michael@0 | 1123 | if (srtt == 0) { |
michael@0 | 1124 | srtt = 1; |
michael@0 | 1125 | } |
michael@0 | 1126 | cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2; |
michael@0 | 1127 | if (cc_delta < t_cwnd) { |
michael@0 | 1128 | net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta); |
michael@0 | 1129 | } else { |
michael@0 | 1130 | net->ssthresh = net->mtu; |
michael@0 | 1131 | } |
michael@0 | 1132 | } |
michael@0 | 1133 | if ((net->cwnd > t_cwnd / 2) && |
michael@0 | 1134 | (net->ssthresh < net->cwnd - t_cwnd / 2)) { |
michael@0 | 1135 | net->ssthresh = net->cwnd - t_cwnd / 2; |
michael@0 | 1136 | } |
michael@0 | 1137 | if (net->ssthresh < net->mtu) { |
michael@0 | 1138 | net->ssthresh = net->mtu; |
michael@0 | 1139 | } |
michael@0 | 1140 | } else { |
michael@0 | 1141 | net->ssthresh = max(net->cwnd / 2, 4 * net->mtu); |
michael@0 | 1142 | } |
michael@0 | 1143 | net->cwnd = net->mtu; |
michael@0 | 1144 | net->partial_bytes_acked = 0; |
michael@0 | 1145 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1146 | SDT_PROBE(sctp, cwnd, net, to, |
michael@0 | 1147 | stcb->asoc.my_vtag, |
michael@0 | 1148 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 1149 | net, |
michael@0 | 1150 | old_cwnd, net->cwnd); |
michael@0 | 1151 | #endif |
michael@0 | 1152 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1153 | sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); |
michael@0 | 1154 | } |
michael@0 | 1155 | } |
michael@0 | 1156 | |
michael@0 | 1157 | static void |
michael@0 | 1158 | sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net, |
michael@0 | 1159 | int in_window, int num_pkt_lost, int use_rtcc) |
michael@0 | 1160 | { |
michael@0 | 1161 | int old_cwnd = net->cwnd; |
michael@0 | 1162 | if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) { |
michael@0 | 1163 | /* Data center Congestion Control */ |
michael@0 | 1164 | if (in_window == 0) { |
michael@0 | 1165 | /* Go to CA with the cwnd at the point we sent |
michael@0 | 1166 | * the TSN that was marked with a CE. |
michael@0 | 1167 | */ |
michael@0 | 1168 | if (net->ecn_prev_cwnd < net->cwnd) { |
michael@0 | 1169 | /* Restore to prev cwnd */ |
michael@0 | 1170 | net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost); |
michael@0 | 1171 | } else { |
michael@0 | 1172 | /* Just cut in 1/2 */ |
michael@0 | 1173 | net->cwnd /= 2; |
michael@0 | 1174 | } |
michael@0 | 1175 | /* Drop to CA */ |
michael@0 | 1176 | net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu); |
michael@0 | 1177 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1178 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); |
michael@0 | 1179 | } |
michael@0 | 1180 | } else { |
michael@0 | 1181 | /* Further tuning down required over the drastic orginal cut */ |
michael@0 | 1182 | net->ssthresh -= (net->mtu * num_pkt_lost); |
michael@0 | 1183 | net->cwnd -= (net->mtu * num_pkt_lost); |
michael@0 | 1184 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1185 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); |
michael@0 | 1186 | } |
michael@0 | 1187 | |
michael@0 | 1188 | } |
michael@0 | 1189 | SCTP_STAT_INCR(sctps_ecnereducedcwnd); |
michael@0 | 1190 | } else { |
michael@0 | 1191 | if (in_window == 0) { |
michael@0 | 1192 | SCTP_STAT_INCR(sctps_ecnereducedcwnd); |
michael@0 | 1193 | net->ssthresh = net->cwnd / 2; |
michael@0 | 1194 | if (net->ssthresh < net->mtu) { |
michael@0 | 1195 | net->ssthresh = net->mtu; |
michael@0 | 1196 | /* here back off the timer as well, to slow us down */ |
michael@0 | 1197 | net->RTO <<= 1; |
michael@0 | 1198 | } |
michael@0 | 1199 | net->cwnd = net->ssthresh; |
michael@0 | 1200 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1201 | SDT_PROBE(sctp, cwnd, net, ecn, |
michael@0 | 1202 | stcb->asoc.my_vtag, |
michael@0 | 1203 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 1204 | net, |
michael@0 | 1205 | old_cwnd, net->cwnd); |
michael@0 | 1206 | #endif |
michael@0 | 1207 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1208 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); |
michael@0 | 1209 | } |
michael@0 | 1210 | } |
michael@0 | 1211 | } |
michael@0 | 1212 | |
michael@0 | 1213 | } |
michael@0 | 1214 | |
michael@0 | 1215 | static void |
michael@0 | 1216 | sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb, |
michael@0 | 1217 | struct sctp_nets *net, struct sctp_pktdrop_chunk *cp, |
michael@0 | 1218 | uint32_t *bottle_bw, uint32_t *on_queue) |
michael@0 | 1219 | { |
michael@0 | 1220 | uint32_t bw_avail; |
michael@0 | 1221 | int rtt; |
michael@0 | 1222 | unsigned int incr; |
michael@0 | 1223 | int old_cwnd = net->cwnd; |
michael@0 | 1224 | |
michael@0 | 1225 | /* need real RTT in msd for this calc */ |
michael@0 | 1226 | rtt = net->rtt / 1000; |
michael@0 | 1227 | /* get bottle neck bw */ |
michael@0 | 1228 | *bottle_bw = ntohl(cp->bottle_bw); |
michael@0 | 1229 | /* and whats on queue */ |
michael@0 | 1230 | *on_queue = ntohl(cp->current_onq); |
michael@0 | 1231 | /* |
michael@0 | 1232 | * adjust the on-queue if our flight is more it could be |
michael@0 | 1233 | * that the router has not yet gotten data "in-flight" to it |
michael@0 | 1234 | */ |
michael@0 | 1235 | if (*on_queue < net->flight_size) |
michael@0 | 1236 | *on_queue = net->flight_size; |
michael@0 | 1237 | /* calculate the available space */ |
michael@0 | 1238 | bw_avail = (*bottle_bw * rtt) / 1000; |
michael@0 | 1239 | if (bw_avail > *bottle_bw) { |
michael@0 | 1240 | /* |
michael@0 | 1241 | * Cap the growth to no more than the bottle neck. |
michael@0 | 1242 | * This can happen as RTT slides up due to queues. |
michael@0 | 1243 | * It also means if you have more than a 1 second |
michael@0 | 1244 | * RTT with a empty queue you will be limited to the |
michael@0 | 1245 | * bottle_bw per second no matter if other points |
michael@0 | 1246 | * have 1/2 the RTT and you could get more out... |
michael@0 | 1247 | */ |
michael@0 | 1248 | bw_avail = *bottle_bw; |
michael@0 | 1249 | } |
michael@0 | 1250 | if (*on_queue > bw_avail) { |
michael@0 | 1251 | /* |
michael@0 | 1252 | * No room for anything else don't allow anything |
michael@0 | 1253 | * else to be "added to the fire". |
michael@0 | 1254 | */ |
michael@0 | 1255 | int seg_inflight, seg_onqueue, my_portion; |
michael@0 | 1256 | net->partial_bytes_acked = 0; |
michael@0 | 1257 | |
michael@0 | 1258 | /* how much are we over queue size? */ |
michael@0 | 1259 | incr = *on_queue - bw_avail; |
michael@0 | 1260 | if (stcb->asoc.seen_a_sack_this_pkt) { |
michael@0 | 1261 | /* |
michael@0 | 1262 | * undo any cwnd adjustment that the sack |
michael@0 | 1263 | * might have made |
michael@0 | 1264 | */ |
michael@0 | 1265 | net->cwnd = net->prev_cwnd; |
michael@0 | 1266 | } |
michael@0 | 1267 | /* Now how much of that is mine? */ |
michael@0 | 1268 | seg_inflight = net->flight_size / net->mtu; |
michael@0 | 1269 | seg_onqueue = *on_queue / net->mtu; |
michael@0 | 1270 | my_portion = (incr * seg_inflight) / seg_onqueue; |
michael@0 | 1271 | |
michael@0 | 1272 | /* Have I made an adjustment already */ |
michael@0 | 1273 | if (net->cwnd > net->flight_size) { |
michael@0 | 1274 | /* |
michael@0 | 1275 | * for this flight I made an adjustment we |
michael@0 | 1276 | * need to decrease the portion by a share |
michael@0 | 1277 | * our previous adjustment. |
michael@0 | 1278 | */ |
michael@0 | 1279 | int diff_adj; |
michael@0 | 1280 | |
michael@0 | 1281 | diff_adj = net->cwnd - net->flight_size; |
michael@0 | 1282 | if (diff_adj > my_portion) |
michael@0 | 1283 | my_portion = 0; |
michael@0 | 1284 | else |
michael@0 | 1285 | my_portion -= diff_adj; |
michael@0 | 1286 | } |
michael@0 | 1287 | /* |
michael@0 | 1288 | * back down to the previous cwnd (assume we have |
michael@0 | 1289 | * had a sack before this packet). minus what ever |
michael@0 | 1290 | * portion of the overage is my fault. |
michael@0 | 1291 | */ |
michael@0 | 1292 | net->cwnd -= my_portion; |
michael@0 | 1293 | |
michael@0 | 1294 | /* we will NOT back down more than 1 MTU */ |
michael@0 | 1295 | if (net->cwnd <= net->mtu) { |
michael@0 | 1296 | net->cwnd = net->mtu; |
michael@0 | 1297 | } |
michael@0 | 1298 | /* force into CA */ |
michael@0 | 1299 | net->ssthresh = net->cwnd - 1; |
michael@0 | 1300 | } else { |
michael@0 | 1301 | /* |
michael@0 | 1302 | * Take 1/4 of the space left or max burst up .. |
michael@0 | 1303 | * whichever is less. |
michael@0 | 1304 | */ |
michael@0 | 1305 | incr = (bw_avail - *on_queue) >> 2; |
michael@0 | 1306 | if ((stcb->asoc.max_burst > 0) && |
michael@0 | 1307 | (stcb->asoc.max_burst * net->mtu < incr)) { |
michael@0 | 1308 | incr = stcb->asoc.max_burst * net->mtu; |
michael@0 | 1309 | } |
michael@0 | 1310 | net->cwnd += incr; |
michael@0 | 1311 | } |
michael@0 | 1312 | if (net->cwnd > bw_avail) { |
michael@0 | 1313 | /* We can't exceed the pipe size */ |
michael@0 | 1314 | net->cwnd = bw_avail; |
michael@0 | 1315 | } |
michael@0 | 1316 | if (net->cwnd < net->mtu) { |
michael@0 | 1317 | /* We always have 1 MTU */ |
michael@0 | 1318 | net->cwnd = net->mtu; |
michael@0 | 1319 | } |
michael@0 | 1320 | |
michael@0 | 1321 | if (net->cwnd - old_cwnd != 0) { |
michael@0 | 1322 | /* log only changes */ |
michael@0 | 1323 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1324 | SDT_PROBE(sctp, cwnd, net, pd, |
michael@0 | 1325 | stcb->asoc.my_vtag, |
michael@0 | 1326 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 1327 | net, |
michael@0 | 1328 | old_cwnd, net->cwnd); |
michael@0 | 1329 | #endif |
michael@0 | 1330 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1331 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), |
michael@0 | 1332 | SCTP_CWND_LOG_FROM_SAT); |
michael@0 | 1333 | } |
michael@0 | 1334 | } |
michael@0 | 1335 | } |
michael@0 | 1336 | |
michael@0 | 1337 | static void |
michael@0 | 1338 | sctp_cwnd_update_after_output(struct sctp_tcb *stcb, |
michael@0 | 1339 | struct sctp_nets *net, int burst_limit) |
michael@0 | 1340 | { |
michael@0 | 1341 | int old_cwnd = net->cwnd; |
michael@0 | 1342 | |
michael@0 | 1343 | if (net->ssthresh < net->cwnd) |
michael@0 | 1344 | net->ssthresh = net->cwnd; |
michael@0 | 1345 | if (burst_limit) { |
michael@0 | 1346 | net->cwnd = (net->flight_size + (burst_limit * net->mtu)); |
michael@0 | 1347 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1348 | SDT_PROBE(sctp, cwnd, net, bl, |
michael@0 | 1349 | stcb->asoc.my_vtag, |
michael@0 | 1350 | ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), |
michael@0 | 1351 | net, |
michael@0 | 1352 | old_cwnd, net->cwnd); |
michael@0 | 1353 | #endif |
michael@0 | 1354 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1355 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST); |
michael@0 | 1356 | } |
michael@0 | 1357 | } |
michael@0 | 1358 | } |
michael@0 | 1359 | |
michael@0 | 1360 | static void |
michael@0 | 1361 | sctp_cwnd_update_after_sack(struct sctp_tcb *stcb, |
michael@0 | 1362 | struct sctp_association *asoc, |
michael@0 | 1363 | int accum_moved, int reneged_all, int will_exit) |
michael@0 | 1364 | { |
michael@0 | 1365 | /* Passing a zero argument in last disables the rtcc algoritm */ |
michael@0 | 1366 | sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0); |
michael@0 | 1367 | } |
michael@0 | 1368 | |
michael@0 | 1369 | static void |
michael@0 | 1370 | sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, |
michael@0 | 1371 | int in_window, int num_pkt_lost) |
michael@0 | 1372 | { |
michael@0 | 1373 | /* Passing a zero argument in last disables the rtcc algoritm */ |
michael@0 | 1374 | sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0); |
michael@0 | 1375 | } |
michael@0 | 1376 | |
michael@0 | 1377 | /* Here starts the RTCCVAR type CC invented by RRS which |
michael@0 | 1378 | * is a slight mod to RFC2581. We reuse a common routine or |
michael@0 | 1379 | * two since these algoritms are so close and need to |
michael@0 | 1380 | * remain the same. |
michael@0 | 1381 | */ |
michael@0 | 1382 | static void |
michael@0 | 1383 | sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, |
michael@0 | 1384 | int in_window, int num_pkt_lost) |
michael@0 | 1385 | { |
michael@0 | 1386 | sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1); |
michael@0 | 1387 | } |
michael@0 | 1388 | |
michael@0 | 1389 | |
michael@0 | 1390 | static |
michael@0 | 1391 | void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net, |
michael@0 | 1392 | struct sctp_tmit_chunk *tp1) |
michael@0 | 1393 | { |
michael@0 | 1394 | net->cc_mod.rtcc.bw_bytes += tp1->send_size; |
michael@0 | 1395 | } |
michael@0 | 1396 | |
michael@0 | 1397 | static void |
michael@0 | 1398 | sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED, |
michael@0 | 1399 | struct sctp_nets *net) |
michael@0 | 1400 | { |
michael@0 | 1401 | if (net->cc_mod.rtcc.tls_needs_set > 0) { |
michael@0 | 1402 | /* We had a bw measurment going on */ |
michael@0 | 1403 | struct timeval ltls; |
michael@0 | 1404 | SCTP_GETPTIME_TIMEVAL(<ls); |
michael@0 | 1405 | timevalsub(<ls, &net->cc_mod.rtcc.tls); |
michael@0 | 1406 | net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec; |
michael@0 | 1407 | } |
michael@0 | 1408 | } |
michael@0 | 1409 | |
michael@0 | 1410 | static void |
michael@0 | 1411 | sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, |
michael@0 | 1412 | struct sctp_nets *net) |
michael@0 | 1413 | { |
michael@0 | 1414 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1415 | uint64_t vtag, probepoint; |
michael@0 | 1416 | |
michael@0 | 1417 | #endif |
michael@0 | 1418 | if (net->cc_mod.rtcc.lbw) { |
michael@0 | 1419 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1420 | /* Clear the old bw.. we went to 0 in-flight */ |
michael@0 | 1421 | vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | |
michael@0 | 1422 | (stcb->rport); |
michael@0 | 1423 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 1424 | /* Probe point 8 */ |
michael@0 | 1425 | probepoint |= ((8 << 16) | 0); |
michael@0 | 1426 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 1427 | vtag, |
michael@0 | 1428 | ((net->cc_mod.rtcc.lbw << 32) | 0), |
michael@0 | 1429 | ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), |
michael@0 | 1430 | net->flight_size, |
michael@0 | 1431 | probepoint); |
michael@0 | 1432 | #endif |
michael@0 | 1433 | net->cc_mod.rtcc.lbw_rtt = 0; |
michael@0 | 1434 | net->cc_mod.rtcc.cwnd_at_bw_set = 0; |
michael@0 | 1435 | net->cc_mod.rtcc.lbw = 0; |
michael@0 | 1436 | net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; |
michael@0 | 1437 | net->cc_mod.rtcc.vol_reduce = 0; |
michael@0 | 1438 | net->cc_mod.rtcc.bw_tot_time = 0; |
michael@0 | 1439 | net->cc_mod.rtcc.bw_bytes = 0; |
michael@0 | 1440 | net->cc_mod.rtcc.tls_needs_set = 0; |
michael@0 | 1441 | if (net->cc_mod.rtcc.steady_step) { |
michael@0 | 1442 | net->cc_mod.rtcc.vol_reduce = 0; |
michael@0 | 1443 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 1444 | net->cc_mod.rtcc.last_step_state = 0; |
michael@0 | 1445 | } |
michael@0 | 1446 | if (net->cc_mod.rtcc.ret_from_eq) { |
michael@0 | 1447 | /* less aggressive one - reset cwnd too */ |
michael@0 | 1448 | uint32_t cwnd_in_mtu, cwnd; |
michael@0 | 1449 | |
michael@0 | 1450 | cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); |
michael@0 | 1451 | if (cwnd_in_mtu == 0) { |
michael@0 | 1452 | /* Using 0 means that the value of RFC 4960 is used. */ |
michael@0 | 1453 | cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); |
michael@0 | 1454 | } else { |
michael@0 | 1455 | /* |
michael@0 | 1456 | * We take the minimum of the burst limit and the |
michael@0 | 1457 | * initial congestion window. |
michael@0 | 1458 | */ |
michael@0 | 1459 | if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst)) |
michael@0 | 1460 | cwnd_in_mtu = stcb->asoc.max_burst; |
michael@0 | 1461 | cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; |
michael@0 | 1462 | } |
michael@0 | 1463 | if (net->cwnd > cwnd) { |
michael@0 | 1464 | /* Only set if we are not a timeout (i.e. down to 1 mtu) */ |
michael@0 | 1465 | net->cwnd = cwnd; |
michael@0 | 1466 | } |
michael@0 | 1467 | } |
michael@0 | 1468 | } |
michael@0 | 1469 | } |
michael@0 | 1470 | |
michael@0 | 1471 | static void |
michael@0 | 1472 | sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb, |
michael@0 | 1473 | struct sctp_nets *net) |
michael@0 | 1474 | { |
michael@0 | 1475 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1476 | uint64_t vtag, probepoint; |
michael@0 | 1477 | |
michael@0 | 1478 | #endif |
michael@0 | 1479 | sctp_set_initial_cc_param(stcb, net); |
michael@0 | 1480 | stcb->asoc.use_precise_time = 1; |
michael@0 | 1481 | #if defined(__FreeBSD__) && __FreeBSD_version >= 803000 |
michael@0 | 1482 | probepoint = (((uint64_t)net->cwnd) << 32); |
michael@0 | 1483 | probepoint |= ((9 << 16) | 0); |
michael@0 | 1484 | vtag = (net->rtt << 32) | |
michael@0 | 1485 | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | |
michael@0 | 1486 | (stcb->rport); |
michael@0 | 1487 | SDT_PROBE(sctp, cwnd, net, rttvar, |
michael@0 | 1488 | vtag, |
michael@0 | 1489 | 0, |
michael@0 | 1490 | 0, |
michael@0 | 1491 | 0, |
michael@0 | 1492 | probepoint); |
michael@0 | 1493 | #endif |
michael@0 | 1494 | net->cc_mod.rtcc.lbw_rtt = 0; |
michael@0 | 1495 | net->cc_mod.rtcc.cwnd_at_bw_set = 0; |
michael@0 | 1496 | net->cc_mod.rtcc.vol_reduce = 0; |
michael@0 | 1497 | net->cc_mod.rtcc.lbw = 0; |
michael@0 | 1498 | net->cc_mod.rtcc.vol_reduce = 0; |
michael@0 | 1499 | net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0; |
michael@0 | 1500 | net->cc_mod.rtcc.bw_tot_time = 0; |
michael@0 | 1501 | net->cc_mod.rtcc.bw_bytes = 0; |
michael@0 | 1502 | net->cc_mod.rtcc.tls_needs_set = 0; |
michael@0 | 1503 | net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret); |
michael@0 | 1504 | net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step); |
michael@0 | 1505 | net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn); |
michael@0 | 1506 | net->cc_mod.rtcc.step_cnt = 0; |
michael@0 | 1507 | net->cc_mod.rtcc.last_step_state = 0; |
michael@0 | 1508 | |
michael@0 | 1509 | |
michael@0 | 1510 | } |
michael@0 | 1511 | |
michael@0 | 1512 | static int |
michael@0 | 1513 | sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget, |
michael@0 | 1514 | struct sctp_cc_option *cc_opt) |
michael@0 | 1515 | { |
michael@0 | 1516 | struct sctp_nets *net; |
michael@0 | 1517 | if (setorget == 1) { |
michael@0 | 1518 | /* a set */ |
michael@0 | 1519 | if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { |
michael@0 | 1520 | if ((cc_opt->aid_value.assoc_value != 0) && |
michael@0 | 1521 | (cc_opt->aid_value.assoc_value != 1)) { |
michael@0 | 1522 | return (EINVAL); |
michael@0 | 1523 | } |
michael@0 | 1524 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
michael@0 | 1525 | net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value; |
michael@0 | 1526 | } |
michael@0 | 1527 | } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { |
michael@0 | 1528 | if ((cc_opt->aid_value.assoc_value != 0) && |
michael@0 | 1529 | (cc_opt->aid_value.assoc_value != 1)) { |
michael@0 | 1530 | return (EINVAL); |
michael@0 | 1531 | } |
michael@0 | 1532 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
michael@0 | 1533 | net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value; |
michael@0 | 1534 | } |
michael@0 | 1535 | } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { |
michael@0 | 1536 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
michael@0 | 1537 | net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value; |
michael@0 | 1538 | } |
michael@0 | 1539 | } else { |
michael@0 | 1540 | return (EINVAL); |
michael@0 | 1541 | } |
michael@0 | 1542 | } else { |
michael@0 | 1543 | /* a get */ |
michael@0 | 1544 | if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { |
michael@0 | 1545 | net = TAILQ_FIRST(&stcb->asoc.nets); |
michael@0 | 1546 | if (net == NULL) { |
michael@0 | 1547 | return (EFAULT); |
michael@0 | 1548 | } |
michael@0 | 1549 | cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq; |
michael@0 | 1550 | } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) { |
michael@0 | 1551 | net = TAILQ_FIRST(&stcb->asoc.nets); |
michael@0 | 1552 | if (net == NULL) { |
michael@0 | 1553 | return (EFAULT); |
michael@0 | 1554 | } |
michael@0 | 1555 | cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn; |
michael@0 | 1556 | } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) { |
michael@0 | 1557 | net = TAILQ_FIRST(&stcb->asoc.nets); |
michael@0 | 1558 | if (net == NULL) { |
michael@0 | 1559 | return (EFAULT); |
michael@0 | 1560 | } |
michael@0 | 1561 | cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step; |
michael@0 | 1562 | } else { |
michael@0 | 1563 | return (EINVAL); |
michael@0 | 1564 | } |
michael@0 | 1565 | } |
michael@0 | 1566 | return (0); |
michael@0 | 1567 | } |
michael@0 | 1568 | |
michael@0 | 1569 | static void |
michael@0 | 1570 | sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED, |
michael@0 | 1571 | struct sctp_nets *net) |
michael@0 | 1572 | { |
michael@0 | 1573 | if (net->cc_mod.rtcc.tls_needs_set == 0) { |
michael@0 | 1574 | SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls); |
michael@0 | 1575 | net->cc_mod.rtcc.tls_needs_set = 2; |
michael@0 | 1576 | } |
michael@0 | 1577 | } |
michael@0 | 1578 | |
michael@0 | 1579 | static void |
michael@0 | 1580 | sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb, |
michael@0 | 1581 | struct sctp_association *asoc, |
michael@0 | 1582 | int accum_moved, int reneged_all, int will_exit) |
michael@0 | 1583 | { |
michael@0 | 1584 | /* Passing a one argument at the last enables the rtcc algoritm */ |
michael@0 | 1585 | sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1); |
michael@0 | 1586 | } |
michael@0 | 1587 | |
michael@0 | 1588 | static void |
michael@0 | 1589 | sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED, |
michael@0 | 1590 | struct sctp_nets *net, |
michael@0 | 1591 | struct timeval *now SCTP_UNUSED) |
michael@0 | 1592 | { |
michael@0 | 1593 | net->cc_mod.rtcc.rtt_set_this_sack = 1; |
michael@0 | 1594 | } |
michael@0 | 1595 | |
michael@0 | 1596 | /* Here starts Sally Floyds HS-TCP */ |
michael@0 | 1597 | |
michael@0 | 1598 | struct sctp_hs_raise_drop { |
michael@0 | 1599 | int32_t cwnd; |
michael@0 | 1600 | int32_t increase; |
michael@0 | 1601 | int32_t drop_percent; |
michael@0 | 1602 | }; |
michael@0 | 1603 | |
michael@0 | 1604 | #define SCTP_HS_TABLE_SIZE 73 |
michael@0 | 1605 | |
michael@0 | 1606 | struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = { |
michael@0 | 1607 | {38, 1, 50}, /* 0 */ |
michael@0 | 1608 | {118, 2, 44}, /* 1 */ |
michael@0 | 1609 | {221, 3, 41}, /* 2 */ |
michael@0 | 1610 | {347, 4, 38}, /* 3 */ |
michael@0 | 1611 | {495, 5, 37}, /* 4 */ |
michael@0 | 1612 | {663, 6, 35}, /* 5 */ |
michael@0 | 1613 | {851, 7, 34}, /* 6 */ |
michael@0 | 1614 | {1058, 8, 33}, /* 7 */ |
michael@0 | 1615 | {1284, 9, 32}, /* 8 */ |
michael@0 | 1616 | {1529, 10, 31}, /* 9 */ |
michael@0 | 1617 | {1793, 11, 30}, /* 10 */ |
michael@0 | 1618 | {2076, 12, 29}, /* 11 */ |
michael@0 | 1619 | {2378, 13, 28}, /* 12 */ |
michael@0 | 1620 | {2699, 14, 28}, /* 13 */ |
michael@0 | 1621 | {3039, 15, 27}, /* 14 */ |
michael@0 | 1622 | {3399, 16, 27}, /* 15 */ |
michael@0 | 1623 | {3778, 17, 26}, /* 16 */ |
michael@0 | 1624 | {4177, 18, 26}, /* 17 */ |
michael@0 | 1625 | {4596, 19, 25}, /* 18 */ |
michael@0 | 1626 | {5036, 20, 25}, /* 19 */ |
michael@0 | 1627 | {5497, 21, 24}, /* 20 */ |
michael@0 | 1628 | {5979, 22, 24}, /* 21 */ |
michael@0 | 1629 | {6483, 23, 23}, /* 22 */ |
michael@0 | 1630 | {7009, 24, 23}, /* 23 */ |
michael@0 | 1631 | {7558, 25, 22}, /* 24 */ |
michael@0 | 1632 | {8130, 26, 22}, /* 25 */ |
michael@0 | 1633 | {8726, 27, 22}, /* 26 */ |
michael@0 | 1634 | {9346, 28, 21}, /* 27 */ |
michael@0 | 1635 | {9991, 29, 21}, /* 28 */ |
michael@0 | 1636 | {10661, 30, 21}, /* 29 */ |
michael@0 | 1637 | {11358, 31, 20}, /* 30 */ |
michael@0 | 1638 | {12082, 32, 20}, /* 31 */ |
michael@0 | 1639 | {12834, 33, 20}, /* 32 */ |
michael@0 | 1640 | {13614, 34, 19}, /* 33 */ |
michael@0 | 1641 | {14424, 35, 19}, /* 34 */ |
michael@0 | 1642 | {15265, 36, 19}, /* 35 */ |
michael@0 | 1643 | {16137, 37, 19}, /* 36 */ |
michael@0 | 1644 | {17042, 38, 18}, /* 37 */ |
michael@0 | 1645 | {17981, 39, 18}, /* 38 */ |
michael@0 | 1646 | {18955, 40, 18}, /* 39 */ |
michael@0 | 1647 | {19965, 41, 17}, /* 40 */ |
michael@0 | 1648 | {21013, 42, 17}, /* 41 */ |
michael@0 | 1649 | {22101, 43, 17}, /* 42 */ |
michael@0 | 1650 | {23230, 44, 17}, /* 43 */ |
michael@0 | 1651 | {24402, 45, 16}, /* 44 */ |
michael@0 | 1652 | {25618, 46, 16}, /* 45 */ |
michael@0 | 1653 | {26881, 47, 16}, /* 46 */ |
michael@0 | 1654 | {28193, 48, 16}, /* 47 */ |
michael@0 | 1655 | {29557, 49, 15}, /* 48 */ |
michael@0 | 1656 | {30975, 50, 15}, /* 49 */ |
michael@0 | 1657 | {32450, 51, 15}, /* 50 */ |
michael@0 | 1658 | {33986, 52, 15}, /* 51 */ |
michael@0 | 1659 | {35586, 53, 14}, /* 52 */ |
michael@0 | 1660 | {37253, 54, 14}, /* 53 */ |
michael@0 | 1661 | {38992, 55, 14}, /* 54 */ |
michael@0 | 1662 | {40808, 56, 14}, /* 55 */ |
michael@0 | 1663 | {42707, 57, 13}, /* 56 */ |
michael@0 | 1664 | {44694, 58, 13}, /* 57 */ |
michael@0 | 1665 | {46776, 59, 13}, /* 58 */ |
michael@0 | 1666 | {48961, 60, 13}, /* 59 */ |
michael@0 | 1667 | {51258, 61, 13}, /* 60 */ |
michael@0 | 1668 | {53677, 62, 12}, /* 61 */ |
michael@0 | 1669 | {56230, 63, 12}, /* 62 */ |
michael@0 | 1670 | {58932, 64, 12}, /* 63 */ |
michael@0 | 1671 | {61799, 65, 12}, /* 64 */ |
michael@0 | 1672 | {64851, 66, 11}, /* 65 */ |
michael@0 | 1673 | {68113, 67, 11}, /* 66 */ |
michael@0 | 1674 | {71617, 68, 11}, /* 67 */ |
michael@0 | 1675 | {75401, 69, 10}, /* 68 */ |
michael@0 | 1676 | {79517, 70, 10}, /* 69 */ |
michael@0 | 1677 | {84035, 71, 10}, /* 70 */ |
michael@0 | 1678 | {89053, 72, 10}, /* 71 */ |
michael@0 | 1679 | {94717, 73, 9} /* 72 */ |
michael@0 | 1680 | }; |
michael@0 | 1681 | |
michael@0 | 1682 | static void |
michael@0 | 1683 | sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 1684 | { |
michael@0 | 1685 | int cur_val, i, indx, incr; |
michael@0 | 1686 | |
michael@0 | 1687 | cur_val = net->cwnd >> 10; |
michael@0 | 1688 | indx = SCTP_HS_TABLE_SIZE - 1; |
michael@0 | 1689 | |
michael@0 | 1690 | if (cur_val < sctp_cwnd_adjust[0].cwnd) { |
michael@0 | 1691 | /* normal mode */ |
michael@0 | 1692 | if (net->net_ack > net->mtu) { |
michael@0 | 1693 | net->cwnd += net->mtu; |
michael@0 | 1694 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1695 | sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS); |
michael@0 | 1696 | } |
michael@0 | 1697 | } else { |
michael@0 | 1698 | net->cwnd += net->net_ack; |
michael@0 | 1699 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1700 | sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS); |
michael@0 | 1701 | } |
michael@0 | 1702 | } |
michael@0 | 1703 | } else { |
michael@0 | 1704 | for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) { |
michael@0 | 1705 | if (cur_val < sctp_cwnd_adjust[i].cwnd) { |
michael@0 | 1706 | indx = i; |
michael@0 | 1707 | break; |
michael@0 | 1708 | } |
michael@0 | 1709 | } |
michael@0 | 1710 | net->last_hs_used = indx; |
michael@0 | 1711 | incr = ((sctp_cwnd_adjust[indx].increase) << 10); |
michael@0 | 1712 | net->cwnd += incr; |
michael@0 | 1713 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1714 | sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS); |
michael@0 | 1715 | } |
michael@0 | 1716 | } |
michael@0 | 1717 | } |
michael@0 | 1718 | |
michael@0 | 1719 | static void |
michael@0 | 1720 | sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 1721 | { |
michael@0 | 1722 | int cur_val, i, indx; |
michael@0 | 1723 | int old_cwnd = net->cwnd; |
michael@0 | 1724 | |
michael@0 | 1725 | cur_val = net->cwnd >> 10; |
michael@0 | 1726 | if (cur_val < sctp_cwnd_adjust[0].cwnd) { |
michael@0 | 1727 | /* normal mode */ |
michael@0 | 1728 | net->ssthresh = net->cwnd / 2; |
michael@0 | 1729 | if (net->ssthresh < (net->mtu * 2)) { |
michael@0 | 1730 | net->ssthresh = 2 * net->mtu; |
michael@0 | 1731 | } |
michael@0 | 1732 | net->cwnd = net->ssthresh; |
michael@0 | 1733 | } else { |
michael@0 | 1734 | /* drop by the proper amount */ |
michael@0 | 1735 | net->ssthresh = net->cwnd - (int)((net->cwnd / 100) * |
michael@0 | 1736 | sctp_cwnd_adjust[net->last_hs_used].drop_percent); |
michael@0 | 1737 | net->cwnd = net->ssthresh; |
michael@0 | 1738 | /* now where are we */ |
michael@0 | 1739 | indx = net->last_hs_used; |
michael@0 | 1740 | cur_val = net->cwnd >> 10; |
michael@0 | 1741 | /* reset where we are in the table */ |
michael@0 | 1742 | if (cur_val < sctp_cwnd_adjust[0].cwnd) { |
michael@0 | 1743 | /* feel out of hs */ |
michael@0 | 1744 | net->last_hs_used = 0; |
michael@0 | 1745 | } else { |
michael@0 | 1746 | for (i = indx; i >= 1; i--) { |
michael@0 | 1747 | if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) { |
michael@0 | 1748 | break; |
michael@0 | 1749 | } |
michael@0 | 1750 | } |
michael@0 | 1751 | net->last_hs_used = indx; |
michael@0 | 1752 | } |
michael@0 | 1753 | } |
michael@0 | 1754 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1755 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR); |
michael@0 | 1756 | } |
michael@0 | 1757 | } |
michael@0 | 1758 | |
michael@0 | 1759 | static void |
michael@0 | 1760 | sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb, |
michael@0 | 1761 | struct sctp_association *asoc) |
michael@0 | 1762 | { |
michael@0 | 1763 | struct sctp_nets *net; |
michael@0 | 1764 | /* |
michael@0 | 1765 | * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && |
michael@0 | 1766 | * (net->fast_retran_loss_recovery == 0))) |
michael@0 | 1767 | */ |
michael@0 | 1768 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 1769 | if ((asoc->fast_retran_loss_recovery == 0) || |
michael@0 | 1770 | (asoc->sctp_cmt_on_off > 0)) { |
michael@0 | 1771 | /* out of a RFC2582 Fast recovery window? */ |
michael@0 | 1772 | if (net->net_ack > 0) { |
michael@0 | 1773 | /* |
michael@0 | 1774 | * per section 7.2.3, are there any |
michael@0 | 1775 | * destinations that had a fast retransmit |
michael@0 | 1776 | * to them. If so what we need to do is |
michael@0 | 1777 | * adjust ssthresh and cwnd. |
michael@0 | 1778 | */ |
michael@0 | 1779 | struct sctp_tmit_chunk *lchk; |
michael@0 | 1780 | |
michael@0 | 1781 | sctp_hs_cwnd_decrease(stcb, net); |
michael@0 | 1782 | |
michael@0 | 1783 | lchk = TAILQ_FIRST(&asoc->send_queue); |
michael@0 | 1784 | |
michael@0 | 1785 | net->partial_bytes_acked = 0; |
michael@0 | 1786 | /* Turn on fast recovery window */ |
michael@0 | 1787 | asoc->fast_retran_loss_recovery = 1; |
michael@0 | 1788 | if (lchk == NULL) { |
michael@0 | 1789 | /* Mark end of the window */ |
michael@0 | 1790 | asoc->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 1791 | } else { |
michael@0 | 1792 | asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 1793 | } |
michael@0 | 1794 | |
michael@0 | 1795 | /* |
michael@0 | 1796 | * CMT fast recovery -- per destination |
michael@0 | 1797 | * recovery variable. |
michael@0 | 1798 | */ |
michael@0 | 1799 | net->fast_retran_loss_recovery = 1; |
michael@0 | 1800 | |
michael@0 | 1801 | if (lchk == NULL) { |
michael@0 | 1802 | /* Mark end of the window */ |
michael@0 | 1803 | net->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 1804 | } else { |
michael@0 | 1805 | net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 1806 | } |
michael@0 | 1807 | |
michael@0 | 1808 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, |
michael@0 | 1809 | stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); |
michael@0 | 1810 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
michael@0 | 1811 | stcb->sctp_ep, stcb, net); |
michael@0 | 1812 | } |
michael@0 | 1813 | } else if (net->net_ack > 0) { |
michael@0 | 1814 | /* |
michael@0 | 1815 | * Mark a peg that we WOULD have done a cwnd |
michael@0 | 1816 | * reduction but RFC2582 prevented this action. |
michael@0 | 1817 | */ |
michael@0 | 1818 | SCTP_STAT_INCR(sctps_fastretransinrtt); |
michael@0 | 1819 | } |
michael@0 | 1820 | } |
michael@0 | 1821 | } |
michael@0 | 1822 | |
michael@0 | 1823 | static void |
michael@0 | 1824 | sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb, |
michael@0 | 1825 | struct sctp_association *asoc, |
michael@0 | 1826 | int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) |
michael@0 | 1827 | { |
michael@0 | 1828 | struct sctp_nets *net; |
michael@0 | 1829 | /******************************/ |
michael@0 | 1830 | /* update cwnd and Early FR */ |
michael@0 | 1831 | /******************************/ |
michael@0 | 1832 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 1833 | |
michael@0 | 1834 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 1835 | /* |
michael@0 | 1836 | * CMT fast recovery code. Need to debug. |
michael@0 | 1837 | */ |
michael@0 | 1838 | if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { |
michael@0 | 1839 | if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || |
michael@0 | 1840 | SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { |
michael@0 | 1841 | net->will_exit_fast_recovery = 1; |
michael@0 | 1842 | } |
michael@0 | 1843 | } |
michael@0 | 1844 | #endif |
michael@0 | 1845 | /* if nothing was acked on this destination skip it */ |
michael@0 | 1846 | if (net->net_ack == 0) { |
michael@0 | 1847 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1848 | sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); |
michael@0 | 1849 | } |
michael@0 | 1850 | continue; |
michael@0 | 1851 | } |
michael@0 | 1852 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 1853 | /* CMT fast recovery code |
michael@0 | 1854 | */ |
michael@0 | 1855 | /* |
michael@0 | 1856 | if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { |
michael@0 | 1857 | @@@ Do something |
michael@0 | 1858 | } |
michael@0 | 1859 | else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { |
michael@0 | 1860 | */ |
michael@0 | 1861 | #endif |
michael@0 | 1862 | |
michael@0 | 1863 | if (asoc->fast_retran_loss_recovery && |
michael@0 | 1864 | (will_exit == 0) && |
michael@0 | 1865 | (asoc->sctp_cmt_on_off == 0)) { |
michael@0 | 1866 | /* |
michael@0 | 1867 | * If we are in loss recovery we skip any cwnd |
michael@0 | 1868 | * update |
michael@0 | 1869 | */ |
michael@0 | 1870 | return; |
michael@0 | 1871 | } |
michael@0 | 1872 | /* |
michael@0 | 1873 | * CMT: CUC algorithm. Update cwnd if pseudo-cumack has |
michael@0 | 1874 | * moved. |
michael@0 | 1875 | */ |
michael@0 | 1876 | if (accum_moved || |
michael@0 | 1877 | ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { |
michael@0 | 1878 | /* If the cumulative ack moved we can proceed */ |
michael@0 | 1879 | if (net->cwnd <= net->ssthresh) { |
michael@0 | 1880 | /* We are in slow start */ |
michael@0 | 1881 | if (net->flight_size + net->net_ack >= net->cwnd) { |
michael@0 | 1882 | |
michael@0 | 1883 | sctp_hs_cwnd_increase(stcb, net); |
michael@0 | 1884 | |
michael@0 | 1885 | } else { |
michael@0 | 1886 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1887 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 1888 | SCTP_CWND_LOG_NOADV_SS); |
michael@0 | 1889 | } |
michael@0 | 1890 | } |
michael@0 | 1891 | } else { |
michael@0 | 1892 | /* We are in congestion avoidance */ |
michael@0 | 1893 | net->partial_bytes_acked += net->net_ack; |
michael@0 | 1894 | if ((net->flight_size + net->net_ack >= net->cwnd) && |
michael@0 | 1895 | (net->partial_bytes_acked >= net->cwnd)) { |
michael@0 | 1896 | net->partial_bytes_acked -= net->cwnd; |
michael@0 | 1897 | net->cwnd += net->mtu; |
michael@0 | 1898 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 1899 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 1900 | SCTP_CWND_LOG_FROM_CA); |
michael@0 | 1901 | } |
michael@0 | 1902 | } else { |
michael@0 | 1903 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1904 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 1905 | SCTP_CWND_LOG_NOADV_CA); |
michael@0 | 1906 | } |
michael@0 | 1907 | } |
michael@0 | 1908 | } |
michael@0 | 1909 | } else { |
michael@0 | 1910 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 1911 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 1912 | SCTP_CWND_LOG_NO_CUMACK); |
michael@0 | 1913 | } |
michael@0 | 1914 | } |
michael@0 | 1915 | } |
michael@0 | 1916 | } |
michael@0 | 1917 | |
michael@0 | 1918 | |
michael@0 | 1919 | /* |
michael@0 | 1920 | * H-TCP congestion control. The algorithm is detailed in: |
michael@0 | 1921 | * R.N.Shorten, D.J.Leith: |
michael@0 | 1922 | * "H-TCP: TCP for high-speed and long-distance networks" |
michael@0 | 1923 | * Proc. PFLDnet, Argonne, 2004. |
michael@0 | 1924 | * http://www.hamilton.ie/net/htcp3.pdf |
michael@0 | 1925 | */ |
michael@0 | 1926 | |
michael@0 | 1927 | |
michael@0 | 1928 | static int use_rtt_scaling = 1; |
michael@0 | 1929 | static int use_bandwidth_switch = 1; |
michael@0 | 1930 | |
michael@0 | 1931 | static inline int |
michael@0 | 1932 | between(uint32_t seq1, uint32_t seq2, uint32_t seq3) |
michael@0 | 1933 | { |
michael@0 | 1934 | return (seq3 - seq2 >= seq1 - seq2); |
michael@0 | 1935 | } |
michael@0 | 1936 | |
michael@0 | 1937 | static inline uint32_t |
michael@0 | 1938 | htcp_cong_time(struct htcp *ca) |
michael@0 | 1939 | { |
michael@0 | 1940 | return (sctp_get_tick_count() - ca->last_cong); |
michael@0 | 1941 | } |
michael@0 | 1942 | |
michael@0 | 1943 | static inline uint32_t |
michael@0 | 1944 | htcp_ccount(struct htcp *ca) |
michael@0 | 1945 | { |
michael@0 | 1946 | return (htcp_cong_time(ca)/ca->minRTT); |
michael@0 | 1947 | } |
michael@0 | 1948 | |
michael@0 | 1949 | static inline void |
michael@0 | 1950 | htcp_reset(struct htcp *ca) |
michael@0 | 1951 | { |
michael@0 | 1952 | ca->undo_last_cong = ca->last_cong; |
michael@0 | 1953 | ca->undo_maxRTT = ca->maxRTT; |
michael@0 | 1954 | ca->undo_old_maxB = ca->old_maxB; |
michael@0 | 1955 | ca->last_cong = sctp_get_tick_count(); |
michael@0 | 1956 | } |
michael@0 | 1957 | |
michael@0 | 1958 | #ifdef SCTP_NOT_USED |
michael@0 | 1959 | |
michael@0 | 1960 | static uint32_t |
michael@0 | 1961 | htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 1962 | { |
michael@0 | 1963 | net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong; |
michael@0 | 1964 | net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT; |
michael@0 | 1965 | net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB; |
michael@0 | 1966 | return (max(net->cwnd, ((net->ssthresh/net->mtu<<7)/net->cc_mod.htcp_ca.beta)*net->mtu)); |
michael@0 | 1967 | } |
michael@0 | 1968 | |
michael@0 | 1969 | #endif |
michael@0 | 1970 | |
michael@0 | 1971 | static inline void |
michael@0 | 1972 | measure_rtt(struct sctp_nets *net) |
michael@0 | 1973 | { |
michael@0 | 1974 | uint32_t srtt = net->lastsa>>SCTP_RTT_SHIFT; |
michael@0 | 1975 | |
michael@0 | 1976 | /* keep track of minimum RTT seen so far, minRTT is zero at first */ |
michael@0 | 1977 | if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT) |
michael@0 | 1978 | net->cc_mod.htcp_ca.minRTT = srtt; |
michael@0 | 1979 | |
michael@0 | 1980 | /* max RTT */ |
michael@0 | 1981 | if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) { |
michael@0 | 1982 | if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT) |
michael@0 | 1983 | net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT; |
michael@0 | 1984 | if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20)) |
michael@0 | 1985 | net->cc_mod.htcp_ca.maxRTT = srtt; |
michael@0 | 1986 | } |
michael@0 | 1987 | } |
michael@0 | 1988 | |
michael@0 | 1989 | static void |
michael@0 | 1990 | measure_achieved_throughput(struct sctp_nets *net) |
michael@0 | 1991 | { |
michael@0 | 1992 | uint32_t now = sctp_get_tick_count(); |
michael@0 | 1993 | |
michael@0 | 1994 | if (net->fast_retran_ip == 0) |
michael@0 | 1995 | net->cc_mod.htcp_ca.bytes_acked = net->net_ack; |
michael@0 | 1996 | |
michael@0 | 1997 | if (!use_bandwidth_switch) |
michael@0 | 1998 | return; |
michael@0 | 1999 | |
michael@0 | 2000 | /* achieved throughput calculations */ |
michael@0 | 2001 | /* JRS - not 100% sure of this statement */ |
michael@0 | 2002 | if (net->fast_retran_ip == 1) { |
michael@0 | 2003 | net->cc_mod.htcp_ca.bytecount = 0; |
michael@0 | 2004 | net->cc_mod.htcp_ca.lasttime = now; |
michael@0 | 2005 | return; |
michael@0 | 2006 | } |
michael@0 | 2007 | |
michael@0 | 2008 | net->cc_mod.htcp_ca.bytecount += net->net_ack; |
michael@0 | 2009 | 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 | 2010 | (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) && |
michael@0 | 2011 | (net->cc_mod.htcp_ca.minRTT > 0)) { |
michael@0 | 2012 | uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount/net->mtu*hz/(now - net->cc_mod.htcp_ca.lasttime); |
michael@0 | 2013 | |
michael@0 | 2014 | if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) { |
michael@0 | 2015 | /* just after backoff */ |
michael@0 | 2016 | net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi; |
michael@0 | 2017 | } else { |
michael@0 | 2018 | net->cc_mod.htcp_ca.Bi = (3*net->cc_mod.htcp_ca.Bi + cur_Bi)/4; |
michael@0 | 2019 | if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB) |
michael@0 | 2020 | net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi; |
michael@0 | 2021 | if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB) |
michael@0 | 2022 | net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB; |
michael@0 | 2023 | } |
michael@0 | 2024 | net->cc_mod.htcp_ca.bytecount = 0; |
michael@0 | 2025 | net->cc_mod.htcp_ca.lasttime = now; |
michael@0 | 2026 | } |
michael@0 | 2027 | } |
michael@0 | 2028 | |
michael@0 | 2029 | static inline void |
michael@0 | 2030 | htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT) |
michael@0 | 2031 | { |
michael@0 | 2032 | if (use_bandwidth_switch) { |
michael@0 | 2033 | uint32_t maxB = ca->maxB; |
michael@0 | 2034 | uint32_t old_maxB = ca->old_maxB; |
michael@0 | 2035 | ca->old_maxB = ca->maxB; |
michael@0 | 2036 | |
michael@0 | 2037 | if (!between(5*maxB, 4*old_maxB, 6*old_maxB)) { |
michael@0 | 2038 | ca->beta = BETA_MIN; |
michael@0 | 2039 | ca->modeswitch = 0; |
michael@0 | 2040 | return; |
michael@0 | 2041 | } |
michael@0 | 2042 | } |
michael@0 | 2043 | |
michael@0 | 2044 | if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) { |
michael@0 | 2045 | ca->beta = (minRTT<<7)/maxRTT; |
michael@0 | 2046 | if (ca->beta < BETA_MIN) |
michael@0 | 2047 | ca->beta = BETA_MIN; |
michael@0 | 2048 | else if (ca->beta > BETA_MAX) |
michael@0 | 2049 | ca->beta = BETA_MAX; |
michael@0 | 2050 | } else { |
michael@0 | 2051 | ca->beta = BETA_MIN; |
michael@0 | 2052 | ca->modeswitch = 1; |
michael@0 | 2053 | } |
michael@0 | 2054 | } |
michael@0 | 2055 | |
michael@0 | 2056 | static inline void |
michael@0 | 2057 | htcp_alpha_update(struct htcp *ca) |
michael@0 | 2058 | { |
michael@0 | 2059 | uint32_t minRTT = ca->minRTT; |
michael@0 | 2060 | uint32_t factor = 1; |
michael@0 | 2061 | uint32_t diff = htcp_cong_time(ca); |
michael@0 | 2062 | |
michael@0 | 2063 | if (diff > (uint32_t)hz) { |
michael@0 | 2064 | diff -= hz; |
michael@0 | 2065 | factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/hz))/hz; |
michael@0 | 2066 | } |
michael@0 | 2067 | |
michael@0 | 2068 | if (use_rtt_scaling && minRTT) { |
michael@0 | 2069 | uint32_t scale = (hz<<3)/(10*minRTT); |
michael@0 | 2070 | scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */ |
michael@0 | 2071 | factor = (factor<<3)/scale; |
michael@0 | 2072 | if (!factor) |
michael@0 | 2073 | factor = 1; |
michael@0 | 2074 | } |
michael@0 | 2075 | |
michael@0 | 2076 | ca->alpha = 2*factor*((1<<7)-ca->beta); |
michael@0 | 2077 | if (!ca->alpha) |
michael@0 | 2078 | ca->alpha = ALPHA_BASE; |
michael@0 | 2079 | } |
michael@0 | 2080 | |
michael@0 | 2081 | /* After we have the rtt data to calculate beta, we'd still prefer to wait one |
michael@0 | 2082 | * rtt before we adjust our beta to ensure we are working from a consistent |
michael@0 | 2083 | * data. |
michael@0 | 2084 | * |
michael@0 | 2085 | * This function should be called when we hit a congestion event since only at |
michael@0 | 2086 | * that point do we really have a real sense of maxRTT (the queues en route |
michael@0 | 2087 | * were getting just too full now). |
michael@0 | 2088 | */ |
michael@0 | 2089 | static void |
michael@0 | 2090 | htcp_param_update(struct sctp_nets *net) |
michael@0 | 2091 | { |
michael@0 | 2092 | uint32_t minRTT = net->cc_mod.htcp_ca.minRTT; |
michael@0 | 2093 | uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT; |
michael@0 | 2094 | |
michael@0 | 2095 | htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT); |
michael@0 | 2096 | htcp_alpha_update(&net->cc_mod.htcp_ca); |
michael@0 | 2097 | |
michael@0 | 2098 | /* add slowly fading memory for maxRTT to accommodate routing changes etc */ |
michael@0 | 2099 | if (minRTT > 0 && maxRTT > minRTT) |
michael@0 | 2100 | net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT-minRTT)*95)/100; |
michael@0 | 2101 | } |
michael@0 | 2102 | |
michael@0 | 2103 | static uint32_t |
michael@0 | 2104 | htcp_recalc_ssthresh(struct sctp_nets *net) |
michael@0 | 2105 | { |
michael@0 | 2106 | htcp_param_update(net); |
michael@0 | 2107 | return (max(((net->cwnd/net->mtu * net->cc_mod.htcp_ca.beta) >> 7)*net->mtu, 2U*net->mtu)); |
michael@0 | 2108 | } |
michael@0 | 2109 | |
michael@0 | 2110 | static void |
michael@0 | 2111 | htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 2112 | { |
michael@0 | 2113 | /*- |
michael@0 | 2114 | * How to handle these functions? |
michael@0 | 2115 | * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question. |
michael@0 | 2116 | * return; |
michael@0 | 2117 | */ |
michael@0 | 2118 | if (net->cwnd <= net->ssthresh) { |
michael@0 | 2119 | /* We are in slow start */ |
michael@0 | 2120 | if (net->flight_size + net->net_ack >= net->cwnd) { |
michael@0 | 2121 | if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) { |
michael@0 | 2122 | net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)); |
michael@0 | 2123 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2124 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 2125 | SCTP_CWND_LOG_FROM_SS); |
michael@0 | 2126 | } |
michael@0 | 2127 | |
michael@0 | 2128 | } else { |
michael@0 | 2129 | net->cwnd += net->net_ack; |
michael@0 | 2130 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2131 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 2132 | SCTP_CWND_LOG_FROM_SS); |
michael@0 | 2133 | } |
michael@0 | 2134 | |
michael@0 | 2135 | } |
michael@0 | 2136 | } else { |
michael@0 | 2137 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 2138 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 2139 | SCTP_CWND_LOG_NOADV_SS); |
michael@0 | 2140 | } |
michael@0 | 2141 | } |
michael@0 | 2142 | } else { |
michael@0 | 2143 | measure_rtt(net); |
michael@0 | 2144 | |
michael@0 | 2145 | /* In dangerous area, increase slowly. |
michael@0 | 2146 | * In theory this is net->cwnd += alpha / net->cwnd |
michael@0 | 2147 | */ |
michael@0 | 2148 | /* What is snd_cwnd_cnt?? */ |
michael@0 | 2149 | if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) { |
michael@0 | 2150 | /*- |
michael@0 | 2151 | * Does SCTP have a cwnd clamp? |
michael@0 | 2152 | * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS). |
michael@0 | 2153 | */ |
michael@0 | 2154 | net->cwnd += net->mtu; |
michael@0 | 2155 | net->partial_bytes_acked = 0; |
michael@0 | 2156 | htcp_alpha_update(&net->cc_mod.htcp_ca); |
michael@0 | 2157 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2158 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 2159 | SCTP_CWND_LOG_FROM_CA); |
michael@0 | 2160 | } |
michael@0 | 2161 | } else { |
michael@0 | 2162 | net->partial_bytes_acked += net->net_ack; |
michael@0 | 2163 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 2164 | sctp_log_cwnd(stcb, net, net->net_ack, |
michael@0 | 2165 | SCTP_CWND_LOG_NOADV_CA); |
michael@0 | 2166 | } |
michael@0 | 2167 | } |
michael@0 | 2168 | |
michael@0 | 2169 | net->cc_mod.htcp_ca.bytes_acked = net->mtu; |
michael@0 | 2170 | } |
michael@0 | 2171 | } |
michael@0 | 2172 | |
michael@0 | 2173 | #ifdef SCTP_NOT_USED |
michael@0 | 2174 | /* Lower bound on congestion window. */ |
michael@0 | 2175 | static uint32_t |
michael@0 | 2176 | htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 2177 | { |
michael@0 | 2178 | return (net->ssthresh); |
michael@0 | 2179 | } |
michael@0 | 2180 | #endif |
michael@0 | 2181 | |
michael@0 | 2182 | static void |
michael@0 | 2183 | htcp_init(struct sctp_nets *net) |
michael@0 | 2184 | { |
michael@0 | 2185 | memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp)); |
michael@0 | 2186 | net->cc_mod.htcp_ca.alpha = ALPHA_BASE; |
michael@0 | 2187 | net->cc_mod.htcp_ca.beta = BETA_MIN; |
michael@0 | 2188 | net->cc_mod.htcp_ca.bytes_acked = net->mtu; |
michael@0 | 2189 | net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count(); |
michael@0 | 2190 | } |
michael@0 | 2191 | |
michael@0 | 2192 | static void |
michael@0 | 2193 | sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 2194 | { |
michael@0 | 2195 | /* |
michael@0 | 2196 | * We take the max of the burst limit times a MTU or the |
michael@0 | 2197 | * INITIAL_CWND. We then limit this to 4 MTU's of sending. |
michael@0 | 2198 | */ |
michael@0 | 2199 | net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); |
michael@0 | 2200 | net->ssthresh = stcb->asoc.peers_rwnd; |
michael@0 | 2201 | htcp_init(net); |
michael@0 | 2202 | |
michael@0 | 2203 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) { |
michael@0 | 2204 | sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION); |
michael@0 | 2205 | } |
michael@0 | 2206 | } |
michael@0 | 2207 | |
michael@0 | 2208 | static void |
michael@0 | 2209 | sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb, |
michael@0 | 2210 | struct sctp_association *asoc, |
michael@0 | 2211 | int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) |
michael@0 | 2212 | { |
michael@0 | 2213 | struct sctp_nets *net; |
michael@0 | 2214 | |
michael@0 | 2215 | /******************************/ |
michael@0 | 2216 | /* update cwnd and Early FR */ |
michael@0 | 2217 | /******************************/ |
michael@0 | 2218 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 2219 | |
michael@0 | 2220 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 2221 | /* |
michael@0 | 2222 | * CMT fast recovery code. Need to debug. |
michael@0 | 2223 | */ |
michael@0 | 2224 | if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) { |
michael@0 | 2225 | if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) || |
michael@0 | 2226 | SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) { |
michael@0 | 2227 | net->will_exit_fast_recovery = 1; |
michael@0 | 2228 | } |
michael@0 | 2229 | } |
michael@0 | 2230 | #endif |
michael@0 | 2231 | /* if nothing was acked on this destination skip it */ |
michael@0 | 2232 | if (net->net_ack == 0) { |
michael@0 | 2233 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 2234 | sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK); |
michael@0 | 2235 | } |
michael@0 | 2236 | continue; |
michael@0 | 2237 | } |
michael@0 | 2238 | #ifdef JANA_CMT_FAST_RECOVERY |
michael@0 | 2239 | /* CMT fast recovery code |
michael@0 | 2240 | */ |
michael@0 | 2241 | /* |
michael@0 | 2242 | if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) { |
michael@0 | 2243 | @@@ Do something |
michael@0 | 2244 | } |
michael@0 | 2245 | else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) { |
michael@0 | 2246 | */ |
michael@0 | 2247 | #endif |
michael@0 | 2248 | |
michael@0 | 2249 | if (asoc->fast_retran_loss_recovery && |
michael@0 | 2250 | will_exit == 0 && |
michael@0 | 2251 | (asoc->sctp_cmt_on_off == 0)) { |
michael@0 | 2252 | /* |
michael@0 | 2253 | * If we are in loss recovery we skip any cwnd |
michael@0 | 2254 | * update |
michael@0 | 2255 | */ |
michael@0 | 2256 | return; |
michael@0 | 2257 | } |
michael@0 | 2258 | /* |
michael@0 | 2259 | * CMT: CUC algorithm. Update cwnd if pseudo-cumack has |
michael@0 | 2260 | * moved. |
michael@0 | 2261 | */ |
michael@0 | 2262 | if (accum_moved || |
michael@0 | 2263 | ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) { |
michael@0 | 2264 | htcp_cong_avoid(stcb, net); |
michael@0 | 2265 | measure_achieved_throughput(net); |
michael@0 | 2266 | } else { |
michael@0 | 2267 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 2268 | sctp_log_cwnd(stcb, net, net->mtu, |
michael@0 | 2269 | SCTP_CWND_LOG_NO_CUMACK); |
michael@0 | 2270 | } |
michael@0 | 2271 | } |
michael@0 | 2272 | } |
michael@0 | 2273 | } |
michael@0 | 2274 | |
michael@0 | 2275 | static void |
michael@0 | 2276 | sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb, |
michael@0 | 2277 | struct sctp_association *asoc) |
michael@0 | 2278 | { |
michael@0 | 2279 | struct sctp_nets *net; |
michael@0 | 2280 | /* |
michael@0 | 2281 | * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) && |
michael@0 | 2282 | * (net->fast_retran_loss_recovery == 0))) |
michael@0 | 2283 | */ |
michael@0 | 2284 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 2285 | if ((asoc->fast_retran_loss_recovery == 0) || |
michael@0 | 2286 | (asoc->sctp_cmt_on_off > 0)) { |
michael@0 | 2287 | /* out of a RFC2582 Fast recovery window? */ |
michael@0 | 2288 | if (net->net_ack > 0) { |
michael@0 | 2289 | /* |
michael@0 | 2290 | * per section 7.2.3, are there any |
michael@0 | 2291 | * destinations that had a fast retransmit |
michael@0 | 2292 | * to them. If so what we need to do is |
michael@0 | 2293 | * adjust ssthresh and cwnd. |
michael@0 | 2294 | */ |
michael@0 | 2295 | struct sctp_tmit_chunk *lchk; |
michael@0 | 2296 | int old_cwnd = net->cwnd; |
michael@0 | 2297 | |
michael@0 | 2298 | /* JRS - reset as if state were changed */ |
michael@0 | 2299 | htcp_reset(&net->cc_mod.htcp_ca); |
michael@0 | 2300 | net->ssthresh = htcp_recalc_ssthresh(net); |
michael@0 | 2301 | net->cwnd = net->ssthresh; |
michael@0 | 2302 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2303 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), |
michael@0 | 2304 | SCTP_CWND_LOG_FROM_FR); |
michael@0 | 2305 | } |
michael@0 | 2306 | lchk = TAILQ_FIRST(&asoc->send_queue); |
michael@0 | 2307 | |
michael@0 | 2308 | net->partial_bytes_acked = 0; |
michael@0 | 2309 | /* Turn on fast recovery window */ |
michael@0 | 2310 | asoc->fast_retran_loss_recovery = 1; |
michael@0 | 2311 | if (lchk == NULL) { |
michael@0 | 2312 | /* Mark end of the window */ |
michael@0 | 2313 | asoc->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 2314 | } else { |
michael@0 | 2315 | asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 2316 | } |
michael@0 | 2317 | |
michael@0 | 2318 | /* |
michael@0 | 2319 | * CMT fast recovery -- per destination |
michael@0 | 2320 | * recovery variable. |
michael@0 | 2321 | */ |
michael@0 | 2322 | net->fast_retran_loss_recovery = 1; |
michael@0 | 2323 | |
michael@0 | 2324 | if (lchk == NULL) { |
michael@0 | 2325 | /* Mark end of the window */ |
michael@0 | 2326 | net->fast_recovery_tsn = asoc->sending_seq - 1; |
michael@0 | 2327 | } else { |
michael@0 | 2328 | net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1; |
michael@0 | 2329 | } |
michael@0 | 2330 | |
michael@0 | 2331 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, |
michael@0 | 2332 | stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32); |
michael@0 | 2333 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, |
michael@0 | 2334 | stcb->sctp_ep, stcb, net); |
michael@0 | 2335 | } |
michael@0 | 2336 | } else if (net->net_ack > 0) { |
michael@0 | 2337 | /* |
michael@0 | 2338 | * Mark a peg that we WOULD have done a cwnd |
michael@0 | 2339 | * reduction but RFC2582 prevented this action. |
michael@0 | 2340 | */ |
michael@0 | 2341 | SCTP_STAT_INCR(sctps_fastretransinrtt); |
michael@0 | 2342 | } |
michael@0 | 2343 | } |
michael@0 | 2344 | } |
michael@0 | 2345 | |
michael@0 | 2346 | static void |
michael@0 | 2347 | sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb, |
michael@0 | 2348 | struct sctp_nets *net) |
michael@0 | 2349 | { |
michael@0 | 2350 | int old_cwnd = net->cwnd; |
michael@0 | 2351 | |
michael@0 | 2352 | /* JRS - reset as if the state were being changed to timeout */ |
michael@0 | 2353 | htcp_reset(&net->cc_mod.htcp_ca); |
michael@0 | 2354 | net->ssthresh = htcp_recalc_ssthresh(net); |
michael@0 | 2355 | net->cwnd = net->mtu; |
michael@0 | 2356 | net->partial_bytes_acked = 0; |
michael@0 | 2357 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2358 | sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX); |
michael@0 | 2359 | } |
michael@0 | 2360 | } |
michael@0 | 2361 | |
michael@0 | 2362 | static void |
michael@0 | 2363 | sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, |
michael@0 | 2364 | struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED) |
michael@0 | 2365 | { |
michael@0 | 2366 | int old_cwnd; |
michael@0 | 2367 | old_cwnd = net->cwnd; |
michael@0 | 2368 | |
michael@0 | 2369 | /* JRS - reset hctp as if state changed */ |
michael@0 | 2370 | if (in_window == 0) { |
michael@0 | 2371 | htcp_reset(&net->cc_mod.htcp_ca); |
michael@0 | 2372 | SCTP_STAT_INCR(sctps_ecnereducedcwnd); |
michael@0 | 2373 | net->ssthresh = htcp_recalc_ssthresh(net); |
michael@0 | 2374 | if (net->ssthresh < net->mtu) { |
michael@0 | 2375 | net->ssthresh = net->mtu; |
michael@0 | 2376 | /* here back off the timer as well, to slow us down */ |
michael@0 | 2377 | net->RTO <<= 1; |
michael@0 | 2378 | } |
michael@0 | 2379 | net->cwnd = net->ssthresh; |
michael@0 | 2380 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { |
michael@0 | 2381 | sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); |
michael@0 | 2382 | } |
michael@0 | 2383 | } |
michael@0 | 2384 | } |
michael@0 | 2385 | |
michael@0 | 2386 | struct sctp_cc_functions sctp_cc_functions[] = { |
michael@0 | 2387 | { |
michael@0 | 2388 | #if defined(__Windows__) || defined(__Userspace_os_Windows) |
michael@0 | 2389 | sctp_set_initial_cc_param, |
michael@0 | 2390 | sctp_cwnd_update_after_sack, |
michael@0 | 2391 | sctp_cwnd_update_exit_pf_common, |
michael@0 | 2392 | sctp_cwnd_update_after_fr, |
michael@0 | 2393 | sctp_cwnd_update_after_timeout, |
michael@0 | 2394 | sctp_cwnd_update_after_ecn_echo, |
michael@0 | 2395 | sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2396 | sctp_cwnd_update_after_output, |
michael@0 | 2397 | #else |
michael@0 | 2398 | .sctp_set_initial_cc_param = sctp_set_initial_cc_param, |
michael@0 | 2399 | .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack, |
michael@0 | 2400 | .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, |
michael@0 | 2401 | .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, |
michael@0 | 2402 | .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, |
michael@0 | 2403 | .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, |
michael@0 | 2404 | .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2405 | .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, |
michael@0 | 2406 | #endif |
michael@0 | 2407 | }, |
michael@0 | 2408 | { |
michael@0 | 2409 | #if defined(__Windows__) || defined(__Userspace_os_Windows) |
michael@0 | 2410 | sctp_set_initial_cc_param, |
michael@0 | 2411 | sctp_hs_cwnd_update_after_sack, |
michael@0 | 2412 | sctp_cwnd_update_exit_pf_common, |
michael@0 | 2413 | sctp_hs_cwnd_update_after_fr, |
michael@0 | 2414 | sctp_cwnd_update_after_timeout, |
michael@0 | 2415 | sctp_cwnd_update_after_ecn_echo, |
michael@0 | 2416 | sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2417 | sctp_cwnd_update_after_output, |
michael@0 | 2418 | #else |
michael@0 | 2419 | .sctp_set_initial_cc_param = sctp_set_initial_cc_param, |
michael@0 | 2420 | .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack, |
michael@0 | 2421 | .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, |
michael@0 | 2422 | .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr, |
michael@0 | 2423 | .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, |
michael@0 | 2424 | .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo, |
michael@0 | 2425 | .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2426 | .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, |
michael@0 | 2427 | #endif |
michael@0 | 2428 | }, |
michael@0 | 2429 | { |
michael@0 | 2430 | #if defined(__Windows__) || defined(__Userspace_os_Windows) |
michael@0 | 2431 | sctp_htcp_set_initial_cc_param, |
michael@0 | 2432 | sctp_htcp_cwnd_update_after_sack, |
michael@0 | 2433 | sctp_cwnd_update_exit_pf_common, |
michael@0 | 2434 | sctp_htcp_cwnd_update_after_fr, |
michael@0 | 2435 | sctp_htcp_cwnd_update_after_timeout, |
michael@0 | 2436 | sctp_htcp_cwnd_update_after_ecn_echo, |
michael@0 | 2437 | sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2438 | sctp_cwnd_update_after_output, |
michael@0 | 2439 | #else |
michael@0 | 2440 | .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param, |
michael@0 | 2441 | .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack, |
michael@0 | 2442 | .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, |
michael@0 | 2443 | .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr, |
michael@0 | 2444 | .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout, |
michael@0 | 2445 | .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo, |
michael@0 | 2446 | .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2447 | .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, |
michael@0 | 2448 | #endif |
michael@0 | 2449 | }, |
michael@0 | 2450 | { |
michael@0 | 2451 | #if defined(__Windows__) || defined(__Userspace_os_Windows) |
michael@0 | 2452 | sctp_set_rtcc_initial_cc_param, |
michael@0 | 2453 | sctp_cwnd_update_rtcc_after_sack, |
michael@0 | 2454 | sctp_cwnd_update_exit_pf_common, |
michael@0 | 2455 | sctp_cwnd_update_after_fr, |
michael@0 | 2456 | sctp_cwnd_update_after_timeout, |
michael@0 | 2457 | sctp_cwnd_update_rtcc_after_ecn_echo, |
michael@0 | 2458 | sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2459 | sctp_cwnd_update_after_output, |
michael@0 | 2460 | sctp_cwnd_update_rtcc_packet_transmitted, |
michael@0 | 2461 | sctp_cwnd_update_rtcc_tsn_acknowledged, |
michael@0 | 2462 | sctp_cwnd_new_rtcc_transmission_begins, |
michael@0 | 2463 | sctp_cwnd_prepare_rtcc_net_for_sack, |
michael@0 | 2464 | sctp_cwnd_rtcc_socket_option, |
michael@0 | 2465 | sctp_rtt_rtcc_calculated |
michael@0 | 2466 | #else |
michael@0 | 2467 | .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param, |
michael@0 | 2468 | .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack, |
michael@0 | 2469 | .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common, |
michael@0 | 2470 | .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr, |
michael@0 | 2471 | .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout, |
michael@0 | 2472 | .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo, |
michael@0 | 2473 | .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped, |
michael@0 | 2474 | .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output, |
michael@0 | 2475 | .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted, |
michael@0 | 2476 | .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged, |
michael@0 | 2477 | .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins, |
michael@0 | 2478 | .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack, |
michael@0 | 2479 | .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option, |
michael@0 | 2480 | .sctp_rtt_calculated = sctp_rtt_rtcc_calculated |
michael@0 | 2481 | #endif |
michael@0 | 2482 | } |
michael@0 | 2483 | }; |