2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 #include <netinet/sctp_os.h>
32 #include <netinet/sctp_var.h>
33 #include <netinet/sctp_sysctl.h>
34 #include <netinet/sctp_pcb.h>
35 #include <netinet/sctp_header.h>
36 #include <netinet/sctputil.h>
37 #include <netinet/sctp_output.h>
38 #include <netinet/sctp_input.h>
39 #include <netinet/sctp_indata.h>
40 #include <netinet/sctp_uio.h>
41 #include <netinet/sctp_timer.h>
42 #include <netinet/sctp_auth.h>
43 #include <netinet/sctp_asconf.h>
44 #include <netinet/sctp_dtrace_declare.h>
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
49 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
51 struct sctp_association *assoc;
55 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
56 if (cwnd_in_mtu == 0) {
57 /* Using 0 means that the value of RFC 4960 is used. */
58 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
61 * We take the minimum of the burst limit and the initial
64 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
65 cwnd_in_mtu = assoc->max_burst;
66 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
68 if (stcb->asoc.sctp_cmt_on_off == 2) {
69 /* In case of resource pooling initialize appropriately */
70 net->cwnd /= assoc->numnets;
71 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
72 net->cwnd = net->mtu - sizeof(struct sctphdr);
75 net->ssthresh = assoc->peers_rwnd;
77 SDT_PROBE(sctp, cwnd, net, init,
78 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
80 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
81 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
82 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
87 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
88 struct sctp_association *asoc)
90 struct sctp_nets *net;
91 uint32_t t_ssthresh, t_cwnd;
93 /* MT FIXME: Don't compute this over and over again */
96 if (asoc->sctp_cmt_on_off == 2) {
97 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
98 t_ssthresh += net->ssthresh;
103 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
104 * (net->fast_retran_loss_recovery == 0)))
106 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
107 if ((asoc->fast_retran_loss_recovery == 0) ||
108 (asoc->sctp_cmt_on_off > 0)) {
109 /* out of a RFC2582 Fast recovery window? */
110 if (net->net_ack > 0) {
112 * per section 7.2.3, are there any
113 * destinations that had a fast retransmit
114 * to them. If so what we need to do is
115 * adjust ssthresh and cwnd.
117 struct sctp_tmit_chunk *lchk;
118 int old_cwnd = net->cwnd;
120 if (asoc->sctp_cmt_on_off == 2) {
121 net->ssthresh = (uint32_t) (((uint64_t) 4 *
122 (uint64_t) net->mtu *
123 (uint64_t) net->ssthresh) /
124 (uint64_t) t_ssthresh);
125 if ((net->cwnd > t_cwnd / 2) &&
126 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
127 net->ssthresh = net->cwnd - t_cwnd / 2;
129 if (net->ssthresh < net->mtu) {
130 net->ssthresh = net->mtu;
133 net->ssthresh = net->cwnd / 2;
134 if (net->ssthresh < (net->mtu * 2)) {
135 net->ssthresh = 2 * net->mtu;
138 net->cwnd = net->ssthresh;
139 SDT_PROBE(sctp, cwnd, net, fr,
140 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
141 old_cwnd, net->cwnd);
142 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
143 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
144 SCTP_CWND_LOG_FROM_FR);
146 lchk = TAILQ_FIRST(&asoc->send_queue);
148 net->partial_bytes_acked = 0;
149 /* Turn on fast recovery window */
150 asoc->fast_retran_loss_recovery = 1;
152 /* Mark end of the window */
153 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
155 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
159 * CMT fast recovery -- per destination
162 net->fast_retran_loss_recovery = 1;
165 /* Mark end of the window */
166 net->fast_recovery_tsn = asoc->sending_seq - 1;
168 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
172 * Disable Nonce Sum Checking and store the
175 asoc->nonce_sum_check = 0;
176 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
178 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
179 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
180 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
181 stcb->sctp_ep, stcb, net);
183 } else if (net->net_ack > 0) {
185 * Mark a peg that we WOULD have done a cwnd
186 * reduction but RFC2582 prevented this action.
188 SCTP_STAT_INCR(sctps_fastretransinrtt);
194 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
195 struct sctp_association *asoc,
196 int accum_moved, int reneged_all, int will_exit)
198 struct sctp_nets *net;
200 uint32_t t_ssthresh, t_cwnd, incr;
202 /* MT FIXME: Don't compute this over and over again */
205 if (stcb->asoc.sctp_cmt_on_off == 2) {
206 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
207 t_ssthresh += net->ssthresh;
211 /******************************/
212 /* update cwnd and Early FR */
213 /******************************/
214 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
216 #ifdef JANA_CMT_FAST_RECOVERY
218 * CMT fast recovery code. Need to debug.
220 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
221 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
222 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
223 net->will_exit_fast_recovery = 1;
227 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
229 * So, first of all do we need to have a Early FR
232 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
233 (net->ref_count > 1) &&
234 (net->flight_size < net->cwnd)) ||
237 * yes, so in this case stop it if its
238 * running, and then restart it. Reneging
239 * all is a special case where we want to
240 * run the Early FR timer and then force the
241 * last few unacked to be sent, causing us
242 * to illicit a sack with gaps to force out
245 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
246 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
247 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
248 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
250 SCTP_STAT_INCR(sctps_earlyfrstrid);
251 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
253 /* No, stop it if its running */
254 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
255 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
256 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
257 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
261 /* if nothing was acked on this destination skip it */
262 if (net->net_ack == 0) {
263 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
264 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
268 if (net->net_ack2 > 0) {
270 * Karn's rule applies to clearing error count, this
273 net->error_count = 0;
274 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
275 SCTP_ADDR_NOT_REACHABLE) {
277 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
278 net->dest_state |= SCTP_ADDR_REACHABLE;
279 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
280 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
281 /* now was it the primary? if so restore */
282 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
283 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
287 * JRS 5/14/07 - If CMT PF is on and the destination
288 * is in PF state, set the destination to active
289 * state and set the cwnd to one or two MTU's based
290 * on whether PF1 or PF2 is being used.
292 * Should we stop any running T3 timer here?
294 if ((asoc->sctp_cmt_on_off > 0) &&
295 (asoc->sctp_cmt_pf > 0) &&
296 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
297 net->dest_state &= ~SCTP_ADDR_PF;
298 old_cwnd = net->cwnd;
299 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
300 SDT_PROBE(sctp, cwnd, net, ack,
301 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
302 old_cwnd, net->cwnd);
303 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
306 * Since the cwnd value is explicitly set,
307 * skip the code that updates the cwnd
310 goto skip_cwnd_update;
313 #ifdef JANA_CMT_FAST_RECOVERY
315 * CMT fast recovery code
318 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
319 * && net->will_exit_fast_recovery == 0) { @@@ Do something
320 * } else if (sctp_cmt_on_off == 0 &&
321 * asoc->fast_retran_loss_recovery && will_exit == 0) {
325 if (asoc->fast_retran_loss_recovery &&
327 (asoc->sctp_cmt_on_off == 0)) {
329 * If we are in loss recovery we skip any cwnd
332 goto skip_cwnd_update;
335 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
339 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
340 /* If the cumulative ack moved we can proceed */
341 if (net->cwnd <= net->ssthresh) {
342 /* We are in slow start */
343 if (net->flight_size + net->net_ack >= net->cwnd) {
344 old_cwnd = net->cwnd;
345 if (stcb->asoc.sctp_cmt_on_off == 2) {
348 limit = (uint32_t) (((uint64_t) net->mtu *
349 (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
350 (uint64_t) net->ssthresh) /
351 (uint64_t) t_ssthresh);
352 incr = (uint32_t) (((uint64_t) net->net_ack *
353 (uint64_t) net->ssthresh) /
354 (uint64_t) t_ssthresh);
363 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
364 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
368 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
369 sctp_log_cwnd(stcb, net, incr,
370 SCTP_CWND_LOG_FROM_SS);
372 SDT_PROBE(sctp, cwnd, net, ack,
374 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
376 old_cwnd, net->cwnd);
378 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
379 sctp_log_cwnd(stcb, net, net->net_ack,
380 SCTP_CWND_LOG_NOADV_SS);
384 /* We are in congestion avoidance */
390 net->partial_bytes_acked += net->net_ack;
392 if ((net->flight_size + net->net_ack >= net->cwnd) &&
393 (net->partial_bytes_acked >= net->cwnd)) {
394 net->partial_bytes_acked -= net->cwnd;
395 old_cwnd = net->cwnd;
396 if (asoc->sctp_cmt_on_off == 2) {
397 incr = (uint32_t) (((uint64_t) net->mtu *
398 (uint64_t) net->ssthresh) /
399 (uint64_t) t_ssthresh);
407 SDT_PROBE(sctp, cwnd, net, ack,
409 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
411 old_cwnd, net->cwnd);
412 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
413 sctp_log_cwnd(stcb, net, net->mtu,
414 SCTP_CWND_LOG_FROM_CA);
417 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
418 sctp_log_cwnd(stcb, net, net->net_ack,
419 SCTP_CWND_LOG_NOADV_CA);
424 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
425 sctp_log_cwnd(stcb, net, net->mtu,
426 SCTP_CWND_LOG_NO_CUMACK);
431 * NOW, according to Karn's rule do we need to restore the
432 * RTO timer back? Check our net_ack2. If not set then we
433 * have a ambiguity.. i.e. all data ack'd was sent to more
437 /* restore any doubled timers */
438 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
439 if (net->RTO < stcb->asoc.minrto) {
440 net->RTO = stcb->asoc.minrto;
442 if (net->RTO > stcb->asoc.maxrto) {
443 net->RTO = stcb->asoc.maxrto;
450 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
452 int old_cwnd = net->cwnd;
453 uint32_t t_ssthresh, t_cwnd;
455 /* MT FIXME: Don't compute this over and over again */
458 if (stcb->asoc.sctp_cmt_on_off == 2) {
459 struct sctp_nets *lnet;
461 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
462 t_ssthresh += lnet->ssthresh;
463 t_cwnd += lnet->cwnd;
465 net->ssthresh = (uint32_t) (((uint64_t) 4 *
466 (uint64_t) net->mtu *
467 (uint64_t) net->ssthresh) /
468 (uint64_t) t_ssthresh);
469 if ((net->cwnd > t_cwnd / 2) &&
470 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
471 net->ssthresh = net->cwnd - t_cwnd / 2;
473 if (net->ssthresh < net->mtu) {
474 net->ssthresh = net->mtu;
477 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
479 net->cwnd = net->mtu;
480 net->partial_bytes_acked = 0;
481 SDT_PROBE(sctp, cwnd, net, to,
483 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
485 old_cwnd, net->cwnd);
486 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
487 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
492 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net)
494 int old_cwnd = net->cwnd;
496 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
497 net->ssthresh = net->cwnd / 2;
498 if (net->ssthresh < net->mtu) {
499 net->ssthresh = net->mtu;
500 /* here back off the timer as well, to slow us down */
503 net->cwnd = net->ssthresh;
504 SDT_PROBE(sctp, cwnd, net, ecn,
506 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
508 old_cwnd, net->cwnd);
509 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
510 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
515 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
516 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
517 uint32_t * bottle_bw, uint32_t * on_queue)
521 int old_cwnd = net->cwnd;
523 /* need real RTT for this calc */
524 rtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
525 /* get bottle neck bw */
526 *bottle_bw = ntohl(cp->bottle_bw);
527 /* and whats on queue */
528 *on_queue = ntohl(cp->current_onq);
530 * adjust the on-queue if our flight is more it could be that the
531 * router has not yet gotten data "in-flight" to it
533 if (*on_queue < net->flight_size)
534 *on_queue = net->flight_size;
535 /* calculate the available space */
536 bw_avail = (*bottle_bw * rtt) / 1000;
537 if (bw_avail > *bottle_bw) {
539 * Cap the growth to no more than the bottle neck. This can
540 * happen as RTT slides up due to queues. It also means if
541 * you have more than a 1 second RTT with a empty queue you
542 * will be limited to the bottle_bw per second no matter if
543 * other points have 1/2 the RTT and you could get more
546 bw_avail = *bottle_bw;
548 if (*on_queue > bw_avail) {
550 * No room for anything else don't allow anything else to be
551 * "added to the fire".
553 int seg_inflight, seg_onqueue, my_portion;
555 net->partial_bytes_acked = 0;
557 /* how much are we over queue size? */
558 incr = *on_queue - bw_avail;
559 if (stcb->asoc.seen_a_sack_this_pkt) {
561 * undo any cwnd adjustment that the sack might have
564 net->cwnd = net->prev_cwnd;
566 /* Now how much of that is mine? */
567 seg_inflight = net->flight_size / net->mtu;
568 seg_onqueue = *on_queue / net->mtu;
569 my_portion = (incr * seg_inflight) / seg_onqueue;
571 /* Have I made an adjustment already */
572 if (net->cwnd > net->flight_size) {
574 * for this flight I made an adjustment we need to
575 * decrease the portion by a share our previous
580 diff_adj = net->cwnd - net->flight_size;
581 if (diff_adj > my_portion)
584 my_portion -= diff_adj;
587 * back down to the previous cwnd (assume we have had a sack
588 * before this packet). minus what ever portion of the
589 * overage is my fault.
591 net->cwnd -= my_portion;
593 /* we will NOT back down more than 1 MTU */
594 if (net->cwnd <= net->mtu) {
595 net->cwnd = net->mtu;
598 net->ssthresh = net->cwnd - 1;
601 * Take 1/4 of the space left or max burst up .. whichever
604 incr = (bw_avail - *on_queue) >> 2;
605 if ((stcb->asoc.max_burst > 0) &&
606 (stcb->asoc.max_burst * net->mtu < incr)) {
607 incr = stcb->asoc.max_burst * net->mtu;
611 if (net->cwnd > bw_avail) {
612 /* We can't exceed the pipe size */
613 net->cwnd = bw_avail;
615 if (net->cwnd < net->mtu) {
616 /* We always have 1 MTU */
617 net->cwnd = net->mtu;
619 if (net->cwnd - old_cwnd != 0) {
620 /* log only changes */
621 SDT_PROBE(sctp, cwnd, net, pd,
623 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
625 old_cwnd, net->cwnd);
626 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
627 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
628 SCTP_CWND_LOG_FROM_SAT);
634 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
635 struct sctp_nets *net, int burst_limit)
637 int old_cwnd = net->cwnd;
639 if (net->ssthresh < net->cwnd)
640 net->ssthresh = net->cwnd;
641 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
642 SDT_PROBE(sctp, cwnd, net, bl,
644 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
646 old_cwnd, net->cwnd);
647 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
648 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
653 sctp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
654 struct sctp_tcb *stcb, struct sctp_nets *net)
656 int old_cwnd = net->cwnd;
658 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
660 * make a small adjustment to cwnd and force to CA.
662 if (net->cwnd > net->mtu)
663 /* drop down one MTU after sending */
664 net->cwnd -= net->mtu;
665 if (net->cwnd < net->ssthresh)
666 /* still in SS move to CA */
667 net->ssthresh = net->cwnd - 1;
668 SDT_PROBE(sctp, cwnd, net, fr,
670 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
672 old_cwnd, net->cwnd);
673 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
674 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
678 struct sctp_hs_raise_drop {
681 int32_t drop_percent;
684 #define SCTP_HS_TABLE_SIZE 73
686 struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
688 {118, 2, 44}, /* 1 */
689 {221, 3, 41}, /* 2 */
690 {347, 4, 38}, /* 3 */
691 {495, 5, 37}, /* 4 */
692 {663, 6, 35}, /* 5 */
693 {851, 7, 34}, /* 6 */
694 {1058, 8, 33}, /* 7 */
695 {1284, 9, 32}, /* 8 */
696 {1529, 10, 31}, /* 9 */
697 {1793, 11, 30}, /* 10 */
698 {2076, 12, 29}, /* 11 */
699 {2378, 13, 28}, /* 12 */
700 {2699, 14, 28}, /* 13 */
701 {3039, 15, 27}, /* 14 */
702 {3399, 16, 27}, /* 15 */
703 {3778, 17, 26}, /* 16 */
704 {4177, 18, 26}, /* 17 */
705 {4596, 19, 25}, /* 18 */
706 {5036, 20, 25}, /* 19 */
707 {5497, 21, 24}, /* 20 */
708 {5979, 22, 24}, /* 21 */
709 {6483, 23, 23}, /* 22 */
710 {7009, 24, 23}, /* 23 */
711 {7558, 25, 22}, /* 24 */
712 {8130, 26, 22}, /* 25 */
713 {8726, 27, 22}, /* 26 */
714 {9346, 28, 21}, /* 27 */
715 {9991, 29, 21}, /* 28 */
716 {10661, 30, 21}, /* 29 */
717 {11358, 31, 20}, /* 30 */
718 {12082, 32, 20}, /* 31 */
719 {12834, 33, 20}, /* 32 */
720 {13614, 34, 19}, /* 33 */
721 {14424, 35, 19}, /* 34 */
722 {15265, 36, 19}, /* 35 */
723 {16137, 37, 19}, /* 36 */
724 {17042, 38, 18}, /* 37 */
725 {17981, 39, 18}, /* 38 */
726 {18955, 40, 18}, /* 39 */
727 {19965, 41, 17}, /* 40 */
728 {21013, 42, 17}, /* 41 */
729 {22101, 43, 17}, /* 42 */
730 {23230, 44, 17}, /* 43 */
731 {24402, 45, 16}, /* 44 */
732 {25618, 46, 16}, /* 45 */
733 {26881, 47, 16}, /* 46 */
734 {28193, 48, 16}, /* 47 */
735 {29557, 49, 15}, /* 48 */
736 {30975, 50, 15}, /* 49 */
737 {32450, 51, 15}, /* 50 */
738 {33986, 52, 15}, /* 51 */
739 {35586, 53, 14}, /* 52 */
740 {37253, 54, 14}, /* 53 */
741 {38992, 55, 14}, /* 54 */
742 {40808, 56, 14}, /* 55 */
743 {42707, 57, 13}, /* 56 */
744 {44694, 58, 13}, /* 57 */
745 {46776, 59, 13}, /* 58 */
746 {48961, 60, 13}, /* 59 */
747 {51258, 61, 13}, /* 60 */
748 {53677, 62, 12}, /* 61 */
749 {56230, 63, 12}, /* 62 */
750 {58932, 64, 12}, /* 63 */
751 {61799, 65, 12}, /* 64 */
752 {64851, 66, 11}, /* 65 */
753 {68113, 67, 11}, /* 66 */
754 {71617, 68, 11}, /* 67 */
755 {75401, 69, 10}, /* 68 */
756 {79517, 70, 10}, /* 69 */
757 {84035, 71, 10}, /* 70 */
758 {89053, 72, 10}, /* 71 */
759 {94717, 73, 9} /* 72 */
763 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
765 int cur_val, i, indx, incr;
767 cur_val = net->cwnd >> 10;
768 indx = SCTP_HS_TABLE_SIZE - 1;
770 printf("HS CC CAlled.\n");
772 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
774 if (net->net_ack > net->mtu) {
775 net->cwnd += net->mtu;
776 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
777 sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS);
780 net->cwnd += net->net_ack;
781 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
782 sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
786 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
787 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
792 net->last_hs_used = indx;
793 incr = ((sctp_cwnd_adjust[indx].increase) << 10);
795 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
796 sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS);
802 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
804 int cur_val, i, indx;
805 int old_cwnd = net->cwnd;
807 cur_val = net->cwnd >> 10;
808 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
810 net->ssthresh = net->cwnd / 2;
811 if (net->ssthresh < (net->mtu * 2)) {
812 net->ssthresh = 2 * net->mtu;
814 net->cwnd = net->ssthresh;
816 /* drop by the proper amount */
817 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
818 sctp_cwnd_adjust[net->last_hs_used].drop_percent);
819 net->cwnd = net->ssthresh;
820 /* now where are we */
821 indx = net->last_hs_used;
822 cur_val = net->cwnd >> 10;
823 /* reset where we are in the table */
824 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
826 net->last_hs_used = 0;
828 for (i = indx; i >= 1; i--) {
829 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
833 net->last_hs_used = indx;
836 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
837 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
842 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
843 struct sctp_association *asoc)
845 struct sctp_nets *net;
848 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
849 * (net->fast_retran_loss_recovery == 0)))
851 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
852 if ((asoc->fast_retran_loss_recovery == 0) ||
853 (asoc->sctp_cmt_on_off > 0)) {
854 /* out of a RFC2582 Fast recovery window? */
855 if (net->net_ack > 0) {
857 * per section 7.2.3, are there any
858 * destinations that had a fast retransmit
859 * to them. If so what we need to do is
860 * adjust ssthresh and cwnd.
862 struct sctp_tmit_chunk *lchk;
864 sctp_hs_cwnd_decrease(stcb, net);
866 lchk = TAILQ_FIRST(&asoc->send_queue);
868 net->partial_bytes_acked = 0;
869 /* Turn on fast recovery window */
870 asoc->fast_retran_loss_recovery = 1;
872 /* Mark end of the window */
873 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
875 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
879 * CMT fast recovery -- per destination
882 net->fast_retran_loss_recovery = 1;
885 /* Mark end of the window */
886 net->fast_recovery_tsn = asoc->sending_seq - 1;
888 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
892 * Disable Nonce Sum Checking and store the
895 asoc->nonce_sum_check = 0;
896 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
898 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
899 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
900 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
901 stcb->sctp_ep, stcb, net);
903 } else if (net->net_ack > 0) {
905 * Mark a peg that we WOULD have done a cwnd
906 * reduction but RFC2582 prevented this action.
908 SCTP_STAT_INCR(sctps_fastretransinrtt);
914 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
915 struct sctp_association *asoc,
916 int accum_moved, int reneged_all, int will_exit)
918 struct sctp_nets *net;
920 /******************************/
921 /* update cwnd and Early FR */
922 /******************************/
923 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
925 #ifdef JANA_CMT_FAST_RECOVERY
927 * CMT fast recovery code. Need to debug.
929 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
930 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
931 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
932 net->will_exit_fast_recovery = 1;
936 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
938 * So, first of all do we need to have a Early FR
941 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
942 (net->ref_count > 1) &&
943 (net->flight_size < net->cwnd)) ||
946 * yes, so in this case stop it if its
947 * running, and then restart it. Reneging
948 * all is a special case where we want to
949 * run the Early FR timer and then force the
950 * last few unacked to be sent, causing us
951 * to illicit a sack with gaps to force out
954 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
955 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
956 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
957 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
959 SCTP_STAT_INCR(sctps_earlyfrstrid);
960 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
962 /* No, stop it if its running */
963 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
964 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
965 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
966 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
970 /* if nothing was acked on this destination skip it */
971 if (net->net_ack == 0) {
972 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
973 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
977 if (net->net_ack2 > 0) {
979 * Karn's rule applies to clearing error count, this
982 net->error_count = 0;
983 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
984 SCTP_ADDR_NOT_REACHABLE) {
986 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
987 net->dest_state |= SCTP_ADDR_REACHABLE;
988 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
989 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
990 /* now was it the primary? if so restore */
991 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
992 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
996 * JRS 5/14/07 - If CMT PF is on and the destination
997 * is in PF state, set the destination to active
998 * state and set the cwnd to one or two MTU's based
999 * on whether PF1 or PF2 is being used.
1001 * Should we stop any running T3 timer here?
1003 if ((asoc->sctp_cmt_on_off > 0) &&
1004 (asoc->sctp_cmt_pf > 0) &&
1005 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
1006 net->dest_state &= ~SCTP_ADDR_PF;
1007 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
1008 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1011 * Since the cwnd value is explicitly set,
1012 * skip the code that updates the cwnd
1015 goto skip_cwnd_update;
1018 #ifdef JANA_CMT_FAST_RECOVERY
1020 * CMT fast recovery code
1023 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1024 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1025 * } else if (sctp_cmt_on_off == 0 &&
1026 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1030 if (asoc->fast_retran_loss_recovery &&
1032 (asoc->sctp_cmt_on_off == 0)) {
1034 * If we are in loss recovery we skip any cwnd
1037 goto skip_cwnd_update;
1040 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1044 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1045 /* If the cumulative ack moved we can proceed */
1046 if (net->cwnd <= net->ssthresh) {
1047 /* We are in slow start */
1048 if (net->flight_size + net->net_ack >= net->cwnd) {
1050 sctp_hs_cwnd_increase(stcb, net);
1053 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1054 sctp_log_cwnd(stcb, net, net->net_ack,
1055 SCTP_CWND_LOG_NOADV_SS);
1059 /* We are in congestion avoidance */
1060 net->partial_bytes_acked += net->net_ack;
1061 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1062 (net->partial_bytes_acked >= net->cwnd)) {
1063 net->partial_bytes_acked -= net->cwnd;
1064 net->cwnd += net->mtu;
1065 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1066 sctp_log_cwnd(stcb, net, net->mtu,
1067 SCTP_CWND_LOG_FROM_CA);
1070 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1071 sctp_log_cwnd(stcb, net, net->net_ack,
1072 SCTP_CWND_LOG_NOADV_CA);
1077 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1078 sctp_log_cwnd(stcb, net, net->mtu,
1079 SCTP_CWND_LOG_NO_CUMACK);
1084 * NOW, according to Karn's rule do we need to restore the
1085 * RTO timer back? Check our net_ack2. If not set then we
1086 * have a ambiguity.. i.e. all data ack'd was sent to more
1089 if (net->net_ack2) {
1090 /* restore any doubled timers */
1091 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
1092 if (net->RTO < stcb->asoc.minrto) {
1093 net->RTO = stcb->asoc.minrto;
1095 if (net->RTO > stcb->asoc.maxrto) {
1096 net->RTO = stcb->asoc.maxrto;
1104 * H-TCP congestion control. The algorithm is detailed in:
1105 * R.N.Shorten, D.J.Leith:
1106 * "H-TCP: TCP for high-speed and long-distance networks"
1107 * Proc. PFLDnet, Argonne, 2004.
1108 * http://www.hamilton.ie/net/htcp3.pdf
1112 static int use_rtt_scaling = 1;
1113 static int use_bandwidth_switch = 1;
1116 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1118 return seq3 - seq2 >= seq1 - seq2;
1121 static inline uint32_t
1122 htcp_cong_time(struct htcp *ca)
1124 return sctp_get_tick_count() - ca->last_cong;
1127 static inline uint32_t
1128 htcp_ccount(struct htcp *ca)
1130 return htcp_cong_time(ca) / ca->minRTT;
1134 htcp_reset(struct htcp *ca)
1136 ca->undo_last_cong = ca->last_cong;
1137 ca->undo_maxRTT = ca->maxRTT;
1138 ca->undo_old_maxB = ca->old_maxB;
1139 ca->last_cong = sctp_get_tick_count();
1142 #ifdef SCTP_NOT_USED
1145 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1147 net->htcp_ca.last_cong = net->htcp_ca.undo_last_cong;
1148 net->htcp_ca.maxRTT = net->htcp_ca.undo_maxRTT;
1149 net->htcp_ca.old_maxB = net->htcp_ca.undo_old_maxB;
1150 return max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->htcp_ca.beta) * net->mtu);
1156 measure_rtt(struct sctp_tcb *stcb, struct sctp_nets *net)
1158 uint32_t srtt = net->lastsa >> 3;
1160 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1161 if (net->htcp_ca.minRTT > srtt || !net->htcp_ca.minRTT)
1162 net->htcp_ca.minRTT = srtt;
1165 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->htcp_ca) > 3) {
1166 if (net->htcp_ca.maxRTT < net->htcp_ca.minRTT)
1167 net->htcp_ca.maxRTT = net->htcp_ca.minRTT;
1168 if (net->htcp_ca.maxRTT < srtt && srtt <= net->htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1169 net->htcp_ca.maxRTT = srtt;
1174 measure_achieved_throughput(struct sctp_tcb *stcb, struct sctp_nets *net)
1176 uint32_t now = sctp_get_tick_count();
1178 if (net->fast_retran_ip == 0)
1179 net->htcp_ca.bytes_acked = net->net_ack;
1181 if (!use_bandwidth_switch)
1184 /* achieved throughput calculations */
1185 /* JRS - not 100% sure of this statement */
1186 if (net->fast_retran_ip == 1) {
1187 net->htcp_ca.bytecount = 0;
1188 net->htcp_ca.lasttime = now;
1191 net->htcp_ca.bytecount += net->net_ack;
1193 if (net->htcp_ca.bytecount >= net->cwnd - ((net->htcp_ca.alpha >> 7 ? : 1) * net->mtu)
1194 && now - net->htcp_ca.lasttime >= net->htcp_ca.minRTT
1195 && net->htcp_ca.minRTT > 0) {
1196 uint32_t cur_Bi = net->htcp_ca.bytecount / net->mtu * hz / (now - net->htcp_ca.lasttime);
1198 if (htcp_ccount(&net->htcp_ca) <= 3) {
1199 /* just after backoff */
1200 net->htcp_ca.minB = net->htcp_ca.maxB = net->htcp_ca.Bi = cur_Bi;
1202 net->htcp_ca.Bi = (3 * net->htcp_ca.Bi + cur_Bi) / 4;
1203 if (net->htcp_ca.Bi > net->htcp_ca.maxB)
1204 net->htcp_ca.maxB = net->htcp_ca.Bi;
1205 if (net->htcp_ca.minB > net->htcp_ca.maxB)
1206 net->htcp_ca.minB = net->htcp_ca.maxB;
1208 net->htcp_ca.bytecount = 0;
1209 net->htcp_ca.lasttime = now;
1214 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1216 if (use_bandwidth_switch) {
1217 uint32_t maxB = ca->maxB;
1218 uint32_t old_maxB = ca->old_maxB;
1220 ca->old_maxB = ca->maxB;
1222 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1223 ca->beta = BETA_MIN;
1228 if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) {
1229 ca->beta = (minRTT << 7) / maxRTT;
1230 if (ca->beta < BETA_MIN)
1231 ca->beta = BETA_MIN;
1232 else if (ca->beta > BETA_MAX)
1233 ca->beta = BETA_MAX;
1235 ca->beta = BETA_MIN;
1241 htcp_alpha_update(struct htcp *ca)
1243 uint32_t minRTT = ca->minRTT;
1244 uint32_t factor = 1;
1245 uint32_t diff = htcp_cong_time(ca);
1247 if (diff > (uint32_t) hz) {
1249 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1251 if (use_rtt_scaling && minRTT) {
1252 uint32_t scale = (hz << 3) / (10 * minRTT);
1254 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1255 * interval [0.5,10]<<3 */
1256 factor = (factor << 3) / scale;
1260 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
1262 ca->alpha = ALPHA_BASE;
1265 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
1266 * rtt before we adjust our beta to ensure we are working from a consistent
1269 * This function should be called when we hit a congestion event since only at
1270 * that point do we really have a real sense of maxRTT (the queues en route
1271 * were getting just too full now).
1274 htcp_param_update(struct sctp_tcb *stcb, struct sctp_nets *net)
1276 uint32_t minRTT = net->htcp_ca.minRTT;
1277 uint32_t maxRTT = net->htcp_ca.maxRTT;
1279 htcp_beta_update(&net->htcp_ca, minRTT, maxRTT);
1280 htcp_alpha_update(&net->htcp_ca);
1283 * add slowly fading memory for maxRTT to accommodate routing
1286 if (minRTT > 0 && maxRTT > minRTT)
1287 net->htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
1291 htcp_recalc_ssthresh(struct sctp_tcb *stcb, struct sctp_nets *net)
1293 htcp_param_update(stcb, net);
1294 return max(((net->cwnd / net->mtu * net->htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu);
1298 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
1301 * How to handle these functions?
1302 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
1305 if (net->cwnd <= net->ssthresh) {
1306 /* We are in slow start */
1307 if (net->flight_size + net->net_ack >= net->cwnd) {
1308 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
1309 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
1310 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1311 sctp_log_cwnd(stcb, net, net->mtu,
1312 SCTP_CWND_LOG_FROM_SS);
1315 net->cwnd += net->net_ack;
1316 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1317 sctp_log_cwnd(stcb, net, net->net_ack,
1318 SCTP_CWND_LOG_FROM_SS);
1322 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1323 sctp_log_cwnd(stcb, net, net->net_ack,
1324 SCTP_CWND_LOG_NOADV_SS);
1328 measure_rtt(stcb, net);
1331 * In dangerous area, increase slowly. In theory this is
1332 * net->cwnd += alpha / net->cwnd
1334 /* What is snd_cwnd_cnt?? */
1335 if (((net->partial_bytes_acked / net->mtu * net->htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
1337 * Does SCTP have a cwnd clamp?
1338 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
1340 net->cwnd += net->mtu;
1341 net->partial_bytes_acked = 0;
1342 htcp_alpha_update(&net->htcp_ca);
1343 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1344 sctp_log_cwnd(stcb, net, net->mtu,
1345 SCTP_CWND_LOG_FROM_CA);
1348 net->partial_bytes_acked += net->net_ack;
1349 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1350 sctp_log_cwnd(stcb, net, net->net_ack,
1351 SCTP_CWND_LOG_NOADV_CA);
1355 net->htcp_ca.bytes_acked = net->mtu;
1359 #ifdef SCTP_NOT_USED
1360 /* Lower bound on congestion window. */
1362 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
1364 return net->ssthresh;
1370 htcp_init(struct sctp_tcb *stcb, struct sctp_nets *net)
1372 memset(&net->htcp_ca, 0, sizeof(struct htcp));
1373 net->htcp_ca.alpha = ALPHA_BASE;
1374 net->htcp_ca.beta = BETA_MIN;
1375 net->htcp_ca.bytes_acked = net->mtu;
1376 net->htcp_ca.last_cong = sctp_get_tick_count();
1380 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
1383 * We take the max of the burst limit times a MTU or the
1384 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
1386 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1387 net->ssthresh = stcb->asoc.peers_rwnd;
1388 htcp_init(stcb, net);
1390 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
1391 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
1396 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1397 struct sctp_association *asoc,
1398 int accum_moved, int reneged_all, int will_exit)
1400 struct sctp_nets *net;
1402 /******************************/
1403 /* update cwnd and Early FR */
1404 /******************************/
1405 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1407 #ifdef JANA_CMT_FAST_RECOVERY
1409 * CMT fast recovery code. Need to debug.
1411 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1412 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1413 SCTP_TSN_GE(net->pseudo_cumack, net->fast_recovery_tsn)) {
1414 net->will_exit_fast_recovery = 1;
1418 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
1420 * So, first of all do we need to have a Early FR
1423 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
1424 (net->ref_count > 1) &&
1425 (net->flight_size < net->cwnd)) ||
1428 * yes, so in this case stop it if its
1429 * running, and then restart it. Reneging
1430 * all is a special case where we want to
1431 * run the Early FR timer and then force the
1432 * last few unacked to be sent, causing us
1433 * to illicit a sack with gaps to force out
1436 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1437 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
1438 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1439 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
1441 SCTP_STAT_INCR(sctps_earlyfrstrid);
1442 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
1444 /* No, stop it if its running */
1445 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1446 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
1447 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1448 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
1452 /* if nothing was acked on this destination skip it */
1453 if (net->net_ack == 0) {
1454 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1455 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1459 if (net->net_ack2 > 0) {
1461 * Karn's rule applies to clearing error count, this
1464 net->error_count = 0;
1465 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
1466 SCTP_ADDR_NOT_REACHABLE) {
1467 /* addr came good */
1468 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
1469 net->dest_state |= SCTP_ADDR_REACHABLE;
1470 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
1471 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
1472 /* now was it the primary? if so restore */
1473 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
1474 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
1478 * JRS 5/14/07 - If CMT PF is on and the destination
1479 * is in PF state, set the destination to active
1480 * state and set the cwnd to one or two MTU's based
1481 * on whether PF1 or PF2 is being used.
1483 * Should we stop any running T3 timer here?
1485 if ((asoc->sctp_cmt_on_off > 0) &&
1486 (asoc->sctp_cmt_pf > 0) &&
1487 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
1488 net->dest_state &= ~SCTP_ADDR_PF;
1489 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
1490 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1493 * Since the cwnd value is explicitly set,
1494 * skip the code that updates the cwnd
1497 goto skip_cwnd_update;
1500 #ifdef JANA_CMT_FAST_RECOVERY
1502 * CMT fast recovery code
1505 * if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery
1506 * && net->will_exit_fast_recovery == 0) { @@@ Do something
1507 * } else if (sctp_cmt_on_off == 0 &&
1508 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1512 if (asoc->fast_retran_loss_recovery &&
1514 (asoc->sctp_cmt_on_off == 0)) {
1516 * If we are in loss recovery we skip any cwnd
1519 goto skip_cwnd_update;
1522 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1526 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1527 htcp_cong_avoid(stcb, net);
1528 measure_achieved_throughput(stcb, net);
1530 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1531 sctp_log_cwnd(stcb, net, net->mtu,
1532 SCTP_CWND_LOG_NO_CUMACK);
1537 * NOW, according to Karn's rule do we need to restore the
1538 * RTO timer back? Check our net_ack2. If not set then we
1539 * have a ambiguity.. i.e. all data ack'd was sent to more
1542 if (net->net_ack2) {
1543 /* restore any doubled timers */
1544 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
1545 if (net->RTO < stcb->asoc.minrto) {
1546 net->RTO = stcb->asoc.minrto;
1548 if (net->RTO > stcb->asoc.maxrto) {
1549 net->RTO = stcb->asoc.maxrto;
1556 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
1557 struct sctp_association *asoc)
1559 struct sctp_nets *net;
1562 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1563 * (net->fast_retran_loss_recovery == 0)))
1565 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1566 if ((asoc->fast_retran_loss_recovery == 0) ||
1567 (asoc->sctp_cmt_on_off > 0)) {
1568 /* out of a RFC2582 Fast recovery window? */
1569 if (net->net_ack > 0) {
1571 * per section 7.2.3, are there any
1572 * destinations that had a fast retransmit
1573 * to them. If so what we need to do is
1574 * adjust ssthresh and cwnd.
1576 struct sctp_tmit_chunk *lchk;
1577 int old_cwnd = net->cwnd;
1579 /* JRS - reset as if state were changed */
1580 htcp_reset(&net->htcp_ca);
1581 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1582 net->cwnd = net->ssthresh;
1583 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1584 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1585 SCTP_CWND_LOG_FROM_FR);
1587 lchk = TAILQ_FIRST(&asoc->send_queue);
1589 net->partial_bytes_acked = 0;
1590 /* Turn on fast recovery window */
1591 asoc->fast_retran_loss_recovery = 1;
1593 /* Mark end of the window */
1594 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1596 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1600 * CMT fast recovery -- per destination
1601 * recovery variable.
1603 net->fast_retran_loss_recovery = 1;
1606 /* Mark end of the window */
1607 net->fast_recovery_tsn = asoc->sending_seq - 1;
1609 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1613 * Disable Nonce Sum Checking and store the
1616 asoc->nonce_sum_check = 0;
1617 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
1619 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1620 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
1621 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1622 stcb->sctp_ep, stcb, net);
1624 } else if (net->net_ack > 0) {
1626 * Mark a peg that we WOULD have done a cwnd
1627 * reduction but RFC2582 prevented this action.
1629 SCTP_STAT_INCR(sctps_fastretransinrtt);
1635 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
1636 struct sctp_nets *net)
1638 int old_cwnd = net->cwnd;
1640 /* JRS - reset as if the state were being changed to timeout */
1641 htcp_reset(&net->htcp_ca);
1642 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1643 net->cwnd = net->mtu;
1644 net->partial_bytes_acked = 0;
1645 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1646 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1651 sctp_htcp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
1652 struct sctp_tcb *stcb, struct sctp_nets *net)
1656 old_cwnd = net->cwnd;
1658 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
1659 net->htcp_ca.last_cong = sctp_get_tick_count();
1661 * make a small adjustment to cwnd and force to CA.
1663 if (net->cwnd > net->mtu)
1664 /* drop down one MTU after sending */
1665 net->cwnd -= net->mtu;
1666 if (net->cwnd < net->ssthresh)
1667 /* still in SS move to CA */
1668 net->ssthresh = net->cwnd - 1;
1669 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1670 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
1675 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
1676 struct sctp_nets *net)
1680 old_cwnd = net->cwnd;
1682 /* JRS - reset hctp as if state changed */
1683 htcp_reset(&net->htcp_ca);
1684 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1685 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1686 if (net->ssthresh < net->mtu) {
1687 net->ssthresh = net->mtu;
1688 /* here back off the timer as well, to slow us down */
1691 net->cwnd = net->ssthresh;
1692 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1693 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1697 struct sctp_cc_functions sctp_cc_functions[] = {
1699 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
1700 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
1701 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
1702 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
1703 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
1704 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
1705 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
1706 .sctp_cwnd_update_after_fr_timer = sctp_cwnd_update_after_fr_timer
1709 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
1710 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
1711 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
1712 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
1713 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
1714 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
1715 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
1716 .sctp_cwnd_update_after_fr_timer = sctp_cwnd_update_after_fr_timer
1719 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
1720 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
1721 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
1722 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
1723 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
1724 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
1725 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
1726 .sctp_cwnd_update_after_fr_timer = sctp_htcp_cwnd_update_after_fr_timer