blob: cebfd694ac624f3127945594b4e71a3b6d923453 [file] [log] [blame]
Steven9cd2d7a2017-12-20 12:43:01 -08001/*
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>
23#include <vnet/ip/ip6_hop_by_hop_packet.h>
24#include <vnet/bonding/node.h>
25
26#define foreach_bond_tx_error \
27 _(NONE, "no error") \
28 _(IF_DOWN, "interface down") \
29 _(NO_SLAVE, "no slave")
30
31typedef enum
32{
33#define _(f,s) BOND_TX_ERROR_##f,
34 foreach_bond_tx_error
35#undef _
36 BOND_TX_N_ERROR,
37} bond_tx_error_t;
38
39static char *bond_tx_error_strings[] = {
40#define _(n,s) s,
41 foreach_bond_tx_error
42#undef _
43};
44
45static u8 *
46format_bond_tx_trace (u8 * s, va_list * args)
47{
48 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
49 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
50 bond_packet_trace_t *t = va_arg (*args, bond_packet_trace_t *);
51 vnet_hw_interface_t *hw, *hw1;
52 vnet_main_t *vnm = vnet_get_main ();
53
54 hw = vnet_get_sup_hw_interface (vnm, t->sw_if_index);
55 hw1 = vnet_get_sup_hw_interface (vnm, t->bond_sw_if_index);
56 s = format (s, "src %U, dst %U, %s -> %s",
57 format_ethernet_address, t->ethernet.src_address,
58 format_ethernet_address, t->ethernet.dst_address,
59 hw->name, hw1->name);
60
61 return s;
62}
63
64u8 *
65format_bond_interface_name (u8 * s, va_list * args)
66{
67 u32 dev_instance = va_arg (*args, u32);
68 bond_main_t *bm = &bond_main;
69 bond_if_t *bif = pool_elt_at_index (bm->interfaces, dev_instance);
70
71 s = format (s, "BondEthernet%lu", bif->dev_instance);
72
73 return s;
74}
75
76static __clib_unused clib_error_t *
77bond_subif_add_del_function (vnet_main_t * vnm, u32 hw_if_index,
78 struct vnet_sw_interface_t *st, int is_add)
79{
80 /* Nothing for now */
81 return 0;
82}
83
84static clib_error_t *
85bond_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
86{
87 vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
88 uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
89 bond_main_t *bm = &bond_main;
90 bond_if_t *bif = pool_elt_at_index (bm->interfaces, hif->dev_instance);
91
92 bif->admin_up = is_up;
93 if (is_up && vec_len (bif->active_slaves))
94 vnet_hw_interface_set_flags (vnm, bif->hw_if_index,
95 VNET_HW_INTERFACE_FLAG_LINK_UP);
96 return 0;
97}
98
99static inline u32
100bond_load_balance_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node,
101 bond_if_t * bif, vlib_buffer_t * b0)
102{
103 vnet_main_t *vnm = vnet_get_main ();
104 vlib_buffer_t *c0;
105 int i;
106 u32 *to_next = 0;
107 u32 sw_if_index;
108 vlib_frame_t *f;
109
110
111 for (i = 1; i < vec_len (bif->active_slaves); i++)
112 {
113 sw_if_index = *vec_elt_at_index (bif->active_slaves, i);
114 f = vnet_get_frame_to_sw_interface (vnm, sw_if_index);
115 to_next = vlib_frame_vector_args (f);
116 to_next += f->n_vectors;
117 c0 = vlib_buffer_copy (vm, b0);
118 if (PREDICT_TRUE (c0 != 0))
119 {
120 vnet_buffer (c0)->sw_if_index[VLIB_TX] = sw_if_index;
121 to_next[0] = vlib_get_buffer_index (vm, c0);
122 f->n_vectors++;
123 vnet_put_frame_to_sw_interface (vnm, sw_if_index, f);
124 }
125 }
126
127 return 0;
128}
129
130static inline u32
131bond_load_balance_l2 (vlib_main_t * vm, vlib_node_runtime_t * node,
132 bond_if_t * bif, vlib_buffer_t * b0)
133{
134 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
135 u32 a = 0, b = 0, c = 0, t1, t2;
136 u16 t11, t22;
137
138 memcpy (&t1, eth->src_address, sizeof (t1));
139 memcpy (&t11, &eth->src_address[4], sizeof (t11));
140 a = t1 ^ t11;
141
142 memcpy (&t2, eth->dst_address, sizeof (t2));
143 memcpy (&t22, &eth->dst_address[4], sizeof (t22));
144 b = t2 ^ t22;
145
146 hash_v3_mix32 (a, b, c);
147 hash_v3_finalize32 (a, b, c);
148
149 return c % vec_len (bif->active_slaves);
150}
151
152static inline u16 *
153bond_locate_ethertype (ethernet_header_t * eth)
154{
155 u16 *ethertype_p;
156 ethernet_vlan_header_t *vlan;
157
158 if (!ethernet_frame_is_tagged (clib_net_to_host_u16 (eth->type)))
159 {
160 ethertype_p = &eth->type;
161 }
162 else
163 {
164 vlan = (void *) (eth + 1);
165 ethertype_p = &vlan->type;
166 if (*ethertype_p == ntohs (ETHERNET_TYPE_VLAN))
167 {
168 vlan++;
169 ethertype_p = &vlan->type;
170 }
171 }
172 return ethertype_p;
173}
174
175static inline u32
176bond_load_balance_l23 (vlib_main_t * vm, vlib_node_runtime_t * node,
177 bond_if_t * bif, vlib_buffer_t * b0)
178{
179 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
180 u8 ip_version;
181 ip4_header_t *ip4;
182 u16 ethertype, *ethertype_p;
183
184 ethertype_p = bond_locate_ethertype (eth);
185 ethertype = *ethertype_p;
186
187 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
188 (ethertype != htons (ETHERNET_TYPE_IP6)))
189 return (bond_load_balance_l2 (vm, node, bif, b0));
190
191 ip4 = (ip4_header_t *) (ethertype_p + 1);
192 ip_version = (ip4->ip_version_and_header_length >> 4);
193
194 if (ip_version == 0x4)
195 {
196 u16 t11, t22;
197 u32 a = 0, b = 0, c = 0, t1, t2;
198
199 memcpy (&t1, eth->src_address, sizeof (t1));
200 memcpy (&t11, &eth->src_address[4], sizeof (t11));
201 a = t1 ^ t11;
202
203 memcpy (&t2, eth->dst_address, sizeof (t2));
204 memcpy (&t22, &eth->dst_address[4], sizeof (t22));
205 b = t2 ^ t22;
206
207 c = ip4->src_address.data_u32 ^ ip4->dst_address.data_u32;
208
209 hash_v3_mix32 (a, b, c);
210 hash_v3_finalize32 (a, b, c);
211
212 return c % vec_len (bif->active_slaves);
213 }
214 else if (ip_version == 0x6)
215 {
216 u64 a, b, c;
217 u64 t1 = 0, t2 = 0;
218 ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
219
220 memcpy (&t1, eth->src_address, sizeof (eth->src_address));
221 memcpy (&t2, eth->dst_address, sizeof (eth->dst_address));
222 a = t1 ^ t2;
223
224 b = (ip6->src_address.as_u64[0] ^ ip6->src_address.as_u64[1]);
225 c = (ip6->dst_address.as_u64[0] ^ ip6->dst_address.as_u64[1]);
226
227 hash_mix64 (a, b, c);
228 return c % vec_len (bif->active_slaves);
229 }
230 return (bond_load_balance_l2 (vm, node, bif, b0));
231}
232
233static inline u32
234bond_load_balance_l34 (vlib_main_t * vm, vlib_node_runtime_t * node,
235 bond_if_t * bif, vlib_buffer_t * b0)
236{
237 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
238 u8 ip_version;
239 uword is_tcp_udp = 0;
240 ip4_header_t *ip4;
241 u16 ethertype, *ethertype_p;
242
243 ethertype_p = bond_locate_ethertype (eth);
244 ethertype = *ethertype_p;
245
246 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
247 (ethertype != htons (ETHERNET_TYPE_IP6)))
248 return (bond_load_balance_l2 (vm, node, bif, b0));
249
250 ip4 = (ip4_header_t *) (ethertype_p + 1);
251 ip_version = (ip4->ip_version_and_header_length >> 4);
252
253 if (ip_version == 0x4)
254 {
255 u32 a = 0, b = 0, c = 0, t1, t2;
256 tcp_header_t *tcp = (void *) (ip4 + 1);
257 is_tcp_udp = (ip4->protocol == IP_PROTOCOL_TCP) ||
258 (ip4->protocol == IP_PROTOCOL_UDP);
259
260 a = ip4->src_address.data_u32 ^ ip4->dst_address.data_u32;
261
262 t1 = is_tcp_udp ? tcp->src : 0;
263 t2 = is_tcp_udp ? tcp->dst : 0;
264 b = t1 + (t2 << 16);
265
266 hash_v3_mix32 (a, b, c);
267 hash_v3_finalize32 (a, b, c);
268
269 return c % vec_len (bif->active_slaves);
270 }
271 else if (ip_version == 0x6)
272 {
273 u64 a, b, c;
274 u64 t1, t2;
275 ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
276 tcp_header_t *tcp = (void *) (ip6 + 1);
277
278 if (PREDICT_TRUE ((ip6->protocol == IP_PROTOCOL_TCP) ||
279 (ip6->protocol == IP_PROTOCOL_UDP)))
280 {
281 is_tcp_udp = 1;
282 tcp = (void *) (ip6 + 1);
283 }
284 else if (ip6->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
285 {
286 ip6_hop_by_hop_header_t *hbh =
287 (ip6_hop_by_hop_header_t *) (ip6 + 1);
288 if ((hbh->protocol == IP_PROTOCOL_TCP)
289 || (hbh->protocol == IP_PROTOCOL_UDP))
290 {
291 is_tcp_udp = 1;
292 tcp = (tcp_header_t *) ((u8 *) hbh + ((hbh->length + 1) << 3));
293 }
294 }
295 a = (ip6->src_address.as_u64[0] ^ ip6->src_address.as_u64[1]);
296 b = (ip6->dst_address.as_u64[0] ^ ip6->dst_address.as_u64[1]);
297
298 t1 = is_tcp_udp ? tcp->src : 0;
299 t2 = is_tcp_udp ? tcp->dst : 0;
300 c = (t2 << 16) | t1;
301 hash_mix64 (a, b, c);
302
303 return c % vec_len (bif->active_slaves);
304 }
305
306 return (bond_load_balance_l2 (vm, node, bif, b0));
307}
308
309static inline u32
310bond_load_balance_round_robin (vlib_main_t * vm,
311 vlib_node_runtime_t * node,
312 bond_if_t * bif, vlib_buffer_t * b0)
313{
314 bif->lb_rr_last_index++;
315 bif->lb_rr_last_index %= vec_len (bif->active_slaves);
316
317 return bif->lb_rr_last_index;
318}
319
320static inline u32
321bond_load_balance_active_backup (vlib_main_t * vm,
322 vlib_node_runtime_t * node,
323 bond_if_t * bif, vlib_buffer_t * b0)
324{
325 /* First interface is the active, the rest is backup */
326 return 0;
327}
328
329static bond_load_balance_func_t bond_load_balance_table[] = {
330#define _(v,f,s, p) { bond_load_balance_##p },
331 foreach_bond_lb_algo
332#undef _
333};
334
335static uword
336bond_tx_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
337 vlib_frame_t * frame)
338{
339 vnet_interface_output_runtime_t *rund = (void *) node->runtime_data;
340 bond_main_t *bm = &bond_main;
341 bond_if_t *bif = pool_elt_at_index (bm->interfaces, rund->dev_instance);
342 u32 bi0, bi1, bi2, bi3;
343 vlib_buffer_t *b0, *b1, *b2, *b3;
344 u32 *from = vlib_frame_vector_args (frame);
345 u32 n_left_from;
346 ethernet_header_t *eth;
347 u32 next0 = 0, next1 = 0, next2 = 0, next3 = 0;
348 u32 port, port1, port2, port3;
349 u32 sw_if_index, sw_if_index1, sw_if_index2, sw_if_index3;
350 bond_packet_trace_t *t0;
351 uword n_trace = vlib_get_trace_count (vm, node);
352 u16 thread_index = vlib_get_thread_index ();
353 vnet_main_t *vnm = vnet_get_main ();
Stevena005e7f2018-03-22 17:46:58 -0700354 u32 *to_next;
Steven9cd2d7a2017-12-20 12:43:01 -0800355 u32 sif_if_index, sif_if_index1, sif_if_index2, sif_if_index3;
Stevena005e7f2018-03-22 17:46:58 -0700356 vlib_frame_t *f;
Steven9cd2d7a2017-12-20 12:43:01 -0800357
358 if (PREDICT_FALSE (bif->admin_up == 0))
359 {
360 vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
361 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters +
362 VNET_INTERFACE_COUNTER_DROP,
363 thread_index, bif->sw_if_index,
364 frame->n_vectors);
365 vlib_error_count (vm, node->node_index, BOND_TX_ERROR_IF_DOWN,
366 frame->n_vectors);
367 return frame->n_vectors;
368 }
369
Stevena005e7f2018-03-22 17:46:58 -0700370 clib_spinlock_lock_if_init (&bif->lockp);
Steven9cd2d7a2017-12-20 12:43:01 -0800371 if (PREDICT_FALSE (vec_len (bif->active_slaves) == 0))
372 {
373 bi0 = from[0];
374 b0 = vlib_get_buffer (vm, bi0);
375 vlib_increment_combined_counter
376 (vnet_main.interface_main.combined_sw_if_counters
377 + VNET_INTERFACE_COUNTER_TX, thread_index, bif->sw_if_index,
378 frame->n_vectors, b0->current_length);
379
380 vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
381 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters +
382 VNET_INTERFACE_COUNTER_DROP,
383 thread_index, bif->sw_if_index,
384 frame->n_vectors);
385 vlib_error_count (vm, node->node_index, BOND_TX_ERROR_NO_SLAVE,
386 frame->n_vectors);
Stevena005e7f2018-03-22 17:46:58 -0700387 clib_spinlock_unlock_if_init (&bif->lockp);
Steven9cd2d7a2017-12-20 12:43:01 -0800388 return frame->n_vectors;
389 }
390
Stevena005e7f2018-03-22 17:46:58 -0700391 vec_validate_aligned (bif->per_thread_info[thread_index].frame,
392 vec_len (bif->active_slaves), CLIB_CACHE_LINE_BYTES);
393
Steven9cd2d7a2017-12-20 12:43:01 -0800394 /* Number of buffers / pkts */
395 n_left_from = frame->n_vectors;
396
Stevena005e7f2018-03-22 17:46:58 -0700397 while (n_left_from > 0)
Steven9cd2d7a2017-12-20 12:43:01 -0800398 {
Stevena005e7f2018-03-22 17:46:58 -0700399 while (n_left_from >= 4)
Steven9cd2d7a2017-12-20 12:43:01 -0800400 {
Stevena005e7f2018-03-22 17:46:58 -0700401 // Prefetch next iteration
402 if (n_left_from >= 8)
Steven9cd2d7a2017-12-20 12:43:01 -0800403 {
Stevena005e7f2018-03-22 17:46:58 -0700404 vlib_buffer_t *p4, *p5, *p6, *p7;
405
406 p4 = vlib_get_buffer (vm, from[4]);
407 p5 = vlib_get_buffer (vm, from[5]);
408 p6 = vlib_get_buffer (vm, from[6]);
409 p7 = vlib_get_buffer (vm, from[7]);
410
411 vlib_prefetch_buffer_header (p4, STORE);
412 vlib_prefetch_buffer_header (p5, STORE);
413 vlib_prefetch_buffer_header (p6, STORE);
414 vlib_prefetch_buffer_header (p7, STORE);
415
416 CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, LOAD);
417 CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, LOAD);
418 CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, LOAD);
419 CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, LOAD);
420 }
421
422 bi0 = from[0];
423 bi1 = from[1];
424 bi2 = from[2];
425 bi3 = from[3];
426
427 b0 = vlib_get_buffer (vm, bi0);
428 b1 = vlib_get_buffer (vm, bi1);
429 b2 = vlib_get_buffer (vm, bi2);
430 b3 = vlib_get_buffer (vm, bi3);
431
432 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
433 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1);
434 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b2);
435 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b3);
436
437 sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
438 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
439 sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
440 sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
441
442 port =
443 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
444 b0);
445 port1 =
446 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
447 b1);
448 port2 =
449 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
450 b2);
451 port3 =
452 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
453 b3);
454
455 sif_if_index = *vec_elt_at_index (bif->active_slaves, port);
456 sif_if_index1 = *vec_elt_at_index (bif->active_slaves, port1);
457 sif_if_index2 = *vec_elt_at_index (bif->active_slaves, port2);
458 sif_if_index3 = *vec_elt_at_index (bif->active_slaves, port3);
459
460 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
461 vnet_buffer (b1)->sw_if_index[VLIB_TX] = sif_if_index1;
462 vnet_buffer (b2)->sw_if_index[VLIB_TX] = sif_if_index2;
463 vnet_buffer (b3)->sw_if_index[VLIB_TX] = sif_if_index3;
464
465 if (bif->per_thread_info[thread_index].frame[port] == 0)
466 bif->per_thread_info[thread_index].frame[port] =
467 vnet_get_frame_to_sw_interface (vnm, sif_if_index);
468
469 if (bif->per_thread_info[thread_index].frame[port1] == 0)
470 bif->per_thread_info[thread_index].frame[port1] =
471 vnet_get_frame_to_sw_interface (vnm, sif_if_index1);
472
473 if (bif->per_thread_info[thread_index].frame[port2] == 0)
474 bif->per_thread_info[thread_index].frame[port2] =
475 vnet_get_frame_to_sw_interface (vnm, sif_if_index2);
476
477 if (bif->per_thread_info[thread_index].frame[port3] == 0)
478 bif->per_thread_info[thread_index].frame[port3] =
479 vnet_get_frame_to_sw_interface (vnm, sif_if_index3);
480
481 f = bif->per_thread_info[thread_index].frame[port];
482 to_next = vlib_frame_vector_args (f);
483 to_next += f->n_vectors;
484 to_next[0] = vlib_get_buffer_index (vm, b0);
485 f->n_vectors++;
486
487 f = bif->per_thread_info[thread_index].frame[port1];
488 to_next = vlib_frame_vector_args (f);
489 to_next += f->n_vectors;
490 to_next[0] = vlib_get_buffer_index (vm, b1);
491 f->n_vectors++;
492
493 f = bif->per_thread_info[thread_index].frame[port2];
494 to_next = vlib_frame_vector_args (f);
495 to_next += f->n_vectors;
496 to_next[0] = vlib_get_buffer_index (vm, b2);
497 f->n_vectors++;
498
499 f = bif->per_thread_info[thread_index].frame[port3];
500 to_next = vlib_frame_vector_args (f);
501 to_next += f->n_vectors;
502 to_next[0] = vlib_get_buffer_index (vm, b3);
503 f->n_vectors++;
504
505 if (PREDICT_FALSE (n_trace > 0))
506 {
507 vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
Steven9cd2d7a2017-12-20 12:43:01 -0800508 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700509 t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
510 eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
Steven9cd2d7a2017-12-20 12:43:01 -0800511 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700512 t0->sw_if_index = sw_if_index;
513 t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
Steven9cd2d7a2017-12-20 12:43:01 -0800514
515 if (PREDICT_TRUE (n_trace > 0))
516 {
Stevena005e7f2018-03-22 17:46:58 -0700517 vlib_trace_buffer (vm, node, next1, b1,
Steven9cd2d7a2017-12-20 12:43:01 -0800518 0 /* follow_chain */ );
519 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700520 t0 = vlib_add_trace (vm, node, b1, sizeof (*t0));
521 eth = (ethernet_header_t *) vlib_buffer_get_current (b1);
Steven9cd2d7a2017-12-20 12:43:01 -0800522 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700523 t0->sw_if_index = sw_if_index1;
Steven9cd2d7a2017-12-20 12:43:01 -0800524 t0->bond_sw_if_index =
Stevena005e7f2018-03-22 17:46:58 -0700525 vnet_buffer (b1)->sw_if_index[VLIB_TX];
Steven9cd2d7a2017-12-20 12:43:01 -0800526
527 if (PREDICT_TRUE (n_trace > 0))
528 {
Stevena005e7f2018-03-22 17:46:58 -0700529 vlib_trace_buffer (vm, node, next2, b2,
Steven9cd2d7a2017-12-20 12:43:01 -0800530 0 /* follow_chain */ );
531 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700532 t0 = vlib_add_trace (vm, node, b2, sizeof (*t0));
Steven9cd2d7a2017-12-20 12:43:01 -0800533 eth =
Stevena005e7f2018-03-22 17:46:58 -0700534 (ethernet_header_t *) vlib_buffer_get_current (b2);
Steven9cd2d7a2017-12-20 12:43:01 -0800535 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700536 t0->sw_if_index = sw_if_index2;
Steven9cd2d7a2017-12-20 12:43:01 -0800537 t0->bond_sw_if_index =
Stevena005e7f2018-03-22 17:46:58 -0700538 vnet_buffer (b2)->sw_if_index[VLIB_TX];
539
540 if (PREDICT_TRUE (n_trace > 0))
541 {
542 vlib_trace_buffer (vm, node, next3, b3,
543 0 /* follow_chain */ );
544 vlib_set_trace_count (vm, node, --n_trace);
545 t0 = vlib_add_trace (vm, node, b3, sizeof (*t0));
546 eth =
547 (ethernet_header_t *)
548 vlib_buffer_get_current (b3);
549 t0->ethernet = *eth;
550 t0->sw_if_index = sw_if_index3;
551 t0->bond_sw_if_index =
552 vnet_buffer (b3)->sw_if_index[VLIB_TX];
553 }
Steven9cd2d7a2017-12-20 12:43:01 -0800554 }
555 }
556 }
Stevena005e7f2018-03-22 17:46:58 -0700557 from += 4;
558 n_left_from -= 4;
Steven9cd2d7a2017-12-20 12:43:01 -0800559 }
560
Stevena005e7f2018-03-22 17:46:58 -0700561 while (n_left_from > 0)
562 {
563 // Prefetch next iteration
564 if (n_left_from > 1)
565 {
566 vlib_buffer_t *p2;
567
568 p2 = vlib_get_buffer (vm, from[1]);
569 vlib_prefetch_buffer_header (p2, STORE);
570 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
571 }
572
573 bi0 = from[0];
574 b0 = vlib_get_buffer (vm, bi0);
575
576 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
577
578 sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
579
580 port =
581 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
582 b0);
583 sif_if_index = *vec_elt_at_index (bif->active_slaves, port);
584 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
585 if (bif->per_thread_info[thread_index].frame[port] == 0)
586 bif->per_thread_info[thread_index].frame[port] =
587 vnet_get_frame_to_sw_interface (vnm, sif_if_index);
588 f = bif->per_thread_info[thread_index].frame[port];
589 to_next = vlib_frame_vector_args (f);
590 to_next += f->n_vectors;
591 to_next[0] = vlib_get_buffer_index (vm, b0);
592 f->n_vectors++;
593
594 if (PREDICT_FALSE (n_trace > 0))
595 {
596 vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
597 vlib_set_trace_count (vm, node, --n_trace);
598 t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
599 eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
600 t0->ethernet = *eth;
601 t0->sw_if_index = sw_if_index;
602 t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
603 }
604
605 from += 1;
606 n_left_from -= 1;
607 }
Steven9cd2d7a2017-12-20 12:43:01 -0800608 }
609
Stevena005e7f2018-03-22 17:46:58 -0700610 for (port = 0; port < vec_len (bif->active_slaves); port++)
Steven9cd2d7a2017-12-20 12:43:01 -0800611 {
Stevena005e7f2018-03-22 17:46:58 -0700612 f = bif->per_thread_info[thread_index].frame[port];
613 if (f == 0)
614 continue;
Steven9cd2d7a2017-12-20 12:43:01 -0800615
Stevena005e7f2018-03-22 17:46:58 -0700616 sw_if_index = *vec_elt_at_index (bif->active_slaves, port);
617 vnet_put_frame_to_sw_interface (vnm, sw_if_index, f);
618 bif->per_thread_info[thread_index].frame[port] = 0;
Steven9cd2d7a2017-12-20 12:43:01 -0800619 }
620
621 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters
622 + VNET_INTERFACE_COUNTER_TX, thread_index,
623 bif->sw_if_index, frame->n_vectors);
624
Stevena005e7f2018-03-22 17:46:58 -0700625 clib_spinlock_unlock_if_init (&bif->lockp);
Steven9cd2d7a2017-12-20 12:43:01 -0800626 return frame->n_vectors;
627}
628
629/* *INDENT-OFF* */
630VNET_DEVICE_CLASS (bond_dev_class) = {
631 .name = "bond",
632 .tx_function = bond_tx_fn,
633 .tx_function_n_errors = BOND_TX_N_ERROR,
634 .tx_function_error_strings = bond_tx_error_strings,
635 .format_device_name = format_bond_interface_name,
636 .admin_up_down_function = bond_interface_admin_up_down,
637 .subif_add_del_function = bond_subif_add_del_function,
638 .format_tx_trace = format_bond_tx_trace,
639};
640
641VLIB_DEVICE_TX_FUNCTION_MULTIARCH (bond_dev_class, bond_tx_fn)
642/* *INDENT-ON* */
643
644/*
645 * fd.io coding-style-patch-verification: ON
646 *
647 * Local Variables:
648 * eval: (c-set-style "gnu")
649 * End:
650 */