session: api to add new transport types
[vpp.git] / src / vnet / bonding / bond_api.c
index 691697c..525f058 100644 (file)
@@ -23,6 +23,7 @@
 #include <vnet/interface.h>
 #include <vnet/api_errno.h>
 #include <vnet/ethernet/ethernet.h>
+#include <vnet/ethernet/ethernet_types_api.h>
 
 #include <vnet/vnet_msg_enum.h>
 
 _(BOND_CREATE, bond_create)                      \
 _(BOND_DELETE, bond_delete)                      \
 _(BOND_ENSLAVE, bond_enslave)                    \
+_(SW_INTERFACE_SET_BOND_WEIGHT, sw_interface_set_bond_weight) \
 _(BOND_DETACH_SLAVE, bond_detach_slave)          \
 _(SW_INTERFACE_BOND_DUMP, sw_interface_bond_dump)\
 _(SW_INTERFACE_SLAVE_DUMP, sw_interface_slave_dump)
 
-static void
-bond_send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                     unix_shared_memory_queue_t * q,
-                                     u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = ntohl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
 static void
 vl_api_bond_delete_t_handler (vl_api_bond_delete_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   int rv;
-  vpe_api_main_t *vam = &vpe_api_main;
   vl_api_bond_delete_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   u32 sw_if_index = ntohl (mp->sw_if_index);
 
   rv = bond_delete_if (vm, sw_if_index);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_DELETE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (rv);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
-
-  if (!rv)
-    bond_send_sw_interface_event_deleted (vam, q, sw_if_index);
+  REPLY_MACRO (VL_API_BOND_DELETE_REPLY);
 }
 
 static void
@@ -101,34 +71,31 @@ vl_api_bond_create_t_handler (vl_api_bond_create_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_create_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_create_if_args_t _a, *ap = &_a;
 
   clib_memset (ap, 0, sizeof (*ap));
 
+  ap->id = ntohl (mp->id);
+
   if (mp->use_custom_mac)
     {
-      clib_memcpy (ap->hw_addr, mp->mac_address, 6);
+      mac_address_decode (mp->mac_address, (mac_address_t *) ap->hw_addr);
       ap->hw_addr_set = 1;
     }
 
-  ap->mode = mp->mode;
-  ap->lb = mp->lb;
+  ap->mode = ntohl (mp->mode);
+  ap->lb = ntohl (mp->lb);
+  ap->numa_only = mp->numa_only;
   bond_create_if (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  if (ap->rv != 0)
-    return;
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_CREATE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (ap->rv);
-  rmp->sw_if_index = ntohl (ap->sw_if_index);
+  int rv = ap->rv;
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  /* *INDENT-OFF* */
+  REPLY_MACRO2(VL_API_BOND_CREATE_REPLY,
+  ({
+    rmp->sw_if_index = ntohl (ap->sw_if_index);
+  }));
+  /* *INDENT-ON* */
 }
 
 static void
@@ -136,8 +103,8 @@ vl_api_bond_enslave_t_handler (vl_api_bond_enslave_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_enslave_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_enslave_args_t _a, *ap = &_a;
+  int rv = 0;
 
   clib_memset (ap, 0, sizeof (*ap));
 
@@ -148,16 +115,26 @@ vl_api_bond_enslave_t_handler (vl_api_bond_enslave_t * mp)
 
   bond_enslave (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
+  REPLY_MACRO (VL_API_BOND_ENSLAVE_REPLY);
+}
+
+static void
+  vl_api_sw_interface_set_bond_weight_t_handler
+  (vl_api_sw_interface_set_bond_weight_t * mp)
+{
+  vlib_main_t *vm = vlib_get_main ();
+  bond_set_intf_weight_args_t _a, *ap = &_a;
+  vl_api_sw_interface_set_bond_weight_reply_t *rmp;
+  int rv = 0;
+
+  clib_memset (ap, 0, sizeof (*ap));
+
+  ap->sw_if_index = ntohl (mp->sw_if_index);
+  ap->weight = ntohl (mp->weight);
 
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_ENSLAVE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (ap->rv);
+  bond_set_intf_weight (vm, ap);
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  REPLY_MACRO (VL_API_SW_INTERFACE_SET_BOND_WEIGHT_REPLY);
 }
 
 static void
@@ -165,24 +142,15 @@ vl_api_bond_detach_slave_t_handler (vl_api_bond_detach_slave_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_detach_slave_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_detach_slave_args_t _a, *ap = &_a;
+  int rv = 0;
 
   clib_memset (ap, 0, sizeof (*ap));
 
   ap->slave = ntohl (mp->sw_if_index);
   bond_detach_slave (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_DETACH_SLAVE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = htonl (ap->rv);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  REPLY_MACRO (VL_API_BOND_DETACH_SLAVE_REPLY);
 }
 
 static void
@@ -197,11 +165,13 @@ bond_send_sw_interface_details (vpe_api_main_t * am,
   clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_BOND_DETAILS);
   mp->sw_if_index = htonl (bond_if->sw_if_index);
+  mp->id = htonl (bond_if->id);
   clib_memcpy (mp->interface_name, bond_if->interface_name,
               MIN (ARRAY_LEN (mp->interface_name) - 1,
                    strlen ((const char *) bond_if->interface_name)));
-  mp->mode = bond_if->mode;
-  mp->lb = bond_if->lb;
+  mp->mode = htonl (bond_if->mode);
+  mp->lb = htonl (bond_if->lb);
+  mp->numa_only = bond_if->numa_only;
   mp->active_slaves = htonl (bond_if->active_slaves);
   mp->slaves = htonl (bond_if->slaves);
 
@@ -251,6 +221,8 @@ bond_send_sw_interface_slave_details (vpe_api_main_t * am,
                    strlen ((const char *) slave_if->interface_name)));
   mp->is_passive = slave_if->is_passive;
   mp->is_long_timeout = slave_if->is_long_timeout;
+  mp->is_local_numa = slave_if->is_local_numa;
+  mp->weight = htonl (slave_if->weight);
 
   mp->context = context;
   vl_api_send_msg (reg, (u8 *) mp);
@@ -297,7 +269,7 @@ bond_setup_message_id_table (api_main_t * am)
 static clib_error_t *
 bond_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
 #define _(N,n)                                                  \
     vl_msg_api_set_handlers(VL_API_##N, #n,                     \