Improve session debugging
[vpp.git] / src / vnet / tcp / tcp.h
index 2f5da10..c3ebe22 100644 (file)
@@ -24,8 +24,8 @@
 #include <vnet/session/session.h>
 #include <vnet/tcp/tcp_debug.h>
 
-#define TCP_TICK 10e-3                 /**< TCP tick period (s) */
-#define THZ 1/TCP_TICK                 /**< TCP tick frequency */
+#define TCP_TICK 0.001                 /**< TCP tick period (s) */
+#define THZ (u32) (1/TCP_TICK)         /**< TCP tick frequency */
 #define TCP_TSTAMP_RESOLUTION TCP_TICK /**< Time stamp resolution */
 #define TCP_PAWS_IDLE 24 * 24 * 60 * 60 * THZ /**< 24 days */
 #define TCP_MAX_OPTION_SPACE 40
@@ -58,6 +58,8 @@ typedef enum _tcp_state
 } tcp_state_t;
 
 format_function_t format_tcp_state;
+format_function_t format_tcp_flags;
+format_function_t format_tcp_sacks;
 
 /** TCP timers */
 #define foreach_tcp_timer               \
@@ -94,14 +96,13 @@ extern timer_expiration_handler tcp_timer_retransmit_syn_handler;
 #define TCP_2MSL_TIME           300    /* 30s */
 #define TCP_CLOSEWAIT_TIME     1       /* 0.1s */
 #define TCP_CLEANUP_TIME       5       /* 0.5s Time to wait before cleanup */
+#define TCP_TIMER_PERSIST_MIN  2       /* 0.2s */
 
 #define TCP_RTO_MAX 60 * THZ   /* Min max RTO (60s) as per RFC6298 */
 #define TCP_RTT_MAX 30 * THZ   /* 30s (probably too much) */
 #define TCP_RTO_SYN_RETRIES 3  /* SYN retries without doubling RTO */
 #define TCP_RTO_INIT 1 * THZ   /* Initial retransmit timer */
 
-void tcp_update_time (f64 now, u32 thread_index);
-
 /** TCP connection flags */
 #define foreach_tcp_connection_flag             \
   _(SNDACK, "Send ACK")                         \
@@ -210,7 +211,9 @@ typedef struct _tcp_connection
   u32 irs;             /**< initial remote sequence */
 
   /* Options */
-  tcp_options_t opt;   /**< TCP connection options parsed */
+  tcp_options_t opt;           /**< TCP connection options parsed */
+  tcp_options_t snd_opts;      /**< Tx options for connection */
+  u8 snd_opts_len;             /**< Tx options len */
   u8 rcv_wscale;       /**< Window scale to advertise to peer */
   u8 snd_wscale;       /**< Window scale to use when sending */
   u32 tsval_recent;    /**< Last timestamp received */
@@ -240,7 +243,8 @@ typedef struct _tcp_connection
   u32 rtt_ts;          /**< Timestamp for tracked ACK */
   u32 rtt_seq;         /**< Sequence number for tracked ACK */
 
-  u16 snd_mss;         /**< Send MSS */
+  u16 snd_mss;         /**< Effective send max seg (data) size */
+  u16 mss;             /**< Our max seg size that includes options */
 } tcp_connection_t;
 
 struct _tcp_cc_algorithm
@@ -350,6 +354,14 @@ vnet_get_tcp_main ()
   return &tcp_main;
 }
 
+always_inline tcp_header_t *
+tcp_buffer_hdr (vlib_buffer_t * b)
+{
+  ASSERT ((signed) b->current_data >= (signed) -VLIB_BUFFER_PRE_DATA_SIZE);
+  return (tcp_header_t *) (b->data + b->current_data
+                          + vnet_buffer (b)->tcp.hdr_offset);
+}
+
 clib_error_t *vnet_tcp_enable_disable (vlib_main_t * vm, u8 is_en);
 
 always_inline tcp_connection_t *
@@ -375,8 +387,9 @@ void tcp_connection_cleanup (tcp_connection_t * tc);
 void tcp_connection_del (tcp_connection_t * tc);
 void tcp_connection_reset (tcp_connection_t * tc);
 
+u8 *format_tcp_connection_id (u8 * s, va_list * args);
 u8 *format_tcp_connection (u8 * s, va_list * args);
-u8 *format_tcp_connection_verbose (u8 * s, va_list * args);
+u8 *format_tcp_scoreboard (u8 * s, va_list * args);
 
 always_inline tcp_connection_t *
 tcp_listener_get (u32 tli)
@@ -396,7 +409,8 @@ void tcp_make_synack (tcp_connection_t * ts, vlib_buffer_t * b);
 void tcp_send_reset (vlib_buffer_t * pkt, u8 is_ip4);
 void tcp_send_syn (tcp_connection_t * tc);
 void tcp_send_fin (tcp_connection_t * tc);
-void tcp_set_snd_mss (tcp_connection_t * tc);
+void tcp_init_mss (tcp_connection_t * tc);
+void tcp_update_snd_mss (tcp_connection_t * tc);
 
 always_inline u32
 tcp_end_seq (tcp_header_t * th, u32 len)
@@ -467,20 +481,31 @@ tcp_available_snd_space (const tcp_connection_t * tc)
   return available_wnd - flight_size;
 }
 
+u32 tcp_rcv_wnd_available (tcp_connection_t * tc);
+u32 tcp_snd_space (tcp_connection_t * tc);
 void tcp_update_rcv_wnd (tcp_connection_t * tc);
 
 void tcp_retransmit_first_unacked (tcp_connection_t * tc);
-
 void tcp_fast_retransmit (tcp_connection_t * tc);
 void tcp_cc_congestion (tcp_connection_t * tc);
 void tcp_cc_recover (tcp_connection_t * tc);
 
+/* Made public for unit testing only */
+void tcp_update_sack_list (tcp_connection_t * tc, u32 start, u32 end);
+
 always_inline u32
 tcp_time_now (void)
 {
   return clib_cpu_time_now () * tcp_main.tstamp_ticks_per_clock;
 }
 
+always_inline void
+tcp_update_time (f64 now, u32 thread_index)
+{
+  tw_timer_expire_timers_16t_2w_512sl (&tcp_main.timer_wheels[thread_index],
+                                      now);
+}
+
 u32 tcp_push_header (transport_connection_t * tconn, vlib_buffer_t * b);
 
 u32
@@ -489,7 +514,6 @@ tcp_prepare_retransmit_segment (tcp_connection_t * tc, vlib_buffer_t * b,
 
 void tcp_connection_timers_init (tcp_connection_t * tc);
 void tcp_connection_timers_reset (tcp_connection_t * tc);
-
 void tcp_connection_init_vars (tcp_connection_t * tc);
 
 always_inline void
@@ -556,14 +580,16 @@ tcp_persist_timer_set (tcp_connection_t * tc)
 {
   /* Reuse RTO. It's backed off in handler */
   tcp_timer_set (tc, TCP_TIMER_PERSIST,
-                clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+                clib_max (tc->rto * TCP_TO_TIMER_TICK,
+                          TCP_TIMER_PERSIST_MIN));
 }
 
 always_inline void
 tcp_persist_timer_update (tcp_connection_t * tc)
 {
   tcp_timer_update (tc, TCP_TIMER_PERSIST,
-                   clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+                   clib_max (tc->rto * TCP_TO_TIMER_TICK,
+                             TCP_TIMER_PERSIST_MIN));
 }
 
 always_inline void