29 #define foreach_bond_tx_error \ 31 _(IF_DOWN, "interface down") \ 32 _(NO_SLAVE, "no slave") 36 #define _(f,s) BOND_TX_ERROR_##f, 59 s =
format (s,
"src %U, dst %U, %s -> %s",
67 #ifndef CLIB_MARCH_VARIANT 75 s =
format (s,
"BondEthernet%lu", bif->
id);
94 if ((bif_hw->
l2_if_count == 1) && (l2_if_adjust == 1))
107 else if ((bif_hw->
l2_if_count == 0) && (l2_if_adjust == -1))
164 for (port = 1; port < n_slaves; port++)
199 ethertype_p = ð->
type;
203 vlan = (
void *) (eth + 1);
204 ethertype_p = &vlan->
type;
205 if (*ethertype_p == ntohs (ETHERNET_TYPE_VLAN))
208 ethertype_p = &vlan->
type;
221 u16 ethertype, *ethertype_p;
222 u32 *mac1, *mac2, *mac3;
227 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
228 (ethertype != htons (ETHERNET_TYPE_IP6)))
229 return (
bond_lb_l2 (vm, node, bif, b0, n_slaves));
234 if (ip_version == 0x4)
249 else if (ip_version == 0x6)
272 return (
bond_lb_l2 (vm, node, bif, b0, n_slaves));
283 u16 ethertype, *ethertype_p;
288 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
289 (ethertype != htons (ETHERNET_TYPE_IP6)))
290 return (
bond_lb_l2 (vm, node, bif, b0, n_slaves));
295 if (ip_version == 0x4)
300 is_tcp_udp = (ip4->
protocol == IP_PROTOCOL_TCP) ||
309 else if (ip_version == 0x6)
318 (ip6->
protocol == IP_PROTOCOL_UDP)))
321 tcp = (
void *) (ip6 + 1);
323 else if (ip6->
protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
327 if ((hbh->
protocol == IP_PROTOCOL_TCP)
328 || (hbh->
protocol == IP_PROTOCOL_UDP))
349 return (
bond_lb_l2 (vm, node, bif, b0, n_slaves));
392 if (lb_alg == BOND_LB_L2)
394 h[0] =
bond_lb_l2 (vm, node, bif, b[0], n_slaves);
395 h[1] =
bond_lb_l2 (vm, node, bif, b[1], n_slaves);
396 h[2] =
bond_lb_l2 (vm, node, bif, b[2], n_slaves);
397 h[3] =
bond_lb_l2 (vm, node, bif, b[3], n_slaves);
399 else if (lb_alg == BOND_LB_L34)
401 h[0] =
bond_lb_l34 (vm, node, bif, b[0], n_slaves);
402 h[1] =
bond_lb_l34 (vm, node, bif, b[1], n_slaves);
403 h[2] =
bond_lb_l34 (vm, node, bif, b[2], n_slaves);
404 h[3] =
bond_lb_l34 (vm, node, bif, b[3], n_slaves);
406 else if (lb_alg == BOND_LB_L23)
408 h[0] =
bond_lb_l23 (vm, node, bif, b[0], n_slaves);
409 h[1] =
bond_lb_l23 (vm, node, bif, b[1], n_slaves);
410 h[2] =
bond_lb_l23 (vm, node, bif, b[2], n_slaves);
411 h[3] =
bond_lb_l23 (vm, node, bif, b[3], n_slaves);
413 else if (lb_alg == BOND_LB_RR)
420 else if (lb_alg == BOND_LB_BC)
441 if (bif->
lb == BOND_LB_L2)
442 h[0] =
bond_lb_l2 (vm, node, bif, b[0], n_slaves);
443 else if (bif->
lb == BOND_LB_L34)
444 h[0] =
bond_lb_l34 (vm, node, bif, b[0], n_slaves);
445 else if (bif->
lb == BOND_LB_L23)
446 h[0] =
bond_lb_l23 (vm, node, bif, b[0], n_slaves);
447 else if (bif->
lb == BOND_LB_RR)
449 else if (bif->
lb == BOND_LB_BC)
464 u32 mask = n_slaves - 1;
466 #ifdef CLIB_HAVE_VEC256 468 u32x8 mask8, sc8u, h8a, h8b;
471 if (use_modulo_shortcut)
473 mask8 = u32x8_splat (mask);
477 mask8 = u32x8_splat (0xffff);
478 sc8u = u32x8_splat (n_slaves);
484 h8a = u32x8_load_unaligned (h) & mask8;
485 h8b = u32x8_load_unaligned (h + 8) & mask8;
487 if (use_modulo_shortcut == 0)
493 u32x8_store_unaligned (h8a, h);
494 u32x8_store_unaligned (h8b, h + 8);
502 if (use_modulo_shortcut)
521 if (use_modulo_shortcut)
533 int single_sw_if_index)
615 while (n_trace > 0 && n_left > 0)
652 u32 n_left = frame->n_vectors;
664 thread_index, bif->sw_if_index,
668 return frame->n_vectors;
671 n_slaves =
vec_len (bif->active_slaves);
677 thread_index, bif->sw_if_index,
681 return frame->n_vectors;
687 if ((bif->lb == BOND_LB_AB) ||
PREDICT_FALSE (n_slaves == 1))
697 if (bif->lb == BOND_LB_BC)
709 if (bif->lb == BOND_LB_L2)
712 else if (bif->lb == BOND_LB_L34)
715 else if (bif->lb == BOND_LB_L23)
718 else if (bif->lb == BOND_LB_RR)
737 for (p = 0; p < n_slaves; p++)
757 bif->sw_if_index, frame->n_vectors);
759 return frame->n_vectors;
778 uword event_type, *event_data = 0;
788 for (i = 0; i <
vec_len (event_data); i++)
790 hw_if_index = event_data[
i];
804 .name =
"bond-process",
VNET_DEVICE_CLASS_TX_FN() bond_dev_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
static __clib_unused clib_error_t * bond_set_l2_mode_function(vnet_main_t *vnm, struct vnet_hw_interface_t *bif_hw, i32 l2_if_adjust)
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
vnet_interface_main_t interface_main
u32 buffers[VLIB_FRAME_SIZE]
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)
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
#define clib_memcpy_fast(a, b, c)
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
void vnet_hw_interface_walk_sw(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_sw_interface_walk_t fn, void *ctx)
Walk the SW interfaces on a HW interface - this is the super interface and any sub-interfaces.
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
static_always_inline u32 lb_hash_hash_2_tuples(u64 k0, u32 k1)
void send_ip6_na(vlib_main_t *vm, u32 sw_if_index)
#define BOND_MODULO_SHORTCUT(a)
struct _tcp_header tcp_header_t
bond_per_thread_data_t * per_thread_data
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
uword as_uword[16/sizeof(uword)]
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
enum walk_rc_t_ walk_rc_t
Walk return code.
#define static_always_inline
u8 * format_ethernet_address(u8 *s, va_list *args)
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)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define VNET_DEVICE_CLASS_TX_FN(devclass)
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)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static_always_inline u16 * bond_locate_ethertype(ethernet_header_t *eth)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define foreach_bond_tx_error
vlib_simple_counter_main_t * sw_if_counters
static char * bond_tx_error_strings[]
void send_ip4_garp(vlib_main_t *vm, u32 sw_if_index)
#define VLIB_REGISTER_NODE(x,...)
static void vnet_put_frame_to_sw_interface(vnet_main_t *vnm, u32 sw_if_index, vlib_frame_t *f)
#define CLIB_PREFETCH(addr, size, type)
ethernet_header_t ethernet
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
static u8 * format_bond_tx_trace(u8 *s, va_list *args)
static_always_inline void bond_hash_to_port(u32 *h, u32 n_left, u32 n_slaves, int use_modulo_shortcut)
static walk_rc_t bond_active_interface_switch_cb(vnet_main_t *vnm, u32 sw_if_index, void *arg)
static_always_inline int ethernet_frame_is_tagged(u16 type)
VNET_DEVICE_CLASS(bond_dev_class)
static_always_inline void bond_tx_trace(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t **b, u32 n_left, u32 *h)
#define clib_mem_unaligned(pointer, type)
static vlib_frame_t * vnet_get_frame_to_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static_always_inline void bond_tx_add_to_queue(bond_per_thread_data_t *ptd, u32 port, u32 bi)
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)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static_always_inline u32x8 u32x8_from_f32x8(f32x8 v)
u8 * format_bond_interface_name(u8 *s, va_list *args)
static_always_inline void bond_update_sw_if_index(bond_per_thread_data_t *ptd, bond_if_t *bif, u32 *bi, vlib_buffer_t **b, u32 *data, u32 n_left, int single_sw_if_index)
static_always_inline void bond_tx_inline(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t **b, u32 *h, u32 n_left, uword n_slaves, u32 lb_alg)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static __clib_unused clib_error_t * bond_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
#define vec_foreach(var, vec)
Vector iterator.
static_always_inline u32 lb_hash_hash(u64 k0, u64 k1, u64 k2, u64 k3, u64 k4)
static_always_inline u32 bond_lb_broadcast(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword n_slaves)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define CLIB_CACHE_LINE_BYTES
static clib_error_t * bond_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static_always_inline f32x8 f32x8_from_u32x8(u32x8 v)
bond_per_port_queue_t * per_port_queue
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static uword bond_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)