aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/tcp/tcp_timer.h
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-03-18 21:26:41 +0000
committerDave Barach <openvpp@barachs.net>2020-04-02 19:17:11 +0000
commit0765d97abef74727c040d2eaf9112865d59f1593 (patch)
treee3639e34a0fccf8b40a6114676f704d9bac205e2 /src/vnet/tcp/tcp_timer.h
parent48d32b43c534c9f52d37b047dbcbc30a8882b52a (diff)
tcp: explicit use of timer wheel in timer apis
Type: refactor Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I06120d43c15b2fa3f437ef235bf5f83ec2beb45e
Diffstat (limited to 'src/vnet/tcp/tcp_timer.h')
-rw-r--r--src/vnet/tcp/tcp_timer.h105
1 files changed, 103 insertions, 2 deletions
diff --git a/src/vnet/tcp/tcp_timer.h b/src/vnet/tcp/tcp_timer.h
index 08516b7eec2..d34fdcb146d 100644
--- a/src/vnet/tcp/tcp_timer.h
+++ b/src/vnet/tcp/tcp_timer.h
@@ -15,8 +15,109 @@
#ifndef __included_tcp_timer_h__
#define __included_tcp_timer_h__
-#include <vppinfra/tw_timer_16t_2w_512sl.h>
-#include <vppinfra/tw_timer_16t_1w_2048sl.h>
+#include <vnet/tcp/tcp_types.h>
+
+always_inline void
+tcp_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
+ u32 interval)
+{
+ ASSERT (tc->c_thread_index == vlib_get_thread_index ());
+ ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
+ tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
+ timer_id, interval);
+}
+
+always_inline void
+tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id)
+{
+ ASSERT (tc->c_thread_index == vlib_get_thread_index ());
+ if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
+ return;
+
+ tw_timer_stop_16t_2w_512sl (tw, tc->timers[timer_id]);
+ tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
+}
+
+always_inline void
+tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
+ u32 interval)
+{
+ ASSERT (tc->c_thread_index == vlib_get_thread_index ());
+ if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
+ tw_timer_update_16t_2w_512sl (tw, tc->timers[timer_id], interval);
+ else
+ tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
+ timer_id, interval);
+}
+
+always_inline void
+tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ ASSERT (tc->snd_una != tc->snd_una_max);
+ tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
+ clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+}
+
+always_inline void
+tcp_retransmit_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
+}
+
+always_inline void
+tcp_retransmit_timer_force_update (tcp_timer_wheel_t * tw,
+ tcp_connection_t * tc)
+{
+ tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
+ clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+}
+
+always_inline void
+tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ /* Reuse RTO. It's backed off in handler */
+ tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
+ clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+}
+
+always_inline void
+tcp_persist_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ u32 interval;
+
+ if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked))
+ interval = 1;
+ else
+ interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1);
+
+ tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval);
+}
+
+always_inline void
+tcp_persist_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
+}
+
+always_inline void
+tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
+{
+ if (tc->snd_una == tc->snd_nxt)
+ {
+ tcp_retransmit_timer_reset (tw, tc);
+ if (tc->snd_wnd < tc->snd_mss)
+ tcp_persist_timer_update (tw, tc);
+ }
+ else
+ tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
+ clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+}
+
+always_inline u8
+tcp_timer_is_active (tcp_connection_t * tc, tcp_timers_e timer)
+{
+ return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID;
+}
#endif /* __included_tcp_timer_h__ */