/* *------------------------------------------------------------------ * Copyright (c) 2017 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *------------------------------------------------------------------ */ #include #include #include #include #include void bond_disable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif) { bond_main_t *bm = &bond_main; bond_if_t *bif; int i; uword p; vnet_main_t *vnm = vnet_get_main (); vnet_hw_interface_t *hw; u8 switching_active = 0; bif = bond_get_master_by_dev_instance (sif->bif_dev_instance); clib_spinlock_lock_if_init (&bif->lockp); vec_foreach_index (i, bif->active_slaves) { p = *vec_elt_at_index (bif->active_slaves, i); if (p == sif->sw_if_index) { if (sif->sw_if_index == bif->sw_if_index_working) { switching_active = 1; if (bif->mode == BOND_MODE_ACTIVE_BACKUP) bif->is_local_numa = 0; } vec_del1 (bif->active_slaves, i); hash_unset (bif->active_slave_by_sw_if_index, sif->sw_if_index); break; } } /* We get a new slave just becoming active */ if ((bif->mode == BOND_MODE_ACTIVE_BACKUP) && switching_active) { if ((vec_len (bif->active_slaves) >= 1)) { /* scan all slaves and try to find the first slave with local numa node. */ vec_foreach_index (i, bif->active_slaves) { p = *vec_elt_at_index (bif->active_slaves, i); hw = vnet_get_sup_hw_interface (vnm, p); if (vm->numa_node == hw->numa_node) { bif->sw_if_index_working = p; bif->is_local_numa = 1; vlib_process_signal_event (bm->vlib_main, bond_process_node.index, BOND_SEND_GARP_NA, bif->hw_if_index); break; } } } /* No local numa node is found in the active slave set. Use the first slave */ if ((bif->is_local_numa == 0) && (vec_len (bif->active_slaves) >= 1)) { p = *vec_elt_at_index (bif->active_slaves, 0); bif->sw_if_index_working = p; vlib_process_signal_event (bm->vlib_main, bond_process_node.index, BOND_SEND_GARP_NA, bif->hw_if_index); } } clib_spinlock_unlock_if_init (&bif->lockp); return; } void bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif) { bond_if_t *bif; bond_main_t *bm = &bond_main; vnet_main_t *vnm = vnet_get_main (); vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index); int i; uword p; bif = bond_get_master_by_dev_instance (sif->bif_dev_instance); clib_spinlock_lock_if_init (&bif->lockp); if (!hash_get (bif->active_slave_by_sw_if_index, sif->sw_if_index)) { hash_set (bif->active_slave_by_sw_if_index, sif->sw_if_index, sif->sw_if_index); vec_add1 (bif->active_slaves, sif->sw_if_index); /* First slave becomes active? */ if ((vec_len (bif->active_slaves) == 1) && (bif->mode == BOND_MODE_ACTIVE_BACKUP)) { bif->sw_if_index_working = sif->sw_if_index; bif->is_local_numa = (vm->numa_node == hw->numa_node) ? 1 : 0; vlib_process_signal_event (bm->vlib_main, bond_process_node.index, BOND_SEND_GARP_NA, bif->hw_if_index); } else if ((vec_len (bif->active_slaves) > 1) && (bif->mode == BOND_MODE_ACTIVE_BACKUP) && bif->is_local_numa == 0) { if (vm->numa_node == hw->numa_node) { vec_foreach_index (i, bif->active_slaves) { p = *vec_elt_at_index (bif->active_slaves, 0); if (p == sif->sw_if_index) break; vec_del1 (bif->active_slaves, 0); hash_unset (bif->active_slave_by_sw_if_index, p); vec_add1 (bif->active_slaves, p); hash_set (bif->active_slave_by_sw_if_index, p, p); } bif->sw_if_index_working = sif->sw_if_index; bif->is_local_numa = 1; vlib_process_signal_event (bm->vlib_main, bond_process_node.index, BOND_SEND_GARP_NA, bif->hw_if_index); } } } clib_spinlock_unlock_if_init (&bif->lockp); return; } int bond_dump_ifs (bond_interface_details_t ** out_bondifs) { vnet_main_t *vnm = vnet_get_main (); bond_main_t *bm = &bond_main; bond_if_t *bif; vnet_hw_interface_t *hi; bond_interface_details_t *r_bondifs = NULL; bond_interface_details_t *bondif = NULL; /* *INDENT-OFF* */ pool_foreach (bif, bm->interfaces, vec_add2(r_bondifs, bondif, 1); clib_memset (bondif, 0, sizeof (*bondif)); bondif->id = bif->id; bondif->sw_if_index = bif->sw_if_index; hi = vnet_get_hw_interface (vnm, bif->hw_if_index); clib_memcpy(bondif->interface_name, hi->name, MIN (ARRAY_LEN (bondif->interface_name) - 1, strlen ((const char *) hi->name))); bondif->mode = bif->mode; bondif->lb = bif->lb; bondif->active_slaves = vec_len (bif->active_slaves); bondif->slaves = vec_len (bif->slaves); ); /* *INDENT-ON* */ *out_bondifs = r_bondifs; return 0; } int bond_dump_slave_ifs (slave_interface_details_t ** out_slaveifs, u32 bond_sw_if_index) { vnet_main_t *vnm = vnet_get_main (); bond_if_t *bif; vnet_hw_interface_t *hi; vnet_sw_interface_t *sw; slave_interface_details_t *r_slaveifs = NULL; slave_interface_details_t *slaveif = NULL; u32 *sw_if_index = NULL; slave_if_t *sif; bif = bond_get_master_by_sw_if_index (bond_sw_if_index); if (!bif) return 1; vec_foreach (sw_if_index, bif->slaves) { vec_add2 (r_slaveifs, slaveif, 1); clib_memset (slaveif, 0, sizeof (*slaveif)); sif = bond_get_slave_by_sw_if_index (*sw_if_index); if (sif) { sw = vnet_get_sw_interface (vnm, sif->sw_if_index); hi = vnet_get_hw_interface (vnm, sw->hw_if_index); clib_memcpy (slaveif->interface_name, hi->name, MIN (ARRAY_LEN (slaveif->interface_name) - 1, strlen ((const char *) hi->name))); slaveif->sw_if_index = sif->sw_if_index; slaveif->is_passive = sif->is_passive; slaveif->is_long_timeout = sif->is_long_timeout; } } *out_slaveifs = r_slaveifs; return 0; } static
/*
 *------------------------------------------------------------------
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

option version = "1.0.0";

/** \brief
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param pci_addr - pci address as unsigned 32bit integer:
		      0-15 domain, 16-23 bus, 24-28 slot, 29-31 function 
		      ddddddddddddddddbbbbbbbbsssssfff
    @param rxq_size - receive queue size
    @param txq_size - transmit queue size
*/

autoreply define avf_create
{
  u32 client_index;
  u32 context;

  u32 pci_addr;
  i32 enable_elog;
  u16 rxq_size;
  u16 txq_size;
};

/** \brief
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - interface index
*/

autoreply define avf_delete
{
  u32 client_index;
  u32 context;

  u32 sw_if_index;
};

/*
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
ibuting (vm, sif); } vec_foreach_index (thread_index, bm->per_thread_data) { bond_per_thread_data_t *ptd = vec_elt_at_index (bm->per_thread_data, thread_index); vec_validate_aligned (ptd->per_port_queue, vec_len (bif->slaves) - 1, CLIB_CACHE_LINE_BYTES); vec_foreach_index (sif_if_index, ptd->per_port_queue) { ptd->per_port_queue[sif_if_index].n_buffers = 0; } } args->rv = vnet_feature_enable_disable ("device-input", "bond-input", sif_hw->hw_if_index, 1, 0, 0); if (args->rv) { args->error = clib_error_return (0, "Error encountered on input feature arc enable"); } } static clib_error_t * enslave_interface_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { bond_enslave_args_t args = { 0 }; unformat_input_t _line_input, *line_input = &_line_input; vnet_main_t *vnm = vnet_get_main (); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return clib_error_return (0, "Missing required arguments."); args.slave = ~0; args.group = ~0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U %U", unformat_vnet_sw_interface, vnm, &args.group, unformat_vnet_sw_interface, vnm, &args.slave)) ; else if (unformat (line_input, "passive")) args.is_passive = 1; else if (unformat (line_input, "long-timeout")) args.is_long_timeout = 1; else { args.error = clib_error_return (0, "unknown input `%U'", format_unformat_error, input); break; } } unformat_free (line_input); if (args.error) return args.error; if (args.group == ~0) return clib_error_return (0, "Missing bond interface"); if (args.slave == ~0) return clib_error_return (0, "please specify valid slave interface name"); bond_enslave (vm, &args); return args.error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (enslave_interface_command, static) = { .path = "bond add", .short_help = "bond add " "[passive] [long-timeout]", .function = enslave_interface_command_fn, }; /* *INDENT-ON* */ void bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args) { bond_if_t *bif; slave_if_t *sif; sif = bond_get_slave_by_sw_if_index (args->slave); if (!sif) { args->rv = VNET_API_ERROR_INVALID_INTERFACE; args->error = clib_error_return (0, "interface was not enslaved"); return; } bif = bond_get_master_by_dev_instance (sif->bif_dev_instance); bond_delete_neighbor (vm, bif, sif); } static clib_error_t * detach_interface_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { bond_detach_slave_args_t args = { 0 }; unformat_input_t _line_input, *line_input = &_line_input; vnet_main_t *vnm = vnet_get_main (); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return clib_error_return (0, "Missing required arguments."); args.slave = ~0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &args.slave)) ; else { args.error = clib_error_return (0, "unknown input `%U'", format_unformat_error, input); break; } } unformat_free (line_input); if (args.error) return args.error; if (args.slave == ~0) return clib_error_return (0, "please specify valid slave interface name"); bond_detach_slave (vm, &args); return args.error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (detach_interface_command, static) = { .path = "bond del", .short_help = "bond del ", .function = detach_interface_command_fn, }; /* *INDENT-ON* */ static void show_bond (vlib_main_t * vm) { bond_main_t *bm = &bond_main; bond_if_t *bif; vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s", "interface name", "sw_if_index", "mode", "load balance", "active slaves", "slaves"); /* *INDENT-OFF* */ pool_foreach (bif, bm->interfaces, ({ vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u", format_bond_interface_name, bif->dev_instance, bif->sw_if_index, format_bond_mode, bif->mode, format_bond_load_balance, bif->lb, vec_len (bif->active_slaves), vec_len (bif->slaves)); })); /* *INDENT-ON* */ } static void show_bond_details (vlib_main_t * vm) { bond_main_t *bm = &bond_main; bond_if_t *bif; u32 *sw_if_index; /* *INDENT-OFF* */ pool_foreach (bif, bm->interfaces, ({ vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance); vlib_cli_output (vm, " mode: %U", format_bond_mode, bif->mode); vlib_cli_output (vm, " load balance: %U", format_bond_load_balance, bif->lb); if (bif->mode == BOND_MODE_ROUND_ROBIN) vlib_cli_output (vm, " last xmit slave index: %u", bif->lb_rr_last_index); vlib_cli_output (vm, " number of active slaves: %d", vec_len (bif->active_slaves)); vec_foreach (sw_if_index, bif->active_slaves) { vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnet_get_main (), *sw_if_index); } vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves)); vec_foreach (sw_if_index, bif->slaves) { vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnet_get_main (), *sw_if_index); } vlib_cli_output (vm, " device instance: %d", bif->dev_instance); vlib_cli_output (vm, " interface id: %d", bif->id); vlib_cli_output (vm, " sw_if_index: %d", bif->sw_if_index); vlib_cli_output (vm, " hw_if_index: %d", bif->hw_if_index); })); /* *INDENT-ON* */ } static clib_error_t * show_bond_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 details = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "details")) details = 1; else { return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } } if (details) show_bond_details (vm); else show_bond (vm); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_bond_command, static) = { .path = "show bond", .short_help = "show bond [details]", .function = show_bond_fn, }; /* *INDENT-ON* */ clib_error_t * bond_cli_init (vlib_main_t * vm) { bond_main_t *bm = &bond_main; bm->vlib_main = vm; bm->vnet_main = vnet_get_main (); vec_validate_aligned (bm->slave_by_sw_if_index, 1, CLIB_CACHE_LINE_BYTES); vec_validate_aligned (bm->per_thread_data, vlib_get_thread_main ()->n_vlib_mains - 1, CLIB_CACHE_LINE_BYTES); return 0; } VLIB_INIT_FUNCTION (bond_cli_init); /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */