FD.io VPP  v21.10.1-2-g0a485f517
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_tcp_twsl (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  tc->pending_timers &= ~(1 << timer_id);
35  if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
36  return;
37 
38  tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]);
39  tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
40 }
41 
42 always_inline void
44  u32 interval)
45 {
46  ASSERT (tc->c_thread_index == vlib_get_thread_index ());
47  if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
48  tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval);
49  else
50  tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
51  timer_id, interval);
52 }
53 
54 always_inline void
56 {
57  ASSERT (tc->snd_una != tc->snd_nxt);
58  tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
59  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
60 }
61 
62 always_inline void
64 {
65  tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
66 }
67 
68 always_inline void
70 {
71  /* Reuse RTO. It's backed off in handler */
72  tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
73  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
74 }
75 
76 always_inline void
78 {
79  u32 interval;
80 
81  if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked))
82  interval = 1;
83  else
84  interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1);
85 
86  tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval);
87 }
88 
89 always_inline void
91 {
92  tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
93 }
94 
95 always_inline void
97 {
98  if (tc->snd_una == tc->snd_nxt)
99  {
101  if (tc->snd_wnd < tc->snd_mss)
102  tcp_persist_timer_update (tw, tc);
103  }
104  else
105  tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
106  clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
107 }
108 
111 {
112  return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID
113  || (tc->pending_timers & (1 << timer));
114 }
115 
116 always_inline void
118 {
119  tw_timer_expire_timers_tcp_twsl (tw, now);
120 }
121 
123  void (*expired_timer_cb) (u32 *), f64 now);
124 
125 #endif /* __included_tcp_timer_h__ */
126 
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */
clib_max
#define clib_max(x, y)
Definition: clib.h:335
tcp_retransmit_timer_set
static void tcp_retransmit_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:55
tcp_connection_t
struct _tcp_connection tcp_connection_t
tcp_timer_update
static void tcp_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp_timer.h:43
tcp_timer_initialize_wheel
void tcp_timer_initialize_wheel(tcp_timer_wheel_t *tw, void(*expired_timer_cb)(u32 *), f64 now)
Definition: tcp_timer.c:20
tcp_timer_expire_timers
static void tcp_timer_expire_timers(tcp_timer_wheel_t *tw, f64 now)
Definition: tcp_timer.h:117
TCP_TO_TIMER_TICK
#define TCP_TO_TIMER_TICK
Factor for converting ticks to timer ticks.
Definition: tcp_types.h:82
tcp_timers_e
enum _tcp_timers tcp_timers_e
tcp_timer_reset
static void tcp_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id)
Definition: tcp_timer.h:31
tcp_retransmit_timer_reset
static void tcp_retransmit_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:63
seq_leq
#define seq_leq(_s1, _s2)
Definition: tcp_packet.h:179
tcp_timer_is_active
static u8 tcp_timer_is_active(tcp_connection_t *tc, tcp_timers_e timer)
Definition: tcp_timer.h:110
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
tcp_retransmit_timer_update
static void tcp_retransmit_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:96
tcp_timer_set
static void tcp_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp_timer.h:21
f64
double f64
Definition: types.h:142
interval
u16 interval
Definition: vrrp.api:34
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
now
f64 now
Definition: nat44_ei_out2in.c:710
tcp_persist_timer_update
static void tcp_persist_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:77
u8
unsigned char u8
Definition: types.h:56
tcp_types.h
tcp_timer_wheel_t
tw_timer_wheel_tcp_twsl_t tcp_timer_wheel_t
Definition: tcp_types.h:475
tcp_persist_timer_set
static void tcp_persist_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:69
TCP_TIMER_HANDLE_INVALID
#define TCP_TIMER_HANDLE_INVALID
Definition: tcp_types.h:79
tcp_persist_timer_reset
static void tcp_persist_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
Definition: tcp_timer.h:90