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;
89 } bond_create_if_args_t;
93 /* slave's sw_if_index */
95 /* bond's sw_if_index */
102 } bond_enslave_args_t;
110 } bond_detach_slave_args_t;
112 /** BOND interface details struct */
117 u8 interface_name[64];
122 } bond_interface_details_t;
124 /** slave interface details struct */
128 u8 interface_name[64];
132 } slave_interface_details_t;
134 typedef CLIB_PACKED (struct
138 u16 key; u16 port_priority; u16 port_number;
144 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
145 u32 buffers[VLIB_FRAME_SIZE];
147 } bond_per_port_queue_t;
151 bond_per_port_queue_t *per_port_queue;
152 } bond_per_thread_data_t;
160 /* the last slave index for the rr lb */
161 u32 lb_rr_last_index;
163 /* Real device instance in interface vector */
166 /* Interface ID being shown to user */
172 /* Configured slaves */
175 /* Slaves that are in DISTRIBUTING state */
178 /* rapidly find an active slave */
179 uword *active_slave_by_sw_if_index;
181 lacp_port_info_t partner;
182 lacp_port_info_t actor;
183 u8 individual_aggregator;
186 uword *port_number_bitmap;
190 clib_spinlock_t lockp;
195 u8 persistent_hw_address[6];
197 /* neighbor's vlib software interface index */
200 /* Neighbor time-to-live (usually 3s) */
203 /* 1 = interface is configured with long timeout (60s) */
206 /* 1 = debug is on; 0 = debug is off */
209 /* tx packet template id for this neighbor */
210 u8 packet_template_index;
212 /* Info we actually keep about each neighbor */
214 /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
215 u8 last_packet_signature_valid;
216 uword last_packet_signature;
218 /* last received lacp packet, for the J-hash optimization */
221 /* last marker packet */
224 /* neighbor vlib hw_if_index */
227 /* actor does not initiate the protocol exchange */
230 /* Partner port information */
231 lacp_port_info_t partner;
232 lacp_port_info_t partner_admin;;
234 /* Partner port information */
235 lacp_port_info_t actor;
236 lacp_port_info_t actor_admin;
238 /* Need To Transmit flag */
241 /* Link has been established and Aggregate Port is operable */
244 /* Initialization or reinitialization of the lacp protocol entity */
247 /* Aggregation Port is operating the lacp */
250 /* MUX to indicate to the Selection Logic wait_while_timer expired */
253 /* Selection Logic indicates al Aggregation Ports attached */
256 /* Selection Logic selected an Aggregator */
259 /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
262 /* timer used to detect whether received protocol information has expired */
263 f64 current_while_timer;
265 /* timer used to detect actor churn states */
266 f64 actor_churn_timer;
268 /* time last lacpdu was sent */
269 f64 last_lacpdu_sent_time;
271 /* time last lacpdu was received */
272 f64 last_lacpdu_recd_time;
274 /* time last marker pdu was sent */
275 f64 last_marker_pdu_sent_time;
277 /* time last marker pdu was received */
278 f64 last_marker_pdu_recd_time;
280 /* timer used to generate periodic transmission */
283 /* timer used to detect partner churn states */
284 f64 partner_churn_timer;
286 /* provides hysteresis before performing an aggregation change */
287 f64 wait_while_timer;
289 /* Implemention variables, not in the spec */
295 /* actor admin key */
300 u32 bif_dev_instance;
307 /* good lacp pdu received */
310 /* bad lacp pdu received */
311 u64 bad_pdu_received;
316 /* good marker pdu received */
317 u64 marker_pdu_received;
319 /* bad marker pdu received */
320 u64 marker_bad_pdu_received;
326 typedef void (*lacp_enable_disable_func) (vlib_main_t * vm, bond_if_t * bif,
327 slave_if_t * sif, u8 enable);
331 /* pool of bonding interfaces */
332 bond_if_t *interfaces;
334 /* record used interface IDs */
337 /* pool of slave interfaces */
338 slave_if_t *neighbors;
340 /* rapidly find a bond by vlib software interface index */
341 uword *bond_by_sw_if_index;
343 /* convenience variables */
344 vlib_main_t *vlib_main;
345 vnet_main_t *vnet_main;
347 /* lacp plugin is loaded */
348 u8 lacp_plugin_loaded;
350 lacp_enable_disable_func lacp_enable_disable;
352 uword *slave_by_sw_if_index;
354 bond_per_thread_data_t *per_thread_data;
357 /* bond packet trace capture */
360 ethernet_header_t ethernet;
362 u32 bond_sw_if_index;
363 } bond_packet_trace_t;
365 typedef u32 (*load_balance_func) (vlib_main_t * vm,
366 vlib_node_runtime_t * node, bond_if_t * bif,
367 vlib_buffer_t * b0, uword slave_count);
371 load_balance_func load_balance;
372 } bond_load_balance_func_t;
374 extern vlib_node_registration_t bond_input_node;
375 extern vlib_node_registration_t bond_process_node;
376 extern vnet_device_class_t bond_dev_class;
377 extern bond_main_t bond_main;
379 void bond_disable_collecting_distributing (vlib_main_t * vm,
381 void bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif);
382 u8 *format_bond_interface_name (u8 * s, va_list * args);
384 void bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args);
385 int bond_delete_if (vlib_main_t * vm, u32 sw_if_index);
386 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
387 void bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args);
388 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
389 int bond_dump_slave_ifs (slave_interface_details_t ** out_slaveids,
390 u32 bond_sw_if_index);
393 unformat_bond_mode (unformat_input_t * input, va_list * args)
395 u8 *r = va_arg (*args, u8 *);
398 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
408 format_bond_mode (u8 * s, va_list * args)
410 u32 i = va_arg (*args, u32);
415 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
419 return format (s, "unknown");
421 return format (s, "%s", t);
425 unformat_bond_load_balance (unformat_input_t * input, va_list * args)
427 u8 *r = va_arg (*args, u8 *);
430 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
440 format_bond_load_balance (u8 * s, va_list * args)
442 u32 i = va_arg (*args, u32);
447 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
451 return format (s, "unknown");
453 return format (s, "%s", t);
457 bond_register_callback (lacp_enable_disable_func func)
459 bond_main_t *bm = &bond_main;
461 bm->lacp_plugin_loaded = 1;
462 bm->lacp_enable_disable = func;
465 static inline bond_if_t *
466 bond_get_master_by_sw_if_index (u32 sw_if_index)
468 bond_main_t *bm = &bond_main;
471 p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
476 return pool_elt_at_index (bm->interfaces, p[0]);
479 static inline bond_if_t *
480 bond_get_master_by_dev_instance (u32 dev_instance)
482 bond_main_t *bm = &bond_main;
484 return pool_elt_at_index (bm->interfaces, dev_instance);
487 static inline slave_if_t *
488 bond_get_slave_by_sw_if_index (u32 sw_if_index)
490 bond_main_t *bm = &bond_main;
494 if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
496 p = bm->slave_by_sw_if_index[sw_if_index];
498 sif = pool_elt_at_index (bm->neighbors, p >> 1);
504 #endif /* __included_vnet_bonding_node_h__ */
507 * fd.io coding-style-patch-verification: ON
510 * eval: (c-set-style "gnu")