tcp: add loss signal to cc algo 86/20486/7
authorFlorin Coras <fcoras@cisco.com>
Thu, 4 Jul 2019 00:47:22 +0000 (17:47 -0700)
committerDamjan Marion <dmarion@me.com>
Fri, 5 Jul 2019 11:58:34 +0000 (11:58 +0000)
Type:feature

Change-Id: Ibe1a4c555b55fb929d55b02599aaf099ed522cdf
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/tcp/tcp.h
src/vnet/tcp/tcp_cubic.c
src/vnet/tcp/tcp_input.c
src/vnet/tcp/tcp_newreno.c
src/vnet/tcp/tcp_output.c

index 8b943cd..2bc6f22 100644 (file)
@@ -379,13 +379,14 @@ struct _tcp_cc_algorithm
 {
   const char *name;
   uword (*unformat_cfg) (unformat_input_t * input);
+  void (*init) (tcp_connection_t * tc);
+  void (*cleanup) (tcp_connection_t * tc);
   void (*rcv_ack) (tcp_connection_t * tc, tcp_rate_sample_t *rs);
   void (*rcv_cong_ack) (tcp_connection_t * tc, tcp_cc_ack_t ack,
                        tcp_rate_sample_t *rs);
   void (*congestion) (tcp_connection_t * tc);
+  void (*loss) (tcp_connection_t * tc);
   void (*recovered) (tcp_connection_t * tc);
-  void (*init) (tcp_connection_t * tc);
-  void (*cleanup) (tcp_connection_t * tc);
 };
 /* *INDENT-ON* */
 
@@ -900,7 +901,7 @@ int tcp_fast_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
 int tcp_fast_retransmit (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
                         u32 burst_size);
 void tcp_cc_init_congestion (tcp_connection_t * tc);
-void tcp_cc_fastrecovery_exit (tcp_connection_t * tc);
+void tcp_cc_fastrecovery_clear (tcp_connection_t * tc);
 
 fib_node_index_t tcp_lookup_rmt_in_fib (tcp_connection_t * tc);
 
@@ -958,6 +959,12 @@ tcp_cc_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type,
   tc->cc_algo->rcv_cong_ack (tc, ack_type, rs);
 }
 
+static inline void
+tcp_cc_loss (tcp_connection_t * tc)
+{
+  tc->cc_algo->loss (tc);
+}
+
 always_inline void
 tcp_timer_set (tcp_connection_t * tc, u8 timer_id, u32 interval)
 {
index 80d4308..0b4226d 100644 (file)
@@ -105,6 +105,18 @@ cubic_congestion (tcp_connection_t * tc)
   tc->ssthresh = clib_max (tc->cwnd * beta_cubic, 2 * tc->snd_mss);
 }
 
+static void
+cubic_loss (tcp_connection_t * tc)
+{
+  cubic_data_t *cd = (cubic_data_t *) tcp_cc_data (tc);
+
+  tc->ssthresh = clib_max (tc->cwnd * beta_cubic, 2 * tc->snd_mss);
+  tc->cwnd = tcp_loss_wnd (tc);
+  cd->t_start = cubic_time (tc->c_thread_index);
+  cd->K = 0;
+  cd->w_max = 0;
+}
+
 static void
 cubic_recovered (tcp_connection_t * tc)
 {
@@ -217,6 +229,7 @@ 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,
index 848028f..5a7ae5e 100644 (file)
@@ -1183,14 +1183,11 @@ tcp_cc_recovery_exit (tcp_connection_t * tc)
   TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3);
 }
 
-#ifndef CLIB_MARCH_VARIANT
-void
-tcp_cc_fastrecovery_exit (tcp_connection_t * tc)
+static inline void
+tcp_cc_fastrecovery_clear_inline (tcp_connection_t * tc)
 {
-  tc->cc_algo->recovered (tc);
   tc->snd_rxt_bytes = 0;
   tc->rcv_dupacks = 0;
-  tc->snd_rxt_bytes = 0;
   tc->rtt_ts = 0;
 
   tcp_fastrecovery_off (tc);
@@ -1198,6 +1195,20 @@ tcp_cc_fastrecovery_exit (tcp_connection_t * tc)
 
   TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3);
 }
+
+static void
+tcp_cc_fastrecovery_exit (tcp_connection_t * tc)
+{
+  tc->cc_algo->recovered (tc);
+  tcp_cc_fastrecovery_clear_inline (tc);
+}
+
+#ifndef CLIB_MARCH_VARIANT
+void
+tcp_cc_fastrecovery_clear (tcp_connection_t * tc)
+{
+  tcp_cc_fastrecovery_clear_inline (tc);
+}
 #endif /* CLIB_MARCH_VARIANT */
 
 static void
index 3887b34..7e37efb 100644 (file)
 
 #include <vnet/tcp/tcp.h>
 
-void
+static void
 newreno_congestion (tcp_connection_t * tc)
 {
   tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
 }
 
-void
+static void
+newreno_loss (tcp_connection_t * tc)
+{
+  tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss);
+  tc->cwnd = tcp_loss_wnd (tc);
+}
+
+static void
 newreno_recovered (tcp_connection_t * tc)
 {
   tc->cwnd = tc->ssthresh;
 }
 
-void
+static void
 newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs)
 {
   if (tcp_in_slowstart (tc))
@@ -72,7 +79,7 @@ newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type,
     }
 }
 
-void
+static void
 newreno_conn_init (tcp_connection_t * tc)
 {
   tc->ssthresh = tc->snd_wnd;
@@ -82,6 +89,7 @@ newreno_conn_init (tcp_connection_t * tc)
 const static tcp_cc_algorithm_t tcp_newreno = {
   .name = "newreno",
   .congestion = newreno_congestion,
+  .loss = newreno_loss,
   .recovered = newreno_recovered,
   .rcv_ack = newreno_rcv_ack,
   .rcv_cong_ack = newreno_rcv_cong_ack,
index 7cf85c3..8537b1f 100644 (file)
@@ -1472,26 +1472,22 @@ done:
  * Reset congestion control, switch cwnd to loss window and try again.
  */
 static void
-tcp_rxt_timeout_cc (tcp_connection_t * tc)
+tcp_cc_init_rxt_timeout (tcp_connection_t * tc)
 {
   TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 6);
   tc->prev_ssthresh = tc->ssthresh;
   tc->prev_cwnd = tc->cwnd;
 
-  /* Cleanly recover cc (also clears up fast retransmit) */
+  /* Clear fast recovery state if needed */
   if (tcp_in_fastrecovery (tc))
-    {
-      /* TODO be less aggressive about this */
-      scoreboard_clear (&tc->sack_sb);
-      tcp_cc_fastrecovery_exit (tc);
-    }
-  else
-    tc->rcv_dupacks = 0;
+    tcp_cc_fastrecovery_clear (tc);
+
+  /* Let cc algo decide loss cwnd and ssthresh */
+  tcp_cc_loss (tc);
 
   /* Start again from the beginning */
-  tc->cc_algo->congestion (tc);
-  tc->cwnd = tcp_loss_wnd (tc);
   tc->snd_congestion = tc->snd_nxt;
+  tc->rcv_dupacks = 0;
   tc->rtt_ts = 0;
   tc->cwnd_acc_bytes = 0;
   tcp_connection_tx_pacer_reset (tc, tc->cwnd, 2 * tc->snd_mss);
@@ -1577,11 +1573,12 @@ tcp_timer_retransmit_handler_i (u32 index, u8 is_syn)
        * to first un-acked byte  */
       tc->rto_boff += 1;
 
+      /* TODO be less aggressive about clearing scoreboard */
+      scoreboard_clear (&tc->sack_sb);
+
       /* First retransmit timeout */
       if (tc->rto_boff == 1)
-       tcp_rxt_timeout_cc (tc);
-      else
-       scoreboard_clear (&tc->sack_sb);
+       tcp_cc_init_rxt_timeout (tc);
 
       if (tc->flags & TCP_CONN_RATE_SAMPLE)
        tcp_bt_flush_samples (tc);