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 | |
| 18 | void |
| 19 | newreno_congestion (tcp_connection_t * tc) |
| 20 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 21 | tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss); |
| 22 | } |
| 23 | |
| 24 | void |
| 25 | newreno_recovered (tcp_connection_t * tc) |
| 26 | { |
| 27 | tc->cwnd = tc->ssthresh; |
| 28 | } |
| 29 | |
| 30 | void |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame^] | 31 | newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 32 | { |
| 33 | if (tcp_in_slowstart (tc)) |
| 34 | { |
| 35 | tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked); |
| 36 | } |
| 37 | else |
| 38 | { |
Florin Coras | 6216600 | 2018-04-18 16:40:55 -0700 | [diff] [blame] | 39 | /* 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] | 40 | tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | void |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame^] | 45 | newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type, |
| 46 | tcp_rate_sample_t * rs) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 47 | { |
| 48 | if (ack_type == TCP_CC_DUPACK) |
| 49 | { |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 50 | if (!tcp_opts_sack_permitted (tc)) |
| 51 | tc->cwnd += tc->snd_mss; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 52 | } |
| 53 | else if (ack_type == TCP_CC_PARTIALACK) |
| 54 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 55 | /* RFC 6582 Sec. 3.2 */ |
| 56 | if (!tcp_opts_sack_permitted (&tc->rcv_opts)) |
| 57 | { |
| 58 | /* Deflate the congestion window by the amount of new data |
| 59 | * acknowledged by the Cumulative Acknowledgment field. |
| 60 | * If the partial ACK acknowledges at least one SMSS of new data, |
| 61 | * then add back SMSS bytes to the congestion window. This |
| 62 | * artificially inflates the congestion window in order to reflect |
| 63 | * the additional segment that has left the network. This "partial |
| 64 | * window deflation" attempts to ensure that, when fast recovery |
| 65 | * eventually ends, approximately ssthresh amount of data will be |
| 66 | * outstanding in the network.*/ |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 67 | tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ? |
| 68 | tc->cwnd - tc->bytes_acked : tc->snd_mss; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 69 | if (tc->bytes_acked > tc->snd_mss) |
| 70 | tc->cwnd += tc->snd_mss; |
| 71 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | newreno_conn_init (tcp_connection_t * tc) |
| 77 | { |
| 78 | tc->ssthresh = tc->snd_wnd; |
| 79 | tc->cwnd = tcp_initial_cwnd (tc); |
| 80 | } |
| 81 | |
| 82 | const static tcp_cc_algorithm_t tcp_newreno = { |
Florin Coras | aa01abb | 2018-11-12 09:13:10 -0800 | [diff] [blame] | 83 | .name = "newreno", |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 84 | .congestion = newreno_congestion, |
| 85 | .recovered = newreno_recovered, |
| 86 | .rcv_ack = newreno_rcv_ack, |
| 87 | .rcv_cong_ack = newreno_rcv_cong_ack, |
| 88 | .init = newreno_conn_init |
| 89 | }; |
| 90 | |
| 91 | clib_error_t * |
| 92 | newreno_init (vlib_main_t * vm) |
| 93 | { |
| 94 | clib_error_t *error = 0; |
| 95 | |
| 96 | tcp_cc_algo_register (TCP_CC_NEWRENO, &tcp_newreno); |
| 97 | |
| 98 | return error; |
| 99 | } |
| 100 | |
| 101 | VLIB_INIT_FUNCTION (newreno_init); |
| 102 | |
| 103 | /* |
| 104 | * fd.io coding-style-patch-verification: ON |
| 105 | * |
| 106 | * Local Variables: |
| 107 | * eval: (c-set-style "gnu") |
| 108 | * End: |
| 109 | */ |