BVI Interface
[vpp.git] / src / vnet / l2 / l2_api.c
index 3f27feb..f60cd41 100644 (file)
@@ -27,6 +27,9 @@
 #include <vnet/l2/l2_vtr.h>
 #include <vnet/l2/l2_learn.h>
 #include <vnet/l2/l2_bd.h>
+#include <vnet/l2/l2_bvi.h>
+#include <vnet/ip/ip_types_api.h>
+#include <vnet/ethernet/ethernet_types_api.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -64,6 +67,7 @@ _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge)       \
 _(L2_PATCH_ADD_DEL, l2_patch_add_del)                          \
 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter)             \
 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del)                         \
+_(BD_IP_MAC_FLUSH, bd_ip_mac_flush)                             \
 _(BD_IP_MAC_DUMP, bd_ip_mac_dump)                              \
 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del)                 \
 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump)                       \
@@ -71,7 +75,9 @@ _(BRIDGE_FLAGS, bridge_flags)                                   \
 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite)   \
 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age)         \
-_(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
+_(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)               \
+_(BVI_CREATE, bvi_create)                                       \
+_(BVI_DELETE, bvi_delete)
 
 static void
 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
@@ -80,7 +86,7 @@ send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
   vl_api_l2_xconnect_details_t *mp;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
   mp->context = context;
   mp->rx_sw_if_index = htonl (rx_sw_if_index);
@@ -135,7 +141,7 @@ send_l2fib_table_entry (vpe_api_main_t * am,
   vl_api_l2_fib_table_details_t *mp;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
 
   mp->bd_id =
@@ -456,7 +462,7 @@ send_bridge_domain_details (l2input_main_t * l2im,
 
   mp = vl_msg_api_alloc (sizeof (*mp) +
                         (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
   mp->bd_id = ntohl (bd_config->bd_id);
   mp->flood = bd_feature_flood (bd_config);
@@ -556,6 +562,7 @@ vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
   vlib_main_t *vm = vlib_get_main ();
   bd_main_t *bdm = &bd_main;
   vl_api_bridge_flags_reply_t *rmp;
+  u32 bitmap = 0;
   int rv = 0;
 
   bd_flags_t flags = bd_flags_decode (mp->flags);
@@ -573,7 +580,7 @@ vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
       goto out;
     }
 
-  u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
+  bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
 
 out:
   /* *INDENT-OFF* */
@@ -688,6 +695,16 @@ static void
                            L2_BD_PORT_TYPE_NORMAL, 0, 0);
     }
 
+  switch (rv)
+    {
+    case MODE_ERROR_ETH:
+      rv = VNET_API_ERROR_NON_ETHERNET;
+      break;
+    case MODE_ERROR_BVI_DEF:
+      rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
+      break;
+    }
+
   BAD_RX_SW_IF_INDEX_LABEL;
   BAD_TX_SW_IF_INDEX_LABEL;
 
@@ -746,6 +763,16 @@ static void
       rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
     }
 
+  switch (rv)
+    {
+    case MODE_ERROR_ETH:
+      rv = VNET_API_ERROR_NON_ETHERNET;
+      break;
+    case MODE_ERROR_BVI_DEF:
+      rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
+      break;
+    }
+
   BAD_RX_SW_IF_INDEX_LABEL;
   BAD_BD_ID_LABEL;
 out:
@@ -761,7 +788,7 @@ send_bd_ip_mac_entry (vpe_api_main_t * am,
   vl_api_bd_ip_mac_details_t *mp;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
 
   mp->bd_id = ntohl (bd_id);
@@ -835,13 +862,17 @@ vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
 static void
 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
 {
-  bd_main_t *bdm = &bd_main;
+  ip46_address_t ip_addr = ip46_address_initializer;
   vl_api_bd_ip_mac_add_del_reply_t *rmp;
+  bd_main_t *bdm = &bd_main;
+  u32 bd_index, bd_id;
+  mac_address_t mac;
+  ip46_type_t type;
   int rv = 0;
-  u32 bd_id = ntohl (mp->bd_id);
-  u32 bd_index;
   uword *p;
 
+  bd_id = ntohl (mp->bd_id);
+
   if (bd_id == 0)
     {
       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
@@ -854,16 +885,49 @@ vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
       goto out;
     }
-
   bd_index = p[0];
-  if (bd_add_del_ip_mac (bd_index, mp->ip_address,
-                        mp->mac_address, mp->is_ipv6, mp->is_add))
+
+  type = ip_address_decode (&mp->ip, &ip_addr);
+  mac_address_decode (mp->mac, &mac);
+
+  if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
     rv = VNET_API_ERROR_UNSPECIFIED;
 
 out:
   REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
 }
 
+static void
+vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp)
+{
+  vl_api_bd_ip_mac_flush_reply_t *rmp;
+  bd_main_t *bdm = &bd_main;
+  u32 bd_index, bd_id;
+  int rv = 0;
+  uword *p;
+
+  bd_id = ntohl (mp->bd_id);
+
+  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;
+      goto out;
+    }
+  bd_index = p[0];
+
+  bd_flush_ip_mac (bd_index);
+
+out:
+  REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
+}
+
 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
                                     u32 sw_if_index, u8 enable);
 
@@ -932,6 +996,37 @@ vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
   REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
 }
 
+static void
+vl_api_bvi_create_t_handler (vl_api_bvi_create_t * mp)
+{
+  vl_api_bvi_create_reply_t *rmp;
+  mac_address_t mac;
+  u32 sw_if_index;
+  int rv;
+
+  mac_address_decode (mp->mac, &mac);
+
+  rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index);
+
+  /* *INDENT-OFF* */
+  REPLY_MACRO2(VL_API_BVI_CREATE_REPLY,
+  ({
+    rmp->sw_if_index = ntohl (sw_if_index);
+  }));
+  /* *INDENT-ON* */
+}
+
+static void
+vl_api_bvi_delete_t_handler (vl_api_bvi_delete_t * mp)
+{
+  vl_api_bvi_delete_reply_t *rmp;
+  int rv;
+
+  rv = l2_bvi_delete (ntohl (mp->sw_if_index));
+
+  REPLY_MACRO (VL_API_BVI_DELETE_REPLY);
+}
+
 /*
  * l2_api_hookup
  * Add vpe's API message handlers to the table.