vlib: add ASSERT to vlib_time_now(...)
[vpp.git] / src / vnet / tcp / tcp.c
index 8a09b56..3703a4a 100644 (file)
  */
 
 #include <vnet/tcp/tcp.h>
+#include <vnet/tcp/tcp_inlines.h>
 #include <vnet/session/session.h>
 #include <vnet/fib/fib.h>
 #include <vnet/dpo/load_balance.h>
-#include <vnet/dpo/receive_dpo.h>
-#include <vnet/ip-neighbor/ip_neighbor.h>
 #include <math.h>
 
 tcp_main_t tcp_main;
@@ -187,7 +186,7 @@ tcp_session_get_listener (u32 listener_index)
  *
  */
 static void
-tcp_half_open_connection_del (tcp_connection_t * tc)
+tcp_half_open_connection_free (tcp_connection_t * tc)
 {
   tcp_main_t *tm = vnet_get_tcp_main ();
   clib_spinlock_lock_if_init (&tm->half_open_lock);
@@ -209,11 +208,16 @@ tcp_half_open_connection_del (tcp_connection_t * tc)
 int
 tcp_half_open_connection_cleanup (tcp_connection_t * tc)
 {
+  tcp_worker_ctx_t *wrk;
+
   /* Make sure this is the owning thread */
   if (tc->c_thread_index != vlib_get_thread_index ())
     return 1;
-  tcp_timer_reset (tc, TCP_TIMER_RETRANSMIT_SYN);
-  tcp_half_open_connection_del (tc);
+
+  session_half_open_delete_notify (TRANSPORT_PROTO_TCP, tc->c_s_ho_handle);
+  wrk = tcp_get_worker (tc->c_thread_index);
+  tcp_timer_reset (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN);
+  tcp_half_open_connection_free (tc);
   return 0;
 }
 
@@ -355,6 +359,8 @@ tcp_program_cleanup (tcp_worker_ctx_t * wrk, tcp_connection_t * tc)
 void
 tcp_connection_close (tcp_connection_t * tc)
 {
+  tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index);
+
   TCP_EVT (TCP_EVT_CLOSE, tc);
 
   /* Send/Program FIN if needed and switch state */
@@ -369,7 +375,8 @@ tcp_connection_close (tcp_connection_t * tc)
       tcp_connection_timers_reset (tc);
       tcp_send_fin (tc);
       tcp_connection_set_state (tc, TCP_STATE_FIN_WAIT_1);
-      tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.finwait1_time);
+      tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE,
+                       tcp_cfg.finwait1_time);
       break;
     case TCP_STATE_ESTABLISHED:
       /* If closing with unread data, reset the connection */
@@ -380,7 +387,7 @@ tcp_connection_close (tcp_connection_t * tc)
          tcp_connection_set_state (tc, TCP_STATE_CLOSED);
          session_transport_closed_notify (&tc->connection);
          tcp_program_cleanup (tcp_get_worker (tc->c_thread_index), tc);
-         tcp_worker_stats_inc (tc->c_thread_index, rst_unread, 1);
+         tcp_worker_stats_inc (wrk, rst_unread, 1);
          break;
        }
       if (!transport_max_tx_dequeue (&tc->connection))
@@ -391,7 +398,8 @@ tcp_connection_close (tcp_connection_t * tc)
       /* Set a timer in case the peer stops responding. Otherwise the
        * connection will be stuck here forever. */
       ASSERT (tc->timers[TCP_TIMER_WAITCLOSE] == TCP_TIMER_HANDLE_INVALID);
-      tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.finwait1_time);
+      tcp_timer_set (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE,
+                    tcp_cfg.finwait1_time);
       break;
     case TCP_STATE_CLOSE_WAIT:
       if (!transport_max_tx_dequeue (&tc->connection))
@@ -399,13 +407,15 @@ tcp_connection_close (tcp_connection_t * tc)
          tcp_send_fin (tc);
          tcp_connection_timers_reset (tc);
          tcp_connection_set_state (tc, TCP_STATE_LAST_ACK);
-         tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time);
+         tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE,
+                           tcp_cfg.lastack_time);
        }
       else
        tc->flags |= TCP_CONN_FINPNDG;
       break;
     case TCP_STATE_FIN_WAIT_1:
-      tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.finwait1_time);
+      tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE,
+                       tcp_cfg.finwait1_time);
       break;
     case TCP_STATE_CLOSED:
       /* Cleanup should've been programmed already */
@@ -434,6 +444,18 @@ tcp_session_cleanup (u32 conn_index, u32 thread_index)
   tcp_connection_cleanup (tc);
 }
 
+static void
+tcp_session_cleanup_ho (u32 conn_index)
+{
+  tcp_worker_ctx_t *wrk;
+  tcp_connection_t *tc;
+
+  tc = tcp_half_open_connection_get (conn_index);
+  wrk = tcp_get_worker (tc->c_thread_index);
+  tcp_timer_reset (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN);
+  tcp_half_open_connection_free (tc);
+}
+
 static void
 tcp_session_reset (u32 conn_index, u32 thread_index)
 {
@@ -470,11 +492,11 @@ tcp_connection_timers_init (tcp_connection_t * tc)
 void
 tcp_connection_timers_reset (tcp_connection_t * tc)
 {
+  tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index);
   int i;
+
   for (i = 0; i < TCP_N_TIMERS; i++)
-    {
-      tcp_timer_reset (tc, i);
-    }
+    tcp_timer_reset (&wrk->timer_wheel, tc, i);
 }
 
 #if 0
@@ -707,51 +729,6 @@ tcp_connection_init_vars (tcp_connection_t * tc)
   tc->start_ts = tcp_time_now_us (tc->c_thread_index);
 }
 
-void
-tcp_init_w_buffer (tcp_connection_t * tc, vlib_buffer_t * b, u8 is_ip4)
-{
-  tcp_header_t *th = tcp_buffer_hdr (b);
-
-  tc->c_lcl_port = th->dst_port;
-  tc->c_rmt_port = th->src_port;
-  tc->c_is_ip4 = is_ip4;
-
-  if (is_ip4)
-    {
-      ip4_header_t *ip4 = vlib_buffer_get_current (b);
-      tc->c_lcl_ip4.as_u32 = ip4->dst_address.as_u32;
-      tc->c_rmt_ip4.as_u32 = ip4->src_address.as_u32;
-    }
-  else
-    {
-      ip6_header_t *ip6 = vlib_buffer_get_current (b);
-      clib_memcpy_fast (&tc->c_lcl_ip6, &ip6->dst_address,
-                       sizeof (ip6_address_t));
-      clib_memcpy_fast (&tc->c_rmt_ip6, &ip6->src_address,
-                       sizeof (ip6_address_t));
-    }
-
-  tc->irs = vnet_buffer (b)->tcp.seq_number;
-  tc->rcv_nxt = vnet_buffer (b)->tcp.seq_number + 1;
-  tc->rcv_las = tc->rcv_nxt;
-  tc->sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
-  tc->snd_wl1 = vnet_buffer (b)->tcp.seq_number;
-  tc->snd_wl2 = vnet_buffer (b)->tcp.ack_number;
-
-  /* RFC1323: TSval timestamps sent on {SYN} and {SYN,ACK}
-   * segments are used to initialize PAWS. */
-  if (tcp_opts_tstamp (&tc->rcv_opts))
-    {
-      tc->tsval_recent = tc->rcv_opts.tsval;
-      tc->tsval_recent_age = tcp_time_now ();
-    }
-
-  if (tcp_opts_wscale (&tc->rcv_opts))
-    tc->snd_wscale = tc->rcv_opts.wscale;
-
-  tc->snd_wnd = clib_net_to_host_u16 (th->window) << tc->snd_wscale;
-}
-
 static int
 tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr,
                                 u16 * lcl_port, u8 is_ip4)
@@ -774,10 +751,7 @@ tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr,
     }
   port = transport_alloc_local_port (TRANSPORT_PROTO_TCP, lcl_addr);
   if (port < 1)
-    {
-      clib_warning ("Failed to allocate src port");
-      return -1;
-    }
+    return SESSION_E_NOPORT;
   *lcl_port = port;
   return 0;
 }
@@ -803,7 +777,20 @@ tcp_session_open (transport_endpoint_cfg_t * rmt)
                                         rmt, &lcl_addr, &lcl_port);
 
   if (rv)
-    return -1;
+    {
+      if (rv != SESSION_E_PORTINUSE)
+       return rv;
+
+      if (session_lookup_connection (rmt->fib_index, &lcl_addr, &rmt->ip,
+                                    lcl_port, rmt->port, TRANSPORT_PROTO_UDP,
+                                    rmt->is_ip4))
+       return SESSION_E_PORTINUSE;
+
+      /* 5-tuple is available so increase lcl endpoint refcount and proceed
+       * with connection allocation */
+      transport_share_local_endpoint (TRANSPORT_PROTO_UDP, &lcl_addr,
+                                     lcl_port);
+    }
 
   /*
    * Create connection and send SYN
@@ -831,256 +818,6 @@ tcp_session_open (transport_endpoint_cfg_t * rmt)
   return tc->c_c_index;
 }
 
-const char *tcp_fsm_states[] = {
-#define _(sym, str) str,
-  foreach_tcp_fsm_state
-#undef _
-};
-
-u8 *
-format_tcp_state (u8 * s, va_list * args)
-{
-  u32 state = va_arg (*args, u32);
-
-  if (state < TCP_N_STATES)
-    s = format (s, "%s", tcp_fsm_states[state]);
-  else
-    s = format (s, "UNKNOWN (%d (0x%x))", state, state);
-  return s;
-}
-
-const char *tcp_cfg_flags_str[] = {
-#define _(sym, str) str,
-  foreach_tcp_cfg_flag
-#undef _
-};
-
-static u8 *
-format_tcp_cfg_flags (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  int i, last = -1;
-
-  for (i = 0; i < TCP_CFG_N_FLAG_BITS; i++)
-    if (tc->cfg_flags & (1 << i))
-      last = i;
-  for (i = 0; i < last; i++)
-    {
-      if (tc->cfg_flags & (1 << i))
-       s = format (s, "%s, ", tcp_cfg_flags_str[i]);
-    }
-  if (last >= 0)
-    s = format (s, "%s", tcp_cfg_flags_str[last]);
-  return s;
-}
-
-const char *tcp_connection_flags_str[] = {
-#define _(sym, str) str,
-  foreach_tcp_connection_flag
-#undef _
-};
-
-static u8 *
-format_tcp_connection_flags (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  int i, last = -1;
-
-  for (i = 0; i < TCP_CONN_N_FLAG_BITS; i++)
-    if (tc->flags & (1 << i))
-      last = i;
-  for (i = 0; i < last; i++)
-    {
-      if (tc->flags & (1 << i))
-       s = format (s, "%s, ", tcp_connection_flags_str[i]);
-    }
-  if (last >= 0)
-    s = format (s, "%s", tcp_connection_flags_str[last]);
-  return s;
-}
-
-const char *tcp_conn_timers[] = {
-#define _(sym, str) str,
-  foreach_tcp_timer
-#undef _
-};
-
-static u8 *
-format_tcp_timers (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  int i, last = -1;
-
-  for (i = 0; i < TCP_N_TIMERS; i++)
-    if (tc->timers[i] != TCP_TIMER_HANDLE_INVALID)
-      last = i;
-
-  for (i = 0; i < last; i++)
-    {
-      if (tc->timers[i] != TCP_TIMER_HANDLE_INVALID)
-       s = format (s, "%s,", tcp_conn_timers[i]);
-    }
-
-  if (last >= 0)
-    s = format (s, "%s", tcp_conn_timers[i]);
-
-  return s;
-}
-
-static u8 *
-format_tcp_congestion_status (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  if (tcp_in_recovery (tc))
-    s = format (s, "recovery");
-  else if (tcp_in_fastrecovery (tc))
-    s = format (s, "fastrecovery");
-  else
-    s = format (s, "none");
-  return s;
-}
-
-static i32
-tcp_rcv_wnd_available (tcp_connection_t * tc)
-{
-  return (i32) tc->rcv_wnd - (tc->rcv_nxt - tc->rcv_las);
-}
-
-static u8 *
-format_tcp_congestion (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  u32 indent = format_get_indent (s), prr_space = 0;
-
-  s = format (s, "%U ", format_tcp_congestion_status, tc);
-  s = format (s, "algo %s cwnd %u ssthresh %u bytes_acked %u\n",
-             tc->cc_algo->name, tc->cwnd, tc->ssthresh, tc->bytes_acked);
-  s = format (s, "%Ucc space %u prev_cwnd %u prev_ssthresh %u\n",
-             format_white_space, indent, tcp_available_cc_snd_space (tc),
-             tc->prev_cwnd, tc->prev_ssthresh);
-  s = format (s, "%Usnd_cong %u dupack %u limited_tx %u\n",
-             format_white_space, indent, tc->snd_congestion - tc->iss,
-             tc->rcv_dupacks, tc->limited_transmit - tc->iss);
-  s = format (s, "%Urxt_bytes %u rxt_delivered %u rxt_head %u rxt_ts %u\n",
-             format_white_space, indent, tc->snd_rxt_bytes,
-             tc->rxt_delivered, tc->rxt_head - tc->iss,
-             tcp_time_now_w_thread (tc->c_thread_index) - tc->snd_rxt_ts);
-  if (tcp_in_fastrecovery (tc))
-    prr_space = tcp_fastrecovery_prr_snd_space (tc);
-  s = format (s, "%Uprr_start %u prr_delivered %u prr space %u\n",
-             format_white_space, indent, tc->prr_start - tc->iss,
-             tc->prr_delivered, prr_space);
-  return s;
-}
-
-static u8 *
-format_tcp_stats (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  u32 indent = format_get_indent (s);
-  s = format (s, "in segs %lu dsegs %lu bytes %lu dupacks %u\n",
-             tc->segs_in, tc->data_segs_in, tc->bytes_in, tc->dupacks_in);
-  s = format (s, "%Uout segs %lu dsegs %lu bytes %lu dupacks %u\n",
-             format_white_space, indent, tc->segs_out,
-             tc->data_segs_out, tc->bytes_out, tc->dupacks_out);
-  s = format (s, "%Ufr %u tr %u rxt segs %lu bytes %lu duration %.3f\n",
-             format_white_space, indent, tc->fr_occurences,
-             tc->tr_occurences, tc->segs_retrans, tc->bytes_retrans,
-             tcp_time_now_us (tc->c_thread_index) - tc->start_ts);
-  s = format (s, "%Uerr wnd data below %u above %u ack below %u above %u",
-             format_white_space, indent, tc->errors.below_data_wnd,
-             tc->errors.above_data_wnd, tc->errors.below_ack_wnd,
-             tc->errors.above_ack_wnd);
-  return s;
-}
-
-static u8 *
-format_tcp_vars (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  s = format (s, " index: %u cfg: %U flags: %U timers: %U\n", tc->c_c_index,
-             format_tcp_cfg_flags, tc, format_tcp_connection_flags, tc,
-             format_tcp_timers, tc);
-  s = format (s, " snd_una %u snd_nxt %u snd_una_max %u",
-             tc->snd_una - tc->iss, tc->snd_nxt - tc->iss,
-             tc->snd_una_max - tc->iss);
-  s = format (s, " rcv_nxt %u rcv_las %u\n",
-             tc->rcv_nxt - tc->irs, tc->rcv_las - tc->irs);
-  s = format (s, " snd_wnd %u rcv_wnd %u rcv_wscale %u ",
-             tc->snd_wnd, tc->rcv_wnd, tc->rcv_wscale);
-  s = format (s, "snd_wl1 %u snd_wl2 %u\n", tc->snd_wl1 - tc->irs,
-             tc->snd_wl2 - tc->iss);
-  s = format (s, " flight size %u out space %u rcv_wnd_av %u",
-             tcp_flight_size (tc), tcp_available_output_snd_space (tc),
-             tcp_rcv_wnd_available (tc));
-  s = format (s, " tsval_recent %u\n", tc->tsval_recent);
-  s = format (s, " tsecr %u tsecr_last_ack %u tsval_recent_age %u",
-             tc->rcv_opts.tsecr, tc->tsecr_last_ack,
-             tcp_time_now () - tc->tsval_recent_age);
-  s = format (s, " snd_mss %u\n", tc->snd_mss);
-  s = format (s, " rto %u rto_boff %u srtt %u us %.3f rttvar %u rtt_ts %.4f",
-             tc->rto, tc->rto_boff, tc->srtt, tc->mrtt_us * 1000, tc->rttvar,
-             tc->rtt_ts);
-  s = format (s, " rtt_seq %u\n", tc->rtt_seq - tc->iss);
-  s = format (s, " next_node %u opaque 0x%x fib_index %u\n",
-             tc->next_node_index, tc->next_node_opaque, tc->c_fib_index);
-  s = format (s, " cong:   %U", format_tcp_congestion, tc);
-
-  if (tc->state >= TCP_STATE_ESTABLISHED)
-    {
-      s = format (s, " sboard: %U\n", format_tcp_scoreboard, &tc->sack_sb,
-                 tc);
-      s = format (s, " stats: %U\n", format_tcp_stats, tc);
-    }
-  if (vec_len (tc->snd_sacks))
-    s = format (s, " sacks tx: %U\n", format_tcp_sacks, tc);
-
-  return s;
-}
-
-u8 *
-format_tcp_connection_id (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  if (!tc)
-    return s;
-  if (tc->c_is_ip4)
-    {
-      s = format (s, "[%d:%d][%s] %U:%d->%U:%d", tc->c_thread_index,
-                 tc->c_s_index, "T", format_ip4_address, &tc->c_lcl_ip4,
-                 clib_net_to_host_u16 (tc->c_lcl_port), format_ip4_address,
-                 &tc->c_rmt_ip4, clib_net_to_host_u16 (tc->c_rmt_port));
-    }
-  else
-    {
-      s = format (s, "[%d:%d][%s] %U:%d->%U:%d", tc->c_thread_index,
-                 tc->c_s_index, "T", format_ip6_address, &tc->c_lcl_ip6,
-                 clib_net_to_host_u16 (tc->c_lcl_port), format_ip6_address,
-                 &tc->c_rmt_ip6, clib_net_to_host_u16 (tc->c_rmt_port));
-    }
-
-  return s;
-}
-
-u8 *
-format_tcp_connection (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  u32 verbose = va_arg (*args, u32);
-
-  if (!tc)
-    return s;
-  s = format (s, "%-50U", format_tcp_connection_id, tc);
-  if (verbose)
-    {
-      s = format (s, "%-15U", format_tcp_state, tc->state);
-      if (verbose > 1)
-       s = format (s, "\n%U", format_tcp_vars, tc);
-    }
-
-  return s;
-}
-
 static u8 *
 format_tcp_session (u8 * s, va_list * args)
 {
@@ -1119,100 +856,6 @@ format_tcp_half_open_session (u8 * s, va_list * args)
   return format (s, "%U", format_tcp_connection_id, tc);
 }
 
-u8 *
-format_tcp_sacks (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  sack_block_t *sacks = tc->snd_sacks;
-  sack_block_t *block;
-  int i, len = 0;
-
-  len = vec_len (sacks);
-  for (i = 0; i < len - 1; i++)
-    {
-      block = &sacks[i];
-      s = format (s, " start %u end %u\n", block->start - tc->irs,
-                 block->end - tc->irs);
-    }
-  if (len)
-    {
-      block = &sacks[len - 1];
-      s = format (s, " start %u end %u", block->start - tc->irs,
-                 block->end - tc->irs);
-    }
-  return s;
-}
-
-u8 *
-format_tcp_rcv_sacks (u8 * s, va_list * args)
-{
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  sack_block_t *sacks = tc->rcv_opts.sacks;
-  sack_block_t *block;
-  int i, len = 0;
-
-  len = vec_len (sacks);
-  for (i = 0; i < len - 1; i++)
-    {
-      block = &sacks[i];
-      s = format (s, " start %u end %u\n", block->start - tc->iss,
-                 block->end - tc->iss);
-    }
-  if (len)
-    {
-      block = &sacks[len - 1];
-      s = format (s, " start %u end %u", block->start - tc->iss,
-                 block->end - tc->iss);
-    }
-  return s;
-}
-
-static u8 *
-format_tcp_sack_hole (u8 * s, va_list * args)
-{
-  sack_scoreboard_hole_t *hole = va_arg (*args, sack_scoreboard_hole_t *);
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  if (tc)
-    s = format (s, "  [%u, %u]", hole->start - tc->iss, hole->end - tc->iss);
-  else
-    s = format (s, "  [%u, %u]", hole->start, hole->end);
-  return s;
-}
-
-u8 *
-format_tcp_scoreboard (u8 * s, va_list * args)
-{
-  sack_scoreboard_t *sb = va_arg (*args, sack_scoreboard_t *);
-  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-  sack_scoreboard_hole_t *hole;
-  u32 indent = format_get_indent (s);
-
-  s = format (s, "sacked %u last_sacked %u lost %u last_lost %u"
-             " rxt_sacked %u\n",
-             sb->sacked_bytes, sb->last_sacked_bytes, sb->lost_bytes,
-             sb->last_lost_bytes, sb->rxt_sacked);
-  s = format (s, "%Ulast_delivered %u high_sacked %u is_reneging %u\n",
-             format_white_space, indent, sb->last_bytes_delivered,
-             sb->high_sacked - tc->iss, sb->is_reneging);
-  s = format (s, "%Ucur_rxt_hole %u high_rxt %u rescue_rxt %u",
-             format_white_space, indent, sb->cur_rxt_hole,
-             sb->high_rxt - tc->iss, sb->rescue_rxt - tc->iss);
-
-  hole = scoreboard_first_hole (sb);
-  if (hole)
-    s = format (s, "\n%Uhead %u tail %u %u holes:\n%U", format_white_space,
-               indent, sb->head, sb->tail, pool_elts (sb->holes),
-               format_white_space, indent);
-
-  while (hole)
-    {
-      s = format (s, "%U", format_tcp_sack_hole, hole, tc);
-      hole = scoreboard_next_hole (sb, hole);
-    }
-
-  return s;
-}
-
 static transport_connection_t *
 tcp_session_get_transport (u32 conn_index, u32 thread_index)
 {
@@ -1346,7 +989,7 @@ tcp_timer_waitclose_handler (tcp_connection_t * tc)
          tcp_connection_set_state (tc, TCP_STATE_CLOSED);
          session_transport_closed_notify (&tc->connection);
          tcp_program_cleanup (wrk, tc);
-         tcp_workerp_stats_inc (wrk, to_closewait, 1);
+         tcp_worker_stats_inc (wrk, to_closewait, 1);
          break;
        }
 
@@ -1359,8 +1002,9 @@ tcp_timer_waitclose_handler (tcp_connection_t * tc)
       session_transport_closed_notify (&tc->connection);
 
       /* Make sure we don't wait in LAST ACK forever */
-      tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time);
-      tcp_workerp_stats_inc (wrk, to_closewait2, 1);
+      tcp_timer_set (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE,
+                    tcp_cfg.lastack_time);
+      tcp_worker_stats_inc (wrk, to_closewait2, 1);
 
       /* Don't delete the connection yet */
       break;
@@ -1382,21 +1026,21 @@ tcp_timer_waitclose_handler (tcp_connection_t * tc)
          tcp_program_cleanup (wrk, tc);
        }
       session_transport_closed_notify (&tc->connection);
-      tcp_workerp_stats_inc (wrk, to_finwait1, 1);
+      tcp_worker_stats_inc (wrk, to_finwait1, 1);
       break;
     case TCP_STATE_LAST_ACK:
       tcp_connection_timers_reset (tc);
       tcp_connection_set_state (tc, TCP_STATE_CLOSED);
       session_transport_closed_notify (&tc->connection);
       tcp_program_cleanup (wrk, tc);
-      tcp_workerp_stats_inc (wrk, to_lastack, 1);
+      tcp_worker_stats_inc (wrk, to_lastack, 1);
       break;
     case TCP_STATE_CLOSING:
       tcp_connection_timers_reset (tc);
       tcp_connection_set_state (tc, TCP_STATE_CLOSED);
       session_transport_closed_notify (&tc->connection);
       tcp_program_cleanup (wrk, tc);
-      tcp_workerp_stats_inc (wrk, to_closing, 1);
+      tcp_worker_stats_inc (wrk, to_closing, 1);
       break;
     case TCP_STATE_FIN_WAIT_2:
       tcp_send_reset (tc);
@@ -1404,7 +1048,7 @@ tcp_timer_waitclose_handler (tcp_connection_t * tc)
       tcp_connection_set_state (tc, TCP_STATE_CLOSED);
       session_transport_closed_notify (&tc->connection);
       tcp_program_cleanup (wrk, tc);
-      tcp_workerp_stats_inc (wrk, to_finwait2, 1);
+      tcp_worker_stats_inc (wrk, to_finwait2, 1);
       break;
     case TCP_STATE_TIME_WAIT:
       tcp_connection_set_state (tc, TCP_STATE_CLOSED);
@@ -1460,28 +1104,7 @@ tcp_dispatch_pending_timers (tcp_worker_ctx_t * wrk)
     }
 
   if (thread_index == 0 && clib_fifo_elts (wrk->pending_timers))
-    vlib_process_signal_event_mt (wrk->vm, session_queue_process_node.index,
-                                 SESSION_Q_PROCESS_FLUSH_FRAMES, 0);
-}
-
-/**
- * Flush ip lookup tx frames populated by timer pops
- */
-static void
-tcp_flush_frames_to_output (tcp_worker_ctx_t * wrk)
-{
-  if (wrk->ip_lookup_tx_frames[0])
-    {
-      vlib_put_frame_to_node (wrk->vm, ip4_lookup_node.index,
-                             wrk->ip_lookup_tx_frames[0]);
-      wrk->ip_lookup_tx_frames[0] = 0;
-    }
-  if (wrk->ip_lookup_tx_frames[1])
-    {
-      vlib_put_frame_to_node (wrk->vm, ip6_lookup_node.index,
-                             wrk->ip_lookup_tx_frames[1]);
-      wrk->ip_lookup_tx_frames[1] = 0;
-    }
+    session_queue_run_on_main_thread (wrk->vm);
 }
 
 static void
@@ -1514,7 +1137,6 @@ tcp_update_time (f64 now, u8 thread_index)
   tcp_handle_cleanups (wrk, now);
   tw_timer_expire_timers_16t_2w_512sl (&wrk->timer_wheel, now);
   tcp_dispatch_pending_timers (wrk);
-  tcp_flush_frames_to_output (wrk);
 }
 
 static void
@@ -1539,6 +1161,7 @@ const static transport_proto_vft_t tcp_proto = {
   .connect = tcp_session_open,
   .close = tcp_session_close,
   .cleanup = tcp_session_cleanup,
+  .cleanup_ho = tcp_session_cleanup_ho,
   .reset = tcp_session_reset,
   .send_params = tcp_session_send_params,
   .update_time = tcp_update_time,
@@ -1548,6 +1171,8 @@ const static transport_proto_vft_t tcp_proto = {
   .format_listener = format_tcp_listener_session,
   .format_half_open = format_tcp_half_open_session,
   .transport_options = {
+    .name = "tcp",
+    .short_name = "T",
     .tx_type = TRANSPORT_TX_PEEK,
     .service_type = TRANSPORT_SERVICE_VC,
   },
@@ -1596,7 +1221,7 @@ tcp_expired_timers_dispatch (u32 * expired_timers)
 
   wrk = tcp_get_worker (thread_index);
   n_expired = vec_len (expired_timers);
-  tcp_workerp_stats_inc (wrk, timer_expirations, n_expired);
+  tcp_worker_stats_inc (wrk, timer_expirations, n_expired);
   n_left = clib_fifo_elts (wrk->pending_timers);
 
   /*
@@ -1627,20 +1252,20 @@ tcp_expired_timers_dispatch (u32 * expired_timers)
                                       max_per_loop);
 
   if (thread_index == 0)
-    vlib_process_signal_event_mt (wrk->vm, session_queue_process_node.index,
-                                 SESSION_Q_PROCESS_FLUSH_FRAMES, 0);
+    session_queue_run_on_main_thread (wrk->vm);
 }
 
 static void
 tcp_initialize_timer_wheels (tcp_main_t * tm)
 {
+  vlib_main_t *vm = vlib_get_main ();
   tw_timer_wheel_16t_2w_512sl_t *tw;
   /* *INDENT-OFF* */
   foreach_vlib_main (({
     tw = &tm->wrk_ctx[ii].timer_wheel;
     tw_timer_wheel_init_16t_2w_512sl (tw, tcp_expired_timers_dispatch,
                                       TCP_TIMER_TICK, ~0);
-    tw->last_run_time = vlib_time_now (this_vlib_main);
+    tw->last_run_time = vlib_time_now (vm);
   }));
   /* *INDENT-ON* */
 }
@@ -1689,6 +1314,12 @@ tcp_main_enable (vlib_main_t * vm)
   n_workers = num_threads == 1 ? 1 : vtm->n_threads;
   prealloc_conn_per_wrk = tcp_cfg.preallocated_connections / n_workers;
 
+  wrk = &tm->wrk_ctx[0];
+  wrk->tco_next_node[0] = vlib_node_get_next (vm, session_queue_node.index,
+                                             tcp4_output_node.index);
+  wrk->tco_next_node[1] = vlib_node_get_next (vm, session_queue_node.index,
+                                             tcp6_output_node.index);
+
   for (thread = 0; thread < num_threads; thread++)
     {
       wrk = &tm->wrk_ctx[thread];
@@ -1702,6 +1333,12 @@ tcp_main_enable (vlib_main_t * vm)
       wrk->vm = vlib_mains[thread];
       wrk->max_timers_per_loop = 10;
 
+      if (thread > 0)
+       {
+         wrk->tco_next_node[0] = tm->wrk_ctx[0].tco_next_node[0];
+         wrk->tco_next_node[1] = tm->wrk_ctx[0].tco_next_node[1];
+       }
+
       /*
        * Preallocate connections. Assume that thread 0 won't
        * use preallocated threads when running multi-core
@@ -1732,6 +1369,11 @@ tcp_main_enable (vlib_main_t * vm)
 
   tm->bytes_per_buffer = vlib_buffer_get_default_data_size (vm);
   tm->cc_last_type = TCP_CC_LAST;
+
+  tm->ipl_next_node[0] = vlib_node_get_next (vm, session_queue_node.index,
+                                            ip4_lookup_node.index);
+  tm->ipl_next_node[1] = vlib_node_get_next (vm, session_queue_node.index,
+                                            ip6_lookup_node.index);
   return error;
 }
 
@@ -1780,7 +1422,7 @@ tcp_configuration_init (void)
   tcp_cfg.enable_tx_pacing = 1;
   tcp_cfg.allow_tso = 0;
   tcp_cfg.csum_offload = 1;
-  tcp_cfg.cc_algo = TCP_CC_NEWRENO;
+  tcp_cfg.cc_algo = TCP_CC_CUBIC;
   tcp_cfg.rwnd_min_update_ack = 1;
 
   /* Time constants defined as timer tick (100ms) multiples */
@@ -1817,7 +1459,6 @@ tcp_init (vlib_main_t * vm)
   transport_register_protocol (TRANSPORT_PROTO_TCP, &tcp_proto,
                               FIB_PROTOCOL_IP6, tcp6_output_node.index);
 
-  tcp_api_reference ();
   tcp_configuration_init ();
 
   tm->cc_algo_by_name = hash_create_string (0, sizeof (uword));
@@ -1827,666 +1468,6 @@ tcp_init (vlib_main_t * vm)
 
 VLIB_INIT_FUNCTION (tcp_init);
 
-uword
-unformat_tcp_cc_algo (unformat_input_t * input, va_list * va)
-{
-  tcp_cc_algorithm_type_e *result = va_arg (*va, tcp_cc_algorithm_type_e *);
-  tcp_main_t *tm = &tcp_main;
-  char *cc_algo_name;
-  u8 found = 0;
-  uword *p;
-
-  if (unformat (input, "%s", &cc_algo_name)
-      && ((p = hash_get_mem (tm->cc_algo_by_name, cc_algo_name))))
-    {
-      *result = *p;
-      found = 1;
-    }
-
-  vec_free (cc_algo_name);
-  return found;
-}
-
-uword
-unformat_tcp_cc_algo_cfg (unformat_input_t * input, va_list * va)
-{
-  tcp_main_t *tm = vnet_get_tcp_main ();
-  tcp_cc_algorithm_t *cc_alg;
-  unformat_input_t sub_input;
-  int found = 0;
-
-  vec_foreach (cc_alg, tm->cc_algos)
-  {
-    if (!unformat (input, cc_alg->name))
-      continue;
-
-    if (cc_alg->unformat_cfg
-       && unformat (input, "%U", unformat_vlib_cli_sub_input, &sub_input))
-      {
-       if (cc_alg->unformat_cfg (&sub_input))
-         found = 1;
-      }
-  }
-  return found;
-}
-
-static clib_error_t *
-tcp_config_fn (vlib_main_t * vm, unformat_input_t * input)
-{
-  u32 cwnd_multiplier, tmp_time;
-  uword memory_size;
-
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "preallocated-connections %d",
-                   &tcp_cfg.preallocated_connections))
-       ;
-      else if (unformat (input, "preallocated-half-open-connections %d",
-                        &tcp_cfg.preallocated_half_open_connections))
-       ;
-      else if (unformat (input, "buffer-fail-fraction %f",
-                        &tcp_cfg.buffer_fail_fraction))
-       ;
-      else if (unformat (input, "max-rx-fifo %U", unformat_memory_size,
-                        &memory_size))
-       {
-         if (memory_size >= 0x100000000)
-           {
-             return clib_error_return
-               (0, "max-rx-fifo %llu (0x%llx) too large", memory_size,
-                memory_size);
-           }
-         tcp_cfg.max_rx_fifo = memory_size;
-       }
-      else if (unformat (input, "min-rx-fifo %U", unformat_memory_size,
-                        &memory_size))
-       {
-         if (memory_size >= 0x100000000)
-           {
-             return clib_error_return
-               (0, "min-rx-fifo %llu (0x%llx) too large", memory_size,
-                memory_size);
-           }
-         tcp_cfg.min_rx_fifo = memory_size;
-       }
-      else if (unformat (input, "mtu %u", &tcp_cfg.default_mtu))
-       ;
-      else if (unformat (input, "rwnd-min-update-ack %d",
-                        &tcp_cfg.rwnd_min_update_ack))
-       ;
-      else if (unformat (input, "initial-cwnd-multiplier %u",
-                        &cwnd_multiplier))
-       tcp_cfg.initial_cwnd_multiplier = cwnd_multiplier;
-      else if (unformat (input, "no-tx-pacing"))
-       tcp_cfg.enable_tx_pacing = 0;
-      else if (unformat (input, "tso"))
-       tcp_cfg.allow_tso = 1;
-      else if (unformat (input, "no-csum-offload"))
-       tcp_cfg.csum_offload = 0;
-      else if (unformat (input, "cc-algo %U", unformat_tcp_cc_algo,
-                        &tcp_cfg.cc_algo))
-       ;
-      else if (unformat (input, "%U", unformat_tcp_cc_algo_cfg))
-       ;
-      else if (unformat (input, "closewait-time %u", &tmp_time))
-       tcp_cfg.closewait_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "timewait-time %u", &tmp_time))
-       tcp_cfg.timewait_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "finwait1-time %u", &tmp_time))
-       tcp_cfg.finwait1_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "finwait2-time %u", &tmp_time))
-       tcp_cfg.finwait2_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "lastack-time %u", &tmp_time))
-       tcp_cfg.lastack_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "closing-time %u", &tmp_time))
-       tcp_cfg.closing_time = tmp_time / TCP_TIMER_TICK;
-      else if (unformat (input, "cleanup-time %u", &tmp_time))
-       tcp_cfg.cleanup_time = tmp_time / 1000.0;
-      else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
-    }
-  return 0;
-}
-
-VLIB_CONFIG_FUNCTION (tcp_config_fn, "tcp");
-
-
-/**
- * \brief Configure an ipv4 source address range
- * @param vm vlib_main_t pointer
- * @param start first ipv4 address in the source address range
- * @param end last ipv4 address in the source address range
- * @param table_id VRF / table ID, 0 for the default FIB
- * @return 0 if all OK, else an error indication from api_errno.h
- */
-
-int
-tcp_configure_v4_source_address_range (vlib_main_t * vm,
-                                      ip4_address_t * start,
-                                      ip4_address_t * end, u32 table_id)
-{
-  u32 start_host_byte_order, end_host_byte_order;
-  fib_prefix_t prefix;
-  fib_node_index_t fei;
-  u32 fib_index = 0;
-  u32 sw_if_index;
-  int rv;
-
-  clib_memset (&prefix, 0, sizeof (prefix));
-
-  fib_index = fib_table_find (FIB_PROTOCOL_IP4, table_id);
-
-  if (fib_index == ~0)
-    return VNET_API_ERROR_NO_SUCH_FIB;
-
-  start_host_byte_order = clib_net_to_host_u32 (start->as_u32);
-  end_host_byte_order = clib_net_to_host_u32 (end->as_u32);
-
-  /* sanity check for reversed args or some such */
-  if ((end_host_byte_order - start_host_byte_order) > (10 << 10))
-    return VNET_API_ERROR_INVALID_ARGUMENT;
-
-  /* Lookup the last address, to identify the interface involved */
-  prefix.fp_len = 32;
-  prefix.fp_proto = FIB_PROTOCOL_IP4;
-  memcpy (&prefix.fp_addr.ip4, end, sizeof (ip4_address_t));
-
-  fei = fib_table_lookup (fib_index, &prefix);
-
-  /* Couldn't find route to destination. Bail out. */
-  if (fei == FIB_NODE_INDEX_INVALID)
-    return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
-
-  sw_if_index = fib_entry_get_resolving_interface (fei);
-
-  /* Configure proxy arp across the range */
-  rv = ip4_neighbor_proxy_add (fib_index, start, end);
-
-  if (rv)
-    return rv;
-
-  rv = ip4_neighbor_proxy_enable (sw_if_index);
-
-  if (rv)
-    return rv;
-
-  do
-    {
-      dpo_id_t dpo = DPO_INVALID;
-
-      vec_add1 (tcp_cfg.ip4_src_addrs, start[0]);
-
-      /* Add local adjacencies for the range */
-
-      receive_dpo_add_or_lock (DPO_PROTO_IP4, ~0 /* sw_if_index */ ,
-                              NULL, &dpo);
-      prefix.fp_len = 32;
-      prefix.fp_proto = FIB_PROTOCOL_IP4;
-      prefix.fp_addr.ip4.as_u32 = start->as_u32;
-
-      fib_table_entry_special_dpo_update (fib_index,
-                                         &prefix,
-                                         FIB_SOURCE_API,
-                                         FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
-      dpo_reset (&dpo);
-
-      start_host_byte_order++;
-      start->as_u32 = clib_host_to_net_u32 (start_host_byte_order);
-    }
-  while (start_host_byte_order <= end_host_byte_order);
-
-  return 0;
-}
-
-/**
- * \brief Configure an ipv6 source address range
- * @param vm vlib_main_t pointer
- * @param start first ipv6 address in the source address range
- * @param end last ipv6 address in the source address range
- * @param table_id VRF / table ID, 0 for the default FIB
- * @return 0 if all OK, else an error indication from api_errno.h
- */
-
-int
-tcp_configure_v6_source_address_range (vlib_main_t * vm,
-                                      ip6_address_t * start,
-                                      ip6_address_t * end, u32 table_id)
-{
-  fib_prefix_t prefix;
-  u32 fib_index = 0;
-  fib_node_index_t fei;
-  u32 sw_if_index;
-
-  clib_memset (&prefix, 0, sizeof (prefix));
-
-  fib_index = fib_table_find (FIB_PROTOCOL_IP6, table_id);
-
-  if (fib_index == ~0)
-    return VNET_API_ERROR_NO_SUCH_FIB;
-
-  while (1)
-    {
-      int i;
-      ip6_address_t tmp;
-      dpo_id_t dpo = DPO_INVALID;
-
-      /* Remember this address */
-      vec_add1 (tcp_cfg.ip6_src_addrs, start[0]);
-
-      /* Lookup the prefix, to identify the interface involved */
-      prefix.fp_len = 128;
-      prefix.fp_proto = FIB_PROTOCOL_IP6;
-      memcpy (&prefix.fp_addr.ip6, start, sizeof (ip6_address_t));
-
-      fei = fib_table_lookup (fib_index, &prefix);
-
-      /* Couldn't find route to destination. Bail out. */
-      if (fei == FIB_NODE_INDEX_INVALID)
-       return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
-
-      sw_if_index = fib_entry_get_resolving_interface (fei);
-
-      if (sw_if_index == (u32) ~ 0)
-       return VNET_API_ERROR_NO_MATCHING_INTERFACE;
-
-      /* Add a proxy neighbor discovery entry for this address */
-      ip6_neighbor_proxy_add (sw_if_index, start);
-
-      /* Add a receive adjacency for this address */
-      receive_dpo_add_or_lock (DPO_PROTO_IP6, ~0 /* sw_if_index */ ,
-                              NULL, &dpo);
-
-      fib_table_entry_special_dpo_update (fib_index,
-                                         &prefix,
-                                         FIB_SOURCE_API,
-                                         FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
-      dpo_reset (&dpo);
-
-      /* Done with the entire range? */
-      if (!memcmp (start, end, sizeof (start[0])))
-       break;
-
-      /* Increment the address. DGMS. */
-      tmp = start[0];
-      for (i = 15; i >= 0; i--)
-       {
-         tmp.as_u8[i] += 1;
-         if (tmp.as_u8[i] != 0)
-           break;
-       }
-      start[0] = tmp;
-    }
-  return 0;
-}
-
-static clib_error_t *
-tcp_src_address_fn (vlib_main_t * vm,
-                   unformat_input_t * input, vlib_cli_command_t * cmd_arg)
-{
-  ip4_address_t v4start, v4end;
-  ip6_address_t v6start, v6end;
-  u32 table_id = 0;
-  int v4set = 0;
-  int v6set = 0;
-  int rv;
-
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "%U - %U", unformat_ip4_address, &v4start,
-                   unformat_ip4_address, &v4end))
-       v4set = 1;
-      else if (unformat (input, "%U", unformat_ip4_address, &v4start))
-       {
-         memcpy (&v4end, &v4start, sizeof (v4start));
-         v4set = 1;
-       }
-      else if (unformat (input, "%U - %U", unformat_ip6_address, &v6start,
-                        unformat_ip6_address, &v6end))
-       v6set = 1;
-      else if (unformat (input, "%U", unformat_ip6_address, &v6start))
-       {
-         memcpy (&v6end, &v6start, sizeof (v6start));
-         v6set = 1;
-       }
-      else if (unformat (input, "fib-table %d", &table_id))
-       ;
-      else
-       break;
-    }
-
-  if (!v4set && !v6set)
-    return clib_error_return (0, "at least one v4 or v6 address required");
-
-  if (v4set)
-    {
-      rv = tcp_configure_v4_source_address_range (vm, &v4start, &v4end,
-                                                 table_id);
-      switch (rv)
-       {
-       case 0:
-         break;
-
-       case VNET_API_ERROR_NO_SUCH_FIB:
-         return clib_error_return (0, "Invalid table-id %d", table_id);
-
-       case VNET_API_ERROR_INVALID_ARGUMENT:
-         return clib_error_return (0, "Invalid address range %U - %U",
-                                   format_ip4_address, &v4start,
-                                   format_ip4_address, &v4end);
-       default:
-         return clib_error_return (0, "error %d", rv);
-         break;
-       }
-    }
-  if (v6set)
-    {
-      rv = tcp_configure_v6_source_address_range (vm, &v6start, &v6end,
-                                                 table_id);
-      switch (rv)
-       {
-       case 0:
-         break;
-
-       case VNET_API_ERROR_NO_SUCH_FIB:
-         return clib_error_return (0, "Invalid table-id %d", table_id);
-
-       default:
-         return clib_error_return (0, "error %d", rv);
-         break;
-       }
-    }
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (tcp_src_address_command, static) =
-{
-  .path = "tcp src-address",
-  .short_help = "tcp src-address <ip-addr> [- <ip-addr>] add src address range",
-  .function = tcp_src_address_fn,
-};
-/* *INDENT-ON* */
-
-static u8 *
-tcp_scoreboard_dump_trace (u8 * s, sack_scoreboard_t * sb)
-{
-#if TCP_SCOREBOARD_TRACE
-
-  scoreboard_trace_elt_t *block;
-  int i = 0;
-
-  if (!sb->trace)
-    return s;
-
-  s = format (s, "scoreboard trace:");
-  vec_foreach (block, sb->trace)
-  {
-    s = format (s, "{%u, %u, %u, %u, %u}, ", block->start, block->end,
-               block->ack, block->snd_una_max, block->group);
-    if ((++i % 3) == 0)
-      s = format (s, "\n");
-  }
-  return s;
-#else
-  return 0;
-#endif
-}
-
-static clib_error_t *
-tcp_show_scoreboard_trace_fn (vlib_main_t * vm, unformat_input_t * input,
-                             vlib_cli_command_t * cmd_arg)
-{
-  transport_connection_t *tconn = 0;
-  tcp_connection_t *tc;
-  u8 *s = 0;
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "%U", unformat_transport_connection, &tconn,
-                   TRANSPORT_PROTO_TCP))
-       ;
-      else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
-    }
-
-  if (!TCP_SCOREBOARD_TRACE)
-    {
-      vlib_cli_output (vm, "scoreboard tracing not enabled");
-      return 0;
-    }
-
-  tc = tcp_get_connection_from_transport (tconn);
-  s = tcp_scoreboard_dump_trace (s, &tc->sack_sb);
-  vlib_cli_output (vm, "%v", s);
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (tcp_show_scoreboard_trace_command, static) =
-{
-  .path = "show tcp scoreboard trace",
-  .short_help = "show tcp scoreboard trace <connection>",
-  .function = tcp_show_scoreboard_trace_fn,
-};
-/* *INDENT-ON* */
-
-u8 *
-tcp_scoreboard_replay (u8 * s, tcp_connection_t * tc, u8 verbose)
-{
-  int i, trace_len;
-  scoreboard_trace_elt_t *trace;
-  u32 next_ack, left, group, has_new_ack = 0;
-  tcp_connection_t _dummy_tc, *dummy_tc = &_dummy_tc;
-  sack_block_t *block;
-
-  if (!TCP_SCOREBOARD_TRACE)
-    {
-      s = format (s, "scoreboard tracing not enabled");
-      return s;
-    }
-
-  if (!tc)
-    return s;
-
-  clib_memset (dummy_tc, 0, sizeof (*dummy_tc));
-  tcp_connection_timers_init (dummy_tc);
-  scoreboard_init (&dummy_tc->sack_sb);
-  dummy_tc->rcv_opts.flags |= TCP_OPTS_FLAG_SACK;
-
-#if TCP_SCOREBOARD_TRACE
-  trace = tc->sack_sb.trace;
-  trace_len = vec_len (tc->sack_sb.trace);
-#endif
-
-  for (i = 0; i < trace_len; i++)
-    {
-      if (trace[i].ack != 0)
-       {
-         dummy_tc->snd_una = trace[i].ack - 1448;
-         dummy_tc->snd_una_max = trace[i].ack;
-       }
-    }
-
-  left = 0;
-  while (left < trace_len)
-    {
-      group = trace[left].group;
-      vec_reset_length (dummy_tc->rcv_opts.sacks);
-      has_new_ack = 0;
-      while (trace[left].group == group)
-       {
-         if (trace[left].ack != 0)
-           {
-             if (verbose)
-               s = format (s, "Adding ack %u, snd_una_max %u, segs: ",
-                           trace[left].ack, trace[left].snd_una_max);
-             dummy_tc->snd_una_max = trace[left].snd_una_max;
-             next_ack = trace[left].ack;
-             has_new_ack = 1;
-           }
-         else
-           {
-             if (verbose)
-               s = format (s, "[%u, %u], ", trace[left].start,
-                           trace[left].end);
-             vec_add2 (dummy_tc->rcv_opts.sacks, block, 1);
-             block->start = trace[left].start;
-             block->end = trace[left].end;
-           }
-         left++;
-       }
-
-      /* Push segments */
-      tcp_rcv_sacks (dummy_tc, next_ack);
-      if (has_new_ack)
-       dummy_tc->snd_una = next_ack;
-
-      if (verbose)
-       s = format (s, "result: %U", format_tcp_scoreboard,
-                   &dummy_tc->sack_sb);
-
-    }
-  s = format (s, "result: %U", format_tcp_scoreboard, &dummy_tc->sack_sb);
-
-  return s;
-}
-
-static clib_error_t *
-tcp_scoreboard_trace_fn (vlib_main_t * vm, unformat_input_t * input,
-                        vlib_cli_command_t * cmd_arg)
-{
-  transport_connection_t *tconn = 0;
-  tcp_connection_t *tc = 0;
-  u8 *str = 0;
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "%U", unformat_transport_connection, &tconn,
-                   TRANSPORT_PROTO_TCP))
-       ;
-      else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
-    }
-
-  if (!TCP_SCOREBOARD_TRACE)
-    {
-      vlib_cli_output (vm, "scoreboard tracing not enabled");
-      return 0;
-    }
-
-  tc = tcp_get_connection_from_transport (tconn);
-  if (!tc)
-    {
-      vlib_cli_output (vm, "connection not found");
-      return 0;
-    }
-  str = tcp_scoreboard_replay (str, tc, 1);
-  vlib_cli_output (vm, "%v", str);
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (tcp_replay_scoreboard_command, static) =
-{
-  .path = "tcp replay scoreboard",
-  .short_help = "tcp replay scoreboard <connection>",
-  .function = tcp_scoreboard_trace_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-show_tcp_punt_fn (vlib_main_t * vm, unformat_input_t * input,
-                 vlib_cli_command_t * cmd_arg)
-{
-  tcp_main_t *tm = vnet_get_tcp_main ();
-  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    return clib_error_return (0, "unknown input `%U'", format_unformat_error,
-                             input);
-  vlib_cli_output (vm, "IPv4 TCP punt: %s",
-                  tm->punt_unknown4 ? "enabled" : "disabled");
-  vlib_cli_output (vm, "IPv6 TCP punt: %s",
-                  tm->punt_unknown6 ? "enabled" : "disabled");
-  return 0;
-}
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_tcp_punt_command, static) =
-{
-  .path = "show tcp punt",
-  .short_help = "show tcp punt",
-  .function = show_tcp_punt_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-show_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input,
-                  vlib_cli_command_t * cmd)
-{
-  tcp_main_t *tm = vnet_get_tcp_main ();
-  tcp_worker_ctx_t *wrk;
-  u32 thread;
-
-  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    return clib_error_return (0, "unknown input `%U'", format_unformat_error,
-                             input);
-  for (thread = 0; thread < vec_len (tm->wrk_ctx); thread++)
-    {
-      wrk = tcp_get_worker (thread);
-      vlib_cli_output (vm, "Thread %u:\n", thread);
-
-      if (clib_fifo_elts (wrk->pending_timers))
-       vlib_cli_output (vm, " %lu pending timers",
-                        clib_fifo_elts (wrk->pending_timers));
-
-#define _(name,type,str)                                       \
-  if (wrk->stats.name)                                         \
-    vlib_cli_output (vm, " %lu %s", wrk->stats.name, str);
-      foreach_tcp_wrk_stat
-#undef _
-    }
-
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_tcp_stats_command, static) =
-{
-  .path = "show tcp stats",
-  .short_help = "show tcp stats",
-  .function = show_tcp_stats_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-clear_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input,
-                   vlib_cli_command_t * cmd)
-{
-  tcp_main_t *tm = vnet_get_tcp_main ();
-  tcp_worker_ctx_t *wrk;
-  u32 thread;
-
-  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    return clib_error_return (0, "unknown input `%U'", format_unformat_error,
-                             input);
-
-  for (thread = 0; thread < vec_len (tm->wrk_ctx); thread++)
-    {
-      wrk = tcp_get_worker (thread);
-      clib_memset (&wrk->stats, 0, sizeof (wrk->stats));
-    }
-
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (clear_tcp_stats_command, static) =
-{
-  .path = "clear tcp stats",
-  .short_help = "clear tcp stats",
-  .function = clear_tcp_stats_fn,
-};
-/* *INDENT-ON* */
-
 /*
  * fd.io coding-style-patch-verification: ON
  *