X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fbonding%2Fdevice.c;h=550321b3763acdaaeeea89e974b63d94f33d7891;hb=cbe25aab3be72154f2c706c39eeba6a77f34450f;hp=e7d6cdad407d8312814d2e0d11ca07cabac0fab1;hpb=a3d5986a35743a3ca1020155bed8267b5246d155;p=vpp.git diff --git a/src/vnet/bonding/device.c b/src/vnet/bonding/device.c index e7d6cdad407..550321b3763 100644 --- a/src/vnet/bonding/device.c +++ b/src/vnet/bonding/device.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define foreach_bond_tx_error \ _(NONE, "no error") \ @@ -72,7 +72,7 @@ format_bond_interface_name (u8 * s, va_list * args) bond_main_t *bm = &bond_main; bond_if_t *bif = pool_elt_at_index (bm->interfaces, dev_instance); - s = format (s, "BondEthernet%lu", bif->dev_instance); + s = format (s, "BondEthernet%lu", bif->id); return s; } @@ -142,6 +142,50 @@ bond_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) return 0; } +static clib_error_t * +bond_add_del_mac_address (vnet_hw_interface_t * hi, const u8 * address, + u8 is_add) +{ + vnet_main_t *vnm = vnet_get_main (); + bond_if_t *bif; + clib_error_t *error = 0; + vnet_hw_interface_t *s_hi; + int i; + + + bif = bond_get_master_by_sw_if_index (hi->sw_if_index); + if (!bif) + { + return clib_error_return (0, "No bond master found for sw_if_index %u", + hi->sw_if_index); + } + + /* Add/del address on each slave hw intf, they control the hardware */ + vec_foreach_index (i, bif->slaves) + { + s_hi = vnet_get_sup_hw_interface (vnm, vec_elt (bif->slaves, i)); + error = vnet_hw_interface_add_del_mac_address (vnm, s_hi->hw_if_index, + address, is_add); + + if (error) + { + int j; + + /* undo any that were completed before the failure */ + for (j = i - 1; j > -1; j--) + { + s_hi = vnet_get_sup_hw_interface (vnm, vec_elt (bif->slaves, j)); + vnet_hw_interface_add_del_mac_address (vnm, s_hi->hw_if_index, + address, !(is_add)); + } + + return error; + } + } + + return 0; +} + static_always_inline void bond_tx_add_to_queue (bond_per_thread_data_t * ptd, u32 port, u32 bi) { @@ -150,7 +194,7 @@ bond_tx_add_to_queue (bond_per_thread_data_t * ptd, u32 port, u32 bi) } static_always_inline u32 -bond_lb_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node, +bond_lb_broadcast (vlib_main_t * vm, bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) { bond_main_t *bm = &bond_main; @@ -176,10 +220,9 @@ bond_lb_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node, } static_always_inline u32 -bond_lb_l2 (vlib_main_t * vm, vlib_node_runtime_t * node, - bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) +bond_lb_l2 (vlib_buffer_t * b0) { - ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0); + ethernet_header_t *eth = vlib_buffer_get_current (b0); u64 *dst = (u64 *) & eth->dst_address[0]; u64 a = clib_mem_unaligned (dst, u64); u32 *src = (u32 *) & eth->src_address[2]; @@ -212,10 +255,9 @@ bond_locate_ethertype (ethernet_header_t * eth) } static_always_inline u32 -bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node, - bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) +bond_lb_l23 (vlib_buffer_t * b0) { - ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0); + ethernet_header_t *eth = vlib_buffer_get_current (b0); u8 ip_version; ip4_header_t *ip4; u16 ethertype, *ethertype_p; @@ -226,7 +268,7 @@ bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node, if ((ethertype != htons (ETHERNET_TYPE_IP4)) && (ethertype != htons (ETHERNET_TYPE_IP6))) - return (bond_lb_l2 (vm, node, bif, b0, n_slaves)); + return bond_lb_l2 (b0); ip4 = (ip4_header_t *) (ethertype_p + 1); ip_version = (ip4->ip_version_and_header_length >> 4); @@ -269,14 +311,13 @@ bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node, uword), a); return c; } - return (bond_lb_l2 (vm, node, bif, b0, n_slaves)); + return bond_lb_l2 (b0); } static_always_inline u32 -bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node, - bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) +bond_lb_l34 (vlib_buffer_t * b0) { - ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0); + ethernet_header_t *eth = vlib_buffer_get_current (b0); u8 ip_version; uword is_tcp_udp; ip4_header_t *ip4; @@ -287,7 +328,7 @@ bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node, if ((ethertype != htons (ETHERNET_TYPE_IP4)) && (ethertype != htons (ETHERNET_TYPE_IP6))) - return (bond_lb_l2 (vm, node, bif, b0, n_slaves)); + return (bond_lb_l2 (b0)); ip4 = (ip4_header_t *) (ethertype_p + 1); ip_version = (ip4->ip_version_and_header_length >> 4); @@ -346,13 +387,11 @@ bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node, return c; } - return (bond_lb_l2 (vm, node, bif, b0, n_slaves)); + return bond_lb_l2 (b0); } static_always_inline u32 -bond_lb_round_robin (vlib_main_t * vm, - vlib_node_runtime_t * node, - bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) +bond_lb_round_robin (bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves) { bif->lb_rr_last_index++; if (bif->lb_rr_last_index >= n_slaves) @@ -362,8 +401,7 @@ bond_lb_round_robin (vlib_main_t * vm, } static_always_inline void -bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - bond_if_t * bif, vlib_buffer_t ** b, +bond_tx_inline (vlib_main_t * vm, bond_if_t * bif, vlib_buffer_t ** b, u32 * h, u32 n_left, uword n_slaves, u32 lb_alg) { while (n_left >= 4) @@ -391,38 +429,38 @@ bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (lb_alg == BOND_LB_L2) { - h[0] = bond_lb_l2 (vm, node, bif, b[0], n_slaves); - h[1] = bond_lb_l2 (vm, node, bif, b[1], n_slaves); - h[2] = bond_lb_l2 (vm, node, bif, b[2], n_slaves); - h[3] = bond_lb_l2 (vm, node, bif, b[3], n_slaves); + h[0] = bond_lb_l2 (b[0]); + h[1] = bond_lb_l2 (b[1]); + h[2] = bond_lb_l2 (b[2]); + h[3] = bond_lb_l2 (b[3]); } else if (lb_alg == BOND_LB_L34) { - h[0] = bond_lb_l34 (vm, node, bif, b[0], n_slaves); - h[1] = bond_lb_l34 (vm, node, bif, b[1], n_slaves); - h[2] = bond_lb_l34 (vm, node, bif, b[2], n_slaves); - h[3] = bond_lb_l34 (vm, node, bif, b[3], n_slaves); + h[0] = bond_lb_l34 (b[0]); + h[1] = bond_lb_l34 (b[1]); + h[2] = bond_lb_l34 (b[2]); + h[3] = bond_lb_l34 (b[3]); } else if (lb_alg == BOND_LB_L23) { - h[0] = bond_lb_l23 (vm, node, bif, b[0], n_slaves); - h[1] = bond_lb_l23 (vm, node, bif, b[1], n_slaves); - h[2] = bond_lb_l23 (vm, node, bif, b[2], n_slaves); - h[3] = bond_lb_l23 (vm, node, bif, b[3], n_slaves); + h[0] = bond_lb_l23 (b[0]); + h[1] = bond_lb_l23 (b[1]); + h[2] = bond_lb_l23 (b[2]); + h[3] = bond_lb_l23 (b[3]); } else if (lb_alg == BOND_LB_RR) { - h[0] = bond_lb_round_robin (vm, node, bif, b[0], n_slaves); - h[1] = bond_lb_round_robin (vm, node, bif, b[1], n_slaves); - h[2] = bond_lb_round_robin (vm, node, bif, b[2], n_slaves); - h[3] = bond_lb_round_robin (vm, node, bif, b[3], n_slaves); + h[0] = bond_lb_round_robin (bif, b[0], n_slaves); + h[1] = bond_lb_round_robin (bif, b[1], n_slaves); + h[2] = bond_lb_round_robin (bif, b[2], n_slaves); + h[3] = bond_lb_round_robin (bif, b[3], n_slaves); } else if (lb_alg == BOND_LB_BC) { - h[0] = bond_lb_broadcast (vm, node, bif, b[0], n_slaves); - h[1] = bond_lb_broadcast (vm, node, bif, b[1], n_slaves); - h[2] = bond_lb_broadcast (vm, node, bif, b[2], n_slaves); - h[3] = bond_lb_broadcast (vm, node, bif, b[3], n_slaves); + h[0] = bond_lb_broadcast (vm, bif, b[0], n_slaves); + h[1] = bond_lb_broadcast (vm, bif, b[1], n_slaves); + h[2] = bond_lb_broadcast (vm, bif, b[2], n_slaves); + h[3] = bond_lb_broadcast (vm, bif, b[3], n_slaves); } else { @@ -439,15 +477,15 @@ bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]); if (bif->lb == BOND_LB_L2) - h[0] = bond_lb_l2 (vm, node, bif, b[0], n_slaves); + h[0] = bond_lb_l2 (b[0]); else if (bif->lb == BOND_LB_L34) - h[0] = bond_lb_l34 (vm, node, bif, b[0], n_slaves); + h[0] = bond_lb_l34 (b[0]); else if (bif->lb == BOND_LB_L23) - h[0] = bond_lb_l23 (vm, node, bif, b[0], n_slaves); + h[0] = bond_lb_l23 (b[0]); else if (bif->lb == BOND_LB_RR) - h[0] = bond_lb_round_robin (vm, node, bif, b[0], n_slaves); + h[0] = bond_lb_round_robin (bif, b[0], n_slaves); else if (bif->lb == BOND_LB_BC) - h[0] = bond_lb_broadcast (vm, node, bif, b[0], n_slaves); + h[0] = bond_lb_broadcast (vm, bif, b[0], n_slaves); else { ASSERT (0); @@ -455,6 +493,7 @@ bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, n_left -= 1; b += 1; + h += 1; } } @@ -464,7 +503,7 @@ bond_hash_to_port (u32 * h, u32 n_left, u32 n_slaves, int use_modulo_shortcut) u32 mask = n_slaves - 1; #ifdef CLIB_HAVE_VEC256 - /* only lower 16 bits of hash due to single precision fp arithmetics */ + /* only lower 16 bits of hash due to single precision fp arithmetic */ u32x8 mask8, sc8u, h8a, h8b; f32x8 sc8f; @@ -621,7 +660,7 @@ bond_tx_trace (vlib_main_t * vm, vlib_node_runtime_t * node, bond_if_t * bif, vlib_trace_buffer (vm, node, next0, b[0], 0 /* follow_chain */ ); vlib_set_trace_count (vm, node, --n_trace); t0 = vlib_add_trace (vm, node, b[0], sizeof (*t0)); - eth = (ethernet_header_t *) vlib_buffer_get_current (b[0]); + eth = vlib_buffer_get_current (b[0]); t0->ethernet = *eth; t0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; if (!h) @@ -683,7 +722,7 @@ VNET_DEVICE_CLASS_TX_FN (bond_dev_class) (vlib_main_t * vm, vlib_get_buffers (vm, from, bufs, n_left); - /* active-backup mode, ship everyting to first sw if index */ + /* active-backup mode, ship everything to first sw if index */ if ((bif->lb == BOND_LB_AB) || PREDICT_FALSE (n_slaves == 1)) { sw_if_index = *vec_elt_at_index (bif->active_slaves, 0); @@ -698,26 +737,26 @@ VNET_DEVICE_CLASS_TX_FN (bond_dev_class) (vlib_main_t * vm, { sw_if_index = *vec_elt_at_index (bif->active_slaves, 0); - bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves, - BOND_LB_BC); + bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_BC); bond_tx_trace (vm, node, bif, bufs, frame->n_vectors, 0); bond_update_sw_if_index (ptd, bif, from, bufs, &sw_if_index, n_left, /* single_sw_if_index */ 1); goto done; } + /* if have at least one slave on local numa node, only slaves on local numa + node will transmit pkts when bif->local_numa_only is enabled */ + if (bif->n_numa_slaves >= 1) + n_slaves = bif->n_numa_slaves; + if (bif->lb == BOND_LB_L2) - bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves, - BOND_LB_L2); + bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L2); else if (bif->lb == BOND_LB_L34) - bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves, - BOND_LB_L34); + bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L34); else if (bif->lb == BOND_LB_L23) - bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves, - BOND_LB_L23); + bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L23); else if (bif->lb == BOND_LB_RR) - bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves, - BOND_LB_RR); + bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_RR); else ASSERT (0); @@ -745,17 +784,12 @@ done: f = vnet_get_frame_to_sw_interface (vnm, sw_if_index); f->n_vectors = ptd->per_port_queue[p].n_buffers; to_next = vlib_frame_vector_args (f); - clib_memcpy (to_next, ptd->per_port_queue[p].buffers, - f->n_vectors * sizeof (u32)); + clib_memcpy_fast (to_next, ptd->per_port_queue[p].buffers, + f->n_vectors * sizeof (u32)); vnet_put_frame_to_sw_interface (vnm, sw_if_index, f); ptd->per_port_queue[p].n_buffers = 0; } } - - vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters - + VNET_INTERFACE_COUNTER_TX, thread_index, - bif->sw_if_index, frame->n_vectors); - return frame->n_vectors; } @@ -765,8 +799,7 @@ bond_active_interface_switch_cb (vnet_main_t * vnm, u32 sw_if_index, { bond_main_t *bm = &bond_main; - send_ip4_garp (bm->vlib_main, sw_if_index); - send_ip6_na (bm->vlib_main, sw_if_index); + ip_neighbor_advertise (bm->vlib_main, IP46_TYPE_BOTH, NULL, sw_if_index); return (WALK_CONTINUE); } @@ -788,9 +821,10 @@ bond_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) for (i = 0; i < vec_len (event_data); i++) { hw_if_index = event_data[i]; - /* walk hw interface to process all subinterfaces */ - vnet_hw_interface_walk_sw (vnm, hw_if_index, - bond_active_interface_switch_cb, 0); + if (vnet_get_hw_interface_or_null (vnm, hw_if_index)) + /* walk hw interface to process all subinterfaces */ + vnet_hw_interface_walk_sw (vnm, hw_if_index, + bond_active_interface_switch_cb, 0); } vec_reset_length (event_data); } @@ -800,6 +834,7 @@ bond_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) /* *INDENT-OFF* */ VLIB_REGISTER_NODE (bond_process_node) = { .function = bond_process, + .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED, .type = VLIB_NODE_TYPE_PROCESS, .name = "bond-process", }; @@ -815,10 +850,30 @@ VNET_DEVICE_CLASS (bond_dev_class) = { .admin_up_down_function = bond_interface_admin_up_down, .subif_add_del_function = bond_subif_add_del_function, .format_tx_trace = format_bond_tx_trace, + .mac_addr_add_del_function = bond_add_del_mac_address, }; /* *INDENT-ON* */ +static clib_error_t * +bond_slave_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) +{ + bond_main_t *bm = &bond_main; + slave_if_t *sif; + bond_detach_slave_args_t args = { 0 }; + + if (is_add) + return 0; + sif = bond_get_slave_by_sw_if_index (sw_if_index); + if (!sif) + return 0; + args.slave = sw_if_index; + bond_detach_slave (bm->vlib_main, &args); + return args.error; +} + +VNET_SW_INTERFACE_ADD_DEL_FUNCTION (bond_slave_interface_add_del); + /* * fd.io coding-style-patch-verification: ON *