blob: ace7464d4a90b429e5e1d4c543f7d459160cc20e [file] [log] [blame]
James Kuszmaul4cb043c2021-01-17 11:25:51 -08001/*-
2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
15 *
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifdef __FreeBSD__
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 310590 2016-12-26 11:06:41Z tuexen $");
36#endif
37
38#include <netinet/sctp_os.h>
39#include <netinet/sctp_var.h>
40#include <netinet/sctp_sysctl.h>
41#include <netinet/sctp_pcb.h>
42#include <netinet/sctp_header.h>
43#include <netinet/sctputil.h>
44#include <netinet/sctp_output.h>
45#include <netinet/sctp_input.h>
46#include <netinet/sctp_indata.h>
47#include <netinet/sctp_uio.h>
48#include <netinet/sctp_timer.h>
49#include <netinet/sctp_auth.h>
50#include <netinet/sctp_asconf.h>
51#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
52#include <netinet/sctp_dtrace_declare.h>
53#endif
54
55#define SHIFT_MPTCP_MULTI_N 40
56#define SHIFT_MPTCP_MULTI_Z 16
57#define SHIFT_MPTCP_MULTI 8
58
59static void
60sctp_enforce_cwnd_limit(struct sctp_association *assoc, struct sctp_nets *net)
61{
62 if ((assoc->max_cwnd > 0) &&
63 (net->cwnd > assoc->max_cwnd) &&
64 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
65 net->cwnd = assoc->max_cwnd ;
66 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
67 net->cwnd = net->mtu - sizeof(struct sctphdr);
68 }
69 }
70}
71
72static void
73sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
74{
75 struct sctp_association *assoc;
76 uint32_t cwnd_in_mtu;
77
78 assoc = &stcb->asoc;
79 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
80 if (cwnd_in_mtu == 0) {
81 /* Using 0 means that the value of RFC 4960 is used. */
82 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
83 } else {
84 /*
85 * We take the minimum of the burst limit and the
86 * initial congestion window.
87 */
88 if ((assoc->max_burst > 0) && (cwnd_in_mtu > assoc->max_burst))
89 cwnd_in_mtu = assoc->max_burst;
90 net->cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
91 }
92 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
93 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
94 /* In case of resource pooling initialize appropriately */
95 net->cwnd /= assoc->numnets;
96 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
97 net->cwnd = net->mtu - sizeof(struct sctphdr);
98 }
99 }
100 sctp_enforce_cwnd_limit(assoc, net);
101 net->ssthresh = assoc->peers_rwnd;
102#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
103 SDT_PROBE5(sctp, cwnd, net, init,
104 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
105 0, net->cwnd);
106#endif
107 if (SCTP_BASE_SYSCTL(sctp_logging_level) &
108 (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) {
109 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
110 }
111}
112
113static void
114sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
115 struct sctp_association *asoc)
116{
117 struct sctp_nets *net;
118 uint32_t t_ssthresh, t_cwnd;
119 uint64_t t_ucwnd_sbw;
120
121 /* MT FIXME: Don't compute this over and over again */
122 t_ssthresh = 0;
123 t_cwnd = 0;
124 t_ucwnd_sbw = 0;
125 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
126 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
127 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
128 t_ssthresh += net->ssthresh;
129 t_cwnd += net->cwnd;
130 if (net->lastsa > 0) {
131 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa;
132 }
133 }
134 if (t_ucwnd_sbw == 0) {
135 t_ucwnd_sbw = 1;
136 }
137 }
138
139 /*-
140 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
141 * (net->fast_retran_loss_recovery == 0)))
142 */
143 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
144 if ((asoc->fast_retran_loss_recovery == 0) ||
145 (asoc->sctp_cmt_on_off > 0)) {
146 /* out of a RFC2582 Fast recovery window? */
147 if (net->net_ack > 0) {
148 /*
149 * per section 7.2.3, are there any
150 * destinations that had a fast retransmit
151 * to them. If so what we need to do is
152 * adjust ssthresh and cwnd.
153 */
154 struct sctp_tmit_chunk *lchk;
155 int old_cwnd = net->cwnd;
156
157 if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) ||
158 (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) {
159 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) {
160 net->ssthresh = (uint32_t)(((uint64_t)4 *
161 (uint64_t)net->mtu *
162 (uint64_t)net->ssthresh) /
163 (uint64_t)t_ssthresh);
164
165 }
166 if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
167 uint32_t srtt;
168
169 srtt = net->lastsa;
170 /* lastsa>>3; we don't need to devide ...*/
171 if (srtt == 0) {
172 srtt = 1;
173 }
174 /* Short Version => Equal to Contel Version MBe */
175 net->ssthresh = (uint32_t) (((uint64_t)4 *
176 (uint64_t)net->mtu *
177 (uint64_t)net->cwnd) /
178 ((uint64_t)srtt *
179 t_ucwnd_sbw));
180 /* INCREASE FACTOR */;
181 }
182 if ((net->cwnd > t_cwnd / 2) &&
183 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
184 net->ssthresh = net->cwnd - t_cwnd / 2;
185 }
186 if (net->ssthresh < net->mtu) {
187 net->ssthresh = net->mtu;
188 }
189 } else {
190 net->ssthresh = net->cwnd / 2;
191 if (net->ssthresh < (net->mtu * 2)) {
192 net->ssthresh = 2 * net->mtu;
193 }
194 }
195 net->cwnd = net->ssthresh;
196 sctp_enforce_cwnd_limit(asoc, net);
197#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
198 SDT_PROBE5(sctp, cwnd, net, fr,
199 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
200 old_cwnd, net->cwnd);
201#endif
202 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
203 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
204 SCTP_CWND_LOG_FROM_FR);
205 }
206 lchk = TAILQ_FIRST(&asoc->send_queue);
207
208 net->partial_bytes_acked = 0;
209 /* Turn on fast recovery window */
210 asoc->fast_retran_loss_recovery = 1;
211 if (lchk == NULL) {
212 /* Mark end of the window */
213 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
214 } else {
215 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
216 }
217
218 /*
219 * CMT fast recovery -- per destination
220 * recovery variable.
221 */
222 net->fast_retran_loss_recovery = 1;
223
224 if (lchk == NULL) {
225 /* Mark end of the window */
226 net->fast_recovery_tsn = asoc->sending_seq - 1;
227 } else {
228 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
229 }
230
231 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
232 stcb->sctp_ep, stcb, net,
233 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_1);
234 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
235 stcb->sctp_ep, stcb, net);
236 }
237 } else if (net->net_ack > 0) {
238 /*
239 * Mark a peg that we WOULD have done a cwnd
240 * reduction but RFC2582 prevented this action.
241 */
242 SCTP_STAT_INCR(sctps_fastretransinrtt);
243 }
244 }
245}
246
247/* Defines for instantaneous bw decisions */
248#define SCTP_INST_LOOSING 1 /* Losing to other flows */
249#define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
250#define SCTP_INST_GAINING 3 /* Gaining, step down possible */
251
252
253#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
254static int
255cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
256 uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
257#else
258static int
259cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw,
260 uint64_t rtt_offset, uint8_t inst_ind)
261#endif
262{
263#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
264 uint64_t oth, probepoint;
265#endif
266
267#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
268 probepoint = (((uint64_t)net->cwnd) << 32);
269#endif
270 if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
271 /*
272 * rtt increased
273 * we don't update bw.. so we don't
274 * update the rtt either.
275 */
276#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
277 /* Probe point 5 */
278 probepoint |= ((5 << 16) | 1);
279 SDT_PROBE5(sctp, cwnd, net, rttvar,
280 vtag,
281 ((net->cc_mod.rtcc.lbw << 32) | nbw),
282 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
283 net->flight_size,
284 probepoint);
285#endif
286 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
287 if (net->cc_mod.rtcc.last_step_state == 5)
288 net->cc_mod.rtcc.step_cnt++;
289 else
290 net->cc_mod.rtcc.step_cnt = 1;
291 net->cc_mod.rtcc.last_step_state = 5;
292 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
293 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
294 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
295 /* Try a step down */
296#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
297 oth = net->cc_mod.rtcc.vol_reduce;
298 oth <<= 16;
299 oth |= net->cc_mod.rtcc.step_cnt;
300 oth <<= 16;
301 oth |= net->cc_mod.rtcc.last_step_state;
302 SDT_PROBE5(sctp, cwnd, net, rttstep,
303 vtag,
304 ((net->cc_mod.rtcc.lbw << 32) | nbw),
305 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
306 oth,
307 probepoint);
308#endif
309 if (net->cwnd > (4 * net->mtu)) {
310 net->cwnd -= net->mtu;
311 net->cc_mod.rtcc.vol_reduce++;
312 } else {
313 net->cc_mod.rtcc.step_cnt = 0;
314 }
315 }
316 }
317 return (1);
318 }
319 if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
320 /*
321 * rtt decreased, there could be more room.
322 * we update both the bw and the rtt here to
323 * lock this in as a good step down.
324 */
325#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
326 /* Probe point 6 */
327 probepoint |= ((6 << 16) | 0);
328 SDT_PROBE5(sctp, cwnd, net, rttvar,
329 vtag,
330 ((net->cc_mod.rtcc.lbw << 32) | nbw),
331 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
332 net->flight_size,
333 probepoint);
334#endif
335 if (net->cc_mod.rtcc.steady_step) {
336#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
337 oth = net->cc_mod.rtcc.vol_reduce;
338 oth <<= 16;
339 oth |= net->cc_mod.rtcc.step_cnt;
340 oth <<= 16;
341 oth |= net->cc_mod.rtcc.last_step_state;
342 SDT_PROBE5(sctp, cwnd, net, rttstep,
343 vtag,
344 ((net->cc_mod.rtcc.lbw << 32) | nbw),
345 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
346 oth,
347 probepoint);
348#endif
349 if ((net->cc_mod.rtcc.last_step_state == 5) &&
350 (net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
351 /* Step down worked */
352 net->cc_mod.rtcc.step_cnt = 0;
353 return (1);
354 } else {
355 net->cc_mod.rtcc.last_step_state = 6;
356 net->cc_mod.rtcc.step_cnt = 0;
357 }
358 }
359 net->cc_mod.rtcc.lbw = nbw;
360 net->cc_mod.rtcc.lbw_rtt = net->rtt;
361 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
362 if (inst_ind == SCTP_INST_GAINING)
363 return (1);
364 else if (inst_ind == SCTP_INST_NEUTRAL)
365 return (1);
366 else
367 return (0);
368 }
369 /* Ok bw and rtt remained the same .. no update to any
370 */
371#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
372 /* Probe point 7 */
373 probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
374 SDT_PROBE5(sctp, cwnd, net, rttvar,
375 vtag,
376 ((net->cc_mod.rtcc.lbw << 32) | nbw),
377 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
378 net->flight_size,
379 probepoint);
380#endif
381 if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
382 if (net->cc_mod.rtcc.last_step_state == 5)
383 net->cc_mod.rtcc.step_cnt++;
384 else
385 net->cc_mod.rtcc.step_cnt = 1;
386 net->cc_mod.rtcc.last_step_state = 5;
387 if ((net->cc_mod.rtcc.step_cnt == net->cc_mod.rtcc.steady_step) ||
388 ((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
389 ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
390 /* Try a step down */
391 if (net->cwnd > (4 * net->mtu)) {
392 net->cwnd -= net->mtu;
393 net->cc_mod.rtcc.vol_reduce++;
394 return (1);
395 } else {
396 net->cc_mod.rtcc.step_cnt = 0;
397 }
398 }
399 }
400 if (inst_ind == SCTP_INST_GAINING)
401 return (1);
402 else if (inst_ind == SCTP_INST_NEUTRAL)
403 return (1);
404 else
405 return ((int)net->cc_mod.rtcc.ret_from_eq);
406}
407
408#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
409static int
410cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
411 uint64_t vtag, uint8_t inst_ind)
412#else
413static int
414cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
415 uint8_t inst_ind)
416#endif
417{
418#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
419 uint64_t oth, probepoint;
420#endif
421
422 /* Bandwidth decreased.*/
423#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
424 probepoint = (((uint64_t)net->cwnd) << 32);
425#endif
426 if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) {
427 /* rtt increased */
428 /* Did we add more */
429 if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
430 (inst_ind != SCTP_INST_LOOSING)) {
431 /* We caused it maybe.. back off? */
432#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
433 /* PROBE POINT 1 */
434 probepoint |= ((1 << 16) | 1);
435 SDT_PROBE5(sctp, cwnd, net, rttvar,
436 vtag,
437 ((net->cc_mod.rtcc.lbw << 32) | nbw),
438 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
439 net->flight_size,
440 probepoint);
441#endif
442 if (net->cc_mod.rtcc.ret_from_eq) {
443 /* Switch over to CA if we are less aggressive */
444 net->ssthresh = net->cwnd-1;
445 net->partial_bytes_acked = 0;
446 }
447 return (1);
448 }
449#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
450 /* Probe point 2 */
451 probepoint |= ((2 << 16) | 0);
452 SDT_PROBE5(sctp, cwnd, net, rttvar,
453 vtag,
454 ((net->cc_mod.rtcc.lbw << 32) | nbw),
455 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
456 net->flight_size,
457 probepoint);
458#endif
459 /* Someone else - fight for more? */
460 if (net->cc_mod.rtcc.steady_step) {
461#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
462 oth = net->cc_mod.rtcc.vol_reduce;
463 oth <<= 16;
464 oth |= net->cc_mod.rtcc.step_cnt;
465 oth <<= 16;
466 oth |= net->cc_mod.rtcc.last_step_state;
467 SDT_PROBE5(sctp, cwnd, net, rttstep,
468 vtag,
469 ((net->cc_mod.rtcc.lbw << 32) | nbw),
470 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
471 oth,
472 probepoint);
473#endif
474 /* Did we voluntarily give up some? if so take
475 * one back please
476 */
477 if ((net->cc_mod.rtcc.vol_reduce) &&
478 (inst_ind != SCTP_INST_GAINING)) {
479 net->cwnd += net->mtu;
480 sctp_enforce_cwnd_limit(&stcb->asoc, net);
481 net->cc_mod.rtcc.vol_reduce--;
482 }
483 net->cc_mod.rtcc.last_step_state = 2;
484 net->cc_mod.rtcc.step_cnt = 0;
485 }
486 goto out_decision;
487 } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
488 /* bw & rtt decreased */
489#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
490 /* Probe point 3 */
491 probepoint |= ((3 << 16) | 0);
492 SDT_PROBE5(sctp, cwnd, net, rttvar,
493 vtag,
494 ((net->cc_mod.rtcc.lbw << 32) | nbw),
495 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
496 net->flight_size,
497 probepoint);
498#endif
499 if (net->cc_mod.rtcc.steady_step) {
500#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
501 oth = net->cc_mod.rtcc.vol_reduce;
502 oth <<= 16;
503 oth |= net->cc_mod.rtcc.step_cnt;
504 oth <<= 16;
505 oth |= net->cc_mod.rtcc.last_step_state;
506 SDT_PROBE5(sctp, cwnd, net, rttstep,
507 vtag,
508 ((net->cc_mod.rtcc.lbw << 32) | nbw),
509 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
510 oth,
511 probepoint);
512#endif
513 if ((net->cc_mod.rtcc.vol_reduce) &&
514 (inst_ind != SCTP_INST_GAINING)) {
515 net->cwnd += net->mtu;
516 sctp_enforce_cwnd_limit(&stcb->asoc, net);
517 net->cc_mod.rtcc.vol_reduce--;
518 }
519 net->cc_mod.rtcc.last_step_state = 3;
520 net->cc_mod.rtcc.step_cnt = 0;
521 }
522 goto out_decision;
523 }
524 /* The bw decreased but rtt stayed the same */
525#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
526 /* Probe point 4 */
527 probepoint |= ((4 << 16) | 0);
528 SDT_PROBE5(sctp, cwnd, net, rttvar,
529 vtag,
530 ((net->cc_mod.rtcc.lbw << 32) | nbw),
531 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
532 net->flight_size,
533 probepoint);
534#endif
535 if (net->cc_mod.rtcc.steady_step) {
536#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
537 oth = net->cc_mod.rtcc.vol_reduce;
538 oth <<= 16;
539 oth |= net->cc_mod.rtcc.step_cnt;
540 oth <<= 16;
541 oth |= net->cc_mod.rtcc.last_step_state;
542 SDT_PROBE5(sctp, cwnd, net, rttstep,
543 vtag,
544 ((net->cc_mod.rtcc.lbw << 32) | nbw),
545 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
546 oth,
547 probepoint);
548#endif
549 if ((net->cc_mod.rtcc.vol_reduce) &&
550 (inst_ind != SCTP_INST_GAINING)) {
551 net->cwnd += net->mtu;
552 sctp_enforce_cwnd_limit(&stcb->asoc, net);
553 net->cc_mod.rtcc.vol_reduce--;
554 }
555 net->cc_mod.rtcc.last_step_state = 4;
556 net->cc_mod.rtcc.step_cnt = 0;
557 }
558out_decision:
559 net->cc_mod.rtcc.lbw = nbw;
560 net->cc_mod.rtcc.lbw_rtt = net->rtt;
561 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
562 if (inst_ind == SCTP_INST_GAINING) {
563 return (1);
564 } else {
565 return (0);
566 }
567}
568
569#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
570static int
571cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
572#else
573static int
574cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw)
575#endif
576{
577#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
578 uint64_t oth, probepoint;
579
580#endif
581 /* BW increased, so update and
582 * return 0, since all actions in
583 * our table say to do the normal CC
584 * update. Note that we pay no attention to
585 * the inst_ind since our overall sum is increasing.
586 */
587#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
588 /* PROBE POINT 0 */
589 probepoint = (((uint64_t)net->cwnd) << 32);
590 SDT_PROBE5(sctp, cwnd, net, rttvar,
591 vtag,
592 ((net->cc_mod.rtcc.lbw << 32) | nbw),
593 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
594 net->flight_size,
595 probepoint);
596#endif
597 if (net->cc_mod.rtcc.steady_step) {
598#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
599 oth = net->cc_mod.rtcc.vol_reduce;
600 oth <<= 16;
601 oth |= net->cc_mod.rtcc.step_cnt;
602 oth <<= 16;
603 oth |= net->cc_mod.rtcc.last_step_state;
604 SDT_PROBE5(sctp, cwnd, net, rttstep,
605 vtag,
606 ((net->cc_mod.rtcc.lbw << 32) | nbw),
607 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
608 oth,
609 probepoint);
610#endif
611 net->cc_mod.rtcc.last_step_state = 0;
612 net->cc_mod.rtcc.step_cnt = 0;
613 net->cc_mod.rtcc.vol_reduce = 0;
614 }
615 net->cc_mod.rtcc.lbw = nbw;
616 net->cc_mod.rtcc.lbw_rtt = net->rtt;
617 net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
618 return (0);
619}
620
621/* RTCC Algorithm to limit growth of cwnd, return
622 * true if you want to NOT allow cwnd growth
623 */
624static int
625cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
626{
627 uint64_t bw_offset, rtt_offset;
628#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
629 uint64_t probepoint, rtt, vtag;
630#endif
631 uint64_t bytes_for_this_rtt, inst_bw;
632 uint64_t div, inst_off;
633 int bw_shift;
634 uint8_t inst_ind;
635 int ret;
636 /*-
637 * Here we need to see if we want
638 * to limit cwnd growth due to increase
639 * in overall rtt but no increase in bw.
640 * We use the following table to figure
641 * out what we should do. When we return
642 * 0, cc update goes on as planned. If we
643 * return 1, then no cc update happens and cwnd
644 * stays where it is at.
645 * ----------------------------------
646 * BW | RTT | Action
647 * *********************************
648 * INC | INC | return 0
649 * ----------------------------------
650 * INC | SAME | return 0
651 * ----------------------------------
652 * INC | DECR | return 0
653 * ----------------------------------
654 * SAME | INC | return 1
655 * ----------------------------------
656 * SAME | SAME | return 1
657 * ----------------------------------
658 * SAME | DECR | return 0
659 * ----------------------------------
660 * DECR | INC | return 0 or 1 based on if we caused.
661 * ----------------------------------
662 * DECR | SAME | return 0
663 * ----------------------------------
664 * DECR | DECR | return 0
665 * ----------------------------------
666 *
667 * We are a bit fuzz on what an increase or
668 * decrease is. For BW it is the same if
669 * it did not change within 1/64th. For
670 * RTT it stayed the same if it did not
671 * change within 1/32nd
672 */
673 bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
674#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
675 rtt = stcb->asoc.my_vtag;
676 vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
677 probepoint = (((uint64_t)net->cwnd) << 32);
678 rtt = net->rtt;
679#endif
680 if (net->cc_mod.rtcc.rtt_set_this_sack) {
681 net->cc_mod.rtcc.rtt_set_this_sack = 0;
682 bytes_for_this_rtt = net->cc_mod.rtcc.bw_bytes - net->cc_mod.rtcc.bw_bytes_at_last_rttc;
683 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
684 if (net->rtt) {
685 div = net->rtt / 1000;
686 if (div) {
687 inst_bw = bytes_for_this_rtt / div;
688 inst_off = inst_bw >> bw_shift;
689 if (inst_bw > nbw)
690 inst_ind = SCTP_INST_GAINING;
691 else if ((inst_bw+inst_off) < nbw)
692 inst_ind = SCTP_INST_LOOSING;
693 else
694 inst_ind = SCTP_INST_NEUTRAL;
695#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
696 probepoint |= ((0xb << 16) | inst_ind);
697#endif
698 } else {
699 inst_ind = net->cc_mod.rtcc.last_inst_ind;
700#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
701 inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
702 /* Can't determine do not change */
703 probepoint |= ((0xc << 16) | inst_ind);
704#endif
705 }
706 } else {
707 inst_ind = net->cc_mod.rtcc.last_inst_ind;
708#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
709 inst_bw = bytes_for_this_rtt;
710 /* Can't determine do not change */
711 probepoint |= ((0xd << 16) | inst_ind);
712#endif
713 }
714#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
715 SDT_PROBE5(sctp, cwnd, net, rttvar,
716 vtag,
717 ((nbw << 32) | inst_bw),
718 ((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
719 net->flight_size,
720 probepoint);
721#endif
722 } else {
723 /* No rtt measurement, use last one */
724 inst_ind = net->cc_mod.rtcc.last_inst_ind;
725 }
726 bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
727 if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
728#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
729 ret = cc_bw_increase(stcb, net, nbw, vtag);
730#else
731 ret = cc_bw_increase(stcb, net, nbw);
732#endif
733 goto out;
734 }
735 rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
736 if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
737#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
738 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
739#else
740 ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind);
741#endif
742 goto out;
743 }
744 /* If we reach here then
745 * we are in a situation where
746 * the bw stayed the same.
747 */
748#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
749 ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
750#else
751 ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind);
752#endif
753out:
754 net->cc_mod.rtcc.last_inst_ind = inst_ind;
755 return (ret);
756}
757
758static void
759sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
760 struct sctp_association *asoc,
761 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
762{
763 struct sctp_nets *net;
764#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
765 int old_cwnd;
766#endif
767 uint32_t t_ssthresh, t_cwnd, incr;
768 uint64_t t_ucwnd_sbw;
769 uint64_t t_path_mptcp;
770 uint64_t mptcp_like_alpha;
771 uint32_t srtt;
772 uint64_t max_path;
773
774 /* MT FIXME: Don't compute this over and over again */
775 t_ssthresh = 0;
776 t_cwnd = 0;
777 t_ucwnd_sbw = 0;
778 t_path_mptcp = 0;
779 mptcp_like_alpha = 1;
780 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
781 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2) ||
782 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_MPTCP)) {
783 max_path = 0;
784 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
785 t_ssthresh += net->ssthresh;
786 t_cwnd += net->cwnd;
787 /* lastsa>>3; we don't need to devide ...*/
788 srtt = net->lastsa;
789 if (srtt > 0) {
790 uint64_t tmp;
791
792 t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt;
793 t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) /
794 (((uint64_t)net->mtu) * (uint64_t)srtt);
795 tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) /
796 ((uint64_t)net->mtu * (uint64_t)(srtt * srtt));
797 if (tmp > max_path) {
798 max_path = tmp;
799 }
800 }
801 }
802 if (t_path_mptcp > 0) {
803 mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp);
804 } else {
805 mptcp_like_alpha = 1;
806 }
807 }
808 if (t_ssthresh == 0) {
809 t_ssthresh = 1;
810 }
811 if (t_ucwnd_sbw == 0) {
812 t_ucwnd_sbw = 1;
813 }
814 /******************************/
815 /* update cwnd and Early FR */
816 /******************************/
817 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
818
819#ifdef JANA_CMT_FAST_RECOVERY
820 /*
821 * CMT fast recovery code. Need to debug.
822 */
823 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
824 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
825 SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) {
826 net->will_exit_fast_recovery = 1;
827 }
828 }
829#endif
830 /* if nothing was acked on this destination skip it */
831 if (net->net_ack == 0) {
832 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
833 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
834 }
835 continue;
836 }
837#ifdef JANA_CMT_FAST_RECOVERY
838 /* CMT fast recovery code
839 */
840 /*
841 if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
842 @@@ Do something
843 }
844 else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) {
845 */
846#endif
847
848 if (asoc->fast_retran_loss_recovery &&
849 (will_exit == 0) &&
850 (asoc->sctp_cmt_on_off == 0)) {
851 /*
852 * If we are in loss recovery we skip any cwnd
853 * update
854 */
855 return;
856 }
857 /*
858 * Did any measurements go on for this network?
859 */
860 if (use_rtcc && (net->cc_mod.rtcc.tls_needs_set > 0)) {
861 uint64_t nbw;
862 /*
863 * At this point our bw_bytes has been updated
864 * by incoming sack information.
865 *
866 * But our bw may not yet be set.
867 *
868 */
869 if ((net->cc_mod.rtcc.new_tot_time/1000) > 0) {
870 nbw = net->cc_mod.rtcc.bw_bytes/(net->cc_mod.rtcc.new_tot_time/1000);
871 } else {
872 nbw = net->cc_mod.rtcc.bw_bytes;
873 }
874 if (net->cc_mod.rtcc.lbw) {
875 if (cc_bw_limit(stcb, net, nbw)) {
876 /* Hold here, no update */
877 continue;
878 }
879 } else {
880#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
881 uint64_t vtag, probepoint;
882
883 probepoint = (((uint64_t)net->cwnd) << 32);
884 probepoint |= ((0xa << 16) | 0);
885 vtag = (net->rtt << 32) |
886 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
887 (stcb->rport);
888
889 SDT_PROBE5(sctp, cwnd, net, rttvar,
890 vtag,
891 nbw,
892 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
893 net->flight_size,
894 probepoint);
895#endif
896 net->cc_mod.rtcc.lbw = nbw;
897 net->cc_mod.rtcc.lbw_rtt = net->rtt;
898 if (net->cc_mod.rtcc.rtt_set_this_sack) {
899 net->cc_mod.rtcc.rtt_set_this_sack = 0;
900 net->cc_mod.rtcc.bw_bytes_at_last_rttc = net->cc_mod.rtcc.bw_bytes;
901 }
902 }
903 }
904 /*
905 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
906 * moved.
907 */
908 if (accum_moved ||
909 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
910 /* If the cumulative ack moved we can proceed */
911 if (net->cwnd <= net->ssthresh) {
912 /* We are in slow start */
913 if (net->flight_size + net->net_ack >= net->cwnd) {
914 uint32_t limit;
915
916#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
917 old_cwnd = net->cwnd;
918#endif
919 switch (asoc->sctp_cmt_on_off) {
920 case SCTP_CMT_RPV1:
921 limit = (uint32_t)(((uint64_t)net->mtu *
922 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
923 (uint64_t)net->ssthresh) /
924 (uint64_t)t_ssthresh);
925 incr = (uint32_t)(((uint64_t)net->net_ack *
926 (uint64_t)net->ssthresh) /
927 (uint64_t)t_ssthresh);
928 if (incr > limit) {
929 incr = limit;
930 }
931 if (incr == 0) {
932 incr = 1;
933 }
934 break;
935 case SCTP_CMT_RPV2:
936 /* lastsa>>3; we don't need to divide ...*/
937 srtt = net->lastsa;
938 if (srtt == 0) {
939 srtt = 1;
940 }
941 limit = (uint32_t)(((uint64_t)net->mtu *
942 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) *
943 (uint64_t)net->cwnd) /
944 ((uint64_t)srtt * t_ucwnd_sbw));
945 /* INCREASE FACTOR */
946 incr = (uint32_t)(((uint64_t)net->net_ack *
947 (uint64_t)net->cwnd) /
948 ((uint64_t)srtt * t_ucwnd_sbw));
949 /* INCREASE FACTOR */
950 if (incr > limit) {
951 incr = limit;
952 }
953 if (incr == 0) {
954 incr = 1;
955 }
956 break;
957 case SCTP_CMT_MPTCP:
958 limit = (uint32_t)(((uint64_t)net->mtu *
959 mptcp_like_alpha *
960 (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >>
961 SHIFT_MPTCP_MULTI);
962 incr = (uint32_t)(((uint64_t)net->net_ack *
963 mptcp_like_alpha) >>
964 SHIFT_MPTCP_MULTI);
965 if (incr > limit) {
966 incr = limit;
967 }
968 if (incr > net->net_ack) {
969 incr = net->net_ack;
970 }
971 if (incr > net->mtu) {
972 incr = net->mtu;
973 }
974 break;
975 default:
976 incr = net->net_ack;
977 if (incr > net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) {
978 incr = net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable);
979 }
980 break;
981 }
982 net->cwnd += incr;
983 sctp_enforce_cwnd_limit(asoc, net);
984 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
985 sctp_log_cwnd(stcb, net, incr,
986 SCTP_CWND_LOG_FROM_SS);
987 }
988#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
989 SDT_PROBE5(sctp, cwnd, net, ack,
990 stcb->asoc.my_vtag,
991 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
992 net,
993 old_cwnd, net->cwnd);
994#endif
995 } else {
996 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
997 sctp_log_cwnd(stcb, net, net->net_ack,
998 SCTP_CWND_LOG_NOADV_SS);
999 }
1000 }
1001 } else {
1002 /* We are in congestion avoidance */
1003 /*
1004 * Add to pba
1005 */
1006 net->partial_bytes_acked += net->net_ack;
1007
1008 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1009 (net->partial_bytes_acked >= net->cwnd)) {
1010 net->partial_bytes_acked -= net->cwnd;
1011#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1012 old_cwnd = net->cwnd;
1013#endif
1014 switch (asoc->sctp_cmt_on_off) {
1015 case SCTP_CMT_RPV1:
1016 incr = (uint32_t)(((uint64_t)net->mtu *
1017 (uint64_t)net->ssthresh) /
1018 (uint64_t)t_ssthresh);
1019 if (incr == 0) {
1020 incr = 1;
1021 }
1022 break;
1023 case SCTP_CMT_RPV2:
1024 /* lastsa>>3; we don't need to divide ... */
1025 srtt = net->lastsa;
1026 if (srtt == 0) {
1027 srtt = 1;
1028 }
1029 incr = (uint32_t)((uint64_t)net->mtu *
1030 (uint64_t)net->cwnd /
1031 ((uint64_t)srtt *
1032 t_ucwnd_sbw));
1033 /* INCREASE FACTOR */
1034 if (incr == 0) {
1035 incr = 1;
1036 }
1037 break;
1038 case SCTP_CMT_MPTCP:
1039 incr = (uint32_t)((mptcp_like_alpha *
1040 (uint64_t) net->cwnd) >>
1041 SHIFT_MPTCP_MULTI);
1042 if (incr > net->mtu) {
1043 incr = net->mtu;
1044 }
1045 break;
1046 default:
1047 incr = net->mtu;
1048 break;
1049 }
1050 net->cwnd += incr;
1051 sctp_enforce_cwnd_limit(asoc, net);
1052#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1053 SDT_PROBE5(sctp, cwnd, net, ack,
1054 stcb->asoc.my_vtag,
1055 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1056 net,
1057 old_cwnd, net->cwnd);
1058#endif
1059 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1060 sctp_log_cwnd(stcb, net, net->mtu,
1061 SCTP_CWND_LOG_FROM_CA);
1062 }
1063 } else {
1064 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1065 sctp_log_cwnd(stcb, net, net->net_ack,
1066 SCTP_CWND_LOG_NOADV_CA);
1067 }
1068 }
1069 }
1070 } else {
1071 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1072 sctp_log_cwnd(stcb, net, net->mtu,
1073 SCTP_CWND_LOG_NO_CUMACK);
1074 }
1075 }
1076 }
1077}
1078
1079#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1080static void
1081sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
1082#else
1083static void
1084sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net)
1085#endif
1086{
1087#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1088 int old_cwnd;
1089
1090 old_cwnd = net->cwnd;
1091#endif
1092 net->cwnd = net->mtu;
1093#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1094 SDT_PROBE5(sctp, cwnd, net, ack,
1095 stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
1096 old_cwnd, net->cwnd);
1097#endif
1098 SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
1099 (void *)net, net->cwnd);
1100}
1101
1102
1103static void
1104sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
1105{
1106 int old_cwnd = net->cwnd;
1107 uint32_t t_ssthresh, t_cwnd;
1108 uint64_t t_ucwnd_sbw;
1109
1110 /* MT FIXME: Don't compute this over and over again */
1111 t_ssthresh = 0;
1112 t_cwnd = 0;
1113 if ((stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) ||
1114 (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV2)) {
1115 struct sctp_nets *lnet;
1116 uint32_t srtt;
1117
1118 t_ucwnd_sbw = 0;
1119 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
1120 t_ssthresh += lnet->ssthresh;
1121 t_cwnd += lnet->cwnd;
1122 srtt = lnet->lastsa;
1123 /* lastsa>>3; we don't need to divide ... */
1124 if (srtt > 0) {
1125 t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt;
1126 }
1127 }
1128 if (t_ssthresh < 1) {
1129 t_ssthresh = 1;
1130 }
1131 if (t_ucwnd_sbw < 1) {
1132 t_ucwnd_sbw = 1;
1133 }
1134 if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) {
1135 net->ssthresh = (uint32_t)(((uint64_t)4 *
1136 (uint64_t)net->mtu *
1137 (uint64_t)net->ssthresh) /
1138 (uint64_t)t_ssthresh);
1139 } else {
1140 uint64_t cc_delta;
1141
1142 srtt = net->lastsa;
1143 /* lastsa>>3; we don't need to divide ... */
1144 if (srtt == 0) {
1145 srtt = 1;
1146 }
1147 cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2;
1148 if (cc_delta < t_cwnd) {
1149 net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta);
1150 } else {
1151 net->ssthresh = net->mtu;
1152 }
1153 }
1154 if ((net->cwnd > t_cwnd / 2) &&
1155 (net->ssthresh < net->cwnd - t_cwnd / 2)) {
1156 net->ssthresh = net->cwnd - t_cwnd / 2;
1157 }
1158 if (net->ssthresh < net->mtu) {
1159 net->ssthresh = net->mtu;
1160 }
1161 } else {
1162 net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
1163 }
1164 net->cwnd = net->mtu;
1165 net->partial_bytes_acked = 0;
1166#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1167 SDT_PROBE5(sctp, cwnd, net, to,
1168 stcb->asoc.my_vtag,
1169 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1170 net,
1171 old_cwnd, net->cwnd);
1172#endif
1173 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1174 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
1175 }
1176}
1177
1178static void
1179sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
1180 int in_window, int num_pkt_lost, int use_rtcc)
1181{
1182 int old_cwnd = net->cwnd;
1183 if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
1184 /* Data center Congestion Control */
1185 if (in_window == 0) {
1186 /* Go to CA with the cwnd at the point we sent
1187 * the TSN that was marked with a CE.
1188 */
1189 if (net->ecn_prev_cwnd < net->cwnd) {
1190 /* Restore to prev cwnd */
1191 net->cwnd = net->ecn_prev_cwnd - (net->mtu * num_pkt_lost);
1192 } else {
1193 /* Just cut in 1/2 */
1194 net->cwnd /= 2;
1195 }
1196 /* Drop to CA */
1197 net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
1198 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1199 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1200 }
1201 } else {
1202 /* Further tuning down required over the drastic original cut */
1203 net->ssthresh -= (net->mtu * num_pkt_lost);
1204 net->cwnd -= (net->mtu * num_pkt_lost);
1205 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1206 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1207 }
1208
1209 }
1210 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1211 } else {
1212 if (in_window == 0) {
1213 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
1214 net->ssthresh = net->cwnd / 2;
1215 if (net->ssthresh < net->mtu) {
1216 net->ssthresh = net->mtu;
1217 /* here back off the timer as well, to slow us down */
1218 net->RTO <<= 1;
1219 }
1220 net->cwnd = net->ssthresh;
1221#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1222 SDT_PROBE5(sctp, cwnd, net, ecn,
1223 stcb->asoc.my_vtag,
1224 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1225 net,
1226 old_cwnd, net->cwnd);
1227#endif
1228 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1229 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
1230 }
1231 }
1232 }
1233
1234}
1235
1236static void
1237sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
1238 struct sctp_nets *net, struct sctp_pktdrop_chunk *cp,
1239 uint32_t *bottle_bw, uint32_t *on_queue)
1240{
1241 uint32_t bw_avail;
1242 unsigned int incr;
1243 int old_cwnd = net->cwnd;
1244
1245 /* get bottle neck bw */
1246 *bottle_bw = ntohl(cp->bottle_bw);
1247 /* and whats on queue */
1248 *on_queue = ntohl(cp->current_onq);
1249 /*
1250 * adjust the on-queue if our flight is more it could be
1251 * that the router has not yet gotten data "in-flight" to it
1252 */
1253 if (*on_queue < net->flight_size) {
1254 *on_queue = net->flight_size;
1255 }
1256 /* rtt is measured in micro seconds, bottle_bw in bytes per second */
1257 bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000);
1258 if (bw_avail > *bottle_bw) {
1259 /*
1260 * Cap the growth to no more than the bottle neck.
1261 * This can happen as RTT slides up due to queues.
1262 * It also means if you have more than a 1 second
1263 * RTT with a empty queue you will be limited to the
1264 * bottle_bw per second no matter if other points
1265 * have 1/2 the RTT and you could get more out...
1266 */
1267 bw_avail = *bottle_bw;
1268 }
1269 if (*on_queue > bw_avail) {
1270 /*
1271 * No room for anything else don't allow anything
1272 * else to be "added to the fire".
1273 */
1274 int seg_inflight, seg_onqueue, my_portion;
1275
1276 net->partial_bytes_acked = 0;
1277 /* how much are we over queue size? */
1278 incr = *on_queue - bw_avail;
1279 if (stcb->asoc.seen_a_sack_this_pkt) {
1280 /*
1281 * undo any cwnd adjustment that the sack
1282 * might have made
1283 */
1284 net->cwnd = net->prev_cwnd;
1285 }
1286 /* Now how much of that is mine? */
1287 seg_inflight = net->flight_size / net->mtu;
1288 seg_onqueue = *on_queue / net->mtu;
1289 my_portion = (incr * seg_inflight) / seg_onqueue;
1290
1291 /* Have I made an adjustment already */
1292 if (net->cwnd > net->flight_size) {
1293 /*
1294 * for this flight I made an adjustment we
1295 * need to decrease the portion by a share
1296 * our previous adjustment.
1297 */
1298 int diff_adj;
1299
1300 diff_adj = net->cwnd - net->flight_size;
1301 if (diff_adj > my_portion)
1302 my_portion = 0;
1303 else
1304 my_portion -= diff_adj;
1305 }
1306 /*
1307 * back down to the previous cwnd (assume we have
1308 * had a sack before this packet). minus what ever
1309 * portion of the overage is my fault.
1310 */
1311 net->cwnd -= my_portion;
1312
1313 /* we will NOT back down more than 1 MTU */
1314 if (net->cwnd <= net->mtu) {
1315 net->cwnd = net->mtu;
1316 }
1317 /* force into CA */
1318 net->ssthresh = net->cwnd - 1;
1319 } else {
1320 /*
1321 * Take 1/4 of the space left or max burst up ..
1322 * whichever is less.
1323 */
1324 incr = (bw_avail - *on_queue) >> 2;
1325 if ((stcb->asoc.max_burst > 0) &&
1326 (stcb->asoc.max_burst * net->mtu < incr)) {
1327 incr = stcb->asoc.max_burst * net->mtu;
1328 }
1329 net->cwnd += incr;
1330 }
1331 if (net->cwnd > bw_avail) {
1332 /* We can't exceed the pipe size */
1333 net->cwnd = bw_avail;
1334 }
1335 if (net->cwnd < net->mtu) {
1336 /* We always have 1 MTU */
1337 net->cwnd = net->mtu;
1338 }
1339 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1340 if (net->cwnd - old_cwnd != 0) {
1341 /* log only changes */
1342#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1343 SDT_PROBE5(sctp, cwnd, net, pd,
1344 stcb->asoc.my_vtag,
1345 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1346 net,
1347 old_cwnd, net->cwnd);
1348#endif
1349 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1350 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
1351 SCTP_CWND_LOG_FROM_SAT);
1352 }
1353 }
1354}
1355
1356static void
1357sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
1358 struct sctp_nets *net, int burst_limit)
1359{
1360 int old_cwnd = net->cwnd;
1361
1362 if (net->ssthresh < net->cwnd)
1363 net->ssthresh = net->cwnd;
1364 if (burst_limit) {
1365 net->cwnd = (net->flight_size + (burst_limit * net->mtu));
1366 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1367#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1368 SDT_PROBE5(sctp, cwnd, net, bl,
1369 stcb->asoc.my_vtag,
1370 ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
1371 net,
1372 old_cwnd, net->cwnd);
1373#endif
1374 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1375 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
1376 }
1377 }
1378}
1379
1380static void
1381sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
1382 struct sctp_association *asoc,
1383 int accum_moved, int reneged_all, int will_exit)
1384{
1385 /* Passing a zero argument in last disables the rtcc algorithm */
1386 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
1387}
1388
1389static void
1390sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1391 int in_window, int num_pkt_lost)
1392{
1393 /* Passing a zero argument in last disables the rtcc algorithm */
1394 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
1395}
1396
1397/* Here starts the RTCCVAR type CC invented by RRS which
1398 * is a slight mod to RFC2581. We reuse a common routine or
1399 * two since these algorithms are so close and need to
1400 * remain the same.
1401 */
1402static void
1403sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
1404 int in_window, int num_pkt_lost)
1405{
1406 sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
1407}
1408
1409
1410static
1411void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
1412 struct sctp_tmit_chunk *tp1)
1413{
1414 net->cc_mod.rtcc.bw_bytes += tp1->send_size;
1415}
1416
1417static void
1418sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
1419 struct sctp_nets *net)
1420{
1421 if (net->cc_mod.rtcc.tls_needs_set > 0) {
1422 /* We had a bw measurment going on */
1423 struct timeval ltls;
1424 SCTP_GETPTIME_TIMEVAL(&ltls);
1425 timevalsub(&ltls, &net->cc_mod.rtcc.tls);
1426 net->cc_mod.rtcc.new_tot_time = (ltls.tv_sec * 1000000) + ltls.tv_usec;
1427 }
1428}
1429
1430static void
1431sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
1432 struct sctp_nets *net)
1433{
1434#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1435 uint64_t vtag, probepoint;
1436
1437#endif
1438 if (net->cc_mod.rtcc.lbw) {
1439#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1440 /* Clear the old bw.. we went to 0 in-flight */
1441 vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1442 (stcb->rport);
1443 probepoint = (((uint64_t)net->cwnd) << 32);
1444 /* Probe point 8 */
1445 probepoint |= ((8 << 16) | 0);
1446 SDT_PROBE5(sctp, cwnd, net, rttvar,
1447 vtag,
1448 ((net->cc_mod.rtcc.lbw << 32) | 0),
1449 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
1450 net->flight_size,
1451 probepoint);
1452#endif
1453 net->cc_mod.rtcc.lbw_rtt = 0;
1454 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1455 net->cc_mod.rtcc.lbw = 0;
1456 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1457 net->cc_mod.rtcc.vol_reduce = 0;
1458 net->cc_mod.rtcc.bw_tot_time = 0;
1459 net->cc_mod.rtcc.bw_bytes = 0;
1460 net->cc_mod.rtcc.tls_needs_set = 0;
1461 if (net->cc_mod.rtcc.steady_step) {
1462 net->cc_mod.rtcc.vol_reduce = 0;
1463 net->cc_mod.rtcc.step_cnt = 0;
1464 net->cc_mod.rtcc.last_step_state = 0;
1465 }
1466 if (net->cc_mod.rtcc.ret_from_eq) {
1467 /* less aggressive one - reset cwnd too */
1468 uint32_t cwnd_in_mtu, cwnd;
1469
1470 cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd);
1471 if (cwnd_in_mtu == 0) {
1472 /* Using 0 means that the value of RFC 4960 is used. */
1473 cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
1474 } else {
1475 /*
1476 * We take the minimum of the burst limit and the
1477 * initial congestion window.
1478 */
1479 if ((stcb->asoc.max_burst > 0) && (cwnd_in_mtu > stcb->asoc.max_burst))
1480 cwnd_in_mtu = stcb->asoc.max_burst;
1481 cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu;
1482 }
1483 if (net->cwnd > cwnd) {
1484 /* Only set if we are not a timeout (i.e. down to 1 mtu) */
1485 net->cwnd = cwnd;
1486 }
1487 }
1488 }
1489}
1490
1491static void
1492sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
1493 struct sctp_nets *net)
1494{
1495#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1496 uint64_t vtag, probepoint;
1497
1498#endif
1499 sctp_set_initial_cc_param(stcb, net);
1500 stcb->asoc.use_precise_time = 1;
1501#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
1502 probepoint = (((uint64_t)net->cwnd) << 32);
1503 probepoint |= ((9 << 16) | 0);
1504 vtag = (net->rtt << 32) |
1505 (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
1506 (stcb->rport);
1507 SDT_PROBE5(sctp, cwnd, net, rttvar,
1508 vtag,
1509 0,
1510 0,
1511 0,
1512 probepoint);
1513#endif
1514 net->cc_mod.rtcc.lbw_rtt = 0;
1515 net->cc_mod.rtcc.cwnd_at_bw_set = 0;
1516 net->cc_mod.rtcc.vol_reduce = 0;
1517 net->cc_mod.rtcc.lbw = 0;
1518 net->cc_mod.rtcc.vol_reduce = 0;
1519 net->cc_mod.rtcc.bw_bytes_at_last_rttc = 0;
1520 net->cc_mod.rtcc.bw_tot_time = 0;
1521 net->cc_mod.rtcc.bw_bytes = 0;
1522 net->cc_mod.rtcc.tls_needs_set = 0;
1523 net->cc_mod.rtcc.ret_from_eq = SCTP_BASE_SYSCTL(sctp_rttvar_eqret);
1524 net->cc_mod.rtcc.steady_step = SCTP_BASE_SYSCTL(sctp_steady_step);
1525 net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
1526 net->cc_mod.rtcc.step_cnt = 0;
1527 net->cc_mod.rtcc.last_step_state = 0;
1528
1529
1530}
1531
1532static int
1533sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
1534 struct sctp_cc_option *cc_opt)
1535{
1536 struct sctp_nets *net;
1537 if (setorget == 1) {
1538 /* a set */
1539 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1540 if ((cc_opt->aid_value.assoc_value != 0) &&
1541 (cc_opt->aid_value.assoc_value != 1)) {
1542 return (EINVAL);
1543 }
1544 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1545 net->cc_mod.rtcc.ret_from_eq = cc_opt->aid_value.assoc_value;
1546 }
1547 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1548 if ((cc_opt->aid_value.assoc_value != 0) &&
1549 (cc_opt->aid_value.assoc_value != 1)) {
1550 return (EINVAL);
1551 }
1552 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1553 net->cc_mod.rtcc.use_dccc_ecn = cc_opt->aid_value.assoc_value;
1554 }
1555 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1556 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1557 net->cc_mod.rtcc.steady_step = cc_opt->aid_value.assoc_value;
1558 }
1559 } else {
1560 return (EINVAL);
1561 }
1562 } else {
1563 /* a get */
1564 if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
1565 net = TAILQ_FIRST(&stcb->asoc.nets);
1566 if (net == NULL) {
1567 return (EFAULT);
1568 }
1569 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.ret_from_eq;
1570 } else if (cc_opt->option == SCTP_CC_OPT_USE_DCCC_ECN) {
1571 net = TAILQ_FIRST(&stcb->asoc.nets);
1572 if (net == NULL) {
1573 return (EFAULT);
1574 }
1575 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.use_dccc_ecn;
1576 } else if (cc_opt->option == SCTP_CC_OPT_STEADY_STEP) {
1577 net = TAILQ_FIRST(&stcb->asoc.nets);
1578 if (net == NULL) {
1579 return (EFAULT);
1580 }
1581 cc_opt->aid_value.assoc_value = net->cc_mod.rtcc.steady_step;
1582 } else {
1583 return (EINVAL);
1584 }
1585 }
1586 return (0);
1587}
1588
1589static void
1590sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
1591 struct sctp_nets *net)
1592{
1593 if (net->cc_mod.rtcc.tls_needs_set == 0) {
1594 SCTP_GETPTIME_TIMEVAL(&net->cc_mod.rtcc.tls);
1595 net->cc_mod.rtcc.tls_needs_set = 2;
1596 }
1597}
1598
1599static void
1600sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
1601 struct sctp_association *asoc,
1602 int accum_moved, int reneged_all, int will_exit)
1603{
1604 /* Passing a one argument at the last enables the rtcc algorithm */
1605 sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
1606}
1607
1608static void
1609sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
1610 struct sctp_nets *net,
1611 struct timeval *now SCTP_UNUSED)
1612{
1613 net->cc_mod.rtcc.rtt_set_this_sack = 1;
1614}
1615
1616/* Here starts Sally Floyds HS-TCP */
1617
1618struct sctp_hs_raise_drop {
1619 int32_t cwnd;
1620 int8_t increase;
1621 int8_t drop_percent;
1622};
1623
1624#define SCTP_HS_TABLE_SIZE 73
1625
1626static const struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
1627 {38, 1, 50}, /* 0 */
1628 {118, 2, 44}, /* 1 */
1629 {221, 3, 41}, /* 2 */
1630 {347, 4, 38}, /* 3 */
1631 {495, 5, 37}, /* 4 */
1632 {663, 6, 35}, /* 5 */
1633 {851, 7, 34}, /* 6 */
1634 {1058, 8, 33}, /* 7 */
1635 {1284, 9, 32}, /* 8 */
1636 {1529, 10, 31}, /* 9 */
1637 {1793, 11, 30}, /* 10 */
1638 {2076, 12, 29}, /* 11 */
1639 {2378, 13, 28}, /* 12 */
1640 {2699, 14, 28}, /* 13 */
1641 {3039, 15, 27}, /* 14 */
1642 {3399, 16, 27}, /* 15 */
1643 {3778, 17, 26}, /* 16 */
1644 {4177, 18, 26}, /* 17 */
1645 {4596, 19, 25}, /* 18 */
1646 {5036, 20, 25}, /* 19 */
1647 {5497, 21, 24}, /* 20 */
1648 {5979, 22, 24}, /* 21 */
1649 {6483, 23, 23}, /* 22 */
1650 {7009, 24, 23}, /* 23 */
1651 {7558, 25, 22}, /* 24 */
1652 {8130, 26, 22}, /* 25 */
1653 {8726, 27, 22}, /* 26 */
1654 {9346, 28, 21}, /* 27 */
1655 {9991, 29, 21}, /* 28 */
1656 {10661, 30, 21}, /* 29 */
1657 {11358, 31, 20}, /* 30 */
1658 {12082, 32, 20}, /* 31 */
1659 {12834, 33, 20}, /* 32 */
1660 {13614, 34, 19}, /* 33 */
1661 {14424, 35, 19}, /* 34 */
1662 {15265, 36, 19}, /* 35 */
1663 {16137, 37, 19}, /* 36 */
1664 {17042, 38, 18}, /* 37 */
1665 {17981, 39, 18}, /* 38 */
1666 {18955, 40, 18}, /* 39 */
1667 {19965, 41, 17}, /* 40 */
1668 {21013, 42, 17}, /* 41 */
1669 {22101, 43, 17}, /* 42 */
1670 {23230, 44, 17}, /* 43 */
1671 {24402, 45, 16}, /* 44 */
1672 {25618, 46, 16}, /* 45 */
1673 {26881, 47, 16}, /* 46 */
1674 {28193, 48, 16}, /* 47 */
1675 {29557, 49, 15}, /* 48 */
1676 {30975, 50, 15}, /* 49 */
1677 {32450, 51, 15}, /* 50 */
1678 {33986, 52, 15}, /* 51 */
1679 {35586, 53, 14}, /* 52 */
1680 {37253, 54, 14}, /* 53 */
1681 {38992, 55, 14}, /* 54 */
1682 {40808, 56, 14}, /* 55 */
1683 {42707, 57, 13}, /* 56 */
1684 {44694, 58, 13}, /* 57 */
1685 {46776, 59, 13}, /* 58 */
1686 {48961, 60, 13}, /* 59 */
1687 {51258, 61, 13}, /* 60 */
1688 {53677, 62, 12}, /* 61 */
1689 {56230, 63, 12}, /* 62 */
1690 {58932, 64, 12}, /* 63 */
1691 {61799, 65, 12}, /* 64 */
1692 {64851, 66, 11}, /* 65 */
1693 {68113, 67, 11}, /* 66 */
1694 {71617, 68, 11}, /* 67 */
1695 {75401, 69, 10}, /* 68 */
1696 {79517, 70, 10}, /* 69 */
1697 {84035, 71, 10}, /* 70 */
1698 {89053, 72, 10}, /* 71 */
1699 {94717, 73, 9} /* 72 */
1700};
1701
1702static void
1703sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net)
1704{
1705 int cur_val, i, indx, incr;
1706 int old_cwnd = net->cwnd;
1707
1708 cur_val = net->cwnd >> 10;
1709 indx = SCTP_HS_TABLE_SIZE - 1;
1710
1711 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1712 /* normal mode */
1713 if (net->net_ack > net->mtu) {
1714 net->cwnd += net->mtu;
1715 } else {
1716 net->cwnd += net->net_ack;
1717 }
1718 } else {
1719 for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
1720 if (cur_val < sctp_cwnd_adjust[i].cwnd) {
1721 indx = i;
1722 break;
1723 }
1724 }
1725 net->last_hs_used = indx;
1726 incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10);
1727 net->cwnd += incr;
1728 }
1729 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1730 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1731 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SS);
1732 }
1733}
1734
1735static void
1736sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net)
1737{
1738 int cur_val, i, indx;
1739 int old_cwnd = net->cwnd;
1740
1741 cur_val = net->cwnd >> 10;
1742 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1743 /* normal mode */
1744 net->ssthresh = net->cwnd / 2;
1745 if (net->ssthresh < (net->mtu * 2)) {
1746 net->ssthresh = 2 * net->mtu;
1747 }
1748 net->cwnd = net->ssthresh;
1749 } else {
1750 /* drop by the proper amount */
1751 net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
1752 (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent);
1753 net->cwnd = net->ssthresh;
1754 /* now where are we */
1755 indx = net->last_hs_used;
1756 cur_val = net->cwnd >> 10;
1757 /* reset where we are in the table */
1758 if (cur_val < sctp_cwnd_adjust[0].cwnd) {
1759 /* feel out of hs */
1760 net->last_hs_used = 0;
1761 } else {
1762 for (i = indx; i >= 1; i--) {
1763 if (cur_val > sctp_cwnd_adjust[i - 1].cwnd) {
1764 break;
1765 }
1766 }
1767 net->last_hs_used = indx;
1768 }
1769 }
1770 sctp_enforce_cwnd_limit(&stcb->asoc, net);
1771 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1772 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_FR);
1773 }
1774}
1775
1776static void
1777sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
1778 struct sctp_association *asoc)
1779{
1780 struct sctp_nets *net;
1781 /*
1782 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
1783 * (net->fast_retran_loss_recovery == 0)))
1784 */
1785 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1786 if ((asoc->fast_retran_loss_recovery == 0) ||
1787 (asoc->sctp_cmt_on_off > 0)) {
1788 /* out of a RFC2582 Fast recovery window? */
1789 if (net->net_ack > 0) {
1790 /*
1791 * per section 7.2.3, are there any
1792 * destinations that had a fast retransmit
1793 * to them. If so what we need to do is
1794 * adjust ssthresh and cwnd.
1795 */
1796 struct sctp_tmit_chunk *lchk;
1797
1798 sctp_hs_cwnd_decrease(stcb, net);
1799
1800 lchk = TAILQ_FIRST(&asoc->send_queue);
1801
1802 net->partial_bytes_acked = 0;
1803 /* Turn on fast recovery window */
1804 asoc->fast_retran_loss_recovery = 1;
1805 if (lchk == NULL) {
1806 /* Mark end of the window */
1807 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
1808 } else {
1809 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1810 }
1811
1812 /*
1813 * CMT fast recovery -- per destination
1814 * recovery variable.
1815 */
1816 net->fast_retran_loss_recovery = 1;
1817
1818 if (lchk == NULL) {
1819 /* Mark end of the window */
1820 net->fast_recovery_tsn = asoc->sending_seq - 1;
1821 } else {
1822 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
1823 }
1824
1825 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
1826 stcb->sctp_ep, stcb, net,
1827 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_2);
1828 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
1829 stcb->sctp_ep, stcb, net);
1830 }
1831 } else if (net->net_ack > 0) {
1832 /*
1833 * Mark a peg that we WOULD have done a cwnd
1834 * reduction but RFC2582 prevented this action.
1835 */
1836 SCTP_STAT_INCR(sctps_fastretransinrtt);
1837 }
1838 }
1839}
1840
1841static void
1842sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
1843 struct sctp_association *asoc,
1844 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
1845{
1846 struct sctp_nets *net;
1847 /******************************/
1848 /* update cwnd and Early FR */
1849 /******************************/
1850 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
1851
1852#ifdef JANA_CMT_FAST_RECOVERY
1853 /*
1854 * CMT fast recovery code. Need to debug.
1855 */
1856 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
1857 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
1858 SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) {
1859 net->will_exit_fast_recovery = 1;
1860 }
1861 }
1862#endif
1863 /* if nothing was acked on this destination skip it */
1864 if (net->net_ack == 0) {
1865 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1866 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
1867 }
1868 continue;
1869 }
1870#ifdef JANA_CMT_FAST_RECOVERY
1871 /* CMT fast recovery code
1872 */
1873 /*
1874 if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
1875 @@@ Do something
1876 }
1877 else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) {
1878 */
1879#endif
1880
1881 if (asoc->fast_retran_loss_recovery &&
1882 (will_exit == 0) &&
1883 (asoc->sctp_cmt_on_off == 0)) {
1884 /*
1885 * If we are in loss recovery we skip any cwnd
1886 * update
1887 */
1888 return;
1889 }
1890 /*
1891 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
1892 * moved.
1893 */
1894 if (accum_moved ||
1895 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
1896 /* If the cumulative ack moved we can proceed */
1897 if (net->cwnd <= net->ssthresh) {
1898 /* We are in slow start */
1899 if (net->flight_size + net->net_ack >= net->cwnd) {
1900 sctp_hs_cwnd_increase(stcb, net);
1901 } else {
1902 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1903 sctp_log_cwnd(stcb, net, net->net_ack,
1904 SCTP_CWND_LOG_NOADV_SS);
1905 }
1906 }
1907 } else {
1908 /* We are in congestion avoidance */
1909 net->partial_bytes_acked += net->net_ack;
1910 if ((net->flight_size + net->net_ack >= net->cwnd) &&
1911 (net->partial_bytes_acked >= net->cwnd)) {
1912 net->partial_bytes_acked -= net->cwnd;
1913 net->cwnd += net->mtu;
1914 sctp_enforce_cwnd_limit(asoc, net);
1915 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
1916 sctp_log_cwnd(stcb, net, net->mtu,
1917 SCTP_CWND_LOG_FROM_CA);
1918 }
1919 } else {
1920 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1921 sctp_log_cwnd(stcb, net, net->net_ack,
1922 SCTP_CWND_LOG_NOADV_CA);
1923 }
1924 }
1925 }
1926 } else {
1927 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
1928 sctp_log_cwnd(stcb, net, net->mtu,
1929 SCTP_CWND_LOG_NO_CUMACK);
1930 }
1931 }
1932 }
1933}
1934
1935
1936/*
1937 * H-TCP congestion control. The algorithm is detailed in:
1938 * R.N.Shorten, D.J.Leith:
1939 * "H-TCP: TCP for high-speed and long-distance networks"
1940 * Proc. PFLDnet, Argonne, 2004.
1941 * http://www.hamilton.ie/net/htcp3.pdf
1942 */
1943
1944
1945static int use_rtt_scaling = 1;
1946static int use_bandwidth_switch = 1;
1947
1948static inline int
1949between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
1950{
1951 return (seq3 - seq2 >= seq1 - seq2);
1952}
1953
1954static inline uint32_t
1955htcp_cong_time(struct htcp *ca)
1956{
1957 return (sctp_get_tick_count() - ca->last_cong);
1958}
1959
1960static inline uint32_t
1961htcp_ccount(struct htcp *ca)
1962{
1963 return (htcp_cong_time(ca)/ca->minRTT);
1964}
1965
1966static inline void
1967htcp_reset(struct htcp *ca)
1968{
1969 ca->undo_last_cong = ca->last_cong;
1970 ca->undo_maxRTT = ca->maxRTT;
1971 ca->undo_old_maxB = ca->old_maxB;
1972 ca->last_cong = sctp_get_tick_count();
1973}
1974
1975#ifdef SCTP_NOT_USED
1976
1977static uint32_t
1978htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net)
1979{
1980 net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong;
1981 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT;
1982 net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB;
1983 return (max(net->cwnd, ((net->ssthresh/net->mtu<<7)/net->cc_mod.htcp_ca.beta)*net->mtu));
1984}
1985
1986#endif
1987
1988static inline void
1989measure_rtt(struct sctp_nets *net)
1990{
1991 uint32_t srtt = net->lastsa>>SCTP_RTT_SHIFT;
1992
1993 /* keep track of minimum RTT seen so far, minRTT is zero at first */
1994 if (net->cc_mod.htcp_ca.minRTT > srtt || !net->cc_mod.htcp_ca.minRTT)
1995 net->cc_mod.htcp_ca.minRTT = srtt;
1996
1997 /* max RTT */
1998 if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
1999 if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
2000 net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
2001 if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20))
2002 net->cc_mod.htcp_ca.maxRTT = srtt;
2003 }
2004}
2005
2006static void
2007measure_achieved_throughput(struct sctp_nets *net)
2008{
2009 uint32_t now = sctp_get_tick_count();
2010
2011 if (net->fast_retran_ip == 0)
2012 net->cc_mod.htcp_ca.bytes_acked = net->net_ack;
2013
2014 if (!use_bandwidth_switch)
2015 return;
2016
2017 /* achieved throughput calculations */
2018 /* JRS - not 100% sure of this statement */
2019 if (net->fast_retran_ip == 1) {
2020 net->cc_mod.htcp_ca.bytecount = 0;
2021 net->cc_mod.htcp_ca.lasttime = now;
2022 return;
2023 }
2024
2025 net->cc_mod.htcp_ca.bytecount += net->net_ack;
2026 if ((net->cc_mod.htcp_ca.bytecount >= net->cwnd - (((net->cc_mod.htcp_ca.alpha >> 7) ? (net->cc_mod.htcp_ca.alpha >> 7) : 1) * net->mtu)) &&
2027 (now - net->cc_mod.htcp_ca.lasttime >= net->cc_mod.htcp_ca.minRTT) &&
2028 (net->cc_mod.htcp_ca.minRTT > 0)) {
2029 uint32_t cur_Bi = net->cc_mod.htcp_ca.bytecount/net->mtu*hz/(now - net->cc_mod.htcp_ca.lasttime);
2030
2031 if (htcp_ccount(&net->cc_mod.htcp_ca) <= 3) {
2032 /* just after backoff */
2033 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi = cur_Bi;
2034 } else {
2035 net->cc_mod.htcp_ca.Bi = (3*net->cc_mod.htcp_ca.Bi + cur_Bi)/4;
2036 if (net->cc_mod.htcp_ca.Bi > net->cc_mod.htcp_ca.maxB)
2037 net->cc_mod.htcp_ca.maxB = net->cc_mod.htcp_ca.Bi;
2038 if (net->cc_mod.htcp_ca.minB > net->cc_mod.htcp_ca.maxB)
2039 net->cc_mod.htcp_ca.minB = net->cc_mod.htcp_ca.maxB;
2040 }
2041 net->cc_mod.htcp_ca.bytecount = 0;
2042 net->cc_mod.htcp_ca.lasttime = now;
2043 }
2044}
2045
2046static inline void
2047htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
2048{
2049 if (use_bandwidth_switch) {
2050 uint32_t maxB = ca->maxB;
2051 uint32_t old_maxB = ca->old_maxB;
2052 ca->old_maxB = ca->maxB;
2053
2054 if (!between(5*maxB, 4*old_maxB, 6*old_maxB)) {
2055 ca->beta = BETA_MIN;
2056 ca->modeswitch = 0;
2057 return;
2058 }
2059 }
2060
2061 if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) {
2062 ca->beta = (minRTT<<7)/maxRTT;
2063 if (ca->beta < BETA_MIN)
2064 ca->beta = BETA_MIN;
2065 else if (ca->beta > BETA_MAX)
2066 ca->beta = BETA_MAX;
2067 } else {
2068 ca->beta = BETA_MIN;
2069 ca->modeswitch = 1;
2070 }
2071}
2072
2073static inline void
2074htcp_alpha_update(struct htcp *ca)
2075{
2076 uint32_t minRTT = ca->minRTT;
2077 uint32_t factor = 1;
2078 uint32_t diff = htcp_cong_time(ca);
2079
2080 if (diff > (uint32_t)hz) {
2081 diff -= hz;
2082 factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/hz))/hz;
2083 }
2084
2085 if (use_rtt_scaling && minRTT) {
2086 uint32_t scale = (hz<<3)/(10*minRTT);
2087 scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */
2088 factor = (factor<<3)/scale;
2089 if (!factor)
2090 factor = 1;
2091 }
2092
2093 ca->alpha = 2*factor*((1<<7)-ca->beta);
2094 if (!ca->alpha)
2095 ca->alpha = ALPHA_BASE;
2096}
2097
2098/* After we have the rtt data to calculate beta, we'd still prefer to wait one
2099 * rtt before we adjust our beta to ensure we are working from a consistent
2100 * data.
2101 *
2102 * This function should be called when we hit a congestion event since only at
2103 * that point do we really have a real sense of maxRTT (the queues en route
2104 * were getting just too full now).
2105 */
2106static void
2107htcp_param_update(struct sctp_nets *net)
2108{
2109 uint32_t minRTT = net->cc_mod.htcp_ca.minRTT;
2110 uint32_t maxRTT = net->cc_mod.htcp_ca.maxRTT;
2111
2112 htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT);
2113 htcp_alpha_update(&net->cc_mod.htcp_ca);
2114
2115 /* add slowly fading memory for maxRTT to accommodate routing changes etc */
2116 if (minRTT > 0 && maxRTT > minRTT)
2117 net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT-minRTT)*95)/100;
2118}
2119
2120static uint32_t
2121htcp_recalc_ssthresh(struct sctp_nets *net)
2122{
2123 htcp_param_update(net);
2124 return (max(((net->cwnd/net->mtu * net->cc_mod.htcp_ca.beta) >> 7)*net->mtu, 2U*net->mtu));
2125}
2126
2127static void
2128htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
2129{
2130 /*-
2131 * How to handle these functions?
2132 * if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
2133 * return;
2134 */
2135 if (net->cwnd <= net->ssthresh) {
2136 /* We are in slow start */
2137 if (net->flight_size + net->net_ack >= net->cwnd) {
2138 if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
2139 net->cwnd += (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable));
2140 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2141 sctp_log_cwnd(stcb, net, net->mtu,
2142 SCTP_CWND_LOG_FROM_SS);
2143 }
2144
2145 } else {
2146 net->cwnd += net->net_ack;
2147 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2148 sctp_log_cwnd(stcb, net, net->net_ack,
2149 SCTP_CWND_LOG_FROM_SS);
2150 }
2151
2152 }
2153 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2154 } else {
2155 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2156 sctp_log_cwnd(stcb, net, net->net_ack,
2157 SCTP_CWND_LOG_NOADV_SS);
2158 }
2159 }
2160 } else {
2161 measure_rtt(net);
2162
2163 /* In dangerous area, increase slowly.
2164 * In theory this is net->cwnd += alpha / net->cwnd
2165 */
2166 /* What is snd_cwnd_cnt?? */
2167 if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) {
2168 /*-
2169 * Does SCTP have a cwnd clamp?
2170 * if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
2171 */
2172 net->cwnd += net->mtu;
2173 net->partial_bytes_acked = 0;
2174 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2175 htcp_alpha_update(&net->cc_mod.htcp_ca);
2176 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2177 sctp_log_cwnd(stcb, net, net->mtu,
2178 SCTP_CWND_LOG_FROM_CA);
2179 }
2180 } else {
2181 net->partial_bytes_acked += net->net_ack;
2182 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2183 sctp_log_cwnd(stcb, net, net->net_ack,
2184 SCTP_CWND_LOG_NOADV_CA);
2185 }
2186 }
2187
2188 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2189 }
2190}
2191
2192#ifdef SCTP_NOT_USED
2193/* Lower bound on congestion window. */
2194static uint32_t
2195htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net)
2196{
2197 return (net->ssthresh);
2198}
2199#endif
2200
2201static void
2202htcp_init(struct sctp_nets *net)
2203{
2204 memset(&net->cc_mod.htcp_ca, 0, sizeof(struct htcp));
2205 net->cc_mod.htcp_ca.alpha = ALPHA_BASE;
2206 net->cc_mod.htcp_ca.beta = BETA_MIN;
2207 net->cc_mod.htcp_ca.bytes_acked = net->mtu;
2208 net->cc_mod.htcp_ca.last_cong = sctp_get_tick_count();
2209}
2210
2211static void
2212sctp_htcp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
2213{
2214 /*
2215 * We take the max of the burst limit times a MTU or the
2216 * INITIAL_CWND. We then limit this to 4 MTU's of sending.
2217 */
2218 net->cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND));
2219 net->ssthresh = stcb->asoc.peers_rwnd;
2220 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2221 htcp_init(net);
2222
2223 if (SCTP_BASE_SYSCTL(sctp_logging_level) & (SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) {
2224 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
2225 }
2226}
2227
2228static void
2229sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
2230 struct sctp_association *asoc,
2231 int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
2232{
2233 struct sctp_nets *net;
2234
2235 /******************************/
2236 /* update cwnd and Early FR */
2237 /******************************/
2238 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2239
2240#ifdef JANA_CMT_FAST_RECOVERY
2241 /*
2242 * CMT fast recovery code. Need to debug.
2243 */
2244 if (net->fast_retran_loss_recovery && net->new_pseudo_cumack) {
2245 if (SCTP_TSN_GE(asoc->last_acked_seq, net->fast_recovery_tsn) ||
2246 SCTP_TSN_GE(net->pseudo_cumack,net->fast_recovery_tsn)) {
2247 net->will_exit_fast_recovery = 1;
2248 }
2249 }
2250#endif
2251 /* if nothing was acked on this destination skip it */
2252 if (net->net_ack == 0) {
2253 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2254 sctp_log_cwnd(stcb, net, 0, SCTP_CWND_LOG_FROM_SACK);
2255 }
2256 continue;
2257 }
2258#ifdef JANA_CMT_FAST_RECOVERY
2259 /* CMT fast recovery code
2260 */
2261 /*
2262 if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
2263 @@@ Do something
2264 }
2265 else if (sctp_cmt_on_off == 0 && asoc->fast_retran_loss_recovery && will_exit == 0) {
2266 */
2267#endif
2268
2269 if (asoc->fast_retran_loss_recovery &&
2270 will_exit == 0 &&
2271 (asoc->sctp_cmt_on_off == 0)) {
2272 /*
2273 * If we are in loss recovery we skip any cwnd
2274 * update
2275 */
2276 return;
2277 }
2278 /*
2279 * CMT: CUC algorithm. Update cwnd if pseudo-cumack has
2280 * moved.
2281 */
2282 if (accum_moved ||
2283 ((asoc->sctp_cmt_on_off > 0) && net->new_pseudo_cumack)) {
2284 htcp_cong_avoid(stcb, net);
2285 measure_achieved_throughput(net);
2286 } else {
2287 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
2288 sctp_log_cwnd(stcb, net, net->mtu,
2289 SCTP_CWND_LOG_NO_CUMACK);
2290 }
2291 }
2292 }
2293}
2294
2295static void
2296sctp_htcp_cwnd_update_after_fr(struct sctp_tcb *stcb,
2297 struct sctp_association *asoc)
2298{
2299 struct sctp_nets *net;
2300 /*
2301 * CMT fast recovery code. Need to debug. ((sctp_cmt_on_off > 0) &&
2302 * (net->fast_retran_loss_recovery == 0)))
2303 */
2304 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
2305 if ((asoc->fast_retran_loss_recovery == 0) ||
2306 (asoc->sctp_cmt_on_off > 0)) {
2307 /* out of a RFC2582 Fast recovery window? */
2308 if (net->net_ack > 0) {
2309 /*
2310 * per section 7.2.3, are there any
2311 * destinations that had a fast retransmit
2312 * to them. If so what we need to do is
2313 * adjust ssthresh and cwnd.
2314 */
2315 struct sctp_tmit_chunk *lchk;
2316 int old_cwnd = net->cwnd;
2317
2318 /* JRS - reset as if state were changed */
2319 htcp_reset(&net->cc_mod.htcp_ca);
2320 net->ssthresh = htcp_recalc_ssthresh(net);
2321 net->cwnd = net->ssthresh;
2322 sctp_enforce_cwnd_limit(asoc, net);
2323 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2324 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
2325 SCTP_CWND_LOG_FROM_FR);
2326 }
2327 lchk = TAILQ_FIRST(&asoc->send_queue);
2328
2329 net->partial_bytes_acked = 0;
2330 /* Turn on fast recovery window */
2331 asoc->fast_retran_loss_recovery = 1;
2332 if (lchk == NULL) {
2333 /* Mark end of the window */
2334 asoc->fast_recovery_tsn = asoc->sending_seq - 1;
2335 } else {
2336 asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2337 }
2338
2339 /*
2340 * CMT fast recovery -- per destination
2341 * recovery variable.
2342 */
2343 net->fast_retran_loss_recovery = 1;
2344
2345 if (lchk == NULL) {
2346 /* Mark end of the window */
2347 net->fast_recovery_tsn = asoc->sending_seq - 1;
2348 } else {
2349 net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
2350 }
2351
2352 sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
2353 stcb->sctp_ep, stcb, net,
2354 SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_3);
2355 sctp_timer_start(SCTP_TIMER_TYPE_SEND,
2356 stcb->sctp_ep, stcb, net);
2357 }
2358 } else if (net->net_ack > 0) {
2359 /*
2360 * Mark a peg that we WOULD have done a cwnd
2361 * reduction but RFC2582 prevented this action.
2362 */
2363 SCTP_STAT_INCR(sctps_fastretransinrtt);
2364 }
2365 }
2366}
2367
2368static void
2369sctp_htcp_cwnd_update_after_timeout(struct sctp_tcb *stcb,
2370 struct sctp_nets *net)
2371{
2372 int old_cwnd = net->cwnd;
2373
2374 /* JRS - reset as if the state were being changed to timeout */
2375 htcp_reset(&net->cc_mod.htcp_ca);
2376 net->ssthresh = htcp_recalc_ssthresh(net);
2377 net->cwnd = net->mtu;
2378 net->partial_bytes_acked = 0;
2379 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2380 sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
2381 }
2382}
2383
2384static void
2385sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
2386 struct sctp_nets *net, int in_window, int num_pkt_lost SCTP_UNUSED)
2387{
2388 int old_cwnd;
2389 old_cwnd = net->cwnd;
2390
2391 /* JRS - reset hctp as if state changed */
2392 if (in_window == 0) {
2393 htcp_reset(&net->cc_mod.htcp_ca);
2394 SCTP_STAT_INCR(sctps_ecnereducedcwnd);
2395 net->ssthresh = htcp_recalc_ssthresh(net);
2396 if (net->ssthresh < net->mtu) {
2397 net->ssthresh = net->mtu;
2398 /* here back off the timer as well, to slow us down */
2399 net->RTO <<= 1;
2400 }
2401 net->cwnd = net->ssthresh;
2402 sctp_enforce_cwnd_limit(&stcb->asoc, net);
2403 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
2404 sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2405 }
2406 }
2407}
2408
2409const struct sctp_cc_functions sctp_cc_functions[] = {
2410{
2411#if defined(__Windows__) || defined(__Userspace_os_Windows)
2412 sctp_set_initial_cc_param,
2413 sctp_cwnd_update_after_sack,
2414 sctp_cwnd_update_exit_pf_common,
2415 sctp_cwnd_update_after_fr,
2416 sctp_cwnd_update_after_timeout,
2417 sctp_cwnd_update_after_ecn_echo,
2418 sctp_cwnd_update_after_packet_dropped,
2419 sctp_cwnd_update_after_output,
2420#else
2421 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2422 .sctp_cwnd_update_after_sack = sctp_cwnd_update_after_sack,
2423 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2424 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2425 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2426 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2427 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2428 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2429#endif
2430},
2431{
2432#if defined(__Windows__) || defined(__Userspace_os_Windows)
2433 sctp_set_initial_cc_param,
2434 sctp_hs_cwnd_update_after_sack,
2435 sctp_cwnd_update_exit_pf_common,
2436 sctp_hs_cwnd_update_after_fr,
2437 sctp_cwnd_update_after_timeout,
2438 sctp_cwnd_update_after_ecn_echo,
2439 sctp_cwnd_update_after_packet_dropped,
2440 sctp_cwnd_update_after_output,
2441#else
2442 .sctp_set_initial_cc_param = sctp_set_initial_cc_param,
2443 .sctp_cwnd_update_after_sack = sctp_hs_cwnd_update_after_sack,
2444 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2445 .sctp_cwnd_update_after_fr = sctp_hs_cwnd_update_after_fr,
2446 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2447 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_after_ecn_echo,
2448 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2449 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2450#endif
2451},
2452{
2453#if defined(__Windows__) || defined(__Userspace_os_Windows)
2454 sctp_htcp_set_initial_cc_param,
2455 sctp_htcp_cwnd_update_after_sack,
2456 sctp_cwnd_update_exit_pf_common,
2457 sctp_htcp_cwnd_update_after_fr,
2458 sctp_htcp_cwnd_update_after_timeout,
2459 sctp_htcp_cwnd_update_after_ecn_echo,
2460 sctp_cwnd_update_after_packet_dropped,
2461 sctp_cwnd_update_after_output,
2462#else
2463 .sctp_set_initial_cc_param = sctp_htcp_set_initial_cc_param,
2464 .sctp_cwnd_update_after_sack = sctp_htcp_cwnd_update_after_sack,
2465 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2466 .sctp_cwnd_update_after_fr = sctp_htcp_cwnd_update_after_fr,
2467 .sctp_cwnd_update_after_timeout = sctp_htcp_cwnd_update_after_timeout,
2468 .sctp_cwnd_update_after_ecn_echo = sctp_htcp_cwnd_update_after_ecn_echo,
2469 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2470 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2471#endif
2472},
2473{
2474#if defined(__Windows__) || defined(__Userspace_os_Windows)
2475 sctp_set_rtcc_initial_cc_param,
2476 sctp_cwnd_update_rtcc_after_sack,
2477 sctp_cwnd_update_exit_pf_common,
2478 sctp_cwnd_update_after_fr,
2479 sctp_cwnd_update_after_timeout,
2480 sctp_cwnd_update_rtcc_after_ecn_echo,
2481 sctp_cwnd_update_after_packet_dropped,
2482 sctp_cwnd_update_after_output,
2483 sctp_cwnd_update_rtcc_packet_transmitted,
2484 sctp_cwnd_update_rtcc_tsn_acknowledged,
2485 sctp_cwnd_new_rtcc_transmission_begins,
2486 sctp_cwnd_prepare_rtcc_net_for_sack,
2487 sctp_cwnd_rtcc_socket_option,
2488 sctp_rtt_rtcc_calculated
2489#else
2490 .sctp_set_initial_cc_param = sctp_set_rtcc_initial_cc_param,
2491 .sctp_cwnd_update_after_sack = sctp_cwnd_update_rtcc_after_sack,
2492 .sctp_cwnd_update_exit_pf = sctp_cwnd_update_exit_pf_common,
2493 .sctp_cwnd_update_after_fr = sctp_cwnd_update_after_fr,
2494 .sctp_cwnd_update_after_timeout = sctp_cwnd_update_after_timeout,
2495 .sctp_cwnd_update_after_ecn_echo = sctp_cwnd_update_rtcc_after_ecn_echo,
2496 .sctp_cwnd_update_after_packet_dropped = sctp_cwnd_update_after_packet_dropped,
2497 .sctp_cwnd_update_after_output = sctp_cwnd_update_after_output,
2498 .sctp_cwnd_update_packet_transmitted = sctp_cwnd_update_rtcc_packet_transmitted,
2499 .sctp_cwnd_update_tsn_acknowledged = sctp_cwnd_update_rtcc_tsn_acknowledged,
2500 .sctp_cwnd_new_transmission_begins = sctp_cwnd_new_rtcc_transmission_begins,
2501 .sctp_cwnd_prepare_net_for_sack = sctp_cwnd_prepare_rtcc_net_for_sack,
2502 .sctp_cwnd_socket_option = sctp_cwnd_rtcc_socket_option,
2503 .sctp_rtt_calculated = sctp_rtt_rtcc_calculated
2504#endif
2505}
2506};