FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
tcp_newreno.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 
18 typedef struct nwreno_cfg_
19 {
22 
23 static newreno_cfg_t newreno_cfg = {
24  .ssthresh = 0x7FFFFFFFU,
25 };
26 
27 static void
29 {
30  tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
31  tc->cwnd = tc->ssthresh;
32 }
33 
34 static void
36 {
37  tc->cwnd = tcp_loss_wnd (tc);
38 }
39 
40 static void
42 {
43  tc->cwnd = tc->ssthresh;
44 }
45 
46 static void
48 {
49  if (tcp_in_slowstart (tc))
50  {
51  tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked);
52  }
53  else
54  {
55  /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */
56  tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked);
57  }
58 }
59 
60 void
62  tcp_rate_sample_t * rs)
63 {
64  if (ack_type == TCP_CC_DUPACK)
65  {
66  if (!tcp_opts_sack_permitted (tc))
67  tc->cwnd += tc->snd_mss;
68  }
69  else if (ack_type == TCP_CC_PARTIALACK)
70  {
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.*/
83  tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ?
84  tc->cwnd - tc->bytes_acked : tc->snd_mss;
85  if (tc->bytes_acked > tc->snd_mss)
86  tc->cwnd += tc->snd_mss;
87  }
88  }
89 }
90 
91 static void
93 {
94  tc->ssthresh = newreno_cfg.ssthresh;
95  tc->cwnd = tcp_initial_cwnd (tc);
96 }
97 
98 static uword
100 {
101  u32 ssthresh = 0x7FFFFFFFU;
102 
103  if (!input)
104  return 0;
105 
107 
109  {
110  if (unformat (input, "ssthresh %u", &ssthresh))
111  newreno_cfg.ssthresh = ssthresh;
112  else
113  return 0;
114  }
115  return 1;
116 }
117 
119  .name = "newreno",
120  .unformat_cfg = newreno_unformat_config,
121  .congestion = newreno_congestion,
122  .loss = newreno_loss,
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 *
131 {
132  clib_error_t *error = 0;
133 
135 
136  return error;
137 }
138 
140 
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "gnu")
146  * End:
147  */
static void newreno_recovered(tcp_connection_t *tc)
Definition: tcp_newreno.c:41
static void newreno_conn_init(tcp_connection_t *tc)
Definition: tcp_newreno.c:92
#define clib_min(x, y)
Definition: clib.h:295
struct nwreno_cfg_ newreno_cfg_t
struct _tcp_connection tcp_connection_t
static void newreno_loss(tcp_connection_t *tc)
Definition: tcp_newreno.c:35
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define tcp_in_slowstart(tc)
Definition: tcp.h:466
unsigned int u32
Definition: types.h:88
struct _unformat_input_t unformat_input_t
static u32 tcp_flight_size(const tcp_connection_t *tc)
Our estimate of the number of bytes in flight (pipe size)
Definition: tcp.h:900
static uword newreno_unformat_config(unformat_input_t *input)
Definition: tcp_newreno.c:99
vlib_main_t * vm
Definition: in2out_ed.c:1810
enum _tcp_cc_ack_t tcp_cc_ack_t
static void tcp_cwnd_accumulate(tcp_connection_t *tc, u32 thresh, u32 bytes)
Definition: tcp.h:936
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
clib_error_t * newreno_init(vlib_main_t *vm)
Definition: tcp_newreno.c:130
static void newreno_rcv_ack(tcp_connection_t *tc, tcp_rate_sample_t *rs)
Definition: tcp_newreno.c:47
void tcp_cc_algo_register(tcp_cc_algorithm_type_e type, const tcp_cc_algorithm_t *vft)
Register exiting cc algo type.
Definition: tcp.c:86
struct _tcp_cc_algorithm tcp_cc_algorithm_t
Definition: tcp.h:305
#define clib_max(x, y)
Definition: clib.h:288
static u32 tcp_initial_cwnd(const tcp_connection_t *tc)
Initial cwnd as per RFC5681.
Definition: tcp.h:916
static const tcp_cc_algorithm_t tcp_newreno
Definition: tcp_newreno.c:118
u64 uword
Definition: types.h:112
void newreno_rcv_cong_ack(tcp_connection_t *tc, tcp_cc_ack_t ack_type, tcp_rate_sample_t *rs)
Definition: tcp_newreno.c:61
#define tcp_opts_sack_permitted(_to)
Definition: tcp_packet.h:159
static u32 tcp_loss_wnd(const tcp_connection_t *tc)
Definition: tcp.h:949
static void newreno_congestion(tcp_connection_t *tc)
Definition: tcp_newreno.c:28
uword unformat_skip_white_space(unformat_input_t *input)
Definition: unformat.c:821
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171