#include <vlib/vlib.h>
#include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
#include <vlib/cli.h>
break;
}
+ if (msm->mac_table_initialized == 0)
+ {
+ vlib_cli_output (vm, "no l2fib entries");
+ return 0;
+ }
+
BV (clib_bihash_foreach_key_value_pair)
(&msm->mac_table, l2fib_show_walk_cb, &ctx);
};
/* *INDENT-ON* */
+void
+l2fib_table_init (void)
+{
+ l2fib_main_t *mp = &l2fib_main;
+
+ if (mp->mac_table_initialized == 1)
+ return;
+
+ BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table",
+ mp->mac_table_n_buckets, mp->mac_table_memory_size);
+ mp->mac_table_initialized = 1;
+}
/* Remove all entries from the l2fib */
void
{
l2fib_main_t *mp = &l2fib_main;
+ if (mp->mac_table_initialized == 0)
+ return;
+
/* Remove all entries */
BV (clib_bihash_free) (&mp->mac_table);
- BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table",
- L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE);
+ l2fib_table_init ();
l2learn_main.global_learn_count = 0;
}
l2learn_main_t *lm = &l2learn_main;
BVT (clib_bihash_kv) kv;
+ if (fm->mac_table_initialized == 0)
+ l2fib_table_init ();
+
/* 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))
/* 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 */ );
l2fib_test_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
- clib_error_t *error = 0;
u8 mac[6], save_mac[6];
u32 bd_index = 0;
u32 sw_if_index = 8;
BVT (clib_bihash_kv) kv;
l2fib_main_t *mp = &l2fib_main;
+ if (mp->mac_table_initialized == 0)
+ return clib_error_return (0, "mac table is not initialized");
+
clib_memcpy_fast (mac, save_mac, 6);
for (i = 0; i < count; i++)
}
}
- return error;
+ return 0;
}
/*?
l2fib_main_t *mp = &l2fib_main;
BVT (clib_bihash_kv) kv;
+ if (mp->mac_table_initialized == 0)
+ return 1;
+
/* set up key */
kv.key = l2fib_make_key (mac, bd_index);
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);
}
}
- 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++)
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 */
/* 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++;
* 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++;
mp->vlib_main = vm;
mp->vnet_main = vnet_get_main ();
-
- /* Create the hash table */
- BV (clib_bihash_init) (&mp->mac_table, "l2fib mac table",
- L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE);
+ if (mp->mac_table_n_buckets == 0)
+ mp->mac_table_n_buckets = L2FIB_NUM_BUCKETS;
+ if (mp->mac_table_memory_size == 0)
+ mp->mac_table_memory_size = L2FIB_MEMORY_SIZE;
+ mp->mac_table_initialized = 0;
/* verify the key constructor is good, since it is endian-sensitive */
clib_memset (test_mac, 0, sizeof (test_mac));
VLIB_INIT_FUNCTION (l2fib_init);
+static clib_error_t *
+lfib_config (vlib_main_t * vm, unformat_input_t * input)
+{
+ l2fib_main_t *lm = &l2fib_main;
+ uword table_size = ~0;
+ u32 n_buckets = ~0;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "table-size %U", unformat_memory_size,
+ &table_size))
+ ;
+ else if (unformat (input, "num-buckets %u", &n_buckets))
+ ;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
+
+ if (n_buckets != ~0)
+ {
+ if (!is_pow2 (n_buckets))
+ return clib_error_return (0, "num-buckets must be power of 2");
+ lm->mac_table_n_buckets = n_buckets;
+ }
+
+ if (table_size != ~0)
+ lm->mac_table_memory_size = table_size;
+ return 0;
+}
+
+VLIB_CONFIG_FUNCTION (lfib_config, "l2fib");
+
/*
* fd.io coding-style-patch-verification: ON
*