Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | c5df8c7 | 2019-04-08 07:42:30 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 15 | #ifndef __included_tcp_timer_h__ |
| 16 | #define __included_tcp_timer_h__ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 17 | |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 18 | #include <vnet/tcp/tcp_types.h> |
| 19 | |
| 20 | always_inline void |
| 21 | tcp_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 Coras | 49036a5 | 2020-10-08 09:28:32 -0700 | [diff] [blame] | 26 | tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index, |
| 27 | timer_id, interval); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | always_inline void |
| 31 | tcp_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 Coras | 1caf7f1 | 2020-07-16 10:05:02 -0700 | [diff] [blame] | 34 | tc->pending_timers &= ~(1 << timer_id); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 35 | if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID) |
| 36 | return; |
| 37 | |
Florin Coras | 49036a5 | 2020-10-08 09:28:32 -0700 | [diff] [blame] | 38 | tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 39 | tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID; |
| 40 | } |
| 41 | |
| 42 | always_inline void |
| 43 | tcp_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 Coras | 49036a5 | 2020-10-08 09:28:32 -0700 | [diff] [blame] | 48 | tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 49 | else |
Florin Coras | 49036a5 | 2020-10-08 09:28:32 -0700 | [diff] [blame] | 50 | tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index, |
| 51 | timer_id, interval); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | always_inline void |
| 55 | tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 56 | { |
| 57 | ASSERT (tc->snd_una != tc->snd_una_max); |
| 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 |
| 63 | tcp_retransmit_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 64 | { |
| 65 | tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT); |
| 66 | } |
| 67 | |
| 68 | always_inline void |
| 69 | tcp_retransmit_timer_force_update (tcp_timer_wheel_t * tw, |
| 70 | tcp_connection_t * tc) |
| 71 | { |
| 72 | tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT, |
| 73 | clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); |
| 74 | } |
| 75 | |
| 76 | always_inline void |
| 77 | tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 78 | { |
| 79 | /* Reuse RTO. It's backed off in handler */ |
| 80 | tcp_timer_set (tw, tc, TCP_TIMER_PERSIST, |
| 81 | clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); |
| 82 | } |
| 83 | |
| 84 | always_inline void |
| 85 | tcp_persist_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 86 | { |
| 87 | u32 interval; |
| 88 | |
| 89 | if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked)) |
| 90 | interval = 1; |
| 91 | else |
| 92 | interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1); |
| 93 | |
| 94 | tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval); |
| 95 | } |
| 96 | |
| 97 | always_inline void |
| 98 | tcp_persist_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 99 | { |
| 100 | tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST); |
| 101 | } |
| 102 | |
| 103 | always_inline void |
| 104 | tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc) |
| 105 | { |
| 106 | if (tc->snd_una == tc->snd_nxt) |
| 107 | { |
| 108 | tcp_retransmit_timer_reset (tw, tc); |
| 109 | if (tc->snd_wnd < tc->snd_mss) |
| 110 | tcp_persist_timer_update (tw, tc); |
| 111 | } |
| 112 | else |
| 113 | tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT, |
| 114 | clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); |
| 115 | } |
| 116 | |
| 117 | always_inline u8 |
| 118 | tcp_timer_is_active (tcp_connection_t * tc, tcp_timers_e timer) |
| 119 | { |
Florin Coras | aa04395 | 2020-10-08 13:33:20 -0700 | [diff] [blame] | 120 | return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID |
| 121 | || (tc->pending_timers & (1 << timer)); |
Florin Coras | 0765d97 | 2020-03-18 21:26:41 +0000 | [diff] [blame] | 122 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 123 | |
Florin Coras | 49036a5 | 2020-10-08 09:28:32 -0700 | [diff] [blame] | 124 | always_inline void |
| 125 | tcp_timer_expire_timers (tcp_timer_wheel_t * tw, f64 now) |
| 126 | { |
| 127 | tw_timer_expire_timers_tcp_twsl (tw, now); |
| 128 | } |
| 129 | |
| 130 | void tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw, |
| 131 | void (*expired_timer_cb) (u32 *), f64 now); |
| 132 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 133 | #endif /* __included_tcp_timer_h__ */ |
| 134 | |
| 135 | /* |
| 136 | * fd.io coding-style-patch-verification: ON |
| 137 | * |
| 138 | * Local Variables: |
| 139 | * eval: (c-set-style "gnu") |
| 140 | * End: |
| 141 | */ |