+ return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST);
+}
+
+static inline void
+spacer_update_bucket (spacer_t * pacer, u32 bytes)
+{
+ ASSERT (pacer->bucket >= bytes);
+ pacer->bucket -= bytes;
+}
+
+static inline void
+spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec,
+ clib_us_time_t rtt)
+{
+ ASSERT (rate_bytes_per_sec != 0);
+ pacer->bytes_per_sec = rate_bytes_per_sec;
+ pacer->tokens_per_period = rate_bytes_per_sec * CLIB_US_TIME_PERIOD;
+ pacer->idle_timeout_us = clib_max (rtt * TRANSPORT_PACER_IDLE_FACTOR,
+ TRANSPORT_PACER_MIN_IDLE);
+}
+
+static inline u64
+spacer_pace_rate (spacer_t * pacer)
+{
+ return pacer->bytes_per_sec;
+}
+
+static inline void
+spacer_reset (spacer_t * pacer, clib_us_time_t time_now, u64 bucket)
+{
+ pacer->last_update = time_now;
+ pacer->bucket = bucket;
+}
+
+void
+transport_connection_tx_pacer_reset (transport_connection_t * tc,
+ u64 rate_bytes_per_sec, u32 start_bucket,
+ clib_us_time_t rtt)
+{
+ spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec, rtt);
+ spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index),
+ start_bucket);
+}
+
+void
+transport_connection_tx_pacer_reset_bucket (transport_connection_t * tc,
+ u32 bucket)
+{
+ spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index), bucket);
+}
+
+void
+transport_connection_tx_pacer_init (transport_connection_t * tc,
+ u64 rate_bytes_per_sec,
+ u32 initial_bucket)
+{
+ tc->flags |= TRANSPORT_CONNECTION_F_IS_TX_PACED;
+ transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec,
+ initial_bucket, 1e6);
+}
+
+void
+transport_connection_tx_pacer_update (transport_connection_t * tc,
+ u64 bytes_per_sec, clib_us_time_t rtt)
+{
+ spacer_set_pace_rate (&tc->pacer, bytes_per_sec, rtt);
+}
+
+u32
+transport_connection_tx_pacer_burst (transport_connection_t * tc)
+{
+ return spacer_max_burst (&tc->pacer,
+ transport_us_time_now (tc->thread_index));
+}
+
+u64
+transport_connection_tx_pacer_rate (transport_connection_t * tc)
+{
+ return spacer_pace_rate (&tc->pacer);
+}
+
+void
+transport_connection_update_tx_bytes (transport_connection_t * tc, u32 bytes)
+{
+ if (transport_connection_is_tx_paced (tc))
+ spacer_update_bucket (&tc->pacer, bytes);
+}
+
+void
+transport_connection_tx_pacer_update_bytes (transport_connection_t * tc,
+ u32 bytes)
+{
+ spacer_update_bucket (&tc->pacer, bytes);
+}
+
+void
+transport_connection_reschedule (transport_connection_t * tc)
+{
+ tc->flags &= ~TRANSPORT_CONNECTION_F_DESCHED;
+ transport_connection_tx_pacer_reset_bucket (tc, TRANSPORT_PACER_MIN_BURST);
+ if (transport_max_tx_dequeue (tc))
+ sesssion_reschedule_tx (tc);
+ else