tcp: avoid fr segments less than mss if possible
[vpp.git] / src / vnet / tcp / tcp_cubic.c
index 17f7932..cf2b9a1 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <vnet/tcp/tcp.h>
+#include <vnet/tcp/tcp_inlines.h>
 #include <math.h>
 
 #define beta_cubic     0.7
 typedef struct cubic_cfg_
 {
   u8 fast_convergence;
+  u32 ssthresh;
 } cubic_cfg_t;
 
 static cubic_cfg_t cubic_cfg = {
   .fast_convergence = 1,
+  .ssthresh = 0x7FFFFFFFU,
 };
 
 typedef struct cubic_data_
@@ -48,7 +51,7 @@ STATIC_ASSERT (sizeof (cubic_data_t) <= TCP_CC_DATA_SZ, "cubic data len");
 static inline f64
 cubic_time (u32 thread_index)
 {
-  return transport_time_now (thread_index);
+  return tcp_time_now_us (thread_index);
 }
 
 /**
@@ -138,7 +141,7 @@ cubic_cwnd_accumulate (tcp_connection_t * tc, u32 thresh, u32 bytes_acked)
       tc->cwnd_acc_bytes = 0;
     }
 
-  tcp_cwnd_accumulate (tc, thresh, tc->bytes_acked);
+  tcp_cwnd_accumulate (tc, thresh, bytes_acked);
 }
 
 static void
@@ -155,7 +158,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
 
   if (tcp_in_slowstart (tc))
     {
-      tc->cwnd += tc->bytes_acked;
+      tc->cwnd += rs->delivered;
       return;
     }
 
@@ -166,7 +169,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
   w_aimd = (u64) W_est (cd, t, rtt_sec) * tc->snd_mss;
   if (w_cubic < w_aimd)
     {
-      cubic_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked);
+      cubic_cwnd_accumulate (tc, tc->cwnd, rs->delivered);
     }
   else
     {
@@ -192,7 +195,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
          /* Practically we can't increment so just inflate threshold */
          thresh = 50 * tc->cwnd;
        }
-      cubic_cwnd_accumulate (tc, thresh, tc->bytes_acked);
+      cubic_cwnd_accumulate (tc, thresh, rs->delivered);
     }
 }
 
@@ -200,7 +203,7 @@ static void
 cubic_conn_init (tcp_connection_t * tc)
 {
   cubic_data_t *cd = (cubic_data_t *) tcp_cc_data (tc);
-  tc->ssthresh = tc->snd_wnd;
+  tc->ssthresh = cubic_cfg.ssthresh;
   tc->cwnd = tcp_initial_cwnd (tc);
   cd->w_max = 0;
   cd->K = 0;
@@ -210,6 +213,8 @@ cubic_conn_init (tcp_connection_t * tc)
 static uword
 cubic_unformat_config (unformat_input_t * input)
 {
+  u32 ssthresh = 0x7FFFFFFFU;
+
   if (!input)
     return 0;
 
@@ -219,12 +224,31 @@ cubic_unformat_config (unformat_input_t * input)
     {
       if (unformat (input, "no-fast-convergence"))
        cubic_cfg.fast_convergence = 0;
+      else if (unformat (input, "ssthresh %u", &ssthresh))
+       cubic_cfg.ssthresh = ssthresh;
       else
        return 0;
     }
   return 1;
 }
 
+void
+cubic_event (tcp_connection_t *tc, tcp_cc_event_t evt)
+{
+  cubic_data_t *cd;
+  f64 now;
+
+  if (evt != TCP_CC_EVT_START_TX)
+    return;
+
+  /* App was idle so update t_start to avoid artificially
+   * inflating cwnd if nothing recently sent and acked */
+  cd = (cubic_data_t *) tcp_cc_data (tc);
+  now = cubic_time (tc->c_thread_index);
+  if (now > tc->mrtt_us + 1)
+    cd->t_start = now;
+}
+
 const static tcp_cc_algorithm_t tcp_cubic = {
   .name = "cubic",
   .unformat_cfg = cubic_unformat_config,
@@ -233,6 +257,7 @@ const static tcp_cc_algorithm_t tcp_cubic = {
   .recovered = cubic_recovered,
   .rcv_ack = cubic_rcv_ack,
   .rcv_cong_ack = newreno_rcv_cong_ack,
+  .event = cubic_event,
   .init = cubic_conn_init,
 };