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$");
48 sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
51 * We take the max of the burst limit times a MTU or the
52 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
54 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
55 /* we always get at LEAST 2 MTU's */
56 if (net->cwnd < (2 * net->mtu)) {
57 net->cwnd = 2 * net->mtu;
59 net->ssthresh = stcb->asoc.peers_rwnd;
61 if (sctp_logging_level & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
62 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
67 sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
68 struct sctp_association *asoc)
70 struct sctp_nets *net;
73 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
74 * (net->fast_retran_loss_recovery == 0)))
76 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
77 if ((asoc->fast_retran_loss_recovery == 0) || (sctp_cmt_on_off == 1)) {
78 /* out of a RFC2582 Fast recovery window? */
79 if (net->net_ack > 0) {
81 * per section 7.2.3, are there any
82 * destinations that had a fast retransmit
83 * to them. If so what we need to do is
84 * adjust ssthresh and cwnd.
86 struct sctp_tmit_chunk *lchk;
87 int old_cwnd = net->cwnd;
89 net->ssthresh = net->cwnd / 2;
90 if (net->ssthresh < (net->mtu * 2)) {
91 net->ssthresh = 2 * net->mtu;
93 net->cwnd = net->ssthresh;
94 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
95 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
96 SCTP_CWND_LOG_FROM_FR);
98 lchk = TAILQ_FIRST(&asoc->send_queue);
100 net->partial_bytes_acked = 0;
101 /* Turn on fast recovery window */
102 asoc->fast_retran_loss_recovery = 1;
104 /* Mark end of the window */
105 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
107 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
111 * CMT fast recovery -- per destination
114 net->fast_retran_loss_recovery = 1;
117 /* Mark end of the window */
118 net->fast_recovery_tsn = asoc->sending_seq - 1;
120 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
124 * Disable Nonce Sum Checking and store the
127 asoc->nonce_sum_check = 0;
128 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
130 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
131 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
132 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
133 stcb->sctp_ep, stcb, net);
135 } else if (net->net_ack > 0) {
137 * Mark a peg that we WOULD have done a cwnd
138 * reduction but RFC2582 prevented this action.
140 SCTP_STAT_INCR(sctps_fastretransinrtt);
146 sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
147 struct sctp_association *asoc,
148 int accum_moved, int reneged_all, int will_exit)
150 struct sctp_nets *net;
152 /******************************/
153 /* update cwnd and Early FR */
154 /******************************/
155 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
157 #ifdef JANA_CMT_FAST_RECOVERY
159 * CMT fast recovery code. Need to debug.
161 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
162 if (compare_with_wrap(asoc->last_acked_seq,
163 net->fast_recovery_tsn, MAX_TSN) ||
164 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
165 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
166 (net->pseudo_cumack == net->fast_recovery_tsn)) {
167 net->will_exit_fast_recovery = 1;
173 * So, first of all do we need to have a Early FR
176 if (((TAILQ_FIRST(&asoc->sent_queue)) &&
177 (net->ref_count > 1) &&
178 (net->flight_size < net->cwnd)) ||
181 * yes, so in this case stop it if its
182 * running, and then restart it. Reneging
183 * all is a special case where we want to
184 * run the Early FR timer and then force the
185 * last few unacked to be sent, causing us
186 * to illicit a sack with gaps to force out
189 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
190 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
191 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
192 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
194 SCTP_STAT_INCR(sctps_earlyfrstrid);
195 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
197 /* No, stop it if its running */
198 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
199 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
200 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
201 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
205 /* if nothing was acked on this destination skip it */
206 if (net->net_ack == 0) {
207 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
208 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
212 if (net->net_ack2 > 0) {
214 * Karn's rule applies to clearing error count, this
217 net->error_count = 0;
218 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
219 SCTP_ADDR_NOT_REACHABLE) {
221 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
222 net->dest_state |= SCTP_ADDR_REACHABLE;
223 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
224 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
225 /* now was it the primary? if so restore */
226 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
227 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
231 * JRS 5/14/07 - If CMT PF is on and the destination
232 * is in PF state, set the destination to active
233 * state and set the cwnd to one or two MTU's based
234 * on whether PF1 or PF2 is being used.
236 * Should we stop any running T3 timer here?
238 if (sctp_cmt_on_off && sctp_cmt_pf && ((net->dest_state & SCTP_ADDR_PF) ==
240 net->dest_state &= ~SCTP_ADDR_PF;
241 net->cwnd = net->mtu * sctp_cmt_pf;
242 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
245 * Since the cwnd value is explicitly set,
246 * skip the code that updates the cwnd
249 goto skip_cwnd_update;
252 #ifdef JANA_CMT_FAST_RECOVERY
254 * CMT fast recovery code
257 * if (sctp_cmt_on_off == 1 &&
258 * net->fast_retran_loss_recovery &&
259 * net->will_exit_fast_recovery == 0) { @@@ Do something }
260 * else if (sctp_cmt_on_off == 0 &&
261 * asoc->fast_retran_loss_recovery && will_exit == 0) {
265 if (asoc->fast_retran_loss_recovery && will_exit == 0 && sctp_cmt_on_off == 0) {
267 * If we are in loss recovery we skip any cwnd
270 goto skip_cwnd_update;
273 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
276 if (accum_moved || (sctp_cmt_on_off && net->new_pseudo_cumack)) {
277 /* If the cumulative ack moved we can proceed */
278 if (net->cwnd <= net->ssthresh) {
279 /* We are in slow start */
280 if (net->flight_size + net->net_ack >=
282 if (net->net_ack > (net->mtu * sctp_L2_abc_variable)) {
283 net->cwnd += (net->mtu * sctp_L2_abc_variable);
284 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
285 sctp_log_cwnd(stcb, net, net->mtu,
286 SCTP_CWND_LOG_FROM_SS);
289 net->cwnd += net->net_ack;
290 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
291 sctp_log_cwnd(stcb, net, net->net_ack,
292 SCTP_CWND_LOG_FROM_SS);
298 dif = net->cwnd - (net->flight_size +
300 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
301 sctp_log_cwnd(stcb, net, net->net_ack,
302 SCTP_CWND_LOG_NOADV_SS);
306 /* We are in congestion avoidance */
307 if (net->flight_size + net->net_ack >=
310 * add to pba only if we had a
311 * cwnd's worth (or so) in flight OR
312 * the burst limit was applied.
314 net->partial_bytes_acked +=
318 * Do we need to increase (if pba is
321 if (net->partial_bytes_acked >=
324 net->partial_bytes_acked) {
325 net->partial_bytes_acked -=
328 net->partial_bytes_acked =
331 net->cwnd += net->mtu;
332 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
333 sctp_log_cwnd(stcb, net, net->mtu,
334 SCTP_CWND_LOG_FROM_CA);
337 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
338 sctp_log_cwnd(stcb, net, net->net_ack,
339 SCTP_CWND_LOG_NOADV_CA);
345 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
346 sctp_log_cwnd(stcb, net, net->net_ack,
347 SCTP_CWND_LOG_NOADV_CA);
349 dif = net->cwnd - (net->flight_size +
354 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
355 sctp_log_cwnd(stcb, net, net->mtu,
356 SCTP_CWND_LOG_NO_CUMACK);
361 * NOW, according to Karn's rule do we need to restore the
362 * RTO timer back? Check our net_ack2. If not set then we
363 * have a ambiguity.. i.e. all data ack'd was sent to more
367 /* restore any doubled timers */
368 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
369 if (net->RTO < stcb->asoc.minrto) {
370 net->RTO = stcb->asoc.minrto;
372 if (net->RTO > stcb->asoc.maxrto) {
373 net->RTO = stcb->asoc.maxrto;
380 sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
381 struct sctp_nets *net)
383 int old_cwnd = net->cwnd;
385 net->ssthresh = net->cwnd >> 1;
386 if (net->ssthresh < (net->mtu << 1)) {
387 net->ssthresh = (net->mtu << 1);
389 net->cwnd = net->mtu;
391 if (net->cwnd < net->mtu)
392 net->cwnd = net->mtu;
393 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
394 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
396 net->partial_bytes_acked = 0;
399 struct sctp_hs_raise_drop {
402 int32_t drop_percent;
405 #define SCTP_HS_TABLE_SIZE 73
407 struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
409 {118, 2, 44}, /* 1 */
410 {221, 3, 41}, /* 2 */
411 {347, 4, 38}, /* 3 */
412 {495, 5, 37}, /* 4 */
413 {663, 6, 35}, /* 5 */
414 {851, 7, 34}, /* 6 */
415 {1058, 8, 33}, /* 7 */
416 {1284, 9, 32}, /* 8 */
417 {1529, 10, 31}, /* 9 */
418 {1793, 11, 30}, /* 10 */
419 {2076, 12, 29}, /* 11 */
420 {2378, 13, 28}, /* 12 */
421 {2699, 14, 28}, /* 13 */
422 {3039, 15, 27}, /* 14 */
423 {3399, 16, 27}, /* 15 */
424 {3778, 17, 26}, /* 16 */
425 {4177, 18, 26}, /* 17 */
426 {4596, 19, 25}, /* 18 */
427 {5036, 20, 25}, /* 19 */
428 {5497, 21, 24}, /* 20 */
429 {5979, 22, 24}, /* 21 */
430 {6483, 23, 23}, /* 22 */
431 {7009, 24, 23}, /* 23 */
432 {7558, 25, 22}, /* 24 */
433 {8130, 26, 22}, /* 25 */
434 {8726, 27, 22}, /* 26 */
435 {9346, 28, 21}, /* 27 */
436 {9991, 29, 21}, /* 28 */
437 {10661, 30, 21}, /* 29 */
438 {11358, 31, 20}, /* 30 */
439 {12082, 32, 20}, /* 31 */
440 {12834, 33, 20}, /* 32 */
441 {13614, 34, 19}, /* 33 */
442 {14424, 35, 19}, /* 34 */
443 {15265, 36, 19}, /* 35 */
444 {16137, 37, 19}, /* 36 */
445 {17042, 38, 18}, /* 37 */
446 {17981, 39, 18}, /* 38 */
447 {18955, 40, 18}, /* 39 */
448 {19965, 41, 17}, /* 40 */
449 {21013, 42, 17}, /* 41 */
450 {22101, 43, 17}, /* 42 */
451 {23230, 44, 17}, /* 43 */
452 {24402, 45, 16}, /* 44 */
453 {25618, 46, 16}, /* 45 */
454 {26881, 47, 16}, /* 46 */
455 {28193, 48, 16}, /* 47 */
456 {29557, 49, 15}, /* 48 */
457 {30975, 50, 15}, /* 49 */
458 {32450, 51, 15}, /* 50 */
459 {33986, 52, 15}, /* 51 */
460 {35586, 53, 14}, /* 52 */
461 {37253, 54, 14}, /* 53 */
462 {38992, 55, 14}, /* 54 */
463 {40808, 56, 14}, /* 55 */
464 {42707, 57, 13}, /* 56 */
465 {44694, 58, 13}, /* 57 */
466 {46776, 59, 13}, /* 58 */
467 {48961, 60, 13}, /* 59 */
468 {51258, 61, 13}, /* 60 */
469 {53677, 62, 12}, /* 61 */
470 {56230, 63, 12}, /* 62 */
471 {58932, 64, 12}, /* 63 */
472 {61799, 65, 12}, /* 64 */
473 {64851, 66, 11}, /* 65 */
474 {68113, 67, 11}, /* 66 */
475 {71617, 68, 11}, /* 67 */
476 {75401, 69, 10}, /* 68 */
477 {79517, 70, 10}, /* 69 */
478 {84035, 71, 10}, /* 70 */
479 {89053, 72, 10}, /* 71 */
480 {94717, 73, 9} /* 72 */
484 sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
486 int cur_val, i, indx, incr;
488 cur_val = net->cwnd >> 10;
489 indx = SCTP_HS_TABLE_SIZE - 1;
491 printf("HS CC CAlled.\n");
493 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
495 if (net->net_ack > net->mtu) {
496 net->cwnd += net->mtu;
497 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
498 sctp_log_cwnd(stcb, net, net->mtu, SCTP_CWND_LOG_FROM_SS);
501 net->cwnd += net->net_ack;
502 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
503 sctp_log_cwnd(stcb, net, net->net_ack, SCTP_CWND_LOG_FROM_SS);
507 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
508 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
513 net->last_hs_used = indx;
514 incr = ((sctp_cwnd_adjust[indx].increase) << 10);
516 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
517 sctp_log_cwnd(stcb, net, incr, SCTP_CWND_LOG_FROM_SS);
523 sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
525 int cur_val, i, indx;
526 int old_cwnd = net->cwnd;
528 cur_val = net->cwnd >> 10;
529 indx = net->last_hs_used;
530 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
532 net->ssthresh = net->cwnd / 2;
533 if (net->ssthresh < (net->mtu * 2)) {
534 net->ssthresh = 2 * net->mtu;
536 net->cwnd = net->ssthresh;
538 /* drop by the proper amount */
539 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
540 sctp_cwnd_adjust[net->last_hs_used].drop_percent);
541 net->cwnd = net->ssthresh;
542 /* now where are we */
543 indx = net->last_hs_used;
544 cur_val = net->cwnd >> 10;
545 /* reset where we are in the table */
546 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
548 net->last_hs_used = 0;
550 for (i = indx; i >= 1; i--) {
551 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
555 net->last_hs_used = indx;
558 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
559 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
564 sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
565 struct sctp_association *asoc)
567 struct sctp_nets *net;
570 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
571 * (net->fast_retran_loss_recovery == 0)))
573 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
574 if ((asoc->fast_retran_loss_recovery == 0) || (sctp_cmt_on_off == 1)) {
575 /* out of a RFC2582 Fast recovery window? */
576 if (net->net_ack > 0) {
578 * per section 7.2.3, are there any
579 * destinations that had a fast retransmit
580 * to them. If so what we need to do is
581 * adjust ssthresh and cwnd.
583 struct sctp_tmit_chunk *lchk;
585 sctp_hs_cwnd_decrease(stcb, net);
587 lchk = TAILQ_FIRST(&asoc->send_queue);
589 net->partial_bytes_acked = 0;
590 /* Turn on fast recovery window */
591 asoc->fast_retran_loss_recovery = 1;
593 /* Mark end of the window */
594 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
596 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
600 * CMT fast recovery -- per destination
603 net->fast_retran_loss_recovery = 1;
606 /* Mark end of the window */
607 net->fast_recovery_tsn = asoc->sending_seq - 1;
609 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
613 * Disable Nonce Sum Checking and store the
616 asoc->nonce_sum_check = 0;
617 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
619 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
620 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
621 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
622 stcb->sctp_ep, stcb, net);
624 } else if (net->net_ack > 0) {
626 * Mark a peg that we WOULD have done a cwnd
627 * reduction but RFC2582 prevented this action.
629 SCTP_STAT_INCR(sctps_fastretransinrtt);
635 sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
636 struct sctp_association *asoc,
637 int accum_moved, int reneged_all, int will_exit)
639 struct sctp_nets *net;
641 /******************************/
642 /* update cwnd and Early FR */
643 /******************************/
644 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
646 #ifdef JANA_CMT_FAST_RECOVERY
648 * CMT fast recovery code. Need to debug.
650 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
651 if (compare_with_wrap(asoc->last_acked_seq,
652 net->fast_recovery_tsn, MAX_TSN) ||
653 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
654 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
655 (net->pseudo_cumack == net->fast_recovery_tsn)) {
656 net->will_exit_fast_recovery = 1;
662 * So, first of all do we need to have a Early FR
665 if (((TAILQ_FIRST(&asoc->sent_queue)) &&
666 (net->ref_count > 1) &&
667 (net->flight_size < net->cwnd)) ||
670 * yes, so in this case stop it if its
671 * running, and then restart it. Reneging
672 * all is a special case where we want to
673 * run the Early FR timer and then force the
674 * last few unacked to be sent, causing us
675 * to illicit a sack with gaps to force out
678 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
679 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
680 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
681 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
683 SCTP_STAT_INCR(sctps_earlyfrstrid);
684 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
686 /* No, stop it if its running */
687 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
688 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
689 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
690 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
694 /* if nothing was acked on this destination skip it */
695 if (net->net_ack == 0) {
696 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
697 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
701 if (net->net_ack2 > 0) {
703 * Karn's rule applies to clearing error count, this
706 net->error_count = 0;
707 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
708 SCTP_ADDR_NOT_REACHABLE) {
710 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
711 net->dest_state |= SCTP_ADDR_REACHABLE;
712 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
713 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
714 /* now was it the primary? if so restore */
715 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
716 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
720 * JRS 5/14/07 - If CMT PF is on and the destination
721 * is in PF state, set the destination to active
722 * state and set the cwnd to one or two MTU's based
723 * on whether PF1 or PF2 is being used.
725 * Should we stop any running T3 timer here?
727 if (sctp_cmt_on_off && sctp_cmt_pf && ((net->dest_state & SCTP_ADDR_PF) ==
729 net->dest_state &= ~SCTP_ADDR_PF;
730 net->cwnd = net->mtu * sctp_cmt_pf;
731 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
734 * Since the cwnd value is explicitly set,
735 * skip the code that updates the cwnd
738 goto skip_cwnd_update;
741 #ifdef JANA_CMT_FAST_RECOVERY
743 * CMT fast recovery code
746 * if (sctp_cmt_on_off == 1 &&
747 * net->fast_retran_loss_recovery &&
748 * net->will_exit_fast_recovery == 0) { @@@ Do something }
749 * else if (sctp_cmt_on_off == 0 &&
750 * asoc->fast_retran_loss_recovery && will_exit == 0) {
754 if (asoc->fast_retran_loss_recovery && will_exit == 0 && sctp_cmt_on_off == 0) {
756 * If we are in loss recovery we skip any cwnd
759 goto skip_cwnd_update;
762 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
765 if (accum_moved || (sctp_cmt_on_off && net->new_pseudo_cumack)) {
766 /* If the cumulative ack moved we can proceed */
767 if (net->cwnd <= net->ssthresh) {
768 /* We are in slow start */
769 if (net->flight_size + net->net_ack >=
772 sctp_hs_cwnd_increase(stcb, net);
777 dif = net->cwnd - (net->flight_size +
779 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
780 sctp_log_cwnd(stcb, net, net->net_ack,
781 SCTP_CWND_LOG_NOADV_SS);
785 /* We are in congestion avoidance */
786 if (net->flight_size + net->net_ack >=
789 * add to pba only if we had a
790 * cwnd's worth (or so) in flight OR
791 * the burst limit was applied.
793 net->partial_bytes_acked +=
797 * Do we need to increase (if pba is
800 if (net->partial_bytes_acked >=
803 net->partial_bytes_acked) {
804 net->partial_bytes_acked -=
807 net->partial_bytes_acked =
810 net->cwnd += net->mtu;
811 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
812 sctp_log_cwnd(stcb, net, net->mtu,
813 SCTP_CWND_LOG_FROM_CA);
816 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
817 sctp_log_cwnd(stcb, net, net->net_ack,
818 SCTP_CWND_LOG_NOADV_CA);
824 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
825 sctp_log_cwnd(stcb, net, net->net_ack,
826 SCTP_CWND_LOG_NOADV_CA);
828 dif = net->cwnd - (net->flight_size +
833 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
834 sctp_log_cwnd(stcb, net, net->mtu,
835 SCTP_CWND_LOG_NO_CUMACK);
840 * NOW, according to Karn's rule do we need to restore the
841 * RTO timer back? Check our net_ack2. If not set then we
842 * have a ambiguity.. i.e. all data ack'd was sent to more
846 /* restore any doubled timers */
847 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
848 if (net->RTO < stcb->asoc.minrto) {
849 net->RTO = stcb->asoc.minrto;
851 if (net->RTO > stcb->asoc.maxrto) {
852 net->RTO = stcb->asoc.maxrto;
859 sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
860 struct sctp_nets *net)
864 old_cwnd = net->cwnd;
866 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
867 net->ssthresh = net->cwnd / 2;
868 if (net->ssthresh < net->mtu) {
869 net->ssthresh = net->mtu;
870 /* here back off the timer as well, to slow us down */
873 net->cwnd = net->ssthresh;
874 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
875 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
880 sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
881 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
882 uint32_t * bottle_bw, uint32_t * on_queue)
886 int old_cwnd = net->cwnd;
888 /* need real RTT for this calc */
889 rtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
890 /* get bottle neck bw */
891 *bottle_bw = ntohl(cp->bottle_bw);
892 /* and whats on queue */
893 *on_queue = ntohl(cp->current_onq);
895 * adjust the on-queue if our flight is more it could be that the
896 * router has not yet gotten data "in-flight" to it
898 if (*on_queue < net->flight_size)
899 *on_queue = net->flight_size;
900 /* calculate the available space */
901 bw_avail = (*bottle_bw * rtt) / 1000;
902 if (bw_avail > *bottle_bw) {
904 * Cap the growth to no more than the bottle neck. This can
905 * happen as RTT slides up due to queues. It also means if
906 * you have more than a 1 second RTT with a empty queue you
907 * will be limited to the bottle_bw per second no matter if
908 * other points have 1/2 the RTT and you could get more
911 bw_avail = *bottle_bw;
913 if (*on_queue > bw_avail) {
915 * No room for anything else don't allow anything else to be
916 * "added to the fire".
918 int seg_inflight, seg_onqueue, my_portion;
920 net->partial_bytes_acked = 0;
922 /* how much are we over queue size? */
923 incr = *on_queue - bw_avail;
924 if (stcb->asoc.seen_a_sack_this_pkt) {
926 * undo any cwnd adjustment that the sack might have
929 net->cwnd = net->prev_cwnd;
931 /* Now how much of that is mine? */
932 seg_inflight = net->flight_size / net->mtu;
933 seg_onqueue = *on_queue / net->mtu;
934 my_portion = (incr * seg_inflight) / seg_onqueue;
936 /* Have I made an adjustment already */
937 if (net->cwnd > net->flight_size) {
939 * for this flight I made an adjustment we need to
940 * decrease the portion by a share our previous
945 diff_adj = net->cwnd - net->flight_size;
946 if (diff_adj > my_portion)
949 my_portion -= diff_adj;
952 * back down to the previous cwnd (assume we have had a sack
953 * before this packet). minus what ever portion of the
954 * overage is my fault.
956 net->cwnd -= my_portion;
958 /* we will NOT back down more than 1 MTU */
959 if (net->cwnd <= net->mtu) {
960 net->cwnd = net->mtu;
963 net->ssthresh = net->cwnd - 1;
966 * Take 1/4 of the space left or max burst up .. whichever
969 incr = min((bw_avail - *on_queue) >> 2,
970 stcb->asoc.max_burst * net->mtu);
973 if (net->cwnd > bw_avail) {
974 /* We can't exceed the pipe size */
975 net->cwnd = bw_avail;
977 if (net->cwnd < net->mtu) {
978 /* We always have 1 MTU */
979 net->cwnd = net->mtu;
981 if (net->cwnd - old_cwnd != 0) {
982 /* log only changes */
983 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
984 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
985 SCTP_CWND_LOG_FROM_SAT);
991 sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
992 struct sctp_nets *net, int burst_limit)
996 if (net->ssthresh < net->cwnd)
997 net->ssthresh = net->cwnd;
998 old_cwnd = net->cwnd;
999 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1001 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1002 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1007 sctp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
1008 struct sctp_tcb *stcb, struct sctp_nets *net)
1012 old_cwnd = net->cwnd;
1014 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
1016 * make a small adjustment to cwnd and force to CA.
1018 if (net->cwnd > net->mtu)
1019 /* drop down one MTU after sending */
1020 net->cwnd -= net->mtu;
1021 if (net->cwnd < net->ssthresh)
1022 /* still in SS move to CA */
1023 net->ssthresh = net->cwnd - 1;
1024 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1025 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
1030 * H-TCP congestion control. The algorithm is detailed in:
1031 * R.N.Shorten, D.J.Leith:
1032 * "H-TCP: TCP for high-speed and long-distance networks"
1033 * Proc. PFLDnet, Argonne, 2004.
1034 * http://www.hamilton.ie/net/htcp3.pdf
1038 static int use_rtt_scaling = 1;
1039 static int use_bandwidth_switch = 1;
1042 between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1044 return seq3 - seq2 >= seq1 - seq2;
1047 static inline uint32_t
1048 htcp_cong_time(struct htcp *ca)
1050 return sctp_get_tick_count() - ca->last_cong;
1053 static inline uint32_t
1054 htcp_ccount(struct htcp *ca)
1056 return htcp_cong_time(ca) / ca->minRTT;
1060 htcp_reset(struct htcp *ca)
1062 ca->undo_last_cong = ca->last_cong;
1063 ca->undo_maxRTT = ca->maxRTT;
1064 ca->undo_old_maxB = ca->old_maxB;
1065 ca->last_cong = sctp_get_tick_count();
1068 #ifdef SCTP_NOT_USED
1071 htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1073 net->htcp_ca.last_cong = net->htcp_ca.undo_last_cong;
1074 net->htcp_ca.maxRTT = net->htcp_ca.undo_maxRTT;
1075 net->htcp_ca.old_maxB = net->htcp_ca.undo_old_maxB;
1076 return max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->htcp_ca.beta) * net->mtu);
1082 measure_rtt(struct sctp_tcb *stcb, struct sctp_nets *net)
1084 uint32_t srtt = net->lastsa >> 3;
1086 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1087 if (net->htcp_ca.minRTT > srtt || !net->htcp_ca.minRTT)
1088 net->htcp_ca.minRTT = srtt;
1091 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->htcp_ca) > 3) {
1092 if (net->htcp_ca.maxRTT < net->htcp_ca.minRTT)
1093 net->htcp_ca.maxRTT = net->htcp_ca.minRTT;
1094 if (net->htcp_ca.maxRTT < srtt && srtt <= net->htcp_ca.maxRTT + MSEC_TO_TICKS(20))
1095 net->htcp_ca.maxRTT = srtt;
1100 measure_achieved_throughput(struct sctp_tcb *stcb, struct sctp_nets *net)
1102 uint32_t now = sctp_get_tick_count();
1104 if (net->fast_retran_ip == 0)
1105 net->htcp_ca.bytes_acked = net->net_ack;
1107 if (!use_bandwidth_switch)
1110 /* achieved throughput calculations */
1111 /* JRS - not 100% sure of this statement */
1112 if (net->fast_retran_ip == 1) {
1113 net->htcp_ca.bytecount = 0;
1114 net->htcp_ca.lasttime = now;
1117 net->htcp_ca.bytecount += net->net_ack;
1119 if (net->htcp_ca.bytecount >= net->cwnd - ((net->htcp_ca.alpha >> 7 ? : 1) * net->mtu)
1120 && now - net->htcp_ca.lasttime >= net->htcp_ca.minRTT
1121 && net->htcp_ca.minRTT > 0) {
1122 uint32_t cur_Bi = net->htcp_ca.bytecount / net->mtu * hz / (now - net->htcp_ca.lasttime);
1124 if (htcp_ccount(&net->htcp_ca) <= 3) {
1125 /* just after backoff */
1126 net->htcp_ca.minB = net->htcp_ca.maxB = net->htcp_ca.Bi = cur_Bi;
1128 net->htcp_ca.Bi = (3 * net->htcp_ca.Bi + cur_Bi) / 4;
1129 if (net->htcp_ca.Bi > net->htcp_ca.maxB)
1130 net->htcp_ca.maxB = net->htcp_ca.Bi;
1131 if (net->htcp_ca.minB > net->htcp_ca.maxB)
1132 net->htcp_ca.minB = net->htcp_ca.maxB;
1134 net->htcp_ca.bytecount = 0;
1135 net->htcp_ca.lasttime = now;
1140 htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
1142 if (use_bandwidth_switch) {
1143 uint32_t maxB = ca->maxB;
1144 uint32_t old_maxB = ca->old_maxB;
1146 ca->old_maxB = ca->maxB;
1148 if (!between(5 * maxB, 4 * old_maxB, 6 * old_maxB)) {
1149 ca->beta = BETA_MIN;
1154 if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) {
1155 ca->beta = (minRTT << 7) / maxRTT;
1156 if (ca->beta < BETA_MIN)
1157 ca->beta = BETA_MIN;
1158 else if (ca->beta > BETA_MAX)
1159 ca->beta = BETA_MAX;
1161 ca->beta = BETA_MIN;
1167 htcp_alpha_update(struct htcp *ca)
1169 uint32_t minRTT = ca->minRTT;
1170 uint32_t factor = 1;
1171 uint32_t diff = htcp_cong_time(ca);
1173 if (diff > (uint32_t) hz) {
1175 factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
1177 if (use_rtt_scaling && minRTT) {
1178 uint32_t scale = (hz << 3) / (10 * minRTT);
1180 scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to
1181 * interval [0.5,10]<<3 */
1182 factor = (factor << 3) / scale;
1186 ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
1188 ca->alpha = ALPHA_BASE;
1191 /* After we have the rtt data to calculate beta, we'd still prefer to wait one
1192 * rtt before we adjust our beta to ensure we are working from a consistent
1195 * This function should be called when we hit a congestion event since only at
1196 * that point do we really have a real sense of maxRTT (the queues en route
1197 * were getting just too full now).
1200 htcp_param_update(struct sctp_tcb *stcb, struct sctp_nets *net)
1202 uint32_t minRTT = net->htcp_ca.minRTT;
1203 uint32_t maxRTT = net->htcp_ca.maxRTT;
1205 htcp_beta_update(&net->htcp_ca, minRTT, maxRTT);
1206 htcp_alpha_update(&net->htcp_ca);
1209 * add slowly fading memory for maxRTT to accommodate routing
1212 if (minRTT > 0 && maxRTT > minRTT)
1213 net->htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100;
1217 htcp_recalc_ssthresh(struct sctp_tcb *stcb, struct sctp_nets *net)
1219 htcp_param_update(stcb, net);
1220 return max(((net->cwnd / net->mtu * net->htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu);
1224 htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
1227 * How to handle these functions?
1228 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
1231 if (net->cwnd <= net->ssthresh) {
1232 /* We are in slow start */
1233 if (net->flight_size + net->net_ack >= net->cwnd) {
1234 if (net->net_ack > (net->mtu * sctp_L2_abc_variable)) {
1235 net->cwnd += (net->mtu * sctp_L2_abc_variable);
1236 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1237 sctp_log_cwnd(stcb, net, net->mtu,
1238 SCTP_CWND_LOG_FROM_SS);
1241 net->cwnd += net->net_ack;
1242 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1243 sctp_log_cwnd(stcb, net, net->net_ack,
1244 SCTP_CWND_LOG_FROM_SS);
1250 dif = net->cwnd - (net->flight_size +
1252 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
1253 sctp_log_cwnd(stcb, net, net->net_ack,
1254 SCTP_CWND_LOG_NOADV_SS);
1258 measure_rtt(stcb, net);
1261 * In dangerous area, increase slowly. In theory this is
1262 * net->cwnd += alpha / net->cwnd
1264 /* What is snd_cwnd_cnt?? */
1265 if (((net->partial_bytes_acked / net->mtu * net->htcp_ca.alpha) >> 7) * net->mtu >= net->cwnd) {
1267 * Does SCTP have a cwnd clamp?
1268 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
1270 net->cwnd += net->mtu;
1271 net->partial_bytes_acked = 0;
1272 htcp_alpha_update(&net->htcp_ca);
1273 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1274 sctp_log_cwnd(stcb, net, net->mtu,
1275 SCTP_CWND_LOG_FROM_CA);
1278 net->partial_bytes_acked += net->net_ack;
1279 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
1280 sctp_log_cwnd(stcb, net, net->net_ack,
1281 SCTP_CWND_LOG_NOADV_CA);
1285 net->htcp_ca.bytes_acked = net->mtu;
1289 #ifdef SCTP_NOT_USED
1290 /* Lower bound on congestion window. */
1292 htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
1294 return net->ssthresh;
1300 htcp_init(struct sctp_tcb *stcb, struct sctp_nets *net)
1302 memset(&net->htcp_ca, 0, sizeof(struct htcp));
1303 net->htcp_ca.alpha = ALPHA_BASE;
1304 net->htcp_ca.beta = BETA_MIN;
1305 net->htcp_ca.bytes_acked = net->mtu;
1306 net->htcp_ca.last_cong = sctp_get_tick_count();
1310 sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
1313 * We take the max of the burst limit times a MTU or the
1314 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
1316 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1317 /* we always get at LEAST 2 MTU's */
1318 if (net->cwnd < (2 * net->mtu)) {
1319 net->cwnd = 2 * net->mtu;
1321 net->ssthresh = stcb->asoc.peers_rwnd;
1322 htcp_init(stcb, net);
1324 if (sctp_logging_level & (SCTP_CWND_MONITOR_ENABLE | SCTP_CWND_LOGGING_ENABLE)) {
1325 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
1330 sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1331 struct sctp_association *asoc,
1332 int accum_moved, int reneged_all, int will_exit)
1334 struct sctp_nets *net;
1336 /******************************/
1337 /* update cwnd and Early FR */
1338 /******************************/
1339 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1341 #ifdef JANA_CMT_FAST_RECOVERY
1343 * CMT fast recovery code. Need to debug.
1345 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1346 if (compare_with_wrap(asoc->last_acked_seq,
1347 net->fast_recovery_tsn, MAX_TSN) ||
1348 (asoc->last_acked_seq == net->fast_recovery_tsn) ||
1349 compare_with_wrap(net->pseudo_cumack, net->fast_recovery_tsn, MAX_TSN) ||
1350 (net->pseudo_cumack == net->fast_recovery_tsn)) {
1351 net->will_exit_fast_recovery = 1;
1355 if (sctp_early_fr) {
1357 * So, first of all do we need to have a Early FR
1360 if (((TAILQ_FIRST(&asoc->sent_queue)) &&
1361 (net->ref_count > 1) &&
1362 (net->flight_size < net->cwnd)) ||
1365 * yes, so in this case stop it if its
1366 * running, and then restart it. Reneging
1367 * all is a special case where we want to
1368 * run the Early FR timer and then force the
1369 * last few unacked to be sent, causing us
1370 * to illicit a sack with gaps to force out
1373 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1374 SCTP_STAT_INCR(sctps_earlyfrstpidsck2);
1375 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1376 SCTP_FROM_SCTP_INDATA + SCTP_LOC_20);
1378 SCTP_STAT_INCR(sctps_earlyfrstrid);
1379 sctp_timer_start(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net);
1381 /* No, stop it if its running */
1382 if (SCTP_OS_TIMER_PENDING(&net->fr_timer.timer)) {
1383 SCTP_STAT_INCR(sctps_earlyfrstpidsck3);
1384 sctp_timer_stop(SCTP_TIMER_TYPE_EARLYFR, stcb->sctp_ep, stcb, net,
1385 SCTP_FROM_SCTP_INDATA + SCTP_LOC_21);
1389 /* if nothing was acked on this destination skip it */
1390 if (net->net_ack == 0) {
1391 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
1392 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1396 if (net->net_ack2 > 0) {
1398 * Karn's rule applies to clearing error count, this
1401 net->error_count = 0;
1402 if ((net->dest_state & SCTP_ADDR_NOT_REACHABLE) ==
1403 SCTP_ADDR_NOT_REACHABLE) {
1404 /* addr came good */
1405 net->dest_state &= ~SCTP_ADDR_NOT_REACHABLE;
1406 net->dest_state |= SCTP_ADDR_REACHABLE;
1407 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
1408 SCTP_RECEIVED_SACK, (void *)net, SCTP_SO_NOT_LOCKED);
1409 /* now was it the primary? if so restore */
1410 if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
1411 (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
1415 * JRS 5/14/07 - If CMT PF is on and the destination
1416 * is in PF state, set the destination to active
1417 * state and set the cwnd to one or two MTU's based
1418 * on whether PF1 or PF2 is being used.
1420 * Should we stop any running T3 timer here?
1422 if (sctp_cmt_on_off && sctp_cmt_pf && ((net->dest_state & SCTP_ADDR_PF) ==
1424 net->dest_state &= ~SCTP_ADDR_PF;
1425 net->cwnd = net->mtu * sctp_cmt_pf;
1426 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1429 * Since the cwnd value is explicitly set,
1430 * skip the code that updates the cwnd
1433 goto skip_cwnd_update;
1436 #ifdef JANA_CMT_FAST_RECOVERY
1438 * CMT fast recovery code
1441 * if (sctp_cmt_on_off == 1 &&
1442 * net->fast_retran_loss_recovery &&
1443 * net->will_exit_fast_recovery == 0) { @@@ Do something }
1444 * else if (sctp_cmt_on_off == 0 &&
1445 * asoc->fast_retran_loss_recovery && will_exit == 0) {
1449 if (asoc->fast_retran_loss_recovery && will_exit == 0 && sctp_cmt_on_off == 0) {
1451 * If we are in loss recovery we skip any cwnd
1454 goto skip_cwnd_update;
1457 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1460 if (accum_moved || (sctp_cmt_on_off && net->new_pseudo_cumack)) {
1461 htcp_cong_avoid(stcb, net);
1462 measure_achieved_throughput(stcb, net);
1464 if (sctp_logging_level & SCTP_CWND_LOGGING_ENABLE) {
1465 sctp_log_cwnd(stcb, net, net->mtu,
1466 SCTP_CWND_LOG_NO_CUMACK);
1471 * NOW, according to Karn's rule do we need to restore the
1472 * RTO timer back? Check our net_ack2. If not set then we
1473 * have a ambiguity.. i.e. all data ack'd was sent to more
1476 if (net->net_ack2) {
1477 /* restore any doubled timers */
1478 net->RTO = ((net->lastsa >> 2) + net->lastsv) >> 1;
1479 if (net->RTO < stcb->asoc.minrto) {
1480 net->RTO = stcb->asoc.minrto;
1482 if (net->RTO > stcb->asoc.maxrto) {
1483 net->RTO = stcb->asoc.maxrto;
1490 sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
1491 struct sctp_association *asoc)
1493 struct sctp_nets *net;
1496 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off == 1) &&
1497 * (net->fast_retran_loss_recovery == 0)))
1499 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1500 if ((asoc->fast_retran_loss_recovery == 0) || (sctp_cmt_on_off == 1)) {
1501 /* out of a RFC2582 Fast recovery window? */
1502 if (net->net_ack > 0) {
1504 * per section 7.2.3, are there any
1505 * destinations that had a fast retransmit
1506 * to them. If so what we need to do is
1507 * adjust ssthresh and cwnd.
1509 struct sctp_tmit_chunk *lchk;
1510 int old_cwnd = net->cwnd;
1512 /* JRS - reset as if state were changed */
1513 htcp_reset(&net->htcp_ca);
1514 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1515 net->cwnd = net->ssthresh;
1516 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1517 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1518 SCTP_CWND_LOG_FROM_FR);
1520 lchk = TAILQ_FIRST(&asoc->send_queue);
1522 net->partial_bytes_acked = 0;
1523 /* Turn on fast recovery window */
1524 asoc->fast_retran_loss_recovery = 1;
1526 /* Mark end of the window */
1527 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1529 asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1533 * CMT fast recovery -- per destination
1534 * recovery variable.
1536 net->fast_retran_loss_recovery = 1;
1539 /* Mark end of the window */
1540 net->fast_recovery_tsn = asoc->sending_seq - 1;
1542 net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
1546 * Disable Nonce Sum Checking and store the
1549 asoc->nonce_sum_check = 0;
1550 asoc->nonce_resync_tsn = asoc->fast_recovery_tsn + 1;
1552 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1553 stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
1554 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1555 stcb->sctp_ep, stcb, net);
1557 } else if (net->net_ack > 0) {
1559 * Mark a peg that we WOULD have done a cwnd
1560 * reduction but RFC2582 prevented this action.
1562 SCTP_STAT_INCR(sctps_fastretransinrtt);
1568 sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
1569 struct sctp_nets *net)
1571 int old_cwnd = net->cwnd;
1573 /* JRS - reset as if the state were being changed to timeout */
1574 htcp_reset(&net->htcp_ca);
1575 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1576 net->cwnd = net->mtu;
1577 /* floor of 1 mtu */
1578 if (net->cwnd < net->mtu)
1579 net->cwnd = net->mtu;
1580 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1581 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1583 net->partial_bytes_acked = 0;
1587 sctp_htcp_cwnd_update_after_fr_timer(struct sctp_inpcb *inp,
1588 struct sctp_tcb *stcb, struct sctp_nets *net)
1592 old_cwnd = net->cwnd;
1594 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_EARLY_FR_TMR, SCTP_SO_NOT_LOCKED);
1595 net->htcp_ca.last_cong = sctp_get_tick_count();
1597 * make a small adjustment to cwnd and force to CA.
1599 if (net->cwnd > net->mtu)
1600 /* drop down one MTU after sending */
1601 net->cwnd -= net->mtu;
1602 if (net->cwnd < net->ssthresh)
1603 /* still in SS move to CA */
1604 net->ssthresh = net->cwnd - 1;
1605 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1606 sctp_log_cwnd(stcb, net, (old_cwnd - net->cwnd), SCTP_CWND_LOG_FROM_FR);
1611 sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
1612 struct sctp_nets *net)
1616 old_cwnd = net->cwnd;
1618 /* JRS - reset hctp as if state changed */
1619 htcp_reset(&net->htcp_ca);
1620 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1621 net->ssthresh = htcp_recalc_ssthresh(stcb, net);
1622 if (net->ssthresh < net->mtu) {
1623 net->ssthresh = net->mtu;
1624 /* here back off the timer as well, to slow us down */
1627 net->cwnd = net->ssthresh;
1628 if (sctp_logging_level & SCTP_CWND_MONITOR_ENABLE) {
1629 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);