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_dtrace_declare.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) {
135 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
136 * (net->fast_retran_loss_recovery == 0)))
138 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
139 if ((asoc->fast_retran_loss_recovery == 0) ||
140 (asoc->sctp_cmt_on_off > 0)) {
141 /* out of a RFC2582 Fast recovery window? */
142 if (net->net_ack > 0) {
144 * per section 7.2.3, are there any
145 * destinations that had a fast retransmit
146 * to them. If so what we need to do is
147 * adjust ssthresh and cwnd.
149 struct sctp_tmit_chunk *lchk;
150 int old_cwnd = net->cwnd;
152 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
153 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
154 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
155 net->ssthresh = (uint32_t)(((uint64_t)4 *
157 (uint64_t)net->ssthresh) /
158 (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 */
253 cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
254 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
256 uint64_t oth, probepoint;
258 probepoint = (((uint64_t)net->cwnd) << 32);
259 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
261 * rtt increased we don't update bw.. so we don't update the
265 probepoint |= ((5 << 16) | 1);
266 SDT_PROBE5(sctp, cwnd, net, rttvar,
268 ((net->cc_mod.rtcc.lbw << 32) | nbw),
269 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
272 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
273 if (net->cc_mod.rtcc.last_step_state == 5)
274 net->cc_mod.rtcc.step_cnt++;
276 net->cc_mod.rtcc.step_cnt = 1;
277 net->cc_mod.rtcc.last_step_state = 5;
278 if ((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) &&
280 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
281 /* Try a step down */
282 oth = net->cc_mod.rtcc.vol_reduce;
284 oth |= net->cc_mod.rtcc.step_cnt;
286 oth |= net->cc_mod.rtcc.last_step_state;
287 SDT_PROBE5(sctp, cwnd, net, rttstep,
289 ((net->cc_mod.rtcc.lbw << 32) | nbw),
290 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
293 if (net->cwnd > (4 * net->mtu)) {
294 net->cwnd -= net->mtu;
295 net->cc_mod.rtcc.vol_reduce++;
297 net->cc_mod.rtcc.step_cnt = 0;
303 if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
305 * rtt decreased, there could be more room. we update both
306 * the bw and the rtt here to lock this in as a good step
310 probepoint |= ((6 << 16) | 0);
311 SDT_PROBE5(sctp, cwnd, net, rttvar,
313 ((net->cc_mod.rtcc.lbw << 32) | nbw),
314 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
317 if (net->cc_mod.rtcc.steady_step) {
318 oth = net->cc_mod.rtcc.vol_reduce;
320 oth |= net->cc_mod.rtcc.step_cnt;
322 oth |= net->cc_mod.rtcc.last_step_state;
323 SDT_PROBE5(sctp, cwnd, net, rttstep,
325 ((net->cc_mod.rtcc.lbw << 32) | nbw),
326 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
329 if ((net->cc_mod.rtcc.last_step_state == 5) &&
330 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
331 /* Step down worked */
332 net->cc_mod.rtcc.step_cnt = 0;
335 net->cc_mod.rtcc.last_step_state = 6;
336 net->cc_mod.rtcc.step_cnt = 0;
339 net->cc_mod.rtcc.lbw = nbw;
340 net->cc_mod.rtcc.lbw_rtt = net->rtt;
341 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
342 if (inst_ind == SCTP_INST_GAINING)
344 else if (inst_ind == SCTP_INST_NEUTRAL)
350 * Ok bw and rtt remained the same .. no update to any
353 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
354 SDT_PROBE5(sctp, cwnd, net, rttvar,
356 ((net->cc_mod.rtcc.lbw << 32) | nbw),
357 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
360 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
361 if (net->cc_mod.rtcc.last_step_state == 5)
362 net->cc_mod.rtcc.step_cnt++;
364 net->cc_mod.rtcc.step_cnt = 1;
365 net->cc_mod.rtcc.last_step_state = 5;
366 if ((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) &&
368 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
369 /* Try a step down */
370 if (net->cwnd > (4 * net->mtu)) {
371 net->cwnd -= net->mtu;
372 net->cc_mod.rtcc.vol_reduce++;
375 net->cc_mod.rtcc.step_cnt = 0;
379 if (inst_ind == SCTP_INST_GAINING)
381 else if (inst_ind == SCTP_INST_NEUTRAL)
384 return ((int)net->cc_mod.rtcc.ret_from_eq);
388 cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
389 uint64_t vtag, uint8_t inst_ind)
391 uint64_t oth, probepoint;
393 /* Bandwidth decreased. */
394 probepoint = (((uint64_t)net->cwnd) << 32);
395 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
397 /* Did we add more */
398 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
399 (inst_ind != SCTP_INST_LOOSING)) {
400 /* We caused it maybe.. back off? */
402 probepoint |= ((1 << 16) | 1);
403 SDT_PROBE5(sctp, cwnd, net, rttvar,
405 ((net->cc_mod.rtcc.lbw << 32) | nbw),
406 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
409 if (net->cc_mod.rtcc.ret_from_eq) {
411 * Switch over to CA if we are less
414 net->ssthresh = net->cwnd - 1;
415 net->partial_bytes_acked = 0;
420 probepoint |= ((2 << 16) | 0);
421 SDT_PROBE5(sctp, cwnd, net, rttvar,
423 ((net->cc_mod.rtcc.lbw << 32) | nbw),
424 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
427 /* Someone else - fight for more? */
428 if (net->cc_mod.rtcc.steady_step) {
429 oth = net->cc_mod.rtcc.vol_reduce;
431 oth |= net->cc_mod.rtcc.step_cnt;
433 oth |= net->cc_mod.rtcc.last_step_state;
434 SDT_PROBE5(sctp, cwnd, net, rttstep,
436 ((net->cc_mod.rtcc.lbw << 32) | nbw),
437 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
441 * Did we voluntarily give up some? if so take one
444 if ((net->cc_mod.rtcc.vol_reduce) &&
445 (inst_ind != SCTP_INST_GAINING)) {
446 net->cwnd += net->mtu;
447 sctp_enforce_cwnd_limit(&stcb->asoc, net);
448 net->cc_mod.rtcc.vol_reduce--;
450 net->cc_mod.rtcc.last_step_state = 2;
451 net->cc_mod.rtcc.step_cnt = 0;
454 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
455 /* bw & rtt decreased */
457 probepoint |= ((3 << 16) | 0);
458 SDT_PROBE5(sctp, cwnd, net, rttvar,
460 ((net->cc_mod.rtcc.lbw << 32) | nbw),
461 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
464 if (net->cc_mod.rtcc.steady_step) {
465 oth = net->cc_mod.rtcc.vol_reduce;
467 oth |= net->cc_mod.rtcc.step_cnt;
469 oth |= net->cc_mod.rtcc.last_step_state;
470 SDT_PROBE5(sctp, cwnd, net, rttstep,
472 ((net->cc_mod.rtcc.lbw << 32) | nbw),
473 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
476 if ((net->cc_mod.rtcc.vol_reduce) &&
477 (inst_ind != SCTP_INST_GAINING)) {
478 net->cwnd += net->mtu;
479 sctp_enforce_cwnd_limit(&stcb->asoc, net);
480 net->cc_mod.rtcc.vol_reduce--;
482 net->cc_mod.rtcc.last_step_state = 3;
483 net->cc_mod.rtcc.step_cnt = 0;
487 /* The bw decreased but rtt stayed the same */
489 probepoint |= ((4 << 16) | 0);
490 SDT_PROBE5(sctp, cwnd, net, rttvar,
492 ((net->cc_mod.rtcc.lbw << 32) | nbw),
493 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
496 if (net->cc_mod.rtcc.steady_step) {
497 oth = net->cc_mod.rtcc.vol_reduce;
499 oth |= net->cc_mod.rtcc.step_cnt;
501 oth |= net->cc_mod.rtcc.last_step_state;
502 SDT_PROBE5(sctp, cwnd, net, rttstep,
504 ((net->cc_mod.rtcc.lbw << 32) | nbw),
505 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
508 if ((net->cc_mod.rtcc.vol_reduce) &&
509 (inst_ind != SCTP_INST_GAINING)) {
510 net->cwnd += net->mtu;
511 sctp_enforce_cwnd_limit(&stcb->asoc, net);
512 net->cc_mod.rtcc.vol_reduce--;
514 net->cc_mod.rtcc.last_step_state = 4;
515 net->cc_mod.rtcc.step_cnt = 0;
518 net->cc_mod.rtcc.lbw = nbw;
519 net->cc_mod.rtcc.lbw_rtt = net->rtt;
520 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
521 if (inst_ind == SCTP_INST_GAINING) {
529 cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
531 uint64_t oth, probepoint;
534 * BW increased, so update and return 0, since all actions in our
535 * table say to do the normal CC update. Note that we pay no
536 * attention to the inst_ind since our overall sum is increasing.
539 probepoint = (((uint64_t)net->cwnd) << 32);
540 SDT_PROBE5(sctp, cwnd, net, rttvar,
542 ((net->cc_mod.rtcc.lbw << 32) | nbw),
543 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
546 if (net->cc_mod.rtcc.steady_step) {
547 oth = net->cc_mod.rtcc.vol_reduce;
549 oth |= net->cc_mod.rtcc.step_cnt;
551 oth |= net->cc_mod.rtcc.last_step_state;
552 SDT_PROBE5(sctp, cwnd, net, rttstep,
554 ((net->cc_mod.rtcc.lbw << 32) | nbw),
555 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
558 net->cc_mod.rtcc.last_step_state = 0;
559 net->cc_mod.rtcc.step_cnt = 0;
560 net->cc_mod.rtcc.vol_reduce = 0;
562 net->cc_mod.rtcc.lbw = nbw;
563 net->cc_mod.rtcc.lbw_rtt = net->rtt;
564 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
568 /* RTCC Algorithm to limit growth of cwnd, return
569 * true if you want to NOT allow cwnd growth
572 cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
574 uint64_t bw_offset, rtt_offset;
575 uint64_t probepoint, rtt, vtag;
576 uint64_t bytes_for_this_rtt, inst_bw;
577 uint64_t div, inst_off;
583 * Here we need to see if we want
584 * to limit cwnd growth due to increase
585 * in overall rtt but no increase in bw.
586 * We use the following table to figure
587 * out what we should do. When we return
588 * 0, cc update goes on as planned. If we
589 * return 1, then no cc update happens and cwnd
590 * stays where it is at.
591 * ----------------------------------
593 * *********************************
594 * INC | INC | return 0
595 * ----------------------------------
596 * INC | SAME | return 0
597 * ----------------------------------
598 * INC | DECR | return 0
599 * ----------------------------------
600 * SAME | INC | return 1
601 * ----------------------------------
602 * SAME | SAME | return 1
603 * ----------------------------------
604 * SAME | DECR | return 0
605 * ----------------------------------
606 * DECR | INC | return 0 or 1 based on if we caused.
607 * ----------------------------------
608 * DECR | SAME | return 0
609 * ----------------------------------
610 * DECR | DECR | return 0
611 * ----------------------------------
613 * We are a bit fuzz on what an increase or
614 * decrease is. For BW it is the same if
615 * it did not change within 1/64th. For
616 * RTT it stayed the same if it did not
617 * change within 1/32nd
619 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
620 rtt = stcb->asoc.my_vtag;
621 vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
622 probepoint = (((uint64_t)net->cwnd) << 32);
624 if (net->cc_mod.rtcc.rtt_set_this_sack) {
625 net->cc_mod.rtcc.rtt_set_this_sack = 0;
626 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
627 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
629 div = net->rtt / 1000;
631 inst_bw = bytes_for_this_rtt / div;
632 inst_off = inst_bw >> bw_shift;
634 inst_ind = SCTP_INST_GAINING;
635 else if ((inst_bw + inst_off) < nbw)
636 inst_ind = SCTP_INST_LOOSING;
638 inst_ind = SCTP_INST_NEUTRAL;
639 probepoint |= ((0xb << 16) | inst_ind);
641 inst_ind = net->cc_mod.rtcc.last_inst_ind;
642 inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
643 /* Can't determine do not change */
644 probepoint |= ((0xc << 16) | inst_ind);
647 inst_ind = net->cc_mod.rtcc.last_inst_ind;
648 inst_bw = bytes_for_this_rtt;
649 /* Can't determine do not change */
650 probepoint |= ((0xd << 16) | inst_ind);
652 SDT_PROBE5(sctp, cwnd, net, rttvar,
654 ((nbw << 32) | inst_bw),
655 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
659 /* No rtt measurement, use last one */
660 inst_ind = net->cc_mod.rtcc.last_inst_ind;
662 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
663 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
664 ret = cc_bw_increase(stcb, net, nbw, vtag);
667 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
668 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
669 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
673 * If we reach here then we are in a situation where the bw stayed
676 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
678 net->cc_mod.rtcc.last_inst_ind = inst_ind;
683 sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
684 struct sctp_association *asoc,
685 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
687 struct sctp_nets *net;
689 uint32_t t_ssthresh, t_cwnd, incr;
690 uint64_t t_ucwnd_sbw;
691 uint64_t t_path_mptcp;
692 uint64_t mptcp_like_alpha;
696 /* MT FIXME: Don't compute this over and over again */
701 mptcp_like_alpha = 1;
702 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
703 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
704 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
706 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
707 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) {
741 #ifdef JANA_CMT_FAST_RECOVERY
743 * CMT fast recovery code. Need to debug.
745 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
746 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
747 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
748 net->will_exit_fast_recovery = 1;
752 /* if nothing was acked on this destination skip it */
753 if (net->net_ack == 0) {
754 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
755 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
759 #ifdef JANA_CMT_FAST_RECOVERY
761 * CMT fast recovery code
764 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
765 * && net->will_exit_fast_recovery == 0) { @@@ Do something
766 * } else if (sctp_cmt_on_off == 0 &&
767 * asoc->fast_retran_loss_recovery && will_exit == 0) {
771 if (asoc->fast_retran_loss_recovery &&
773 (asoc->sctp_cmt_on_off == 0)) {
775 * If we are in loss recovery we skip any cwnd
781 * Did any measurements go on for this network?
783 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
787 * At this point our bw_bytes has been updated by
788 * incoming sack information.
790 * But our bw may not yet be set.
793 if ((net->cc_mod.rtcc.new_tot_time / 1000) > 0) {
794 nbw = net->cc_mod.rtcc.bw_bytes / (net->cc_mod.rtcc.new_tot_time / 1000);
796 nbw = net->cc_mod.rtcc.bw_bytes;
798 if (net->cc_mod.rtcc.lbw) {
799 if (cc_bw_limit(stcb, net, nbw)) {
800 /* Hold here, no update */
804 uint64_t vtag, probepoint;
806 probepoint = (((uint64_t)net->cwnd) << 32);
807 probepoint |= ((0xa << 16) | 0);
808 vtag = (net->rtt << 32) |
809 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
812 SDT_PROBE5(sctp, cwnd, net, rttvar,
815 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
818 net->cc_mod.rtcc.lbw = nbw;
819 net->cc_mod.rtcc.lbw_rtt = net->rtt;
820 if (net->cc_mod.rtcc.rtt_set_this_sack) {
821 net->cc_mod.rtcc.rtt_set_this_sack = 0;
822 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
827 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
831 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
832 /* If the cumulative ack moved we can proceed */
833 if (net->cwnd <= net->ssthresh) {
834 /* We are in slow start */
835 if (net->flight_size + net->net_ack >= net->cwnd) {
838 old_cwnd = net->cwnd;
839 switch (asoc->sctp_cmt_on_off) {
841 limit = (uint32_t)(((uint64_t)net->mtu *
842 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
843 (uint64_t)net->ssthresh) /
844 (uint64_t)t_ssthresh);
845 incr = (uint32_t)(((uint64_t)net->net_ack *
846 (uint64_t)net->ssthresh) /
847 (uint64_t)t_ssthresh);
857 * lastsa>>3; we don't need
864 limit = (uint32_t)(((uint64_t)net->mtu *
865 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
866 (uint64_t)net->cwnd) /
867 ((uint64_t)srtt * t_ucwnd_sbw));
868 /* INCREASE FACTOR */
869 incr = (uint32_t)(((uint64_t)net->net_ack *
870 (uint64_t)net->cwnd) /
871 ((uint64_t)srtt * t_ucwnd_sbw));
872 /* INCREASE FACTOR */
881 limit = (uint32_t)(((uint64_t)net->mtu *
883 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
885 incr = (uint32_t)(((uint64_t)net->net_ack *
891 if (incr > net->net_ack) {
894 if (incr > net->mtu) {
900 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
901 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
906 sctp_enforce_cwnd_limit(asoc, net);
907 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
908 sctp_log_cwnd(stcb, net, incr,
909 SCTP_CWND_LOG_FROM_SS);
911 SDT_PROBE5(sctp, cwnd, net, ack,
913 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
915 old_cwnd, net->cwnd);
917 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
918 sctp_log_cwnd(stcb, net, net->net_ack,
919 SCTP_CWND_LOG_NOADV_SS);
923 /* We are in congestion avoidance */
927 net->partial_bytes_acked += net->net_ack;
929 if ((net->flight_size + net->net_ack >= net->cwnd) &&
930 (net->partial_bytes_acked >= net->cwnd)) {
931 net->partial_bytes_acked -= net->cwnd;
932 old_cwnd = net->cwnd;
933 switch (asoc->sctp_cmt_on_off) {
935 incr = (uint32_t)(((uint64_t)net->mtu *
936 (uint64_t)net->ssthresh) /
937 (uint64_t)t_ssthresh);
944 * lastsa>>3; we don't need
951 incr = (uint32_t)((uint64_t)net->mtu *
952 (uint64_t)net->cwnd /
955 /* INCREASE FACTOR */
961 incr = (uint32_t)((mptcp_like_alpha *
962 (uint64_t)net->cwnd) >>
964 if (incr > net->mtu) {
973 sctp_enforce_cwnd_limit(asoc, net);
974 SDT_PROBE5(sctp, cwnd, net, ack,
976 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
978 old_cwnd, net->cwnd);
979 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
980 sctp_log_cwnd(stcb, net, net->mtu,
981 SCTP_CWND_LOG_FROM_CA);
984 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
985 sctp_log_cwnd(stcb, net, net->net_ack,
986 SCTP_CWND_LOG_NOADV_CA);
991 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
992 sctp_log_cwnd(stcb, net, net->mtu,
993 SCTP_CWND_LOG_NO_CUMACK);
1000 sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
1004 old_cwnd = net->cwnd;
1005 net->cwnd = net->mtu;
1006 SDT_PROBE5(sctp, cwnd, net, ack,
1007 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
1008 old_cwnd, net->cwnd);
1009 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1010 (void *)net, net->cwnd);
1015 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
1017 int old_cwnd = net->cwnd;
1018 uint32_t t_ssthresh, t_cwnd;
1019 uint64_t t_ucwnd_sbw;
1021 /* MT FIXME: Don't compute this over and over again */
1024 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1025 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1026 struct sctp_nets *lnet;
1030 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1031 t_ssthresh += lnet->ssthresh;
1032 t_cwnd += lnet->cwnd;
1033 srtt = lnet->lastsa;
1034 /* lastsa>>3; we don't need to divide ... */
1036 t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt;
1039 if (t_ssthresh < 1) {
1042 if (t_ucwnd_sbw < 1) {
1045 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1046 net->ssthresh = (uint32_t)(((uint64_t)4 *
1047 (uint64_t)net->mtu *
1048 (uint64_t)net->ssthresh) /
1049 (uint64_t)t_ssthresh);
1054 /* lastsa>>3; we don't need to divide ... */
1058 cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2;
1059 if (cc_delta < t_cwnd) {
1060 net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta);
1062 net->ssthresh = net->mtu;
1065 if ((net->cwnd > t_cwnd / 2) &&
1066 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1067 net->ssthresh = net->cwnd - t_cwnd / 2;
1069 if (net->ssthresh < net->mtu) {
1070 net->ssthresh = net->mtu;
1073 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1075 net->cwnd = net->mtu;
1076 net->partial_bytes_acked = 0;
1077 SDT_PROBE5(sctp, cwnd, net, to,
1079 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1081 old_cwnd, net->cwnd);
1082 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1083 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1088 sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1089 int in_window, int num_pkt_lost, int use_rtcc)
1091 int old_cwnd = net->cwnd;
1093 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1094 /* Data center Congestion Control */
1095 if (in_window == 0) {
1097 * Go to CA with the cwnd at the point we sent the
1098 * TSN that was marked with a CE.
1100 if (net->ecn_prev_cwnd < net->cwnd) {
1101 /* Restore to prev cwnd */
1102 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1104 /* Just cut in 1/2 */
1108 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1109 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1110 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1114 * Further tuning down required over the drastic
1117 net->ssthresh -= (net->mtu * num_pkt_lost);
1118 net->cwnd -= (net->mtu * num_pkt_lost);
1119 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1120 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1123 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1125 if (in_window == 0) {
1126 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1127 net->ssthresh = net->cwnd / 2;
1128 if (net->ssthresh < net->mtu) {
1129 net->ssthresh = net->mtu;
1131 * here back off the timer as well, to slow
1136 net->cwnd = net->ssthresh;
1137 SDT_PROBE5(sctp, cwnd, net, ecn,
1139 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1141 old_cwnd, net->cwnd);
1142 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1143 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1151 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1152 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1153 uint32_t *bottle_bw, uint32_t *on_queue)
1157 int old_cwnd = net->cwnd;
1159 /* get bottle neck bw */
1160 *bottle_bw = ntohl(cp->bottle_bw);
1161 /* and whats on queue */
1162 *on_queue = ntohl(cp->current_onq);
1164 * adjust the on-queue if our flight is more it could be that the
1165 * router has not yet gotten data "in-flight" to it
1167 if (*on_queue < net->flight_size) {
1168 *on_queue = net->flight_size;
1170 /* rtt is measured in micro seconds, bottle_bw in bytes per second */
1171 bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000);
1172 if (bw_avail > *bottle_bw) {
1174 * Cap the growth to no more than the bottle neck. This can
1175 * happen as RTT slides up due to queues. It also means if
1176 * you have more than a 1 second RTT with a empty queue you
1177 * will be limited to the bottle_bw per second no matter if
1178 * other points have 1/2 the RTT and you could get more
1181 bw_avail = *bottle_bw;
1183 if (*on_queue > bw_avail) {
1185 * No room for anything else don't allow anything else to be
1186 * "added to the fire".
1188 int seg_inflight, seg_onqueue, my_portion;
1190 net->partial_bytes_acked = 0;
1191 /* how much are we over queue size? */
1192 incr = *on_queue - bw_avail;
1193 if (stcb->asoc.seen_a_sack_this_pkt) {
1195 * undo any cwnd adjustment that the sack might have
1198 net->cwnd = net->prev_cwnd;
1200 /* Now how much of that is mine? */
1201 seg_inflight = net->flight_size / net->mtu;
1202 seg_onqueue = *on_queue / net->mtu;
1203 my_portion = (incr * seg_inflight) / seg_onqueue;
1205 /* Have I made an adjustment already */
1206 if (net->cwnd > net->flight_size) {
1208 * for this flight I made an adjustment we need to
1209 * decrease the portion by a share our previous
1214 diff_adj = net->cwnd - net->flight_size;
1215 if (diff_adj > my_portion)
1218 my_portion -= diff_adj;
1221 * back down to the previous cwnd (assume we have had a sack
1222 * before this packet). minus what ever portion of the
1223 * overage is my fault.
1225 net->cwnd -= my_portion;
1227 /* we will NOT back down more than 1 MTU */
1228 if (net->cwnd <= net->mtu) {
1229 net->cwnd = net->mtu;
1232 net->ssthresh = net->cwnd - 1;
1235 * Take 1/4 of the space left or max burst up .. whichever
1238 incr = (bw_avail - *on_queue) >> 2;
1239 if ((stcb->asoc.max_burst > 0) &&
1240 (stcb->asoc.max_burst * net->mtu < incr)) {
1241 incr = stcb->asoc.max_burst * net->mtu;
1245 if (net->cwnd > bw_avail) {
1246 /* We can't exceed the pipe size */
1247 net->cwnd = bw_avail;
1249 if (net->cwnd < net->mtu) {
1250 /* We always have 1 MTU */
1251 net->cwnd = net->mtu;
1253 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1254 if (net->cwnd - old_cwnd != 0) {
1255 /* log only changes */
1256 SDT_PROBE5(sctp, cwnd, net, pd,
1258 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1260 old_cwnd, net->cwnd);
1261 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1262 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1263 SCTP_CWND_LOG_FROM_SAT);
1269 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1270 struct sctp_nets *net, int burst_limit)
1272 int old_cwnd = net->cwnd;
1274 if (net->ssthresh < net->cwnd)
1275 net->ssthresh = net->cwnd;
1277 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1278 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1279 SDT_PROBE5(sctp, cwnd, net, bl,
1281 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1283 old_cwnd, net->cwnd);
1284 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1285 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1291 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1292 struct sctp_association *asoc,
1293 int accum_moved, int reneged_all, int will_exit)
1295 /* Passing a zero argument in last disables the rtcc algorithm */
1296 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1300 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1301 int in_window, int num_pkt_lost)
1303 /* Passing a zero argument in last disables the rtcc algorithm */
1304 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1307 /* Here starts the RTCCVAR type CC invented by RRS which
1308 * is a slight mod to RFC2581. We reuse a common routine or
1309 * two since these algorithms are so close and need to
1313 sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1314 int in_window, int num_pkt_lost)
1316 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1322 sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1323 struct sctp_tmit_chunk *tp1)
1325 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1329 sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1330 struct sctp_nets *net)
1332 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1333 /* We had a bw measurment going on */
1334 struct timeval ltls;
1336 SCTP_GETPTIME_TIMEVAL(<ls);
1337 timevalsub(<ls, &net->cc_mod.rtcc.tls);
1338 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1343 sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1344 struct sctp_nets *net)
1346 uint64_t vtag, probepoint;
1348 if (net->cc_mod.rtcc.lbw) {
1349 /* Clear the old bw.. we went to 0 in-flight */
1350 vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1352 probepoint = (((uint64_t)net->cwnd) << 32);
1354 probepoint |= ((8 << 16) | 0);
1355 SDT_PROBE5(sctp, cwnd, net, rttvar,
1357 ((net->cc_mod.rtcc.lbw << 32) | 0),
1358 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1361 net->cc_mod.rtcc.lbw_rtt = 0;
1362 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1363 net->cc_mod.rtcc.lbw = 0;
1364 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1365 net->cc_mod.rtcc.vol_reduce = 0;
1366 net->cc_mod.rtcc.bw_tot_time = 0;
1367 net->cc_mod.rtcc.bw_bytes = 0;
1368 net->cc_mod.rtcc.tls_needs_set = 0;
1369 if (net->cc_mod.rtcc.steady_step) {
1370 net->cc_mod.rtcc.vol_reduce = 0;
1371 net->cc_mod.rtcc.step_cnt = 0;
1372 net->cc_mod.rtcc.last_step_state = 0;
1374 if (net->cc_mod.rtcc.ret_from_eq) {
1375 /* less aggressive one - reset cwnd too */
1376 uint32_t cwnd_in_mtu, cwnd;
1378 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1379 if (cwnd_in_mtu == 0) {
1381 * Using 0 means that the value of RFC 4960
1384 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1387 * We take the minimum of the burst limit
1388 * and the initial congestion window.
1390 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1391 cwnd_in_mtu = stcb->asoc.max_burst;
1392 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1394 if (net->cwnd > cwnd) {
1396 * Only set if we are not a timeout (i.e.
1406 sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1407 struct sctp_nets *net)
1409 uint64_t vtag, probepoint;
1411 sctp_set_initial_cc_param(stcb, net);
1412 stcb->asoc.use_precise_time = 1;
1413 probepoint = (((uint64_t)net->cwnd) << 32);
1414 probepoint |= ((9 << 16) | 0);
1415 vtag = (net->rtt << 32) |
1416 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1418 SDT_PROBE5(sctp, cwnd, net, rttvar,
1424 net->cc_mod.rtcc.lbw_rtt = 0;
1425 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1426 net->cc_mod.rtcc.vol_reduce = 0;
1427 net->cc_mod.rtcc.lbw = 0;
1428 net->cc_mod.rtcc.vol_reduce = 0;
1429 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1430 net->cc_mod.rtcc.bw_tot_time = 0;
1431 net->cc_mod.rtcc.bw_bytes = 0;
1432 net->cc_mod.rtcc.tls_needs_set = 0;
1433 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1434 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1435 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1436 net->cc_mod.rtcc.step_cnt = 0;
1437 net->cc_mod.rtcc.last_step_state = 0;
1443 sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1444 struct sctp_cc_option *cc_opt)
1446 struct sctp_nets *net;
1448 if (setorget == 1) {
1450 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1451 if ((cc_opt->aid_value.assoc_value != 0) &&
1452 (cc_opt->aid_value.assoc_value != 1)) {
1455 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1456 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1458 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1459 if ((cc_opt->aid_value.assoc_value != 0) &&
1460 (cc_opt->aid_value.assoc_value != 1)) {
1463 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1464 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1466 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1467 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1468 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1475 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1476 net = TAILQ_FIRST(&stcb->asoc.nets);
1480 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1481 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1482 net = TAILQ_FIRST(&stcb->asoc.nets);
1486 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1487 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1488 net = TAILQ_FIRST(&stcb->asoc.nets);
1492 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1501 sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1502 struct sctp_nets *net)
1504 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1505 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1506 net->cc_mod.rtcc.tls_needs_set = 2;
1511 sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1512 struct sctp_association *asoc,
1513 int accum_moved, int reneged_all, int will_exit)
1515 /* Passing a one argument at the last enables the rtcc algorithm */
1516 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1520 sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1521 struct sctp_nets *net,
1522 struct timeval *now SCTP_UNUSED)
1524 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1527 /* Here starts Sally Floyds HS-TCP */
1529 struct sctp_hs_raise_drop {
1532 int8_t drop_percent;
1535 #define SCTP_HS_TABLE_SIZE 73
1537 static const struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1538 {38, 1, 50}, /* 0 */
1539 {118, 2, 44}, /* 1 */
1540 {221, 3, 41}, /* 2 */
1541 {347, 4, 38}, /* 3 */
1542 {495, 5, 37}, /* 4 */
1543 {663, 6, 35}, /* 5 */
1544 {851, 7, 34}, /* 6 */
1545 {1058, 8, 33}, /* 7 */
1546 {1284, 9, 32}, /* 8 */
1547 {1529, 10, 31}, /* 9 */
1548 {1793, 11, 30}, /* 10 */
1549 {2076, 12, 29}, /* 11 */
1550 {2378, 13, 28}, /* 12 */
1551 {2699, 14, 28}, /* 13 */
1552 {3039, 15, 27}, /* 14 */
1553 {3399, 16, 27}, /* 15 */
1554 {3778, 17, 26}, /* 16 */
1555 {4177, 18, 26}, /* 17 */
1556 {4596, 19, 25}, /* 18 */
1557 {5036, 20, 25}, /* 19 */
1558 {5497, 21, 24}, /* 20 */
1559 {5979, 22, 24}, /* 21 */
1560 {6483, 23, 23}, /* 22 */
1561 {7009, 24, 23}, /* 23 */
1562 {7558, 25, 22}, /* 24 */
1563 {8130, 26, 22}, /* 25 */
1564 {8726, 27, 22}, /* 26 */
1565 {9346, 28, 21}, /* 27 */
1566 {9991, 29, 21}, /* 28 */
1567 {10661, 30, 21}, /* 29 */
1568 {11358, 31, 20}, /* 30 */
1569 {12082, 32, 20}, /* 31 */
1570 {12834, 33, 20}, /* 32 */
1571 {13614, 34, 19}, /* 33 */
1572 {14424, 35, 19}, /* 34 */
1573 {15265, 36, 19}, /* 35 */
1574 {16137, 37, 19}, /* 36 */
1575 {17042, 38, 18}, /* 37 */
1576 {17981, 39, 18}, /* 38 */
1577 {18955, 40, 18}, /* 39 */
1578 {19965, 41, 17}, /* 40 */
1579 {21013, 42, 17}, /* 41 */
1580 {22101, 43, 17}, /* 42 */
1581 {23230, 44, 17}, /* 43 */
1582 {24402, 45, 16}, /* 44 */
1583 {25618, 46, 16}, /* 45 */
1584 {26881, 47, 16}, /* 46 */
1585 {28193, 48, 16}, /* 47 */
1586 {29557, 49, 15}, /* 48 */
1587 {30975, 50, 15}, /* 49 */
1588 {32450, 51, 15}, /* 50 */
1589 {33986, 52, 15}, /* 51 */
1590 {35586, 53, 14}, /* 52 */
1591 {37253, 54, 14}, /* 53 */
1592 {38992, 55, 14}, /* 54 */
1593 {40808, 56, 14}, /* 55 */
1594 {42707, 57, 13}, /* 56 */
1595 {44694, 58, 13}, /* 57 */
1596 {46776, 59, 13}, /* 58 */
1597 {48961, 60, 13}, /* 59 */
1598 {51258, 61, 13}, /* 60 */
1599 {53677, 62, 12}, /* 61 */
1600 {56230, 63, 12}, /* 62 */
1601 {58932, 64, 12}, /* 63 */
1602 {61799, 65, 12}, /* 64 */
1603 {64851, 66, 11}, /* 65 */
1604 {68113, 67, 11}, /* 66 */
1605 {71617, 68, 11}, /* 67 */
1606 {75401, 69, 10}, /* 68 */
1607 {79517, 70, 10}, /* 69 */
1608 {84035, 71, 10}, /* 70 */
1609 {89053, 72, 10}, /* 71 */
1610 {94717, 73, 9} /* 72 */
1614 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1616 int cur_val, i, indx, incr;
1617 int old_cwnd = net->cwnd;
1619 cur_val = net->cwnd >> 10;
1620 indx = SCTP_HS_TABLE_SIZE - 1;
1622 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1624 if (net->net_ack > net->mtu) {
1625 net->cwnd += net->mtu;
1627 net->cwnd += net->net_ack;
1630 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1631 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1636 net->last_hs_used = indx;
1637 incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10);
1640 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1641 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1642 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SS);
1647 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1649 int cur_val, i, indx;
1650 int old_cwnd = net->cwnd;
1652 cur_val = net->cwnd >> 10;
1653 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1655 net->ssthresh = net->cwnd / 2;
1656 if (net->ssthresh < (net->mtu * 2)) {
1657 net->ssthresh = 2 * net->mtu;
1659 net->cwnd = net->ssthresh;
1661 /* drop by the proper amount */
1662 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1663 (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1664 net->cwnd = net->ssthresh;
1665 /* now where are we */
1666 indx = net->last_hs_used;
1667 cur_val = net->cwnd >> 10;
1668 /* reset where we are in the table */
1669 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1670 /* feel out of hs */
1671 net->last_hs_used = 0;
1673 for (i = indx; i >= 1; i--) {
1674 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1678 net->last_hs_used = indx;
1681 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1682 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1683 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1688 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1689 struct sctp_association *asoc)
1691 struct sctp_nets *net;
1694 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1695 * (net->fast_retran_loss_recovery == 0)))
1697 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1698 if ((asoc->fast_retran_loss_recovery == 0) ||
1699 (asoc->sctp_cmt_on_off > 0)) {
1700 /* out of a RFC2582 Fast recovery window? */
1701 if (net->net_ack > 0) {
1703 * per section 7.2.3, are there any
1704 * destinations that had a fast retransmit
1705 * to them. If so what we need to do is
1706 * adjust ssthresh and cwnd.
1708 struct sctp_tmit_chunk *lchk;
1710 sctp_hs_cwnd_decrease(stcb, net);
1712 lchk = TAILQ_FIRST(&asoc->send_queue);
1714 net->partial_bytes_acked = 0;
1715 /* Turn on fast recovery window */
1716 asoc->fast_retran_loss_recovery = 1;
1718 /* Mark end of the window */
1719 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1721 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1725 * CMT fast recovery -- per destination
1726 * recovery variable.
1728 net->fast_retran_loss_recovery = 1;
1731 /* Mark end of the window */
1732 net->fast_recovery_tsn = asoc->sending_seq - 1;
1734 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1737 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1738 stcb->sctp_ep, stcb, net,
1739 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_2);
1740 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1741 stcb->sctp_ep, stcb, net);
1743 } else if (net->net_ack > 0) {
1745 * Mark a peg that we WOULD have done a cwnd
1746 * reduction but RFC2582 prevented this action.
1748 SCTP_STAT_INCR(sctps_fastretransinrtt);
1754 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1755 struct sctp_association *asoc,
1756 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1758 struct sctp_nets *net;
1760 /******************************/
1761 /* update cwnd and Early FR */
1762 /******************************/
1763 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1765 #ifdef JANA_CMT_FAST_RECOVERY
1767 * CMT fast recovery code. Need to debug.
1769 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1770 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1771 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1772 net->will_exit_fast_recovery = 1;
1776 /* if nothing was acked on this destination skip it */
1777 if (net->net_ack == 0) {
1778 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1779 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1783 #ifdef JANA_CMT_FAST_RECOVERY
1785 * CMT fast recovery code
1788 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1789 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1790 * } else if (sctp_cmt_on_off == 0 &&
1791 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1795 if (asoc->fast_retran_loss_recovery &&
1797 (asoc->sctp_cmt_on_off == 0)) {
1799 * If we are in loss recovery we skip any cwnd
1805 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1809 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1810 /* If the cumulative ack moved we can proceed */
1811 if (net->cwnd <= net->ssthresh) {
1812 /* We are in slow start */
1813 if (net->flight_size + net->net_ack >= net->cwnd) {
1814 sctp_hs_cwnd_increase(stcb, net);
1816 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1817 sctp_log_cwnd(stcb, net, net->net_ack,
1818 SCTP_CWND_LOG_NOADV_SS);
1822 /* We are in congestion avoidance */
1823 net->partial_bytes_acked += net->net_ack;
1824 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1825 (net->partial_bytes_acked >= net->cwnd)) {
1826 net->partial_bytes_acked -= net->cwnd;
1827 net->cwnd += net->mtu;
1828 sctp_enforce_cwnd_limit(asoc, net);
1829 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1830 sctp_log_cwnd(stcb, net, net->mtu,
1831 SCTP_CWND_LOG_FROM_CA);
1834 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1835 sctp_log_cwnd(stcb, net, net->net_ack,
1836 SCTP_CWND_LOG_NOADV_CA);
1841 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1842 sctp_log_cwnd(stcb, net, net->mtu,
1843 SCTP_CWND_LOG_NO_CUMACK);
1851 * H-TCP congestion control. The algorithm is detailed in:
1852 * R.N.Shorten, D.J.Leith:
1853 * "H-TCP: TCP for high-speed and long-distance networks"
1854 * Proc. PFLDnet, Argonne, 2004.
1855 * http://www.hamilton.ie/net/htcp3.pdf
1859 static int use_rtt_scaling = 1;
1860 static int use_bandwidth_switch = 1;
1863 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1865 return (seq3 - seq2 >= seq1 - seq2);
1868 static inline uint32_t
1869 htcp_cong_time(struct htcp *ca)
1871 return (sctp_get_tick_count() - ca->last_cong);
1874 static inline uint32_t
1875 htcp_ccount(struct htcp *ca)
1877 return (htcp_cong_time(ca) / ca->minRTT);
1881 htcp_reset(struct htcp *ca)
1883 ca->undo_last_cong = ca->last_cong;
1884 ca->undo_maxRTT = ca->maxRTT;
1885 ca->undo_old_maxB = ca->old_maxB;
1886 ca->last_cong = sctp_get_tick_count();
1889 #ifdef SCTP_NOT_USED
1892 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1894 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1895 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1896 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1897 return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu));
1903 measure_rtt(struct sctp_nets *net)
1905 uint32_t srtt = net->lastsa >> SCTP_RTT_SHIFT;
1907 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1908 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1909 net->cc_mod.htcp_ca.minRTT = srtt;
1912 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1913 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
1914 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
1915 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1916 net->cc_mod.htcp_ca.maxRTT = srtt;
1921 measure_achieved_throughput(struct sctp_nets *net)
1923 uint32_t now = sctp_get_tick_count();
1925 if (net->fast_retran_ip == 0)
1926 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
1928 if (!use_bandwidth_switch)
1931 /* achieved throughput calculations */
1932 /* JRS - not 100% sure of this statement */
1933 if (net->fast_retran_ip == 1) {
1934 net->cc_mod.htcp_ca.bytecount = 0;
1935 net->cc_mod.htcp_ca.lasttime = now;
1938 net->cc_mod.htcp_ca.bytecount += net->net_ack;
1939 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)) &&
1940 (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) &&
1941 (net->cc_mod.htcp_ca.minRTT > 0)) {
1942 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount / net->mtu * hz / (now - net->cc_mod.htcp_ca.lasttime);
1944 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
1945 /* just after backoff */
1946 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
1948 net->cc_mod.htcp_ca.Bi = (3 * net->cc_mod.htcp_ca.Bi + cur_Bi) / 4;
1949 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
1950 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
1951 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
1952 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
1954 net->cc_mod.htcp_ca.bytecount = 0;
1955 net->cc_mod.htcp_ca.lasttime = now;
1960 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1962 if (use_bandwidth_switch) {
1963 uint32_t maxB = ca->maxB;
1964 uint32_t old_maxB = ca->old_maxB;
1966 ca->old_maxB = ca->maxB;
1968 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1969 ca->beta = BETA_MIN;
1974 if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) {
1975 ca->beta = (minRTT << 7) / maxRTT;
1976 if (ca->beta < BETA_MIN)
1977 ca->beta = BETA_MIN;
1978 else if (ca->beta > BETA_MAX)
1979 ca->beta = BETA_MAX;
1981 ca->beta = BETA_MIN;
1987 htcp_alpha_update(struct htcp *ca)
1989 uint32_t minRTT = ca->minRTT;
1990 uint32_t factor = 1;
1991 uint32_t diff = htcp_cong_time(ca);
1993 if (diff > (uint32_t)hz) {
1995 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1997 if (use_rtt_scaling && minRTT) {
1998 uint32_t scale = (hz << 3) / (10 * minRTT);
2000 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
2001 * interval [0.5,10]<<3 */
2002 factor = (factor << 3) / scale;
2006 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
2008 ca->alpha = ALPHA_BASE;
2011 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
2012 * rtt before we adjust our beta to ensure we are working from a consistent
2015 * This function should be called when we hit a congestion event since only at
2016 * that point do we really have a real sense of maxRTT (the queues en route
2017 * were getting just too full now).
2020 htcp_param_update(struct sctp_nets *net)
2022 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2023 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2025 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2026 htcp_alpha_update(&net->cc_mod.htcp_ca);
2029 * add slowly fading memory for maxRTT to accommodate routing
2032 if (minRTT > 0 && maxRTT > minRTT)
2033 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
2037 htcp_recalc_ssthresh(struct sctp_nets *net)
2039 htcp_param_update(net);
2040 return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu));
2044 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2047 * How to handle these functions?
2048 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2051 if (net->cwnd <= net->ssthresh) {
2052 /* We are in slow start */
2053 if (net->flight_size + net->net_ack >= net->cwnd) {
2054 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2055 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2056 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2057 sctp_log_cwnd(stcb, net, net->mtu,
2058 SCTP_CWND_LOG_FROM_SS);
2061 net->cwnd += net->net_ack;
2062 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2063 sctp_log_cwnd(stcb, net, net->net_ack,
2064 SCTP_CWND_LOG_FROM_SS);
2067 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2069 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2070 sctp_log_cwnd(stcb, net, net->net_ack,
2071 SCTP_CWND_LOG_NOADV_SS);
2078 * In dangerous area, increase slowly. In theory this is
2079 * net->cwnd += alpha / net->cwnd
2081 /* What is snd_cwnd_cnt?? */
2082 if (((net->partial_bytes_acked / net->mtu * net->cc_mod.htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
2084 * Does SCTP have a cwnd clamp?
2085 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2087 net->cwnd += net->mtu;
2088 net->partial_bytes_acked = 0;
2089 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2090 htcp_alpha_update(&net->cc_mod.htcp_ca);
2091 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2092 sctp_log_cwnd(stcb, net, net->mtu,
2093 SCTP_CWND_LOG_FROM_CA);
2096 net->partial_bytes_acked += net->net_ack;
2097 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2098 sctp_log_cwnd(stcb, net, net->net_ack,
2099 SCTP_CWND_LOG_NOADV_CA);
2103 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2107 #ifdef SCTP_NOT_USED
2108 /* Lower bound on congestion window. */
2110 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2112 return (net->ssthresh);
2117 htcp_init(struct sctp_nets *net)
2119 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2120 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2121 net->cc_mod.htcp_ca.beta = BETA_MIN;
2122 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2123 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2127 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2130 * We take the max of the burst limit times a MTU or the
2131 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2133 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2134 net->ssthresh = stcb->asoc.peers_rwnd;
2135 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2138 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
2139 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2144 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2145 struct sctp_association *asoc,
2146 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2148 struct sctp_nets *net;
2150 /******************************/
2151 /* update cwnd and Early FR */
2152 /******************************/
2153 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2155 #ifdef JANA_CMT_FAST_RECOVERY
2157 * CMT fast recovery code. Need to debug.
2159 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2160 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2161 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
2162 net->will_exit_fast_recovery = 1;
2166 /* if nothing was acked on this destination skip it */
2167 if (net->net_ack == 0) {
2168 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2169 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2173 #ifdef JANA_CMT_FAST_RECOVERY
2175 * CMT fast recovery code
2178 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
2179 * && net->will_exit_fast_recovery == 0) { @@@ Do something
2180 * } else if (sctp_cmt_on_off == 0 &&
2181 * asoc->fast_retran_loss_recovery && will_exit == 0) {
2185 if (asoc->fast_retran_loss_recovery &&
2187 (asoc->sctp_cmt_on_off == 0)) {
2189 * If we are in loss recovery we skip any cwnd
2195 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2199 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2200 htcp_cong_avoid(stcb, net);
2201 measure_achieved_throughput(net);
2203 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2204 sctp_log_cwnd(stcb, net, net->mtu,
2205 SCTP_CWND_LOG_NO_CUMACK);
2212 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2213 struct sctp_association *asoc)
2215 struct sctp_nets *net;
2218 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2219 * (net->fast_retran_loss_recovery == 0)))
2221 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2222 if ((asoc->fast_retran_loss_recovery == 0) ||
2223 (asoc->sctp_cmt_on_off > 0)) {
2224 /* out of a RFC2582 Fast recovery window? */
2225 if (net->net_ack > 0) {
2227 * per section 7.2.3, are there any
2228 * destinations that had a fast retransmit
2229 * to them. If so what we need to do is
2230 * adjust ssthresh and cwnd.
2232 struct sctp_tmit_chunk *lchk;
2233 int old_cwnd = net->cwnd;
2235 /* JRS - reset as if state were changed */
2236 htcp_reset(&net->cc_mod.htcp_ca);
2237 net->ssthresh = htcp_recalc_ssthresh(net);
2238 net->cwnd = net->ssthresh;
2239 sctp_enforce_cwnd_limit(asoc, net);
2240 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2241 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2242 SCTP_CWND_LOG_FROM_FR);
2244 lchk = TAILQ_FIRST(&asoc->send_queue);
2246 net->partial_bytes_acked = 0;
2247 /* Turn on fast recovery window */
2248 asoc->fast_retran_loss_recovery = 1;
2250 /* Mark end of the window */
2251 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2253 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2257 * CMT fast recovery -- per destination
2258 * recovery variable.
2260 net->fast_retran_loss_recovery = 1;
2263 /* Mark end of the window */
2264 net->fast_recovery_tsn = asoc->sending_seq - 1;
2266 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2269 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2270 stcb->sctp_ep, stcb, net,
2271 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_3);
2272 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2273 stcb->sctp_ep, stcb, net);
2275 } else if (net->net_ack > 0) {
2277 * Mark a peg that we WOULD have done a cwnd
2278 * reduction but RFC2582 prevented this action.
2280 SCTP_STAT_INCR(sctps_fastretransinrtt);
2286 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2287 struct sctp_nets *net)
2289 int old_cwnd = net->cwnd;
2291 /* JRS - reset as if the state were being changed to timeout */
2292 htcp_reset(&net->cc_mod.htcp_ca);
2293 net->ssthresh = htcp_recalc_ssthresh(net);
2294 net->cwnd = net->mtu;
2295 net->partial_bytes_acked = 0;
2296 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2297 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2302 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2303 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2307 old_cwnd = net->cwnd;
2309 /* JRS - reset hctp as if state changed */
2310 if (in_window == 0) {
2311 htcp_reset(&net->cc_mod.htcp_ca);
2312 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2313 net->ssthresh = htcp_recalc_ssthresh(net);
2314 if (net->ssthresh < net->mtu) {
2315 net->ssthresh = net->mtu;
2316 /* here back off the timer as well, to slow us down */
2319 net->cwnd = net->ssthresh;
2320 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2321 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2322 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2327 const struct sctp_cc_functions sctp_cc_functions[] = {
2329 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2330 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2331 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2332 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2333 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2334 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2335 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2336 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2339 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2340 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2341 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2342 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2343 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2344 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2345 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2346 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2349 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2350 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2351 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2352 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2353 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2354 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2355 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2356 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2359 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2360 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2361 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2362 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2363 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2364 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2365 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2366 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2367 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2368 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2369 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2370 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2371 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2372 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated