FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
device.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #define _GNU_SOURCE
19 #include <stdint.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ip/ip6_packet.h>
24 #include <vnet/bonding/node.h>
25 #include <vppinfra/lb_hash_hash.h>
26 
27 #define foreach_bond_tx_error \
28  _(NONE, "no error") \
29  _(IF_DOWN, "interface down") \
30  _(NO_SLAVE, "no slave")
31 
32 typedef enum
33 {
34 #define _(f,s) BOND_TX_ERROR_##f,
36 #undef _
39 
40 static char *bond_tx_error_strings[] = {
41 #define _(n,s) s,
43 #undef _
44 };
45 
46 static u8 *
47 format_bond_tx_trace (u8 * s, va_list * args)
48 {
49  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
50  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
51  bond_packet_trace_t *t = va_arg (*args, bond_packet_trace_t *);
52  vnet_hw_interface_t *hw, *hw1;
53  vnet_main_t *vnm = vnet_get_main ();
54 
57  s = format (s, "src %U, dst %U, %s -> %s",
60  hw->name, hw1->name);
61 
62  return s;
63 }
64 
65 u8 *
66 format_bond_interface_name (u8 * s, va_list * args)
67 {
68  u32 dev_instance = va_arg (*args, u32);
69  bond_main_t *bm = &bond_main;
70  bond_if_t *bif = pool_elt_at_index (bm->interfaces, dev_instance);
71 
72  s = format (s, "BondEthernet%lu", bif->dev_instance);
73 
74  return s;
75 }
76 
77 static __clib_unused clib_error_t *
79  struct vnet_hw_interface_t *bif_hw,
80  i32 l2_if_adjust)
81 {
82  bond_if_t *bif;
84  struct vnet_hw_interface_t *sif_hw;
85 
87  if (!bif)
88  return 0;
89 
90  if ((bif_hw->l2_if_count == 1) && (l2_if_adjust == 1))
91  {
92  /* Just added first L2 interface on this port */
93  vec_foreach (sw_if_index, bif->slaves)
94  {
95  sif_hw = vnet_get_sup_hw_interface (vnm, *sw_if_index);
96  ethernet_set_flags (vnm, sif_hw->hw_if_index,
98 
99  /* ensure all packets go to ethernet-input */
100  ethernet_set_rx_redirect (vnm, sif_hw, 1);
101  }
102  }
103 
104  return 0;
105 }
106 
107 static __clib_unused clib_error_t *
109  struct vnet_sw_interface_t *st, int is_add)
110 {
111  /* Nothing for now */
112  return 0;
113 }
114 
115 static clib_error_t *
117 {
118  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
119  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
120  bond_main_t *bm = &bond_main;
122 
123  bif->admin_up = is_up;
124  if (is_up && vec_len (bif->active_slaves))
127  return 0;
128 }
129 
132  bond_if_t * bif, vlib_buffer_t * b0,
133  uword slave_count)
134 {
135  vnet_main_t *vnm = vnet_get_main ();
136  vlib_buffer_t *c0;
137  int port;
138  u32 *to_next = 0;
140  vlib_frame_t *f;
141  u16 thread_index = vlib_get_thread_index ();
142 
143  for (port = 1; port < slave_count; port++)
144  {
145  sw_if_index = *vec_elt_at_index (bif->active_slaves, port);
146  if (bif->per_thread_info[thread_index].frame[port] == 0)
147  bif->per_thread_info[thread_index].frame[port] =
148  vnet_get_frame_to_sw_interface (vnm, sw_if_index);
149  f = bif->per_thread_info[thread_index].frame[port];
150  to_next = vlib_frame_vector_args (f);
151  to_next += f->n_vectors;
152  c0 = vlib_buffer_copy (vm, b0);
153  if (PREDICT_TRUE (c0 != 0))
154  {
155  vnet_buffer (c0)->sw_if_index[VLIB_TX] = sw_if_index;
156  to_next[0] = vlib_get_buffer_index (vm, c0);
157  f->n_vectors++;
158  }
159  }
160 
161  return 0;
162 }
163 
166  bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
167 {
169  u32 c;
170  u64 *dst = (u64 *) & eth->dst_address[0];
171  u64 a = clib_mem_unaligned (dst, u64);
172  u32 *src = (u32 *) & eth->src_address[2];
173  u32 b = clib_mem_unaligned (src, u32);
174 
175  c = lb_hash_hash_2_tuples (a, b);
176 
177  if (BOND_MODULO_SHORTCUT (slave_count))
178  return (c & (slave_count - 1));
179  else
180  return c % slave_count;
181 }
182 
185 {
186  u16 *ethertype_p;
188 
189  if (!ethernet_frame_is_tagged (clib_net_to_host_u16 (eth->type)))
190  {
191  ethertype_p = &eth->type;
192  }
193  else
194  {
195  vlan = (void *) (eth + 1);
196  ethertype_p = &vlan->type;
197  if (*ethertype_p == ntohs (ETHERNET_TYPE_VLAN))
198  {
199  vlan++;
200  ethertype_p = &vlan->type;
201  }
202  }
203  return ethertype_p;
204 }
205 
208  bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
209 {
211  u8 ip_version;
212  ip4_header_t *ip4;
213  u16 ethertype, *ethertype_p;
214  u32 *mac1, *mac2, *mac3;
215 
216  ethertype_p = bond_locate_ethertype (eth);
217  ethertype = clib_mem_unaligned (ethertype_p, u16);
218 
219  if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
220  (ethertype != htons (ETHERNET_TYPE_IP6)))
221  return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
222 
223  ip4 = (ip4_header_t *) (ethertype_p + 1);
224  ip_version = (ip4->ip_version_and_header_length >> 4);
225 
226  if (ip_version == 0x4)
227  {
228  u32 a, c;
229 
230  mac1 = (u32 *) & eth->dst_address[0];
231  mac2 = (u32 *) & eth->dst_address[4];
232  mac3 = (u32 *) & eth->src_address[2];
233 
234  a = clib_mem_unaligned (mac1, u32) ^ clib_mem_unaligned (mac2, u32) ^
235  clib_mem_unaligned (mac3, u32);
236  c =
238  a);
239  if (BOND_MODULO_SHORTCUT (slave_count))
240  return (c & (slave_count - 1));
241  else
242  return c % slave_count;
243  }
244  else if (ip_version == 0x6)
245  {
246  u64 a;
247  u32 c;
248  ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
249 
250  mac1 = (u32 *) & eth->dst_address[0];
251  mac2 = (u32 *) & eth->dst_address[4];
252  mac3 = (u32 *) & eth->src_address[2];
253 
254  a = clib_mem_unaligned (mac1, u32) ^ clib_mem_unaligned (mac2, u32) ^
255  clib_mem_unaligned (mac3, u32);
256  c =
258  (&ip6->src_address.as_uword[0], uword),
260  uword),
262  uword),
264  uword), a);
265  if (BOND_MODULO_SHORTCUT (slave_count))
266  return (c & (slave_count - 1));
267  else
268  return c % slave_count;
269  }
270  return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
271 }
272 
275  bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
276 {
278  u8 ip_version;
279  uword is_tcp_udp;
280  ip4_header_t *ip4;
281  u16 ethertype, *ethertype_p;
282 
283  ethertype_p = bond_locate_ethertype (eth);
284  ethertype = clib_mem_unaligned (ethertype_p, u16);
285 
286  if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
287  (ethertype != htons (ETHERNET_TYPE_IP6)))
288  return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
289 
290  ip4 = (ip4_header_t *) (ethertype_p + 1);
291  ip_version = (ip4->ip_version_and_header_length >> 4);
292 
293  if (ip_version == 0x4)
294  {
295  u32 a, c, t1, t2;
296  tcp_header_t *tcp = (void *) (ip4 + 1);
297 
298  is_tcp_udp = (ip4->protocol == IP_PROTOCOL_TCP) ||
299  (ip4->protocol == IP_PROTOCOL_UDP);
300  t1 = is_tcp_udp ? clib_mem_unaligned (&tcp->src, u16) : 0;
301  t2 = is_tcp_udp ? clib_mem_unaligned (&tcp->dst, u16) : 0;
302  a = t1 ^ t2;
303  c =
304  lb_hash_hash_2_tuples (clib_mem_unaligned (&ip4->address_pair, u64),
305  a);
306  if (BOND_MODULO_SHORTCUT (slave_count))
307  return (c & (slave_count - 1));
308  else
309  return c % slave_count;
310  }
311  else if (ip_version == 0x6)
312  {
313  u64 a;
314  u32 c, t1, t2;
315  ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
316  tcp_header_t *tcp = (void *) (ip6 + 1);
317 
318  is_tcp_udp = 0;
319  if (PREDICT_TRUE ((ip6->protocol == IP_PROTOCOL_TCP) ||
320  (ip6->protocol == IP_PROTOCOL_UDP)))
321  {
322  is_tcp_udp = 1;
323  tcp = (void *) (ip6 + 1);
324  }
325  else if (ip6->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
326  {
328  (ip6_hop_by_hop_header_t *) (ip6 + 1);
329  if ((hbh->protocol == IP_PROTOCOL_TCP)
330  || (hbh->protocol == IP_PROTOCOL_UDP))
331  {
332  is_tcp_udp = 1;
333  tcp = (tcp_header_t *) ((u8 *) hbh + ((hbh->length + 1) << 3));
334  }
335  }
336  t1 = is_tcp_udp ? clib_mem_unaligned (&tcp->src, u16) : 0;
337  t2 = is_tcp_udp ? clib_mem_unaligned (&tcp->dst, u16) : 0;
338  a = t1 ^ t2;
339  c =
340  lb_hash_hash (clib_mem_unaligned
341  (&ip6->src_address.as_uword[0], uword),
342  clib_mem_unaligned (&ip6->src_address.as_uword[1],
343  uword),
344  clib_mem_unaligned (&ip6->dst_address.as_uword[0],
345  uword),
346  clib_mem_unaligned (&ip6->dst_address.as_uword[1],
347  uword), a);
348  if (BOND_MODULO_SHORTCUT (slave_count))
349  return (c & (slave_count - 1));
350  else
351  return c % slave_count;
352  }
353 
354  return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
355 }
356 
359  vlib_node_runtime_t * node,
360  bond_if_t * bif, vlib_buffer_t * b0,
361  uword slave_count)
362 {
363  bif->lb_rr_last_index++;
364  if (BOND_MODULO_SHORTCUT (slave_count))
365  bif->lb_rr_last_index &= slave_count - 1;
366  else
367  bif->lb_rr_last_index %= slave_count;
368 
369  return bif->lb_rr_last_index;
370 }
371 
374  vlib_node_runtime_t * node,
375  bond_if_t * bif, vlib_buffer_t * b0,
376  uword slave_count)
377 {
378  /* First interface is the active, the rest is backup */
379  return 0;
380 }
381 
382 static bond_load_balance_func_t bond_load_balance_table[] = {
383 #define _(v,f,s, p) { bond_load_balance_##p },
385 #undef _
386 };
387 
388 static uword
390  vlib_frame_t * frame)
391 {
392  vnet_interface_output_runtime_t *rund = (void *) node->runtime_data;
393  bond_main_t *bm = &bond_main;
394  bond_if_t *bif = pool_elt_at_index (bm->interfaces, rund->dev_instance);
395  u32 bi0, bi1, bi2, bi3;
396  vlib_buffer_t *b0, *b1, *b2, *b3;
397  u32 *from = vlib_frame_vector_args (frame);
398  u32 n_left_from;
399  ethernet_header_t *eth;
400  u32 port;
401  u32 sw_if_index, sw_if_index1, sw_if_index2, sw_if_index3;
403  uword n_trace = vlib_get_trace_count (vm, node);
404  u16 thread_index = vlib_get_thread_index ();
405  vnet_main_t *vnm = vnet_get_main ();
406  u32 *to_next;
407  u32 sif_if_index, sif_if_index1, sif_if_index2, sif_if_index3;
408  vlib_frame_t *f;
409  uword slave_count;
410 
411  if (PREDICT_FALSE (bif->admin_up == 0))
412  {
413  vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
416  thread_index, bif->sw_if_index,
417  frame->n_vectors);
418  vlib_error_count (vm, node->node_index, BOND_TX_ERROR_IF_DOWN,
419  frame->n_vectors);
420  return frame->n_vectors;
421  }
422 
423  clib_spinlock_lock_if_init (&bif->lockp);
424  slave_count = vec_len (bif->active_slaves);
425  if (PREDICT_FALSE (slave_count == 0))
426  {
427  bi0 = from[0];
428  b0 = vlib_get_buffer (vm, bi0);
431  + VNET_INTERFACE_COUNTER_TX, thread_index, bif->sw_if_index,
432  frame->n_vectors, b0->current_length);
433 
434  vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
437  thread_index, bif->sw_if_index,
438  frame->n_vectors);
439  vlib_error_count (vm, node->node_index, BOND_TX_ERROR_NO_SLAVE,
440  frame->n_vectors);
441  clib_spinlock_unlock_if_init (&bif->lockp);
442  return frame->n_vectors;
443  }
444 
445  vec_validate_aligned (bif->per_thread_info[thread_index].frame, slave_count,
447 
448  /* Number of buffers / pkts */
449  n_left_from = frame->n_vectors;
450 
451  while (n_left_from > 0)
452  {
453  while (n_left_from >= 4)
454  {
455  u32 next0 = 0, next1 = 0, next2 = 0, next3 = 0;
456  u32 port0 = 0, port1 = 0, port2 = 0, port3 = 0;
457 
458  // Prefetch next iteration
459  if (n_left_from >= 8)
460  {
461  vlib_buffer_t *p4, *p5, *p6, *p7;
462 
463  p4 = vlib_get_buffer (vm, from[4]);
464  p5 = vlib_get_buffer (vm, from[5]);
465  p6 = vlib_get_buffer (vm, from[6]);
466  p7 = vlib_get_buffer (vm, from[7]);
467 
468  vlib_prefetch_buffer_header (p4, LOAD);
469  vlib_prefetch_buffer_header (p5, LOAD);
470  vlib_prefetch_buffer_header (p6, LOAD);
471  vlib_prefetch_buffer_header (p7, LOAD);
472 
477  }
478 
479  bi0 = from[0];
480  bi1 = from[1];
481  bi2 = from[2];
482  bi3 = from[3];
483 
484  b0 = vlib_get_buffer (vm, bi0);
485  b1 = vlib_get_buffer (vm, bi1);
486  b2 = vlib_get_buffer (vm, bi2);
487  b3 = vlib_get_buffer (vm, bi3);
488 
493 
494  sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
495  sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
496  sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
497  sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
498 
499  if (PREDICT_TRUE (slave_count != 1))
500  {
501  port0 =
502  (bond_load_balance_table[bif->lb]).load_balance (vm, node,
503  bif, b0,
504  slave_count);
505  port1 =
506  (bond_load_balance_table[bif->lb]).load_balance (vm, node,
507  bif, b1,
508  slave_count);
509  port2 =
510  (bond_load_balance_table[bif->lb]).load_balance (vm, node,
511  bif, b2,
512  slave_count);
513  port3 =
514  (bond_load_balance_table[bif->lb]).load_balance (vm, node,
515  bif, b3,
516  slave_count);
517  }
518 
519  sif_if_index = *vec_elt_at_index (bif->active_slaves, port0);
520  sif_if_index1 = *vec_elt_at_index (bif->active_slaves, port1);
521  sif_if_index2 = *vec_elt_at_index (bif->active_slaves, port2);
522  sif_if_index3 = *vec_elt_at_index (bif->active_slaves, port3);
523 
524  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
525  vnet_buffer (b1)->sw_if_index[VLIB_TX] = sif_if_index1;
526  vnet_buffer (b2)->sw_if_index[VLIB_TX] = sif_if_index2;
527  vnet_buffer (b3)->sw_if_index[VLIB_TX] = sif_if_index3;
528 
529  if (PREDICT_FALSE ((bif->per_thread_info[thread_index].frame[port0]
530  == 0)))
531  bif->per_thread_info[thread_index].frame[port0] =
532  vnet_get_frame_to_sw_interface (vnm, sif_if_index);
533 
534  if (PREDICT_FALSE ((bif->per_thread_info[thread_index].frame[port1]
535  == 0)))
536  bif->per_thread_info[thread_index].frame[port1] =
537  vnet_get_frame_to_sw_interface (vnm, sif_if_index1);
538 
539  if (PREDICT_FALSE ((bif->per_thread_info[thread_index].frame[port2]
540  == 0)))
541  bif->per_thread_info[thread_index].frame[port2] =
542  vnet_get_frame_to_sw_interface (vnm, sif_if_index2);
543 
544  if (PREDICT_FALSE ((bif->per_thread_info[thread_index].frame[port3]
545  == 0)))
546  bif->per_thread_info[thread_index].frame[port3] =
547  vnet_get_frame_to_sw_interface (vnm, sif_if_index3);
548 
549  f = bif->per_thread_info[thread_index].frame[port0];
550  to_next = vlib_frame_vector_args (f);
551  to_next += f->n_vectors;
552  to_next[0] = vlib_get_buffer_index (vm, b0);
553  f->n_vectors++;
554 
555  f = bif->per_thread_info[thread_index].frame[port1];
556  to_next = vlib_frame_vector_args (f);
557  to_next += f->n_vectors;
558  to_next[0] = vlib_get_buffer_index (vm, b1);
559  f->n_vectors++;
560 
561  f = bif->per_thread_info[thread_index].frame[port2];
562  to_next = vlib_frame_vector_args (f);
563  to_next += f->n_vectors;
564  to_next[0] = vlib_get_buffer_index (vm, b2);
565  f->n_vectors++;
566 
567  f = bif->per_thread_info[thread_index].frame[port3];
568  to_next = vlib_frame_vector_args (f);
569  to_next += f->n_vectors;
570  to_next[0] = vlib_get_buffer_index (vm, b3);
571  f->n_vectors++;
572 
573  if (PREDICT_FALSE (n_trace > 0))
574  {
575  vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
576  vlib_set_trace_count (vm, node, --n_trace);
577  t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
579  t0->ethernet = *eth;
580  t0->sw_if_index = sw_if_index;
581  t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
582 
583  if (PREDICT_TRUE (n_trace > 0))
584  {
585  vlib_trace_buffer (vm, node, next1, b1,
586  0 /* follow_chain */ );
587  vlib_set_trace_count (vm, node, --n_trace);
588  t0 = vlib_add_trace (vm, node, b1, sizeof (*t0));
590  t0->ethernet = *eth;
591  t0->sw_if_index = sw_if_index1;
592  t0->bond_sw_if_index =
593  vnet_buffer (b1)->sw_if_index[VLIB_TX];
594 
595  if (PREDICT_TRUE (n_trace > 0))
596  {
597  vlib_trace_buffer (vm, node, next2, b2,
598  0 /* follow_chain */ );
599  vlib_set_trace_count (vm, node, --n_trace);
600  t0 = vlib_add_trace (vm, node, b2, sizeof (*t0));
601  eth =
603  t0->ethernet = *eth;
604  t0->sw_if_index = sw_if_index2;
605  t0->bond_sw_if_index =
606  vnet_buffer (b2)->sw_if_index[VLIB_TX];
607 
608  if (PREDICT_TRUE (n_trace > 0))
609  {
610  vlib_trace_buffer (vm, node, next3, b3,
611  0 /* follow_chain */ );
612  vlib_set_trace_count (vm, node, --n_trace);
613  t0 = vlib_add_trace (vm, node, b3, sizeof (*t0));
614  eth =
617  t0->ethernet = *eth;
618  t0->sw_if_index = sw_if_index3;
619  t0->bond_sw_if_index =
620  vnet_buffer (b3)->sw_if_index[VLIB_TX];
621  }
622  }
623  }
624  }
625  from += 4;
626  n_left_from -= 4;
627  }
628 
629  while (n_left_from > 0)
630  {
631  u32 next0 = 0;
632  u32 port0 = 0;
633 
634  // Prefetch next iteration
635  if (n_left_from > 1)
636  {
637  vlib_buffer_t *p2;
638 
639  p2 = vlib_get_buffer (vm, from[1]);
640  vlib_prefetch_buffer_header (p2, LOAD);
642  }
643 
644  bi0 = from[0];
645  b0 = vlib_get_buffer (vm, bi0);
646 
648 
649  sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
650 
651  if (PREDICT_TRUE (slave_count != 1))
652  port0 =
653  (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
654  b0,
655  slave_count);
656  sif_if_index = *vec_elt_at_index (bif->active_slaves, port0);
657  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
658  if (PREDICT_FALSE
659  ((bif->per_thread_info[thread_index].frame[port0] == 0)))
660  bif->per_thread_info[thread_index].frame[port0] =
661  vnet_get_frame_to_sw_interface (vnm, sif_if_index);
662  f = bif->per_thread_info[thread_index].frame[port0];
663  to_next = vlib_frame_vector_args (f);
664  to_next += f->n_vectors;
665  to_next[0] = vlib_get_buffer_index (vm, b0);
666  f->n_vectors++;
667 
668  if (PREDICT_FALSE (n_trace > 0))
669  {
670  vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
671  vlib_set_trace_count (vm, node, --n_trace);
672  t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
674  t0->ethernet = *eth;
675  t0->sw_if_index = sw_if_index;
676  t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
677  }
678 
679  from += 1;
680  n_left_from -= 1;
681  }
682  }
683 
684  for (port = 0; port < slave_count; port++)
685  {
686  f = bif->per_thread_info[thread_index].frame[port];
687  if (f == 0)
688  continue;
689 
690  sw_if_index = *vec_elt_at_index (bif->active_slaves, port);
691  vnet_put_frame_to_sw_interface (vnm, sw_if_index, f);
692  bif->per_thread_info[thread_index].frame[port] = 0;
693  }
694 
696  + VNET_INTERFACE_COUNTER_TX, thread_index,
697  bif->sw_if_index, frame->n_vectors);
698 
699  clib_spinlock_unlock_if_init (&bif->lockp);
700  return frame->n_vectors;
701 }
702 
703 /* *INDENT-OFF* */
705  .name = "bond",
706  .tx_function = bond_tx_fn,
707  .tx_function_n_errors = BOND_TX_N_ERROR,
708  .tx_function_error_strings = bond_tx_error_strings,
709  .format_device_name = format_bond_interface_name,
710  .set_l2_mode_function = bond_set_l2_mode_function,
711  .admin_up_down_function = bond_interface_admin_up_down,
712  .subif_add_del_function = bond_subif_add_del_function,
713  .format_tx_trace = format_bond_tx_trace,
714 };
715 
717 /* *INDENT-ON* */
718 
719 /*
720  * fd.io coding-style-patch-verification: ON
721  *
722  * Local Variables:
723  * eval: (c-set-style "gnu")
724  * End:
725  */
u32 dev_instance
Definition: node.h:150
u32 hw_if_index
Definition: node.h:151
#define CLIB_UNUSED(x)
Definition: clib.h:79
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)
Definition: device.c:78
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:554
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:143
a
Definition: bitmap.h:516
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:211
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:391
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:464
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static_always_inline u32 bond_load_balance_round_robin(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:358
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define PREDICT_TRUE(x)
Definition: clib.h:106
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:418
u8 src_address[6]
Definition: packet.h:56
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:98
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
vlib_frame_t ** frame
Definition: node.h:137
bond_main_t bond_main
Definition: node.c:24
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:78
static_always_inline u32 lb_hash_hash_2_tuples(u64 k0, u32 k1)
Definition: lb_hash_hash.h:54
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:390
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:445
#define BOND_MODULO_SHORTCUT(a)
Definition: node.h:34
struct _tcp_header tcp_header_t
ip6_address_t src_address
Definition: ip6_packet.h:342
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:572
uword as_uword[16/sizeof(uword)]
Definition: ip6_packet.h:52
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:104
static uword bond_tx_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: device.c:389
#define static_always_inline
Definition: clib.h:93
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:718
u8 dst_address[6]
Definition: packet.h:55
int i32
Definition: types.h:81
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:191
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static_always_inline u32 bond_load_balance_l23(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:207
unsigned long u64
Definition: types.h:89
u32 lb_rr_last_index
Definition: node.h:148
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:74
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
vnet_device_class_t bond_dev_class
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:108
u8 admin_up
Definition: node.h:143
static_always_inline u16 * bond_locate_ethertype(ethernet_header_t *eth)
Definition: device.c:184
bond_if_per_thread_t * per_thread_info
Definition: node.h:173
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:209
static_always_inline u32 bond_load_balance_broadcast(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:131
#define foreach_bond_tx_error
Definition: device.c:27
ip4_address_pair_t address_pair
Definition: ip4_packet.h:166
#define PREDICT_FALSE(x)
Definition: clib.h:105
vnet_main_t vnet_main
Definition: misc.c:43
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:717
u32 node_index
Node index.
Definition: node.h:437
static char * bond_tx_error_strings[]
Definition: device.c:40
bond_if_t * interfaces
Definition: node.h:290
u32 * slaves
Definition: node.h:155
svmdb_client_t * c
u16 n_vectors
Definition: node.h:344
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
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)
Definition: cache.h:74
vlib_main_t * vm
Definition: buffer.c:294
ethernet_header_t ethernet
Definition: node.h:313
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:147
static u8 * format_bond_tx_trace(u8 *s, va_list *args)
Definition: device.c:47
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:588
unsigned int u32
Definition: types.h:88
static_always_inline int ethernet_frame_is_tagged(u16 type)
Definition: ethernet.h:85
static void * vlib_frame_args(vlib_frame_t *f)
Get pointer to frame scalar data.
Definition: node_funcs.h:284
static_always_inline u32 bond_load_balance_l2(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:165
VNET_DEVICE_CLASS(bond_dev_class)
u32 * active_slaves
Definition: node.h:158
static vlib_frame_t * vnet_get_frame_to_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
static_always_inline u32 bond_load_balance_active_backup(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:373
Definition: defs.h:47
static_always_inline u32 bond_load_balance_l34(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: device.c:274
u8 * format_bond_interface_name(u8 *s, va_list *args)
Definition: device.c:66
unsigned short u16
Definition: types.h:57
bond_tx_error_t
Definition: device.c:32
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:553
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
#define clib_mem_unaligned(pointer, type)
Definition: types.h:155
#define vnet_buffer(b)
Definition: buffer.h:372
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)
Definition: device.c:108
u8 data[0]
Packet data.
Definition: buffer.h:179
#define vec_foreach(var, vec)
Vector iterator.
static_always_inline u32 lb_hash_hash(u64 k0, u64 k1, u64 k2, u64 k3, u64 k4)
Definition: lb_hash_hash.h:46
u8 ip_version_and_header_length
Definition: ip4_packet.h:132
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
Definition: trace_funcs.h:159
u32 bond_sw_if_index
Definition: node.h:315
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static clib_error_t * bond_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:116
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:82
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
#define VLIB_DEVICE_TX_FUNCTION_MULTIARCH(dev, fn)
Definition: interface.h:228
ip6_address_t dst_address
Definition: ip6_packet.h:342
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:367