2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <netinet/sctp_os.h>
36 #include <netinet/sctp_var.h>
37 #include <netinet/sctp_sysctl.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctputil.h>
41 #include <netinet/sctp_output.h>
42 #include <netinet/sctp_input.h>
43 #include <netinet/sctp_indata.h>
44 #include <netinet/sctp_uio.h>
45 #include <netinet/sctp_timer.h>
46 #include <netinet/sctp_auth.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctp_kdtrace.h>
50 #define SHIFT_MPTCP_MULTI_N 40
51 #define SHIFT_MPTCP_MULTI_Z 16
52 #define SHIFT_MPTCP_MULTI 8
57 #define __dtrace __unused
61 sctp_enforce_cwnd_limit(struct sctp_association *assoc, struct sctp_nets *net)
63 if ((assoc->max_cwnd > 0) &&
64 (net->cwnd > assoc->max_cwnd) &&
65 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
66 net->cwnd = assoc->max_cwnd;
67 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
68 net->cwnd = net->mtu - sizeof(struct sctphdr);
74 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
76 struct sctp_association *assoc;
80 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
81 if (cwnd_in_mtu == 0) {
82 /* Using 0 means that the value of RFC 4960 is used. */
83 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
86 * We take the minimum of the burst limit and the initial
89 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
90 cwnd_in_mtu = assoc->max_burst;
91 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
93 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
94 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
95 /* In case of resource pooling initialize appropriately */
96 net->cwnd /= assoc->numnets;
97 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
98 net->cwnd = net->mtu - sizeof(struct sctphdr);
101 sctp_enforce_cwnd_limit(assoc, net);
102 net->ssthresh = assoc->peers_rwnd;
103 SDT_PROBE5(sctp, cwnd, net, init,
104 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
106 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
107 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
108 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
113 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
114 struct sctp_association *asoc)
116 struct sctp_nets *net;
117 uint32_t t_ssthresh, t_cwnd;
118 uint64_t t_ucwnd_sbw;
120 /* MT FIXME: Don't compute this over and over again */
124 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
125 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
126 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
127 t_ssthresh += net->ssthresh;
129 if (net->lastsa > 0) {
130 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa;
133 if (t_ucwnd_sbw == 0) {
139 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
140 * (net->fast_retran_loss_recovery == 0)))
142 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
143 if ((asoc->fast_retran_loss_recovery == 0) ||
144 (asoc->sctp_cmt_on_off > 0)) {
145 /* out of a RFC2582 Fast recovery window? */
146 if (net->net_ack > 0) {
148 * per section 7.2.3, are there any
149 * destinations that had a fast retransmit
150 * to them. If so what we need to do is
151 * adjust ssthresh and cwnd.
153 struct sctp_tmit_chunk *lchk;
154 int old_cwnd = net->cwnd;
156 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
157 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
158 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
159 net->ssthresh = (uint32_t)(((uint64_t)4 *
161 (uint64_t)net->ssthresh) /
162 (uint64_t)t_ssthresh);
164 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
169 * lastsa>>3; we don't need
176 * Short Version => Equal to
179 net->ssthresh = (uint32_t)(((uint64_t)4 *
181 (uint64_t)net->cwnd) /
184 /* INCREASE FACTOR */ ;
186 if ((net->cwnd > t_cwnd / 2) &&
187 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
188 net->ssthresh = net->cwnd - t_cwnd / 2;
190 if (net->ssthresh < net->mtu) {
191 net->ssthresh = net->mtu;
194 net->ssthresh = net->cwnd / 2;
195 if (net->ssthresh < (net->mtu * 2)) {
196 net->ssthresh = 2 * net->mtu;
199 net->cwnd = net->ssthresh;
200 sctp_enforce_cwnd_limit(asoc, net);
201 SDT_PROBE5(sctp, cwnd, net, fr,
202 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
203 old_cwnd, net->cwnd);
204 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
205 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
206 SCTP_CWND_LOG_FROM_FR);
208 lchk = TAILQ_FIRST(&asoc->send_queue);
210 net->partial_bytes_acked = 0;
211 /* Turn on fast recovery window */
212 asoc->fast_retran_loss_recovery = 1;
214 /* Mark end of the window */
215 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
217 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
221 * CMT fast recovery -- per destination
224 net->fast_retran_loss_recovery = 1;
227 /* Mark end of the window */
228 net->fast_recovery_tsn = asoc->sending_seq - 1;
230 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
233 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
234 stcb->sctp_ep, stcb, net,
235 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_1);
236 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
237 stcb->sctp_ep, stcb, net);
239 } else if (net->net_ack > 0) {
241 * Mark a peg that we WOULD have done a cwnd
242 * reduction but RFC2582 prevented this action.
244 SCTP_STAT_INCR(sctps_fastretransinrtt);
249 /* Defines for instantaneous bw decisions */
250 #define SCTP_INST_LOOSING 1 /* Losing to other flows */
251 #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
252 #define SCTP_INST_GAINING 3 /* Gaining, step down possible */
255 cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
256 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
258 uint64_t oth __dtrace, probepoint __dtrace;
260 probepoint = (((uint64_t)net->cwnd) << 32);
261 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
263 * rtt increased we don't update bw.. so we don't update the
267 probepoint |= ((5 << 16) | 1);
268 SDT_PROBE5(sctp, cwnd, net, rttvar,
270 ((net->cc_mod.rtcc.lbw << 32) | nbw),
271 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
274 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
275 if (net->cc_mod.rtcc.last_step_state == 5)
276 net->cc_mod.rtcc.step_cnt++;
278 net->cc_mod.rtcc.step_cnt = 1;
279 net->cc_mod.rtcc.last_step_state = 5;
280 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
281 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
282 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
283 /* Try a step down */
284 oth = net->cc_mod.rtcc.vol_reduce;
286 oth |= net->cc_mod.rtcc.step_cnt;
288 oth |= net->cc_mod.rtcc.last_step_state;
289 SDT_PROBE5(sctp, cwnd, net, rttstep,
291 ((net->cc_mod.rtcc.lbw << 32) | nbw),
292 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
295 if (net->cwnd > (4 * net->mtu)) {
296 net->cwnd -= net->mtu;
297 net->cc_mod.rtcc.vol_reduce++;
299 net->cc_mod.rtcc.step_cnt = 0;
305 if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
307 * rtt decreased, there could be more room. we update both
308 * the bw and the rtt here to lock this in as a good step
312 probepoint |= ((6 << 16) | 0);
313 SDT_PROBE5(sctp, cwnd, net, rttvar,
315 ((net->cc_mod.rtcc.lbw << 32) | nbw),
316 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
319 if (net->cc_mod.rtcc.steady_step) {
320 oth = net->cc_mod.rtcc.vol_reduce;
322 oth |= net->cc_mod.rtcc.step_cnt;
324 oth |= net->cc_mod.rtcc.last_step_state;
325 SDT_PROBE5(sctp, cwnd, net, rttstep,
327 ((net->cc_mod.rtcc.lbw << 32) | nbw),
328 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
331 if ((net->cc_mod.rtcc.last_step_state == 5) &&
332 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
333 /* Step down worked */
334 net->cc_mod.rtcc.step_cnt = 0;
337 net->cc_mod.rtcc.last_step_state = 6;
338 net->cc_mod.rtcc.step_cnt = 0;
341 net->cc_mod.rtcc.lbw = nbw;
342 net->cc_mod.rtcc.lbw_rtt = net->rtt;
343 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
344 if (inst_ind == SCTP_INST_GAINING)
346 else if (inst_ind == SCTP_INST_NEUTRAL)
352 * Ok bw and rtt remained the same .. no update to any
355 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
356 SDT_PROBE5(sctp, cwnd, net, rttvar,
358 ((net->cc_mod.rtcc.lbw << 32) | nbw),
359 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
362 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
363 if (net->cc_mod.rtcc.last_step_state == 5)
364 net->cc_mod.rtcc.step_cnt++;
366 net->cc_mod.rtcc.step_cnt = 1;
367 net->cc_mod.rtcc.last_step_state = 5;
368 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
369 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
370 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
371 /* Try a step down */
372 if (net->cwnd > (4 * net->mtu)) {
373 net->cwnd -= net->mtu;
374 net->cc_mod.rtcc.vol_reduce++;
377 net->cc_mod.rtcc.step_cnt = 0;
381 if (inst_ind == SCTP_INST_GAINING)
383 else if (inst_ind == SCTP_INST_NEUTRAL)
386 return ((int)net->cc_mod.rtcc.ret_from_eq);
390 cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
391 uint64_t vtag, uint8_t inst_ind)
393 uint64_t oth __dtrace, probepoint __dtrace;
395 /* Bandwidth decreased. */
396 probepoint = (((uint64_t)net->cwnd) << 32);
397 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
399 /* Did we add more */
400 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
401 (inst_ind != SCTP_INST_LOOSING)) {
402 /* We caused it maybe.. back off? */
404 probepoint |= ((1 << 16) | 1);
405 SDT_PROBE5(sctp, cwnd, net, rttvar,
407 ((net->cc_mod.rtcc.lbw << 32) | nbw),
408 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
411 if (net->cc_mod.rtcc.ret_from_eq) {
413 * Switch over to CA if we are less
416 net->ssthresh = net->cwnd - 1;
417 net->partial_bytes_acked = 0;
422 probepoint |= ((2 << 16) | 0);
423 SDT_PROBE5(sctp, cwnd, net, rttvar,
425 ((net->cc_mod.rtcc.lbw << 32) | nbw),
426 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
429 /* Someone else - fight for more? */
430 if (net->cc_mod.rtcc.steady_step) {
431 oth = net->cc_mod.rtcc.vol_reduce;
433 oth |= net->cc_mod.rtcc.step_cnt;
435 oth |= net->cc_mod.rtcc.last_step_state;
436 SDT_PROBE5(sctp, cwnd, net, rttstep,
438 ((net->cc_mod.rtcc.lbw << 32) | nbw),
439 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
443 * Did we voluntarily give up some? if so take one
446 if ((net->cc_mod.rtcc.vol_reduce) &&
447 (inst_ind != SCTP_INST_GAINING)) {
448 net->cwnd += net->mtu;
449 sctp_enforce_cwnd_limit(&stcb->asoc, net);
450 net->cc_mod.rtcc.vol_reduce--;
452 net->cc_mod.rtcc.last_step_state = 2;
453 net->cc_mod.rtcc.step_cnt = 0;
456 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
457 /* bw & rtt decreased */
459 probepoint |= ((3 << 16) | 0);
460 SDT_PROBE5(sctp, cwnd, net, rttvar,
462 ((net->cc_mod.rtcc.lbw << 32) | nbw),
463 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
466 if (net->cc_mod.rtcc.steady_step) {
467 oth = net->cc_mod.rtcc.vol_reduce;
469 oth |= net->cc_mod.rtcc.step_cnt;
471 oth |= net->cc_mod.rtcc.last_step_state;
472 SDT_PROBE5(sctp, cwnd, net, rttstep,
474 ((net->cc_mod.rtcc.lbw << 32) | nbw),
475 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
478 if ((net->cc_mod.rtcc.vol_reduce) &&
479 (inst_ind != SCTP_INST_GAINING)) {
480 net->cwnd += net->mtu;
481 sctp_enforce_cwnd_limit(&stcb->asoc, net);
482 net->cc_mod.rtcc.vol_reduce--;
484 net->cc_mod.rtcc.last_step_state = 3;
485 net->cc_mod.rtcc.step_cnt = 0;
489 /* The bw decreased but rtt stayed the same */
491 probepoint |= ((4 << 16) | 0);
492 SDT_PROBE5(sctp, cwnd, net, rttvar,
494 ((net->cc_mod.rtcc.lbw << 32) | nbw),
495 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
498 if (net->cc_mod.rtcc.steady_step) {
499 oth = net->cc_mod.rtcc.vol_reduce;
501 oth |= net->cc_mod.rtcc.step_cnt;
503 oth |= net->cc_mod.rtcc.last_step_state;
504 SDT_PROBE5(sctp, cwnd, net, rttstep,
506 ((net->cc_mod.rtcc.lbw << 32) | nbw),
507 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
510 if ((net->cc_mod.rtcc.vol_reduce) &&
511 (inst_ind != SCTP_INST_GAINING)) {
512 net->cwnd += net->mtu;
513 sctp_enforce_cwnd_limit(&stcb->asoc, net);
514 net->cc_mod.rtcc.vol_reduce--;
516 net->cc_mod.rtcc.last_step_state = 4;
517 net->cc_mod.rtcc.step_cnt = 0;
520 net->cc_mod.rtcc.lbw = nbw;
521 net->cc_mod.rtcc.lbw_rtt = net->rtt;
522 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
523 if (inst_ind == SCTP_INST_GAINING) {
531 cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
533 uint64_t oth __dtrace, probepoint __dtrace;
536 * BW increased, so update and return 0, since all actions in our
537 * table say to do the normal CC update. Note that we pay no
538 * attention to the inst_ind since our overall sum is increasing.
541 probepoint = (((uint64_t)net->cwnd) << 32);
542 SDT_PROBE5(sctp, cwnd, net, rttvar,
544 ((net->cc_mod.rtcc.lbw << 32) | nbw),
545 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
548 if (net->cc_mod.rtcc.steady_step) {
549 oth = net->cc_mod.rtcc.vol_reduce;
551 oth |= net->cc_mod.rtcc.step_cnt;
553 oth |= net->cc_mod.rtcc.last_step_state;
554 SDT_PROBE5(sctp, cwnd, net, rttstep,
556 ((net->cc_mod.rtcc.lbw << 32) | nbw),
557 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
560 net->cc_mod.rtcc.last_step_state = 0;
561 net->cc_mod.rtcc.step_cnt = 0;
562 net->cc_mod.rtcc.vol_reduce = 0;
564 net->cc_mod.rtcc.lbw = nbw;
565 net->cc_mod.rtcc.lbw_rtt = net->rtt;
566 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
570 /* RTCC Algorithm to limit growth of cwnd, return
571 * true if you want to NOT allow cwnd growth
574 cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
576 uint64_t bw_offset, rtt_offset;
577 uint64_t probepoint __dtrace, rtt, vtag;
578 uint64_t bytes_for_this_rtt, inst_bw;
579 uint64_t div, inst_off;
585 * Here we need to see if we want
586 * to limit cwnd growth due to increase
587 * in overall rtt but no increase in bw.
588 * We use the following table to figure
589 * out what we should do. When we return
590 * 0, cc update goes on as planned. If we
591 * return 1, then no cc update happens and cwnd
592 * stays where it is at.
593 * ----------------------------------
595 * *********************************
596 * INC | INC | return 0
597 * ----------------------------------
598 * INC | SAME | return 0
599 * ----------------------------------
600 * INC | DECR | return 0
601 * ----------------------------------
602 * SAME | INC | return 1
603 * ----------------------------------
604 * SAME | SAME | return 1
605 * ----------------------------------
606 * SAME | DECR | return 0
607 * ----------------------------------
608 * DECR | INC | return 0 or 1 based on if we caused.
609 * ----------------------------------
610 * DECR | SAME | return 0
611 * ----------------------------------
612 * DECR | DECR | return 0
613 * ----------------------------------
615 * We are a bit fuzz on what an increase or
616 * decrease is. For BW it is the same if
617 * it did not change within 1/64th. For
618 * RTT it stayed the same if it did not
619 * change within 1/32nd
621 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
622 rtt = stcb->asoc.my_vtag;
623 vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
624 probepoint = (((uint64_t)net->cwnd) << 32);
626 if (net->cc_mod.rtcc.rtt_set_this_sack) {
627 net->cc_mod.rtcc.rtt_set_this_sack = 0;
628 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
629 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
631 div = net->rtt / 1000;
633 inst_bw = bytes_for_this_rtt / div;
634 inst_off = inst_bw >> bw_shift;
636 inst_ind = SCTP_INST_GAINING;
637 else if ((inst_bw + inst_off) < nbw)
638 inst_ind = SCTP_INST_LOOSING;
640 inst_ind = SCTP_INST_NEUTRAL;
641 probepoint |= ((0xb << 16) | inst_ind);
643 inst_ind = net->cc_mod.rtcc.last_inst_ind;
644 inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
645 /* Can't determine do not change */
646 probepoint |= ((0xc << 16) | inst_ind);
649 inst_ind = net->cc_mod.rtcc.last_inst_ind;
650 inst_bw = bytes_for_this_rtt;
651 /* Can't determine do not change */
652 probepoint |= ((0xd << 16) | inst_ind);
654 SDT_PROBE5(sctp, cwnd, net, rttvar,
656 ((nbw << 32) | inst_bw),
657 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
661 /* No rtt measurement, use last one */
662 inst_ind = net->cc_mod.rtcc.last_inst_ind;
664 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
665 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
666 ret = cc_bw_increase(stcb, net, nbw, vtag);
669 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
670 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
671 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
675 * If we reach here then we are in a situation where the bw stayed
678 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
680 net->cc_mod.rtcc.last_inst_ind = inst_ind;
685 sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
686 struct sctp_association *asoc,
687 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
689 struct sctp_nets *net;
690 int old_cwnd __dtrace;
691 uint32_t t_ssthresh, incr;
692 uint64_t t_ucwnd_sbw;
693 uint64_t t_path_mptcp;
694 uint64_t mptcp_like_alpha;
698 /* MT FIXME: Don't compute this over and over again */
702 mptcp_like_alpha = 1;
703 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
704 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
705 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
707 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
708 t_ssthresh += net->ssthresh;
709 /* lastsa>>3; we don't need to devide ... */
714 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt;
715 t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) /
716 (((uint64_t)net->mtu) * (uint64_t)srtt);
717 tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) /
718 ((uint64_t)net->mtu * (uint64_t)(srtt * srtt));
719 if (tmp > max_path) {
724 if (t_path_mptcp > 0) {
725 mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp);
727 mptcp_like_alpha = 1;
730 if (t_ssthresh == 0) {
733 if (t_ucwnd_sbw == 0) {
736 /******************************/
737 /* update cwnd and Early FR */
738 /******************************/
739 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
740 #ifdef JANA_CMT_FAST_RECOVERY
742 * CMT fast recovery code. Need to debug.
744 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
745 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
746 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
747 net->will_exit_fast_recovery = 1;
751 /* if nothing was acked on this destination skip it */
752 if (net->net_ack == 0) {
753 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
754 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
758 #ifdef JANA_CMT_FAST_RECOVERY
760 * CMT fast recovery code
763 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
764 * && net->will_exit_fast_recovery == 0) { @@@ Do something
765 * } else if (sctp_cmt_on_off == 0 &&
766 * asoc->fast_retran_loss_recovery && will_exit == 0) {
770 if (asoc->fast_retran_loss_recovery &&
772 (asoc->sctp_cmt_on_off == 0)) {
774 * If we are in loss recovery we skip any cwnd
780 * Did any measurements go on for this network?
782 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
786 * At this point our bw_bytes has been updated by
787 * incoming sack information.
789 * But our bw may not yet be set.
792 if ((net->cc_mod.rtcc.new_tot_time / 1000) > 0) {
793 nbw = net->cc_mod.rtcc.bw_bytes / (net->cc_mod.rtcc.new_tot_time / 1000);
795 nbw = net->cc_mod.rtcc.bw_bytes;
797 if (net->cc_mod.rtcc.lbw) {
798 if (cc_bw_limit(stcb, net, nbw)) {
799 /* Hold here, no update */
803 uint64_t vtag __dtrace, probepoint __dtrace;
805 probepoint = (((uint64_t)net->cwnd) << 32);
806 probepoint |= ((0xa << 16) | 0);
807 vtag = (net->rtt << 32) |
808 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
811 SDT_PROBE5(sctp, cwnd, net, rttvar,
814 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
817 net->cc_mod.rtcc.lbw = nbw;
818 net->cc_mod.rtcc.lbw_rtt = net->rtt;
819 if (net->cc_mod.rtcc.rtt_set_this_sack) {
820 net->cc_mod.rtcc.rtt_set_this_sack = 0;
821 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
826 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
830 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
831 /* If the cumulative ack moved we can proceed */
832 if (net->cwnd <= net->ssthresh) {
833 /* We are in slow start */
834 if (net->flight_size + net->net_ack >= net->cwnd) {
837 old_cwnd = net->cwnd;
838 switch (asoc->sctp_cmt_on_off) {
840 limit = (uint32_t)(((uint64_t)net->mtu *
841 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
842 (uint64_t)net->ssthresh) /
843 (uint64_t)t_ssthresh);
844 incr = (uint32_t)(((uint64_t)net->net_ack *
845 (uint64_t)net->ssthresh) /
846 (uint64_t)t_ssthresh);
856 * lastsa>>3; we don't need
863 limit = (uint32_t)(((uint64_t)net->mtu *
864 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
865 (uint64_t)net->cwnd) /
866 ((uint64_t)srtt * t_ucwnd_sbw));
867 /* INCREASE FACTOR */
868 incr = (uint32_t)(((uint64_t)net->net_ack *
869 (uint64_t)net->cwnd) /
870 ((uint64_t)srtt * t_ucwnd_sbw));
871 /* INCREASE FACTOR */
880 limit = (uint32_t)(((uint64_t)net->mtu *
882 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
884 incr = (uint32_t)(((uint64_t)net->net_ack *
890 if (incr > net->net_ack) {
893 if (incr > net->mtu) {
899 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
900 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
905 sctp_enforce_cwnd_limit(asoc, net);
906 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
907 sctp_log_cwnd(stcb, net, incr,
908 SCTP_CWND_LOG_FROM_SS);
910 SDT_PROBE5(sctp, cwnd, net, ack,
912 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
914 old_cwnd, net->cwnd);
916 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
917 sctp_log_cwnd(stcb, net, net->net_ack,
918 SCTP_CWND_LOG_NOADV_SS);
922 /* We are in congestion avoidance */
926 net->partial_bytes_acked += net->net_ack;
928 if ((net->flight_size + net->net_ack >= net->cwnd) &&
929 (net->partial_bytes_acked >= net->cwnd)) {
930 net->partial_bytes_acked -= net->cwnd;
931 old_cwnd = net->cwnd;
932 switch (asoc->sctp_cmt_on_off) {
934 incr = (uint32_t)(((uint64_t)net->mtu *
935 (uint64_t)net->ssthresh) /
936 (uint64_t)t_ssthresh);
943 * lastsa>>3; we don't need
950 incr = (uint32_t)((uint64_t)net->mtu *
951 (uint64_t)net->cwnd /
954 /* INCREASE FACTOR */
960 incr = (uint32_t)((mptcp_like_alpha *
961 (uint64_t)net->cwnd) >>
963 if (incr > net->mtu) {
972 sctp_enforce_cwnd_limit(asoc, net);
973 SDT_PROBE5(sctp, cwnd, net, ack,
975 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
977 old_cwnd, net->cwnd);
978 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
979 sctp_log_cwnd(stcb, net, net->mtu,
980 SCTP_CWND_LOG_FROM_CA);
983 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
984 sctp_log_cwnd(stcb, net, net->net_ack,
985 SCTP_CWND_LOG_NOADV_CA);
990 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
991 sctp_log_cwnd(stcb, net, net->mtu,
992 SCTP_CWND_LOG_NO_CUMACK);
999 sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
1001 int old_cwnd __dtrace;
1003 old_cwnd = net->cwnd;
1004 net->cwnd = net->mtu;
1005 SDT_PROBE5(sctp, cwnd, net, ack,
1006 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
1007 old_cwnd, net->cwnd);
1008 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1009 (void *)net, net->cwnd);
1013 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
1015 int old_cwnd = net->cwnd;
1016 uint32_t t_ssthresh, t_cwnd;
1017 uint64_t t_ucwnd_sbw;
1019 /* MT FIXME: Don't compute this over and over again */
1022 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1023 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1024 struct sctp_nets *lnet;
1028 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1029 t_ssthresh += lnet->ssthresh;
1030 t_cwnd += lnet->cwnd;
1031 srtt = lnet->lastsa;
1032 /* lastsa>>3; we don't need to divide ... */
1034 t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt;
1037 if (t_ssthresh < 1) {
1040 if (t_ucwnd_sbw < 1) {
1043 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1044 net->ssthresh = (uint32_t)(((uint64_t)4 *
1045 (uint64_t)net->mtu *
1046 (uint64_t)net->ssthresh) /
1047 (uint64_t)t_ssthresh);
1052 /* lastsa>>3; we don't need to divide ... */
1056 cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2;
1057 if (cc_delta < t_cwnd) {
1058 net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta);
1060 net->ssthresh = net->mtu;
1063 if ((net->cwnd > t_cwnd / 2) &&
1064 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1065 net->ssthresh = net->cwnd - t_cwnd / 2;
1067 if (net->ssthresh < net->mtu) {
1068 net->ssthresh = net->mtu;
1071 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1073 net->cwnd = net->mtu;
1074 net->partial_bytes_acked = 0;
1075 SDT_PROBE5(sctp, cwnd, net, to,
1077 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1079 old_cwnd, net->cwnd);
1080 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1081 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1086 sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1087 int in_window, int num_pkt_lost, int use_rtcc)
1089 int old_cwnd = net->cwnd;
1091 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1092 /* Data center Congestion Control */
1093 if (in_window == 0) {
1095 * Go to CA with the cwnd at the point we sent the
1096 * TSN that was marked with a CE.
1098 if (net->ecn_prev_cwnd < net->cwnd) {
1099 /* Restore to prev cwnd */
1100 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1102 /* Just cut in 1/2 */
1106 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1107 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1108 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1112 * Further tuning down required over the drastic
1115 net->ssthresh -= (net->mtu * num_pkt_lost);
1116 net->cwnd -= (net->mtu * num_pkt_lost);
1117 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1118 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1121 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1123 if (in_window == 0) {
1124 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1125 net->ssthresh = net->cwnd / 2;
1126 if (net->ssthresh < net->mtu) {
1127 net->ssthresh = net->mtu;
1129 * here back off the timer as well, to slow
1134 net->cwnd = net->ssthresh;
1135 SDT_PROBE5(sctp, cwnd, net, ecn,
1137 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1139 old_cwnd, net->cwnd);
1140 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1141 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1149 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1150 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1151 uint32_t *bottle_bw, uint32_t *on_queue)
1155 int old_cwnd = net->cwnd;
1157 /* get bottle neck bw */
1158 *bottle_bw = ntohl(cp->bottle_bw);
1159 /* and whats on queue */
1160 *on_queue = ntohl(cp->current_onq);
1162 * adjust the on-queue if our flight is more it could be that the
1163 * router has not yet gotten data "in-flight" to it
1165 if (*on_queue < net->flight_size) {
1166 *on_queue = net->flight_size;
1168 /* rtt is measured in micro seconds, bottle_bw in bytes per second */
1169 bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000);
1170 if (bw_avail > *bottle_bw) {
1172 * Cap the growth to no more than the bottle neck. This can
1173 * happen as RTT slides up due to queues. It also means if
1174 * you have more than a 1 second RTT with a empty queue you
1175 * will be limited to the bottle_bw per second no matter if
1176 * other points have 1/2 the RTT and you could get more
1179 bw_avail = *bottle_bw;
1181 if (*on_queue > bw_avail) {
1183 * No room for anything else don't allow anything else to be
1184 * "added to the fire".
1186 int seg_inflight, seg_onqueue, my_portion;
1188 net->partial_bytes_acked = 0;
1189 /* how much are we over queue size? */
1190 incr = *on_queue - bw_avail;
1191 if (stcb->asoc.seen_a_sack_this_pkt) {
1193 * undo any cwnd adjustment that the sack might have
1196 net->cwnd = net->prev_cwnd;
1198 /* Now how much of that is mine? */
1199 seg_inflight = net->flight_size / net->mtu;
1200 seg_onqueue = *on_queue / net->mtu;
1201 my_portion = (incr * seg_inflight) / seg_onqueue;
1203 /* Have I made an adjustment already */
1204 if (net->cwnd > net->flight_size) {
1206 * for this flight I made an adjustment we need to
1207 * decrease the portion by a share our previous
1212 diff_adj = net->cwnd - net->flight_size;
1213 if (diff_adj > my_portion)
1216 my_portion -= diff_adj;
1219 * back down to the previous cwnd (assume we have had a sack
1220 * before this packet). minus what ever portion of the
1221 * overage is my fault.
1223 net->cwnd -= my_portion;
1225 /* we will NOT back down more than 1 MTU */
1226 if (net->cwnd <= net->mtu) {
1227 net->cwnd = net->mtu;
1230 net->ssthresh = net->cwnd - 1;
1233 * Take 1/4 of the space left or max burst up .. whichever
1236 incr = (bw_avail - *on_queue) >> 2;
1237 if ((stcb->asoc.max_burst > 0) &&
1238 (stcb->asoc.max_burst * net->mtu < incr)) {
1239 incr = stcb->asoc.max_burst * net->mtu;
1243 if (net->cwnd > bw_avail) {
1244 /* We can't exceed the pipe size */
1245 net->cwnd = bw_avail;
1247 if (net->cwnd < net->mtu) {
1248 /* We always have 1 MTU */
1249 net->cwnd = net->mtu;
1251 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1252 if (net->cwnd - old_cwnd != 0) {
1253 /* log only changes */
1254 SDT_PROBE5(sctp, cwnd, net, pd,
1256 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1258 old_cwnd, net->cwnd);
1259 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1260 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1261 SCTP_CWND_LOG_FROM_SAT);
1267 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1268 struct sctp_nets *net, int burst_limit)
1270 int old_cwnd = net->cwnd;
1272 if (net->ssthresh < net->cwnd)
1273 net->ssthresh = net->cwnd;
1275 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1276 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1277 SDT_PROBE5(sctp, cwnd, net, bl,
1279 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1281 old_cwnd, net->cwnd);
1282 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1283 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1289 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1290 struct sctp_association *asoc,
1291 int accum_moved, int reneged_all, int will_exit)
1293 /* Passing a zero argument in last disables the rtcc algorithm */
1294 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1298 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1299 int in_window, int num_pkt_lost)
1301 /* Passing a zero argument in last disables the rtcc algorithm */
1302 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1305 /* Here starts the RTCCVAR type CC invented by RRS which
1306 * is a slight mod to RFC2581. We reuse a common routine or
1307 * two since these algorithms are so close and need to
1311 sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1312 int in_window, int num_pkt_lost)
1314 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1318 sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1319 struct sctp_tmit_chunk *tp1)
1321 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1325 sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1326 struct sctp_nets *net)
1328 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1329 /* We had a bw measurement going on */
1330 struct timeval ltls;
1332 SCTP_GETPTIME_TIMEVAL(<ls);
1333 timevalsub(<ls, &net->cc_mod.rtcc.tls);
1334 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1339 sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1340 struct sctp_nets *net)
1342 uint64_t vtag __dtrace, probepoint __dtrace;
1344 if (net->cc_mod.rtcc.lbw) {
1345 /* Clear the old bw.. we went to 0 in-flight */
1346 vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1348 probepoint = (((uint64_t)net->cwnd) << 32);
1350 probepoint |= ((8 << 16) | 0);
1351 SDT_PROBE5(sctp, cwnd, net, rttvar,
1353 ((net->cc_mod.rtcc.lbw << 32) | 0),
1354 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1357 net->cc_mod.rtcc.lbw_rtt = 0;
1358 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1359 net->cc_mod.rtcc.lbw = 0;
1360 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1361 net->cc_mod.rtcc.vol_reduce = 0;
1362 net->cc_mod.rtcc.bw_tot_time = 0;
1363 net->cc_mod.rtcc.bw_bytes = 0;
1364 net->cc_mod.rtcc.tls_needs_set = 0;
1365 if (net->cc_mod.rtcc.steady_step) {
1366 net->cc_mod.rtcc.vol_reduce = 0;
1367 net->cc_mod.rtcc.step_cnt = 0;
1368 net->cc_mod.rtcc.last_step_state = 0;
1370 if (net->cc_mod.rtcc.ret_from_eq) {
1371 /* less aggressive one - reset cwnd too */
1372 uint32_t cwnd_in_mtu, cwnd;
1374 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1375 if (cwnd_in_mtu == 0) {
1377 * Using 0 means that the value of RFC 4960
1380 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1383 * We take the minimum of the burst limit
1384 * and the initial congestion window.
1386 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1387 cwnd_in_mtu = stcb->asoc.max_burst;
1388 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1390 if (net->cwnd > cwnd) {
1392 * Only set if we are not a timeout (i.e.
1402 sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1403 struct sctp_nets *net)
1405 uint64_t vtag __dtrace, probepoint __dtrace;
1407 sctp_set_initial_cc_param(stcb, net);
1408 stcb->asoc.use_precise_time = 1;
1409 probepoint = (((uint64_t)net->cwnd) << 32);
1410 probepoint |= ((9 << 16) | 0);
1411 vtag = (net->rtt << 32) |
1412 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1414 SDT_PROBE5(sctp, cwnd, net, rttvar,
1420 net->cc_mod.rtcc.lbw_rtt = 0;
1421 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1422 net->cc_mod.rtcc.vol_reduce = 0;
1423 net->cc_mod.rtcc.lbw = 0;
1424 net->cc_mod.rtcc.vol_reduce = 0;
1425 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1426 net->cc_mod.rtcc.bw_tot_time = 0;
1427 net->cc_mod.rtcc.bw_bytes = 0;
1428 net->cc_mod.rtcc.tls_needs_set = 0;
1429 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1430 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1431 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1432 net->cc_mod.rtcc.step_cnt = 0;
1433 net->cc_mod.rtcc.last_step_state = 0;
1437 sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1438 struct sctp_cc_option *cc_opt)
1440 struct sctp_nets *net;
1442 if (setorget == 1) {
1444 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1445 if ((cc_opt->aid_value.assoc_value != 0) &&
1446 (cc_opt->aid_value.assoc_value != 1)) {
1449 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1450 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1452 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1453 if ((cc_opt->aid_value.assoc_value != 0) &&
1454 (cc_opt->aid_value.assoc_value != 1)) {
1457 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1458 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1460 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1461 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1462 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1469 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1470 net = TAILQ_FIRST(&stcb->asoc.nets);
1474 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1475 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1476 net = TAILQ_FIRST(&stcb->asoc.nets);
1480 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1481 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1482 net = TAILQ_FIRST(&stcb->asoc.nets);
1486 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1495 sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1496 struct sctp_nets *net)
1498 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1499 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1500 net->cc_mod.rtcc.tls_needs_set = 2;
1505 sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1506 struct sctp_association *asoc,
1507 int accum_moved, int reneged_all, int will_exit)
1509 /* Passing a one argument at the last enables the rtcc algorithm */
1510 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1514 sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1515 struct sctp_nets *net,
1516 struct timeval *now SCTP_UNUSED)
1518 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1521 /* Here starts Sally Floyds HS-TCP */
1523 struct sctp_hs_raise_drop {
1526 int8_t drop_percent;
1529 #define SCTP_HS_TABLE_SIZE 73
1531 static const struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1532 {38, 1, 50}, /* 0 */
1533 {118, 2, 44}, /* 1 */
1534 {221, 3, 41}, /* 2 */
1535 {347, 4, 38}, /* 3 */
1536 {495, 5, 37}, /* 4 */
1537 {663, 6, 35}, /* 5 */
1538 {851, 7, 34}, /* 6 */
1539 {1058, 8, 33}, /* 7 */
1540 {1284, 9, 32}, /* 8 */
1541 {1529, 10, 31}, /* 9 */
1542 {1793, 11, 30}, /* 10 */
1543 {2076, 12, 29}, /* 11 */
1544 {2378, 13, 28}, /* 12 */
1545 {2699, 14, 28}, /* 13 */
1546 {3039, 15, 27}, /* 14 */
1547 {3399, 16, 27}, /* 15 */
1548 {3778, 17, 26}, /* 16 */
1549 {4177, 18, 26}, /* 17 */
1550 {4596, 19, 25}, /* 18 */
1551 {5036, 20, 25}, /* 19 */
1552 {5497, 21, 24}, /* 20 */
1553 {5979, 22, 24}, /* 21 */
1554 {6483, 23, 23}, /* 22 */
1555 {7009, 24, 23}, /* 23 */
1556 {7558, 25, 22}, /* 24 */
1557 {8130, 26, 22}, /* 25 */
1558 {8726, 27, 22}, /* 26 */
1559 {9346, 28, 21}, /* 27 */
1560 {9991, 29, 21}, /* 28 */
1561 {10661, 30, 21}, /* 29 */
1562 {11358, 31, 20}, /* 30 */
1563 {12082, 32, 20}, /* 31 */
1564 {12834, 33, 20}, /* 32 */
1565 {13614, 34, 19}, /* 33 */
1566 {14424, 35, 19}, /* 34 */
1567 {15265, 36, 19}, /* 35 */
1568 {16137, 37, 19}, /* 36 */
1569 {17042, 38, 18}, /* 37 */
1570 {17981, 39, 18}, /* 38 */
1571 {18955, 40, 18}, /* 39 */
1572 {19965, 41, 17}, /* 40 */
1573 {21013, 42, 17}, /* 41 */
1574 {22101, 43, 17}, /* 42 */
1575 {23230, 44, 17}, /* 43 */
1576 {24402, 45, 16}, /* 44 */
1577 {25618, 46, 16}, /* 45 */
1578 {26881, 47, 16}, /* 46 */
1579 {28193, 48, 16}, /* 47 */
1580 {29557, 49, 15}, /* 48 */
1581 {30975, 50, 15}, /* 49 */
1582 {32450, 51, 15}, /* 50 */
1583 {33986, 52, 15}, /* 51 */
1584 {35586, 53, 14}, /* 52 */
1585 {37253, 54, 14}, /* 53 */
1586 {38992, 55, 14}, /* 54 */
1587 {40808, 56, 14}, /* 55 */
1588 {42707, 57, 13}, /* 56 */
1589 {44694, 58, 13}, /* 57 */
1590 {46776, 59, 13}, /* 58 */
1591 {48961, 60, 13}, /* 59 */
1592 {51258, 61, 13}, /* 60 */
1593 {53677, 62, 12}, /* 61 */
1594 {56230, 63, 12}, /* 62 */
1595 {58932, 64, 12}, /* 63 */
1596 {61799, 65, 12}, /* 64 */
1597 {64851, 66, 11}, /* 65 */
1598 {68113, 67, 11}, /* 66 */
1599 {71617, 68, 11}, /* 67 */
1600 {75401, 69, 10}, /* 68 */
1601 {79517, 70, 10}, /* 69 */
1602 {84035, 71, 10}, /* 70 */
1603 {89053, 72, 10}, /* 71 */
1604 {94717, 73, 9} /* 72 */
1608 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1610 int cur_val, i, indx, incr;
1611 int old_cwnd = net->cwnd;
1613 cur_val = net->cwnd >> 10;
1614 indx = SCTP_HS_TABLE_SIZE - 1;
1616 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1618 if (net->net_ack > net->mtu) {
1619 net->cwnd += net->mtu;
1621 net->cwnd += net->net_ack;
1624 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1625 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1630 net->last_hs_used = indx;
1631 incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10);
1634 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1635 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1636 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SS);
1641 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1643 int cur_val, i, indx;
1644 int old_cwnd = net->cwnd;
1646 cur_val = net->cwnd >> 10;
1647 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1649 net->ssthresh = net->cwnd / 2;
1650 if (net->ssthresh < (net->mtu * 2)) {
1651 net->ssthresh = 2 * net->mtu;
1653 net->cwnd = net->ssthresh;
1655 /* drop by the proper amount */
1656 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1657 (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1658 net->cwnd = net->ssthresh;
1659 /* now where are we */
1660 indx = net->last_hs_used;
1661 cur_val = net->cwnd >> 10;
1662 /* reset where we are in the table */
1663 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1664 /* feel out of hs */
1665 net->last_hs_used = 0;
1667 for (i = indx; i >= 1; i--) {
1668 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1672 net->last_hs_used = indx;
1675 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1676 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1677 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1682 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1683 struct sctp_association *asoc)
1685 struct sctp_nets *net;
1688 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1689 * (net->fast_retran_loss_recovery == 0)))
1691 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1692 if ((asoc->fast_retran_loss_recovery == 0) ||
1693 (asoc->sctp_cmt_on_off > 0)) {
1694 /* out of a RFC2582 Fast recovery window? */
1695 if (net->net_ack > 0) {
1697 * per section 7.2.3, are there any
1698 * destinations that had a fast retransmit
1699 * to them. If so what we need to do is
1700 * adjust ssthresh and cwnd.
1702 struct sctp_tmit_chunk *lchk;
1704 sctp_hs_cwnd_decrease(stcb, net);
1706 lchk = TAILQ_FIRST(&asoc->send_queue);
1708 net->partial_bytes_acked = 0;
1709 /* Turn on fast recovery window */
1710 asoc->fast_retran_loss_recovery = 1;
1712 /* Mark end of the window */
1713 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1715 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1719 * CMT fast recovery -- per destination
1720 * recovery variable.
1722 net->fast_retran_loss_recovery = 1;
1725 /* Mark end of the window */
1726 net->fast_recovery_tsn = asoc->sending_seq - 1;
1728 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1731 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1732 stcb->sctp_ep, stcb, net,
1733 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_2);
1734 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1735 stcb->sctp_ep, stcb, net);
1737 } else if (net->net_ack > 0) {
1739 * Mark a peg that we WOULD have done a cwnd
1740 * reduction but RFC2582 prevented this action.
1742 SCTP_STAT_INCR(sctps_fastretransinrtt);
1748 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1749 struct sctp_association *asoc,
1750 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1752 struct sctp_nets *net;
1754 /******************************/
1755 /* update cwnd and Early FR */
1756 /******************************/
1757 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1758 #ifdef JANA_CMT_FAST_RECOVERY
1760 * CMT fast recovery code. Need to debug.
1762 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1763 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1764 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1765 net->will_exit_fast_recovery = 1;
1769 /* if nothing was acked on this destination skip it */
1770 if (net->net_ack == 0) {
1771 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1772 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1776 #ifdef JANA_CMT_FAST_RECOVERY
1778 * CMT fast recovery code
1781 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1782 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1783 * } else if (sctp_cmt_on_off == 0 &&
1784 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1788 if (asoc->fast_retran_loss_recovery &&
1790 (asoc->sctp_cmt_on_off == 0)) {
1792 * If we are in loss recovery we skip any cwnd
1798 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1802 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1803 /* If the cumulative ack moved we can proceed */
1804 if (net->cwnd <= net->ssthresh) {
1805 /* We are in slow start */
1806 if (net->flight_size + net->net_ack >= net->cwnd) {
1807 sctp_hs_cwnd_increase(stcb, net);
1809 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1810 sctp_log_cwnd(stcb, net, net->net_ack,
1811 SCTP_CWND_LOG_NOADV_SS);
1815 /* We are in congestion avoidance */
1816 net->partial_bytes_acked += net->net_ack;
1817 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1818 (net->partial_bytes_acked >= net->cwnd)) {
1819 net->partial_bytes_acked -= net->cwnd;
1820 net->cwnd += net->mtu;
1821 sctp_enforce_cwnd_limit(asoc, net);
1822 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1823 sctp_log_cwnd(stcb, net, net->mtu,
1824 SCTP_CWND_LOG_FROM_CA);
1827 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1828 sctp_log_cwnd(stcb, net, net->net_ack,
1829 SCTP_CWND_LOG_NOADV_CA);
1834 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1835 sctp_log_cwnd(stcb, net, net->mtu,
1836 SCTP_CWND_LOG_NO_CUMACK);
1843 * H-TCP congestion control. The algorithm is detailed in:
1844 * R.N.Shorten, D.J.Leith:
1845 * "H-TCP: TCP for high-speed and long-distance networks"
1846 * Proc. PFLDnet, Argonne, 2004.
1847 * http://www.hamilton.ie/net/htcp3.pdf
1850 static int use_rtt_scaling = 1;
1851 static int use_bandwidth_switch = 1;
1854 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1856 return (seq3 - seq2 >= seq1 - seq2);
1859 static inline uint32_t
1860 htcp_cong_time(struct htcp *ca)
1862 return (sctp_get_tick_count() - ca->last_cong);
1865 static inline uint32_t
1866 htcp_ccount(struct htcp *ca)
1868 return (ca->minRTT == 0 ? htcp_cong_time(ca) : htcp_cong_time(ca) / ca->minRTT);
1872 htcp_reset(struct htcp *ca)
1874 ca->undo_last_cong = ca->last_cong;
1875 ca->undo_maxRTT = ca->maxRTT;
1876 ca->undo_old_maxB = ca->old_maxB;
1877 ca->last_cong = sctp_get_tick_count();
1880 #ifdef SCTP_NOT_USED
1883 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1885 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1886 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1887 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1888 return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu));
1894 measure_rtt(struct sctp_nets *net)
1896 uint32_t srtt = net->lastsa >> SCTP_RTT_SHIFT;
1898 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1899 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1900 net->cc_mod.htcp_ca.minRTT = srtt;
1903 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1904 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
1905 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
1906 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT + sctp_msecs_to_ticks(20))
1907 net->cc_mod.htcp_ca.maxRTT = srtt;
1912 measure_achieved_throughput(struct sctp_nets *net)
1914 uint32_t now = sctp_get_tick_count();
1916 if (net->fast_retran_ip == 0)
1917 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
1919 if (!use_bandwidth_switch)
1922 /* achieved throughput calculations */
1923 /* JRS - not 100% sure of this statement */
1924 if (net->fast_retran_ip == 1) {
1925 net->cc_mod.htcp_ca.bytecount = 0;
1926 net->cc_mod.htcp_ca.lasttime = now;
1930 net->cc_mod.htcp_ca.bytecount += net->net_ack;
1931 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)) &&
1932 (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) &&
1933 (net->cc_mod.htcp_ca.minRTT > 0)) {
1934 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount / net->mtu * hz / (now - net->cc_mod.htcp_ca.lasttime);
1936 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
1937 /* just after backoff */
1938 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
1940 net->cc_mod.htcp_ca.Bi = (3 * net->cc_mod.htcp_ca.Bi + cur_Bi) / 4;
1941 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
1942 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
1943 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
1944 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
1946 net->cc_mod.htcp_ca.bytecount = 0;
1947 net->cc_mod.htcp_ca.lasttime = now;
1952 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1954 if (use_bandwidth_switch) {
1955 uint32_t maxB = ca->maxB;
1956 uint32_t old_maxB = ca->old_maxB;
1958 ca->old_maxB = ca->maxB;
1960 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1961 ca->beta = BETA_MIN;
1967 if (ca->modeswitch && minRTT > sctp_msecs_to_ticks(10) && maxRTT) {
1968 ca->beta = (minRTT << 7) / maxRTT;
1969 if (ca->beta < BETA_MIN)
1970 ca->beta = BETA_MIN;
1971 else if (ca->beta > BETA_MAX)
1972 ca->beta = BETA_MAX;
1974 ca->beta = BETA_MIN;
1980 htcp_alpha_update(struct htcp *ca)
1982 uint32_t minRTT = ca->minRTT;
1983 uint32_t factor = 1;
1984 uint32_t diff = htcp_cong_time(ca);
1986 if (diff > (uint32_t)hz) {
1988 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1991 if (use_rtt_scaling && minRTT) {
1992 uint32_t scale = (hz << 3) / (10 * minRTT);
1994 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1995 * interval [0.5,10]<<3 */
1996 factor = (factor << 3) / scale;
2001 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
2003 ca->alpha = ALPHA_BASE;
2006 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
2007 * rtt before we adjust our beta to ensure we are working from a consistent
2010 * This function should be called when we hit a congestion event since only at
2011 * that point do we really have a real sense of maxRTT (the queues en route
2012 * were getting just too full now).
2015 htcp_param_update(struct sctp_nets *net)
2017 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2018 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2020 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2021 htcp_alpha_update(&net->cc_mod.htcp_ca);
2024 * add slowly fading memory for maxRTT to accommodate routing
2027 if (minRTT > 0 && maxRTT > minRTT)
2028 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
2032 htcp_recalc_ssthresh(struct sctp_nets *net)
2034 htcp_param_update(net);
2035 return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu));
2039 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2042 * How to handle these functions?
2043 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2046 if (net->cwnd <= net->ssthresh) {
2047 /* We are in slow start */
2048 if (net->flight_size + net->net_ack >= net->cwnd) {
2049 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2050 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2051 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2052 sctp_log_cwnd(stcb, net, net->mtu,
2053 SCTP_CWND_LOG_FROM_SS);
2057 net->cwnd += net->net_ack;
2058 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2059 sctp_log_cwnd(stcb, net, net->net_ack,
2060 SCTP_CWND_LOG_FROM_SS);
2063 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2065 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2066 sctp_log_cwnd(stcb, net, net->net_ack,
2067 SCTP_CWND_LOG_NOADV_SS);
2074 * In dangerous area, increase slowly. In theory this is
2075 * net->cwnd += alpha / net->cwnd
2077 /* What is snd_cwnd_cnt?? */
2078 if (((net->partial_bytes_acked / net->mtu * net->cc_mod.htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
2080 * Does SCTP have a cwnd clamp?
2081 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2083 net->cwnd += net->mtu;
2084 net->partial_bytes_acked = 0;
2085 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2086 htcp_alpha_update(&net->cc_mod.htcp_ca);
2087 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2088 sctp_log_cwnd(stcb, net, net->mtu,
2089 SCTP_CWND_LOG_FROM_CA);
2092 net->partial_bytes_acked += net->net_ack;
2093 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2094 sctp_log_cwnd(stcb, net, net->net_ack,
2095 SCTP_CWND_LOG_NOADV_CA);
2099 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2103 #ifdef SCTP_NOT_USED
2104 /* Lower bound on congestion window. */
2106 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2108 return (net->ssthresh);
2113 htcp_init(struct sctp_nets *net)
2115 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2116 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2117 net->cc_mod.htcp_ca.beta = BETA_MIN;
2118 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2119 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2123 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2126 * We take the max of the burst limit times a MTU or the
2127 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2129 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2130 net->ssthresh = stcb->asoc.peers_rwnd;
2131 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2134 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
2135 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2140 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2141 struct sctp_association *asoc,
2142 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2144 struct sctp_nets *net;
2146 /******************************/
2147 /* update cwnd and Early FR */
2148 /******************************/
2149 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2150 #ifdef JANA_CMT_FAST_RECOVERY
2152 * CMT fast recovery code. Need to debug.
2154 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2155 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2156 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
2157 net->will_exit_fast_recovery = 1;
2161 /* if nothing was acked on this destination skip it */
2162 if (net->net_ack == 0) {
2163 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2164 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2168 #ifdef JANA_CMT_FAST_RECOVERY
2170 * CMT fast recovery code
2173 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
2174 * && net->will_exit_fast_recovery == 0) { @@@ Do something
2175 * } else if (sctp_cmt_on_off == 0 &&
2176 * asoc->fast_retran_loss_recovery && will_exit == 0) {
2180 if (asoc->fast_retran_loss_recovery &&
2182 (asoc->sctp_cmt_on_off == 0)) {
2184 * If we are in loss recovery we skip any cwnd
2190 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2194 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2195 htcp_cong_avoid(stcb, net);
2196 measure_achieved_throughput(net);
2198 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2199 sctp_log_cwnd(stcb, net, net->mtu,
2200 SCTP_CWND_LOG_NO_CUMACK);
2207 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2208 struct sctp_association *asoc)
2210 struct sctp_nets *net;
2213 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2214 * (net->fast_retran_loss_recovery == 0)))
2216 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2217 if ((asoc->fast_retran_loss_recovery == 0) ||
2218 (asoc->sctp_cmt_on_off > 0)) {
2219 /* out of a RFC2582 Fast recovery window? */
2220 if (net->net_ack > 0) {
2222 * per section 7.2.3, are there any
2223 * destinations that had a fast retransmit
2224 * to them. If so what we need to do is
2225 * adjust ssthresh and cwnd.
2227 struct sctp_tmit_chunk *lchk;
2228 int old_cwnd = net->cwnd;
2230 /* JRS - reset as if state were changed */
2231 htcp_reset(&net->cc_mod.htcp_ca);
2232 net->ssthresh = htcp_recalc_ssthresh(net);
2233 net->cwnd = net->ssthresh;
2234 sctp_enforce_cwnd_limit(asoc, net);
2235 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2236 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2237 SCTP_CWND_LOG_FROM_FR);
2239 lchk = TAILQ_FIRST(&asoc->send_queue);
2241 net->partial_bytes_acked = 0;
2242 /* Turn on fast recovery window */
2243 asoc->fast_retran_loss_recovery = 1;
2245 /* Mark end of the window */
2246 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2248 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2252 * CMT fast recovery -- per destination
2253 * recovery variable.
2255 net->fast_retran_loss_recovery = 1;
2258 /* Mark end of the window */
2259 net->fast_recovery_tsn = asoc->sending_seq - 1;
2261 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2264 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2265 stcb->sctp_ep, stcb, net,
2266 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_3);
2267 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2268 stcb->sctp_ep, stcb, net);
2270 } else if (net->net_ack > 0) {
2272 * Mark a peg that we WOULD have done a cwnd
2273 * reduction but RFC2582 prevented this action.
2275 SCTP_STAT_INCR(sctps_fastretransinrtt);
2281 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2282 struct sctp_nets *net)
2284 int old_cwnd = net->cwnd;
2286 /* JRS - reset as if the state were being changed to timeout */
2287 htcp_reset(&net->cc_mod.htcp_ca);
2288 net->ssthresh = htcp_recalc_ssthresh(net);
2289 net->cwnd = net->mtu;
2290 net->partial_bytes_acked = 0;
2291 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2292 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2297 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2298 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2302 old_cwnd = net->cwnd;
2304 /* JRS - reset hctp as if state changed */
2305 if (in_window == 0) {
2306 htcp_reset(&net->cc_mod.htcp_ca);
2307 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2308 net->ssthresh = htcp_recalc_ssthresh(net);
2309 if (net->ssthresh < net->mtu) {
2310 net->ssthresh = net->mtu;
2311 /* here back off the timer as well, to slow us down */
2314 net->cwnd = net->ssthresh;
2315 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2316 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2317 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2322 const struct sctp_cc_functions sctp_cc_functions[] = {
2324 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2325 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2326 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2327 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2328 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2329 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2330 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2331 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2334 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2335 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2336 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2337 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2338 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2339 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2340 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2341 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2344 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2345 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2346 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2347 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2348 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2349 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2350 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2351 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2354 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2355 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2356 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2357 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2358 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2359 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2360 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2361 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2362 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2363 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2364 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2365 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2366 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2367 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated