blob: 5f14a71ee7d5b85780d06d5ba34bd67fd28dccfe [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
20always_inline void
21tcp_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
22 u32 interval)
23{
24 ASSERT (tc->c_thread_index == vlib_get_thread_index ());
25 ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
Florin Coras49036a52020-10-08 09:28:32 -070026 tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
27 timer_id, interval);
Florin Coras0765d972020-03-18 21:26:41 +000028}
29
30always_inline void
31tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id)
32{
33 ASSERT (tc->c_thread_index == vlib_get_thread_index ());
Florin Coras1caf7f12020-07-16 10:05:02 -070034 tc->pending_timers &= ~(1 << timer_id);
Florin Coras0765d972020-03-18 21:26:41 +000035 if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
36 return;
37
Florin Coras49036a52020-10-08 09:28:32 -070038 tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]);
Florin Coras0765d972020-03-18 21:26:41 +000039 tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
40}
41
42always_inline void
43tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
44 u32 interval)
45{
46 ASSERT (tc->c_thread_index == vlib_get_thread_index ());
47 if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
Florin Coras49036a52020-10-08 09:28:32 -070048 tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval);
Florin Coras0765d972020-03-18 21:26:41 +000049 else
Florin Coras49036a52020-10-08 09:28:32 -070050 tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
51 timer_id, interval);
Florin Coras0765d972020-03-18 21:26:41 +000052}
53
54always_inline void
55tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
56{
Florin Coras55e556c2020-10-23 10:45:48 -070057 ASSERT (tc->snd_una != tc->snd_nxt);
Florin Coras0765d972020-03-18 21:26:41 +000058 tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
Florin Coras273968c2022-01-03 10:34:52 -080059 clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
Florin Coras0765d972020-03-18 21:26:41 +000060}
61
62always_inline void
63tcp_retransmit_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
64{
65 tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
66}
67
68always_inline void
Florin Coras0765d972020-03-18 21:26:41 +000069tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
70{
71 /* Reuse RTO. It's backed off in handler */
72 tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
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_persist_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
78{
79 u32 interval;
80
81 if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked))
82 interval = 1;
83 else
Florin Coras273968c2022-01-03 10:34:52 -080084 interval = clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1);
Florin Coras0765d972020-03-18 21:26:41 +000085
86 tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval);
87}
88
89always_inline void
90tcp_persist_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
91{
92 tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
93}
94
95always_inline void
96tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
97{
98 if (tc->snd_una == tc->snd_nxt)
99 {
100 tcp_retransmit_timer_reset (tw, tc);
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,
Florin Coras273968c2022-01-03 10:34:52 -0800106 clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
Florin Coras0765d972020-03-18 21:26:41 +0000107}
108
109always_inline u8
110tcp_timer_is_active (tcp_connection_t * tc, tcp_timers_e timer)
111{
Florin Corasaa043952020-10-08 13:33:20 -0700112 return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID
113 || (tc->pending_timers & (1 << timer));
Florin Coras0765d972020-03-18 21:26:41 +0000114}
Dave Barach68b0fb02017-02-28 15:15:56 -0500115
Florin Coras49036a52020-10-08 09:28:32 -0700116always_inline void
117tcp_timer_expire_timers (tcp_timer_wheel_t * tw, f64 now)
118{
119 tw_timer_expire_timers_tcp_twsl (tw, now);
120}
121
122void tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw,
123 void (*expired_timer_cb) (u32 *), f64 now);
124
Dave Barach68b0fb02017-02-28 15:15:56 -0500125#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 */