blob: 8b704a6ba042ff027631651be8e7355fb7e7136b [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Dave Barach68b0fb02017-02-28 15:15:56 -05003 * 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
Florin Corasa3c32652019-07-03 17:47:22 -070018static void
Dave Barach68b0fb02017-02-28 15:15:56 -050019newreno_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);
Florin Coras8b4114e2019-09-03 12:37:11 -070022 tc->cwnd = tc->ssthresh;
23 /* Post retransmit update cwnd to ssthresh and account for the
24 * three segments that have left the network and should've been
25 * buffered at the receiver XXX */
26 if (!tcp_opts_sack_permitted (&tc->rcv_opts))
27 tc->cwnd += 3 * tc->snd_mss;
Dave Barach68b0fb02017-02-28 15:15:56 -050028}
29
Florin Corasa3c32652019-07-03 17:47:22 -070030static void
31newreno_loss (tcp_connection_t * tc)
32{
33 tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
34 tc->cwnd = tcp_loss_wnd (tc);
35}
36
37static void
Dave Barach68b0fb02017-02-28 15:15:56 -050038newreno_recovered (tcp_connection_t * tc)
39{
40 tc->cwnd = tc->ssthresh;
41}
42
Florin Corasa3c32652019-07-03 17:47:22 -070043static void
Florin Coras52814732019-06-12 15:38:19 -070044newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
Dave Barach68b0fb02017-02-28 15:15:56 -050045{
46 if (tcp_in_slowstart (tc))
47 {
48 tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked);
49 }
50 else
51 {
Florin Coras62166002018-04-18 16:40:55 -070052 /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */
Florin Coras2e31cc32018-09-25 14:00:34 -070053 tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked);
Dave Barach68b0fb02017-02-28 15:15:56 -050054 }
55}
56
57void
Florin Coras52814732019-06-12 15:38:19 -070058newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type,
59 tcp_rate_sample_t * rs)
Dave Barach68b0fb02017-02-28 15:15:56 -050060{
61 if (ack_type == TCP_CC_DUPACK)
62 {
Florin Corasf03a59a2017-06-09 21:07:32 -070063 if (!tcp_opts_sack_permitted (tc))
64 tc->cwnd += tc->snd_mss;
Dave Barach68b0fb02017-02-28 15:15:56 -050065 }
66 else if (ack_type == TCP_CC_PARTIALACK)
67 {
Florin Coras93992a92017-05-24 18:03:56 -070068 /* RFC 6582 Sec. 3.2 */
69 if (!tcp_opts_sack_permitted (&tc->rcv_opts))
70 {
71 /* Deflate the congestion window by the amount of new data
72 * acknowledged by the Cumulative Acknowledgment field.
73 * If the partial ACK acknowledges at least one SMSS of new data,
74 * then add back SMSS bytes to the congestion window. This
75 * artificially inflates the congestion window in order to reflect
76 * the additional segment that has left the network. This "partial
77 * window deflation" attempts to ensure that, when fast recovery
78 * eventually ends, approximately ssthresh amount of data will be
79 * outstanding in the network.*/
Dave Barach2c25a622017-06-26 11:35:07 -040080 tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ?
81 tc->cwnd - tc->bytes_acked : tc->snd_mss;
Florin Coras93992a92017-05-24 18:03:56 -070082 if (tc->bytes_acked > tc->snd_mss)
83 tc->cwnd += tc->snd_mss;
84 }
Dave Barach68b0fb02017-02-28 15:15:56 -050085 }
86}
87
Florin Corasa3c32652019-07-03 17:47:22 -070088static void
Dave Barach68b0fb02017-02-28 15:15:56 -050089newreno_conn_init (tcp_connection_t * tc)
90{
91 tc->ssthresh = tc->snd_wnd;
92 tc->cwnd = tcp_initial_cwnd (tc);
93}
94
95const static tcp_cc_algorithm_t tcp_newreno = {
Florin Corasaa01abb2018-11-12 09:13:10 -080096 .name = "newreno",
Dave Barach68b0fb02017-02-28 15:15:56 -050097 .congestion = newreno_congestion,
Florin Corasa3c32652019-07-03 17:47:22 -070098 .loss = newreno_loss,
Dave Barach68b0fb02017-02-28 15:15:56 -050099 .recovered = newreno_recovered,
100 .rcv_ack = newreno_rcv_ack,
101 .rcv_cong_ack = newreno_rcv_cong_ack,
102 .init = newreno_conn_init
103};
104
105clib_error_t *
106newreno_init (vlib_main_t * vm)
107{
108 clib_error_t *error = 0;
109
110 tcp_cc_algo_register (TCP_CC_NEWRENO, &tcp_newreno);
111
112 return error;
113}
114
115VLIB_INIT_FUNCTION (newreno_init);
116
117/*
118 * fd.io coding-style-patch-verification: ON
119 *
120 * Local Variables:
121 * eval: (c-set-style "gnu")
122 * End:
123 */