L2FIB:CLI/API to flush all non-static entries
[vpp.git] / src / vnet / l2 / l2_api.c
index 026f170..5f371cc 100644 (file)
@@ -48,6 +48,7 @@
 _(L2_XCONNECT_DUMP, l2_xconnect_dump)                       \
 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table)                   \
 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump)                     \
+_(L2FIB_FLUSH_ALL, l2fib_flush_all)                         \
 _(L2FIB_FLUSH_INT, l2fib_flush_int)                         \
 _(L2FIB_FLUSH_BD, l2fib_flush_bd)                           \
 _(L2FIB_ADD_DEL, l2fib_add_del)                             \
@@ -106,11 +107,8 @@ vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
   int rv = 0;
   vl_api_l2_fib_clear_table_reply_t *rmp;
 
-  /* DAW-FIXME: This API should only clear non-static l2fib entries, but
-   *            that is not currently implemented.  When that TODO is fixed
-   *            this call should be changed to pass 1 instead of 0.
-   */
-  l2fib_clear_table (0);
+  /* Clear all MACs including static MACs  */
+  l2fib_clear_table ();
 
   REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
 }
@@ -258,6 +256,16 @@ vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
   REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
 }
 
+static void
+vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
+{
+  int rv = 0;
+  vl_api_l2fib_flush_all_reply_t *rmp;
+
+  l2fib_flush_all_mac (vlib_get_main ());
+  REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
+}
+
 static void
 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
 {
@@ -310,7 +318,15 @@ vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
   vl_api_bridge_domain_set_mac_age_reply_t *rmp;
   int rv = 0;
   u32 bd_id = ntohl (mp->bd_id);
-  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
+  uword *p;
+
+  if (bd_id == 0)
+    {
+      rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
+      goto out;
+    }
+
+  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
   if (p == 0)
     {
       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
@@ -324,54 +340,20 @@ out:
 static void
 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
 {
-  vlib_main_t *vm = vlib_get_main ();
-  bd_main_t *bdm = &bd_main;
-  vl_api_bridge_domain_add_del_reply_t *rmp;
-  int rv = 0;
-  u32 enable_flags = 0, disable_flags = 0;
-  u32 bd_id = ntohl (mp->bd_id);
-  u32 bd_index;
-
-  if (mp->is_add)
-    {
-      bd_index = bd_find_or_add_bd_index (bdm, bd_id);
-
-      if (mp->flood)
-       enable_flags |= L2_FLOOD;
-      else
-       disable_flags |= L2_FLOOD;
-
-      if (mp->uu_flood)
-       enable_flags |= L2_UU_FLOOD;
-      else
-       disable_flags |= L2_UU_FLOOD;
-
-      if (mp->forward)
-       enable_flags |= L2_FWD;
-      else
-       disable_flags |= L2_FWD;
-
-      if (mp->arp_term)
-       enable_flags |= L2_ARP_TERM;
-      else
-       disable_flags |= L2_ARP_TERM;
-
-      if (mp->learn)
-       enable_flags |= L2_LEARN;
-      else
-       disable_flags |= L2_LEARN;
-
-      if (enable_flags)
-       bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
-
-      if (disable_flags)
-       bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
-
-      bd_set_mac_age (vm, bd_index, mp->mac_age);
-    }
-  else
-    rv = bd_delete_bd_index (bdm, bd_id);
+  l2_bridge_domain_add_del_args_t a = {
+    .is_add = mp->is_add,
+    .flood = mp->flood,
+    .uu_flood = mp->uu_flood,
+    .forward = mp->forward,
+    .learn = mp->learn,
+    .arp_term = mp->arp_term,
+    .mac_age = mp->mac_age,
+    .bd_id = ntohl (mp->bd_id),
+  };
+
+  int rv = bd_add_del (&a);
 
+  vl_api_bridge_domain_add_del_reply_t *rmp;
   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
 }
 
@@ -435,9 +417,13 @@ vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
     return;
 
   bd_id = ntohl (mp->bd_id);
+  if (bd_id == 0)
+    return;
 
-  bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
+  bd_index = (bd_id == ~0) ? 0 : bd_find_index (bdm, bd_id);
+  ASSERT (bd_index != ~0);
   end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
+
   for (; bd_index < end; bd_index++)
     {
       bd_config = l2input_bd_config_from_index (l2im, bd_index);
@@ -470,6 +456,12 @@ vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
   u32 flags = ntohl (mp->feature_bitmap);
   uword *p;
 
+  if (bd_id == 0)
+    {
+      rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
+      goto out;
+    }
+
   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
   if (p == 0)
     {