+/**
+ Kick off ager to scan MACs to age/delete MAC entries
+*/
+void
+l2fib_start_ager_scan (vlib_main_t * vm)
+{
+ uword evt = L2_MAC_AGE_PROCESS_EVENT_ONE_PASS;
+
+ /* check if there is at least one bd with mac aging enabled */
+ l2_bridge_domain_t *bd_config;
+ vec_foreach (bd_config, l2input_main.bd_configs)
+ {
+ if (bd_config->bd_id != ~0 && bd_config->mac_age != 0)
+ {
+ evt = L2_MAC_AGE_PROCESS_EVENT_START;
+ break;
+ }
+ }
+
+ vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index,
+ evt, 0);
+}
+
+/**
+ Flush all non static MACs from an interface
+*/
+void
+l2fib_flush_int_mac (vlib_main_t * vm, u32 sw_if_index)
+{
+ *l2fib_swif_seq_num (sw_if_index) += 1;
+ l2fib_start_ager_scan (vm);
+}
+
+/**
+ Flush all non static MACs in a bridge domain
+*/
+void
+l2fib_flush_bd_mac (vlib_main_t * vm, u32 bd_index)
+{
+ l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index);
+ bd_config->seq_num += 1;
+ l2fib_start_ager_scan (vm);
+}
+
+/**
+ Flush all non static MACs - flushes all valid BDs
+*/
+void
+l2fib_flush_all_mac (vlib_main_t * vm)
+{
+ l2_bridge_domain_t *bd_config;
+ vec_foreach (bd_config, l2input_main.bd_configs)
+ if (bd_is_valid (bd_config))
+ bd_config->seq_num += 1;
+
+ l2fib_start_ager_scan (vm);
+}
+
+
+/**
+ Flush MACs, except static ones, associated with an interface
+ The CLI format is:
+ l2fib flush-mac interface <if-name>
+*/
+static clib_error_t *
+l2fib_flush_mac_int (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ clib_error_t *error = 0;
+ u32 sw_if_index;
+
+ if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+ {
+ error = clib_error_return (0, "unknown interface `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+
+ l2fib_flush_int_mac (vm, sw_if_index);
+
+done:
+ return error;
+}
+
+/**
+ Flush all MACs, except static ones
+ The CLI format is:
+ l2fib flush-mac all
+*/
+static clib_error_t *
+l2fib_flush_mac_all (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ l2fib_flush_all_mac (vm);
+ return 0;
+}
+
+/*?
+ * This command kick off ager to delete all existing MAC Address entries,
+ * except static ones, associated with an interface from the L2 FIB table.
+ *
+ * @cliexpar
+ * 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,
+ * except static ones, associated with an interface from the L2 FIB table.
+ *
+ * @cliexpar
+ * 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.
+ The CLI format is:
+ l2fib flush-mac bridge-domain <bd-id>
+*/
+static clib_error_t *
+l2fib_flush_mac_bd (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ bd_main_t *bdm = &bd_main;
+ clib_error_t *error = 0;
+ u32 bd_index, bd_id;
+ uword *p;
+
+ if (!unformat (input, "%d", &bd_id))
+ {
+ error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
+ format_unformat_error, input);
+ goto done;
+ }
+
+ p = hash_get (bdm->bd_index_by_bd_id, bd_id);
+ if (p)
+ bd_index = *p;
+ else
+ return clib_error_return (0, "No such bridge domain %d", bd_id);
+
+ l2fib_flush_bd_mac (vm, bd_index);
+
+done:
+ return error;
+}
+
+/*?
+ * This command kick off ager to delete all existing MAC Address entries,
+ * except static ones, in a bridge domain from the L2 FIB table.
+ *
+ * @cliexpar
+ * 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)
+ l2fib_flush_int_mac (vnm->vlib_main, sw_if_index);
+ return 0;
+}
+
+VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (l2fib_sw_interface_up_down);