Horizontal (nSessions) scaling draft
[vpp.git] / src / vnet / tcp / tcp_output.c
index 47c94e6..b418e8b 100644 (file)
@@ -19,7 +19,7 @@
 vlib_node_registration_t tcp4_output_node;
 vlib_node_registration_t tcp6_output_node;
 
-typedef enum _tcp_output_nect
+typedef enum _tcp_output_next
 {
   TCP_OUTPUT_NEXT_DROP,
   TCP_OUTPUT_NEXT_IP_LOOKUP,
@@ -430,16 +430,16 @@ tcp_init_mss (tcp_connection_t * tc)
 #define tcp_get_free_buffer_index(tm, bidx)                             \
 do {                                                                    \
   u32 *my_tx_buffers, n_free_buffers;                                   \
-  u32 thread_index = vlib_get_thread_index();                                  \
-  my_tx_buffers = tm->tx_buffers[thread_index];                            \
+  u32 thread_index = vlib_get_thread_index();                           \
+  my_tx_buffers = tm->tx_buffers[thread_index];                         \
   if (PREDICT_FALSE(vec_len (my_tx_buffers) == 0))                      \
     {                                                                   \
       n_free_buffers = 32;      /* TODO config or macro */              \
       vec_validate (my_tx_buffers, n_free_buffers - 1);                 \
       _vec_len(my_tx_buffers) = vlib_buffer_alloc_from_free_list (      \
-          tm->vlib_main, my_tx_buffers, n_free_buffers,                 \
+       vlib_get_main(), my_tx_buffers, n_free_buffers,                  \
           VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);                         \
-      tm->tx_buffers[thread_index] = my_tx_buffers;                        \
+      tm->tx_buffers[thread_index] = my_tx_buffers;                     \
     }                                                                   \
   /* buffer shortage */                                                 \
   if (PREDICT_FALSE (vec_len (my_tx_buffers) == 0))                     \
@@ -448,12 +448,12 @@ do {                                                                    \
   _vec_len (my_tx_buffers) -= 1;                                        \
 } while (0)
 
-#define tcp_return_buffer(tm)                                          \
-do {                                                                   \
-  u32 *my_tx_buffers;                                                  \
-  u32 thread_index = vlib_get_thread_index();                                  \
-  my_tx_buffers = tm->tx_buffers[thread_index];                                \
-  _vec_len (my_tx_buffers) +=1;                                                \
+#define tcp_return_buffer(tm)                   \
+do {                                            \
+  u32 *my_tx_buffers;                           \
+  u32 thread_index = vlib_get_thread_index();   \
+  my_tx_buffers = tm->tx_buffers[thread_index]; \
+  _vec_len (my_tx_buffers) +=1;                 \
 } while (0)
 
 always_inline void
@@ -760,23 +760,22 @@ void
 tcp_push_ip_hdr (tcp_main_t * tm, tcp_connection_t * tc, vlib_buffer_t * b)
 {
   tcp_header_t *th = vlib_buffer_get_current (b);
-
+  vlib_main_t *vm = vlib_get_main ();
   if (tc->c_is_ip4)
     {
       ip4_header_t *ih;
-      ih = vlib_buffer_push_ip4 (tm->vlib_main, b, &tc->c_lcl_ip4,
+      ih = vlib_buffer_push_ip4 (vm, b, &tc->c_lcl_ip4,
                                 &tc->c_rmt_ip4, IP_PROTOCOL_TCP);
-      th->checksum = ip4_tcp_udp_compute_checksum (tm->vlib_main, b, ih);
+      th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih);
     }
   else
     {
       ip6_header_t *ih;
       int bogus = ~0;
 
-      ih = vlib_buffer_push_ip6 (tm->vlib_main, b, &tc->c_lcl_ip6,
+      ih = vlib_buffer_push_ip6 (vm, b, &tc->c_lcl_ip6,
                                 &tc->c_rmt_ip6, IP_PROTOCOL_TCP);
-      th->checksum = ip6_tcp_udp_icmp_compute_checksum (tm->vlib_main, b, ih,
-                                                       &bogus);
+      th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ih, &bogus);
       ASSERT (!bogus);
     }
 }
@@ -854,6 +853,13 @@ tcp_enqueue_to_output (vlib_main_t * vm, vlib_buffer_t * b, u32 bi, u8 is_ip4)
   /* Decide where to send the packet */
   next_index = is_ip4 ? tcp4_output_node.index : tcp6_output_node.index;
 
+  /* Initialize the trajectory trace, if configured */
+  if (VLIB_BUFFER_TRACE_TRAJECTORY > 0)
+    {
+      b->pre_data[0] = 1;
+      b->pre_data[1] = next_index;
+    }
+
   /* Enqueue the packet */
   f = vlib_get_frame_to_node (vm, next_index);
   to_next = vlib_frame_vector_args (f);
@@ -1052,6 +1058,7 @@ tcp_rtx_timeout_cc (tcp_connection_t * tc)
   tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
   tc->cwnd = tcp_loss_wnd (tc);
   tc->snd_congestion = tc->snd_una_max;
+
   tcp_recovery_on (tc);
 }
 
@@ -1146,6 +1153,7 @@ tcp_timer_retransmit_handler_i (u32 index, u8 is_syn)
 
       /* Account for the SYN */
       tc->snd_nxt += 1;
+      tc->rtt_ts = 0;
     }
   else
     {
@@ -1213,7 +1221,7 @@ tcp_timer_persist_handler (u32 index)
   tc->timers[TCP_TIMER_PERSIST] = TCP_TIMER_HANDLE_INVALID;
 
   /* Problem already solved or worse */
-  if (tc->state == TCP_STATE_CLOSED
+  if (tc->state == TCP_STATE_CLOSED || tc->state > TCP_STATE_ESTABLISHED
       || tc->snd_wnd > tc->snd_mss || tcp_in_recovery (tc))
     return;
 
@@ -1234,7 +1242,7 @@ tcp_timer_persist_handler (u32 index)
   /* Nothing to send */
   if (n_bytes <= 0)
     {
-      clib_warning ("persist found nothing to send");
+      // clib_warning ("persist found nothing to send");
       tcp_return_buffer (tm);
       return;
     }
@@ -1505,10 +1513,7 @@ tcp46_output_inline (vlib_main_t * vm,
 
          /* Stop DELACK timer and fix flags */
          tc0->flags &= ~(TCP_CONN_SNDACK);
-         if (tcp_timer_is_active (tc0, TCP_TIMER_DELACK))
-           {
-             tcp_timer_reset (tc0, TCP_TIMER_DELACK);
-           }
+         tcp_timer_reset (tc0, TCP_TIMER_DELACK);
 
          /* If not retransmitting
           * 1) update snd_una_max (SYN, SYNACK, FIN)
@@ -1532,10 +1537,31 @@ tcp46_output_inline (vlib_main_t * vm,
              tc0->rto_boff = 0;
            }
 
-         /* set fib index to default and lookup node */
-         /* XXX network virtualization (vrf/vni) */
+#if 0
+         /* Make sure we haven't lost route to our peer */
+         if (PREDICT_FALSE (tc0->last_fib_check
+                            < tc0->snd_opts.tsval + TCP_FIB_RECHECK_PERIOD))
+           {
+             if (PREDICT_TRUE
+                 (tc0->c_rmt_fei == tcp_lookup_rmt_in_fib (tc0)))
+               {
+                 tc0->last_fib_check = tc0->snd_opts.tsval;
+               }
+             else
+               {
+                 clib_warning ("lost connection to peer");
+                 tcp_connection_reset (tc0);
+                 goto done;
+               }
+           }
+
+         /* Use pre-computed dpo to set next node */
+         next0 = tc0->c_rmt_dpo.dpoi_next_node;
+         vnet_buffer (b0)->ip.adj_index[VLIB_TX] = tc0->c_rmt_dpo.dpoi_index;
+#endif
+
          vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
-         vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+         vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
 
          b0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
        done:
@@ -1630,7 +1656,7 @@ tcp_push_header (transport_connection_t * tconn, vlib_buffer_t * b)
   tc = (tcp_connection_t *) tconn;
   tcp_push_hdr_i (tc, b, TCP_STATE_ESTABLISHED, 0);
 
-  if (tc->rtt_ts == 0)
+  if (tc->rtt_ts == 0 && !tcp_in_cong_recovery (tc))
     {
       tc->rtt_ts = tcp_time_now ();
       tc->rtt_seq = tc->snd_nxt;