2 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/tcp/tcp.h>
17 #include <vnet/tcp/tcp_inlines.h>
19 typedef struct nwreno_cfg_
24 static newreno_cfg_t newreno_cfg = {
25 .ssthresh = 0x7FFFFFFFU,
29 newreno_congestion (tcp_connection_t * tc)
31 tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
32 tc->cwnd = tc->ssthresh;
36 newreno_loss (tcp_connection_t * tc)
38 tc->cwnd = tcp_loss_wnd (tc);
42 newreno_recovered (tcp_connection_t * tc)
44 tc->cwnd = tc->ssthresh;
48 newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
50 if (tcp_in_slowstart (tc))
52 tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked);
56 /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */
57 tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked);
62 newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type,
63 tcp_rate_sample_t * rs)
65 if (ack_type == TCP_CC_DUPACK)
67 if (!tcp_opts_sack_permitted (tc))
68 tc->cwnd += tc->snd_mss;
70 else if (ack_type == TCP_CC_PARTIALACK)
72 /* RFC 6582 Sec. 3.2 */
73 if (!tcp_opts_sack_permitted (&tc->rcv_opts))
75 /* Deflate the congestion window by the amount of new data
76 * acknowledged by the Cumulative Acknowledgment field.
77 * If the partial ACK acknowledges at least one SMSS of new data,
78 * then add back SMSS bytes to the congestion window. This
79 * artificially inflates the congestion window in order to reflect
80 * the additional segment that has left the network. This "partial
81 * window deflation" attempts to ensure that, when fast recovery
82 * eventually ends, approximately ssthresh amount of data will be
83 * outstanding in the network.*/
84 tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ?
85 tc->cwnd - tc->bytes_acked : tc->snd_mss;
86 if (tc->bytes_acked > tc->snd_mss)
87 tc->cwnd += tc->snd_mss;
93 newreno_conn_init (tcp_connection_t * tc)
95 tc->ssthresh = newreno_cfg.ssthresh;
96 tc->cwnd = tcp_initial_cwnd (tc);
100 newreno_unformat_config (unformat_input_t * input)
102 u32 ssthresh = 0x7FFFFFFFU;
107 unformat_skip_white_space (input);
109 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
111 if (unformat (input, "ssthresh %u", &ssthresh))
112 newreno_cfg.ssthresh = ssthresh;
119 const static tcp_cc_algorithm_t tcp_newreno = {
121 .unformat_cfg = newreno_unformat_config,
122 .congestion = newreno_congestion,
123 .loss = newreno_loss,
124 .recovered = newreno_recovered,
125 .rcv_ack = newreno_rcv_ack,
126 .rcv_cong_ack = newreno_rcv_cong_ack,
127 .init = newreno_conn_init
131 newreno_init (vlib_main_t * vm)
133 clib_error_t *error = 0;
135 tcp_cc_algo_register (TCP_CC_NEWRENO, &tcp_newreno);
140 VLIB_INIT_FUNCTION (newreno_init);
143 * fd.io coding-style-patch-verification: ON
146 * eval: (c-set-style "gnu")