2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef __included_vnet_bonding_node_h__
16 #define __included_vnet_bonding_node_h__
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vppinfra/format.h>
21 #include <vppinfra/hash.h>
22 #include <vnet/ethernet/ethernet.h>
23 #include <vnet/interface.h>
25 #define LACP_FAST_PERIODIC_TIMER 1.0
26 #define LACP_SHORT_TIMOUT_TIME (LACP_FAST_PERIODIC_TIMER * 3)
27 #define LACP_SLOW_PERIODIC_TIMER 30.0
28 #define LACP_LONG_TIMOUT_TIME (LACP_SLOW_PERIODIC_TIMER * 3)
31 #define MIN(x,y) (((x)<(y))?(x):(y))
34 #define BOND_MODULO_SHORTCUT(a) \
37 #define foreach_bond_mode \
38 _ (1, ROUND_ROBIN, "round-robin") \
39 _ (2, ACTIVE_BACKUP, "active-backup") \
41 _ (4, BROADCAST, "broadcast") \
46 #define _(v, f, s) BOND_MODE_##f = v,
51 /* configurable load-balances */
52 #define foreach_bond_lb \
53 _ (2, L23, "l23", l23) \
54 _ (1, L34 , "l34", l34) \
57 /* load-balance functions implemented in bond-output */
58 #define foreach_bond_lb_algo \
60 _ (1, L34 , "l34", l34) \
61 _ (2, L23, "l23", l23) \
62 _ (3, RR, "round-robin", round_robin) \
63 _ (4, BC, "broadcast", broadcast) \
64 _ (5, AB, "active-backup", active_backup)
68 #define _(v, f, s, p) BOND_LB_##f = v,
71 } bond_load_balance_t;
75 BOND_SEND_GARP_NA = 1,
76 } bond_send_garp_na_process_event_t;
90 } bond_create_if_args_t;
94 /* slave's sw_if_index */
96 /* bond's sw_if_index */
103 } bond_enslave_args_t;
111 } bond_detach_slave_args_t;
120 } bond_set_intf_weight_args_t;
122 /** BOND interface details struct */
127 u8 interface_name[64];
133 } bond_interface_details_t;
135 /** slave interface details struct */
139 u8 interface_name[64];
145 } slave_interface_details_t;
147 typedef CLIB_PACKED (struct
151 u16 key; u16 port_priority; u16 port_number;
157 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
158 u32 buffers[VLIB_FRAME_SIZE];
160 } bond_per_port_queue_t;
164 bond_per_port_queue_t *per_port_queue;
165 } bond_per_thread_data_t;
173 /* the last slave index for the rr lb */
174 u32 lb_rr_last_index;
176 /* Real device instance in interface vector */
179 /* Interface ID being shown to user */
185 /* Configured slaves */
188 /* Slaves that are in DISTRIBUTING state */
191 /* rapidly find an active slave */
192 uword *active_slave_by_sw_if_index;
194 lacp_port_info_t partner;
195 lacp_port_info_t actor;
196 u8 individual_aggregator;
198 /* If the flag numa_only is set, it means that only slaves
199 on local numa node works for lacp mode if have at least one,
200 otherwise it works as usual. */
203 /* How many slaves on local numa node are there in lacp mode? */
207 uword *port_number_bitmap;
211 clib_spinlock_t lockp;
216 u8 persistent_hw_address[6];
218 /* neighbor's vlib software interface index */
221 /* Neighbor time-to-live (usually 3s) */
224 /* 1 = interface is configured with long timeout (60s) */
227 /* 1 = debug is on; 0 = debug is off */
230 /* tx packet template id for this neighbor */
231 u8 packet_template_index;
233 /* Info we actually keep about each neighbor */
235 /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
236 u8 last_packet_signature_valid;
237 uword last_packet_signature;
239 /* last received lacp packet, for the J-hash optimization */
242 /* last marker packet */
245 /* neighbor vlib hw_if_index */
248 /* weight -- valid only for active backup */
251 /* actor does not initiate the protocol exchange */
254 /* Partner port information */
255 lacp_port_info_t partner;
256 lacp_port_info_t partner_admin;;
258 /* Actor port information */
259 lacp_port_info_t actor;
260 lacp_port_info_t actor_admin;
262 /* Need To Transmit flag */
265 /* Link has been established and Aggregate Port is operable */
268 /* Initialization or reinitialization of the lacp protocol entity */
271 /* Aggregation Port is operating the lacp */
274 /* MUX to indicate to the Selection Logic wait_while_timer expired */
277 /* Selection Logic indicates al Aggregation Ports attached */
280 /* Selection Logic selected an Aggregator */
283 /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
286 /* timer used to detect whether received protocol information has expired */
287 f64 current_while_timer;
289 /* timer used to detect actor churn states */
290 f64 actor_churn_timer;
292 /* time last lacpdu was sent */
293 f64 last_lacpdu_sent_time;
295 /* time last lacpdu was received */
296 f64 last_lacpdu_recd_time;
298 /* time last marker pdu was sent */
299 f64 last_marker_pdu_sent_time;
301 /* time last marker pdu was received */
302 f64 last_marker_pdu_recd_time;
304 /* timer used to generate periodic transmission */
307 /* timer used to detect partner churn states */
308 f64 partner_churn_timer;
310 /* provides hysteresis before performing an aggregation change */
311 f64 wait_while_timer;
313 /* Implemention variables, not in the spec */
319 /* actor admin key */
324 u32 bif_dev_instance;
331 /* good lacp pdu received */
334 /* bad lacp pdu received */
335 u64 bad_pdu_received;
340 /* good marker pdu received */
341 u64 marker_pdu_received;
343 /* bad marker pdu received */
344 u64 marker_bad_pdu_received;
349 /* slave is numa node */
353 typedef void (*lacp_enable_disable_func) (vlib_main_t * vm, bond_if_t * bif,
354 slave_if_t * sif, u8 enable);
358 /* pool of bonding interfaces */
359 bond_if_t *interfaces;
361 /* record used interface IDs */
364 /* pool of slave interfaces */
365 slave_if_t *neighbors;
367 /* rapidly find a bond by vlib software interface index */
368 uword *bond_by_sw_if_index;
370 /* convenience variables */
371 vlib_main_t *vlib_main;
372 vnet_main_t *vnet_main;
374 /* lacp plugin is loaded */
375 u8 lacp_plugin_loaded;
377 lacp_enable_disable_func lacp_enable_disable;
379 uword *slave_by_sw_if_index;
381 bond_per_thread_data_t *per_thread_data;
386 /* bond packet trace capture */
389 ethernet_header_t ethernet;
391 u32 bond_sw_if_index;
392 } bond_packet_trace_t;
394 typedef u32 (*load_balance_func) (vlib_main_t * vm,
395 vlib_node_runtime_t * node, bond_if_t * bif,
396 vlib_buffer_t * b0, uword slave_count);
400 load_balance_func load_balance;
401 } bond_load_balance_func_t;
403 extern vlib_node_registration_t bond_input_node;
404 extern vlib_node_registration_t bond_process_node;
405 extern vnet_device_class_t bond_dev_class;
406 extern bond_main_t bond_main;
408 void bond_disable_collecting_distributing (vlib_main_t * vm,
410 void bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif);
411 u8 *format_bond_interface_name (u8 * s, va_list * args);
413 void bond_set_intf_weight (vlib_main_t * vm,
414 bond_set_intf_weight_args_t * args);
415 void bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args);
416 int bond_delete_if (vlib_main_t * vm, u32 sw_if_index);
417 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
418 void bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args);
419 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
420 int bond_dump_slave_ifs (slave_interface_details_t ** out_slaveids,
421 u32 bond_sw_if_index);
424 unformat_bond_mode (unformat_input_t * input, va_list * args)
426 u8 *r = va_arg (*args, u8 *);
429 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
439 format_bond_mode (u8 * s, va_list * args)
441 u32 i = va_arg (*args, u32);
446 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
450 return format (s, "unknown");
452 return format (s, "%s", t);
456 unformat_bond_load_balance (unformat_input_t * input, va_list * args)
458 u8 *r = va_arg (*args, u8 *);
461 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
471 format_bond_load_balance (u8 * s, va_list * args)
473 u32 i = va_arg (*args, u32);
478 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
482 return format (s, "unknown");
484 return format (s, "%s", t);
488 bond_register_callback (lacp_enable_disable_func func)
490 bond_main_t *bm = &bond_main;
492 bm->lacp_plugin_loaded = 1;
493 bm->lacp_enable_disable = func;
496 static inline bond_if_t *
497 bond_get_master_by_sw_if_index (u32 sw_if_index)
499 bond_main_t *bm = &bond_main;
502 p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
507 return pool_elt_at_index (bm->interfaces, p[0]);
510 static inline bond_if_t *
511 bond_get_master_by_dev_instance (u32 dev_instance)
513 bond_main_t *bm = &bond_main;
515 return pool_elt_at_index (bm->interfaces, dev_instance);
518 static inline slave_if_t *
519 bond_get_slave_by_sw_if_index (u32 sw_if_index)
521 bond_main_t *bm = &bond_main;
525 if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
527 p = bm->slave_by_sw_if_index[sw_if_index];
529 sif = pool_elt_at_index (bm->neighbors, p >> 1);
535 #endif /* __included_vnet_bonding_node_h__ */
538 * fd.io coding-style-patch-verification: ON
541 * eval: (c-set-style "gnu")