summaryrefslogtreecommitdiffstats
path: root/src/vat/api_format.c
diff options
context:
space:
mode:
authorSteven <sluong@cisco.com>2017-12-20 12:43:01 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2018-03-21 21:02:15 +0000
commit9cd2d7a5a4fafadb65d772c48109d55d1e19d425 (patch)
tree4a9e0665be0096ee6bfc2235388f90b276b23814 /src/vat/api_format.c
parent43ebe29b6ea1107c30311cfb3dbd8190282903d0 (diff)
bond: Add bonding driver and LACP protocol
Add bonding driver to support creation of bond interface which composes of multiple slave interfaces. The slave interfaces could be physical interfaces, or just any virtual interfaces. For example, memif interfaces. The syntax to create a bond interface is create bond mode <lacp | xor | acitve-backup | broadcast | round-robin> To enslave an interface to the bond interface, enslave interface TenGigabitEthernet6/0/0 to BondEthernet0 Please see src/plugins/lacp/lacp_doc.md for more examples and additional options. LACP is a control plane protocol which manages and monitors the status of the slave interfaces. The protocol is part of 802.3ad standard. This patch implements LACPv1. LACPv2 is not supported. To enable LACP on the bond interface, specify "mode lacp" when the bond interface is created. The syntax to enslave a slave interface is the same as other bonding modes. Change-Id: I06581d3b87635972f9f0e1ec50b67560fc13e26c Signed-off-by: Steven <sluong@cisco.com>
Diffstat (limited to 'src/vat/api_format.c')
-rw-r--r--src/vat/api_format.c477
1 files changed, 476 insertions, 1 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 97e67f9d80b..019d095c40a 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -50,7 +50,7 @@
#include <vnet/policer/police.h>
#include <vnet/mfib/mfib_types.h>
#include <vnet/dhcp/dhcp_proxy.h>
-
+#include <vnet/bonding/node.h>
#include "vat/json_format.h"
#include <inttypes.h>
@@ -1775,6 +1775,275 @@ static void vl_api_tap_delete_v2_reply_t_handler_json
vam->result_ready = 1;
}
+static void
+vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+
+ if (vam->async_mode)
+ {
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ vam->sw_if_index = ntohl (mp->sw_if_index);
+ vam->result_ready = 1;
+ }
+}
+
+static void vl_api_bond_create_reply_t_handler_json
+ (vl_api_bond_create_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t node;
+
+ vat_json_init_object (&node);
+ vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+ vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
+
+ vat_json_print (vam->ofp, &node);
+ vat_json_free (&node);
+
+ vam->retval = ntohl (mp->retval);
+ vam->result_ready = 1;
+}
+
+static void
+vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+
+ if (vam->async_mode)
+ {
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ vam->result_ready = 1;
+ }
+}
+
+static void vl_api_bond_delete_reply_t_handler_json
+ (vl_api_bond_delete_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t node;
+
+ vat_json_init_object (&node);
+ vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+
+ vat_json_print (vam->ofp, &node);
+ vat_json_free (&node);
+
+ vam->retval = ntohl (mp->retval);
+ vam->result_ready = 1;
+}
+
+static void
+vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+
+ if (vam->async_mode)
+ {
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ vam->result_ready = 1;
+ }
+}
+
+static void vl_api_bond_enslave_reply_t_handler_json
+ (vl_api_bond_enslave_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t node;
+
+ vat_json_init_object (&node);
+ vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+
+ vat_json_print (vam->ofp, &node);
+ vat_json_free (&node);
+
+ vam->retval = ntohl (mp->retval);
+ vam->result_ready = 1;
+}
+
+static void
+vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
+ mp)
+{
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+
+ if (vam->async_mode)
+ {
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ vam->result_ready = 1;
+ }
+}
+
+static void vl_api_bond_detach_slave_reply_t_handler_json
+ (vl_api_bond_detach_slave_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t node;
+
+ vat_json_init_object (&node);
+ vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+
+ vat_json_print (vam->ofp, &node);
+ vat_json_free (&node);
+
+ vam->retval = ntohl (mp->retval);
+ vam->result_ready = 1;
+}
+
+static void vl_api_sw_interface_bond_details_t_handler
+ (vl_api_sw_interface_bond_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+
+ print (vam->ofp,
+ "%-16s %-12d %-12U %-13U %-14u %-14u",
+ mp->interface_name, ntohl (mp->sw_if_index),
+ format_bond_mode, mp->mode, format_bond_load_balance, mp->lb,
+ ntohl (mp->active_slaves), ntohl (mp->slaves));
+}
+
+static void vl_api_sw_interface_bond_details_t_handler_json
+ (vl_api_sw_interface_bond_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t *node = NULL;
+
+ if (VAT_JSON_ARRAY != vam->json_tree.type)
+ {
+ ASSERT (VAT_JSON_NONE == vam->json_tree.type);
+ vat_json_init_array (&vam->json_tree);
+ }
+ node = vat_json_array_add (&vam->json_tree);
+
+ vat_json_init_object (node);
+ vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
+ vat_json_object_add_string_copy (node, "interface_name",
+ mp->interface_name);
+ vat_json_object_add_uint (node, "mode", mp->mode);
+ vat_json_object_add_uint (node, "load_balance", mp->lb);
+ vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
+ vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
+}
+
+static int
+api_sw_interface_bond_dump (vat_main_t * vam)
+{
+ vl_api_sw_interface_bond_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+
+ print (vam->ofp,
+ "\n%-16s %-12s %-12s %-13s %-14s %-14s",
+ "interface name", "sw_if_index", "mode", "load balance",
+ "active slaves", "slaves");
+
+ /* Get list of bond interfaces */
+ M (SW_INTERFACE_BOND_DUMP, mp);
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ MPING (CONTROL_PING, mp_ping);
+ S (mp_ping);
+
+ W (ret);
+ return ret;
+}
+
+static void vl_api_sw_interface_slave_details_t_handler
+ (vl_api_sw_interface_slave_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+
+ print (vam->ofp,
+ "%-25s %-12d %-12d %d", mp->interface_name,
+ ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout);
+}
+
+static void vl_api_sw_interface_slave_details_t_handler_json
+ (vl_api_sw_interface_slave_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t *node = NULL;
+
+ if (VAT_JSON_ARRAY != vam->json_tree.type)
+ {
+ ASSERT (VAT_JSON_NONE == vam->json_tree.type);
+ vat_json_init_array (&vam->json_tree);
+ }
+ node = vat_json_array_add (&vam->json_tree);
+
+ vat_json_init_object (node);
+ vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
+ vat_json_object_add_string_copy (node, "interface_name",
+ mp->interface_name);
+ vat_json_object_add_uint (node, "passive", mp->is_passive);
+ vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
+}
+
+static int
+api_sw_interface_slave_dump (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_sw_interface_slave_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ u32 sw_if_index = ~0;
+ u8 sw_if_index_set = 0;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
+ sw_if_index_set = 1;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else
+ break;
+ }
+
+ if (sw_if_index_set == 0)
+ {
+ errmsg ("missing vpp interface name. ");
+ return -99;
+ }
+
+ print (vam->ofp,
+ "\n%-25s %-12s %-12s %s",
+ "slave interface name", "sw_if_index", "passive", "long_timeout");
+
+ /* Get list of bond interfaces */
+ M (SW_INTERFACE_SLAVE_DUMP, mp);
+ mp->sw_if_index = ntohl (sw_if_index);
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ MPING (CONTROL_PING, mp_ping);
+ S (mp_ping);
+
+ W (ret);
+ return ret;
+}
+
static void vl_api_mpls_tunnel_add_del_reply_t_handler
(vl_api_mpls_tunnel_add_del_reply_t * mp)
{
@@ -5466,6 +5735,12 @@ _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
+_(BOND_CREATE_REPLY, bond_create_reply) \
+_(BOND_DELETE_REPLY, bond_delete_reply) \
+_(BOND_ENSLAVE_REPLY, bond_enslave_reply) \
+_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply) \
+_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
+_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
@@ -7954,6 +8229,194 @@ api_tap_delete_v2 (vat_main_t * vam)
}
static int
+api_bond_create (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bond_create_t *mp;
+ u8 mac_address[6];
+ u8 custom_mac = 0;
+ int ret;
+ u8 mode;
+ u8 lb;
+ u8 mode_is_set = 0;
+
+ memset (mac_address, 0, sizeof (mac_address));
+ lb = BOND_LB_L2;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "mode %U", unformat_bond_mode, &mode))
+ mode_is_set = 1;
+ else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
+ && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
+ ;
+ else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
+ mac_address))
+ custom_mac = 1;
+ else
+ break;
+ }
+
+ if (mode_is_set == 0)
+ {
+ errmsg ("Missing bond mode. ");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (BOND_CREATE, mp);
+
+ mp->use_custom_mac = custom_mac;
+
+ mp->mode = mode;
+ mp->lb = lb;
+
+ if (custom_mac)
+ clib_memcpy (mp->mac_address, mac_address, 6);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static int
+api_bond_delete (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bond_delete_t *mp;
+ u32 sw_if_index = ~0;
+ u8 sw_if_index_set = 0;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
+ sw_if_index_set = 1;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else
+ break;
+ }
+
+ if (sw_if_index_set == 0)
+ {
+ errmsg ("missing vpp interface name. ");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (BOND_DELETE, mp);
+
+ mp->sw_if_index = ntohl (sw_if_index);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static int
+api_bond_enslave (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bond_enslave_t *mp;
+ u32 bond_sw_if_index;
+ int ret;
+ u8 is_passive;
+ u8 is_long_timeout;
+ u32 bond_sw_if_index_is_set = 0;
+ u32 sw_if_index;
+ u8 sw_if_index_is_set = 0;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_is_set = 1;
+ else if (unformat (i, "bond %u", &bond_sw_if_index))
+ bond_sw_if_index_is_set = 1;
+ else if (unformat (i, "passive %d", &is_passive))
+ ;
+ else if (unformat (i, "long-timeout %d", &is_long_timeout))
+ ;
+ else
+ break;
+ }
+
+ if (bond_sw_if_index_is_set == 0)
+ {
+ errmsg ("Missing bond sw_if_index. ");
+ return -99;
+ }
+ if (sw_if_index_is_set == 0)
+ {
+ errmsg ("Missing slave sw_if_index. ");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (BOND_ENSLAVE, mp);
+
+ mp->bond_sw_if_index = ntohl (bond_sw_if_index);
+ mp->sw_if_index = ntohl (sw_if_index);
+ mp->is_long_timeout = is_long_timeout;
+ mp->is_passive = is_passive;
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static int
+api_bond_detach_slave (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_bond_detach_slave_t *mp;
+ u32 sw_if_index = ~0;
+ u8 sw_if_index_set = 0;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
+ sw_if_index_set = 1;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else
+ break;
+ }
+
+ if (sw_if_index_set == 0)
+ {
+ errmsg ("missing vpp interface name. ");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (BOND_DETACH_SLAVE, mp);
+
+ mp->sw_if_index = ntohl (sw_if_index);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static int
api_ip_table_add_del (vat_main_t * vam)
{
unformat_input_t *i = vam->input;
@@ -22782,6 +23245,18 @@ _(tap_create_v2, \
_(tap_delete_v2, \
"<vpp-if-name> | sw_if_index <id>") \
_(sw_interface_tap_v2_dump, "") \
+_(bond_create, \
+ "[hw-addr <mac-addr>] {round-robin | active-backup | " \
+ "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]}") \
+_(bond_delete, \
+ "<vpp-if-name> | sw_if_index <id>") \
+_(bond_enslave, \
+ "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
+_(bond_detach_slave, \
+ "sw_if_index <n>") \
+_(sw_interface_bond_dump, "") \
+_(sw_interface_slave_dump, \
+ "<vpp-if-name> | sw_if_index <id>") \
_(ip_table_add_del, \
"table-id <n> [ipv6]\n") \
_(ip_add_del_route, \