session tcp: support pacer idle timeouts
[vpp.git] / src / vnet / tcp / tcp.h
index a31c46c..e9247eb 100644 (file)
@@ -103,6 +103,29 @@ extern timer_expiration_handler tcp_timer_retransmit_syn_handler;
 #define TCP_RTO_BOFF_MAX 8     /* Max number of retries before reset */
 #define TCP_ESTABLISH_TIME (60 * THZ)  /* Connection establish timeout */
 
+/** Connection configuration flags */
+#define foreach_tcp_cfg_flag                   \
+  _(RATE_SAMPLE, "Rate sampling")              \
+  _(NO_CSUM_OFFLOAD, "No csum offload")        \
+  _(NO_TSO, "TSO off")                         \
+  _(TSO, "TSO")                                        \
+
+typedef enum tcp_cfg_flag_bits_
+{
+#define _(sym, str) TCP_CFG_F_##sym##_BIT,
+  foreach_tcp_cfg_flag
+#undef _
+  TCP_CFG_N_FLAG_BITS
+} tcp_cfg_flag_bits_e;
+
+typedef enum tcp_cfg_flag_
+{
+#define _(sym, str) TCP_CFG_F_##sym = 1 << TCP_CFG_F_##sym##_BIT,
+  foreach_tcp_cfg_flag
+#undef _
+  TCP_CFG_N_FLAGS
+} tcp_cfg_flags_e;
+
 /** TCP connection flags */
 #define foreach_tcp_connection_flag             \
   _(SNDACK, "Send ACK")                         \
@@ -113,16 +136,13 @@ extern timer_expiration_handler tcp_timer_retransmit_syn_handler;
   _(HALF_OPEN_DONE, "Half-open completed")     \
   _(FINPNDG, "FIN pending")                    \
   _(RXT_PENDING, "Retransmit pending")         \
-  _(FRXT_FIRST, "Fast-retransmit first again") \
-  _(DEQ_PENDING, "Pending dequeue acked")      \
+  _(FRXT_FIRST, "Retransmit first")            \
+  _(DEQ_PENDING, "Dequeue pending ")           \
   _(PSH_PENDING, "PSH pending")                        \
   _(FINRCVD, "FIN received")                   \
-  _(RATE_SAMPLE, "Conn does rate sampling")    \
-  _(TRACK_BURST, "Track burst")                        \
   _(ZERO_RWND_SENT, "Zero RWND sent")          \
-  _(NO_CSUM_OFFLOAD, "No Checksum Offload")     \
 
-typedef enum _tcp_connection_flag_bits
+typedef enum tcp_connection_flag_bits_
 {
 #define _(sym, str) TCP_CONN_##sym##_BIT,
   foreach_tcp_connection_flag
@@ -130,7 +150,7 @@ typedef enum _tcp_connection_flag_bits
   TCP_CONN_N_FLAG_BITS
 } tcp_connection_flag_bits_e;
 
-typedef enum _tcp_connection_flag
+typedef enum tcp_connection_flag_
 {
 #define _(sym, str) TCP_CONN_##sym = 1 << TCP_CONN_##sym##_BIT,
   foreach_tcp_connection_flag
@@ -235,6 +255,8 @@ typedef enum tcp_bts_flags_
 {
   TCP_BTS_IS_RXT = 1,
   TCP_BTS_IS_APP_LIMITED = 1 << 1,
+  TCP_BTS_IS_SACKED = 1 << 2,
+  TCP_BTS_IS_RXT_LOST = 1 << 3,
 } __clib_packed tcp_bts_flags_t;
 
 typedef struct tcp_bt_sample_
@@ -310,7 +332,7 @@ typedef struct _tcp_connection
   transport_connection_t connection;  /**< Common transport data. First! */
 
   u8 state;                    /**< TCP state as per tcp_state_t */
-  u8 is_tso;     /** is connection could use tso */
+  u8 cfg_flags;                        /**< Connection configuration flags */
   u16 flags;                   /**< Connection flags (see tcp_conn_flags_e) */
   u32 timers[TCP_N_TIMERS];    /**< Timer handles into timer wheel */
 
@@ -412,6 +434,7 @@ typedef struct _tcp_connection
   u32 last_fib_check;  /**< Last time we checked fib route for peer */
   u16 mss;             /**< Our max seg size that includes options */
   u32 timestamp_delta; /**< Offset for timestamp */
+  u32 ipv6_flow_label; /**< flow label for ipv6 header */
 } tcp_connection_t;
 
 /* *INDENT-OFF* */
@@ -450,6 +473,8 @@ struct _tcp_cc_algorithm
 #define tcp_in_cong_recovery(tc) ((tc)->flags &                \
          (TCP_CONN_FAST_RECOVERY | TCP_CONN_RECOVERY))
 
+#define tcp_csum_offload(tc) (!((tc)->cfg_flags & TCP_CFG_F_NO_CSUM_OFFLOAD))
+
 always_inline void
 tcp_cong_recovery_off (tcp_connection_t * tc)
 {
@@ -486,9 +511,6 @@ typedef struct tcp_worker_ctx_
   /** tx buffer free list */
   u32 *tx_buffers;
 
-  /** tx frames for tcp 4/6 output nodes */
-  vlib_frame_t *tx_frames[2];
-
   /** tx frames for ip 4/6 lookup nodes */
   vlib_frame_t *ip_lookup_tx_frames[2];
 
@@ -533,6 +555,9 @@ typedef struct tcp_configuration_
   /** Enable tx pacing for new connections */
   u8 enable_tx_pacing;
 
+  /** Allow use of TSO whenever available */
+  u8 allow_tso;
+
   /** Default congestion control algorithm type */
   tcp_cc_algorithm_type_e cc_algo;
 
@@ -759,9 +784,9 @@ void tcp_send_reset (tcp_connection_t * tc);
 void tcp_send_syn (tcp_connection_t * tc);
 void tcp_send_synack (tcp_connection_t * tc);
 void tcp_send_fin (tcp_connection_t * tc);
+void tcp_send_ack (tcp_connection_t * tc);
 void tcp_update_burst_snd_vars (tcp_connection_t * tc);
 void tcp_update_rto (tcp_connection_t * tc);
-void tcp_flush_frame_to_output (tcp_worker_ctx_t * wrk, u8 is_ip4);
 void tcp_flush_frames_to_output (tcp_worker_ctx_t * wrk);
 void tcp_send_window_update_ack (tcp_connection_t * tc);
 
@@ -797,7 +822,7 @@ void tcp_bt_flush_samples (tcp_connection_t * tc);
  *
  * @param tc   tcp connection
  */
-void tcp_bt_track_tx (tcp_connection_t * tc);
+void tcp_bt_track_tx (tcp_connection_t * tc, u32 len);
 /**
  * Track a tcp retransmission
  *
@@ -828,6 +853,7 @@ void tcp_bt_check_app_limited (tcp_connection_t * tc);
  * @param bt   byte tracker
  */
 int tcp_bt_is_sane (tcp_byte_tracker_t * bt);
+u8 *format_tcp_bt (u8 * s, va_list * args);
 
 always_inline u32
 tcp_end_seq (tcp_header_t * th, u32 len)
@@ -855,7 +881,8 @@ tcp_bytes_out (const tcp_connection_t * tc)
   if (tcp_opts_sack_permitted (&tc->rcv_opts))
     return tc->sack_sb.sacked_bytes + tc->sack_sb.lost_bytes;
   else
-    return tc->rcv_dupacks * tc->snd_mss;
+    return clib_min (tc->rcv_dupacks * tc->snd_mss,
+                    tc->snd_nxt - tc->snd_una);
 }
 
 /**
@@ -1144,8 +1171,14 @@ tcp_persist_timer_set (tcp_connection_t * tc)
 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));
+  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 (tc, TCP_TIMER_PERSIST, interval);
 }
 
 always_inline void