session: cleanup part 1
[vpp.git] / src / vnet / session / transport.c
index 42149eb..0f86f9e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -47,7 +47,8 @@ static clib_spinlock_t local_endpoints_lock;
  */
 static double transport_pacer_period;
 
-#define TRANSPORT_PACER_MIN_MSS 1460
+#define TRANSPORT_PACER_MIN_MSS        1460
+#define TRANSPORT_PACER_MIN_BURST      TRANSPORT_PACER_MIN_MSS
 
 u8 *
 format_transport_proto (u8 * s, va_list * args)
@@ -124,14 +125,13 @@ u8 *
 format_transport_listen_connection (u8 * s, va_list * args)
 {
   u32 transport_proto = va_arg (*args, u32);
-  u32 listen_index = va_arg (*args, u32);
   transport_proto_vft_t *tp_vft;
 
   tp_vft = transport_protocol_get_vft (transport_proto);
   if (!tp_vft)
     return s;
 
-  s = format (s, "%U", tp_vft->format_listener, listen_index);
+  s = (tp_vft->format_listener) (s, args);
   return s;
 }
 
@@ -318,7 +318,7 @@ transport_endpoint_mark_used (u8 proto, ip46_address_t * ip, u16 port)
   transport_endpoint_t *tep;
   clib_spinlock_lock_if_init (&local_endpoints_lock);
   tep = transport_endpoint_new ();
-  clib_memcpy (&tep->ip, ip, sizeof (*ip));
+  clib_memcpy_fast (&tep->ip, ip, sizeof (*ip));
   tep->port = port;
   transport_endpoint_table_add (&local_endpoints_table, proto, tep,
                                tep - local_endpoints);
@@ -387,7 +387,7 @@ transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
        return clib_error_return (0, "no routable ip6 addresses on %U",
                                  format_vnet_sw_if_index_name,
                                  vnet_get_main (), sw_if_index);
-      clib_memcpy (&addr->ip6, ip6, sizeof (*ip6));
+      clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
     }
   return 0;
 }
@@ -403,7 +403,7 @@ transport_find_local_ip_for_remote (u32 sw_if_index,
   if (sw_if_index == ENDPOINT_INVALID_INDEX)
     {
       /* Find a FIB path to the destination */
-      clib_memcpy (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
+      clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
       prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
       prefix.fp_len = rmt->is_ip4 ? 32 : 128;
 
@@ -443,12 +443,16 @@ transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt_cfg,
       error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index,
                                                  rmt, lcl_addr);
       if (error)
-       return -1;
+       {
+         clib_error_report (error);
+         return -1;
+       }
     }
   else
     {
       /* Assume session layer vetted this address */
-      clib_memcpy (lcl_addr, &rmt_cfg->peer.ip, sizeof (rmt_cfg->peer.ip));
+      clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip,
+                       sizeof (rmt_cfg->peer.ip));
     }
 
   /*
@@ -518,7 +522,8 @@ spacer_update_bucket (spacer_t * pacer, u32 bytes)
 static inline void
 spacer_update_max_burst_size (spacer_t * pacer, u32 max_burst_bytes)
 {
-  pacer->max_burst_size = clib_max (max_burst_bytes, TRANSPORT_PACER_MIN_MSS);
+  pacer->max_burst_size = clib_max (max_burst_bytes,
+                                   TRANSPORT_PACER_MIN_BURST);
 }
 
 static inline void
@@ -561,9 +566,8 @@ void
 transport_connection_tx_pacer_update (transport_connection_t * tc,
                                      u64 bytes_per_sec)
 {
-  u32 burst_size;
-
-  burst_size = bytes_per_sec * transport_dispatch_period (tc->thread_index);
+  f64 dispatch_period = transport_dispatch_period (tc->thread_index);
+  u32 burst_size = 1.1 * bytes_per_sec * dispatch_period;
   spacer_set_pace_rate (&tc->pacer, bytes_per_sec);
   spacer_update_max_burst_size (&tc->pacer, burst_size);
 }