session tcp vcl: api to update connection attributes
[vpp.git] / src / vnet / tcp / tcp.c
index 5ebb638..7f1e63e 100644 (file)
@@ -337,7 +337,7 @@ tcp_program_cleanup (tcp_worker_ctx_t * wrk, tcp_connection_t * tc)
   tcp_cleanup_req_t *req;
   clib_time_type_t now;
 
-  now = transport_time_now (tc->c_thread_index);
+  now = tcp_time_now_us (tc->c_thread_index);
   clib_fifo_add2 (wrk->pending_cleanups, req);
   req->connection_index = tc->c_c_index;
   req->free_time = now + tcp_cfg.cleanup_time;
@@ -657,9 +657,10 @@ tcp_init_mss (tcp_connection_t * tc)
   /* We should have enough space for 40 bytes of options */
   ASSERT (tc->snd_mss > 45);
 
-  /* If we use timestamp option, account for it */
+  /* If we use timestamp option, account for it and make sure
+   * the options are 4-byte aligned */
   if (tcp_opts_tstamp (&tc->rcv_opts))
-    tc->snd_mss -= TCP_OPTION_LEN_TIMESTAMP;
+    tc->snd_mss -= TCP_OPTION_LEN_TIMESTAMP + 2 /* alignment */;
 }
 
 /**
@@ -674,13 +675,12 @@ tcp_init_snd_vars (tcp_connection_t * tc)
    * handshake may make it look as if time has flown in the opposite
    * direction for us.
    */
-  tcp_set_time_now (tcp_get_worker (vlib_get_thread_index ()));
+  tcp_update_time_now (tcp_get_worker (vlib_get_thread_index ()));
 
   tcp_init_rcv_mss (tc);
   tc->iss = tcp_generate_random_iss (tc);
   tc->snd_una = tc->iss;
   tc->snd_nxt = tc->iss + 1;
-  tc->snd_una_max = tc->snd_nxt;
   tc->srtt = 0.1 * THZ;                /* 100 ms */
 
   if (!tcp_cfg.csum_offload)
@@ -873,6 +873,101 @@ tcp_half_open_session_get_transport (u32 conn_index)
   return &tc->connection;
 }
 
+static int
+tcp_set_attribute (tcp_connection_t *tc, transport_endpt_attr_t *attr)
+{
+  int rv = 0;
+
+  switch (attr->type)
+    {
+    case TRANSPORT_ENDPT_ATTR_NEXT_OUTPUT_NODE:
+      tc->next_node_index = attr->next_output_node & 0xffffffff;
+      tc->next_node_opaque = attr->next_output_node >> 32;
+      break;
+    case TRANSPORT_ENDPT_ATTR_MSS:
+      tc->mss = attr->mss;
+      tc->snd_mss = clib_min (tc->snd_mss, tc->mss);
+      break;
+    case TRANSPORT_ENDPT_ATTR_FLAGS:
+      if (attr->flags & TRANSPORT_ENDPT_ATTR_F_CSUM_OFFLOAD)
+       tc->cfg_flags |= TCP_CFG_F_NO_CSUM_OFFLOAD;
+      else
+       tc->cfg_flags &= ~TCP_CFG_F_NO_CSUM_OFFLOAD;
+      if (attr->flags & TRANSPORT_ENDPT_ATTR_F_GSO)
+       {
+         if (!(tc->cfg_flags & TCP_CFG_F_TSO))
+           tcp_check_gso (tc);
+         tc->cfg_flags &= ~TCP_CFG_F_NO_TSO;
+       }
+      else
+       {
+         tc->cfg_flags |= TCP_CFG_F_NO_TSO;
+         tc->cfg_flags &= ~TCP_CFG_F_TSO;
+       }
+      break;
+    case TRANSPORT_ENDPT_ATTR_CC_ALGO:
+      if (tc->cc_algo == tcp_cc_algo_get (attr->cc_algo))
+       break;
+      tcp_cc_cleanup (tc);
+      tc->cc_algo = tcp_cc_algo_get (attr->cc_algo);
+      tcp_cc_init (tc);
+      break;
+    default:
+      rv = -1;
+      break;
+    }
+
+  return rv;
+}
+
+static int
+tcp_get_attribute (tcp_connection_t *tc, transport_endpt_attr_t *attr)
+{
+  int rv = 0;
+  u64 non;
+
+  switch (attr->type)
+    {
+    case TRANSPORT_ENDPT_ATTR_NEXT_OUTPUT_NODE:
+      non = (u64) tc->next_node_opaque << 32 | tc->next_node_index;
+      attr->next_output_node = non;
+      break;
+    case TRANSPORT_ENDPT_ATTR_MSS:
+      attr->mss = tc->snd_mss;
+      break;
+    case TRANSPORT_ENDPT_ATTR_FLAGS:
+      attr->flags = 0;
+      if (!(tc->cfg_flags & TCP_CFG_F_NO_CSUM_OFFLOAD))
+       attr->flags |= TRANSPORT_ENDPT_ATTR_F_CSUM_OFFLOAD;
+      if (tc->cfg_flags & TCP_CFG_F_TSO)
+       attr->flags |= TRANSPORT_ENDPT_ATTR_F_GSO;
+      break;
+    case TRANSPORT_ENDPT_ATTR_CC_ALGO:
+      attr->cc_algo = tc->cc_algo - tcp_main.cc_algos;
+      break;
+    default:
+      rv = -1;
+      break;
+    }
+
+  return rv;
+}
+
+static int
+tcp_session_attribute (u32 conn_index, u32 thread_index, u8 is_get,
+                      transport_endpt_attr_t *attr)
+{
+  tcp_connection_t *tc = tcp_connection_get (conn_index, thread_index);
+
+  if (PREDICT_FALSE (!tc))
+    return -1;
+
+  if (is_get)
+    return tcp_get_attribute (tc, attr);
+  else
+    return tcp_set_attribute (tc, attr);
+}
+
 static u16
 tcp_session_cal_goal_size (tcp_connection_t * tc)
 {
@@ -916,7 +1011,10 @@ tcp_snd_space_inline (tcp_connection_t * tc)
 {
   int snd_space;
 
-  if (PREDICT_FALSE (tcp_in_fastrecovery (tc)
+  /* Fast path is disabled when recovery is on. @ref tcp_session_custom_tx
+   * controls both retransmits and the sending of new data while congested
+   */
+  if (PREDICT_FALSE (tcp_in_cong_recovery (tc)
                     || tc->state == TCP_STATE_CLOSED))
     return 0;
 
@@ -1101,7 +1199,7 @@ tcp_dispatch_pending_timers (tcp_worker_ctx_t * wrk)
        continue;
 
       /* Skip if the timer is not pending. Probably it was reset while
-       * wating for dispatch */
+       * waiting for dispatch */
       if (PREDICT_FALSE (!(tc->pending_timers & (1 << timer_id))))
        continue;
 
@@ -1144,7 +1242,7 @@ tcp_update_time (f64 now, u8 thread_index)
 {
   tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
 
-  tcp_set_time_now (wrk);
+  tcp_set_time_now (wrk, now);
   tcp_handle_cleanups (wrk, now);
   tcp_timer_expire_timers (&wrk->timer_wheel, now);
   tcp_dispatch_pending_timers (wrk);
@@ -1169,6 +1267,7 @@ const static transport_proto_vft_t tcp_proto = {
   .get_connection = tcp_session_get_transport,
   .get_listener = tcp_session_get_listener,
   .get_half_open = tcp_half_open_session_get_transport,
+  .attribute = tcp_session_attribute,
   .connect = tcp_session_open,
   .close = tcp_session_close,
   .cleanup = tcp_session_cleanup,
@@ -1327,7 +1426,7 @@ tcp_main_enable (vlib_main_t * vm)
       vec_reset_length (wrk->pending_deq_acked);
       vec_reset_length (wrk->pending_disconnects);
       vec_reset_length (wrk->pending_resets);
-      wrk->vm = vlib_mains[thread];
+      wrk->vm = vlib_get_main_by_index (thread);
       wrk->max_timers_per_loop = 10;
 
       if (thread > 0)
@@ -1421,14 +1520,15 @@ tcp_configuration_init (void)
   tcp_cfg.rwnd_min_update_ack = 1;
   tcp_cfg.max_gso_size = TCP_MAX_GSO_SZ;
 
-  /* Time constants defined as timer tick (100ms) multiples */
-  tcp_cfg.delack_time = 1;     /* 0.1s */
-  tcp_cfg.closewait_time = 20; /* 2s */
-  tcp_cfg.timewait_time = 100; /* 10s */
-  tcp_cfg.finwait1_time = 600; /* 60s */
-  tcp_cfg.lastack_time = 300;  /* 30s */
-  tcp_cfg.finwait2_time = 300; /* 30s */
-  tcp_cfg.closing_time = 300;  /* 30s */
+  /* Time constants defined as timer tick (100us) multiples */
+  tcp_cfg.closewait_time = 20000;      /* 2s */
+  tcp_cfg.timewait_time = 100000;      /* 10s */
+  tcp_cfg.finwait1_time = 600000;      /* 60s */
+  tcp_cfg.lastack_time = 300000;       /* 30s */
+  tcp_cfg.finwait2_time = 300000;      /* 30s */
+  tcp_cfg.closing_time = 300000;       /* 30s */
+
+  /* This value is seconds */
   tcp_cfg.cleanup_time = 0.1;  /* 100ms */
 }