FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
tcp_timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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 #ifndef __included_tcp_timer_h__
16 #define __included_tcp_timer_h__
17 
18 #include <vnet/tcp/tcp_types.h>
19 
20 always_inline void
22  u32 interval)
23 {
24  ASSERT (tc->c_thread_index == vlib_get_thread_index ());
25  ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
26  tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
27  timer_id, interval);
28 }
29 
30 always_inline void
32 {
33  ASSERT (tc->c_thread_index == vlib_get_thread_index ());
34  if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
35  return;
36 
37  tw_timer_stop_16t_2w_512sl (tw, tc->timers[timer_id]);
38  tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
39 }
40 
41 always_inline void
43  u32 interval)
44 {
45  ASSERT (tc->c_thread_index == vlib_get_thread_index ());
46  if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
47  tw_timer_update_16t_2w_512sl (tw, tc->timers[timer_id], interval);
48  else
49  tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
50  timer_id, interval);
51 }
52 
53 always_inline void
55 {
56  ASSERT (tc->snd_una != tc->snd_una_max);
57  tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
58  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
59 }
60 
61 always_inline void
63 {
64  tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
65 }
66 
67 always_inline void
69  tcp_connection_t * tc)
70 {
71  tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
72  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
73 }
74 
75 always_inline void
77 {
78  /* Reuse RTO. It's backed off in handler */
79  tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
80  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
81 }
82 
83 always_inline void
85 {
86  u32 interval;
87 
88  if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked))
89  interval = 1;
90  else
91  interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1);
92 
93  tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval);
94 }
95 
96 always_inline void
98 {
99  tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
100 }
101 
102 always_inline void
104 {
105  if (tc->snd_una == tc->snd_nxt)
106  {
108  if (tc->snd_wnd < tc->snd_mss)
109  tcp_persist_timer_update (tw, tc);
110  }
111  else
112  tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
113  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
114 }
115 
118 {
119  return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID;
120 }
121 
122 #endif /* __included_tcp_timer_h__ */
123 
124 /*
125  * fd.io coding-style-patch-verification: ON
126  *
127  * Local Variables:
128  * eval: (c-set-style "gnu")
129  * End:
130  */
#define TCP_TIMER_HANDLE_INVALID
Definition: tcp_types.h:78
static void tcp_persist_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:76
struct _tcp_connection tcp_connection_t
unsigned char u8
Definition: types.h:56
static void tcp_persist_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:97
#define seq_leq(_s1, _s2)
Definition: tcp_packet.h:178
static void tcp_retransmit_timer_force_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:68
unsigned int u32
Definition: types.h:88
static void tcp_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id)
Definition: tcp_timer.h:31
static void tcp_retransmit_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:103
static void tcp_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp_timer.h:21
enum _tcp_timers tcp_timers_e
static void tcp_retransmit_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:62
static void tcp_retransmit_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:54
tw_timer_wheel_16t_2w_512sl_t tcp_timer_wheel_t
Definition: tcp_types.h:445
#define always_inline
Definition: ipsec.h:28
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:218
#define TCP_TO_TIMER_TICK
Factor for converting ticks to timer ticks.
Definition: tcp_types.h:81
#define ASSERT(truth)
u16 interval
Definition: vrrp.api:34
#define clib_max(x, y)
Definition: clib.h:312
static void tcp_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp_timer.h:42
static u8 tcp_timer_is_active(tcp_connection_t *tc, tcp_timers_e timer)
Definition: tcp_timer.h:117
static void tcp_persist_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:84