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