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 <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_var.h>
40 #include <netinet/sctp_sysctl.h>
41 #include <netinet/sctp_pcb.h>
42 #include <netinet/sctp_header.h>
43 #include <netinet/sctputil.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_input.h>
46 #include <netinet/sctp_indata.h>
47 #include <netinet/sctp_uio.h>
48 #include <netinet/sctp_timer.h>
49 #include <netinet/sctp_auth.h>
50 #include <netinet/sctp_asconf.h>
51 #include <netinet/sctp_kdtrace.h>
53 #define SHIFT_MPTCP_MULTI_N 40
54 #define SHIFT_MPTCP_MULTI_Z 16
55 #define SHIFT_MPTCP_MULTI 8
58 sctp_enforce_cwnd_limit(struct sctp_association *assoc, struct sctp_nets *net)
60 if ((assoc->max_cwnd > 0) &&
61 (net->cwnd > assoc->max_cwnd) &&
62 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
63 net->cwnd = assoc->max_cwnd;
64 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
65 net->cwnd = net->mtu - sizeof(struct sctphdr);
71 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
73 struct sctp_association *assoc;
77 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
78 if (cwnd_in_mtu == 0) {
79 /* Using 0 means that the value of RFC 4960 is used. */
80 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
83 * We take the minimum of the burst limit and the initial
86 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
87 cwnd_in_mtu = assoc->max_burst;
88 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
90 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
91 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
92 /* In case of resource pooling initialize appropriately */
93 net->cwnd /= assoc->numnets;
94 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
95 net->cwnd = net->mtu - sizeof(struct sctphdr);
98 sctp_enforce_cwnd_limit(assoc, net);
99 net->ssthresh = assoc->peers_rwnd;
100 SDT_PROBE5(sctp, cwnd, net, init,
101 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
103 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
104 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
105 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
110 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
111 struct sctp_association *asoc)
113 struct sctp_nets *net;
114 uint32_t t_ssthresh, t_cwnd;
115 uint64_t t_ucwnd_sbw;
117 /* MT FIXME: Don't compute this over and over again */
121 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
122 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
123 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
124 t_ssthresh += net->ssthresh;
126 if (net->lastsa > 0) {
127 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa;
130 if (t_ucwnd_sbw == 0) {
136 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
137 * (net->fast_retran_loss_recovery == 0)))
139 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
140 if ((asoc->fast_retran_loss_recovery == 0) ||
141 (asoc->sctp_cmt_on_off > 0)) {
142 /* out of a RFC2582 Fast recovery window? */
143 if (net->net_ack > 0) {
145 * per section 7.2.3, are there any
146 * destinations that had a fast retransmit
147 * to them. If so what we need to do is
148 * adjust ssthresh and cwnd.
150 struct sctp_tmit_chunk *lchk;
151 int old_cwnd = net->cwnd;
153 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
154 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
155 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
156 net->ssthresh = (uint32_t)(((uint64_t)4 *
158 (uint64_t)net->ssthresh) /
159 (uint64_t)t_ssthresh);
161 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
166 * lastsa>>3; we don't need
173 * Short Version => Equal to
176 net->ssthresh = (uint32_t)(((uint64_t)4 *
178 (uint64_t)net->cwnd) /
181 /* INCREASE FACTOR */ ;
183 if ((net->cwnd > t_cwnd / 2) &&
184 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
185 net->ssthresh = net->cwnd - t_cwnd / 2;
187 if (net->ssthresh < net->mtu) {
188 net->ssthresh = net->mtu;
191 net->ssthresh = net->cwnd / 2;
192 if (net->ssthresh < (net->mtu * 2)) {
193 net->ssthresh = 2 * net->mtu;
196 net->cwnd = net->ssthresh;
197 sctp_enforce_cwnd_limit(asoc, net);
198 SDT_PROBE5(sctp, cwnd, net, fr,
199 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
200 old_cwnd, net->cwnd);
201 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
202 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
203 SCTP_CWND_LOG_FROM_FR);
205 lchk = TAILQ_FIRST(&asoc->send_queue);
207 net->partial_bytes_acked = 0;
208 /* Turn on fast recovery window */
209 asoc->fast_retran_loss_recovery = 1;
211 /* Mark end of the window */
212 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
214 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
218 * CMT fast recovery -- per destination
221 net->fast_retran_loss_recovery = 1;
224 /* Mark end of the window */
225 net->fast_recovery_tsn = asoc->sending_seq - 1;
227 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
230 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
231 stcb->sctp_ep, stcb, net,
232 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_1);
233 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
234 stcb->sctp_ep, stcb, net);
236 } else if (net->net_ack > 0) {
238 * Mark a peg that we WOULD have done a cwnd
239 * reduction but RFC2582 prevented this action.
241 SCTP_STAT_INCR(sctps_fastretransinrtt);
246 /* Defines for instantaneous bw decisions */
247 #define SCTP_INST_LOOSING 1 /* Losing to other flows */
248 #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
249 #define SCTP_INST_GAINING 3 /* Gaining, step down possible */
252 cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
253 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
255 uint64_t oth, probepoint;
257 probepoint = (((uint64_t)net->cwnd) << 32);
258 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
260 * rtt increased we don't update bw.. so we don't update the
264 probepoint |= ((5 << 16) | 1);
265 SDT_PROBE5(sctp, cwnd, net, rttvar,
267 ((net->cc_mod.rtcc.lbw << 32) | nbw),
268 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
271 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
272 if (net->cc_mod.rtcc.last_step_state == 5)
273 net->cc_mod.rtcc.step_cnt++;
275 net->cc_mod.rtcc.step_cnt = 1;
276 net->cc_mod.rtcc.last_step_state = 5;
277 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
278 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
279 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
280 /* Try a step down */
281 oth = net->cc_mod.rtcc.vol_reduce;
283 oth |= net->cc_mod.rtcc.step_cnt;
285 oth |= net->cc_mod.rtcc.last_step_state;
286 SDT_PROBE5(sctp, cwnd, net, rttstep,
288 ((net->cc_mod.rtcc.lbw << 32) | nbw),
289 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
292 if (net->cwnd > (4 * net->mtu)) {
293 net->cwnd -= net->mtu;
294 net->cc_mod.rtcc.vol_reduce++;
296 net->cc_mod.rtcc.step_cnt = 0;
302 if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
304 * rtt decreased, there could be more room. we update both
305 * the bw and the rtt here to lock this in as a good step
309 probepoint |= ((6 << 16) | 0);
310 SDT_PROBE5(sctp, cwnd, net, rttvar,
312 ((net->cc_mod.rtcc.lbw << 32) | nbw),
313 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
316 if (net->cc_mod.rtcc.steady_step) {
317 oth = net->cc_mod.rtcc.vol_reduce;
319 oth |= net->cc_mod.rtcc.step_cnt;
321 oth |= net->cc_mod.rtcc.last_step_state;
322 SDT_PROBE5(sctp, cwnd, net, rttstep,
324 ((net->cc_mod.rtcc.lbw << 32) | nbw),
325 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
328 if ((net->cc_mod.rtcc.last_step_state == 5) &&
329 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
330 /* Step down worked */
331 net->cc_mod.rtcc.step_cnt = 0;
334 net->cc_mod.rtcc.last_step_state = 6;
335 net->cc_mod.rtcc.step_cnt = 0;
338 net->cc_mod.rtcc.lbw = nbw;
339 net->cc_mod.rtcc.lbw_rtt = net->rtt;
340 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
341 if (inst_ind == SCTP_INST_GAINING)
343 else if (inst_ind == SCTP_INST_NEUTRAL)
349 * Ok bw and rtt remained the same .. no update to any
352 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
353 SDT_PROBE5(sctp, cwnd, net, rttvar,
355 ((net->cc_mod.rtcc.lbw << 32) | nbw),
356 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
359 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
360 if (net->cc_mod.rtcc.last_step_state == 5)
361 net->cc_mod.rtcc.step_cnt++;
363 net->cc_mod.rtcc.step_cnt = 1;
364 net->cc_mod.rtcc.last_step_state = 5;
365 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
366 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
367 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
368 /* Try a step down */
369 if (net->cwnd > (4 * net->mtu)) {
370 net->cwnd -= net->mtu;
371 net->cc_mod.rtcc.vol_reduce++;
374 net->cc_mod.rtcc.step_cnt = 0;
378 if (inst_ind == SCTP_INST_GAINING)
380 else if (inst_ind == SCTP_INST_NEUTRAL)
383 return ((int)net->cc_mod.rtcc.ret_from_eq);
387 cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
388 uint64_t vtag, uint8_t inst_ind)
390 uint64_t oth, probepoint;
392 /* Bandwidth decreased. */
393 probepoint = (((uint64_t)net->cwnd) << 32);
394 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
396 /* Did we add more */
397 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
398 (inst_ind != SCTP_INST_LOOSING)) {
399 /* We caused it maybe.. back off? */
401 probepoint |= ((1 << 16) | 1);
402 SDT_PROBE5(sctp, cwnd, net, rttvar,
404 ((net->cc_mod.rtcc.lbw << 32) | nbw),
405 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
408 if (net->cc_mod.rtcc.ret_from_eq) {
410 * Switch over to CA if we are less
413 net->ssthresh = net->cwnd - 1;
414 net->partial_bytes_acked = 0;
419 probepoint |= ((2 << 16) | 0);
420 SDT_PROBE5(sctp, cwnd, net, rttvar,
422 ((net->cc_mod.rtcc.lbw << 32) | nbw),
423 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
426 /* Someone else - fight for more? */
427 if (net->cc_mod.rtcc.steady_step) {
428 oth = net->cc_mod.rtcc.vol_reduce;
430 oth |= net->cc_mod.rtcc.step_cnt;
432 oth |= net->cc_mod.rtcc.last_step_state;
433 SDT_PROBE5(sctp, cwnd, net, rttstep,
435 ((net->cc_mod.rtcc.lbw << 32) | nbw),
436 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
440 * Did we voluntarily give up some? if so take one
443 if ((net->cc_mod.rtcc.vol_reduce) &&
444 (inst_ind != SCTP_INST_GAINING)) {
445 net->cwnd += net->mtu;
446 sctp_enforce_cwnd_limit(&stcb->asoc, net);
447 net->cc_mod.rtcc.vol_reduce--;
449 net->cc_mod.rtcc.last_step_state = 2;
450 net->cc_mod.rtcc.step_cnt = 0;
453 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
454 /* bw & rtt decreased */
456 probepoint |= ((3 << 16) | 0);
457 SDT_PROBE5(sctp, cwnd, net, rttvar,
459 ((net->cc_mod.rtcc.lbw << 32) | nbw),
460 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
463 if (net->cc_mod.rtcc.steady_step) {
464 oth = net->cc_mod.rtcc.vol_reduce;
466 oth |= net->cc_mod.rtcc.step_cnt;
468 oth |= net->cc_mod.rtcc.last_step_state;
469 SDT_PROBE5(sctp, cwnd, net, rttstep,
471 ((net->cc_mod.rtcc.lbw << 32) | nbw),
472 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
475 if ((net->cc_mod.rtcc.vol_reduce) &&
476 (inst_ind != SCTP_INST_GAINING)) {
477 net->cwnd += net->mtu;
478 sctp_enforce_cwnd_limit(&stcb->asoc, net);
479 net->cc_mod.rtcc.vol_reduce--;
481 net->cc_mod.rtcc.last_step_state = 3;
482 net->cc_mod.rtcc.step_cnt = 0;
486 /* The bw decreased but rtt stayed the same */
488 probepoint |= ((4 << 16) | 0);
489 SDT_PROBE5(sctp, cwnd, net, rttvar,
491 ((net->cc_mod.rtcc.lbw << 32) | nbw),
492 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
495 if (net->cc_mod.rtcc.steady_step) {
496 oth = net->cc_mod.rtcc.vol_reduce;
498 oth |= net->cc_mod.rtcc.step_cnt;
500 oth |= net->cc_mod.rtcc.last_step_state;
501 SDT_PROBE5(sctp, cwnd, net, rttstep,
503 ((net->cc_mod.rtcc.lbw << 32) | nbw),
504 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
507 if ((net->cc_mod.rtcc.vol_reduce) &&
508 (inst_ind != SCTP_INST_GAINING)) {
509 net->cwnd += net->mtu;
510 sctp_enforce_cwnd_limit(&stcb->asoc, net);
511 net->cc_mod.rtcc.vol_reduce--;
513 net->cc_mod.rtcc.last_step_state = 4;
514 net->cc_mod.rtcc.step_cnt = 0;
517 net->cc_mod.rtcc.lbw = nbw;
518 net->cc_mod.rtcc.lbw_rtt = net->rtt;
519 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
520 if (inst_ind == SCTP_INST_GAINING) {
528 cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
530 uint64_t oth, probepoint;
533 * BW increased, so update and return 0, since all actions in our
534 * table say to do the normal CC update. Note that we pay no
535 * attention to the inst_ind since our overall sum is increasing.
538 probepoint = (((uint64_t)net->cwnd) << 32);
539 SDT_PROBE5(sctp, cwnd, net, rttvar,
541 ((net->cc_mod.rtcc.lbw << 32) | nbw),
542 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
545 if (net->cc_mod.rtcc.steady_step) {
546 oth = net->cc_mod.rtcc.vol_reduce;
548 oth |= net->cc_mod.rtcc.step_cnt;
550 oth |= net->cc_mod.rtcc.last_step_state;
551 SDT_PROBE5(sctp, cwnd, net, rttstep,
553 ((net->cc_mod.rtcc.lbw << 32) | nbw),
554 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
557 net->cc_mod.rtcc.last_step_state = 0;
558 net->cc_mod.rtcc.step_cnt = 0;
559 net->cc_mod.rtcc.vol_reduce = 0;
561 net->cc_mod.rtcc.lbw = nbw;
562 net->cc_mod.rtcc.lbw_rtt = net->rtt;
563 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
567 /* RTCC Algorithm to limit growth of cwnd, return
568 * true if you want to NOT allow cwnd growth
571 cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
573 uint64_t bw_offset, rtt_offset;
574 uint64_t probepoint, rtt, vtag;
575 uint64_t bytes_for_this_rtt, inst_bw;
576 uint64_t div, inst_off;
582 * Here we need to see if we want
583 * to limit cwnd growth due to increase
584 * in overall rtt but no increase in bw.
585 * We use the following table to figure
586 * out what we should do. When we return
587 * 0, cc update goes on as planned. If we
588 * return 1, then no cc update happens and cwnd
589 * stays where it is at.
590 * ----------------------------------
592 * *********************************
593 * INC | INC | return 0
594 * ----------------------------------
595 * INC | SAME | return 0
596 * ----------------------------------
597 * INC | DECR | return 0
598 * ----------------------------------
599 * SAME | INC | return 1
600 * ----------------------------------
601 * SAME | SAME | return 1
602 * ----------------------------------
603 * SAME | DECR | return 0
604 * ----------------------------------
605 * DECR | INC | return 0 or 1 based on if we caused.
606 * ----------------------------------
607 * DECR | SAME | return 0
608 * ----------------------------------
609 * DECR | DECR | return 0
610 * ----------------------------------
612 * We are a bit fuzz on what an increase or
613 * decrease is. For BW it is the same if
614 * it did not change within 1/64th. For
615 * RTT it stayed the same if it did not
616 * change within 1/32nd
618 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
619 rtt = stcb->asoc.my_vtag;
620 vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
621 probepoint = (((uint64_t)net->cwnd) << 32);
623 if (net->cc_mod.rtcc.rtt_set_this_sack) {
624 net->cc_mod.rtcc.rtt_set_this_sack = 0;
625 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
626 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
628 div = net->rtt / 1000;
630 inst_bw = bytes_for_this_rtt / div;
631 inst_off = inst_bw >> bw_shift;
633 inst_ind = SCTP_INST_GAINING;
634 else if ((inst_bw + inst_off) < nbw)
635 inst_ind = SCTP_INST_LOOSING;
637 inst_ind = SCTP_INST_NEUTRAL;
638 probepoint |= ((0xb << 16) | inst_ind);
640 inst_ind = net->cc_mod.rtcc.last_inst_ind;
641 inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
642 /* Can't determine do not change */
643 probepoint |= ((0xc << 16) | inst_ind);
646 inst_ind = net->cc_mod.rtcc.last_inst_ind;
647 inst_bw = bytes_for_this_rtt;
648 /* Can't determine do not change */
649 probepoint |= ((0xd << 16) | inst_ind);
651 SDT_PROBE5(sctp, cwnd, net, rttvar,
653 ((nbw << 32) | inst_bw),
654 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
658 /* No rtt measurement, use last one */
659 inst_ind = net->cc_mod.rtcc.last_inst_ind;
661 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
662 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
663 ret = cc_bw_increase(stcb, net, nbw, vtag);
666 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
667 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
668 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
672 * If we reach here then we are in a situation where the bw stayed
675 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
677 net->cc_mod.rtcc.last_inst_ind = inst_ind;
682 sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
683 struct sctp_association *asoc,
684 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
686 struct sctp_nets *net;
688 uint32_t t_ssthresh, incr;
689 uint64_t t_ucwnd_sbw;
690 uint64_t t_path_mptcp;
691 uint64_t mptcp_like_alpha;
695 /* MT FIXME: Don't compute this over and over again */
699 mptcp_like_alpha = 1;
700 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
701 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
702 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
704 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
705 t_ssthresh += net->ssthresh;
706 /* lastsa>>3; we don't need to devide ... */
711 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt;
712 t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) /
713 (((uint64_t)net->mtu) * (uint64_t)srtt);
714 tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) /
715 ((uint64_t)net->mtu * (uint64_t)(srtt * srtt));
716 if (tmp > max_path) {
721 if (t_path_mptcp > 0) {
722 mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp);
724 mptcp_like_alpha = 1;
727 if (t_ssthresh == 0) {
730 if (t_ucwnd_sbw == 0) {
733 /******************************/
734 /* update cwnd and Early FR */
735 /******************************/
736 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
737 #ifdef JANA_CMT_FAST_RECOVERY
739 * CMT fast recovery code. Need to debug.
741 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
742 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
743 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
744 net->will_exit_fast_recovery = 1;
748 /* if nothing was acked on this destination skip it */
749 if (net->net_ack == 0) {
750 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
751 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
755 #ifdef JANA_CMT_FAST_RECOVERY
757 * CMT fast recovery code
760 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
761 * && net->will_exit_fast_recovery == 0) { @@@ Do something
762 * } else if (sctp_cmt_on_off == 0 &&
763 * asoc->fast_retran_loss_recovery && will_exit == 0) {
767 if (asoc->fast_retran_loss_recovery &&
769 (asoc->sctp_cmt_on_off == 0)) {
771 * If we are in loss recovery we skip any cwnd
777 * Did any measurements go on for this network?
779 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
783 * At this point our bw_bytes has been updated by
784 * incoming sack information.
786 * But our bw may not yet be set.
789 if ((net->cc_mod.rtcc.new_tot_time / 1000) > 0) {
790 nbw = net->cc_mod.rtcc.bw_bytes / (net->cc_mod.rtcc.new_tot_time / 1000);
792 nbw = net->cc_mod.rtcc.bw_bytes;
794 if (net->cc_mod.rtcc.lbw) {
795 if (cc_bw_limit(stcb, net, nbw)) {
796 /* Hold here, no update */
800 uint64_t vtag, probepoint;
802 probepoint = (((uint64_t)net->cwnd) << 32);
803 probepoint |= ((0xa << 16) | 0);
804 vtag = (net->rtt << 32) |
805 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
808 SDT_PROBE5(sctp, cwnd, net, rttvar,
811 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
814 net->cc_mod.rtcc.lbw = nbw;
815 net->cc_mod.rtcc.lbw_rtt = net->rtt;
816 if (net->cc_mod.rtcc.rtt_set_this_sack) {
817 net->cc_mod.rtcc.rtt_set_this_sack = 0;
818 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
823 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
827 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
828 /* If the cumulative ack moved we can proceed */
829 if (net->cwnd <= net->ssthresh) {
830 /* We are in slow start */
831 if (net->flight_size + net->net_ack >= net->cwnd) {
834 old_cwnd = net->cwnd;
835 switch (asoc->sctp_cmt_on_off) {
837 limit = (uint32_t)(((uint64_t)net->mtu *
838 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
839 (uint64_t)net->ssthresh) /
840 (uint64_t)t_ssthresh);
841 incr = (uint32_t)(((uint64_t)net->net_ack *
842 (uint64_t)net->ssthresh) /
843 (uint64_t)t_ssthresh);
853 * lastsa>>3; we don't need
860 limit = (uint32_t)(((uint64_t)net->mtu *
861 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
862 (uint64_t)net->cwnd) /
863 ((uint64_t)srtt * t_ucwnd_sbw));
864 /* INCREASE FACTOR */
865 incr = (uint32_t)(((uint64_t)net->net_ack *
866 (uint64_t)net->cwnd) /
867 ((uint64_t)srtt * t_ucwnd_sbw));
868 /* INCREASE FACTOR */
877 limit = (uint32_t)(((uint64_t)net->mtu *
879 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
881 incr = (uint32_t)(((uint64_t)net->net_ack *
887 if (incr > net->net_ack) {
890 if (incr > net->mtu) {
896 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
897 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
902 sctp_enforce_cwnd_limit(asoc, net);
903 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
904 sctp_log_cwnd(stcb, net, incr,
905 SCTP_CWND_LOG_FROM_SS);
907 SDT_PROBE5(sctp, cwnd, net, ack,
909 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
911 old_cwnd, net->cwnd);
913 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
914 sctp_log_cwnd(stcb, net, net->net_ack,
915 SCTP_CWND_LOG_NOADV_SS);
919 /* We are in congestion avoidance */
923 net->partial_bytes_acked += net->net_ack;
925 if ((net->flight_size + net->net_ack >= net->cwnd) &&
926 (net->partial_bytes_acked >= net->cwnd)) {
927 net->partial_bytes_acked -= net->cwnd;
928 old_cwnd = net->cwnd;
929 switch (asoc->sctp_cmt_on_off) {
931 incr = (uint32_t)(((uint64_t)net->mtu *
932 (uint64_t)net->ssthresh) /
933 (uint64_t)t_ssthresh);
940 * lastsa>>3; we don't need
947 incr = (uint32_t)((uint64_t)net->mtu *
948 (uint64_t)net->cwnd /
951 /* INCREASE FACTOR */
957 incr = (uint32_t)((mptcp_like_alpha *
958 (uint64_t)net->cwnd) >>
960 if (incr > net->mtu) {
969 sctp_enforce_cwnd_limit(asoc, net);
970 SDT_PROBE5(sctp, cwnd, net, ack,
972 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
974 old_cwnd, net->cwnd);
975 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
976 sctp_log_cwnd(stcb, net, net->mtu,
977 SCTP_CWND_LOG_FROM_CA);
980 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
981 sctp_log_cwnd(stcb, net, net->net_ack,
982 SCTP_CWND_LOG_NOADV_CA);
987 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
988 sctp_log_cwnd(stcb, net, net->mtu,
989 SCTP_CWND_LOG_NO_CUMACK);
996 sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
1000 old_cwnd = net->cwnd;
1001 net->cwnd = net->mtu;
1002 SDT_PROBE5(sctp, cwnd, net, ack,
1003 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
1004 old_cwnd, net->cwnd);
1005 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1006 (void *)net, net->cwnd);
1010 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
1012 int old_cwnd = net->cwnd;
1013 uint32_t t_ssthresh, t_cwnd;
1014 uint64_t t_ucwnd_sbw;
1016 /* MT FIXME: Don't compute this over and over again */
1019 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1020 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1021 struct sctp_nets *lnet;
1025 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1026 t_ssthresh += lnet->ssthresh;
1027 t_cwnd += lnet->cwnd;
1028 srtt = lnet->lastsa;
1029 /* lastsa>>3; we don't need to divide ... */
1031 t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt;
1034 if (t_ssthresh < 1) {
1037 if (t_ucwnd_sbw < 1) {
1040 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1041 net->ssthresh = (uint32_t)(((uint64_t)4 *
1042 (uint64_t)net->mtu *
1043 (uint64_t)net->ssthresh) /
1044 (uint64_t)t_ssthresh);
1049 /* lastsa>>3; we don't need to divide ... */
1053 cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2;
1054 if (cc_delta < t_cwnd) {
1055 net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta);
1057 net->ssthresh = net->mtu;
1060 if ((net->cwnd > t_cwnd / 2) &&
1061 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1062 net->ssthresh = net->cwnd - t_cwnd / 2;
1064 if (net->ssthresh < net->mtu) {
1065 net->ssthresh = net->mtu;
1068 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1070 net->cwnd = net->mtu;
1071 net->partial_bytes_acked = 0;
1072 SDT_PROBE5(sctp, cwnd, net, to,
1074 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1076 old_cwnd, net->cwnd);
1077 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1078 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1083 sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1084 int in_window, int num_pkt_lost, int use_rtcc)
1086 int old_cwnd = net->cwnd;
1088 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1089 /* Data center Congestion Control */
1090 if (in_window == 0) {
1092 * Go to CA with the cwnd at the point we sent the
1093 * TSN that was marked with a CE.
1095 if (net->ecn_prev_cwnd < net->cwnd) {
1096 /* Restore to prev cwnd */
1097 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1099 /* Just cut in 1/2 */
1103 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1104 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1105 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1109 * Further tuning down required over the drastic
1112 net->ssthresh -= (net->mtu * num_pkt_lost);
1113 net->cwnd -= (net->mtu * num_pkt_lost);
1114 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1115 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1118 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1120 if (in_window == 0) {
1121 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1122 net->ssthresh = net->cwnd / 2;
1123 if (net->ssthresh < net->mtu) {
1124 net->ssthresh = net->mtu;
1126 * here back off the timer as well, to slow
1131 net->cwnd = net->ssthresh;
1132 SDT_PROBE5(sctp, cwnd, net, ecn,
1134 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1136 old_cwnd, net->cwnd);
1137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1138 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1146 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1147 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1148 uint32_t *bottle_bw, uint32_t *on_queue)
1152 int old_cwnd = net->cwnd;
1154 /* get bottle neck bw */
1155 *bottle_bw = ntohl(cp->bottle_bw);
1156 /* and whats on queue */
1157 *on_queue = ntohl(cp->current_onq);
1159 * adjust the on-queue if our flight is more it could be that the
1160 * router has not yet gotten data "in-flight" to it
1162 if (*on_queue < net->flight_size) {
1163 *on_queue = net->flight_size;
1165 /* rtt is measured in micro seconds, bottle_bw in bytes per second */
1166 bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000);
1167 if (bw_avail > *bottle_bw) {
1169 * Cap the growth to no more than the bottle neck. This can
1170 * happen as RTT slides up due to queues. It also means if
1171 * you have more than a 1 second RTT with a empty queue you
1172 * will be limited to the bottle_bw per second no matter if
1173 * other points have 1/2 the RTT and you could get more
1176 bw_avail = *bottle_bw;
1178 if (*on_queue > bw_avail) {
1180 * No room for anything else don't allow anything else to be
1181 * "added to the fire".
1183 int seg_inflight, seg_onqueue, my_portion;
1185 net->partial_bytes_acked = 0;
1186 /* how much are we over queue size? */
1187 incr = *on_queue - bw_avail;
1188 if (stcb->asoc.seen_a_sack_this_pkt) {
1190 * undo any cwnd adjustment that the sack might have
1193 net->cwnd = net->prev_cwnd;
1195 /* Now how much of that is mine? */
1196 seg_inflight = net->flight_size / net->mtu;
1197 seg_onqueue = *on_queue / net->mtu;
1198 my_portion = (incr * seg_inflight) / seg_onqueue;
1200 /* Have I made an adjustment already */
1201 if (net->cwnd > net->flight_size) {
1203 * for this flight I made an adjustment we need to
1204 * decrease the portion by a share our previous
1209 diff_adj = net->cwnd - net->flight_size;
1210 if (diff_adj > my_portion)
1213 my_portion -= diff_adj;
1216 * back down to the previous cwnd (assume we have had a sack
1217 * before this packet). minus what ever portion of the
1218 * overage is my fault.
1220 net->cwnd -= my_portion;
1222 /* we will NOT back down more than 1 MTU */
1223 if (net->cwnd <= net->mtu) {
1224 net->cwnd = net->mtu;
1227 net->ssthresh = net->cwnd - 1;
1230 * Take 1/4 of the space left or max burst up .. whichever
1233 incr = (bw_avail - *on_queue) >> 2;
1234 if ((stcb->asoc.max_burst > 0) &&
1235 (stcb->asoc.max_burst * net->mtu < incr)) {
1236 incr = stcb->asoc.max_burst * net->mtu;
1240 if (net->cwnd > bw_avail) {
1241 /* We can't exceed the pipe size */
1242 net->cwnd = bw_avail;
1244 if (net->cwnd < net->mtu) {
1245 /* We always have 1 MTU */
1246 net->cwnd = net->mtu;
1248 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1249 if (net->cwnd - old_cwnd != 0) {
1250 /* log only changes */
1251 SDT_PROBE5(sctp, cwnd, net, pd,
1253 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1255 old_cwnd, net->cwnd);
1256 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1257 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1258 SCTP_CWND_LOG_FROM_SAT);
1264 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1265 struct sctp_nets *net, int burst_limit)
1267 int old_cwnd = net->cwnd;
1269 if (net->ssthresh < net->cwnd)
1270 net->ssthresh = net->cwnd;
1272 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1273 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1274 SDT_PROBE5(sctp, cwnd, net, bl,
1276 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1278 old_cwnd, net->cwnd);
1279 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1280 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1286 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1287 struct sctp_association *asoc,
1288 int accum_moved, int reneged_all, int will_exit)
1290 /* Passing a zero argument in last disables the rtcc algorithm */
1291 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1295 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1296 int in_window, int num_pkt_lost)
1298 /* Passing a zero argument in last disables the rtcc algorithm */
1299 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1302 /* Here starts the RTCCVAR type CC invented by RRS which
1303 * is a slight mod to RFC2581. We reuse a common routine or
1304 * two since these algorithms are so close and need to
1308 sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1309 int in_window, int num_pkt_lost)
1311 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1315 sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1316 struct sctp_tmit_chunk *tp1)
1318 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1322 sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1323 struct sctp_nets *net)
1325 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1326 /* We had a bw measurement going on */
1327 struct timeval ltls;
1329 SCTP_GETPTIME_TIMEVAL(<ls);
1330 timevalsub(<ls, &net->cc_mod.rtcc.tls);
1331 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1336 sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1337 struct sctp_nets *net)
1339 uint64_t vtag, probepoint;
1341 if (net->cc_mod.rtcc.lbw) {
1342 /* Clear the old bw.. we went to 0 in-flight */
1343 vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1345 probepoint = (((uint64_t)net->cwnd) << 32);
1347 probepoint |= ((8 << 16) | 0);
1348 SDT_PROBE5(sctp, cwnd, net, rttvar,
1350 ((net->cc_mod.rtcc.lbw << 32) | 0),
1351 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1354 net->cc_mod.rtcc.lbw_rtt = 0;
1355 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1356 net->cc_mod.rtcc.lbw = 0;
1357 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1358 net->cc_mod.rtcc.vol_reduce = 0;
1359 net->cc_mod.rtcc.bw_tot_time = 0;
1360 net->cc_mod.rtcc.bw_bytes = 0;
1361 net->cc_mod.rtcc.tls_needs_set = 0;
1362 if (net->cc_mod.rtcc.steady_step) {
1363 net->cc_mod.rtcc.vol_reduce = 0;
1364 net->cc_mod.rtcc.step_cnt = 0;
1365 net->cc_mod.rtcc.last_step_state = 0;
1367 if (net->cc_mod.rtcc.ret_from_eq) {
1368 /* less aggressive one - reset cwnd too */
1369 uint32_t cwnd_in_mtu, cwnd;
1371 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1372 if (cwnd_in_mtu == 0) {
1374 * Using 0 means that the value of RFC 4960
1377 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1380 * We take the minimum of the burst limit
1381 * and the initial congestion window.
1383 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1384 cwnd_in_mtu = stcb->asoc.max_burst;
1385 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1387 if (net->cwnd > cwnd) {
1389 * Only set if we are not a timeout (i.e.
1399 sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1400 struct sctp_nets *net)
1402 uint64_t vtag, probepoint;
1404 sctp_set_initial_cc_param(stcb, net);
1405 stcb->asoc.use_precise_time = 1;
1406 probepoint = (((uint64_t)net->cwnd) << 32);
1407 probepoint |= ((9 << 16) | 0);
1408 vtag = (net->rtt << 32) |
1409 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1411 SDT_PROBE5(sctp, cwnd, net, rttvar,
1417 net->cc_mod.rtcc.lbw_rtt = 0;
1418 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1419 net->cc_mod.rtcc.vol_reduce = 0;
1420 net->cc_mod.rtcc.lbw = 0;
1421 net->cc_mod.rtcc.vol_reduce = 0;
1422 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1423 net->cc_mod.rtcc.bw_tot_time = 0;
1424 net->cc_mod.rtcc.bw_bytes = 0;
1425 net->cc_mod.rtcc.tls_needs_set = 0;
1426 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1427 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1428 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1429 net->cc_mod.rtcc.step_cnt = 0;
1430 net->cc_mod.rtcc.last_step_state = 0;
1434 sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1435 struct sctp_cc_option *cc_opt)
1437 struct sctp_nets *net;
1439 if (setorget == 1) {
1441 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1442 if ((cc_opt->aid_value.assoc_value != 0) &&
1443 (cc_opt->aid_value.assoc_value != 1)) {
1446 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1447 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1449 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1450 if ((cc_opt->aid_value.assoc_value != 0) &&
1451 (cc_opt->aid_value.assoc_value != 1)) {
1454 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1455 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1457 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1459 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1466 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1467 net = TAILQ_FIRST(&stcb->asoc.nets);
1471 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1472 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1473 net = TAILQ_FIRST(&stcb->asoc.nets);
1477 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1478 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1479 net = TAILQ_FIRST(&stcb->asoc.nets);
1483 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1492 sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1493 struct sctp_nets *net)
1495 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1496 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1497 net->cc_mod.rtcc.tls_needs_set = 2;
1502 sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1503 struct sctp_association *asoc,
1504 int accum_moved, int reneged_all, int will_exit)
1506 /* Passing a one argument at the last enables the rtcc algorithm */
1507 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1511 sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1512 struct sctp_nets *net,
1513 struct timeval *now SCTP_UNUSED)
1515 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1518 /* Here starts Sally Floyds HS-TCP */
1520 struct sctp_hs_raise_drop {
1523 int8_t drop_percent;
1526 #define SCTP_HS_TABLE_SIZE 73
1528 static const struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1529 {38, 1, 50}, /* 0 */
1530 {118, 2, 44}, /* 1 */
1531 {221, 3, 41}, /* 2 */
1532 {347, 4, 38}, /* 3 */
1533 {495, 5, 37}, /* 4 */
1534 {663, 6, 35}, /* 5 */
1535 {851, 7, 34}, /* 6 */
1536 {1058, 8, 33}, /* 7 */
1537 {1284, 9, 32}, /* 8 */
1538 {1529, 10, 31}, /* 9 */
1539 {1793, 11, 30}, /* 10 */
1540 {2076, 12, 29}, /* 11 */
1541 {2378, 13, 28}, /* 12 */
1542 {2699, 14, 28}, /* 13 */
1543 {3039, 15, 27}, /* 14 */
1544 {3399, 16, 27}, /* 15 */
1545 {3778, 17, 26}, /* 16 */
1546 {4177, 18, 26}, /* 17 */
1547 {4596, 19, 25}, /* 18 */
1548 {5036, 20, 25}, /* 19 */
1549 {5497, 21, 24}, /* 20 */
1550 {5979, 22, 24}, /* 21 */
1551 {6483, 23, 23}, /* 22 */
1552 {7009, 24, 23}, /* 23 */
1553 {7558, 25, 22}, /* 24 */
1554 {8130, 26, 22}, /* 25 */
1555 {8726, 27, 22}, /* 26 */
1556 {9346, 28, 21}, /* 27 */
1557 {9991, 29, 21}, /* 28 */
1558 {10661, 30, 21}, /* 29 */
1559 {11358, 31, 20}, /* 30 */
1560 {12082, 32, 20}, /* 31 */
1561 {12834, 33, 20}, /* 32 */
1562 {13614, 34, 19}, /* 33 */
1563 {14424, 35, 19}, /* 34 */
1564 {15265, 36, 19}, /* 35 */
1565 {16137, 37, 19}, /* 36 */
1566 {17042, 38, 18}, /* 37 */
1567 {17981, 39, 18}, /* 38 */
1568 {18955, 40, 18}, /* 39 */
1569 {19965, 41, 17}, /* 40 */
1570 {21013, 42, 17}, /* 41 */
1571 {22101, 43, 17}, /* 42 */
1572 {23230, 44, 17}, /* 43 */
1573 {24402, 45, 16}, /* 44 */
1574 {25618, 46, 16}, /* 45 */
1575 {26881, 47, 16}, /* 46 */
1576 {28193, 48, 16}, /* 47 */
1577 {29557, 49, 15}, /* 48 */
1578 {30975, 50, 15}, /* 49 */
1579 {32450, 51, 15}, /* 50 */
1580 {33986, 52, 15}, /* 51 */
1581 {35586, 53, 14}, /* 52 */
1582 {37253, 54, 14}, /* 53 */
1583 {38992, 55, 14}, /* 54 */
1584 {40808, 56, 14}, /* 55 */
1585 {42707, 57, 13}, /* 56 */
1586 {44694, 58, 13}, /* 57 */
1587 {46776, 59, 13}, /* 58 */
1588 {48961, 60, 13}, /* 59 */
1589 {51258, 61, 13}, /* 60 */
1590 {53677, 62, 12}, /* 61 */
1591 {56230, 63, 12}, /* 62 */
1592 {58932, 64, 12}, /* 63 */
1593 {61799, 65, 12}, /* 64 */
1594 {64851, 66, 11}, /* 65 */
1595 {68113, 67, 11}, /* 66 */
1596 {71617, 68, 11}, /* 67 */
1597 {75401, 69, 10}, /* 68 */
1598 {79517, 70, 10}, /* 69 */
1599 {84035, 71, 10}, /* 70 */
1600 {89053, 72, 10}, /* 71 */
1601 {94717, 73, 9} /* 72 */
1605 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1607 int cur_val, i, indx, incr;
1608 int old_cwnd = net->cwnd;
1610 cur_val = net->cwnd >> 10;
1611 indx = SCTP_HS_TABLE_SIZE - 1;
1613 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1615 if (net->net_ack > net->mtu) {
1616 net->cwnd += net->mtu;
1618 net->cwnd += net->net_ack;
1621 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1622 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1627 net->last_hs_used = indx;
1628 incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10);
1631 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1632 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1633 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SS);
1638 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1640 int cur_val, i, indx;
1641 int old_cwnd = net->cwnd;
1643 cur_val = net->cwnd >> 10;
1644 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1646 net->ssthresh = net->cwnd / 2;
1647 if (net->ssthresh < (net->mtu * 2)) {
1648 net->ssthresh = 2 * net->mtu;
1650 net->cwnd = net->ssthresh;
1652 /* drop by the proper amount */
1653 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1654 (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1655 net->cwnd = net->ssthresh;
1656 /* now where are we */
1657 indx = net->last_hs_used;
1658 cur_val = net->cwnd >> 10;
1659 /* reset where we are in the table */
1660 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1661 /* feel out of hs */
1662 net->last_hs_used = 0;
1664 for (i = indx; i >= 1; i--) {
1665 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1669 net->last_hs_used = indx;
1672 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1673 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1674 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1679 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1680 struct sctp_association *asoc)
1682 struct sctp_nets *net;
1685 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1686 * (net->fast_retran_loss_recovery == 0)))
1688 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1689 if ((asoc->fast_retran_loss_recovery == 0) ||
1690 (asoc->sctp_cmt_on_off > 0)) {
1691 /* out of a RFC2582 Fast recovery window? */
1692 if (net->net_ack > 0) {
1694 * per section 7.2.3, are there any
1695 * destinations that had a fast retransmit
1696 * to them. If so what we need to do is
1697 * adjust ssthresh and cwnd.
1699 struct sctp_tmit_chunk *lchk;
1701 sctp_hs_cwnd_decrease(stcb, net);
1703 lchk = TAILQ_FIRST(&asoc->send_queue);
1705 net->partial_bytes_acked = 0;
1706 /* Turn on fast recovery window */
1707 asoc->fast_retran_loss_recovery = 1;
1709 /* Mark end of the window */
1710 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1712 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1716 * CMT fast recovery -- per destination
1717 * recovery variable.
1719 net->fast_retran_loss_recovery = 1;
1722 /* Mark end of the window */
1723 net->fast_recovery_tsn = asoc->sending_seq - 1;
1725 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1728 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1729 stcb->sctp_ep, stcb, net,
1730 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_2);
1731 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1732 stcb->sctp_ep, stcb, net);
1734 } else if (net->net_ack > 0) {
1736 * Mark a peg that we WOULD have done a cwnd
1737 * reduction but RFC2582 prevented this action.
1739 SCTP_STAT_INCR(sctps_fastretransinrtt);
1745 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1746 struct sctp_association *asoc,
1747 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1749 struct sctp_nets *net;
1751 /******************************/
1752 /* update cwnd and Early FR */
1753 /******************************/
1754 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1755 #ifdef JANA_CMT_FAST_RECOVERY
1757 * CMT fast recovery code. Need to debug.
1759 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1760 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1761 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1762 net->will_exit_fast_recovery = 1;
1766 /* if nothing was acked on this destination skip it */
1767 if (net->net_ack == 0) {
1768 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1769 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1773 #ifdef JANA_CMT_FAST_RECOVERY
1775 * CMT fast recovery code
1778 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1779 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1780 * } else if (sctp_cmt_on_off == 0 &&
1781 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1785 if (asoc->fast_retran_loss_recovery &&
1787 (asoc->sctp_cmt_on_off == 0)) {
1789 * If we are in loss recovery we skip any cwnd
1795 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1799 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1800 /* If the cumulative ack moved we can proceed */
1801 if (net->cwnd <= net->ssthresh) {
1802 /* We are in slow start */
1803 if (net->flight_size + net->net_ack >= net->cwnd) {
1804 sctp_hs_cwnd_increase(stcb, net);
1806 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1807 sctp_log_cwnd(stcb, net, net->net_ack,
1808 SCTP_CWND_LOG_NOADV_SS);
1812 /* We are in congestion avoidance */
1813 net->partial_bytes_acked += net->net_ack;
1814 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1815 (net->partial_bytes_acked >= net->cwnd)) {
1816 net->partial_bytes_acked -= net->cwnd;
1817 net->cwnd += net->mtu;
1818 sctp_enforce_cwnd_limit(asoc, net);
1819 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1820 sctp_log_cwnd(stcb, net, net->mtu,
1821 SCTP_CWND_LOG_FROM_CA);
1824 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1825 sctp_log_cwnd(stcb, net, net->net_ack,
1826 SCTP_CWND_LOG_NOADV_CA);
1831 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1832 sctp_log_cwnd(stcb, net, net->mtu,
1833 SCTP_CWND_LOG_NO_CUMACK);
1840 * H-TCP congestion control. The algorithm is detailed in:
1841 * R.N.Shorten, D.J.Leith:
1842 * "H-TCP: TCP for high-speed and long-distance networks"
1843 * Proc. PFLDnet, Argonne, 2004.
1844 * http://www.hamilton.ie/net/htcp3.pdf
1847 static int use_rtt_scaling = 1;
1848 static int use_bandwidth_switch = 1;
1851 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1853 return (seq3 - seq2 >= seq1 - seq2);
1856 static inline uint32_t
1857 htcp_cong_time(struct htcp *ca)
1859 return (sctp_get_tick_count() - ca->last_cong);
1862 static inline uint32_t
1863 htcp_ccount(struct htcp *ca)
1865 return (ca->minRTT == 0 ? htcp_cong_time(ca) : htcp_cong_time(ca) / ca->minRTT);
1869 htcp_reset(struct htcp *ca)
1871 ca->undo_last_cong = ca->last_cong;
1872 ca->undo_maxRTT = ca->maxRTT;
1873 ca->undo_old_maxB = ca->old_maxB;
1874 ca->last_cong = sctp_get_tick_count();
1877 #ifdef SCTP_NOT_USED
1880 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1882 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1883 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1884 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1885 return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu));
1891 measure_rtt(struct sctp_nets *net)
1893 uint32_t srtt = net->lastsa >> SCTP_RTT_SHIFT;
1895 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1896 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1897 net->cc_mod.htcp_ca.minRTT = srtt;
1900 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1901 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
1902 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
1903 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT + sctp_msecs_to_ticks(20))
1904 net->cc_mod.htcp_ca.maxRTT = srtt;
1909 measure_achieved_throughput(struct sctp_nets *net)
1911 uint32_t now = sctp_get_tick_count();
1913 if (net->fast_retran_ip == 0)
1914 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
1916 if (!use_bandwidth_switch)
1919 /* achieved throughput calculations */
1920 /* JRS - not 100% sure of this statement */
1921 if (net->fast_retran_ip == 1) {
1922 net->cc_mod.htcp_ca.bytecount = 0;
1923 net->cc_mod.htcp_ca.lasttime = now;
1927 net->cc_mod.htcp_ca.bytecount += net->net_ack;
1928 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)) &&
1929 (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) &&
1930 (net->cc_mod.htcp_ca.minRTT > 0)) {
1931 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount / net->mtu * hz / (now - net->cc_mod.htcp_ca.lasttime);
1933 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
1934 /* just after backoff */
1935 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
1937 net->cc_mod.htcp_ca.Bi = (3 * net->cc_mod.htcp_ca.Bi + cur_Bi) / 4;
1938 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
1939 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
1940 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
1941 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
1943 net->cc_mod.htcp_ca.bytecount = 0;
1944 net->cc_mod.htcp_ca.lasttime = now;
1949 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1951 if (use_bandwidth_switch) {
1952 uint32_t maxB = ca->maxB;
1953 uint32_t old_maxB = ca->old_maxB;
1955 ca->old_maxB = ca->maxB;
1957 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1958 ca->beta = BETA_MIN;
1964 if (ca->modeswitch && minRTT > sctp_msecs_to_ticks(10) && maxRTT) {
1965 ca->beta = (minRTT << 7) / maxRTT;
1966 if (ca->beta < BETA_MIN)
1967 ca->beta = BETA_MIN;
1968 else if (ca->beta > BETA_MAX)
1969 ca->beta = BETA_MAX;
1971 ca->beta = BETA_MIN;
1977 htcp_alpha_update(struct htcp *ca)
1979 uint32_t minRTT = ca->minRTT;
1980 uint32_t factor = 1;
1981 uint32_t diff = htcp_cong_time(ca);
1983 if (diff > (uint32_t)hz) {
1985 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1988 if (use_rtt_scaling && minRTT) {
1989 uint32_t scale = (hz << 3) / (10 * minRTT);
1991 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1992 * interval [0.5,10]<<3 */
1993 factor = (factor << 3) / scale;
1998 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
2000 ca->alpha = ALPHA_BASE;
2003 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
2004 * rtt before we adjust our beta to ensure we are working from a consistent
2007 * This function should be called when we hit a congestion event since only at
2008 * that point do we really have a real sense of maxRTT (the queues en route
2009 * were getting just too full now).
2012 htcp_param_update(struct sctp_nets *net)
2014 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2015 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2017 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2018 htcp_alpha_update(&net->cc_mod.htcp_ca);
2021 * add slowly fading memory for maxRTT to accommodate routing
2024 if (minRTT > 0 && maxRTT > minRTT)
2025 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
2029 htcp_recalc_ssthresh(struct sctp_nets *net)
2031 htcp_param_update(net);
2032 return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu));
2036 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2039 * How to handle these functions?
2040 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2043 if (net->cwnd <= net->ssthresh) {
2044 /* We are in slow start */
2045 if (net->flight_size + net->net_ack >= net->cwnd) {
2046 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2047 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2048 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2049 sctp_log_cwnd(stcb, net, net->mtu,
2050 SCTP_CWND_LOG_FROM_SS);
2054 net->cwnd += net->net_ack;
2055 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2056 sctp_log_cwnd(stcb, net, net->net_ack,
2057 SCTP_CWND_LOG_FROM_SS);
2060 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2062 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2063 sctp_log_cwnd(stcb, net, net->net_ack,
2064 SCTP_CWND_LOG_NOADV_SS);
2071 * In dangerous area, increase slowly. In theory this is
2072 * net->cwnd += alpha / net->cwnd
2074 /* What is snd_cwnd_cnt?? */
2075 if (((net->partial_bytes_acked / net->mtu * net->cc_mod.htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
2077 * Does SCTP have a cwnd clamp?
2078 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2080 net->cwnd += net->mtu;
2081 net->partial_bytes_acked = 0;
2082 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2083 htcp_alpha_update(&net->cc_mod.htcp_ca);
2084 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2085 sctp_log_cwnd(stcb, net, net->mtu,
2086 SCTP_CWND_LOG_FROM_CA);
2089 net->partial_bytes_acked += net->net_ack;
2090 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2091 sctp_log_cwnd(stcb, net, net->net_ack,
2092 SCTP_CWND_LOG_NOADV_CA);
2096 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2100 #ifdef SCTP_NOT_USED
2101 /* Lower bound on congestion window. */
2103 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2105 return (net->ssthresh);
2110 htcp_init(struct sctp_nets *net)
2112 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2113 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2114 net->cc_mod.htcp_ca.beta = BETA_MIN;
2115 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2116 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2120 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2123 * We take the max of the burst limit times a MTU or the
2124 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2126 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2127 net->ssthresh = stcb->asoc.peers_rwnd;
2128 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
2132 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2137 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2138 struct sctp_association *asoc,
2139 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2141 struct sctp_nets *net;
2143 /******************************/
2144 /* update cwnd and Early FR */
2145 /******************************/
2146 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2147 #ifdef JANA_CMT_FAST_RECOVERY
2149 * CMT fast recovery code. Need to debug.
2151 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2152 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2153 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
2154 net->will_exit_fast_recovery = 1;
2158 /* if nothing was acked on this destination skip it */
2159 if (net->net_ack == 0) {
2160 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2161 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2165 #ifdef JANA_CMT_FAST_RECOVERY
2167 * CMT fast recovery code
2170 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
2171 * && net->will_exit_fast_recovery == 0) { @@@ Do something
2172 * } else if (sctp_cmt_on_off == 0 &&
2173 * asoc->fast_retran_loss_recovery && will_exit == 0) {
2177 if (asoc->fast_retran_loss_recovery &&
2179 (asoc->sctp_cmt_on_off == 0)) {
2181 * If we are in loss recovery we skip any cwnd
2187 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2191 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2192 htcp_cong_avoid(stcb, net);
2193 measure_achieved_throughput(net);
2195 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2196 sctp_log_cwnd(stcb, net, net->mtu,
2197 SCTP_CWND_LOG_NO_CUMACK);
2204 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2205 struct sctp_association *asoc)
2207 struct sctp_nets *net;
2210 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2211 * (net->fast_retran_loss_recovery == 0)))
2213 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2214 if ((asoc->fast_retran_loss_recovery == 0) ||
2215 (asoc->sctp_cmt_on_off > 0)) {
2216 /* out of a RFC2582 Fast recovery window? */
2217 if (net->net_ack > 0) {
2219 * per section 7.2.3, are there any
2220 * destinations that had a fast retransmit
2221 * to them. If so what we need to do is
2222 * adjust ssthresh and cwnd.
2224 struct sctp_tmit_chunk *lchk;
2225 int old_cwnd = net->cwnd;
2227 /* JRS - reset as if state were changed */
2228 htcp_reset(&net->cc_mod.htcp_ca);
2229 net->ssthresh = htcp_recalc_ssthresh(net);
2230 net->cwnd = net->ssthresh;
2231 sctp_enforce_cwnd_limit(asoc, net);
2232 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2233 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2234 SCTP_CWND_LOG_FROM_FR);
2236 lchk = TAILQ_FIRST(&asoc->send_queue);
2238 net->partial_bytes_acked = 0;
2239 /* Turn on fast recovery window */
2240 asoc->fast_retran_loss_recovery = 1;
2242 /* Mark end of the window */
2243 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2245 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2249 * CMT fast recovery -- per destination
2250 * recovery variable.
2252 net->fast_retran_loss_recovery = 1;
2255 /* Mark end of the window */
2256 net->fast_recovery_tsn = asoc->sending_seq - 1;
2258 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2261 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2262 stcb->sctp_ep, stcb, net,
2263 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_3);
2264 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2265 stcb->sctp_ep, stcb, net);
2267 } else if (net->net_ack > 0) {
2269 * Mark a peg that we WOULD have done a cwnd
2270 * reduction but RFC2582 prevented this action.
2272 SCTP_STAT_INCR(sctps_fastretransinrtt);
2278 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2279 struct sctp_nets *net)
2281 int old_cwnd = net->cwnd;
2283 /* JRS - reset as if the state were being changed to timeout */
2284 htcp_reset(&net->cc_mod.htcp_ca);
2285 net->ssthresh = htcp_recalc_ssthresh(net);
2286 net->cwnd = net->mtu;
2287 net->partial_bytes_acked = 0;
2288 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2289 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2294 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2295 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2299 old_cwnd = net->cwnd;
2301 /* JRS - reset hctp as if state changed */
2302 if (in_window == 0) {
2303 htcp_reset(&net->cc_mod.htcp_ca);
2304 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2305 net->ssthresh = htcp_recalc_ssthresh(net);
2306 if (net->ssthresh < net->mtu) {
2307 net->ssthresh = net->mtu;
2308 /* here back off the timer as well, to slow us down */
2311 net->cwnd = net->ssthresh;
2312 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2313 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2314 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2319 const struct sctp_cc_functions sctp_cc_functions[] = {
2321 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2322 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2323 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2324 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2325 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2326 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2327 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2328 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2331 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2332 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2333 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2334 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2335 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2336 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2337 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2338 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2341 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2342 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2343 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2344 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2345 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2346 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2347 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2348 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2351 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2352 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2353 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2354 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2355 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2356 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2357 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2358 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2359 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2360 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2361 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2362 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2363 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2364 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated