blob: 420e47a8ca43c506ff608e47ddceda67b2249889 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
2 * Copyright (c) 2017 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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#include <vnet/tcp/tcp.h>
17
18void
19newreno_congestion (tcp_connection_t * tc)
20{
Dave Barach68b0fb02017-02-28 15:15:56 -050021 tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
22}
23
24void
25newreno_recovered (tcp_connection_t * tc)
26{
27 tc->cwnd = tc->ssthresh;
28}
29
30void
31newreno_rcv_ack (tcp_connection_t * tc)
32{
33 if (tcp_in_slowstart (tc))
34 {
35 tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked);
36 }
37 else
38 {
Florin Coras62166002018-04-18 16:40:55 -070039 /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */
Florin Coras2e31cc32018-09-25 14:00:34 -070040 tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked);
Dave Barach68b0fb02017-02-28 15:15:56 -050041 }
42}
43
44void
45newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type)
46{
47 if (ack_type == TCP_CC_DUPACK)
48 {
Florin Corasf03a59a2017-06-09 21:07:32 -070049 if (!tcp_opts_sack_permitted (tc))
50 tc->cwnd += tc->snd_mss;
Dave Barach68b0fb02017-02-28 15:15:56 -050051 }
52 else if (ack_type == TCP_CC_PARTIALACK)
53 {
Florin Coras93992a92017-05-24 18:03:56 -070054 /* RFC 6582 Sec. 3.2 */
55 if (!tcp_opts_sack_permitted (&tc->rcv_opts))
56 {
57 /* Deflate the congestion window by the amount of new data
58 * acknowledged by the Cumulative Acknowledgment field.
59 * If the partial ACK acknowledges at least one SMSS of new data,
60 * then add back SMSS bytes to the congestion window. This
61 * artificially inflates the congestion window in order to reflect
62 * the additional segment that has left the network. This "partial
63 * window deflation" attempts to ensure that, when fast recovery
64 * eventually ends, approximately ssthresh amount of data will be
65 * outstanding in the network.*/
Dave Barach2c25a622017-06-26 11:35:07 -040066 tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ?
67 tc->cwnd - tc->bytes_acked : tc->snd_mss;
Florin Coras93992a92017-05-24 18:03:56 -070068 if (tc->bytes_acked > tc->snd_mss)
69 tc->cwnd += tc->snd_mss;
70 }
Dave Barach68b0fb02017-02-28 15:15:56 -050071 }
72}
73
74void
75newreno_conn_init (tcp_connection_t * tc)
76{
77 tc->ssthresh = tc->snd_wnd;
78 tc->cwnd = tcp_initial_cwnd (tc);
79}
80
81const static tcp_cc_algorithm_t tcp_newreno = {
82 .congestion = newreno_congestion,
83 .recovered = newreno_recovered,
84 .rcv_ack = newreno_rcv_ack,
85 .rcv_cong_ack = newreno_rcv_cong_ack,
86 .init = newreno_conn_init
87};
88
89clib_error_t *
90newreno_init (vlib_main_t * vm)
91{
92 clib_error_t *error = 0;
93
94 tcp_cc_algo_register (TCP_CC_NEWRENO, &tcp_newreno);
95
96 return error;
97}
98
99VLIB_INIT_FUNCTION (newreno_init);
100
101/*
102 * fd.io coding-style-patch-verification: ON
103 *
104 * Local Variables:
105 * eval: (c-set-style "gnu")
106 * End:
107 */