2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
37 #include <netinet/sctp_var.h>
38 #include <netinet/sctp_sysctl.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctputil.h>
42 #include <netinet/sctp_output.h>
43 #include <netinet/sctp_input.h>
44 #include <netinet/sctp_indata.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_timer.h>
47 #include <netinet/sctp_auth.h>
48 #include <netinet/sctp_asconf.h>
49 #include <netinet/sctp_dtrace_declare.h>
51 #define SHIFT_MPTCP_MULTI_N 40
52 #define SHIFT_MPTCP_MULTI_Z 16
53 #define SHIFT_MPTCP_MULTI 8
56 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
58 struct sctp_association *assoc;
62 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
63 if (cwnd_in_mtu == 0) {
64 /* Using 0 means that the value of RFC 4960 is used. */
65 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
68 * We take the minimum of the burst limit and the initial
71 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
72 cwnd_in_mtu = assoc->max_burst;
73 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
75 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
76 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
77 /* In case of resource pooling initialize appropriately */
78 net->cwnd /= assoc->numnets;
79 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
80 net->cwnd = net->mtu - sizeof(struct sctphdr);
83 net->ssthresh = assoc->peers_rwnd;
84 SDT_PROBE(sctp, cwnd, net, init,
85 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
87 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
88 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
89 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
94 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
95 struct sctp_association *asoc)
97 struct sctp_nets *net;
98 uint32_t t_ssthresh, t_cwnd;
101 /* MT FIXME: Don't compute this over and over again */
105 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
106 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
107 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
108 t_ssthresh += net->ssthresh;
110 if (net->lastsa > 0) {
111 t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) net->lastsa;
114 if (t_ucwnd_sbw == 0) {
119 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
120 * (net->fast_retran_loss_recovery == 0)))
122 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
123 if ((asoc->fast_retran_loss_recovery == 0) ||
124 (asoc->sctp_cmt_on_off > 0)) {
125 /* out of a RFC2582 Fast recovery window? */
126 if (net->net_ack > 0) {
128 * per section 7.2.3, are there any
129 * destinations that had a fast retransmit
130 * to them. If so what we need to do is
131 * adjust ssthresh and cwnd.
133 struct sctp_tmit_chunk *lchk;
134 int old_cwnd = net->cwnd;
136 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
137 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
138 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
139 net->ssthresh = (uint32_t) (((uint64_t) 4 *
140 (uint64_t) net->mtu *
141 (uint64_t) net->ssthresh) /
142 (uint64_t) t_ssthresh);
145 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
150 * lastsa>>3; we don't need
157 * Short Version => Equal to
160 net->ssthresh = (uint32_t) (((uint64_t) 4 *
161 (uint64_t) net->mtu *
162 (uint64_t) net->cwnd) /
165 /* INCREASE FACTOR */ ;
167 if ((net->cwnd > t_cwnd / 2) &&
168 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
169 net->ssthresh = net->cwnd - t_cwnd / 2;
171 if (net->ssthresh < net->mtu) {
172 net->ssthresh = net->mtu;
175 net->ssthresh = net->cwnd / 2;
176 if (net->ssthresh < (net->mtu * 2)) {
177 net->ssthresh = 2 * net->mtu;
180 net->cwnd = net->ssthresh;
181 SDT_PROBE(sctp, cwnd, net, fr,
182 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
183 old_cwnd, net->cwnd);
184 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
185 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
186 SCTP_CWND_LOG_FROM_FR);
188 lchk = TAILQ_FIRST(&asoc->send_queue);
190 net->partial_bytes_acked = 0;
191 /* Turn on fast recovery window */
192 asoc->fast_retran_loss_recovery = 1;
194 /* Mark end of the window */
195 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
197 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
201 * CMT fast recovery -- per destination
204 net->fast_retran_loss_recovery = 1;
207 /* Mark end of the window */
208 net->fast_recovery_tsn = asoc->sending_seq - 1;
210 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
213 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
214 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
215 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
216 stcb->sctp_ep, stcb, net);
218 } else if (net->net_ack > 0) {
220 * Mark a peg that we WOULD have done a cwnd
221 * reduction but RFC2582 prevented this action.
223 SCTP_STAT_INCR(sctps_fastretransinrtt);
228 /* Defines for instantaneous bw decisions */
229 #define SCTP_INST_LOOSING 1 /* Loosing to other flows */
230 #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
231 #define SCTP_INST_GAINING 3 /* Gaining, step down possible */
235 cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
236 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
238 uint64_t oth, probepoint;
240 probepoint = (((uint64_t) net->cwnd) << 32);
241 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
243 * rtt increased we don't update bw.. so we don't update the
247 probepoint |= ((5 << 16) | 1);
248 SDT_PROBE(sctp, cwnd, net, rttvar,
250 ((net->cc_mod.rtcc.lbw << 32) | nbw),
251 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
254 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
255 if (net->cc_mod.rtcc.last_step_state == 5)
256 net->cc_mod.rtcc.step_cnt++;
258 net->cc_mod.rtcc.step_cnt = 1;
259 net->cc_mod.rtcc.last_step_state = 5;
260 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
261 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
262 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
263 /* Try a step down */
264 oth = net->cc_mod.rtcc.vol_reduce;
266 oth |= net->cc_mod.rtcc.step_cnt;
268 oth |= net->cc_mod.rtcc.last_step_state;
269 SDT_PROBE(sctp, cwnd, net, rttstep,
271 ((net->cc_mod.rtcc.lbw << 32) | nbw),
272 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
275 if (net->cwnd > (4 * net->mtu)) {
276 net->cwnd -= net->mtu;
277 net->cc_mod.rtcc.vol_reduce++;
279 net->cc_mod.rtcc.step_cnt = 0;
285 if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
287 * rtt decreased, there could be more room. we update both
288 * the bw and the rtt here to lock this in as a good step
292 probepoint |= ((6 << 16) | 0);
293 SDT_PROBE(sctp, cwnd, net, rttvar,
295 ((net->cc_mod.rtcc.lbw << 32) | nbw),
296 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
299 if (net->cc_mod.rtcc.steady_step) {
300 oth = net->cc_mod.rtcc.vol_reduce;
302 oth |= net->cc_mod.rtcc.step_cnt;
304 oth |= net->cc_mod.rtcc.last_step_state;
305 SDT_PROBE(sctp, cwnd, net, rttstep,
307 ((net->cc_mod.rtcc.lbw << 32) | nbw),
308 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
311 if ((net->cc_mod.rtcc.last_step_state == 5) &&
312 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
313 /* Step down worked */
314 net->cc_mod.rtcc.step_cnt = 0;
317 net->cc_mod.rtcc.last_step_state = 6;
318 net->cc_mod.rtcc.step_cnt = 0;
321 net->cc_mod.rtcc.lbw = nbw;
322 net->cc_mod.rtcc.lbw_rtt = net->rtt;
323 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
324 if (inst_ind == SCTP_INST_GAINING)
326 else if (inst_ind == SCTP_INST_NEUTRAL)
332 * Ok bw and rtt remained the same .. no update to any
335 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
336 SDT_PROBE(sctp, cwnd, net, rttvar,
338 ((net->cc_mod.rtcc.lbw << 32) | nbw),
339 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
342 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
343 if (net->cc_mod.rtcc.last_step_state == 5)
344 net->cc_mod.rtcc.step_cnt++;
346 net->cc_mod.rtcc.step_cnt = 1;
347 net->cc_mod.rtcc.last_step_state = 5;
348 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
349 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
350 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
351 /* Try a step down */
352 if (net->cwnd > (4 * net->mtu)) {
353 net->cwnd -= net->mtu;
354 net->cc_mod.rtcc.vol_reduce++;
357 net->cc_mod.rtcc.step_cnt = 0;
361 if (inst_ind == SCTP_INST_GAINING)
363 else if (inst_ind == SCTP_INST_NEUTRAL)
366 return ((int)net->cc_mod.rtcc.ret_from_eq);
370 cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
371 uint64_t vtag, uint8_t inst_ind)
373 uint64_t oth, probepoint;
375 /* Bandwidth decreased. */
376 probepoint = (((uint64_t) net->cwnd) << 32);
377 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
379 /* Did we add more */
380 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
381 (inst_ind != SCTP_INST_LOOSING)) {
382 /* We caused it maybe.. back off? */
384 probepoint |= ((1 << 16) | 1);
385 SDT_PROBE(sctp, cwnd, net, rttvar,
387 ((net->cc_mod.rtcc.lbw << 32) | nbw),
388 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
391 if (net->cc_mod.rtcc.ret_from_eq) {
393 * Switch over to CA if we are less
396 net->ssthresh = net->cwnd - 1;
397 net->partial_bytes_acked = 0;
402 probepoint |= ((2 << 16) | 0);
403 SDT_PROBE(sctp, cwnd, net, rttvar,
405 ((net->cc_mod.rtcc.lbw << 32) | nbw),
406 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
409 /* Someone else - fight for more? */
410 if (net->cc_mod.rtcc.steady_step) {
411 oth = net->cc_mod.rtcc.vol_reduce;
413 oth |= net->cc_mod.rtcc.step_cnt;
415 oth |= net->cc_mod.rtcc.last_step_state;
416 SDT_PROBE(sctp, cwnd, net, rttstep,
418 ((net->cc_mod.rtcc.lbw << 32) | nbw),
419 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
423 * Did we voluntarily give up some? if so take one
426 if ((net->cc_mod.rtcc.vol_reduce) &&
427 (inst_ind != SCTP_INST_GAINING)) {
428 net->cwnd += net->mtu;
429 net->cc_mod.rtcc.vol_reduce--;
431 net->cc_mod.rtcc.last_step_state = 2;
432 net->cc_mod.rtcc.step_cnt = 0;
435 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
436 /* bw & rtt decreased */
438 probepoint |= ((3 << 16) | 0);
439 SDT_PROBE(sctp, cwnd, net, rttvar,
441 ((net->cc_mod.rtcc.lbw << 32) | nbw),
442 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
445 if (net->cc_mod.rtcc.steady_step) {
446 oth = net->cc_mod.rtcc.vol_reduce;
448 oth |= net->cc_mod.rtcc.step_cnt;
450 oth |= net->cc_mod.rtcc.last_step_state;
451 SDT_PROBE(sctp, cwnd, net, rttstep,
453 ((net->cc_mod.rtcc.lbw << 32) | nbw),
454 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
457 if ((net->cc_mod.rtcc.vol_reduce) &&
458 (inst_ind != SCTP_INST_GAINING)) {
459 net->cwnd += net->mtu;
460 net->cc_mod.rtcc.vol_reduce--;
462 net->cc_mod.rtcc.last_step_state = 3;
463 net->cc_mod.rtcc.step_cnt = 0;
467 /* The bw decreased but rtt stayed the same */
469 probepoint |= ((4 << 16) | 0);
470 SDT_PROBE(sctp, cwnd, net, rttvar,
472 ((net->cc_mod.rtcc.lbw << 32) | nbw),
473 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
476 if (net->cc_mod.rtcc.steady_step) {
477 oth = net->cc_mod.rtcc.vol_reduce;
479 oth |= net->cc_mod.rtcc.step_cnt;
481 oth |= net->cc_mod.rtcc.last_step_state;
482 SDT_PROBE(sctp, cwnd, net, rttstep,
484 ((net->cc_mod.rtcc.lbw << 32) | nbw),
485 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
488 if ((net->cc_mod.rtcc.vol_reduce) &&
489 (inst_ind != SCTP_INST_GAINING)) {
490 net->cwnd += net->mtu;
491 net->cc_mod.rtcc.vol_reduce--;
493 net->cc_mod.rtcc.last_step_state = 4;
494 net->cc_mod.rtcc.step_cnt = 0;
497 net->cc_mod.rtcc.lbw = nbw;
498 net->cc_mod.rtcc.lbw_rtt = net->rtt;
499 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
500 if (inst_ind == SCTP_INST_GAINING) {
508 cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
510 uint64_t oth, probepoint;
513 * BW increased, so update and return 0, since all actions in our
514 * table say to do the normal CC update. Note that we pay no
515 * attention to the inst_ind since our overall sum is increasing.
518 probepoint = (((uint64_t) net->cwnd) << 32);
519 SDT_PROBE(sctp, cwnd, net, rttvar,
521 ((net->cc_mod.rtcc.lbw << 32) | nbw),
522 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
525 if (net->cc_mod.rtcc.steady_step) {
526 oth = net->cc_mod.rtcc.vol_reduce;
528 oth |= net->cc_mod.rtcc.step_cnt;
530 oth |= net->cc_mod.rtcc.last_step_state;
531 SDT_PROBE(sctp, cwnd, net, rttstep,
533 ((net->cc_mod.rtcc.lbw << 32) | nbw),
534 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
537 net->cc_mod.rtcc.last_step_state = 0;
538 net->cc_mod.rtcc.step_cnt = 0;
539 net->cc_mod.rtcc.vol_reduce = 0;
541 net->cc_mod.rtcc.lbw = nbw;
542 net->cc_mod.rtcc.lbw_rtt = net->rtt;
543 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
547 /* RTCC Algoritm to limit growth of cwnd, return
548 * true if you want to NOT allow cwnd growth
551 cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
553 uint64_t bw_offset, rtt_offset;
554 uint64_t probepoint, rtt, vtag;
555 uint64_t bytes_for_this_rtt, inst_bw;
556 uint64_t div, inst_off;
562 * Here we need to see if we want
563 * to limit cwnd growth due to increase
564 * in overall rtt but no increase in bw.
565 * We use the following table to figure
566 * out what we should do. When we return
567 * 0, cc update goes on as planned. If we
568 * return 1, then no cc update happens and cwnd
569 * stays where it is at.
570 * ----------------------------------
572 * *********************************
573 * INC | INC | return 0
574 * ----------------------------------
575 * INC | SAME | return 0
576 * ----------------------------------
577 * INC | DECR | return 0
578 * ----------------------------------
579 * SAME | INC | return 1
580 * ----------------------------------
581 * SAME | SAME | return 1
582 * ----------------------------------
583 * SAME | DECR | return 0
584 * ----------------------------------
585 * DECR | INC | return 0 or 1 based on if we caused.
586 * ----------------------------------
587 * DECR | SAME | return 0
588 * ----------------------------------
589 * DECR | DECR | return 0
590 * ----------------------------------
592 * We are a bit fuzz on what an increase or
593 * decrease is. For BW it is the same if
594 * it did not change within 1/64th. For
595 * RTT it stayed the same if it did not
596 * change within 1/32nd
598 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
599 rtt = stcb->asoc.my_vtag;
600 vtag = (rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
601 probepoint = (((uint64_t) net->cwnd) << 32);
603 if (net->cc_mod.rtcc.rtt_set_this_sack) {
604 net->cc_mod.rtcc.rtt_set_this_sack = 0;
605 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
606 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
608 div = net->rtt / 1000;
610 inst_bw = bytes_for_this_rtt / div;
611 inst_off = inst_bw >> bw_shift;
613 inst_ind = SCTP_INST_GAINING;
614 else if ((inst_bw + inst_off) < nbw)
615 inst_ind = SCTP_INST_LOOSING;
617 inst_ind = SCTP_INST_NEUTRAL;
618 probepoint |= ((0xb << 16) | inst_ind);
620 inst_ind = net->cc_mod.rtcc.last_inst_ind;
621 inst_bw = bytes_for_this_rtt / (uint64_t) (net->rtt);
622 /* Can't determine do not change */
623 probepoint |= ((0xc << 16) | inst_ind);
626 inst_ind = net->cc_mod.rtcc.last_inst_ind;
627 inst_bw = bytes_for_this_rtt;
628 /* Can't determine do not change */
629 probepoint |= ((0xd << 16) | inst_ind);
631 SDT_PROBE(sctp, cwnd, net, rttvar,
633 ((nbw << 32) | inst_bw),
634 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
638 /* No rtt measurement, use last one */
639 inst_ind = net->cc_mod.rtcc.last_inst_ind;
641 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
642 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
643 ret = cc_bw_increase(stcb, net, nbw, vtag);
646 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
647 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
648 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
652 * If we reach here then we are in a situation where the bw stayed
655 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
657 net->cc_mod.rtcc.last_inst_ind = inst_ind;
662 sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
663 struct sctp_association *asoc,
664 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
666 struct sctp_nets *net;
668 uint32_t t_ssthresh, t_cwnd, incr;
669 uint64_t t_ucwnd_sbw;
670 uint64_t t_path_mptcp;
671 uint64_t mptcp_like_alpha;
675 /* MT FIXME: Don't compute this over and over again */
680 mptcp_like_alpha = 1;
681 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
682 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
683 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
685 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
686 t_ssthresh += net->ssthresh;
688 /* lastsa>>3; we don't need to devide ... */
693 t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) srtt;
694 t_path_mptcp += (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_Z) /
695 (((uint64_t) net->mtu) * (uint64_t) srtt);
696 tmp = (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_N) /
697 ((uint64_t) net->mtu * (uint64_t) (srtt * srtt));
698 if (tmp > max_path) {
703 if (t_path_mptcp > 0) {
704 mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp);
706 mptcp_like_alpha = 1;
709 if (t_ssthresh == 0) {
712 if (t_ucwnd_sbw == 0) {
715 /******************************/
716 /* update cwnd and Early FR */
717 /******************************/
718 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
720 #ifdef JANA_CMT_FAST_RECOVERY
722 * CMT fast recovery code. Need to debug.
724 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
725 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
726 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
727 net->will_exit_fast_recovery = 1;
731 /* if nothing was acked on this destination skip it */
732 if (net->net_ack == 0) {
733 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
734 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
738 #ifdef JANA_CMT_FAST_RECOVERY
740 * CMT fast recovery code
743 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
744 * && net->will_exit_fast_recovery == 0) { @@@ Do something
745 * } else if (sctp_cmt_on_off == 0 &&
746 * asoc->fast_retran_loss_recovery && will_exit == 0) {
750 if (asoc->fast_retran_loss_recovery &&
752 (asoc->sctp_cmt_on_off == 0)) {
754 * If we are in loss recovery we skip any cwnd
760 * Did any measurements go on for this network?
762 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
766 * At this point our bw_bytes has been updated by
767 * incoming sack information.
769 * But our bw may not yet be set.
772 if ((net->cc_mod.rtcc.new_tot_time / 1000) > 0) {
773 nbw = net->cc_mod.rtcc.bw_bytes / (net->cc_mod.rtcc.new_tot_time / 1000);
775 nbw = net->cc_mod.rtcc.bw_bytes;
777 if (net->cc_mod.rtcc.lbw) {
778 if (cc_bw_limit(stcb, net, nbw)) {
779 /* Hold here, no update */
783 uint64_t vtag, probepoint;
785 probepoint = (((uint64_t) net->cwnd) << 32);
786 probepoint |= ((0xa << 16) | 0);
787 vtag = (net->rtt << 32) |
788 (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
791 SDT_PROBE(sctp, cwnd, net, rttvar,
794 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
797 net->cc_mod.rtcc.lbw = nbw;
798 net->cc_mod.rtcc.lbw_rtt = net->rtt;
799 if (net->cc_mod.rtcc.rtt_set_this_sack) {
800 net->cc_mod.rtcc.rtt_set_this_sack = 0;
801 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
806 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
810 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
811 /* If the cumulative ack moved we can proceed */
812 if (net->cwnd <= net->ssthresh) {
813 /* We are in slow start */
814 if (net->flight_size + net->net_ack >= net->cwnd) {
817 old_cwnd = net->cwnd;
818 switch (asoc->sctp_cmt_on_off) {
820 limit = (uint32_t) (((uint64_t) net->mtu *
821 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
822 (uint64_t) net->ssthresh) /
823 (uint64_t) t_ssthresh);
824 incr = (uint32_t) (((uint64_t) net->net_ack *
825 (uint64_t) net->ssthresh) /
826 (uint64_t) t_ssthresh);
836 * lastsa>>3; we don't need
843 limit = (uint32_t) (((uint64_t) net->mtu *
844 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
845 (uint64_t) net->cwnd) /
846 ((uint64_t) srtt * t_ucwnd_sbw));
847 /* INCREASE FACTOR */
848 incr = (uint32_t) (((uint64_t) net->net_ack *
849 (uint64_t) net->cwnd) /
850 ((uint64_t) srtt * t_ucwnd_sbw));
851 /* INCREASE FACTOR */
860 limit = (uint32_t) (((uint64_t) net->mtu *
862 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
864 incr = (uint32_t) (((uint64_t) net->net_ack *
870 if (incr > net->net_ack) {
873 if (incr > net->mtu) {
879 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
880 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
885 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
886 sctp_log_cwnd(stcb, net, incr,
887 SCTP_CWND_LOG_FROM_SS);
889 SDT_PROBE(sctp, cwnd, net, ack,
891 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
893 old_cwnd, net->cwnd);
895 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
896 sctp_log_cwnd(stcb, net, net->net_ack,
897 SCTP_CWND_LOG_NOADV_SS);
901 /* We are in congestion avoidance */
905 net->partial_bytes_acked += net->net_ack;
907 if ((net->flight_size + net->net_ack >= net->cwnd) &&
908 (net->partial_bytes_acked >= net->cwnd)) {
909 net->partial_bytes_acked -= net->cwnd;
910 old_cwnd = net->cwnd;
911 switch (asoc->sctp_cmt_on_off) {
913 incr = (uint32_t) (((uint64_t) net->mtu *
914 (uint64_t) net->ssthresh) /
915 (uint64_t) t_ssthresh);
922 * lastsa>>3; we don't need
929 incr = (uint32_t) ((uint64_t) net->mtu *
930 (uint64_t) net->cwnd /
933 /* INCREASE FACTOR */
939 incr = (uint32_t) ((mptcp_like_alpha *
940 (uint64_t) net->cwnd) >>
942 if (incr > net->mtu) {
951 SDT_PROBE(sctp, cwnd, net, ack,
953 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
955 old_cwnd, net->cwnd);
956 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
957 sctp_log_cwnd(stcb, net, net->mtu,
958 SCTP_CWND_LOG_FROM_CA);
961 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
962 sctp_log_cwnd(stcb, net, net->net_ack,
963 SCTP_CWND_LOG_NOADV_CA);
968 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
969 sctp_log_cwnd(stcb, net, net->mtu,
970 SCTP_CWND_LOG_NO_CUMACK);
977 sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
981 old_cwnd = net->cwnd;
982 net->cwnd = net->mtu;
983 SDT_PROBE(sctp, cwnd, net, ack,
984 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
985 old_cwnd, net->cwnd);
986 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
992 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
994 int old_cwnd = net->cwnd;
995 uint32_t t_ssthresh, t_cwnd;
996 uint64_t t_ucwnd_sbw;
998 /* MT FIXME: Don't compute this over and over again */
1001 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1002 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1003 struct sctp_nets *lnet;
1007 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1008 t_ssthresh += lnet->ssthresh;
1009 t_cwnd += lnet->cwnd;
1010 srtt = lnet->lastsa;
1011 /* lastsa>>3; we don't need to divide ... */
1013 t_ucwnd_sbw += (uint64_t) lnet->cwnd / (uint64_t) srtt;
1016 if (t_ssthresh < 1) {
1019 if (t_ucwnd_sbw < 1) {
1022 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1023 net->ssthresh = (uint32_t) (((uint64_t) 4 *
1024 (uint64_t) net->mtu *
1025 (uint64_t) net->ssthresh) /
1026 (uint64_t) t_ssthresh);
1031 /* lastsa>>3; we don't need to divide ... */
1035 cc_delta = t_ucwnd_sbw * (uint64_t) srtt / 2;
1036 if (cc_delta < t_cwnd) {
1037 net->ssthresh = (uint32_t) ((uint64_t) t_cwnd - cc_delta);
1039 net->ssthresh = net->mtu;
1042 if ((net->cwnd > t_cwnd / 2) &&
1043 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1044 net->ssthresh = net->cwnd - t_cwnd / 2;
1046 if (net->ssthresh < net->mtu) {
1047 net->ssthresh = net->mtu;
1050 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1052 net->cwnd = net->mtu;
1053 net->partial_bytes_acked = 0;
1054 SDT_PROBE(sctp, cwnd, net, to,
1056 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1058 old_cwnd, net->cwnd);
1059 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1060 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1065 sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1066 int in_window, int num_pkt_lost, int use_rtcc)
1068 int old_cwnd = net->cwnd;
1070 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1071 /* Data center Congestion Control */
1072 if (in_window == 0) {
1074 * Go to CA with the cwnd at the point we sent the
1075 * TSN that was marked with a CE.
1077 if (net->ecn_prev_cwnd < net->cwnd) {
1078 /* Restore to prev cwnd */
1079 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1081 /* Just cut in 1/2 */
1085 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1086 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1087 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1091 * Further tuning down required over the drastic
1094 net->ssthresh -= (net->mtu * num_pkt_lost);
1095 net->cwnd -= (net->mtu * num_pkt_lost);
1096 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1097 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1100 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1102 if (in_window == 0) {
1103 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1104 net->ssthresh = net->cwnd / 2;
1105 if (net->ssthresh < net->mtu) {
1106 net->ssthresh = net->mtu;
1108 * here back off the timer as well, to slow
1113 net->cwnd = net->ssthresh;
1114 SDT_PROBE(sctp, cwnd, net, ecn,
1116 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1118 old_cwnd, net->cwnd);
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);
1128 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1129 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1130 uint32_t * bottle_bw, uint32_t * on_queue)
1135 int old_cwnd = net->cwnd;
1137 /* need real RTT in msd for this calc */
1138 rtt = net->rtt / 1000;
1139 /* get bottle neck bw */
1140 *bottle_bw = ntohl(cp->bottle_bw);
1141 /* and whats on queue */
1142 *on_queue = ntohl(cp->current_onq);
1144 * adjust the on-queue if our flight is more it could be that the
1145 * router has not yet gotten data "in-flight" to it
1147 if (*on_queue < net->flight_size)
1148 *on_queue = net->flight_size;
1149 /* calculate the available space */
1150 bw_avail = (*bottle_bw * rtt) / 1000;
1151 if (bw_avail > *bottle_bw) {
1153 * Cap the growth to no more than the bottle neck. This can
1154 * happen as RTT slides up due to queues. It also means if
1155 * you have more than a 1 second RTT with a empty queue you
1156 * will be limited to the bottle_bw per second no matter if
1157 * other points have 1/2 the RTT and you could get more
1160 bw_avail = *bottle_bw;
1162 if (*on_queue > bw_avail) {
1164 * No room for anything else don't allow anything else to be
1165 * "added to the fire".
1167 int seg_inflight, seg_onqueue, my_portion;
1169 net->partial_bytes_acked = 0;
1171 /* how much are we over queue size? */
1172 incr = *on_queue - bw_avail;
1173 if (stcb->asoc.seen_a_sack_this_pkt) {
1175 * undo any cwnd adjustment that the sack might have
1178 net->cwnd = net->prev_cwnd;
1180 /* Now how much of that is mine? */
1181 seg_inflight = net->flight_size / net->mtu;
1182 seg_onqueue = *on_queue / net->mtu;
1183 my_portion = (incr * seg_inflight) / seg_onqueue;
1185 /* Have I made an adjustment already */
1186 if (net->cwnd > net->flight_size) {
1188 * for this flight I made an adjustment we need to
1189 * decrease the portion by a share our previous
1194 diff_adj = net->cwnd - net->flight_size;
1195 if (diff_adj > my_portion)
1198 my_portion -= diff_adj;
1201 * back down to the previous cwnd (assume we have had a sack
1202 * before this packet). minus what ever portion of the
1203 * overage is my fault.
1205 net->cwnd -= my_portion;
1207 /* we will NOT back down more than 1 MTU */
1208 if (net->cwnd <= net->mtu) {
1209 net->cwnd = net->mtu;
1212 net->ssthresh = net->cwnd - 1;
1215 * Take 1/4 of the space left or max burst up .. whichever
1218 incr = (bw_avail - *on_queue) >> 2;
1219 if ((stcb->asoc.max_burst > 0) &&
1220 (stcb->asoc.max_burst * net->mtu < incr)) {
1221 incr = stcb->asoc.max_burst * net->mtu;
1225 if (net->cwnd > bw_avail) {
1226 /* We can't exceed the pipe size */
1227 net->cwnd = bw_avail;
1229 if (net->cwnd < net->mtu) {
1230 /* We always have 1 MTU */
1231 net->cwnd = net->mtu;
1233 if (net->cwnd - old_cwnd != 0) {
1234 /* log only changes */
1235 SDT_PROBE(sctp, cwnd, net, pd,
1237 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1239 old_cwnd, net->cwnd);
1240 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1241 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1242 SCTP_CWND_LOG_FROM_SAT);
1248 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1249 struct sctp_nets *net, int burst_limit)
1251 int old_cwnd = net->cwnd;
1253 if (net->ssthresh < net->cwnd)
1254 net->ssthresh = net->cwnd;
1256 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1257 SDT_PROBE(sctp, cwnd, net, bl,
1259 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1261 old_cwnd, net->cwnd);
1262 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1263 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1269 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1270 struct sctp_association *asoc,
1271 int accum_moved, int reneged_all, int will_exit)
1273 /* Passing a zero argument in last disables the rtcc algoritm */
1274 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1278 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1279 int in_window, int num_pkt_lost)
1281 /* Passing a zero argument in last disables the rtcc algoritm */
1282 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1285 /* Here starts the RTCCVAR type CC invented by RRS which
1286 * is a slight mod to RFC2581. We reuse a common routine or
1287 * two since these algoritms are so close and need to
1291 sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1292 int in_window, int num_pkt_lost)
1294 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1300 sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1301 struct sctp_tmit_chunk *tp1)
1303 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1307 sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1308 struct sctp_nets *net)
1310 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1311 /* We had a bw measurment going on */
1312 struct timeval ltls;
1314 SCTP_GETPTIME_TIMEVAL(<ls);
1315 timevalsub(<ls, &net->cc_mod.rtcc.tls);
1316 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1321 sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1322 struct sctp_nets *net)
1324 uint64_t vtag, probepoint;
1326 if (net->cc_mod.rtcc.lbw) {
1327 /* Clear the old bw.. we went to 0 in-flight */
1328 vtag = (net->rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
1330 probepoint = (((uint64_t) net->cwnd) << 32);
1332 probepoint |= ((8 << 16) | 0);
1333 SDT_PROBE(sctp, cwnd, net, rttvar,
1335 ((net->cc_mod.rtcc.lbw << 32) | 0),
1336 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1339 net->cc_mod.rtcc.lbw_rtt = 0;
1340 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1341 net->cc_mod.rtcc.lbw = 0;
1342 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1343 net->cc_mod.rtcc.vol_reduce = 0;
1344 net->cc_mod.rtcc.bw_tot_time = 0;
1345 net->cc_mod.rtcc.bw_bytes = 0;
1346 net->cc_mod.rtcc.tls_needs_set = 0;
1347 if (net->cc_mod.rtcc.steady_step) {
1348 net->cc_mod.rtcc.vol_reduce = 0;
1349 net->cc_mod.rtcc.step_cnt = 0;
1350 net->cc_mod.rtcc.last_step_state = 0;
1352 if (net->cc_mod.rtcc.ret_from_eq) {
1353 /* less aggressive one - reset cwnd too */
1354 uint32_t cwnd_in_mtu, cwnd;
1356 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1357 if (cwnd_in_mtu == 0) {
1359 * Using 0 means that the value of RFC 4960
1362 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1365 * We take the minimum of the burst limit
1366 * and the initial congestion window.
1368 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1369 cwnd_in_mtu = stcb->asoc.max_burst;
1370 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1372 if (net->cwnd > cwnd) {
1374 * Only set if we are not a timeout (i.e.
1384 sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1385 struct sctp_nets *net)
1387 uint64_t vtag, probepoint;
1389 sctp_set_initial_cc_param(stcb, net);
1390 stcb->asoc.use_precise_time = 1;
1391 probepoint = (((uint64_t) net->cwnd) << 32);
1392 probepoint |= ((9 << 16) | 0);
1393 vtag = (net->rtt << 32) |
1394 (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
1396 SDT_PROBE(sctp, cwnd, net, rttvar,
1402 net->cc_mod.rtcc.lbw_rtt = 0;
1403 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1404 net->cc_mod.rtcc.vol_reduce = 0;
1405 net->cc_mod.rtcc.lbw = 0;
1406 net->cc_mod.rtcc.vol_reduce = 0;
1407 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1408 net->cc_mod.rtcc.bw_tot_time = 0;
1409 net->cc_mod.rtcc.bw_bytes = 0;
1410 net->cc_mod.rtcc.tls_needs_set = 0;
1411 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1412 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1413 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1414 net->cc_mod.rtcc.step_cnt = 0;
1415 net->cc_mod.rtcc.last_step_state = 0;
1421 sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1422 struct sctp_cc_option *cc_opt)
1424 struct sctp_nets *net;
1426 if (setorget == 1) {
1428 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1429 if ((cc_opt->aid_value.assoc_value != 0) &&
1430 (cc_opt->aid_value.assoc_value != 1)) {
1433 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1434 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1436 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1437 if ((cc_opt->aid_value.assoc_value != 0) &&
1438 (cc_opt->aid_value.assoc_value != 1)) {
1441 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1442 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1444 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1445 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1446 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1453 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1454 net = TAILQ_FIRST(&stcb->asoc.nets);
1458 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1459 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1460 net = TAILQ_FIRST(&stcb->asoc.nets);
1464 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1465 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1466 net = TAILQ_FIRST(&stcb->asoc.nets);
1470 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1479 sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1480 struct sctp_nets *net)
1482 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1483 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1484 net->cc_mod.rtcc.tls_needs_set = 2;
1489 sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1490 struct sctp_association *asoc,
1491 int accum_moved, int reneged_all, int will_exit)
1493 /* Passing a one argument at the last enables the rtcc algoritm */
1494 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1498 sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1499 struct sctp_nets *net,
1500 struct timeval *now SCTP_UNUSED)
1502 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1505 /* Here starts Sally Floyds HS-TCP */
1507 struct sctp_hs_raise_drop {
1510 int32_t drop_percent;
1513 #define SCTP_HS_TABLE_SIZE 73
1515 struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1516 {38, 1, 50}, /* 0 */
1517 {118, 2, 44}, /* 1 */
1518 {221, 3, 41}, /* 2 */
1519 {347, 4, 38}, /* 3 */
1520 {495, 5, 37}, /* 4 */
1521 {663, 6, 35}, /* 5 */
1522 {851, 7, 34}, /* 6 */
1523 {1058, 8, 33}, /* 7 */
1524 {1284, 9, 32}, /* 8 */
1525 {1529, 10, 31}, /* 9 */
1526 {1793, 11, 30}, /* 10 */
1527 {2076, 12, 29}, /* 11 */
1528 {2378, 13, 28}, /* 12 */
1529 {2699, 14, 28}, /* 13 */
1530 {3039, 15, 27}, /* 14 */
1531 {3399, 16, 27}, /* 15 */
1532 {3778, 17, 26}, /* 16 */
1533 {4177, 18, 26}, /* 17 */
1534 {4596, 19, 25}, /* 18 */
1535 {5036, 20, 25}, /* 19 */
1536 {5497, 21, 24}, /* 20 */
1537 {5979, 22, 24}, /* 21 */
1538 {6483, 23, 23}, /* 22 */
1539 {7009, 24, 23}, /* 23 */
1540 {7558, 25, 22}, /* 24 */
1541 {8130, 26, 22}, /* 25 */
1542 {8726, 27, 22}, /* 26 */
1543 {9346, 28, 21}, /* 27 */
1544 {9991, 29, 21}, /* 28 */
1545 {10661, 30, 21}, /* 29 */
1546 {11358, 31, 20}, /* 30 */
1547 {12082, 32, 20}, /* 31 */
1548 {12834, 33, 20}, /* 32 */
1549 {13614, 34, 19}, /* 33 */
1550 {14424, 35, 19}, /* 34 */
1551 {15265, 36, 19}, /* 35 */
1552 {16137, 37, 19}, /* 36 */
1553 {17042, 38, 18}, /* 37 */
1554 {17981, 39, 18}, /* 38 */
1555 {18955, 40, 18}, /* 39 */
1556 {19965, 41, 17}, /* 40 */
1557 {21013, 42, 17}, /* 41 */
1558 {22101, 43, 17}, /* 42 */
1559 {23230, 44, 17}, /* 43 */
1560 {24402, 45, 16}, /* 44 */
1561 {25618, 46, 16}, /* 45 */
1562 {26881, 47, 16}, /* 46 */
1563 {28193, 48, 16}, /* 47 */
1564 {29557, 49, 15}, /* 48 */
1565 {30975, 50, 15}, /* 49 */
1566 {32450, 51, 15}, /* 50 */
1567 {33986, 52, 15}, /* 51 */
1568 {35586, 53, 14}, /* 52 */
1569 {37253, 54, 14}, /* 53 */
1570 {38992, 55, 14}, /* 54 */
1571 {40808, 56, 14}, /* 55 */
1572 {42707, 57, 13}, /* 56 */
1573 {44694, 58, 13}, /* 57 */
1574 {46776, 59, 13}, /* 58 */
1575 {48961, 60, 13}, /* 59 */
1576 {51258, 61, 13}, /* 60 */
1577 {53677, 62, 12}, /* 61 */
1578 {56230, 63, 12}, /* 62 */
1579 {58932, 64, 12}, /* 63 */
1580 {61799, 65, 12}, /* 64 */
1581 {64851, 66, 11}, /* 65 */
1582 {68113, 67, 11}, /* 66 */
1583 {71617, 68, 11}, /* 67 */
1584 {75401, 69, 10}, /* 68 */
1585 {79517, 70, 10}, /* 69 */
1586 {84035, 71, 10}, /* 70 */
1587 {89053, 72, 10}, /* 71 */
1588 {94717, 73, 9} /* 72 */
1592 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1594 int cur_val, i, indx, incr;
1596 cur_val = net->cwnd >> 10;
1597 indx = SCTP_HS_TABLE_SIZE - 1;
1599 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1601 if (net->net_ack > net->mtu) {
1602 net->cwnd += net->mtu;
1603 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1604 sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS);
1607 net->cwnd += net->net_ack;
1608 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1609 sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
1613 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1614 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1619 net->last_hs_used = indx;
1620 incr = ((sctp_cwnd_adjust[indx].increase) << 10);
1622 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1623 sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS);
1629 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1631 int cur_val, i, indx;
1632 int old_cwnd = net->cwnd;
1634 cur_val = net->cwnd >> 10;
1635 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1637 net->ssthresh = net->cwnd / 2;
1638 if (net->ssthresh < (net->mtu * 2)) {
1639 net->ssthresh = 2 * net->mtu;
1641 net->cwnd = net->ssthresh;
1643 /* drop by the proper amount */
1644 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1645 sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1646 net->cwnd = net->ssthresh;
1647 /* now where are we */
1648 indx = net->last_hs_used;
1649 cur_val = net->cwnd >> 10;
1650 /* reset where we are in the table */
1651 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1652 /* feel out of hs */
1653 net->last_hs_used = 0;
1655 for (i = indx; i >= 1; i--) {
1656 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1660 net->last_hs_used = indx;
1663 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1664 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1669 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1670 struct sctp_association *asoc)
1672 struct sctp_nets *net;
1675 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1676 * (net->fast_retran_loss_recovery == 0)))
1678 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1679 if ((asoc->fast_retran_loss_recovery == 0) ||
1680 (asoc->sctp_cmt_on_off > 0)) {
1681 /* out of a RFC2582 Fast recovery window? */
1682 if (net->net_ack > 0) {
1684 * per section 7.2.3, are there any
1685 * destinations that had a fast retransmit
1686 * to them. If so what we need to do is
1687 * adjust ssthresh and cwnd.
1689 struct sctp_tmit_chunk *lchk;
1691 sctp_hs_cwnd_decrease(stcb, net);
1693 lchk = TAILQ_FIRST(&asoc->send_queue);
1695 net->partial_bytes_acked = 0;
1696 /* Turn on fast recovery window */
1697 asoc->fast_retran_loss_recovery = 1;
1699 /* Mark end of the window */
1700 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1702 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1706 * CMT fast recovery -- per destination
1707 * recovery variable.
1709 net->fast_retran_loss_recovery = 1;
1712 /* Mark end of the window */
1713 net->fast_recovery_tsn = asoc->sending_seq - 1;
1715 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1718 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1719 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
1720 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1721 stcb->sctp_ep, stcb, net);
1723 } else if (net->net_ack > 0) {
1725 * Mark a peg that we WOULD have done a cwnd
1726 * reduction but RFC2582 prevented this action.
1728 SCTP_STAT_INCR(sctps_fastretransinrtt);
1734 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1735 struct sctp_association *asoc,
1736 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1738 struct sctp_nets *net;
1740 /******************************/
1741 /* update cwnd and Early FR */
1742 /******************************/
1743 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1745 #ifdef JANA_CMT_FAST_RECOVERY
1747 * CMT fast recovery code. Need to debug.
1749 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1750 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1751 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1752 net->will_exit_fast_recovery = 1;
1756 /* if nothing was acked on this destination skip it */
1757 if (net->net_ack == 0) {
1758 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1759 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1763 #ifdef JANA_CMT_FAST_RECOVERY
1765 * CMT fast recovery code
1768 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1769 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1770 * } else if (sctp_cmt_on_off == 0 &&
1771 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1775 if (asoc->fast_retran_loss_recovery &&
1777 (asoc->sctp_cmt_on_off == 0)) {
1779 * If we are in loss recovery we skip any cwnd
1785 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1789 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1790 /* If the cumulative ack moved we can proceed */
1791 if (net->cwnd <= net->ssthresh) {
1792 /* We are in slow start */
1793 if (net->flight_size + net->net_ack >= net->cwnd) {
1795 sctp_hs_cwnd_increase(stcb, net);
1798 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1799 sctp_log_cwnd(stcb, net, net->net_ack,
1800 SCTP_CWND_LOG_NOADV_SS);
1804 /* We are in congestion avoidance */
1805 net->partial_bytes_acked += net->net_ack;
1806 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1807 (net->partial_bytes_acked >= net->cwnd)) {
1808 net->partial_bytes_acked -= net->cwnd;
1809 net->cwnd += net->mtu;
1810 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1811 sctp_log_cwnd(stcb, net, net->mtu,
1812 SCTP_CWND_LOG_FROM_CA);
1815 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1816 sctp_log_cwnd(stcb, net, net->net_ack,
1817 SCTP_CWND_LOG_NOADV_CA);
1822 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1823 sctp_log_cwnd(stcb, net, net->mtu,
1824 SCTP_CWND_LOG_NO_CUMACK);
1832 * H-TCP congestion control. The algorithm is detailed in:
1833 * R.N.Shorten, D.J.Leith:
1834 * "H-TCP: TCP for high-speed and long-distance networks"
1835 * Proc. PFLDnet, Argonne, 2004.
1836 * http://www.hamilton.ie/net/htcp3.pdf
1840 static int use_rtt_scaling = 1;
1841 static int use_bandwidth_switch = 1;
1844 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1846 return (seq3 - seq2 >= seq1 - seq2);
1849 static inline uint32_t
1850 htcp_cong_time(struct htcp *ca)
1852 return (sctp_get_tick_count() - ca->last_cong);
1855 static inline uint32_t
1856 htcp_ccount(struct htcp *ca)
1858 return (htcp_cong_time(ca) / ca->minRTT);
1862 htcp_reset(struct htcp *ca)
1864 ca->undo_last_cong = ca->last_cong;
1865 ca->undo_maxRTT = ca->maxRTT;
1866 ca->undo_old_maxB = ca->old_maxB;
1867 ca->last_cong = sctp_get_tick_count();
1870 #ifdef SCTP_NOT_USED
1873 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1875 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1876 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1877 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1878 return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu));
1884 measure_rtt(struct sctp_nets *net)
1886 uint32_t srtt = net->lastsa >> SCTP_RTT_SHIFT;
1888 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1889 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1890 net->cc_mod.htcp_ca.minRTT = srtt;
1893 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1894 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
1895 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
1896 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1897 net->cc_mod.htcp_ca.maxRTT = srtt;
1902 measure_achieved_throughput(struct sctp_nets *net)
1904 uint32_t now = sctp_get_tick_count();
1906 if (net->fast_retran_ip == 0)
1907 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
1909 if (!use_bandwidth_switch)
1912 /* achieved throughput calculations */
1913 /* JRS - not 100% sure of this statement */
1914 if (net->fast_retran_ip == 1) {
1915 net->cc_mod.htcp_ca.bytecount = 0;
1916 net->cc_mod.htcp_ca.lasttime = now;
1919 net->cc_mod.htcp_ca.bytecount += net->net_ack;
1921 if (net->cc_mod.htcp_ca.bytecount >= net->cwnd - ((net->cc_mod.htcp_ca.alpha >> 7 ? : 1) * net->mtu)
1922 && now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT
1923 && net->cc_mod.htcp_ca.minRTT > 0) {
1924 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount / net->mtu * hz / (now - net->cc_mod.htcp_ca.lasttime);
1926 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
1927 /* just after backoff */
1928 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
1930 net->cc_mod.htcp_ca.Bi = (3 * net->cc_mod.htcp_ca.Bi + cur_Bi) / 4;
1931 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
1932 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
1933 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
1934 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
1936 net->cc_mod.htcp_ca.bytecount = 0;
1937 net->cc_mod.htcp_ca.lasttime = now;
1942 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1944 if (use_bandwidth_switch) {
1945 uint32_t maxB = ca->maxB;
1946 uint32_t old_maxB = ca->old_maxB;
1948 ca->old_maxB = ca->maxB;
1950 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1951 ca->beta = BETA_MIN;
1956 if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) {
1957 ca->beta = (minRTT << 7) / maxRTT;
1958 if (ca->beta < BETA_MIN)
1959 ca->beta = BETA_MIN;
1960 else if (ca->beta > BETA_MAX)
1961 ca->beta = BETA_MAX;
1963 ca->beta = BETA_MIN;
1969 htcp_alpha_update(struct htcp *ca)
1971 uint32_t minRTT = ca->minRTT;
1972 uint32_t factor = 1;
1973 uint32_t diff = htcp_cong_time(ca);
1975 if (diff > (uint32_t) hz) {
1977 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1979 if (use_rtt_scaling && minRTT) {
1980 uint32_t scale = (hz << 3) / (10 * minRTT);
1982 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1983 * interval [0.5,10]<<3 */
1984 factor = (factor << 3) / scale;
1988 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
1990 ca->alpha = ALPHA_BASE;
1993 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
1994 * rtt before we adjust our beta to ensure we are working from a consistent
1997 * This function should be called when we hit a congestion event since only at
1998 * that point do we really have a real sense of maxRTT (the queues en route
1999 * were getting just too full now).
2002 htcp_param_update(struct sctp_nets *net)
2004 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2005 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2007 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2008 htcp_alpha_update(&net->cc_mod.htcp_ca);
2011 * add slowly fading memory for maxRTT to accommodate routing
2014 if (minRTT > 0 && maxRTT > minRTT)
2015 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
2019 htcp_recalc_ssthresh(struct sctp_nets *net)
2021 htcp_param_update(net);
2022 return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu));
2026 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2029 * How to handle these functions?
2030 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2033 if (net->cwnd <= net->ssthresh) {
2034 /* We are in slow start */
2035 if (net->flight_size + net->net_ack >= net->cwnd) {
2036 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2037 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2038 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2039 sctp_log_cwnd(stcb, net, net->mtu,
2040 SCTP_CWND_LOG_FROM_SS);
2043 net->cwnd += net->net_ack;
2044 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2045 sctp_log_cwnd(stcb, net, net->net_ack,
2046 SCTP_CWND_LOG_FROM_SS);
2050 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2051 sctp_log_cwnd(stcb, net, net->net_ack,
2052 SCTP_CWND_LOG_NOADV_SS);
2059 * In dangerous area, increase slowly. In theory this is
2060 * net->cwnd += alpha / net->cwnd
2062 /* What is snd_cwnd_cnt?? */
2063 if (((net->partial_bytes_acked / net->mtu * net->cc_mod.htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
2065 * Does SCTP have a cwnd clamp?
2066 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2068 net->cwnd += net->mtu;
2069 net->partial_bytes_acked = 0;
2070 htcp_alpha_update(&net->cc_mod.htcp_ca);
2071 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2072 sctp_log_cwnd(stcb, net, net->mtu,
2073 SCTP_CWND_LOG_FROM_CA);
2076 net->partial_bytes_acked += net->net_ack;
2077 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2078 sctp_log_cwnd(stcb, net, net->net_ack,
2079 SCTP_CWND_LOG_NOADV_CA);
2083 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2087 #ifdef SCTP_NOT_USED
2088 /* Lower bound on congestion window. */
2090 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2092 return (net->ssthresh);
2098 htcp_init(struct sctp_nets *net)
2100 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2101 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2102 net->cc_mod.htcp_ca.beta = BETA_MIN;
2103 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2104 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2108 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2111 * We take the max of the burst limit times a MTU or the
2112 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2114 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2115 net->ssthresh = stcb->asoc.peers_rwnd;
2118 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
2119 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2124 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2125 struct sctp_association *asoc,
2126 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2128 struct sctp_nets *net;
2130 /******************************/
2131 /* update cwnd and Early FR */
2132 /******************************/
2133 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2135 #ifdef JANA_CMT_FAST_RECOVERY
2137 * CMT fast recovery code. Need to debug.
2139 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2140 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2141 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
2142 net->will_exit_fast_recovery = 1;
2146 /* if nothing was acked on this destination skip it */
2147 if (net->net_ack == 0) {
2148 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2149 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2153 #ifdef JANA_CMT_FAST_RECOVERY
2155 * CMT fast recovery code
2158 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
2159 * && net->will_exit_fast_recovery == 0) { @@@ Do something
2160 * } else if (sctp_cmt_on_off == 0 &&
2161 * asoc->fast_retran_loss_recovery && will_exit == 0) {
2165 if (asoc->fast_retran_loss_recovery &&
2167 (asoc->sctp_cmt_on_off == 0)) {
2169 * If we are in loss recovery we skip any cwnd
2175 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2179 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2180 htcp_cong_avoid(stcb, net);
2181 measure_achieved_throughput(net);
2183 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2184 sctp_log_cwnd(stcb, net, net->mtu,
2185 SCTP_CWND_LOG_NO_CUMACK);
2192 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2193 struct sctp_association *asoc)
2195 struct sctp_nets *net;
2198 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2199 * (net->fast_retran_loss_recovery == 0)))
2201 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2202 if ((asoc->fast_retran_loss_recovery == 0) ||
2203 (asoc->sctp_cmt_on_off > 0)) {
2204 /* out of a RFC2582 Fast recovery window? */
2205 if (net->net_ack > 0) {
2207 * per section 7.2.3, are there any
2208 * destinations that had a fast retransmit
2209 * to them. If so what we need to do is
2210 * adjust ssthresh and cwnd.
2212 struct sctp_tmit_chunk *lchk;
2213 int old_cwnd = net->cwnd;
2215 /* JRS - reset as if state were changed */
2216 htcp_reset(&net->cc_mod.htcp_ca);
2217 net->ssthresh = htcp_recalc_ssthresh(net);
2218 net->cwnd = net->ssthresh;
2219 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2220 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2221 SCTP_CWND_LOG_FROM_FR);
2223 lchk = TAILQ_FIRST(&asoc->send_queue);
2225 net->partial_bytes_acked = 0;
2226 /* Turn on fast recovery window */
2227 asoc->fast_retran_loss_recovery = 1;
2229 /* Mark end of the window */
2230 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2232 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
2236 * CMT fast recovery -- per destination
2237 * recovery variable.
2239 net->fast_retran_loss_recovery = 1;
2242 /* Mark end of the window */
2243 net->fast_recovery_tsn = asoc->sending_seq - 1;
2245 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
2248 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2249 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
2250 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2251 stcb->sctp_ep, stcb, net);
2253 } else if (net->net_ack > 0) {
2255 * Mark a peg that we WOULD have done a cwnd
2256 * reduction but RFC2582 prevented this action.
2258 SCTP_STAT_INCR(sctps_fastretransinrtt);
2264 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2265 struct sctp_nets *net)
2267 int old_cwnd = net->cwnd;
2269 /* JRS - reset as if the state were being changed to timeout */
2270 htcp_reset(&net->cc_mod.htcp_ca);
2271 net->ssthresh = htcp_recalc_ssthresh(net);
2272 net->cwnd = net->mtu;
2273 net->partial_bytes_acked = 0;
2274 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2275 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2280 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2281 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2285 old_cwnd = net->cwnd;
2287 /* JRS - reset hctp as if state changed */
2288 if (in_window == 0) {
2289 htcp_reset(&net->cc_mod.htcp_ca);
2290 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2291 net->ssthresh = htcp_recalc_ssthresh(net);
2292 if (net->ssthresh < net->mtu) {
2293 net->ssthresh = net->mtu;
2294 /* here back off the timer as well, to slow us down */
2297 net->cwnd = net->ssthresh;
2298 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2299 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2304 struct sctp_cc_functions sctp_cc_functions[] = {
2306 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2307 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2308 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2309 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2310 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2311 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2312 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2313 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2316 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2317 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2318 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2319 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2320 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2321 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2322 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2323 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2326 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2327 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2328 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2329 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2330 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2331 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2332 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2333 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2336 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2337 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2338 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2339 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2340 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2341 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2342 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2343 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2344 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2345 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2346 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2347 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2348 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2349 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated