Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | c5df8c7 | 2019-04-08 07:42:30 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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> |
Florin Coras | 999840c | 2020-03-18 20:31:34 +0000 | [diff] [blame] | 17 | #include <vnet/tcp/tcp_inlines.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 18 | |
Sergey Ivanushkin | c30318d | 2019-10-17 10:16:27 +0100 | [diff] [blame] | 19 | typedef struct nwreno_cfg_ |
| 20 | { |
| 21 | u32 ssthresh; |
| 22 | } newreno_cfg_t; |
| 23 | |
| 24 | static newreno_cfg_t newreno_cfg = { |
| 25 | .ssthresh = 0x7FFFFFFFU, |
| 26 | }; |
| 27 | |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 28 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 29 | newreno_congestion (tcp_connection_t * tc) |
| 30 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 31 | tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss); |
Florin Coras | 8b4114e | 2019-09-03 12:37:11 -0700 | [diff] [blame] | 32 | tc->cwnd = tc->ssthresh; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 35 | static void |
| 36 | newreno_loss (tcp_connection_t * tc) |
| 37 | { |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 38 | tc->cwnd = tcp_loss_wnd (tc); |
| 39 | } |
| 40 | |
| 41 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 42 | newreno_recovered (tcp_connection_t * tc) |
| 43 | { |
| 44 | tc->cwnd = tc->ssthresh; |
| 45 | } |
| 46 | |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 47 | static void |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame] | 48 | newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 49 | { |
| 50 | if (tcp_in_slowstart (tc)) |
| 51 | { |
Florin Coras | 0f8b91f | 2022-01-05 08:47:11 -0800 | [diff] [blame] | 52 | tc->cwnd += clib_min (tc->snd_mss, rs->delivered); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 53 | } |
| 54 | else |
| 55 | { |
Florin Coras | 6216600 | 2018-04-18 16:40:55 -0700 | [diff] [blame] | 56 | /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */ |
Florin Coras | 0f8b91f | 2022-01-05 08:47:11 -0800 | [diff] [blame] | 57 | tcp_cwnd_accumulate (tc, tc->cwnd, rs->delivered); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | void |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame] | 62 | newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type, |
| 63 | tcp_rate_sample_t * rs) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 64 | { |
Florin Coras | ec3a636 | 2022-01-06 17:47:14 -0800 | [diff] [blame^] | 65 | /* With sacks prr controls the data in flight post congestion */ |
| 66 | if (PREDICT_TRUE (tcp_opts_sack_permitted (tc))) |
| 67 | return; |
| 68 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 69 | if (ack_type == TCP_CC_DUPACK) |
| 70 | { |
Florin Coras | ec3a636 | 2022-01-06 17:47:14 -0800 | [diff] [blame^] | 71 | tc->cwnd += tc->snd_mss; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 72 | } |
| 73 | else if (ack_type == TCP_CC_PARTIALACK) |
| 74 | { |
Florin Coras | ec3a636 | 2022-01-06 17:47:14 -0800 | [diff] [blame^] | 75 | /* RFC 6582 Sec. 3.2 |
| 76 | * Deflate the congestion window by the amount of new data |
| 77 | * acknowledged by the Cumulative Acknowledgment field. |
| 78 | * If the partial ACK acknowledges at least one SMSS of new data, |
| 79 | * then add back SMSS bytes to the congestion window. This |
| 80 | * artificially inflates the congestion window in order to reflect |
| 81 | * the additional segment that has left the network. This "partial |
| 82 | * window deflation" attempts to ensure that, when fast recovery |
| 83 | * eventually ends, approximately ssthresh amount of data will be |
| 84 | * outstanding in the network. */ |
| 85 | tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ? |
| 86 | tc->cwnd - tc->bytes_acked : |
| 87 | tc->snd_mss; |
| 88 | if (tc->bytes_acked > tc->snd_mss) |
| 89 | tc->cwnd += tc->snd_mss; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 93 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 94 | newreno_conn_init (tcp_connection_t * tc) |
| 95 | { |
Sergey Ivanushkin | c30318d | 2019-10-17 10:16:27 +0100 | [diff] [blame] | 96 | tc->ssthresh = newreno_cfg.ssthresh; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 97 | tc->cwnd = tcp_initial_cwnd (tc); |
| 98 | } |
| 99 | |
Sergey Ivanushkin | c30318d | 2019-10-17 10:16:27 +0100 | [diff] [blame] | 100 | static uword |
| 101 | newreno_unformat_config (unformat_input_t * input) |
| 102 | { |
| 103 | u32 ssthresh = 0x7FFFFFFFU; |
| 104 | |
| 105 | if (!input) |
| 106 | return 0; |
| 107 | |
| 108 | unformat_skip_white_space (input); |
| 109 | |
| 110 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 111 | { |
| 112 | if (unformat (input, "ssthresh %u", &ssthresh)) |
| 113 | newreno_cfg.ssthresh = ssthresh; |
| 114 | else |
| 115 | return 0; |
| 116 | } |
| 117 | return 1; |
| 118 | } |
| 119 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 120 | const static tcp_cc_algorithm_t tcp_newreno = { |
Florin Coras | aa01abb | 2018-11-12 09:13:10 -0800 | [diff] [blame] | 121 | .name = "newreno", |
Sergey Ivanushkin | c30318d | 2019-10-17 10:16:27 +0100 | [diff] [blame] | 122 | .unformat_cfg = newreno_unformat_config, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 123 | .congestion = newreno_congestion, |
Florin Coras | a3c3265 | 2019-07-03 17:47:22 -0700 | [diff] [blame] | 124 | .loss = newreno_loss, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 125 | .recovered = newreno_recovered, |
| 126 | .rcv_ack = newreno_rcv_ack, |
| 127 | .rcv_cong_ack = newreno_rcv_cong_ack, |
| 128 | .init = newreno_conn_init |
| 129 | }; |
| 130 | |
| 131 | clib_error_t * |
| 132 | newreno_init (vlib_main_t * vm) |
| 133 | { |
| 134 | clib_error_t *error = 0; |
| 135 | |
| 136 | tcp_cc_algo_register (TCP_CC_NEWRENO, &tcp_newreno); |
| 137 | |
| 138 | return error; |
| 139 | } |
| 140 | |
| 141 | VLIB_INIT_FUNCTION (newreno_init); |
| 142 | |
| 143 | /* |
| 144 | * fd.io coding-style-patch-verification: ON |
| 145 | * |
| 146 | * Local Variables: |
| 147 | * eval: (c-set-style "gnu") |
| 148 | * End: |
| 149 | */ |