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;
91 } bond_create_if_args_t;
95 /* member's sw_if_index */
97 /* bond's sw_if_index */
104 } bond_add_member_args_t;
112 } bond_detach_member_args_t;
121 } bond_set_intf_weight_args_t;
123 /** BOND interface details struct */
128 u8 interface_name[64];
134 } bond_interface_details_t;
136 /** member interface details struct */
140 u8 interface_name[64];
146 } member_interface_details_t;
148 typedef CLIB_PACKED (struct
152 u16 key; u16 port_priority; u16 port_number;
158 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
159 u32 buffers[VLIB_FRAME_SIZE];
161 } bond_per_port_queue_t;
165 bond_per_port_queue_t *per_port_queue;
166 } bond_per_thread_data_t;
174 /* the last member index for the rr lb */
175 u32 lb_rr_last_index;
177 /* Real device instance in interface vector */
180 /* Interface ID being shown to user */
186 /* Configured members */
189 /* Members that are in DISTRIBUTING state */
192 lacp_port_info_t partner;
193 lacp_port_info_t actor;
194 u8 individual_aggregator;
196 /* If the flag numa_only is set, it means that only members
197 on local numa node works for lacp mode if have at least one,
198 otherwise it works as usual. */
202 /* How many members on local numa node are there in lacp mode? */
206 uword *port_number_bitmap;
210 clib_spinlock_t lockp;
215 u8 persistent_hw_address[6];
217 /* neighbor's vlib software interface index */
220 /* Neighbor time-to-live (usually 3s) */
223 /* 1 = interface is configured with long timeout (60s) */
226 /* 1 = debug is on; 0 = debug is off */
229 /* tx packet template id for this neighbor */
230 u8 packet_template_index;
232 /* Info we actually keep about each neighbor */
234 /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
235 u8 last_packet_signature_valid;
236 uword last_packet_signature;
238 /* last received lacp packet, for the J-hash optimization */
241 /* last marker packet */
244 /* neighbor vlib hw_if_index */
247 /* weight -- valid only for active backup */
250 /* actor does not initiate the protocol exchange */
253 /* Partner port information */
254 lacp_port_info_t partner;
255 lacp_port_info_t partner_admin;;
257 /* Actor port information */
258 lacp_port_info_t actor;
259 lacp_port_info_t actor_admin;
261 /* Need To Transmit flag */
264 /* Link has been established and Aggregate Port is operable */
267 /* Initialization or reinitialization of the lacp protocol entity */
270 /* Aggregation Port is operating the lacp */
273 /* MUX to indicate to the Selection Logic wait_while_timer expired */
276 /* Selection Logic indicates al Aggregation Ports attached */
279 /* Selection Logic selected an Aggregator */
282 /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
285 /* timer used to detect whether received protocol information has expired */
286 f64 current_while_timer;
288 /* timer used to detect actor churn states */
289 f64 actor_churn_timer;
291 /* time last lacpdu was sent */
292 f64 last_lacpdu_sent_time;
294 /* time last lacpdu was received */
295 f64 last_lacpdu_recd_time;
297 /* time last marker pdu was sent */
298 f64 last_marker_pdu_sent_time;
300 /* time last marker pdu was received */
301 f64 last_marker_pdu_recd_time;
303 /* timer used to generate periodic transmission */
306 /* timer used to detect partner churn states */
307 f64 partner_churn_timer;
309 /* provides hysteresis before performing an aggregation change */
310 f64 wait_while_timer;
312 /* Implemention variables, not in the spec */
318 /* actor admin key */
323 u32 bif_dev_instance;
330 /* good lacp pdu received */
333 /* bad lacp pdu received */
334 u64 bad_pdu_received;
339 /* good marker pdu received */
340 u64 marker_pdu_received;
342 /* bad marker pdu received */
343 u64 marker_bad_pdu_received;
348 /* member is numa node */
352 typedef void (*lacp_enable_disable_func) (vlib_main_t * vm, bond_if_t * bif,
353 member_if_t * mif, u8 enable);
363 /* pool of bonding interfaces */
364 bond_if_t *interfaces;
366 /* record used interface IDs */
369 /* pool of member interfaces */
370 member_if_t *neighbors;
372 /* rapidly find a bond by vlib software interface index */
373 uword *bond_by_sw_if_index;
375 /* convenience variables */
376 vlib_main_t *vlib_main;
377 vnet_main_t *vnet_main;
379 /* lacp plugin is loaded */
380 u8 lacp_plugin_loaded;
382 lacp_enable_disable_func lacp_enable_disable;
384 uword *member_by_sw_if_index;
386 bond_per_thread_data_t *per_thread_data;
388 lacp_stats_t **stats;
391 /* bond packet trace capture */
394 ethernet_header_t ethernet;
396 u32 bond_sw_if_index;
397 } bond_packet_trace_t;
399 typedef u32 (*load_balance_func) (vlib_main_t * vm,
400 vlib_node_runtime_t * node, bond_if_t * bif,
401 vlib_buffer_t * b0, uword member_count);
405 load_balance_func load_balance;
406 } bond_load_balance_func_t;
408 extern vlib_node_registration_t bond_input_node;
409 extern vlib_node_registration_t bond_process_node;
410 extern vnet_device_class_t bond_dev_class;
411 extern bond_main_t bond_main;
413 void bond_disable_collecting_distributing (vlib_main_t * vm,
415 void bond_enable_collecting_distributing (vlib_main_t * vm,
417 u8 *format_bond_interface_name (u8 * s, va_list * args);
419 void bond_set_intf_weight (vlib_main_t * vm,
420 bond_set_intf_weight_args_t * args);
421 void bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args);
422 int bond_delete_if (vlib_main_t * vm, u32 sw_if_index);
423 void bond_add_member (vlib_main_t * vm, bond_add_member_args_t * args);
424 void bond_detach_member (vlib_main_t * vm, bond_detach_member_args_t * args);
425 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
426 int bond_dump_member_ifs (member_interface_details_t ** out_memberids,
427 u32 bond_sw_if_index);
430 unformat_bond_mode (unformat_input_t * input, va_list * args)
432 u8 *r = va_arg (*args, u8 *);
435 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
445 format_bond_mode (u8 * s, va_list * args)
447 u32 i = va_arg (*args, u32);
452 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
456 return format (s, "unknown");
458 return format (s, "%s", t);
462 unformat_bond_load_balance (unformat_input_t * input, va_list * args)
464 u8 *r = va_arg (*args, u8 *);
467 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
477 format_bond_load_balance (u8 * s, va_list * args)
479 u32 i = va_arg (*args, u32);
484 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
488 return format (s, "unknown");
490 return format (s, "%s", t);
494 bond_register_callback (lacp_enable_disable_func func)
496 bond_main_t *bm = &bond_main;
498 bm->lacp_plugin_loaded = 1;
499 bm->lacp_enable_disable = func;
502 static inline bond_if_t *
503 bond_get_bond_if_by_sw_if_index (u32 sw_if_index)
505 bond_main_t *bm = &bond_main;
508 p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
513 return pool_elt_at_index (bm->interfaces, p[0]);
516 static inline bond_if_t *
517 bond_get_bond_if_by_dev_instance (u32 dev_instance)
519 bond_main_t *bm = &bond_main;
521 return pool_elt_at_index (bm->interfaces, dev_instance);
524 static inline member_if_t *
525 bond_get_member_by_sw_if_index (u32 sw_if_index)
527 bond_main_t *bm = &bond_main;
528 member_if_t *mif = 0;
531 if (sw_if_index < vec_len (bm->member_by_sw_if_index))
533 p = bm->member_by_sw_if_index[sw_if_index];
535 mif = pool_elt_at_index (bm->neighbors, p >> 1);
541 #endif /* __included_vnet_bonding_node_h__ */
544 * fd.io coding-style-patch-verification: ON
547 * eval: (c-set-style "gnu")