blob: d4aa4a7fd3151f5c7b10179154db32148765c426 [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,
Steven18c0f222018-03-26 21:52:11 -0700101 bond_if_t * bif, vlib_buffer_t * b0,
102 uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800103{
104 vnet_main_t *vnm = vnet_get_main ();
105 vlib_buffer_t *c0;
106 int i;
107 u32 *to_next = 0;
108 u32 sw_if_index;
109 vlib_frame_t *f;
110
111
Steven18c0f222018-03-26 21:52:11 -0700112 for (i = 1; i < slave_count; i++)
Steven9cd2d7a2017-12-20 12:43:01 -0800113 {
114 sw_if_index = *vec_elt_at_index (bif->active_slaves, i);
115 f = vnet_get_frame_to_sw_interface (vnm, sw_if_index);
116 to_next = vlib_frame_vector_args (f);
117 to_next += f->n_vectors;
118 c0 = vlib_buffer_copy (vm, b0);
119 if (PREDICT_TRUE (c0 != 0))
120 {
121 vnet_buffer (c0)->sw_if_index[VLIB_TX] = sw_if_index;
122 to_next[0] = vlib_get_buffer_index (vm, c0);
123 f->n_vectors++;
124 vnet_put_frame_to_sw_interface (vnm, sw_if_index, f);
125 }
126 }
127
128 return 0;
129}
130
131static inline u32
132bond_load_balance_l2 (vlib_main_t * vm, vlib_node_runtime_t * node,
Steven18c0f222018-03-26 21:52:11 -0700133 bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800134{
135 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
136 u32 a = 0, b = 0, c = 0, t1, t2;
137 u16 t11, t22;
138
139 memcpy (&t1, eth->src_address, sizeof (t1));
140 memcpy (&t11, &eth->src_address[4], sizeof (t11));
141 a = t1 ^ t11;
142
143 memcpy (&t2, eth->dst_address, sizeof (t2));
144 memcpy (&t22, &eth->dst_address[4], sizeof (t22));
145 b = t2 ^ t22;
146
147 hash_v3_mix32 (a, b, c);
148 hash_v3_finalize32 (a, b, c);
149
Steven18c0f222018-03-26 21:52:11 -0700150 return c % slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800151}
152
153static inline u16 *
154bond_locate_ethertype (ethernet_header_t * eth)
155{
156 u16 *ethertype_p;
157 ethernet_vlan_header_t *vlan;
158
159 if (!ethernet_frame_is_tagged (clib_net_to_host_u16 (eth->type)))
160 {
161 ethertype_p = &eth->type;
162 }
163 else
164 {
165 vlan = (void *) (eth + 1);
166 ethertype_p = &vlan->type;
167 if (*ethertype_p == ntohs (ETHERNET_TYPE_VLAN))
168 {
169 vlan++;
170 ethertype_p = &vlan->type;
171 }
172 }
173 return ethertype_p;
174}
175
176static inline u32
177bond_load_balance_l23 (vlib_main_t * vm, vlib_node_runtime_t * node,
Steven18c0f222018-03-26 21:52:11 -0700178 bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800179{
180 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
181 u8 ip_version;
182 ip4_header_t *ip4;
183 u16 ethertype, *ethertype_p;
184
185 ethertype_p = bond_locate_ethertype (eth);
186 ethertype = *ethertype_p;
187
188 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
189 (ethertype != htons (ETHERNET_TYPE_IP6)))
Steven18c0f222018-03-26 21:52:11 -0700190 return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
Steven9cd2d7a2017-12-20 12:43:01 -0800191
192 ip4 = (ip4_header_t *) (ethertype_p + 1);
193 ip_version = (ip4->ip_version_and_header_length >> 4);
194
195 if (ip_version == 0x4)
196 {
197 u16 t11, t22;
198 u32 a = 0, b = 0, c = 0, t1, t2;
199
200 memcpy (&t1, eth->src_address, sizeof (t1));
201 memcpy (&t11, &eth->src_address[4], sizeof (t11));
202 a = t1 ^ t11;
203
204 memcpy (&t2, eth->dst_address, sizeof (t2));
205 memcpy (&t22, &eth->dst_address[4], sizeof (t22));
206 b = t2 ^ t22;
207
208 c = ip4->src_address.data_u32 ^ ip4->dst_address.data_u32;
209
210 hash_v3_mix32 (a, b, c);
211 hash_v3_finalize32 (a, b, c);
212
Steven18c0f222018-03-26 21:52:11 -0700213 return c % slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800214 }
215 else if (ip_version == 0x6)
216 {
217 u64 a, b, c;
218 u64 t1 = 0, t2 = 0;
219 ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
220
221 memcpy (&t1, eth->src_address, sizeof (eth->src_address));
222 memcpy (&t2, eth->dst_address, sizeof (eth->dst_address));
223 a = t1 ^ t2;
224
225 b = (ip6->src_address.as_u64[0] ^ ip6->src_address.as_u64[1]);
226 c = (ip6->dst_address.as_u64[0] ^ ip6->dst_address.as_u64[1]);
227
228 hash_mix64 (a, b, c);
Steven18c0f222018-03-26 21:52:11 -0700229 return c % slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800230 }
Steven18c0f222018-03-26 21:52:11 -0700231 return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
Steven9cd2d7a2017-12-20 12:43:01 -0800232}
233
234static inline u32
235bond_load_balance_l34 (vlib_main_t * vm, vlib_node_runtime_t * node,
Steven18c0f222018-03-26 21:52:11 -0700236 bond_if_t * bif, vlib_buffer_t * b0, uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800237{
238 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
239 u8 ip_version;
240 uword is_tcp_udp = 0;
241 ip4_header_t *ip4;
242 u16 ethertype, *ethertype_p;
243
244 ethertype_p = bond_locate_ethertype (eth);
245 ethertype = *ethertype_p;
246
247 if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
248 (ethertype != htons (ETHERNET_TYPE_IP6)))
Steven18c0f222018-03-26 21:52:11 -0700249 return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
Steven9cd2d7a2017-12-20 12:43:01 -0800250
251 ip4 = (ip4_header_t *) (ethertype_p + 1);
252 ip_version = (ip4->ip_version_and_header_length >> 4);
253
254 if (ip_version == 0x4)
255 {
256 u32 a = 0, b = 0, c = 0, t1, t2;
257 tcp_header_t *tcp = (void *) (ip4 + 1);
258 is_tcp_udp = (ip4->protocol == IP_PROTOCOL_TCP) ||
259 (ip4->protocol == IP_PROTOCOL_UDP);
260
261 a = ip4->src_address.data_u32 ^ ip4->dst_address.data_u32;
262
263 t1 = is_tcp_udp ? tcp->src : 0;
264 t2 = is_tcp_udp ? tcp->dst : 0;
265 b = t1 + (t2 << 16);
266
267 hash_v3_mix32 (a, b, c);
268 hash_v3_finalize32 (a, b, c);
269
Steven18c0f222018-03-26 21:52:11 -0700270 return c % slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800271 }
272 else if (ip_version == 0x6)
273 {
274 u64 a, b, c;
275 u64 t1, t2;
276 ip6_header_t *ip6 = (ip6_header_t *) (eth + 1);
277 tcp_header_t *tcp = (void *) (ip6 + 1);
278
279 if (PREDICT_TRUE ((ip6->protocol == IP_PROTOCOL_TCP) ||
280 (ip6->protocol == IP_PROTOCOL_UDP)))
281 {
282 is_tcp_udp = 1;
283 tcp = (void *) (ip6 + 1);
284 }
285 else if (ip6->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
286 {
287 ip6_hop_by_hop_header_t *hbh =
288 (ip6_hop_by_hop_header_t *) (ip6 + 1);
289 if ((hbh->protocol == IP_PROTOCOL_TCP)
290 || (hbh->protocol == IP_PROTOCOL_UDP))
291 {
292 is_tcp_udp = 1;
293 tcp = (tcp_header_t *) ((u8 *) hbh + ((hbh->length + 1) << 3));
294 }
295 }
296 a = (ip6->src_address.as_u64[0] ^ ip6->src_address.as_u64[1]);
297 b = (ip6->dst_address.as_u64[0] ^ ip6->dst_address.as_u64[1]);
298
299 t1 = is_tcp_udp ? tcp->src : 0;
300 t2 = is_tcp_udp ? tcp->dst : 0;
301 c = (t2 << 16) | t1;
302 hash_mix64 (a, b, c);
303
Steven18c0f222018-03-26 21:52:11 -0700304 return c % slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800305 }
306
Steven18c0f222018-03-26 21:52:11 -0700307 return (bond_load_balance_l2 (vm, node, bif, b0, slave_count));
Steven9cd2d7a2017-12-20 12:43:01 -0800308}
309
310static inline u32
311bond_load_balance_round_robin (vlib_main_t * vm,
312 vlib_node_runtime_t * node,
Steven18c0f222018-03-26 21:52:11 -0700313 bond_if_t * bif, vlib_buffer_t * b0,
314 uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800315{
316 bif->lb_rr_last_index++;
Steven18c0f222018-03-26 21:52:11 -0700317 bif->lb_rr_last_index %= slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800318
319 return bif->lb_rr_last_index;
320}
321
322static inline u32
323bond_load_balance_active_backup (vlib_main_t * vm,
324 vlib_node_runtime_t * node,
Steven18c0f222018-03-26 21:52:11 -0700325 bond_if_t * bif, vlib_buffer_t * b0,
326 uword slave_count)
Steven9cd2d7a2017-12-20 12:43:01 -0800327{
328 /* First interface is the active, the rest is backup */
329 return 0;
330}
331
332static bond_load_balance_func_t bond_load_balance_table[] = {
333#define _(v,f,s, p) { bond_load_balance_##p },
334 foreach_bond_lb_algo
335#undef _
336};
337
338static uword
339bond_tx_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
340 vlib_frame_t * frame)
341{
342 vnet_interface_output_runtime_t *rund = (void *) node->runtime_data;
343 bond_main_t *bm = &bond_main;
344 bond_if_t *bif = pool_elt_at_index (bm->interfaces, rund->dev_instance);
345 u32 bi0, bi1, bi2, bi3;
346 vlib_buffer_t *b0, *b1, *b2, *b3;
347 u32 *from = vlib_frame_vector_args (frame);
348 u32 n_left_from;
349 ethernet_header_t *eth;
350 u32 next0 = 0, next1 = 0, next2 = 0, next3 = 0;
351 u32 port, port1, port2, port3;
352 u32 sw_if_index, sw_if_index1, sw_if_index2, sw_if_index3;
353 bond_packet_trace_t *t0;
354 uword n_trace = vlib_get_trace_count (vm, node);
355 u16 thread_index = vlib_get_thread_index ();
356 vnet_main_t *vnm = vnet_get_main ();
Stevena005e7f2018-03-22 17:46:58 -0700357 u32 *to_next;
Steven9cd2d7a2017-12-20 12:43:01 -0800358 u32 sif_if_index, sif_if_index1, sif_if_index2, sif_if_index3;
Stevena005e7f2018-03-22 17:46:58 -0700359 vlib_frame_t *f;
Steven18c0f222018-03-26 21:52:11 -0700360 uword slave_count;
Steven9cd2d7a2017-12-20 12:43:01 -0800361
362 if (PREDICT_FALSE (bif->admin_up == 0))
363 {
364 vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
365 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters +
366 VNET_INTERFACE_COUNTER_DROP,
367 thread_index, bif->sw_if_index,
368 frame->n_vectors);
369 vlib_error_count (vm, node->node_index, BOND_TX_ERROR_IF_DOWN,
370 frame->n_vectors);
371 return frame->n_vectors;
372 }
373
Stevena005e7f2018-03-22 17:46:58 -0700374 clib_spinlock_lock_if_init (&bif->lockp);
Steven18c0f222018-03-26 21:52:11 -0700375 slave_count = vec_len (bif->active_slaves);
376 if (PREDICT_FALSE (slave_count == 0))
Steven9cd2d7a2017-12-20 12:43:01 -0800377 {
378 bi0 = from[0];
379 b0 = vlib_get_buffer (vm, bi0);
380 vlib_increment_combined_counter
381 (vnet_main.interface_main.combined_sw_if_counters
382 + VNET_INTERFACE_COUNTER_TX, thread_index, bif->sw_if_index,
383 frame->n_vectors, b0->current_length);
384
385 vlib_buffer_free (vm, vlib_frame_args (frame), frame->n_vectors);
386 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters +
387 VNET_INTERFACE_COUNTER_DROP,
388 thread_index, bif->sw_if_index,
389 frame->n_vectors);
390 vlib_error_count (vm, node->node_index, BOND_TX_ERROR_NO_SLAVE,
391 frame->n_vectors);
Stevena005e7f2018-03-22 17:46:58 -0700392 clib_spinlock_unlock_if_init (&bif->lockp);
Steven9cd2d7a2017-12-20 12:43:01 -0800393 return frame->n_vectors;
394 }
395
Steven18c0f222018-03-26 21:52:11 -0700396 vec_validate_aligned (bif->per_thread_info[thread_index].frame, slave_count,
397 CLIB_CACHE_LINE_BYTES);
Stevena005e7f2018-03-22 17:46:58 -0700398
Steven9cd2d7a2017-12-20 12:43:01 -0800399 /* Number of buffers / pkts */
400 n_left_from = frame->n_vectors;
401
Stevena005e7f2018-03-22 17:46:58 -0700402 while (n_left_from > 0)
Steven9cd2d7a2017-12-20 12:43:01 -0800403 {
Stevena005e7f2018-03-22 17:46:58 -0700404 while (n_left_from >= 4)
Steven9cd2d7a2017-12-20 12:43:01 -0800405 {
Stevena005e7f2018-03-22 17:46:58 -0700406 // Prefetch next iteration
407 if (n_left_from >= 8)
Steven9cd2d7a2017-12-20 12:43:01 -0800408 {
Stevena005e7f2018-03-22 17:46:58 -0700409 vlib_buffer_t *p4, *p5, *p6, *p7;
410
411 p4 = vlib_get_buffer (vm, from[4]);
412 p5 = vlib_get_buffer (vm, from[5]);
413 p6 = vlib_get_buffer (vm, from[6]);
414 p7 = vlib_get_buffer (vm, from[7]);
415
416 vlib_prefetch_buffer_header (p4, STORE);
417 vlib_prefetch_buffer_header (p5, STORE);
418 vlib_prefetch_buffer_header (p6, STORE);
419 vlib_prefetch_buffer_header (p7, STORE);
420
421 CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, LOAD);
422 CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, LOAD);
423 CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, LOAD);
424 CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, LOAD);
425 }
426
427 bi0 = from[0];
428 bi1 = from[1];
429 bi2 = from[2];
430 bi3 = from[3];
431
432 b0 = vlib_get_buffer (vm, bi0);
433 b1 = vlib_get_buffer (vm, bi1);
434 b2 = vlib_get_buffer (vm, bi2);
435 b3 = vlib_get_buffer (vm, bi3);
436
437 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
438 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1);
439 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b2);
440 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b3);
441
442 sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
443 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
444 sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
445 sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
446
447 port =
448 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
Steven18c0f222018-03-26 21:52:11 -0700449 b0, slave_count);
Stevena005e7f2018-03-22 17:46:58 -0700450 port1 =
451 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
Steven18c0f222018-03-26 21:52:11 -0700452 b1, slave_count);
Stevena005e7f2018-03-22 17:46:58 -0700453 port2 =
454 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
Steven18c0f222018-03-26 21:52:11 -0700455 b2, slave_count);
Stevena005e7f2018-03-22 17:46:58 -0700456 port3 =
457 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
Steven18c0f222018-03-26 21:52:11 -0700458 b3, slave_count);
Stevena005e7f2018-03-22 17:46:58 -0700459
460 sif_if_index = *vec_elt_at_index (bif->active_slaves, port);
461 sif_if_index1 = *vec_elt_at_index (bif->active_slaves, port1);
462 sif_if_index2 = *vec_elt_at_index (bif->active_slaves, port2);
463 sif_if_index3 = *vec_elt_at_index (bif->active_slaves, port3);
464
465 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
466 vnet_buffer (b1)->sw_if_index[VLIB_TX] = sif_if_index1;
467 vnet_buffer (b2)->sw_if_index[VLIB_TX] = sif_if_index2;
468 vnet_buffer (b3)->sw_if_index[VLIB_TX] = sif_if_index3;
469
470 if (bif->per_thread_info[thread_index].frame[port] == 0)
471 bif->per_thread_info[thread_index].frame[port] =
472 vnet_get_frame_to_sw_interface (vnm, sif_if_index);
473
474 if (bif->per_thread_info[thread_index].frame[port1] == 0)
475 bif->per_thread_info[thread_index].frame[port1] =
476 vnet_get_frame_to_sw_interface (vnm, sif_if_index1);
477
478 if (bif->per_thread_info[thread_index].frame[port2] == 0)
479 bif->per_thread_info[thread_index].frame[port2] =
480 vnet_get_frame_to_sw_interface (vnm, sif_if_index2);
481
482 if (bif->per_thread_info[thread_index].frame[port3] == 0)
483 bif->per_thread_info[thread_index].frame[port3] =
484 vnet_get_frame_to_sw_interface (vnm, sif_if_index3);
485
486 f = bif->per_thread_info[thread_index].frame[port];
487 to_next = vlib_frame_vector_args (f);
488 to_next += f->n_vectors;
489 to_next[0] = vlib_get_buffer_index (vm, b0);
490 f->n_vectors++;
491
492 f = bif->per_thread_info[thread_index].frame[port1];
493 to_next = vlib_frame_vector_args (f);
494 to_next += f->n_vectors;
495 to_next[0] = vlib_get_buffer_index (vm, b1);
496 f->n_vectors++;
497
498 f = bif->per_thread_info[thread_index].frame[port2];
499 to_next = vlib_frame_vector_args (f);
500 to_next += f->n_vectors;
501 to_next[0] = vlib_get_buffer_index (vm, b2);
502 f->n_vectors++;
503
504 f = bif->per_thread_info[thread_index].frame[port3];
505 to_next = vlib_frame_vector_args (f);
506 to_next += f->n_vectors;
507 to_next[0] = vlib_get_buffer_index (vm, b3);
508 f->n_vectors++;
509
510 if (PREDICT_FALSE (n_trace > 0))
511 {
512 vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
Steven9cd2d7a2017-12-20 12:43:01 -0800513 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700514 t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
515 eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
Steven9cd2d7a2017-12-20 12:43:01 -0800516 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700517 t0->sw_if_index = sw_if_index;
518 t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
Steven9cd2d7a2017-12-20 12:43:01 -0800519
520 if (PREDICT_TRUE (n_trace > 0))
521 {
Stevena005e7f2018-03-22 17:46:58 -0700522 vlib_trace_buffer (vm, node, next1, b1,
Steven9cd2d7a2017-12-20 12:43:01 -0800523 0 /* follow_chain */ );
524 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700525 t0 = vlib_add_trace (vm, node, b1, sizeof (*t0));
526 eth = (ethernet_header_t *) vlib_buffer_get_current (b1);
Steven9cd2d7a2017-12-20 12:43:01 -0800527 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700528 t0->sw_if_index = sw_if_index1;
Steven9cd2d7a2017-12-20 12:43:01 -0800529 t0->bond_sw_if_index =
Stevena005e7f2018-03-22 17:46:58 -0700530 vnet_buffer (b1)->sw_if_index[VLIB_TX];
Steven9cd2d7a2017-12-20 12:43:01 -0800531
532 if (PREDICT_TRUE (n_trace > 0))
533 {
Stevena005e7f2018-03-22 17:46:58 -0700534 vlib_trace_buffer (vm, node, next2, b2,
Steven9cd2d7a2017-12-20 12:43:01 -0800535 0 /* follow_chain */ );
536 vlib_set_trace_count (vm, node, --n_trace);
Stevena005e7f2018-03-22 17:46:58 -0700537 t0 = vlib_add_trace (vm, node, b2, sizeof (*t0));
Steven9cd2d7a2017-12-20 12:43:01 -0800538 eth =
Stevena005e7f2018-03-22 17:46:58 -0700539 (ethernet_header_t *) vlib_buffer_get_current (b2);
Steven9cd2d7a2017-12-20 12:43:01 -0800540 t0->ethernet = *eth;
Stevena005e7f2018-03-22 17:46:58 -0700541 t0->sw_if_index = sw_if_index2;
Steven9cd2d7a2017-12-20 12:43:01 -0800542 t0->bond_sw_if_index =
Stevena005e7f2018-03-22 17:46:58 -0700543 vnet_buffer (b2)->sw_if_index[VLIB_TX];
544
545 if (PREDICT_TRUE (n_trace > 0))
546 {
547 vlib_trace_buffer (vm, node, next3, b3,
548 0 /* follow_chain */ );
549 vlib_set_trace_count (vm, node, --n_trace);
550 t0 = vlib_add_trace (vm, node, b3, sizeof (*t0));
551 eth =
552 (ethernet_header_t *)
553 vlib_buffer_get_current (b3);
554 t0->ethernet = *eth;
555 t0->sw_if_index = sw_if_index3;
556 t0->bond_sw_if_index =
557 vnet_buffer (b3)->sw_if_index[VLIB_TX];
558 }
Steven9cd2d7a2017-12-20 12:43:01 -0800559 }
560 }
561 }
Stevena005e7f2018-03-22 17:46:58 -0700562 from += 4;
563 n_left_from -= 4;
Steven9cd2d7a2017-12-20 12:43:01 -0800564 }
565
Stevena005e7f2018-03-22 17:46:58 -0700566 while (n_left_from > 0)
567 {
568 // Prefetch next iteration
569 if (n_left_from > 1)
570 {
571 vlib_buffer_t *p2;
572
573 p2 = vlib_get_buffer (vm, from[1]);
574 vlib_prefetch_buffer_header (p2, STORE);
575 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
576 }
577
578 bi0 = from[0];
579 b0 = vlib_get_buffer (vm, bi0);
580
581 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
582
583 sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
584
585 port =
586 (bond_load_balance_table[bif->lb]).load_balance (vm, node, bif,
Steven18c0f222018-03-26 21:52:11 -0700587 b0, slave_count);
Stevena005e7f2018-03-22 17:46:58 -0700588 sif_if_index = *vec_elt_at_index (bif->active_slaves, port);
589 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sif_if_index;
590 if (bif->per_thread_info[thread_index].frame[port] == 0)
591 bif->per_thread_info[thread_index].frame[port] =
592 vnet_get_frame_to_sw_interface (vnm, sif_if_index);
593 f = bif->per_thread_info[thread_index].frame[port];
594 to_next = vlib_frame_vector_args (f);
595 to_next += f->n_vectors;
596 to_next[0] = vlib_get_buffer_index (vm, b0);
597 f->n_vectors++;
598
599 if (PREDICT_FALSE (n_trace > 0))
600 {
601 vlib_trace_buffer (vm, node, next0, b0, 0 /* follow_chain */ );
602 vlib_set_trace_count (vm, node, --n_trace);
603 t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
604 eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
605 t0->ethernet = *eth;
606 t0->sw_if_index = sw_if_index;
607 t0->bond_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
608 }
609
610 from += 1;
611 n_left_from -= 1;
612 }
Steven9cd2d7a2017-12-20 12:43:01 -0800613 }
614
Steven18c0f222018-03-26 21:52:11 -0700615 for (port = 0; port < slave_count; port++)
Steven9cd2d7a2017-12-20 12:43:01 -0800616 {
Stevena005e7f2018-03-22 17:46:58 -0700617 f = bif->per_thread_info[thread_index].frame[port];
618 if (f == 0)
619 continue;
Steven9cd2d7a2017-12-20 12:43:01 -0800620
Stevena005e7f2018-03-22 17:46:58 -0700621 sw_if_index = *vec_elt_at_index (bif->active_slaves, port);
622 vnet_put_frame_to_sw_interface (vnm, sw_if_index, f);
623 bif->per_thread_info[thread_index].frame[port] = 0;
Steven9cd2d7a2017-12-20 12:43:01 -0800624 }
625
626 vlib_increment_simple_counter (vnet_main.interface_main.sw_if_counters
627 + VNET_INTERFACE_COUNTER_TX, thread_index,
628 bif->sw_if_index, frame->n_vectors);
629
Stevena005e7f2018-03-22 17:46:58 -0700630 clib_spinlock_unlock_if_init (&bif->lockp);
Steven9cd2d7a2017-12-20 12:43:01 -0800631 return frame->n_vectors;
632}
633
634/* *INDENT-OFF* */
635VNET_DEVICE_CLASS (bond_dev_class) = {
636 .name = "bond",
637 .tx_function = bond_tx_fn,
638 .tx_function_n_errors = BOND_TX_N_ERROR,
639 .tx_function_error_strings = bond_tx_error_strings,
640 .format_device_name = format_bond_interface_name,
641 .admin_up_down_function = bond_interface_admin_up_down,
642 .subif_add_del_function = bond_subif_add_del_function,
643 .format_tx_trace = format_bond_tx_trace,
644};
645
646VLIB_DEVICE_TX_FUNCTION_MULTIARCH (bond_dev_class, bond_tx_fn)
647/* *INDENT-ON* */
648
649/*
650 * fd.io coding-style-patch-verification: ON
651 *
652 * Local Variables:
653 * eval: (c-set-style "gnu")
654 * End:
655 */