blob: c0907cae1ccb12d22f4a6482e9e8fb18a27d1bff [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2016-2019 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * 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 */
Dave Barach68b0fb02017-02-28 15:15:56 -050015#ifndef __included_tcp_timer_h__
16#define __included_tcp_timer_h__
Ed Warnickecb9cada2015-12-08 15:45:58 -070017
Florin Coras0765d972020-03-18 21:26:41 +000018#include <vnet/tcp/tcp_types.h>
19
Florin Coras309f7aa2022-03-18 08:33:08 -070020static inline u8
21tcp_timer_thread_is_valid (tcp_connection_t *tc)
22{
23 return ((tc->c_thread_index == vlib_get_thread_index ()) ||
24 vlib_thread_is_main_w_barrier ());
25}
26
Florin Coras0765d972020-03-18 21:26:41 +000027always_inline void
Florin Coras309f7aa2022-03-18 08:33:08 -070028tcp_timer_set (tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id,
Florin Coras0765d972020-03-18 21:26:41 +000029 u32 interval)
30{
Florin Coras309f7aa2022-03-18 08:33:08 -070031 ASSERT (tcp_timer_thread_is_valid (tc));
Florin Coras0765d972020-03-18 21:26:41 +000032 ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
Florin Coras49036a52020-10-08 09:28:32 -070033 tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
34 timer_id, interval);
Florin Coras0765d972020-03-18 21:26:41 +000035}
36
37always_inline void
38tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id)
39{
Florin Coras309f7aa2022-03-18 08:33:08 -070040 ASSERT (tcp_timer_thread_is_valid (tc));
Florin Coras1caf7f12020-07-16 10:05:02 -070041 tc->pending_timers &= ~(1 << timer_id);
Florin Coras0765d972020-03-18 21:26:41 +000042 if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
43 return;
44
Florin Coras49036a52020-10-08 09:28:32 -070045 tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]);
Florin Coras0765d972020-03-18 21:26:41 +000046 tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
47}
48
49always_inline void
50tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
51 u32 interval)
52{
Florin Coras309f7aa2022-03-18 08:33:08 -070053 ASSERT (tcp_timer_thread_is_valid (tc));
Florin Coras0765d972020-03-18 21:26:41 +000054 if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
Florin Coras49036a52020-10-08 09:28:32 -070055 tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval);
Florin Coras0765d972020-03-18 21:26:41 +000056 else
Florin Coras49036a52020-10-08 09:28:32 -070057 tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
58 timer_id, interval);
Florin Coras0765d972020-03-18 21:26:41 +000059}
60
Florin Corasc8144352022-01-06 11:58:24 -080061always_inline u8
62tcp_timer_is_active (tcp_connection_t *tc, tcp_timers_e timer)
63{
64 return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID ||
65 (tc->pending_timers & (1 << timer));
66}
67
Florin Coras0765d972020-03-18 21:26:41 +000068always_inline void
69tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
70{
Florin Coras55e556c2020-10-23 10:45:48 -070071 ASSERT (tc->snd_una != tc->snd_nxt);
Florin Coras0765d972020-03-18 21:26:41 +000072 tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
Florin Coras273968c2022-01-03 10:34:52 -080073 clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
Florin Coras0765d972020-03-18 21:26:41 +000074}
75
76always_inline void
77tcp_retransmit_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
78{
79 tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
80}
81
82always_inline void
Florin Coras0765d972020-03-18 21:26:41 +000083tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
84{
85 /* Reuse RTO. It's backed off in handler */
86 tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
Florin Coras273968c2022-01-03 10:34:52 -080087 clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
Florin Coras0765d972020-03-18 21:26:41 +000088}
89
90always_inline void
Florin Coras0765d972020-03-18 21:26:41 +000091tcp_persist_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
92{
93 tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
94}
95
96always_inline void
97tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
98{
99 if (tc->snd_una == tc->snd_nxt)
100 {
101 tcp_retransmit_timer_reset (tw, tc);
Florin Corasc8144352022-01-06 11:58:24 -0800102 if (tc->snd_wnd < tc->snd_mss &&
103 !tcp_timer_is_active (tc, TCP_TIMER_PERSIST))
104 tcp_persist_timer_set (tw, tc);
Florin Coras0765d972020-03-18 21:26:41 +0000105 }
106 else
107 tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
Florin Coras273968c2022-01-03 10:34:52 -0800108 clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
Florin Coras0765d972020-03-18 21:26:41 +0000109}
110
Florin Coras49036a52020-10-08 09:28:32 -0700111always_inline void
112tcp_timer_expire_timers (tcp_timer_wheel_t * tw, f64 now)
113{
114 tw_timer_expire_timers_tcp_twsl (tw, now);
115}
116
117void tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw,
118 void (*expired_timer_cb) (u32 *), f64 now);
119
Dave Barach68b0fb02017-02-28 15:15:56 -0500120#endif /* __included_tcp_timer_h__ */
121
122/*
123 * fd.io coding-style-patch-verification: ON
124 *
125 * Local Variables:
126 * eval: (c-set-style "gnu")
127 * End:
128 */