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_cc_functions.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;
56 * We take the minimum of the burst limit and the initial congestion
57 * window. The initial congestion window is at least two times the
60 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
61 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
62 cwnd_in_mtu = assoc->max_burst;
63 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
64 net->ssthresh = assoc->peers_rwnd;
66 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
67 (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
68 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
73 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
74 struct sctp_association *asoc)
76 struct sctp_nets *net;
79 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
80 * (net->fast_retran_loss_recovery == 0)))
82 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
83 if ((asoc->fast_retran_loss_recovery == 0) ||
84 (asoc->sctp_cmt_on_off == 1)) {
85 /* out of a RFC2582 Fast recovery window? */
86 if (net->net_ack > 0) {
88 * per section 7.2.3, are there any
89 * destinations that had a fast retransmit
90 * to them. If so what we need to do is
91 * adjust ssthresh and cwnd.
93 struct sctp_tmit_chunk *lchk;
94 int old_cwnd = net->cwnd;
96 net->ssthresh = net->cwnd / 2;
97 if (net->ssthresh < (net->mtu * 2)) {
98 net->ssthresh = 2 * net->mtu;
100 net->cwnd = net->ssthresh;
101 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
102 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
103 SCTP_CWND_LOG_FROM_FR);
105 lchk = TAILQ_FIRST(&asoc->send_queue);
107 net->partial_bytes_acked = 0;
108 /* Turn on fast recovery window */
109 asoc->fast_retran_loss_recovery = 1;
111 /* Mark end of the window */
112 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
114 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
118 * CMT fast recovery -- per destination
121 net->fast_retran_loss_recovery = 1;
124 /* Mark end of the window */
125 net->fast_recovery_tsn = asoc->sending_seq - 1;
127 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
131 * Disable Nonce Sum Checking and store the
134 asoc->nonce_sum_check = 0;
135 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
137 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
138 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
139 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
140 stcb->sctp_ep, stcb, net);
142 } else if (net->net_ack > 0) {
144 * Mark a peg that we WOULD have done a cwnd
145 * reduction but RFC2582 prevented this action.
147 SCTP_STAT_INCR(sctps_fastretransinrtt);
153 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
154 struct sctp_association *asoc,
155 int accum_moved, int reneged_all, int will_exit)
157 struct sctp_nets *net;
159 /******************************/
160 /* update cwnd and Early FR */
161 /******************************/
162 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
164 #ifdef JANA_CMT_FAST_RECOVERY
166 * CMT fast recovery code. Need to debug.
168 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
169 if (compare_with_wrap(asoc->last_acked_seq,
170 net->fast_recovery_tsn, MAX_TSN) ||
171 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
172 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
173 (net->pseudo_cumack == net->fast_recovery_tsn)) {
174 net->will_exit_fast_recovery = 1;
178 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
180 * So, first of all do we need to have a Early FR
183 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
184 (net->ref_count > 1) &&
185 (net->flight_size < net->cwnd)) ||
188 * yes, so in this case stop it if its
189 * running, and then restart it. Reneging
190 * all is a special case where we want to
191 * run the Early FR timer and then force the
192 * last few unacked to be sent, causing us
193 * to illicit a sack with gaps to force out
196 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
197 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
198 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
199 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
201 SCTP_STAT_INCR(sctps_earlyfrstrid);
202 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
204 /* No, stop it if its running */
205 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
206 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
207 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
208 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
212 /* if nothing was acked on this destination skip it */
213 if (net->net_ack == 0) {
214 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
215 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
219 if (net->net_ack2 > 0) {
221 * Karn's rule applies to clearing error count, this
224 net->error_count = 0;
225 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
226 SCTP_ADDR_NOT_REACHABLE) {
228 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
229 net->dest_state |= SCTP_ADDR_REACHABLE;
230 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
231 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
232 /* now was it the primary? if so restore */
233 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
234 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
238 * JRS 5/14/07 - If CMT PF is on and the destination
239 * is in PF state, set the destination to active
240 * state and set the cwnd to one or two MTU's based
241 * on whether PF1 or PF2 is being used.
243 * Should we stop any running T3 timer here?
245 if ((asoc->sctp_cmt_on_off == 1) &&
246 (asoc->sctp_cmt_pf > 0) &&
247 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
248 net->dest_state &= ~SCTP_ADDR_PF;
249 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
250 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
253 * Since the cwnd value is explicitly set,
254 * skip the code that updates the cwnd
257 goto skip_cwnd_update;
260 #ifdef JANA_CMT_FAST_RECOVERY
262 * CMT fast recovery code
265 * if (sctp_cmt_on_off == 1 &&
266 * net->fast_retran_loss_recovery &&
267 * net->will_exit_fast_recovery == 0) { @@@ Do something }
268 * else if (sctp_cmt_on_off == 0 &&
269 * asoc->fast_retran_loss_recovery && will_exit == 0) {
273 if (asoc->fast_retran_loss_recovery &&
275 (asoc->sctp_cmt_on_off == 0)) {
277 * If we are in loss recovery we skip any cwnd
280 goto skip_cwnd_update;
283 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
287 ((asoc->sctp_cmt_on_off == 1) && net->new_pseudo_cumack)) {
288 /* If the cumulative ack moved we can proceed */
289 if (net->cwnd <= net->ssthresh) {
290 /* We are in slow start */
291 if (net->flight_size + net->net_ack >= net->cwnd) {
292 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
293 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
294 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
295 sctp_log_cwnd(stcb, net, net->mtu,
296 SCTP_CWND_LOG_FROM_SS);
299 net->cwnd += net->net_ack;
300 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
301 sctp_log_cwnd(stcb, net, net->net_ack,
302 SCTP_CWND_LOG_FROM_SS);
306 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
307 sctp_log_cwnd(stcb, net, net->net_ack,
308 SCTP_CWND_LOG_NOADV_SS);
312 /* We are in congestion avoidance */
316 net->partial_bytes_acked += net->net_ack;
318 if ((net->flight_size + net->net_ack >= net->cwnd) &&
319 (net->partial_bytes_acked >= net->cwnd)) {
320 net->partial_bytes_acked -= net->cwnd;
321 net->cwnd += net->mtu;
322 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
323 sctp_log_cwnd(stcb, net, net->mtu,
324 SCTP_CWND_LOG_FROM_CA);
327 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
328 sctp_log_cwnd(stcb, net, net->net_ack,
329 SCTP_CWND_LOG_NOADV_CA);
334 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
335 sctp_log_cwnd(stcb, net, net->mtu,
336 SCTP_CWND_LOG_NO_CUMACK);
341 * NOW, according to Karn's rule do we need to restore the
342 * RTO timer back? Check our net_ack2. If not set then we
343 * have a ambiguity.. i.e. all data ack'd was sent to more
347 /* restore any doubled timers */
348 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
349 if (net->RTO < stcb->asoc.minrto) {
350 net->RTO = stcb->asoc.minrto;
352 if (net->RTO > stcb->asoc.maxrto) {
353 net->RTO = stcb->asoc.maxrto;
360 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
362 int old_cwnd = net->cwnd;
364 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
365 net->cwnd = net->mtu;
366 net->partial_bytes_acked = 0;
368 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
369 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
374 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net)
376 int old_cwnd = net->cwnd;
378 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
379 net->ssthresh = net->cwnd / 2;
380 if (net->ssthresh < net->mtu) {
381 net->ssthresh = net->mtu;
382 /* here back off the timer as well, to slow us down */
385 net->cwnd = net->ssthresh;
386 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
387 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
392 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
393 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
394 uint32_t * bottle_bw, uint32_t * on_queue)
398 int old_cwnd = net->cwnd;
400 /* need real RTT for this calc */
401 rtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
402 /* get bottle neck bw */
403 *bottle_bw = ntohl(cp->bottle_bw);
404 /* and whats on queue */
405 *on_queue = ntohl(cp->current_onq);
407 * adjust the on-queue if our flight is more it could be that the
408 * router has not yet gotten data "in-flight" to it
410 if (*on_queue < net->flight_size)
411 *on_queue = net->flight_size;
412 /* calculate the available space */
413 bw_avail = (*bottle_bw * rtt) / 1000;
414 if (bw_avail > *bottle_bw) {
416 * Cap the growth to no more than the bottle neck. This can
417 * happen as RTT slides up due to queues. It also means if
418 * you have more than a 1 second RTT with a empty queue you
419 * will be limited to the bottle_bw per second no matter if
420 * other points have 1/2 the RTT and you could get more
423 bw_avail = *bottle_bw;
425 if (*on_queue > bw_avail) {
427 * No room for anything else don't allow anything else to be
428 * "added to the fire".
430 int seg_inflight, seg_onqueue, my_portion;
432 net->partial_bytes_acked = 0;
434 /* how much are we over queue size? */
435 incr = *on_queue - bw_avail;
436 if (stcb->asoc.seen_a_sack_this_pkt) {
438 * undo any cwnd adjustment that the sack might have
441 net->cwnd = net->prev_cwnd;
443 /* Now how much of that is mine? */
444 seg_inflight = net->flight_size / net->mtu;
445 seg_onqueue = *on_queue / net->mtu;
446 my_portion = (incr * seg_inflight) / seg_onqueue;
448 /* Have I made an adjustment already */
449 if (net->cwnd > net->flight_size) {
451 * for this flight I made an adjustment we need to
452 * decrease the portion by a share our previous
457 diff_adj = net->cwnd - net->flight_size;
458 if (diff_adj > my_portion)
461 my_portion -= diff_adj;
464 * back down to the previous cwnd (assume we have had a sack
465 * before this packet). minus what ever portion of the
466 * overage is my fault.
468 net->cwnd -= my_portion;
470 /* we will NOT back down more than 1 MTU */
471 if (net->cwnd <= net->mtu) {
472 net->cwnd = net->mtu;
475 net->ssthresh = net->cwnd - 1;
478 * Take 1/4 of the space left or max burst up .. whichever
481 incr = min((bw_avail - *on_queue) >> 2,
482 stcb->asoc.max_burst * net->mtu);
485 if (net->cwnd > bw_avail) {
486 /* We can't exceed the pipe size */
487 net->cwnd = bw_avail;
489 if (net->cwnd < net->mtu) {
490 /* We always have 1 MTU */
491 net->cwnd = net->mtu;
493 if (net->cwnd - old_cwnd != 0) {
494 /* log only changes */
495 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
496 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
497 SCTP_CWND_LOG_FROM_SAT);
503 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
504 struct sctp_nets *net, int burst_limit)
506 int old_cwnd = net->cwnd;
508 if (net->ssthresh < net->cwnd)
509 net->ssthresh = net->cwnd;
510 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
512 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
513 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
518 sctp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
519 struct sctp_tcb *stcb, struct sctp_nets *net)
521 int old_cwnd = net->cwnd;
523 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
525 * make a small adjustment to cwnd and force to CA.
527 if (net->cwnd > net->mtu)
528 /* drop down one MTU after sending */
529 net->cwnd -= net->mtu;
530 if (net->cwnd < net->ssthresh)
531 /* still in SS move to CA */
532 net->ssthresh = net->cwnd - 1;
533 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
534 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
538 struct sctp_hs_raise_drop {
541 int32_t drop_percent;
544 #define SCTP_HS_TABLE_SIZE 73
546 struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
548 {118, 2, 44}, /* 1 */
549 {221, 3, 41}, /* 2 */
550 {347, 4, 38}, /* 3 */
551 {495, 5, 37}, /* 4 */
552 {663, 6, 35}, /* 5 */
553 {851, 7, 34}, /* 6 */
554 {1058, 8, 33}, /* 7 */
555 {1284, 9, 32}, /* 8 */
556 {1529, 10, 31}, /* 9 */
557 {1793, 11, 30}, /* 10 */
558 {2076, 12, 29}, /* 11 */
559 {2378, 13, 28}, /* 12 */
560 {2699, 14, 28}, /* 13 */
561 {3039, 15, 27}, /* 14 */
562 {3399, 16, 27}, /* 15 */
563 {3778, 17, 26}, /* 16 */
564 {4177, 18, 26}, /* 17 */
565 {4596, 19, 25}, /* 18 */
566 {5036, 20, 25}, /* 19 */
567 {5497, 21, 24}, /* 20 */
568 {5979, 22, 24}, /* 21 */
569 {6483, 23, 23}, /* 22 */
570 {7009, 24, 23}, /* 23 */
571 {7558, 25, 22}, /* 24 */
572 {8130, 26, 22}, /* 25 */
573 {8726, 27, 22}, /* 26 */
574 {9346, 28, 21}, /* 27 */
575 {9991, 29, 21}, /* 28 */
576 {10661, 30, 21}, /* 29 */
577 {11358, 31, 20}, /* 30 */
578 {12082, 32, 20}, /* 31 */
579 {12834, 33, 20}, /* 32 */
580 {13614, 34, 19}, /* 33 */
581 {14424, 35, 19}, /* 34 */
582 {15265, 36, 19}, /* 35 */
583 {16137, 37, 19}, /* 36 */
584 {17042, 38, 18}, /* 37 */
585 {17981, 39, 18}, /* 38 */
586 {18955, 40, 18}, /* 39 */
587 {19965, 41, 17}, /* 40 */
588 {21013, 42, 17}, /* 41 */
589 {22101, 43, 17}, /* 42 */
590 {23230, 44, 17}, /* 43 */
591 {24402, 45, 16}, /* 44 */
592 {25618, 46, 16}, /* 45 */
593 {26881, 47, 16}, /* 46 */
594 {28193, 48, 16}, /* 47 */
595 {29557, 49, 15}, /* 48 */
596 {30975, 50, 15}, /* 49 */
597 {32450, 51, 15}, /* 50 */
598 {33986, 52, 15}, /* 51 */
599 {35586, 53, 14}, /* 52 */
600 {37253, 54, 14}, /* 53 */
601 {38992, 55, 14}, /* 54 */
602 {40808, 56, 14}, /* 55 */
603 {42707, 57, 13}, /* 56 */
604 {44694, 58, 13}, /* 57 */
605 {46776, 59, 13}, /* 58 */
606 {48961, 60, 13}, /* 59 */
607 {51258, 61, 13}, /* 60 */
608 {53677, 62, 12}, /* 61 */
609 {56230, 63, 12}, /* 62 */
610 {58932, 64, 12}, /* 63 */
611 {61799, 65, 12}, /* 64 */
612 {64851, 66, 11}, /* 65 */
613 {68113, 67, 11}, /* 66 */
614 {71617, 68, 11}, /* 67 */
615 {75401, 69, 10}, /* 68 */
616 {79517, 70, 10}, /* 69 */
617 {84035, 71, 10}, /* 70 */
618 {89053, 72, 10}, /* 71 */
619 {94717, 73, 9} /* 72 */
623 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
625 int cur_val, i, indx, incr;
627 cur_val = net->cwnd >> 10;
628 indx = SCTP_HS_TABLE_SIZE - 1;
630 printf("HS CC CAlled.\n");
632 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
634 if (net->net_ack > net->mtu) {
635 net->cwnd += net->mtu;
636 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
637 sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS);
640 net->cwnd += net->net_ack;
641 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
642 sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
646 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
647 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
652 net->last_hs_used = indx;
653 incr = ((sctp_cwnd_adjust[indx].increase) << 10);
655 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
656 sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS);
662 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
664 int cur_val, i, indx;
665 int old_cwnd = net->cwnd;
667 cur_val = net->cwnd >> 10;
668 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
670 net->ssthresh = net->cwnd / 2;
671 if (net->ssthresh < (net->mtu * 2)) {
672 net->ssthresh = 2 * net->mtu;
674 net->cwnd = net->ssthresh;
676 /* drop by the proper amount */
677 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
678 sctp_cwnd_adjust[net->last_hs_used].drop_percent);
679 net->cwnd = net->ssthresh;
680 /* now where are we */
681 indx = net->last_hs_used;
682 cur_val = net->cwnd >> 10;
683 /* reset where we are in the table */
684 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
686 net->last_hs_used = 0;
688 for (i = indx; i >= 1; i--) {
689 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
693 net->last_hs_used = indx;
696 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
697 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
702 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
703 struct sctp_association *asoc)
705 struct sctp_nets *net;
708 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
709 * (net->fast_retran_loss_recovery == 0)))
711 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
712 if ((asoc->fast_retran_loss_recovery == 0) ||
713 (asoc->sctp_cmt_on_off == 1)) {
714 /* out of a RFC2582 Fast recovery window? */
715 if (net->net_ack > 0) {
717 * per section 7.2.3, are there any
718 * destinations that had a fast retransmit
719 * to them. If so what we need to do is
720 * adjust ssthresh and cwnd.
722 struct sctp_tmit_chunk *lchk;
724 sctp_hs_cwnd_decrease(stcb, net);
726 lchk = TAILQ_FIRST(&asoc->send_queue);
728 net->partial_bytes_acked = 0;
729 /* Turn on fast recovery window */
730 asoc->fast_retran_loss_recovery = 1;
732 /* Mark end of the window */
733 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
735 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
739 * CMT fast recovery -- per destination
742 net->fast_retran_loss_recovery = 1;
745 /* Mark end of the window */
746 net->fast_recovery_tsn = asoc->sending_seq - 1;
748 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
752 * Disable Nonce Sum Checking and store the
755 asoc->nonce_sum_check = 0;
756 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
758 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
759 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
760 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
761 stcb->sctp_ep, stcb, net);
763 } else if (net->net_ack > 0) {
765 * Mark a peg that we WOULD have done a cwnd
766 * reduction but RFC2582 prevented this action.
768 SCTP_STAT_INCR(sctps_fastretransinrtt);
774 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
775 struct sctp_association *asoc,
776 int accum_moved, int reneged_all, int will_exit)
778 struct sctp_nets *net;
780 /******************************/
781 /* update cwnd and Early FR */
782 /******************************/
783 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
785 #ifdef JANA_CMT_FAST_RECOVERY
787 * CMT fast recovery code. Need to debug.
789 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
790 if (compare_with_wrap(asoc->last_acked_seq,
791 net->fast_recovery_tsn, MAX_TSN) ||
792 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
793 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
794 (net->pseudo_cumack == net->fast_recovery_tsn)) {
795 net->will_exit_fast_recovery = 1;
799 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
801 * So, first of all do we need to have a Early FR
804 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
805 (net->ref_count > 1) &&
806 (net->flight_size < net->cwnd)) ||
809 * yes, so in this case stop it if its
810 * running, and then restart it. Reneging
811 * all is a special case where we want to
812 * run the Early FR timer and then force the
813 * last few unacked to be sent, causing us
814 * to illicit a sack with gaps to force out
817 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
818 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
819 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
820 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
822 SCTP_STAT_INCR(sctps_earlyfrstrid);
823 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
825 /* No, stop it if its running */
826 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
827 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
828 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
829 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
833 /* if nothing was acked on this destination skip it */
834 if (net->net_ack == 0) {
835 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
836 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
840 if (net->net_ack2 > 0) {
842 * Karn's rule applies to clearing error count, this
845 net->error_count = 0;
846 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
847 SCTP_ADDR_NOT_REACHABLE) {
849 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
850 net->dest_state |= SCTP_ADDR_REACHABLE;
851 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
852 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
853 /* now was it the primary? if so restore */
854 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
855 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
859 * JRS 5/14/07 - If CMT PF is on and the destination
860 * is in PF state, set the destination to active
861 * state and set the cwnd to one or two MTU's based
862 * on whether PF1 or PF2 is being used.
864 * Should we stop any running T3 timer here?
866 if ((asoc->sctp_cmt_on_off == 1) &&
867 (asoc->sctp_cmt_pf > 0) &&
868 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
869 net->dest_state &= ~SCTP_ADDR_PF;
870 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
871 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
874 * Since the cwnd value is explicitly set,
875 * skip the code that updates the cwnd
878 goto skip_cwnd_update;
881 #ifdef JANA_CMT_FAST_RECOVERY
883 * CMT fast recovery code
886 * if (sctp_cmt_on_off == 1 &&
887 * net->fast_retran_loss_recovery &&
888 * net->will_exit_fast_recovery == 0) { @@@ Do something }
889 * else if (sctp_cmt_on_off == 0 &&
890 * asoc->fast_retran_loss_recovery && will_exit == 0) {
894 if (asoc->fast_retran_loss_recovery &&
896 (asoc->sctp_cmt_on_off == 0)) {
898 * If we are in loss recovery we skip any cwnd
901 goto skip_cwnd_update;
904 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
908 ((asoc->sctp_cmt_on_off == 1) && net->new_pseudo_cumack)) {
909 /* If the cumulative ack moved we can proceed */
910 if (net->cwnd <= net->ssthresh) {
911 /* We are in slow start */
912 if (net->flight_size + net->net_ack >= net->cwnd) {
914 sctp_hs_cwnd_increase(stcb, net);
917 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
918 sctp_log_cwnd(stcb, net, net->net_ack,
919 SCTP_CWND_LOG_NOADV_SS);
923 /* We are in congestion avoidance */
924 net->partial_bytes_acked += net->net_ack;
925 if ((net->flight_size + net->net_ack >= net->cwnd) &&
926 (net->partial_bytes_acked >= net->cwnd)) {
927 net->partial_bytes_acked -= net->cwnd;
928 net->cwnd += net->mtu;
929 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
930 sctp_log_cwnd(stcb, net, net->mtu,
931 SCTP_CWND_LOG_FROM_CA);
934 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
935 sctp_log_cwnd(stcb, net, net->net_ack,
936 SCTP_CWND_LOG_NOADV_CA);
941 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
942 sctp_log_cwnd(stcb, net, net->mtu,
943 SCTP_CWND_LOG_NO_CUMACK);
948 * NOW, according to Karn's rule do we need to restore the
949 * RTO timer back? Check our net_ack2. If not set then we
950 * have a ambiguity.. i.e. all data ack'd was sent to more
954 /* restore any doubled timers */
955 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
956 if (net->RTO < stcb->asoc.minrto) {
957 net->RTO = stcb->asoc.minrto;
959 if (net->RTO > stcb->asoc.maxrto) {
960 net->RTO = stcb->asoc.maxrto;
968 * H-TCP congestion control. The algorithm is detailed in:
969 * R.N.Shorten, D.J.Leith:
970 * "H-TCP: TCP for high-speed and long-distance networks"
971 * Proc. PFLDnet, Argonne, 2004.
972 * http://www.hamilton.ie/net/htcp3.pdf
976 static int use_rtt_scaling = 1;
977 static int use_bandwidth_switch = 1;
980 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
982 return seq3 - seq2 >= seq1 - seq2;
985 static inline uint32_t
986 htcp_cong_time(struct htcp *ca)
988 return sctp_get_tick_count() - ca->last_cong;
991 static inline uint32_t
992 htcp_ccount(struct htcp *ca)
994 return htcp_cong_time(ca) / ca->minRTT;
998 htcp_reset(struct htcp *ca)
1000 ca->undo_last_cong = ca->last_cong;
1001 ca->undo_maxRTT = ca->maxRTT;
1002 ca->undo_old_maxB = ca->old_maxB;
1003 ca->last_cong = sctp_get_tick_count();
1006 #ifdef SCTP_NOT_USED
1009 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1011 net->htcp_ca.last_cong = net->htcp_ca.undo_last_cong;
1012 net->htcp_ca.maxRTT = net->htcp_ca.undo_maxRTT;
1013 net->htcp_ca.old_maxB = net->htcp_ca.undo_old_maxB;
1014 return max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->htcp_ca.beta) * net->mtu);
1020 measure_rtt(struct sctp_tcb *stcb, struct sctp_nets *net)
1022 uint32_t srtt = net->lastsa >> 3;
1024 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1025 if (net->htcp_ca.minRTT > srtt || !net->htcp_ca.minRTT)
1026 net->htcp_ca.minRTT = srtt;
1029 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->htcp_ca) > 3) {
1030 if (net->htcp_ca.maxRTT < net->htcp_ca.minRTT)
1031 net->htcp_ca.maxRTT = net->htcp_ca.minRTT;
1032 if (net->htcp_ca.maxRTT < srtt && srtt <= net->htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1033 net->htcp_ca.maxRTT = srtt;
1038 measure_achieved_throughput(struct sctp_tcb *stcb, struct sctp_nets *net)
1040 uint32_t now = sctp_get_tick_count();
1042 if (net->fast_retran_ip == 0)
1043 net->htcp_ca.bytes_acked = net->net_ack;
1045 if (!use_bandwidth_switch)
1048 /* achieved throughput calculations */
1049 /* JRS - not 100% sure of this statement */
1050 if (net->fast_retran_ip == 1) {
1051 net->htcp_ca.bytecount = 0;
1052 net->htcp_ca.lasttime = now;
1055 net->htcp_ca.bytecount += net->net_ack;
1057 if (net->htcp_ca.bytecount >= net->cwnd - ((net->htcp_ca.alpha >> 7 ? : 1) * net->mtu)
1058 && now - net->htcp_ca.lasttime >= net->htcp_ca.minRTT
1059 && net->htcp_ca.minRTT > 0) {
1060 uint32_t cur_Bi = net->htcp_ca.bytecount / net->mtu * hz / (now - net->htcp_ca.lasttime);
1062 if (htcp_ccount(&net->htcp_ca) <= 3) {
1063 /* just after backoff */
1064 net->htcp_ca.minB = net->htcp_ca.maxB = net->htcp_ca.Bi = cur_Bi;
1066 net->htcp_ca.Bi = (3 * net->htcp_ca.Bi + cur_Bi) / 4;
1067 if (net->htcp_ca.Bi > net->htcp_ca.maxB)
1068 net->htcp_ca.maxB = net->htcp_ca.Bi;
1069 if (net->htcp_ca.minB > net->htcp_ca.maxB)
1070 net->htcp_ca.minB = net->htcp_ca.maxB;
1072 net->htcp_ca.bytecount = 0;
1073 net->htcp_ca.lasttime = now;
1078 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1080 if (use_bandwidth_switch) {
1081 uint32_t maxB = ca->maxB;
1082 uint32_t old_maxB = ca->old_maxB;
1084 ca->old_maxB = ca->maxB;
1086 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1087 ca->beta = BETA_MIN;
1092 if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) {
1093 ca->beta = (minRTT << 7) / maxRTT;
1094 if (ca->beta < BETA_MIN)
1095 ca->beta = BETA_MIN;
1096 else if (ca->beta > BETA_MAX)
1097 ca->beta = BETA_MAX;
1099 ca->beta = BETA_MIN;
1105 htcp_alpha_update(struct htcp *ca)
1107 uint32_t minRTT = ca->minRTT;
1108 uint32_t factor = 1;
1109 uint32_t diff = htcp_cong_time(ca);
1111 if (diff > (uint32_t) hz) {
1113 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1115 if (use_rtt_scaling && minRTT) {
1116 uint32_t scale = (hz << 3) / (10 * minRTT);
1118 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1119 * interval [0.5,10]<<3 */
1120 factor = (factor << 3) / scale;
1124 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
1126 ca->alpha = ALPHA_BASE;
1129 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
1130 * rtt before we adjust our beta to ensure we are working from a consistent
1133 * This function should be called when we hit a congestion event since only at
1134 * that point do we really have a real sense of maxRTT (the queues en route
1135 * were getting just too full now).
1138 htcp_param_update(struct sctp_tcb *stcb, struct sctp_nets *net)
1140 uint32_t minRTT = net->htcp_ca.minRTT;
1141 uint32_t maxRTT = net->htcp_ca.maxRTT;
1143 htcp_beta_update(&net->htcp_ca, minRTT, maxRTT);
1144 htcp_alpha_update(&net->htcp_ca);
1147 * add slowly fading memory for maxRTT to accommodate routing
1150 if (minRTT > 0 && maxRTT > minRTT)
1151 net->htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
1155 htcp_recalc_ssthresh(struct sctp_tcb *stcb, struct sctp_nets *net)
1157 htcp_param_update(stcb, net);
1158 return max(((net->cwnd / net->mtu * net->htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu);
1162 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
1165 * How to handle these functions?
1166 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
1169 if (net->cwnd <= net->ssthresh) {
1170 /* We are in slow start */
1171 if (net->flight_size + net->net_ack >= net->cwnd) {
1172 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
1173 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
1174 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1175 sctp_log_cwnd(stcb, net, net->mtu,
1176 SCTP_CWND_LOG_FROM_SS);
1179 net->cwnd += net->net_ack;
1180 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1181 sctp_log_cwnd(stcb, net, net->net_ack,
1182 SCTP_CWND_LOG_FROM_SS);
1186 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1187 sctp_log_cwnd(stcb, net, net->net_ack,
1188 SCTP_CWND_LOG_NOADV_SS);
1192 measure_rtt(stcb, net);
1195 * In dangerous area, increase slowly. In theory this is
1196 * net->cwnd += alpha / net->cwnd
1198 /* What is snd_cwnd_cnt?? */
1199 if (((net->partial_bytes_acked / net->mtu * net->htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
1201 * Does SCTP have a cwnd clamp?
1202 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
1204 net->cwnd += net->mtu;
1205 net->partial_bytes_acked = 0;
1206 htcp_alpha_update(&net->htcp_ca);
1207 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1208 sctp_log_cwnd(stcb, net, net->mtu,
1209 SCTP_CWND_LOG_FROM_CA);
1212 net->partial_bytes_acked += net->net_ack;
1213 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1214 sctp_log_cwnd(stcb, net, net->net_ack,
1215 SCTP_CWND_LOG_NOADV_CA);
1219 net->htcp_ca.bytes_acked = net->mtu;
1223 #ifdef SCTP_NOT_USED
1224 /* Lower bound on congestion window. */
1226 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
1228 return net->ssthresh;
1234 htcp_init(struct sctp_tcb *stcb, struct sctp_nets *net)
1236 memset(&net->htcp_ca, 0, sizeof(struct htcp));
1237 net->htcp_ca.alpha = ALPHA_BASE;
1238 net->htcp_ca.beta = BETA_MIN;
1239 net->htcp_ca.bytes_acked = net->mtu;
1240 net->htcp_ca.last_cong = sctp_get_tick_count();
1244 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
1247 * We take the max of the burst limit times a MTU or the
1248 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
1250 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1251 net->ssthresh = stcb->asoc.peers_rwnd;
1252 htcp_init(stcb, net);
1254 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
1255 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
1260 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1261 struct sctp_association *asoc,
1262 int accum_moved, int reneged_all, int will_exit)
1264 struct sctp_nets *net;
1266 /******************************/
1267 /* update cwnd and Early FR */
1268 /******************************/
1269 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1271 #ifdef JANA_CMT_FAST_RECOVERY
1273 * CMT fast recovery code. Need to debug.
1275 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1276 if (compare_with_wrap(asoc->last_acked_seq,
1277 net->fast_recovery_tsn, MAX_TSN) ||
1278 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
1279 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
1280 (net->pseudo_cumack == net->fast_recovery_tsn)) {
1281 net->will_exit_fast_recovery = 1;
1285 if (SCTP_BASE_SYSCTL(sctp_early_fr)) {
1287 * So, first of all do we need to have a Early FR
1290 if ((!TAILQ_EMPTY(&asoc->sent_queue) &&
1291 (net->ref_count > 1) &&
1292 (net->flight_size < net->cwnd)) ||
1295 * yes, so in this case stop it if its
1296 * running, and then restart it. Reneging
1297 * all is a special case where we want to
1298 * run the Early FR timer and then force the
1299 * last few unacked to be sent, causing us
1300 * to illicit a sack with gaps to force out
1303 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1304 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
1305 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1306 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
1308 SCTP_STAT_INCR(sctps_earlyfrstrid);
1309 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
1311 /* No, stop it if its running */
1312 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1313 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
1314 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1315 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
1319 /* if nothing was acked on this destination skip it */
1320 if (net->net_ack == 0) {
1321 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1322 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1326 if (net->net_ack2 > 0) {
1328 * Karn's rule applies to clearing error count, this
1331 net->error_count = 0;
1332 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
1333 SCTP_ADDR_NOT_REACHABLE) {
1334 /* addr came good */
1335 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
1336 net->dest_state |= SCTP_ADDR_REACHABLE;
1337 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
1338 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
1339 /* now was it the primary? if so restore */
1340 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
1341 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
1345 * JRS 5/14/07 - If CMT PF is on and the destination
1346 * is in PF state, set the destination to active
1347 * state and set the cwnd to one or two MTU's based
1348 * on whether PF1 or PF2 is being used.
1350 * Should we stop any running T3 timer here?
1352 if ((asoc->sctp_cmt_on_off == 1) &&
1353 (asoc->sctp_cmt_pf > 0) &&
1354 ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF)) {
1355 net->dest_state &= ~SCTP_ADDR_PF;
1356 net->cwnd = net->mtu * asoc->sctp_cmt_pf;
1357 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1360 * Since the cwnd value is explicitly set,
1361 * skip the code that updates the cwnd
1364 goto skip_cwnd_update;
1367 #ifdef JANA_CMT_FAST_RECOVERY
1369 * CMT fast recovery code
1372 * if (sctp_cmt_on_off == 1 &&
1373 * net->fast_retran_loss_recovery &&
1374 * net->will_exit_fast_recovery == 0) { @@@ Do something }
1375 * else if (sctp_cmt_on_off == 0 &&
1376 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1380 if (asoc->fast_retran_loss_recovery &&
1382 (asoc->sctp_cmt_on_off == 0)) {
1384 * If we are in loss recovery we skip any cwnd
1387 goto skip_cwnd_update;
1390 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1394 ((asoc->sctp_cmt_on_off == 1) && net->new_pseudo_cumack)) {
1395 htcp_cong_avoid(stcb, net);
1396 measure_achieved_throughput(stcb, net);
1398 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1399 sctp_log_cwnd(stcb, net, net->mtu,
1400 SCTP_CWND_LOG_NO_CUMACK);
1405 * NOW, according to Karn's rule do we need to restore the
1406 * RTO timer back? Check our net_ack2. If not set then we
1407 * have a ambiguity.. i.e. all data ack'd was sent to more
1410 if (net->net_ack2) {
1411 /* restore any doubled timers */
1412 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
1413 if (net->RTO < stcb->asoc.minrto) {
1414 net->RTO = stcb->asoc.minrto;
1416 if (net->RTO > stcb->asoc.maxrto) {
1417 net->RTO = stcb->asoc.maxrto;
1424 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
1425 struct sctp_association *asoc)
1427 struct sctp_nets *net;
1430 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
1431 * (net->fast_retran_loss_recovery == 0)))
1433 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1434 if ((asoc->fast_retran_loss_recovery == 0) ||
1435 (asoc->sctp_cmt_on_off == 1)) {
1436 /* out of a RFC2582 Fast recovery window? */
1437 if (net->net_ack > 0) {
1439 * per section 7.2.3, are there any
1440 * destinations that had a fast retransmit
1441 * to them. If so what we need to do is
1442 * adjust ssthresh and cwnd.
1444 struct sctp_tmit_chunk *lchk;
1445 int old_cwnd = net->cwnd;
1447 /* JRS - reset as if state were changed */
1448 htcp_reset(&net->htcp_ca);
1449 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1450 net->cwnd = net->ssthresh;
1451 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1452 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1453 SCTP_CWND_LOG_FROM_FR);
1455 lchk = TAILQ_FIRST(&asoc->send_queue);
1457 net->partial_bytes_acked = 0;
1458 /* Turn on fast recovery window */
1459 asoc->fast_retran_loss_recovery = 1;
1461 /* Mark end of the window */
1462 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1464 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1468 * CMT fast recovery -- per destination
1469 * recovery variable.
1471 net->fast_retran_loss_recovery = 1;
1474 /* Mark end of the window */
1475 net->fast_recovery_tsn = asoc->sending_seq - 1;
1477 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1481 * Disable Nonce Sum Checking and store the
1484 asoc->nonce_sum_check = 0;
1485 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
1487 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1488 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
1489 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1490 stcb->sctp_ep, stcb, net);
1492 } else if (net->net_ack > 0) {
1494 * Mark a peg that we WOULD have done a cwnd
1495 * reduction but RFC2582 prevented this action.
1497 SCTP_STAT_INCR(sctps_fastretransinrtt);
1503 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
1504 struct sctp_nets *net)
1506 int old_cwnd = net->cwnd;
1508 /* JRS - reset as if the state were being changed to timeout */
1509 htcp_reset(&net->htcp_ca);
1510 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1511 net->cwnd = net->mtu;
1512 net->partial_bytes_acked = 0;
1513 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1514 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1519 sctp_htcp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
1520 struct sctp_tcb *stcb, struct sctp_nets *net)
1524 old_cwnd = net->cwnd;
1526 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
1527 net->htcp_ca.last_cong = sctp_get_tick_count();
1529 * make a small adjustment to cwnd and force to CA.
1531 if (net->cwnd > net->mtu)
1532 /* drop down one MTU after sending */
1533 net->cwnd -= net->mtu;
1534 if (net->cwnd < net->ssthresh)
1535 /* still in SS move to CA */
1536 net->ssthresh = net->cwnd - 1;
1537 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1538 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
1543 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
1544 struct sctp_nets *net)
1548 old_cwnd = net->cwnd;
1550 /* JRS - reset hctp as if state changed */
1551 htcp_reset(&net->htcp_ca);
1552 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1553 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1554 if (net->ssthresh < net->mtu) {
1555 net->ssthresh = net->mtu;
1556 /* here back off the timer as well, to slow us down */
1559 net->cwnd = net->ssthresh;
1560 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1561 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);