tcp: avoid fr segments less than mss if possible
[vpp.git] / src / vnet / tcp / tcp_cubic.c
index 3815627..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);
 }
 
 /**
@@ -103,6 +106,18 @@ cubic_congestion (tcp_connection_t * tc)
 
   cd->w_max = w_max;
   tc->ssthresh = clib_max (tc->cwnd * beta_cubic, 2 * tc->snd_mss);
+  tc->cwnd = tc->ssthresh;
+}
+
+static void
+cubic_loss (tcp_connection_t * tc)
+{
+  cubic_data_t *cd = (cubic_data_t *) tcp_cc_data (tc);
+
+  tc->cwnd = tcp_loss_wnd (tc);
+  cd->t_start = cubic_time (tc->c_thread_index);
+  cd->K = 0;
+  cd->w_max = tc->cwnd / tc->snd_mss;
 }
 
 static void
@@ -126,11 +141,11 @@ 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
-cubic_rcv_ack (tcp_connection_t * tc)
+cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
 {
   cubic_data_t *cd = (cubic_data_t *) tcp_cc_data (tc);
   u64 w_cubic, w_aimd;
@@ -143,7 +158,7 @@ cubic_rcv_ack (tcp_connection_t * tc)
 
   if (tcp_in_slowstart (tc))
     {
-      tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked);
+      tc->cwnd += rs->delivered;
       return;
     }
 
@@ -154,7 +169,7 @@ cubic_rcv_ack (tcp_connection_t * tc)
   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
     {
@@ -180,7 +195,7 @@ cubic_rcv_ack (tcp_connection_t * tc)
          /* 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);
     }
 }
 
@@ -188,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;
@@ -198,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;
 
@@ -207,19 +224,40 @@ 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,
   .congestion = cubic_congestion,
+  .loss = cubic_loss,
   .recovered = cubic_recovered,
   .rcv_ack = cubic_rcv_ack,
   .rcv_cong_ack = newreno_rcv_cong_ack,
+  .event = cubic_event,
   .init = cubic_conn_init,
 };