vppinfra: improve clocks_per_second convergence
[vpp.git] / src / vnet / bfd / bfd_main.c
index 0cc7d72..a9a6d05 100644 (file)
@@ -60,7 +60,7 @@ bfd_usec_to_clocks (const bfd_main_t * bm, u64 us)
 u32
 bfd_clocks_to_usec (const bfd_main_t * bm, u64 clocks)
 {
-  return (clocks / bm->cpu_cps) * USEC_PER_SECOND;
+  return ((f64) clocks / bm->cpu_cps) * USEC_PER_SECOND;
 }
 
 static vlib_node_registration_t bfd_process_node;
@@ -1054,6 +1054,19 @@ bfd_check_rx_timeout (bfd_main_t * bm, bfd_session_t * bs, u64 now,
       now + bm->wheel_inaccuracy)
     {
       BFD_DBG ("Rx timeout, session goes down");
+      /*
+       * RFC 5880 6.8.1. State Variables
+
+       * bfd.RemoteDiscr
+
+       * The remote discriminator for this BFD session.  This is the
+       * discriminator chosen by the remote system, and is totally opaque
+       * to the local system.  This MUST be initialized to zero.  If a
+       * period of a Detection Time passes without the receipt of a valid,
+       * authenticated BFD packet from the remote system, this variable
+       * MUST be set to zero.
+       */
+      bs->remote_discr = 0;
       bfd_set_diag (bs, BFD_DIAG_CODE_det_time_exp);
       bfd_set_state (bm, bs, BFD_STATE_down, handling_wakeup);
       /*
@@ -1314,7 +1327,7 @@ bfd_main_init (vlib_main_t * vm)
   bm->vlib_main = vm;
   bm->vnet_main = vnet_get_main ();
   clib_memset (&bm->wheel, 0, sizeof (bm->wheel));
-  bm->cpu_cps = vm->clib_time.clocks_per_second;
+  bm->cpu_cps = (u64) vm->clib_time.clocks_per_second;
   BFD_DBG ("cps is %.2f", bm->cpu_cps);
   bm->default_desired_min_tx_clocks =
     bfd_usec_to_clocks (bm, BFD_DEFAULT_DESIRED_MIN_TX_USEC);