X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ftcp%2Ftcp_output.c;h=7b0303f30335f31e50adef9f60430c87bc5e9083;hb=1cfcb78940580c8e3645fca0419d32f9286e942d;hp=2abc40a8cc77e18837712f1bfd7e402b2792a308;hpb=537e85deab6fd916952ff4badeda4ec5d6f1a121;p=vpp.git diff --git a/src/vnet/tcp/tcp_output.c b/src/vnet/tcp/tcp_output.c index 2abc40a8cc7..7b0303f3033 100644 --- a/src/vnet/tcp/tcp_output.c +++ b/src/vnet/tcp/tcp_output.c @@ -130,20 +130,19 @@ tcp_initial_window_to_advertise (tcp_connection_t * tc) return clib_min (tc->rcv_wnd, TCP_WND_MAX); } -static void +static inline void tcp_update_rcv_wnd (tcp_connection_t * tc) { + u32 available_space, wnd; i32 observed_wnd; - u32 available_space, max_fifo, wnd; + + ASSERT (tc->rcv_opts.mss < transport_rx_fifo_size (&tc->connection)); /* * Figure out how much space we have available */ available_space = transport_max_rx_enqueue (&tc->connection); - max_fifo = transport_rx_fifo_size (&tc->connection); - - ASSERT (tc->rcv_opts.mss < max_fifo); - if (available_space < tc->rcv_opts.mss && available_space < max_fifo >> 3) + if (PREDICT_FALSE (available_space < tc->rcv_opts.mss)) available_space = 0; /* @@ -151,13 +150,11 @@ tcp_update_rcv_wnd (tcp_connection_t * tc) * to compute the new window */ observed_wnd = (i32) tc->rcv_wnd - (tc->rcv_nxt - tc->rcv_las); - if (observed_wnd < 0) - observed_wnd = 0; /* Bad. Thou shalt not shrink */ - if (available_space < observed_wnd) + if (PREDICT_FALSE ((i32) available_space < observed_wnd)) { - wnd = observed_wnd; + wnd = clib_max (observed_wnd, 0); TCP_EVT_DBG (TCP_EVT_RCV_WND_SHRUNK, tc, observed_wnd, available_space); } else @@ -186,16 +183,6 @@ tcp_window_to_advertise (tcp_connection_t * tc, tcp_state_t state) return tcp_initial_window_to_advertise (tc); tcp_update_rcv_wnd (tc); - - if (tc->rcv_wnd == 0) - { - tc->flags |= TCP_CONN_SENT_RCV_WND0; - } - else - { - tc->flags &= ~TCP_CONN_SENT_RCV_WND0; - } - return tc->rcv_wnd >> tc->rcv_wscale; } @@ -357,7 +344,7 @@ tcp_make_established_options (tcp_connection_t * tc, tcp_options_t * opts) if (tcp_opts_tstamp (&tc->rcv_opts)) { opts->flags |= TCP_OPTS_FLAG_TSTAMP; - opts->tsval = tcp_time_now_w_thread (tc->c_thread_index); + opts->tsval = tcp_tstamp (tc); opts->tsecr = tc->tsval_recent; len += TCP_OPTION_LEN_TIMESTAMP; } @@ -435,6 +422,12 @@ tcp_update_burst_snd_vars (tcp_connection_t * tc) &tc->snd_opts); tcp_update_rcv_wnd (tc); + + if (tc->flags & TCP_CONN_RATE_SAMPLE) + tc->flags |= TCP_CONN_TRACK_BURST; + + if (tc->snd_una == tc->snd_nxt) + tcp_cc_event (tc, TCP_CC_EVT_START_TX); } void @@ -515,6 +508,11 @@ tcp_make_ack_i (tcp_connection_t * tc, vlib_buffer_t * b, tcp_state_t state, tcp_options_write ((u8 *) (th + 1), snd_opts); vnet_buffer (b)->tcp.connection_index = tc->c_c_index; + + if (wnd == 0) + tcp_zero_rwnd_sent_on (tc); + else + tcp_zero_rwnd_sent_off (tc); } /** @@ -535,9 +533,6 @@ void tcp_make_fin (tcp_connection_t * tc, vlib_buffer_t * b) { tcp_make_ack_i (tc, b, TCP_STATE_ESTABLISHED, TCP_FLAG_FIN | TCP_FLAG_ACK); - - /* Reset flags, make sure ack is sent */ - vnet_buffer (b)->tcp.flags &= ~TCP_BUF_FLAG_DUPACK; } /** @@ -1145,10 +1140,18 @@ u32 tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b) { tcp_connection_t *tc = (tcp_connection_t *) tconn; + + if (tc->flags & TCP_CONN_TRACK_BURST) + { + tcp_bt_check_app_limited (tc); + tcp_bt_track_tx (tc); + tc->flags &= ~TCP_CONN_TRACK_BURST; + } + tcp_push_hdr_i (tc, b, tc->snd_nxt, /* compute opts */ 0, /* burst */ 1, /* update_snd_nxt */ 1); + tc->snd_una_max = seq_max (tc->snd_nxt, tc->snd_una_max); - ASSERT (seq_leq (tc->snd_una_max, tc->snd_una + tc->snd_wnd)); tcp_validate_txf_size (tc, tc->snd_una_max - tc->snd_una); /* If not tracking an ACK, start tracking */ if (tc->rtt_ts == 0 && !tcp_in_cong_recovery (tc)) @@ -1270,6 +1273,28 @@ tcp_timer_delack_handler (u32 index) tcp_send_ack (tc); } +/** + * Send Window Update ACK, + * ensuring that it will be sent once, if RWND became non-zero, + * after zero RWND has been advertised in ACK before + */ +void +tcp_send_window_update_ack (tcp_connection_t * tc) +{ + tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index); + u32 win; + + if (tcp_zero_rwnd_sent (tc)) + { + win = tcp_window_to_advertise (tc, tc->state); + if (win > 0) + { + tcp_zero_rwnd_sent_off (tc); + tcp_program_ack (wrk, tc); + } + } +} + /** * Allocate a new buffer and build a new tcp segment * @@ -1435,7 +1460,11 @@ tcp_prepare_retransmit_segment (tcp_worker_ctx_t * wrk, return 0; if (tcp_in_fastrecovery (tc)) - tc->snd_rxt_bytes += n_bytes; + { + tc->snd_rxt_bytes += n_bytes; + if (tc->flags & TCP_CONN_RATE_SAMPLE) + tcp_bt_track_rxt (tc, start, start + n_bytes); + } done: TCP_EVT_DBG (TCP_EVT_CC_RTX, tc, offset, n_bytes); @@ -1446,26 +1475,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); @@ -1534,15 +1559,32 @@ tcp_timer_retransmit_handler_i (u32 index, u8 is_syn) tcp_update_rto (tc); } + /* Peer is dead or network connectivity is lost. Close connection. + * RFC 1122 section 4.2.3.5 recommends a value of at least 100s. For + * a min rto of 0.2s we need to retry about 8 times. */ + if (tc->rto_boff >= TCP_RTO_BOFF_MAX) + { + tcp_send_reset (tc); + tcp_connection_set_state (tc, TCP_STATE_CLOSED); + session_transport_closing_notify (&tc->connection); + tcp_connection_timers_reset (tc); + tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME); + return; + } + /* Increment RTO backoff (also equal to number of retries) and go back * 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); /* If we've sent beyond snd_congestion, update it */ tc->snd_congestion = seq_max (tc->snd_nxt, tc->snd_congestion); @@ -1563,7 +1605,7 @@ tcp_timer_retransmit_handler_i (u32 index, u8 is_syn) /* For first retransmit, record timestamp (Eifel detection RFC3522) */ if (tc->rto_boff == 1) - tc->snd_rxt_ts = tcp_time_now_w_thread (tc->c_thread_index); + tc->snd_rxt_ts = tcp_tstamp (tc); tcp_enqueue_to_output (wrk, b, bi, tc->c_is_ip4); tcp_retransmit_timer_force_update (tc); @@ -1908,12 +1950,13 @@ tcp_fast_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, ASSERT (tcp_in_fastrecovery (tc)); TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 0); + snd_space = tcp_available_cc_snd_space (tc); + if (!tcp_fastrecovery_first (tc)) goto send_unsent; /* RFC 6582: [If a partial ack], retransmit the first unacknowledged * segment. */ - snd_space = tc->sack_sb.last_bytes_delivered; while (snd_space > 0 && n_segs < burst_size) { n_written = tcp_prepare_retransmit_segment (wrk, tc, offset, @@ -1936,7 +1979,6 @@ tcp_fast_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, send_unsent: /* RFC 6582: Send a new segment if permitted by the new value of cwnd. */ - snd_space = tcp_available_cc_snd_space (tc); if (snd_space < tc->snd_mss || tc->snd_mss == 0) goto done; @@ -2066,6 +2108,13 @@ tcp_output_handle_packet (tcp_connection_t * tc0, vlib_buffer_t * b0, return; } + /* If next_index is not drop use it */ + if (tc0->next_node_index) + { + *next0 = tc0->next_node_index; + vnet_buffer (b0)->tcp.next_node_opaque = tc0->next_node_opaque; + } + vnet_buffer (b0)->sw_if_index[VLIB_TX] = tc0->c_fib_index; vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;