linux-cp: populate mapping vif-sw_if_index only for default-ns
[vpp.git] / src / vnet / l2 / l2_fib.c
index 57325af..3dcd1e7 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
 #include <vnet/ethernet/ethernet.h>
 #include <vlib/cli.h>
 
 #include <vnet/l2/l2_fib.h>
 #include <vnet/l2/l2_learn.h>
 #include <vnet/l2/l2_bd.h>
-
 #include <vppinfra/bihash_template.c>
-
 #include <vlibmemory/api.h>
-#include <vnet/vnet_msg_enum.h>
 
-#define vl_typedefs            /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
+#include <vnet/l2/l2.api_enum.h>
+#include <vnet/l2/l2.api_types.h>
 
-#define vl_endianfun           /* define message structures */
-#include <vnet/vnet_all_api_h.h>
+#define vl_endianfun
+#include <vnet/l2/l2.api.h>
 #undef vl_endianfun
 
 /**
@@ -100,8 +95,7 @@ format_vnet_sw_if_index_name_with_NA (u8 * s, va_list * args)
   if (!swif)
     return format (s, "Stale");
 
-  return format (s, "%U", format_vnet_sw_interface_name, vnm,
-                vnet_get_sw_interface_or_null (vnm, sw_if_index));
+  return format (s, "%U", format_vnet_sw_if_index_name, vnm, sw_if_index);
 }
 
 typedef struct l2fib_dump_walk_ctx_t_
@@ -147,6 +141,26 @@ l2fib_table_dump (u32 bd_index,
   *l2fe_res = ctx.l2fe_res;
 }
 
+void
+l2_fib_extract_seq_num (l2fib_seq_num_t sn, u8 * bd_sn, u8 * if_sn)
+{
+  *bd_sn = sn >> 8;
+  *if_sn = sn & 0xff;
+}
+
+u8 *
+format_l2_fib_seq_num (u8 * s, va_list * a)
+{
+  l2fib_seq_num_t sn = va_arg (*a, int);
+  u8 bd_sn, if_sn;
+
+  l2_fib_extract_seq_num (sn, &bd_sn, &if_sn);
+
+  s = format (s, "%3d/%-3d", bd_sn, if_sn);
+
+  return (s);
+}
+
 typedef struct l2fib_show_walk_ctx_t_
 {
   u8 first_entry;
@@ -193,8 +207,7 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
       if (ctx->add && !l2fib_entry_result_is_set_AGE_NOT (&result))
        return (BIHASH_WALK_CONTINUE);  /* skip learned macs */
 
-      bd_config = vec_elt_at_index (l2input_main.bd_configs,
-                                   key.fields.bd_index);
+      bd_config = &vec_elt (l2input_main.bd_configs, key.fields.bd_index);
 
       if (l2fib_entry_result_is_set_AGE_NOT (&result))
        s = format (s, "no");
@@ -208,12 +221,12 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
        }
 
       vlib_cli_output (ctx->vm,
-                      "%=19U%=7d%=7d %3d/%-3d%=9v%=7s%=7s%=5s%=30U",
+                      "%=19U%=7d%=7d %U%=9v%=7s%=7s%=5s%=30U",
                       format_ethernet_address, key.fields.mac,
                       key.fields.bd_index,
                       result.fields.sw_if_index == ~0
                       ? -1 : result.fields.sw_if_index,
-                      result.fields.sn.bd, result.fields.sn.swif, s,
+                      format_l2_fib_seq_num, result.fields.sn, s,
                       l2fib_entry_result_is_set_STATIC (&result) ? "*" : "-",
                       l2fib_entry_result_is_set_FILTER (&result) ? "*" : "-",
                       l2fib_entry_result_is_set_BVI (&result) ? "*" : "-",
@@ -285,6 +298,12 @@ show_l2fib (vlib_main_t * vm,
        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);
 
@@ -333,26 +352,43 @@ show_l2fib (vlib_main_t * vm,
  * 3 l2fib entries
  * @cliexend
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_l2fib_cli, static) = {
   .path = "show l2fib",
   .short_help = "show l2fib [all] | [bd_id <nn> | bd_index <nn>] [learn | add] | [raw]",
   .function = show_l2fib,
 };
-/* *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_clear_table (void)
 {
   l2fib_main_t *mp = &l2fib_main;
+  l2_bridge_domain_t *bd_config;
+
+  if (mp->mac_table_initialized == 0)
+    return;
+
+  mp->mac_table_initialized = 0;
 
   /* 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;
+  vec_foreach (bd_config, l2input_main.bd_configs)
+    bd_config->learn_count = 0;
 }
 
 /** Clear all entries in L2FIB.
@@ -377,24 +413,19 @@ clear_l2fib (vlib_main_t * vm,
  * no l2fib entries
  * @cliexend
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (clear_l2fib_cli, static) = {
   .path = "clear l2fib",
   .short_help = "clear l2fib",
   .function = clear_l2fib,
 };
-/* *INDENT-ON* */
 
-static inline l2fib_seq_num_t
+static l2fib_seq_num_t
 l2fib_cur_seq_num (u32 bd_index, u32 sw_if_index)
 {
   l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index);
-  /* *INDENT-OFF* */
-  return (l2fib_seq_num_t) {
-    .swif = *l2fib_swif_seq_num (sw_if_index),
-    .bd = bd_config->seq_num,
-  };
-  /* *INDENT-ON* */
+
+  return l2_fib_mk_seq_num (bd_config->seq_num,
+                           l2_input_seq_num (sw_if_index));
 }
 
 /**
@@ -412,6 +443,9 @@ l2fib_add_entry (const u8 * mac, u32 bd_index,
   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;
@@ -421,9 +455,21 @@ l2fib_add_entry (const u8 * mac, u32 bd_index,
     {
       /* decrement counter if overwriting a learned mac  */
       result.raw = kv.value;
-      if ((!l2fib_entry_result_is_set_AGE_NOT (&result))
-         && (lm->global_learn_count))
-       lm->global_learn_count--;
+      if (!l2fib_entry_result_is_set_AGE_NOT (&result))
+       {
+         l2_bridge_domain_t *bd_config =
+           vec_elt_at_index (l2input_main.bd_configs, bd_index);
+
+         /* check if learn_count == 0 in case of race condition between 2
+          * workers adding an entry simultaneously */
+         /* learn_count variable may have little inaccuracy because they are
+          * not incremented/decremented with atomic operations */
+         /* l2fib_scan is call every 2sec fixing potential inaccuracy */
+         if (lm->global_learn_count)
+           lm->global_learn_count--;
+         if (bd_config->learn_count)
+           bd_config->learn_count--;
+       }
     }
 
   /* set up result */
@@ -542,21 +588,18 @@ done:
  * 3 l2fib entries
  * @cliexend
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_add_cli, static) = {
   .path = "l2fib add",
   .short_help = "l2fib add <mac> <bridge-domain-id> filter | <intf> [static | bvi]",
   .function = l2fib_add,
 };
-/* *INDENT-ON* */
 
 
 static clib_error_t *
 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];
+  u8 mac[8], save_mac[6];
   u32 bd_index = 0;
   u32 sw_if_index = 8;
   u32 is_add = 0;
@@ -606,6 +649,9 @@ l2fib_test_command_fn (vlib_main_t * vm,
       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++)
@@ -631,7 +677,7 @@ l2fib_test_command_fn (vlib_main_t * vm,
        }
     }
 
-  return error;
+  return 0;
 }
 
 /*?
@@ -671,13 +717,11 @@ l2fib_test_command_fn (vlib_main_t * vm,
  * @cliexcmd{test l2fib del mac 52:54:00:53:00:00 count 4}
  * @endparblock
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_test_command, static) = {
   .path = "test l2fib",
   .short_help = "test l2fib [add|del|check] mac <base-addr> count <nn>",
   .function = l2fib_test_command_fn,
 };
-/* *INDENT-ON* */
 
 
 /**
@@ -692,6 +736,9 @@ l2fib_del_entry (const u8 * mac, u32 bd_index, u32 sw_if_index)
   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);
 
@@ -705,9 +752,15 @@ l2fib_del_entry (const u8 * mac, u32 bd_index, u32 sw_if_index)
     return 1;
 
   /* decrement counter if dynamically learned mac */
-  if ((!l2fib_entry_result_is_set_AGE_NOT (&result)) &&
-      (l2learn_main.global_learn_count))
-    l2learn_main.global_learn_count--;
+  if (!l2fib_entry_result_is_set_AGE_NOT (&result))
+    {
+      l2_bridge_domain_t *bd_config =
+       vec_elt_at_index (l2input_main.bd_configs, bd_index);
+      if (l2learn_main.global_learn_count)
+       l2learn_main.global_learn_count--;
+      if (bd_config->learn_count)
+       bd_config->learn_count--;
+    }
 
   /* Remove entry from hash table */
   BV (clib_bihash_add_del) (&mp->mac_table, &kv, 0 /* is_add */ );
@@ -771,13 +824,41 @@ done:
  * Example of how to delete a MAC Address entry from the L2 FIB table of a bridge-domain (where 200 is the bridge-domain-id):
  * @cliexcmd{l2fib del 52:54:00:53:18:33 200}
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_del_cli, static) = {
   .path = "l2fib del",
   .short_help = "l2fib del <mac> <bridge-domain-id> []",
   .function = l2fib_del,
 };
-/* *INDENT-ON* */
+
+static clib_error_t *
+l2fib_set_scan_delay (vlib_main_t *vm, unformat_input_t *input,
+                     vlib_cli_command_t *cmd)
+{
+  clib_error_t *error = 0;
+  u32 scan_delay;
+  l2fib_main_t *fm = &l2fib_main;
+
+  if (!unformat (input, "%d", &scan_delay))
+    {
+      error = clib_error_return (0, "expecting delay but got `%U'",
+                                format_unformat_error, input);
+      goto done;
+    }
+  fm->event_scan_delay = (f64) (scan_delay) *10e-3;
+  l2fib_flush_all_mac (vlib_get_main ());
+done:
+  return error;
+}
+
+/*?
+ * This command set scan delay (in 1/10s unit)
+ *
+?*/
+VLIB_CLI_COMMAND (l2fib_set_scan_delay_cli, static) = {
+  .path = "set l2fib scan-delay",
+  .short_help = "set l2fib scan-delay <delay>",
+  .function = l2fib_set_scan_delay,
+};
 
 /**
     Kick off ager to scan MACs to age/delete MAC entries
@@ -808,7 +889,7 @@ l2fib_start_ager_scan (vlib_main_t * vm)
 void
 l2fib_flush_int_mac (vlib_main_t * vm, u32 sw_if_index)
 {
-  *l2fib_swif_seq_num (sw_if_index) += 1;
+  l2_input_seq_num_inc (sw_if_index);
   l2fib_start_ager_scan (vm);
 }
 
@@ -885,13 +966,11 @@ l2fib_flush_mac_all (vlib_main_t * vm,
  * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table:
  * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0}
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_flush_mac_all_cli, static) = {
   .path = "l2fib flush-mac all",
   .short_help = "l2fib flush-mac all",
   .function = l2fib_flush_mac_all,
 };
-/* *INDENT-ON* */
 
 /*?
  * This command kick off ager to delete all existing MAC Address entries,
@@ -901,13 +980,11 @@ VLIB_CLI_COMMAND (l2fib_flush_mac_all_cli, static) = {
  * Example of how to flush MAC Address entries learned on an interface from the L2 FIB table:
  * @cliexcmd{l2fib flush-mac interface GigabitEthernet2/1/0}
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_flush_mac_int_cli, static) = {
   .path = "l2fib flush-mac interface",
   .short_help = "l2fib flush-mac interface <if-name>",
   .function = l2fib_flush_mac_int,
 };
-/* *INDENT-ON* */
 
 /**
     Flush bridge-domain MACs except static ones.
@@ -950,19 +1027,18 @@ done:
  * Example of how to flush MAC Address entries learned in a bridge domain from the L2 FIB table:
  * @cliexcmd{l2fib flush-mac bridge-domain 1000}
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (l2fib_flush_mac_bd_cli, static) = {
   .path = "l2fib flush-mac bridge-domain",
   .short_help = "l2fib flush-mac bridge-domain <bd-id>",
   .function = l2fib_flush_mac_bd,
 };
-/* *INDENT-ON* */
 
 clib_error_t *
 l2fib_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
 {
   l2_input_config_t *config = l2input_intf_config (sw_if_index);
-  if ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0 && config->bridge)
+  if ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0 &&
+      l2_input_is_bridge (config))
     l2fib_flush_int_mac (vnm->vlib_main, sw_if_index);
   return 0;
 }
@@ -981,7 +1057,7 @@ allocate_mac_evt_buf (u32 client, u32 client_index)
   l2fib_main_t *fm = &l2fib_main;
   vl_api_l2_macs_event_t *mp = vl_msg_api_alloc
     (sizeof (*mp) + (fm->max_macs_in_event * sizeof (vl_api_mac_entry_t)));
-  mp->_vl_msg_id = htons (VL_API_L2_MACS_EVENT);
+  mp->_vl_msg_id = htons (l2input_main.msg_id_base + VL_API_L2_MACS_EVENT);
   mp->pid = htonl (client);
   mp->client_index = client_index;
   return mp;
@@ -1004,11 +1080,16 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
   u32 cl_idx = lm->client_index;
   vl_api_l2_macs_event_t *mp = 0;
   vl_api_registration_t *reg = 0;
+  u32 bd_index;
+  static u32 *bd_learn_counts = 0;
 
   /* Don't scan the l2 fib if it hasn't been instantiated yet */
   if (alloc_arena (h) == 0)
     return 0.0;
 
+  vec_reset_length (bd_learn_counts);
+  vec_validate (bd_learn_counts, vec_len (l2input_main.bd_configs) - 1);
+
   if (client)
     {
       mp = allocate_mac_evt_buf (client, cl_idx);
@@ -1022,39 +1103,46 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
       if (delta_t > 20e-6)
        {
          vlib_process_suspend (vm, 100e-6);    /* suspend for 100 us */
+         /* in case a new bd was created while sleeping */
+         vec_validate (bd_learn_counts,
+                       vec_len (l2input_main.bd_configs) - 1);
          last_start = vlib_time_now (vm);
          accum_t += delta_t;
        }
 
       if (i < (h->nbuckets - 3))
        {
-         BVT (clib_bihash_bucket) * b = &h->buckets[i + 3];
-         CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
-         b = &h->buckets[i + 1];
-         if (b->offset)
+         BVT (clib_bihash_bucket) * b =
+           BV (clib_bihash_get_bucket) (h, i + 3);
+         clib_prefetch_load (b);
+         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);
-             CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, LOAD);
+             clib_prefetch_load (v);
            }
        }
 
-      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++)
        {
          for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
            {
-             if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL)
+             if (BV (clib_bihash_is_free) (&v->kvp[k]))
                continue;
 
              l2fib_entry_key_t key = {.raw = v->kvp[k].key };
              l2fib_entry_result_t result = {.raw = v->kvp[k].value };
 
              if (!l2fib_entry_result_is_set_AGE_NOT (&result))
-               learn_count++;
+               {
+                 learn_count++;
+                 vec_elt (bd_learn_counts, key.fields.bd_index)++;
+               }
 
              if (client)
                {
@@ -1084,7 +1172,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 */
@@ -1105,8 +1196,8 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
              /* start aging processing */
              u32 bd_index = key.fields.bd_index;
              u32 sw_if_index = result.fields.sw_if_index;
-             u16 sn = l2fib_cur_seq_num (bd_index, sw_if_index).as_u16;
-             if (result.fields.sn.as_u16 != sn)
+             u16 sn = l2fib_cur_seq_num (bd_index, sw_if_index);
+             if (result.fields.sn != sn)
                goto age_out;   /* stale mac */
 
              l2_bridge_domain_t *bd_config =
@@ -1127,7 +1218,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++;
@@ -1137,11 +1230,12 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
              kv.key = key.raw;
              BV (clib_bihash_add_del) (&fm->mac_table, &kv, 0);
              learn_count--;
+             vec_elt (bd_learn_counts, key.fields.bd_index)--;
              /*
               * 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++;
@@ -1152,6 +1246,11 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
 
   /* keep learn count consistent */
   l2learn_main.global_learn_count = learn_count;
+  vec_foreach_index (bd_index, l2input_main.bd_configs)
+    {
+      vec_elt (l2input_main.bd_configs, bd_index).learn_count =
+       vec_elt (bd_learn_counts, bd_index);
+    }
 
   if (mp)
     {
@@ -1250,13 +1349,11 @@ l2fib_mac_age_scanner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (l2fib_mac_age_scanner_process_node) = {
     .function = l2fib_mac_age_scanner_process,
     .type = VLIB_NODE_TYPE_PROCESS,
     .name = "l2fib-mac-age-scanner-process",
 };
-/* *INDENT-ON* */
 
 clib_error_t *
 l2fib_init (vlib_main_t * vm)
@@ -1267,10 +1364,11 @@ l2fib_init (vlib_main_t * vm)
 
   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));
@@ -1285,6 +1383,39 @@ l2fib_init (vlib_main_t * vm)
 
 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
  *