Improvements to tcp rx path and debugging
[vpp.git] / src / vnet / tcp / tcp.h
index 37b10fd..89c3061 100644 (file)
@@ -33,6 +33,7 @@
 
 #define TCP_DUPACK_THRESHOLD   3
 #define TCP_MAX_RX_FIFO_SIZE   4 << 20
+#define TCP_MIN_RX_FIFO_SIZE   4 << 10
 #define TCP_IW_N_SEGMENTS      10
 #define TCP_ALWAYS_ACK         1       /**< On/off delayed acks */
 #define TCP_USE_SACKS          1       /**< Disable only for testing */
@@ -62,6 +63,7 @@ typedef enum _tcp_state
 format_function_t format_tcp_state;
 format_function_t format_tcp_flags;
 format_function_t format_tcp_sacks;
+format_function_t format_tcp_rcv_sacks;
 
 /** TCP timers */
 #define foreach_tcp_timer               \
@@ -151,9 +153,19 @@ enum
 #undef _
 };
 
+#define TCP_SCOREBOARD_TRACE (0)
 #define TCP_MAX_SACK_BLOCKS 15 /**< Max number of SACK blocks stored */
 #define TCP_INVALID_SACK_HOLE_INDEX ((u32)~0)
 
+typedef struct _scoreboard_trace_elt
+{
+  u32 start;
+  u32 end;
+  u32 ack;
+  u32 snd_una_max;
+  u32 group;
+} scoreboard_trace_elt_t;
+
 typedef struct _sack_scoreboard_hole
 {
   u32 next;            /**< Index for next entry in linked list */
@@ -177,8 +189,38 @@ typedef struct _sack_scoreboard
   u32 rescue_rxt;                      /**< Rescue sequence number */
   u32 lost_bytes;                      /**< Bytes lost as per RFC6675 */
   u32 cur_rxt_hole;                    /**< Retransmitting from this hole */
+
+#if TCP_SCOREBOARD_TRACE
+  scoreboard_trace_elt_t *trace;
+#endif
+
 } sack_scoreboard_t;
 
+#if TCP_SCOREBOARD_TRACE
+#define tcp_scoreboard_trace_add(_tc, _ack)                            \
+{                                                                      \
+    static u64 _group = 0;                                             \
+    sack_scoreboard_t *_sb = &_tc->sack_sb;                            \
+    sack_block_t *_sack, *_sacks;                                      \
+    scoreboard_trace_elt_t *_elt;                                      \
+    int i;                                                             \
+    _group++;                                                          \
+    _sacks = _tc->rcv_opts.sacks;                                      \
+    for (i = 0; i < vec_len (_sacks); i++)                             \
+      {                                                                        \
+       _sack = &_sacks[i];                                             \
+       vec_add2 (_sb->trace, _elt, 1);                                 \
+       _elt->start = _sack->start;                                     \
+       _elt->end = _sack->end;                                         \
+       _elt->ack = _elt->end == _ack ? _ack : 0;                       \
+       _elt->snd_una_max = _elt->end == _ack ? _tc->snd_una_max : 0;   \
+       _elt->group = _group;                                           \
+      }                                                                        \
+}
+#else
+#define tcp_scoreboard_trace_add(_tc, _ack)
+#endif
+
 typedef enum _tcp_cc_algorithm_type
 {
   TCP_CC_NEWRENO,
@@ -330,11 +372,9 @@ typedef struct _tcp_main
   /* Per worker-thread timer wheel for connections timers */
   tw_timer_wheel_16t_2w_512sl_t *timer_wheels;
 
-//  /* Convenience per worker-thread vector of connections to DELACK */
-//  u32 **delack_connections;
-
   /* Pool of half-open connections on which we've sent a SYN */
   tcp_connection_t *half_open_connections;
+  clib_spinlock_t half_open_lock;
 
   /* Pool of local TCP endpoints */
   transport_endpoint_t *local_endpoints;
@@ -405,15 +445,25 @@ tcp_connection_get_if_valid (u32 conn_index, u32 thread_index)
   return pool_elt_at_index (tcp_main.connections[thread_index], conn_index);
 }
 
+always_inline tcp_connection_t *
+tcp_get_connection_from_transport (transport_connection_t * tconn)
+{
+  return (tcp_connection_t *) tconn;
+}
+
 void tcp_connection_close (tcp_connection_t * tc);
 void tcp_connection_cleanup (tcp_connection_t * tc);
 void tcp_connection_del (tcp_connection_t * tc);
+void tcp_half_open_connection_del (tcp_connection_t * tc);
+tcp_connection_t *tcp_connection_new (u8 thread_index);
 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_scoreboard (u8 * s, va_list * args);
 
+u8 *tcp_scoreboard_replay (u8 * s, tcp_connection_t * tc, u8 verbose);
+
 always_inline tcp_connection_t *
 tcp_listener_get (u32 tli)
 {
@@ -423,13 +473,15 @@ tcp_listener_get (u32 tli)
 always_inline tcp_connection_t *
 tcp_half_open_connection_get (u32 conn_index)
 {
+  if (pool_is_free_index (tcp_main.half_open_connections, conn_index))
+    return 0;
   return pool_elt_at_index (tcp_main.half_open_connections, conn_index);
 }
 
 void tcp_make_ack (tcp_connection_t * ts, vlib_buffer_t * b);
 void tcp_make_fin (tcp_connection_t * tc, vlib_buffer_t * b);
 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_reset (tcp_connection_t * tc, 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_init_mss (tcp_connection_t * tc);
@@ -609,7 +661,6 @@ tcp_timer_update (tcp_connection_t * tc, u8 timer_id, u32 interval)
                                 tc->c_c_index, timer_id, interval);
 }
 
-/* XXX Switch retransmit to faster TW */
 always_inline void
 tcp_retransmit_timer_set (tcp_connection_t * tc)
 {
@@ -689,7 +740,7 @@ sack_scoreboard_hole_t *scoreboard_next_rxt_hole (sack_scoreboard_t * sb,
                                                  start, u8 have_sent_1_smss,
                                                  u8 * can_rescue,
                                                  u8 * snd_limited);
-void scoreboard_init_high_rxt (sack_scoreboard_t * sb);
+void scoreboard_init_high_rxt (sack_scoreboard_t * sb, u32 seq);
 
 always_inline sack_scoreboard_hole_t *
 scoreboard_get_hole (sack_scoreboard_t * sb, u32 index)
@@ -740,6 +791,7 @@ scoreboard_clear (sack_scoreboard_t * sb)
       scoreboard_remove_hole (sb, hole);
     }
   ASSERT (sb->head == sb->tail && sb->head == TCP_INVALID_SACK_HOLE_INDEX);
+  ASSERT (pool_elts (sb->holes) == 0);
   sb->sacked_bytes = 0;
   sb->last_sacked_bytes = 0;
   sb->last_bytes_delivered = 0;
@@ -759,6 +811,7 @@ scoreboard_hole_bytes (sack_scoreboard_hole_t * hole)
 always_inline u32
 scoreboard_hole_index (sack_scoreboard_t * sb, sack_scoreboard_hole_t * hole)
 {
+  ASSERT (!pool_is_free_index (sb->holes, hole - sb->holes));
   return hole - sb->holes;
 }