aboutsummaryrefslogtreecommitdiffstats
path: root/src/vat/api_format.c
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2019-08-20 16:58:00 -0700
committerDamjan Marion <dmarion@me.com>2019-09-06 16:07:59 +0000
commita1876b84e5598fcfad1debe5abb51d152e06a66e (patch)
tree58e7d58a52b8b0beb85dc99c6071dab4a17f32e1 /src/vat/api_format.c
parentffbfe3a2d6aaf4e847a1848c29fc8ce2997ed260 (diff)
bonding: add weight support for active-backup mode
Not all interfaces have the same characteristics within the bonding group. For active-backup mode, we should do our best to select the slave that performs the best as the primary slave. We already did that by preferring the slave that is local numa. Sometimes, this is not enough. For example, when all are local numas, the selection is arbitrary. Some slave interfaces may have higher speed or better qos than the others. But this is hard to infer. One rule does not fit all. So we let the operator to optionally specify the weight for each slave interface. Our primary slave selection rule is now 1. biggest weight 2. is local numa 3. current primary slave (to avoid churn) 4. lowest sw_if_index (for deterministic behavior) This selection rule only applies to active-backup mode which only one slave is used for forwarding traffic until it becomes unreachable. At that time, the next "best" slave candidate is automatically promoted. The slaves are sorted according to the preference rule when they are up. So there is no need to find the next best candidate when the primary slave goes down. Another good thing about this rule is when the down slave comes back up, it is selected as the primary slave again unless there is indeed a "better" slave than this down slave that were added during that period. To set the weight for the slave interface, do this after the interface is enslaved set interface bond <interface-name> weight <value> Type: feature Signed-off-by: Steven Luong <sluong@cisco.com> Change-Id: I59ced6d20ce1dec532e667dbe1afd1b4243e04f9
Diffstat (limited to 'src/vat/api_format.c')
-rw-r--r--src/vat/api_format.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 46039371a45..416110677d3 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -1999,6 +1999,49 @@ static void vl_api_bond_detach_slave_reply_t_handler_json
vam->result_ready = 1;
}
+static int
+api_sw_interface_set_bond_weight (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_sw_interface_set_bond_weight_t *mp;
+ u32 sw_if_index = ~0;
+ u32 weight = 0;
+ u8 weight_enter = 0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
+ ;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ ;
+ else if (unformat (i, "weight %u", &weight))
+ weight_enter = 1;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ {
+ errmsg ("missing interface name or sw_if_index");
+ return -99;
+ }
+ if (weight_enter == 0)
+ {
+ errmsg ("missing valid weight");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
+ mp->sw_if_index = ntohl (sw_if_index);
+ mp->weight = ntohl (weight);
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
static void vl_api_sw_interface_bond_details_t_handler
(vl_api_sw_interface_bond_details_t * mp)
{
@@ -2064,8 +2107,9 @@ static void vl_api_sw_interface_slave_details_t_handler
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);
+ "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
+ ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
+ ntohl (mp->weight), mp->is_local_numa);
}
static void vl_api_sw_interface_slave_details_t_handler_json
@@ -2087,6 +2131,8 @@ static void vl_api_sw_interface_slave_details_t_handler_json
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);
+ vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
+ vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
}
static int
@@ -2117,8 +2163,9 @@ api_sw_interface_slave_dump (vat_main_t * vam)
}
print (vam->ofp,
- "\n%-25s %-12s %-12s %s",
- "slave interface name", "sw_if_index", "passive", "long_timeout");
+ "\n%-25s %-12s %-7s %-12s %-10s %-10s",
+ "slave interface name", "sw_if_index", "passive", "long_timeout",
+ "weight", "local numa");
/* Get list of bond interfaces */
M (SW_INTERFACE_SLAVE_DUMP, mp);
@@ -5040,6 +5087,7 @@ _(sw_interface_set_vxlan_bypass_reply) \
_(sw_interface_set_geneve_bypass_reply) \
_(sw_interface_set_vxlan_gpe_bypass_reply) \
_(sw_interface_set_l2_bridge_reply) \
+_(sw_interface_set_bond_weight_reply) \
_(bridge_domain_add_del_reply) \
_(sw_interface_set_l2_xconnect_reply) \
_(l2fib_add_del_reply) \
@@ -5242,6 +5290,7 @@ _(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_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
@@ -21724,13 +21773,14 @@ _(sw_interface_virtio_pci_dump, "") \
_(bond_create, \
"[hw-addr <mac-addr>] {round-robin | active-backup | " \
"broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
- "[id <if-id>]") \
+ "[id <if-id>]") \
_(bond_delete, \
"<vpp-if-name> | sw_if_index <id>") \
_(bond_enslave, \
- "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
+ "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
_(bond_detach_slave, \
"sw_if_index <n>") \
+ _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
_(sw_interface_bond_dump, "") \
_(sw_interface_slave_dump, \
"<vpp-if-name> | sw_if_index <id>") \