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) \
35 (((a) == 2) || ((a) == 4) || ((a) == 8) || ((a) == 16))
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;
88 } bond_create_if_args_t;
92 /* slave's sw_if_index */
94 /* bond's sw_if_index */
101 } bond_enslave_args_t;
109 } bond_detach_slave_args_t;
111 /** BOND interface details struct */
115 u8 interface_name[64];
120 } bond_interface_details_t;
122 /** slave interface details struct */
126 u8 interface_name[64];
130 } slave_interface_details_t;
132 typedef CLIB_PACKED (struct
136 u16 key; u16 port_priority; u16 port_number;
142 vlib_frame_t **frame;
144 } bond_if_per_thread_t;
152 /* the last slave index for the rr lb */
153 u32 lb_rr_last_index;
159 /* Configured slaves */
162 /* Slaves that are in DISTRIBUTING state */
165 /* rapidly find an active slave */
166 uword *active_slave_by_sw_if_index;
168 lacp_port_info_t partner;
169 lacp_port_info_t actor;
170 u8 individual_aggregator;
173 uword *port_number_bitmap;
177 clib_spinlock_t lockp;
178 bond_if_per_thread_t *per_thread_info;
183 u8 persistent_hw_address[6];
185 /* neighbor's vlib software interface index */
188 /* Neighbor time-to-live (usually 3s) */
191 /* 1 = interface is configured with long timeout (60s) */
194 /* 1 = debug is on; 0 = debug is off */
197 /* tx packet template id for this neighbor */
198 u8 packet_template_index;
200 /* Info we actually keep about each neighbor */
202 /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
203 u8 last_packet_signature_valid;
204 uword last_packet_signature;
206 /* last received lacp packet, for the J-hash optimization */
209 /* last marker packet */
212 /* neighbor vlib hw_if_index */
215 /* actor does not initiate the protocol exchange */
218 /* Partner port information */
219 lacp_port_info_t partner;
220 lacp_port_info_t partner_admin;;
222 /* Partner port information */
223 lacp_port_info_t actor;
224 lacp_port_info_t actor_admin;
226 /* Need To Transmit flag */
229 /* Link has been established and Aggregate Port is operable */
232 /* Initialization or reinitialization of the lacp protocol entity */
235 /* Aggregation Port is operating the lacp */
238 /* MUX to indicate to the Selection Logic wait_while_timer expired */
241 /* Selection Logic indicates al Aggregation Ports attached */
244 /* Selection Logic selected an Aggregator */
247 /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
250 /* timer used to detect whether received protocol information has expired */
251 f64 current_while_timer;
253 /* timer used to detect actor churn states */
254 f64 actor_churn_timer;
256 /* time last lacpdu was sent */
257 f64 last_lacpdu_time;
259 /* timer used to generate periodic transmission */
262 /* timer used to detect partner churn states */
263 f64 partner_churn_timer;
265 /* provides hysteresis before performing an aggregation change */
266 f64 wait_while_timer;
268 /* Implemention variables, not in the spec */
274 /* actor admin key */
279 u32 bif_dev_instance;
286 clib_spinlock_t lockp;
289 typedef void (*lacp_enable_disable_func) (vlib_main_t * vm, bond_if_t * bif,
290 slave_if_t * sif, u8 enable);
294 /* pool of bonding interfaces */
295 bond_if_t *interfaces;
297 /* pool of lacp neighbors */
298 slave_if_t *neighbors;
300 /* rapidly find a bond by vlib software interface index */
301 uword *bond_by_sw_if_index;
303 /* convenience variables */
304 vlib_main_t *vlib_main;
305 vnet_main_t *vnet_main;
307 /* lacp plugin is loaded */
308 u8 lacp_plugin_loaded;
310 lacp_enable_disable_func lacp_enable_disable;
312 uword *slave_by_sw_if_index;
315 /* bond packet trace capture */
318 ethernet_header_t ethernet;
320 u32 bond_sw_if_index;
321 } bond_packet_trace_t;
323 typedef u32 (*load_balance_func) (vlib_main_t * vm,
324 vlib_node_runtime_t * node, bond_if_t * bif,
325 vlib_buffer_t * b0, uword slave_count);
329 load_balance_func load_balance;
330 } bond_load_balance_func_t;
332 extern vlib_node_registration_t bond_input_node;
333 extern vlib_node_registration_t bond_process_node;
334 extern vnet_device_class_t bond_dev_class;
335 extern bond_main_t bond_main;
337 void bond_disable_collecting_distributing (vlib_main_t * vm,
339 void bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif);
340 u8 *format_bond_interface_name (u8 * s, va_list * args);
342 void bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args);
343 int bond_delete_if (vlib_main_t * vm, u32 sw_if_index);
344 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
345 void bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args);
346 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
347 int bond_dump_slave_ifs (slave_interface_details_t ** out_slaveids,
348 u32 bond_sw_if_index);
351 unformat_bond_mode (unformat_input_t * input, va_list * args)
353 u8 *r = va_arg (*args, u8 *);
356 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
366 format_bond_mode (u8 * s, va_list * args)
368 u32 i = va_arg (*args, u32);
373 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
377 return format (s, "unknown");
379 return format (s, "%s", t);
383 unformat_bond_load_balance (unformat_input_t * input, va_list * args)
385 u8 *r = va_arg (*args, u8 *);
388 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
398 format_bond_load_balance (u8 * s, va_list * args)
400 u32 i = va_arg (*args, u32);
405 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
409 return format (s, "unknown");
411 return format (s, "%s", t);
415 bond_register_callback (lacp_enable_disable_func func)
417 bond_main_t *bm = &bond_main;
419 bm->lacp_plugin_loaded = 1;
420 bm->lacp_enable_disable = func;
423 static inline bond_if_t *
424 bond_get_master_by_sw_if_index (u32 sw_if_index)
426 bond_main_t *bm = &bond_main;
429 p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
434 return pool_elt_at_index (bm->interfaces, p[0]);
437 static inline bond_if_t *
438 bond_get_master_by_dev_instance (u32 dev_instance)
440 bond_main_t *bm = &bond_main;
442 return pool_elt_at_index (bm->interfaces, dev_instance);
445 static inline slave_if_t *
446 bond_get_slave_by_sw_if_index (u32 sw_if_index)
448 bond_main_t *bm = &bond_main;
452 if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
454 p = bm->slave_by_sw_if_index[sw_if_index];
456 sif = pool_elt_at_index (bm->neighbors, p >> 1);
462 #endif /* __included_vnet_bonding_node_h__ */
465 * fd.io coding-style-patch-verification: ON
468 * eval: (c-set-style "gnu")