vppinfra: bihash improvements
[vpp.git] / src / vnet / l2 / l2_fib.c
index 3e71f77..983e021 100644 (file)
@@ -414,6 +414,7 @@ l2fib_add_entry (const u8 * mac, u32 bd_index,
 
   /* set up key */
   key.raw = l2fib_make_key (mac, bd_index);
+  kv.key = key.raw;
 
   /* check if entry already exist */
   if (BV (clib_bihash_search) (&fm->mac_table, &kv, &kv))
@@ -433,7 +434,6 @@ l2fib_add_entry (const u8 * mac, u32 bd_index,
   /* no aging for provisioned entry */
   l2fib_entry_result_set_AGE_NOT (&result);
 
-  kv.key = key.raw;
   kv.value = result.raw;
 
   BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1 /* is_add */ );
@@ -1028,10 +1028,11 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
 
       if (i < (h->nbuckets - 3))
        {
-         BVT (clib_bihash_bucket) * b = &h->buckets[i + 3];
+         BVT (clib_bihash_bucket) * b =
+           BV (clib_bihash_get_bucket) (h, i + 3);
          CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
-         b = &h->buckets[i + 1];
-         if (b->offset)
+         b = BV (clib_bihash_get_bucket) (h, i + 1);
+         if (!BV (clib_bihash_bucket_is_empty) (b))
            {
              BVT (clib_bihash_value) * v =
                BV (clib_bihash_get_value) (h, b->offset);
@@ -1039,8 +1040,8 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
            }
        }
 
-      BVT (clib_bihash_bucket) * b = &h->buckets[i];
-      if (b->offset == 0)
+      BVT (clib_bihash_bucket) * b = BV (clib_bihash_get_bucket) (h, i);
+      if (BV (clib_bihash_bucket_is_empty) (b))
        continue;
       BVT (clib_bihash_value) * v = BV (clib_bihash_get_value) (h, b->offset);
       for (j = 0; j < (1 << b->log2_pages); j++)
@@ -1084,7 +1085,10 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
                                        key.fields.mac, 6);
                      mp->mac[evt_idx].action =
                        l2fib_entry_result_is_set_LRN_MOV (&result) ?
-                       MAC_EVENT_ACTION_MOVE : MAC_EVENT_ACTION_ADD;
+                       (vl_api_mac_event_action_t) MAC_EVENT_ACTION_MOVE
+                       : (vl_api_mac_event_action_t) MAC_EVENT_ACTION_ADD;
+                     mp->mac[evt_idx].action =
+                       htonl (mp->mac[evt_idx].action);
                      mp->mac[evt_idx].sw_if_index =
                        htonl (result.fields.sw_if_index);
                      /* clear event bits and update mac entry */
@@ -1127,7 +1131,9 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
                  /* copy mac entry to event msg */
                  clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac,
                                    6);
-                 mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE;
+                 mp->mac[evt_idx].action =
+                   (vl_api_mac_event_action_t) MAC_EVENT_ACTION_DELETE;
+                 mp->mac[evt_idx].action = htonl (mp->mac[evt_idx].action);
                  mp->mac[evt_idx].sw_if_index =
                    htonl (result.fields.sw_if_index);
                  evt_idx++;
@@ -1141,7 +1147,7 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
               * Note: we may have just freed the bucket's backing
               * storage, so check right here...
               */
-             if (b->offset == 0)
+             if (BV (clib_bihash_bucket_is_empty) (b))
                goto doublebreak;
            }
          v++;