2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, 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 <netinet/sctp_os.h>
34 #include <netinet/sctp_var.h>
35 #include <netinet/sctp_sysctl.h>
36 #include <netinet/sctp_pcb.h>
37 #include <netinet/sctp_header.h>
38 #include <netinet/sctputil.h>
39 #include <netinet/sctp_output.h>
40 #include <netinet/sctp_input.h>
41 #include <netinet/sctp_indata.h>
42 #include <netinet/sctp_uio.h>
43 #include <netinet/sctp_timer.h>
44 #include <netinet/sctp_auth.h>
45 #include <netinet/sctp_asconf.h>
46 #include <netinet/sctp_dtrace_declare.h>
47 #include <sys/cdefs.h>
48 __FBSDID("$FreeBSD$");
50 #define SHIFT_MPTCP_MULTI_N 40
51 #define SHIFT_MPTCP_MULTI_Z 16
52 #define SHIFT_MPTCP_MULTI 8
55 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
57 struct sctp_association *assoc;
61 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
62 if (cwnd_in_mtu == 0) {
63 /* Using 0 means that the value of RFC 4960 is used. */
64 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
67 * We take the minimum of the burst limit and the initial
70 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
71 cwnd_in_mtu = assoc->max_burst;
72 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
74 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
75 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
76 /* In case of resource pooling initialize appropriately */
77 net->cwnd /= assoc->numnets;
78 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
79 net->cwnd = net->mtu - sizeof(struct sctphdr);
82 net->ssthresh = assoc->peers_rwnd;
83 SDT_PROBE(sctp, cwnd, net, init,
84 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
86 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
87 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
88 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
93 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
94 struct sctp_association *asoc)
96 struct sctp_nets *net;
97 uint32_t t_ssthresh, t_cwnd;
100 /* MT FIXME: Don't compute this over and over again */
104 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
105 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
106 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
107 t_ssthresh += net->ssthresh;
109 if (net->lastsa > 0) {
110 t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) net->lastsa;
113 if (t_ucwnd_sbw == 0) {
118 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
119 * (net->fast_retran_loss_recovery == 0)))
121 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
122 if ((asoc->fast_retran_loss_recovery == 0) ||
123 (asoc->sctp_cmt_on_off > 0)) {
124 /* out of a RFC2582 Fast recovery window? */
125 if (net->net_ack > 0) {
127 * per section 7.2.3, are there any
128 * destinations that had a fast retransmit
129 * to them. If so what we need to do is
130 * adjust ssthresh and cwnd.
132 struct sctp_tmit_chunk *lchk;
133 int old_cwnd = net->cwnd;
135 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
136 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
137 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
138 net->ssthresh = (uint32_t) (((uint64_t) 4 *
139 (uint64_t) net->mtu *
140 (uint64_t) net->ssthresh) /
141 (uint64_t) t_ssthresh);
144 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
149 * lastsa>>3; we don't need
156 * Short Version => Equal to
159 net->ssthresh = (uint32_t) (((uint64_t) 4 *
160 (uint64_t) net->mtu *
161 (uint64_t) net->cwnd) /
164 /* INCREASE FACTOR */ ;
166 if ((net->cwnd > t_cwnd / 2) &&
167 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
168 net->ssthresh = net->cwnd - t_cwnd / 2;
170 if (net->ssthresh < net->mtu) {
171 net->ssthresh = net->mtu;
174 net->ssthresh = net->cwnd / 2;
175 if (net->ssthresh < (net->mtu * 2)) {
176 net->ssthresh = 2 * net->mtu;
179 net->cwnd = net->ssthresh;
180 SDT_PROBE(sctp, cwnd, net, fr,
181 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
182 old_cwnd, net->cwnd);
183 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
184 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
185 SCTP_CWND_LOG_FROM_FR);
187 lchk = TAILQ_FIRST(&asoc->send_queue);
189 net->partial_bytes_acked = 0;
190 /* Turn on fast recovery window */
191 asoc->fast_retran_loss_recovery = 1;
193 /* Mark end of the window */
194 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
196 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
200 * CMT fast recovery -- per destination
203 net->fast_retran_loss_recovery = 1;
206 /* Mark end of the window */
207 net->fast_recovery_tsn = asoc->sending_seq - 1;
209 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
212 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
213 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
214 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
215 stcb->sctp_ep, stcb, net);
217 } else if (net->net_ack > 0) {
219 * Mark a peg that we WOULD have done a cwnd
220 * reduction but RFC2582 prevented this action.
222 SCTP_STAT_INCR(sctps_fastretransinrtt);
227 /* Defines for instantaneous bw decisions */
228 #define SCTP_INST_LOOSING 1 /* Loosing to other flows */
229 #define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
230 #define SCTP_INST_GAINING 3 /* Gaining, step down possible */
234 cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
235 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
237 uint64_t oth, probepoint;
239 probepoint = (((uint64_t) net->cwnd) << 32);
240 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
242 * rtt increased we don't update bw.. so we don't update the
246 probepoint |= ((5 << 16) | 1);
247 SDT_PROBE(sctp, cwnd, net, rttvar,
249 ((net->cc_mod.rtcc.lbw << 32) | nbw),
250 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
253 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
254 if (net->cc_mod.rtcc.last_step_state == 5)
255 net->cc_mod.rtcc.step_cnt++;
257 net->cc_mod.rtcc.step_cnt = 1;
258 net->cc_mod.rtcc.last_step_state = 5;
259 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
260 ((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) == 0))) {
262 /* Try a step down */
263 oth = net->cc_mod.rtcc.vol_reduce;
265 oth |= net->cc_mod.rtcc.step_cnt;
267 oth |= net->cc_mod.rtcc.last_step_state;
268 SDT_PROBE(sctp, cwnd, net, rttstep,
270 ((net->cc_mod.rtcc.lbw << 32) | nbw),
271 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
274 if (net->cwnd > (4 * net->mtu)) {
275 net->cwnd -= net->mtu;
276 net->cc_mod.rtcc.vol_reduce++;
278 net->cc_mod.rtcc.step_cnt = 0;
284 if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
286 * rtt decreased, there could be more room. we update both
287 * the bw and the rtt here to lock this in as a good step
291 probepoint |= ((6 << 16) | 0);
292 SDT_PROBE(sctp, cwnd, net, rttvar,
294 ((net->cc_mod.rtcc.lbw << 32) | nbw),
295 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
298 if (net->cc_mod.rtcc.steady_step) {
299 oth = net->cc_mod.rtcc.vol_reduce;
301 oth |= net->cc_mod.rtcc.step_cnt;
303 oth |= net->cc_mod.rtcc.last_step_state;
304 SDT_PROBE(sctp, cwnd, net, rttstep,
306 ((net->cc_mod.rtcc.lbw << 32) | nbw),
307 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
310 if ((net->cc_mod.rtcc.last_step_state == 5) &&
311 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
312 /* Step down worked */
313 net->cc_mod.rtcc.step_cnt = 0;
316 net->cc_mod.rtcc.last_step_state = 6;
317 net->cc_mod.rtcc.step_cnt = 0;
320 net->cc_mod.rtcc.lbw = nbw;
321 net->cc_mod.rtcc.lbw_rtt = net->rtt;
322 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
323 if (inst_ind == SCTP_INST_GAINING)
325 else if (inst_ind == SCTP_INST_NEUTRAL)
331 * Ok bw and rtt remained the same .. no update to any
334 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
335 SDT_PROBE(sctp, cwnd, net, rttvar,
337 ((net->cc_mod.rtcc.lbw << 32) | nbw),
338 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
341 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
342 if (net->cc_mod.rtcc.last_step_state == 5)
343 net->cc_mod.rtcc.step_cnt++;
345 net->cc_mod.rtcc.step_cnt = 1;
346 net->cc_mod.rtcc.last_step_state = 5;
347 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
348 ((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) == 0))) {
350 /* Try a step down */
351 if (net->cwnd > (4 * net->mtu)) {
352 net->cwnd -= net->mtu;
353 net->cc_mod.rtcc.vol_reduce++;
356 net->cc_mod.rtcc.step_cnt = 0;
360 if (inst_ind == SCTP_INST_GAINING)
362 else if (inst_ind == SCTP_INST_NEUTRAL)
365 return ((int)net->cc_mod.rtcc.ret_from_eq);
369 cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
370 uint64_t vtag, uint8_t inst_ind)
372 uint64_t oth, probepoint;
374 /* Bandwidth decreased. */
375 probepoint = (((uint64_t) net->cwnd) << 32);
376 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
378 /* Did we add more */
379 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
380 (inst_ind != SCTP_INST_LOOSING)) {
381 /* We caused it maybe.. back off? */
383 probepoint |= ((1 << 16) | 1);
384 SDT_PROBE(sctp, cwnd, net, rttvar,
386 ((net->cc_mod.rtcc.lbw << 32) | nbw),
387 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
390 if (net->cc_mod.rtcc.ret_from_eq) {
392 * Switch over to CA if we are less
395 net->ssthresh = net->cwnd - 1;
396 net->partial_bytes_acked = 0;
401 probepoint |= ((2 << 16) | 0);
402 SDT_PROBE(sctp, cwnd, net, rttvar,
404 ((net->cc_mod.rtcc.lbw << 32) | nbw),
405 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
408 /* Someone else - fight for more? */
409 if (net->cc_mod.rtcc.steady_step) {
410 oth = net->cc_mod.rtcc.vol_reduce;
412 oth |= net->cc_mod.rtcc.step_cnt;
414 oth |= net->cc_mod.rtcc.last_step_state;
415 SDT_PROBE(sctp, cwnd, net, rttstep,
417 ((net->cc_mod.rtcc.lbw << 32) | nbw),
418 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
422 * Did we voluntarily give up some? if so take one
425 if ((net->cc_mod.rtcc.vol_reduce) &&
426 (inst_ind != SCTP_INST_GAINING)) {
427 net->cwnd += net->mtu;
428 net->cc_mod.rtcc.vol_reduce--;
430 net->cc_mod.rtcc.last_step_state = 2;
431 net->cc_mod.rtcc.step_cnt = 0;
434 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt - rtt_offset) {
435 /* bw & rtt decreased */
437 probepoint |= ((3 << 16) | 0);
438 SDT_PROBE(sctp, cwnd, net, rttvar,
440 ((net->cc_mod.rtcc.lbw << 32) | nbw),
441 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
444 if (net->cc_mod.rtcc.steady_step) {
445 oth = net->cc_mod.rtcc.vol_reduce;
447 oth |= net->cc_mod.rtcc.step_cnt;
449 oth |= net->cc_mod.rtcc.last_step_state;
450 SDT_PROBE(sctp, cwnd, net, rttstep,
452 ((net->cc_mod.rtcc.lbw << 32) | nbw),
453 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
456 if ((net->cc_mod.rtcc.vol_reduce) &&
457 (inst_ind != SCTP_INST_GAINING)) {
458 net->cwnd += net->mtu;
459 net->cc_mod.rtcc.vol_reduce--;
461 net->cc_mod.rtcc.last_step_state = 3;
462 net->cc_mod.rtcc.step_cnt = 0;
466 /* The bw decreased but rtt stayed the same */
468 probepoint |= ((4 << 16) | 0);
469 SDT_PROBE(sctp, cwnd, net, rttvar,
471 ((net->cc_mod.rtcc.lbw << 32) | nbw),
472 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
475 if (net->cc_mod.rtcc.steady_step) {
476 oth = net->cc_mod.rtcc.vol_reduce;
478 oth |= net->cc_mod.rtcc.step_cnt;
480 oth |= net->cc_mod.rtcc.last_step_state;
481 SDT_PROBE(sctp, cwnd, net, rttstep,
483 ((net->cc_mod.rtcc.lbw << 32) | nbw),
484 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
487 if ((net->cc_mod.rtcc.vol_reduce) &&
488 (inst_ind != SCTP_INST_GAINING)) {
489 net->cwnd += net->mtu;
490 net->cc_mod.rtcc.vol_reduce--;
492 net->cc_mod.rtcc.last_step_state = 4;
493 net->cc_mod.rtcc.step_cnt = 0;
496 net->cc_mod.rtcc.lbw = nbw;
497 net->cc_mod.rtcc.lbw_rtt = net->rtt;
498 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
499 if (inst_ind == SCTP_INST_GAINING) {
507 cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
509 uint64_t oth, probepoint;
512 * BW increased, so update and return 0, since all actions in our
513 * table say to do the normal CC update. Note that we pay no
514 * attention to the inst_ind since our overall sum is increasing.
517 probepoint = (((uint64_t) net->cwnd) << 32);
518 SDT_PROBE(sctp, cwnd, net, rttvar,
520 ((net->cc_mod.rtcc.lbw << 32) | nbw),
521 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
524 if (net->cc_mod.rtcc.steady_step) {
525 oth = net->cc_mod.rtcc.vol_reduce;
527 oth |= net->cc_mod.rtcc.step_cnt;
529 oth |= net->cc_mod.rtcc.last_step_state;
530 SDT_PROBE(sctp, cwnd, net, rttstep,
532 ((net->cc_mod.rtcc.lbw << 32) | nbw),
533 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
536 net->cc_mod.rtcc.last_step_state = 0;
537 net->cc_mod.rtcc.step_cnt = 0;
538 net->cc_mod.rtcc.vol_reduce = 0;
540 net->cc_mod.rtcc.lbw = nbw;
541 net->cc_mod.rtcc.lbw_rtt = net->rtt;
542 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
546 /* RTCC Algoritm to limit growth of cwnd, return
547 * true if you want to NOT allow cwnd growth
550 cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
552 uint64_t bw_offset, rtt_offset;
553 uint64_t probepoint, rtt, vtag;
554 uint64_t bytes_for_this_rtt, inst_bw;
555 uint64_t div, inst_off;
561 * Here we need to see if we want
562 * to limit cwnd growth due to increase
563 * in overall rtt but no increase in bw.
564 * We use the following table to figure
565 * out what we should do. When we return
566 * 0, cc update goes on as planned. If we
567 * return 1, then no cc update happens and cwnd
568 * stays where it is at.
569 * ----------------------------------
571 * *********************************
572 * INC | INC | return 0
573 * ----------------------------------
574 * INC | SAME | return 0
575 * ----------------------------------
576 * INC | DECR | return 0
577 * ----------------------------------
578 * SAME | INC | return 1
579 * ----------------------------------
580 * SAME | SAME | return 1
581 * ----------------------------------
582 * SAME | DECR | return 0
583 * ----------------------------------
584 * DECR | INC | return 0 or 1 based on if we caused.
585 * ----------------------------------
586 * DECR | SAME | return 0
587 * ----------------------------------
588 * DECR | DECR | return 0
589 * ----------------------------------
591 * We are a bit fuzz on what an increase or
592 * decrease is. For BW it is the same if
593 * it did not change within 1/64th. For
594 * RTT it stayed the same if it did not
595 * change within 1/32nd
597 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
598 rtt = stcb->asoc.my_vtag;
599 vtag = (rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
600 probepoint = (((uint64_t) net->cwnd) << 32);
602 if (net->cc_mod.rtcc.rtt_set_this_sack) {
603 net->cc_mod.rtcc.rtt_set_this_sack = 0;
604 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
605 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
607 div = net->rtt / 1000;
609 inst_bw = bytes_for_this_rtt / div;
610 inst_off = inst_bw >> bw_shift;
612 inst_ind = SCTP_INST_GAINING;
613 else if ((inst_bw + inst_off) < nbw)
614 inst_ind = SCTP_INST_LOOSING;
616 inst_ind = SCTP_INST_NEUTRAL;
617 probepoint |= ((0xb << 16) | inst_ind);
619 inst_ind = net->cc_mod.rtcc.last_inst_ind;
620 inst_bw = bytes_for_this_rtt / (uint64_t) (net->rtt);
621 /* Can't determine do not change */
622 probepoint |= ((0xc << 16) | inst_ind);
625 inst_ind = net->cc_mod.rtcc.last_inst_ind;
626 inst_bw = bytes_for_this_rtt;
627 /* Can't determine do not change */
628 probepoint |= ((0xd << 16) | inst_ind);
630 SDT_PROBE(sctp, cwnd, net, rttvar,
632 ((nbw << 32) | inst_bw),
633 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
637 /* No rtt measurement, use last one */
638 inst_ind = net->cc_mod.rtcc.last_inst_ind;
640 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
641 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
642 ret = cc_bw_increase(stcb, net, nbw, vtag);
645 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
646 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
647 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
651 * If we reach here then we are in a situation where the bw stayed
654 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
656 net->cc_mod.rtcc.last_inst_ind = inst_ind;
661 sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
662 struct sctp_association *asoc,
663 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
665 struct sctp_nets *net;
667 uint32_t t_ssthresh, t_cwnd, incr;
668 uint64_t t_ucwnd_sbw;
669 uint64_t t_path_mptcp;
670 uint64_t mptcp_like_alpha;
674 /* MT FIXME: Don't compute this over and over again */
679 mptcp_like_alpha = 1;
680 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
681 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
682 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
684 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
685 t_ssthresh += net->ssthresh;
687 /* lastsa>>3; we don't need to devide ... */
692 t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) srtt;
693 t_path_mptcp += (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_Z) /
694 (((uint64_t) net->mtu) * (uint64_t) srtt);
695 tmp = (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_N) /
696 ((uint64_t) net->mtu * (uint64_t) (srtt * srtt));
697 if (tmp > max_path) {
702 if (t_path_mptcp > 0) {
703 mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp);
705 mptcp_like_alpha = 1;
708 if (t_ssthresh == 0) {
711 if (t_ucwnd_sbw == 0) {
714 /******************************/
715 /* update cwnd and Early FR */
716 /******************************/
717 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
719 #ifdef JANA_CMT_FAST_RECOVERY
721 * CMT fast recovery code. Need to debug.
723 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
724 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
725 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
726 net->will_exit_fast_recovery = 1;
730 /* if nothing was acked on this destination skip it */
731 if (net->net_ack == 0) {
732 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
733 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
737 #ifdef JANA_CMT_FAST_RECOVERY
739 * CMT fast recovery code
742 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
743 * && net->will_exit_fast_recovery == 0) { @@@ Do something
744 * } else if (sctp_cmt_on_off == 0 &&
745 * asoc->fast_retran_loss_recovery && will_exit == 0) {
749 if (asoc->fast_retran_loss_recovery &&
751 (asoc->sctp_cmt_on_off == 0)) {
753 * If we are in loss recovery we skip any cwnd
759 * Did any measurements go on for this network?
761 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
765 * At this point our bw_bytes has been updated by
766 * incoming sack information.
768 * But our bw may not yet be set.
771 if ((net->cc_mod.rtcc.new_tot_time / 1000) > 0) {
772 nbw = net->cc_mod.rtcc.bw_bytes / (net->cc_mod.rtcc.new_tot_time / 1000);
774 nbw = net->cc_mod.rtcc.bw_bytes;
776 if (net->cc_mod.rtcc.lbw) {
777 if (cc_bw_limit(stcb, net, nbw)) {
778 /* Hold here, no update */
782 uint64_t vtag, probepoint;
784 probepoint = (((uint64_t) net->cwnd) << 32);
785 probepoint |= ((0xa << 16) | 0);
786 vtag = (net->rtt << 32) |
787 (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
790 SDT_PROBE(sctp, cwnd, net, rttvar,
793 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
796 net->cc_mod.rtcc.lbw = nbw;
797 net->cc_mod.rtcc.lbw_rtt = net->rtt;
798 if (net->cc_mod.rtcc.rtt_set_this_sack) {
799 net->cc_mod.rtcc.rtt_set_this_sack = 0;
800 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
805 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
809 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
810 /* If the cumulative ack moved we can proceed */
811 if (net->cwnd <= net->ssthresh) {
812 /* We are in slow start */
813 if (net->flight_size + net->net_ack >= net->cwnd) {
816 old_cwnd = net->cwnd;
817 switch (asoc->sctp_cmt_on_off) {
819 limit = (uint32_t) (((uint64_t) net->mtu *
820 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
821 (uint64_t) net->ssthresh) /
822 (uint64_t) t_ssthresh);
823 incr = (uint32_t) (((uint64_t) net->net_ack *
824 (uint64_t) net->ssthresh) /
825 (uint64_t) t_ssthresh);
835 * lastsa>>3; we don't need
842 limit = (uint32_t) (((uint64_t) net->mtu *
843 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
844 (uint64_t) net->cwnd) /
845 ((uint64_t) srtt * t_ucwnd_sbw));
846 /* INCREASE FACTOR */
847 incr = (uint32_t) (((uint64_t) net->net_ack *
848 (uint64_t) net->cwnd) /
849 ((uint64_t) srtt * t_ucwnd_sbw));
850 /* INCREASE FACTOR */
859 limit = (uint32_t) (((uint64_t) net->mtu *
861 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
863 incr = (uint32_t) (((uint64_t) net->net_ack *
869 if (incr > net->net_ack) {
872 if (incr > net->mtu) {
878 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
879 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
884 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
885 sctp_log_cwnd(stcb, net, incr,
886 SCTP_CWND_LOG_FROM_SS);
888 SDT_PROBE(sctp, cwnd, net, ack,
890 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
892 old_cwnd, net->cwnd);
894 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
895 sctp_log_cwnd(stcb, net, net->net_ack,
896 SCTP_CWND_LOG_NOADV_SS);
900 /* We are in congestion avoidance */
904 net->partial_bytes_acked += net->net_ack;
906 if ((net->flight_size + net->net_ack >= net->cwnd) &&
907 (net->partial_bytes_acked >= net->cwnd)) {
908 net->partial_bytes_acked -= net->cwnd;
909 old_cwnd = net->cwnd;
910 switch (asoc->sctp_cmt_on_off) {
912 incr = (uint32_t) (((uint64_t) net->mtu *
913 (uint64_t) net->ssthresh) /
914 (uint64_t) t_ssthresh);
921 * lastsa>>3; we don't need
928 incr = (uint32_t) ((uint64_t) net->mtu *
929 (uint64_t) net->cwnd /
932 /* INCREASE FACTOR */
938 incr = (uint32_t) ((mptcp_like_alpha *
939 (uint64_t) net->cwnd) >>
941 if (incr > net->mtu) {
950 SDT_PROBE(sctp, cwnd, net, ack,
952 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
954 old_cwnd, net->cwnd);
955 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
956 sctp_log_cwnd(stcb, net, net->mtu,
957 SCTP_CWND_LOG_FROM_CA);
960 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
961 sctp_log_cwnd(stcb, net, net->net_ack,
962 SCTP_CWND_LOG_NOADV_CA);
967 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
968 sctp_log_cwnd(stcb, net, net->mtu,
969 SCTP_CWND_LOG_NO_CUMACK);
976 sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
980 old_cwnd = net->cwnd;
981 net->cwnd = net->mtu;
982 SDT_PROBE(sctp, cwnd, net, ack,
983 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
984 old_cwnd, net->cwnd);
985 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
991 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
993 int old_cwnd = net->cwnd;
994 uint32_t t_ssthresh, t_cwnd;
995 uint64_t t_ucwnd_sbw;
997 /* MT FIXME: Don't compute this over and over again */
1000 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1001 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1002 struct sctp_nets *lnet;
1006 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1007 t_ssthresh += lnet->ssthresh;
1008 t_cwnd += lnet->cwnd;
1009 srtt = lnet->lastsa;
1010 /* lastsa>>3; we don't need to divide ... */
1012 t_ucwnd_sbw += (uint64_t) lnet->cwnd / (uint64_t) srtt;
1015 if (t_ssthresh < 1) {
1018 if (t_ucwnd_sbw < 1) {
1021 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1022 net->ssthresh = (uint32_t) (((uint64_t) 4 *
1023 (uint64_t) net->mtu *
1024 (uint64_t) net->ssthresh) /
1025 (uint64_t) t_ssthresh);
1030 /* lastsa>>3; we don't need to divide ... */
1034 cc_delta = t_ucwnd_sbw * (uint64_t) srtt / 2;
1035 if (cc_delta < t_cwnd) {
1036 net->ssthresh = (uint32_t) ((uint64_t) t_cwnd - cc_delta);
1038 net->ssthresh = net->mtu;
1041 if ((net->cwnd > t_cwnd / 2) &&
1042 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1043 net->ssthresh = net->cwnd - t_cwnd / 2;
1045 if (net->ssthresh < net->mtu) {
1046 net->ssthresh = net->mtu;
1049 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1051 net->cwnd = net->mtu;
1052 net->partial_bytes_acked = 0;
1053 SDT_PROBE(sctp, cwnd, net, to,
1055 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1057 old_cwnd, net->cwnd);
1058 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1059 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1064 sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1065 int in_window, int num_pkt_lost, int use_rtcc)
1067 int old_cwnd = net->cwnd;
1069 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1070 /* Data center Congestion Control */
1071 if (in_window == 0) {
1073 * Go to CA with the cwnd at the point we sent the
1074 * TSN that was marked with a CE.
1076 if (net->ecn_prev_cwnd < net->cwnd) {
1077 /* Restore to prev cwnd */
1078 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1080 /* Just cut in 1/2 */
1084 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1085 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1086 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1090 * Further tuning down required over the drastic
1093 net->ssthresh -= (net->mtu * num_pkt_lost);
1094 net->cwnd -= (net->mtu * num_pkt_lost);
1095 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1096 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1099 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1101 if (in_window == 0) {
1102 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1103 net->ssthresh = net->cwnd / 2;
1104 if (net->ssthresh < net->mtu) {
1105 net->ssthresh = net->mtu;
1107 * here back off the timer as well, to slow
1112 net->cwnd = net->ssthresh;
1113 SDT_PROBE(sctp, cwnd, net, ecn,
1115 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1117 old_cwnd, net->cwnd);
1118 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1119 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1127 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1128 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1129 uint32_t * bottle_bw, uint32_t * on_queue)
1134 int old_cwnd = net->cwnd;
1136 /* need real RTT in msd for this calc */
1137 rtt = net->rtt / 1000;
1138 /* get bottle neck bw */
1139 *bottle_bw = ntohl(cp->bottle_bw);
1140 /* and whats on queue */
1141 *on_queue = ntohl(cp->current_onq);
1143 * adjust the on-queue if our flight is more it could be that the
1144 * router has not yet gotten data "in-flight" to it
1146 if (*on_queue < net->flight_size)
1147 *on_queue = net->flight_size;
1148 /* calculate the available space */
1149 bw_avail = (*bottle_bw * rtt) / 1000;
1150 if (bw_avail > *bottle_bw) {
1152 * Cap the growth to no more than the bottle neck. This can
1153 * happen as RTT slides up due to queues. It also means if
1154 * you have more than a 1 second RTT with a empty queue you
1155 * will be limited to the bottle_bw per second no matter if
1156 * other points have 1/2 the RTT and you could get more
1159 bw_avail = *bottle_bw;
1161 if (*on_queue > bw_avail) {
1163 * No room for anything else don't allow anything else to be
1164 * "added to the fire".
1166 int seg_inflight, seg_onqueue, my_portion;
1168 net->partial_bytes_acked = 0;
1170 /* how much are we over queue size? */
1171 incr = *on_queue - bw_avail;
1172 if (stcb->asoc.seen_a_sack_this_pkt) {
1174 * undo any cwnd adjustment that the sack might have
1177 net->cwnd = net->prev_cwnd;
1179 /* Now how much of that is mine? */
1180 seg_inflight = net->flight_size / net->mtu;
1181 seg_onqueue = *on_queue / net->mtu;
1182 my_portion = (incr * seg_inflight) / seg_onqueue;
1184 /* Have I made an adjustment already */
1185 if (net->cwnd > net->flight_size) {
1187 * for this flight I made an adjustment we need to
1188 * decrease the portion by a share our previous
1193 diff_adj = net->cwnd - net->flight_size;
1194 if (diff_adj > my_portion)
1197 my_portion -= diff_adj;
1200 * back down to the previous cwnd (assume we have had a sack
1201 * before this packet). minus what ever portion of the
1202 * overage is my fault.
1204 net->cwnd -= my_portion;
1206 /* we will NOT back down more than 1 MTU */
1207 if (net->cwnd <= net->mtu) {
1208 net->cwnd = net->mtu;
1211 net->ssthresh = net->cwnd - 1;
1214 * Take 1/4 of the space left or max burst up .. whichever
1217 incr = (bw_avail - *on_queue) >> 2;
1218 if ((stcb->asoc.max_burst > 0) &&
1219 (stcb->asoc.max_burst * net->mtu < incr)) {
1220 incr = stcb->asoc.max_burst * net->mtu;
1224 if (net->cwnd > bw_avail) {
1225 /* We can't exceed the pipe size */
1226 net->cwnd = bw_avail;
1228 if (net->cwnd < net->mtu) {
1229 /* We always have 1 MTU */
1230 net->cwnd = net->mtu;
1232 if (net->cwnd - old_cwnd != 0) {
1233 /* log only changes */
1234 SDT_PROBE(sctp, cwnd, net, pd,
1236 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1238 old_cwnd, net->cwnd);
1239 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1240 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1241 SCTP_CWND_LOG_FROM_SAT);
1247 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1248 struct sctp_nets *net, int burst_limit)
1250 int old_cwnd = net->cwnd;
1252 if (net->ssthresh < net->cwnd)
1253 net->ssthresh = net->cwnd;
1255 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1256 SDT_PROBE(sctp, cwnd, net, bl,
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), SCTP_CWND_LOG_FROM_BRST);
1268 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1269 struct sctp_association *asoc,
1270 int accum_moved, int reneged_all, int will_exit)
1272 /* Passing a zero argument in last disables the rtcc algoritm */
1273 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1277 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1278 int in_window, int num_pkt_lost)
1280 /* Passing a zero argument in last disables the rtcc algoritm */
1281 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1284 /* Here starts the RTCCVAR type CC invented by RRS which
1285 * is a slight mod to RFC2581. We reuse a common routine or
1286 * two since these algoritms are so close and need to
1290 sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1291 int in_window, int num_pkt_lost)
1293 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1299 sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1300 struct sctp_tmit_chunk *tp1)
1302 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1306 sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1307 struct sctp_nets *net)
1309 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1310 /* We had a bw measurment going on */
1311 struct timeval ltls;
1313 SCTP_GETPTIME_TIMEVAL(<ls);
1314 timevalsub(<ls, &net->cc_mod.rtcc.tls);
1315 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1320 sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1321 struct sctp_nets *net)
1323 uint64_t vtag, probepoint;
1325 if (net->cc_mod.rtcc.lbw) {
1326 /* Clear the old bw.. we went to 0 in-flight */
1327 vtag = (net->rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
1329 probepoint = (((uint64_t) net->cwnd) << 32);
1331 probepoint |= ((8 << 16) | 0);
1332 SDT_PROBE(sctp, cwnd, net, rttvar,
1334 ((net->cc_mod.rtcc.lbw << 32) | 0),
1335 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1338 net->cc_mod.rtcc.lbw_rtt = 0;
1339 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1340 net->cc_mod.rtcc.lbw = 0;
1341 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1342 net->cc_mod.rtcc.vol_reduce = 0;
1343 net->cc_mod.rtcc.bw_tot_time = 0;
1344 net->cc_mod.rtcc.bw_bytes = 0;
1345 net->cc_mod.rtcc.tls_needs_set = 0;
1346 if (net->cc_mod.rtcc.steady_step) {
1347 net->cc_mod.rtcc.vol_reduce = 0;
1348 net->cc_mod.rtcc.step_cnt = 0;
1349 net->cc_mod.rtcc.last_step_state = 0;
1351 if (net->cc_mod.rtcc.ret_from_eq) {
1352 /* less aggressive one - reset cwnd too */
1353 uint32_t cwnd_in_mtu, cwnd;
1355 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1356 if (cwnd_in_mtu == 0) {
1358 * Using 0 means that the value of RFC 4960
1361 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1364 * We take the minimum of the burst limit
1365 * and the initial congestion window.
1367 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1368 cwnd_in_mtu = stcb->asoc.max_burst;
1369 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1371 if (net->cwnd > cwnd) {
1373 * Only set if we are not a timeout (i.e.
1383 sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1384 struct sctp_nets *net)
1386 uint64_t vtag, probepoint;
1388 sctp_set_initial_cc_param(stcb, net);
1389 stcb->asoc.use_precise_time = 1;
1390 probepoint = (((uint64_t) net->cwnd) << 32);
1391 probepoint |= ((9 << 16) | 0);
1392 vtag = (net->rtt << 32) |
1393 (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) |
1395 SDT_PROBE(sctp, cwnd, net, rttvar,
1401 net->cc_mod.rtcc.lbw_rtt = 0;
1402 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1403 net->cc_mod.rtcc.vol_reduce = 0;
1404 net->cc_mod.rtcc.lbw = 0;
1405 net->cc_mod.rtcc.vol_reduce = 0;
1406 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1407 net->cc_mod.rtcc.bw_tot_time = 0;
1408 net->cc_mod.rtcc.bw_bytes = 0;
1409 net->cc_mod.rtcc.tls_needs_set = 0;
1410 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1411 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1412 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1413 net->cc_mod.rtcc.step_cnt = 0;
1414 net->cc_mod.rtcc.last_step_state = 0;
1420 sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1421 struct sctp_cc_option *cc_opt)
1423 struct sctp_nets *net;
1425 if (setorget == 1) {
1427 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1428 if ((cc_opt->aid_value.assoc_value != 0) &&
1429 (cc_opt->aid_value.assoc_value != 1)) {
1432 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1433 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1435 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1436 if ((cc_opt->aid_value.assoc_value != 0) &&
1437 (cc_opt->aid_value.assoc_value != 1)) {
1440 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1441 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1443 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1444 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1445 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1452 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1453 net = TAILQ_FIRST(&stcb->asoc.nets);
1457 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1458 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1459 net = TAILQ_FIRST(&stcb->asoc.nets);
1463 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1464 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1465 net = TAILQ_FIRST(&stcb->asoc.nets);
1469 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1478 sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1479 struct sctp_nets *net)
1481 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1482 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1483 net->cc_mod.rtcc.tls_needs_set = 2;
1488 sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1489 struct sctp_association *asoc,
1490 int accum_moved, int reneged_all, int will_exit)
1492 /* Passing a one argument at the last enables the rtcc algoritm */
1493 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1497 sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1498 struct sctp_nets *net,
1499 struct timeval *now SCTP_UNUSED)
1501 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1504 /* Here starts Sally Floyds HS-TCP */
1506 struct sctp_hs_raise_drop {
1509 int32_t drop_percent;
1512 #define SCTP_HS_TABLE_SIZE 73
1514 struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1515 {38, 1, 50}, /* 0 */
1516 {118, 2, 44}, /* 1 */
1517 {221, 3, 41}, /* 2 */
1518 {347, 4, 38}, /* 3 */
1519 {495, 5, 37}, /* 4 */
1520 {663, 6, 35}, /* 5 */
1521 {851, 7, 34}, /* 6 */
1522 {1058, 8, 33}, /* 7 */
1523 {1284, 9, 32}, /* 8 */
1524 {1529, 10, 31}, /* 9 */
1525 {1793, 11, 30}, /* 10 */
1526 {2076, 12, 29}, /* 11 */
1527 {2378, 13, 28}, /* 12 */
1528 {2699, 14, 28}, /* 13 */
1529 {3039, 15, 27}, /* 14 */
1530 {3399, 16, 27}, /* 15 */
1531 {3778, 17, 26}, /* 16 */
1532 {4177, 18, 26}, /* 17 */
1533 {4596, 19, 25}, /* 18 */
1534 {5036, 20, 25}, /* 19 */
1535 {5497, 21, 24}, /* 20 */
1536 {5979, 22, 24}, /* 21 */
1537 {6483, 23, 23}, /* 22 */
1538 {7009, 24, 23}, /* 23 */
1539 {7558, 25, 22}, /* 24 */
1540 {8130, 26, 22}, /* 25 */
1541 {8726, 27, 22}, /* 26 */
1542 {9346, 28, 21}, /* 27 */
1543 {9991, 29, 21}, /* 28 */
1544 {10661, 30, 21}, /* 29 */
1545 {11358, 31, 20}, /* 30 */
1546 {12082, 32, 20}, /* 31 */
1547 {12834, 33, 20}, /* 32 */
1548 {13614, 34, 19}, /* 33 */
1549 {14424, 35, 19}, /* 34 */
1550 {15265, 36, 19}, /* 35 */
1551 {16137, 37, 19}, /* 36 */
1552 {17042, 38, 18}, /* 37 */
1553 {17981, 39, 18}, /* 38 */
1554 {18955, 40, 18}, /* 39 */
1555 {19965, 41, 17}, /* 40 */
1556 {21013, 42, 17}, /* 41 */
1557 {22101, 43, 17}, /* 42 */
1558 {23230, 44, 17}, /* 43 */
1559 {24402, 45, 16}, /* 44 */
1560 {25618, 46, 16}, /* 45 */
1561 {26881, 47, 16}, /* 46 */
1562 {28193, 48, 16}, /* 47 */
1563 {29557, 49, 15}, /* 48 */
1564 {30975, 50, 15}, /* 49 */
1565 {32450, 51, 15}, /* 50 */
1566 {33986, 52, 15}, /* 51 */
1567 {35586, 53, 14}, /* 52 */
1568 {37253, 54, 14}, /* 53 */
1569 {38992, 55, 14}, /* 54 */
1570 {40808, 56, 14}, /* 55 */
1571 {42707, 57, 13}, /* 56 */
1572 {44694, 58, 13}, /* 57 */
1573 {46776, 59, 13}, /* 58 */
1574 {48961, 60, 13}, /* 59 */
1575 {51258, 61, 13}, /* 60 */
1576 {53677, 62, 12}, /* 61 */
1577 {56230, 63, 12}, /* 62 */
1578 {58932, 64, 12}, /* 63 */
1579 {61799, 65, 12}, /* 64 */
1580 {64851, 66, 11}, /* 65 */
1581 {68113, 67, 11}, /* 66 */
1582 {71617, 68, 11}, /* 67 */
1583 {75401, 69, 10}, /* 68 */
1584 {79517, 70, 10}, /* 69 */
1585 {84035, 71, 10}, /* 70 */
1586 {89053, 72, 10}, /* 71 */
1587 {94717, 73, 9} /* 72 */
1591 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1593 int cur_val, i, indx, incr;
1595 cur_val = net->cwnd >> 10;
1596 indx = SCTP_HS_TABLE_SIZE - 1;
1598 printf("HS CC CAlled.\n");
1600 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1602 if (net->net_ack > net->mtu) {
1603 net->cwnd += net->mtu;
1604 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1605 sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS);
1608 net->cwnd += net->net_ack;
1609 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1610 sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
1614 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1615 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1620 net->last_hs_used = indx;
1621 incr = ((sctp_cwnd_adjust[indx].increase) << 10);
1623 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1624 sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS);
1630 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1632 int cur_val, i, indx;
1633 int old_cwnd = net->cwnd;
1635 cur_val = net->cwnd >> 10;
1636 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1638 net->ssthresh = net->cwnd / 2;
1639 if (net->ssthresh < (net->mtu * 2)) {
1640 net->ssthresh = 2 * net->mtu;
1642 net->cwnd = net->ssthresh;
1644 /* drop by the proper amount */
1645 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1646 sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1647 net->cwnd = net->ssthresh;
1648 /* now where are we */
1649 indx = net->last_hs_used;
1650 cur_val = net->cwnd >> 10;
1651 /* reset where we are in the table */
1652 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1653 /* feel out of hs */
1654 net->last_hs_used = 0;
1656 for (i = indx; i >= 1; i--) {
1657 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1661 net->last_hs_used = indx;
1664 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1665 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1670 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1671 struct sctp_association *asoc)
1673 struct sctp_nets *net;
1676 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1677 * (net->fast_retran_loss_recovery == 0)))
1679 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1680 if ((asoc->fast_retran_loss_recovery == 0) ||
1681 (asoc->sctp_cmt_on_off > 0)) {
1682 /* out of a RFC2582 Fast recovery window? */
1683 if (net->net_ack > 0) {
1685 * per section 7.2.3, are there any
1686 * destinations that had a fast retransmit
1687 * to them. If so what we need to do is
1688 * adjust ssthresh and cwnd.
1690 struct sctp_tmit_chunk *lchk;
1692 sctp_hs_cwnd_decrease(stcb, net);
1694 lchk = TAILQ_FIRST(&asoc->send_queue);
1696 net->partial_bytes_acked = 0;
1697 /* Turn on fast recovery window */
1698 asoc->fast_retran_loss_recovery = 1;
1700 /* Mark end of the window */
1701 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1703 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1707 * CMT fast recovery -- per destination
1708 * recovery variable.
1710 net->fast_retran_loss_recovery = 1;
1713 /* Mark end of the window */
1714 net->fast_recovery_tsn = asoc->sending_seq - 1;
1716 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1719 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1720 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
1721 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1722 stcb->sctp_ep, stcb, net);
1724 } else if (net->net_ack > 0) {
1726 * Mark a peg that we WOULD have done a cwnd
1727 * reduction but RFC2582 prevented this action.
1729 SCTP_STAT_INCR(sctps_fastretransinrtt);
1735 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1736 struct sctp_association *asoc,
1737 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1739 struct sctp_nets *net;
1741 /******************************/
1742 /* update cwnd and Early FR */
1743 /******************************/
1744 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1746 #ifdef JANA_CMT_FAST_RECOVERY
1748 * CMT fast recovery code. Need to debug.
1750 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1751 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1752 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1753 net->will_exit_fast_recovery = 1;
1757 /* if nothing was acked on this destination skip it */
1758 if (net->net_ack == 0) {
1759 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1760 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1764 #ifdef JANA_CMT_FAST_RECOVERY
1766 * CMT fast recovery code
1769 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1770 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1771 * } else if (sctp_cmt_on_off == 0 &&
1772 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1776 if (asoc->fast_retran_loss_recovery &&
1778 (asoc->sctp_cmt_on_off == 0)) {
1780 * If we are in loss recovery we skip any cwnd
1786 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1790 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1791 /* If the cumulative ack moved we can proceed */
1792 if (net->cwnd <= net->ssthresh) {
1793 /* We are in slow start */
1794 if (net->flight_size + net->net_ack >= net->cwnd) {
1796 sctp_hs_cwnd_increase(stcb, net);
1799 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1800 sctp_log_cwnd(stcb, net, net->net_ack,
1801 SCTP_CWND_LOG_NOADV_SS);
1805 /* We are in congestion avoidance */
1806 net->partial_bytes_acked += net->net_ack;
1807 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1808 (net->partial_bytes_acked >= net->cwnd)) {
1809 net->partial_bytes_acked -= net->cwnd;
1810 net->cwnd += net->mtu;
1811 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1812 sctp_log_cwnd(stcb, net, net->mtu,
1813 SCTP_CWND_LOG_FROM_CA);
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_CA);
1823 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1824 sctp_log_cwnd(stcb, net, net->mtu,
1825 SCTP_CWND_LOG_NO_CUMACK);
1833 * H-TCP congestion control. The algorithm is detailed in:
1834 * R.N.Shorten, D.J.Leith:
1835 * "H-TCP: TCP for high-speed and long-distance networks"
1836 * Proc. PFLDnet, Argonne, 2004.
1837 * http://www.hamilton.ie/net/htcp3.pdf
1841 static int use_rtt_scaling = 1;
1842 static int use_bandwidth_switch = 1;
1845 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1847 return (seq3 - seq2 >= seq1 - seq2);
1850 static inline uint32_t
1851 htcp_cong_time(struct htcp *ca)
1853 return (sctp_get_tick_count() - ca->last_cong);
1856 static inline uint32_t
1857 htcp_ccount(struct htcp *ca)
1859 return (htcp_cong_time(ca) / ca->minRTT);
1863 htcp_reset(struct htcp *ca)
1865 ca->undo_last_cong = ca->last_cong;
1866 ca->undo_maxRTT = ca->maxRTT;
1867 ca->undo_old_maxB = ca->old_maxB;
1868 ca->last_cong = sctp_get_tick_count();
1871 #ifdef SCTP_NOT_USED
1874 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1876 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1877 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1878 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1879 return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu));
1885 measure_rtt(struct sctp_nets *net)
1887 uint32_t srtt = net->lastsa >> SCTP_RTT_SHIFT;
1889 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1890 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1891 net->cc_mod.htcp_ca.minRTT = srtt;
1894 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1895 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
1896 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
1897 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1898 net->cc_mod.htcp_ca.maxRTT = srtt;
1903 measure_achieved_throughput(struct sctp_nets *net)
1905 uint32_t now = sctp_get_tick_count();
1907 if (net->fast_retran_ip == 0)
1908 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
1910 if (!use_bandwidth_switch)
1913 /* achieved throughput calculations */
1914 /* JRS - not 100% sure of this statement */
1915 if (net->fast_retran_ip == 1) {
1916 net->cc_mod.htcp_ca.bytecount = 0;
1917 net->cc_mod.htcp_ca.lasttime = now;
1920 net->cc_mod.htcp_ca.bytecount += net->net_ack;
1922 if (net->cc_mod.htcp_ca.bytecount >= net->cwnd - ((net->cc_mod.htcp_ca.alpha >> 7 ? : 1) * net->mtu)
1923 && now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT
1924 && net->cc_mod.htcp_ca.minRTT > 0) {
1925 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount / net->mtu * hz / (now - net->cc_mod.htcp_ca.lasttime);
1927 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
1928 /* just after backoff */
1929 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
1931 net->cc_mod.htcp_ca.Bi = (3 * net->cc_mod.htcp_ca.Bi + cur_Bi) / 4;
1932 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
1933 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
1934 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
1935 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
1937 net->cc_mod.htcp_ca.bytecount = 0;
1938 net->cc_mod.htcp_ca.lasttime = now;
1943 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1945 if (use_bandwidth_switch) {
1946 uint32_t maxB = ca->maxB;
1947 uint32_t old_maxB = ca->old_maxB;
1949 ca->old_maxB = ca->maxB;
1951 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1952 ca->beta = BETA_MIN;
1957 if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) {
1958 ca->beta = (minRTT << 7) / maxRTT;
1959 if (ca->beta < BETA_MIN)
1960 ca->beta = BETA_MIN;
1961 else if (ca->beta > BETA_MAX)
1962 ca->beta = BETA_MAX;
1964 ca->beta = BETA_MIN;
1970 htcp_alpha_update(struct htcp *ca)
1972 uint32_t minRTT = ca->minRTT;
1973 uint32_t factor = 1;
1974 uint32_t diff = htcp_cong_time(ca);
1976 if (diff > (uint32_t) hz) {
1978 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1980 if (use_rtt_scaling && minRTT) {
1981 uint32_t scale = (hz << 3) / (10 * minRTT);
1983 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1984 * interval [0.5,10]<<3 */
1985 factor = (factor << 3) / scale;
1989 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
1991 ca->alpha = ALPHA_BASE;
1994 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
1995 * rtt before we adjust our beta to ensure we are working from a consistent
1998 * This function should be called when we hit a congestion event since only at
1999 * that point do we really have a real sense of maxRTT (the queues en route
2000 * were getting just too full now).
2003 htcp_param_update(struct sctp_nets *net)
2005 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2006 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2008 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2009 htcp_alpha_update(&net->cc_mod.htcp_ca);
2012 * add slowly fading memory for maxRTT to accommodate routing
2015 if (minRTT > 0 && maxRTT > minRTT)
2016 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
2020 htcp_recalc_ssthresh(struct sctp_nets *net)
2022 htcp_param_update(net);
2023 return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu));
2027 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2030 * How to handle these functions?
2031 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2034 if (net->cwnd <= net->ssthresh) {
2035 /* We are in slow start */
2036 if (net->flight_size + net->net_ack >= net->cwnd) {
2037 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2038 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2039 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2040 sctp_log_cwnd(stcb, net, net->mtu,
2041 SCTP_CWND_LOG_FROM_SS);
2044 net->cwnd += net->net_ack;
2045 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2046 sctp_log_cwnd(stcb, net, net->net_ack,
2047 SCTP_CWND_LOG_FROM_SS);
2051 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2052 sctp_log_cwnd(stcb, net, net->net_ack,
2053 SCTP_CWND_LOG_NOADV_SS);
2060 * In dangerous area, increase slowly. In theory this is
2061 * net->cwnd += alpha / net->cwnd
2063 /* What is snd_cwnd_cnt?? */
2064 if (((net->partial_bytes_acked / net->mtu * net->cc_mod.htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
2066 * Does SCTP have a cwnd clamp?
2067 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2069 net->cwnd += net->mtu;
2070 net->partial_bytes_acked = 0;
2071 htcp_alpha_update(&net->cc_mod.htcp_ca);
2072 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2073 sctp_log_cwnd(stcb, net, net->mtu,
2074 SCTP_CWND_LOG_FROM_CA);
2077 net->partial_bytes_acked += net->net_ack;
2078 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2079 sctp_log_cwnd(stcb, net, net->net_ack,
2080 SCTP_CWND_LOG_NOADV_CA);
2084 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2088 #ifdef SCTP_NOT_USED
2089 /* Lower bound on congestion window. */
2091 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2093 return (net->ssthresh);
2099 htcp_init(struct sctp_nets *net)
2101 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2102 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2103 net->cc_mod.htcp_ca.beta = BETA_MIN;
2104 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2105 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2109 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2112 * We take the max of the burst limit times a MTU or the
2113 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2115 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2116 net->ssthresh = stcb->asoc.peers_rwnd;
2119 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
2120 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2125 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2126 struct sctp_association *asoc,
2127 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2129 struct sctp_nets *net;
2131 /******************************/
2132 /* update cwnd and Early FR */
2133 /******************************/
2134 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2136 #ifdef JANA_CMT_FAST_RECOVERY
2138 * CMT fast recovery code. Need to debug.
2140 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2141 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2142 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
2143 net->will_exit_fast_recovery = 1;
2147 /* if nothing was acked on this destination skip it */
2148 if (net->net_ack == 0) {
2149 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2150 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2154 #ifdef JANA_CMT_FAST_RECOVERY
2156 * CMT fast recovery code
2159 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
2160 * && net->will_exit_fast_recovery == 0) { @@@ Do something
2161 * } else if (sctp_cmt_on_off == 0 &&
2162 * asoc->fast_retran_loss_recovery && will_exit == 0) {
2166 if (asoc->fast_retran_loss_recovery &&
2168 (asoc->sctp_cmt_on_off == 0)) {
2170 * If we are in loss recovery we skip any cwnd
2176 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2180 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2181 htcp_cong_avoid(stcb, net);
2182 measure_achieved_throughput(net);
2184 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2185 sctp_log_cwnd(stcb, net, net->mtu,
2186 SCTP_CWND_LOG_NO_CUMACK);
2193 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2194 struct sctp_association *asoc)
2196 struct sctp_nets *net;
2199 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2200 * (net->fast_retran_loss_recovery == 0)))
2202 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2203 if ((asoc->fast_retran_loss_recovery == 0) ||
2204 (asoc->sctp_cmt_on_off > 0)) {
2205 /* out of a RFC2582 Fast recovery window? */
2206 if (net->net_ack > 0) {
2208 * per section 7.2.3, are there any
2209 * destinations that had a fast retransmit
2210 * to them. If so what we need to do is
2211 * adjust ssthresh and cwnd.
2213 struct sctp_tmit_chunk *lchk;
2214 int old_cwnd = net->cwnd;
2216 /* JRS - reset as if state were changed */
2217 htcp_reset(&net->cc_mod.htcp_ca);
2218 net->ssthresh = htcp_recalc_ssthresh(net);
2219 net->cwnd = net->ssthresh;
2220 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2221 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2222 SCTP_CWND_LOG_FROM_FR);
2224 lchk = TAILQ_FIRST(&asoc->send_queue);
2226 net->partial_bytes_acked = 0;
2227 /* Turn on fast recovery window */
2228 asoc->fast_retran_loss_recovery = 1;
2230 /* Mark end of the window */
2231 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2233 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
2237 * CMT fast recovery -- per destination
2238 * recovery variable.
2240 net->fast_retran_loss_recovery = 1;
2243 /* Mark end of the window */
2244 net->fast_recovery_tsn = asoc->sending_seq - 1;
2246 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
2249 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2250 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
2251 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2252 stcb->sctp_ep, stcb, net);
2254 } else if (net->net_ack > 0) {
2256 * Mark a peg that we WOULD have done a cwnd
2257 * reduction but RFC2582 prevented this action.
2259 SCTP_STAT_INCR(sctps_fastretransinrtt);
2265 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2266 struct sctp_nets *net)
2268 int old_cwnd = net->cwnd;
2270 /* JRS - reset as if the state were being changed to timeout */
2271 htcp_reset(&net->cc_mod.htcp_ca);
2272 net->ssthresh = htcp_recalc_ssthresh(net);
2273 net->cwnd = net->mtu;
2274 net->partial_bytes_acked = 0;
2275 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2276 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2281 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2282 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2286 old_cwnd = net->cwnd;
2288 /* JRS - reset hctp as if state changed */
2289 if (in_window == 0) {
2290 htcp_reset(&net->cc_mod.htcp_ca);
2291 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2292 net->ssthresh = htcp_recalc_ssthresh(net);
2293 if (net->ssthresh < net->mtu) {
2294 net->ssthresh = net->mtu;
2295 /* here back off the timer as well, to slow us down */
2298 net->cwnd = net->ssthresh;
2299 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2300 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2305 struct sctp_cc_functions sctp_cc_functions[] = {
2307 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2308 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2309 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2310 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2311 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2312 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2313 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2314 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2317 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2318 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2319 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2320 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2321 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2322 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2323 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2324 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2327 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2328 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2329 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2330 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2331 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2332 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2333 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2334 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2337 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2338 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2339 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2340 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2341 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2342 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2343 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2344 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2345 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2346 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2347 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2348 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2349 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2350 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated