FD.io VPP  v21.01.1
Vector Packet Processing
node.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 #ifndef __included_vnet_bonding_node_h__
16 #define __included_vnet_bonding_node_h__
17 
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>
24 
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)
29 
30 #ifndef MIN
31 #define MIN(x,y) (((x)<(y))?(x):(y))
32 #endif
33 
34 #define BOND_MODULO_SHORTCUT(a) \
35  (is_pow2 (a))
36 
37 #define foreach_bond_mode \
38  _ (1, ROUND_ROBIN, "round-robin") \
39  _ (2, ACTIVE_BACKUP, "active-backup") \
40  _ (3, XOR, "xor") \
41  _ (4, BROADCAST, "broadcast") \
42  _ (5, LACP, "lacp")
43 
44 typedef enum
45 {
46 #define _(v, f, s) BOND_MODE_##f = v,
48 #undef _
49 } bond_mode_t;
50 
51 /* configurable load-balances */
52 #define foreach_bond_lb \
53  _ (2, L23, "l23", l23) \
54  _ (1, L34 , "l34", l34) \
55  _ (0, L2, "l2", l2)
56 
57 /* load-balance functions implemented in bond-output */
58 #define foreach_bond_lb_algo \
59  _ (0, L2, "l2", l2) \
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)
65 
66 typedef enum
67 {
68 #define _(v, f, s, p) BOND_LB_##f = v,
70 #undef _
72 
73 typedef enum
74 {
77 
78 typedef struct
79 {
82  u8 hw_addr[6];
84  u8 lb;
87  /* return */
89  int rv;
92 
93 typedef struct
94 {
95  /* member's sw_if_index */
97  /* bond's sw_if_index */
101  /* return */
102  int rv;
105 
106 typedef struct
107 {
109  /* return */
110  int rv;
113 
114 typedef struct
115 {
118  /* return */
119  int rv;
122 
123 /** BOND interface details struct */
124 typedef struct
125 {
128  u8 interface_name[64];
135 
136 /** member interface details struct */
137 typedef struct
138 {
140  u8 interface_name[64];
147 
148 typedef CLIB_PACKED (struct
149  {
150  u16 system_priority;
151  u8 system[6];
152  u16 key; u16 port_priority; u16 port_number;
153  u8 state;
154  }) lacp_port_info_t;
155 
156 typedef struct
157 {
158  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
162 
163 typedef struct
164 {
167 
168 typedef struct
169 {
173 
174  /* the last member index for the rr lb */
176 
177  /* Real device instance in interface vector */
179 
180  /* Interface ID being shown to user */
182 
185 
186  /* Configured members */
188 
189  /* Members that are in DISTRIBUTING state */
191 
192  lacp_port_info_t partner;
193  lacp_port_info_t actor;
195 
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. */
201 
202  /* How many members on local numa node are there in lacp mode? */
204 
208  u8 hw_address[6];
209 
211 } bond_if_t;
212 
213 typedef struct
214 {
215  u8 persistent_hw_address[6];
216 
217  /* neighbor's vlib software interface index */
219 
220  /* Neighbor time-to-live (usually 3s) */
222 
223  /* 1 = interface is configured with long timeout (60s) */
225 
226  /* 1 = debug is on; 0 = debug is off */
228 
229  /* tx packet template id for this neighbor */
231 
232  /* Info we actually keep about each neighbor */
233 
234  /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
237 
238  /* last received lacp packet, for the J-hash optimization */
240 
241  /* last marker packet */
243 
244  /* neighbor vlib hw_if_index */
246 
247  /* weight -- valid only for active backup */
249 
250  /* actor does not initiate the protocol exchange */
252 
253  /* Partner port information */
254  lacp_port_info_t partner;
255  lacp_port_info_t partner_admin;;
256 
257  /* Actor port information */
258  lacp_port_info_t actor;
259  lacp_port_info_t actor_admin;
260 
261  /* Need To Transmit flag */
263 
264  /* Link has been established and Aggregate Port is operable */
266 
267  /* Initialization or reinitialization of the lacp protocol entity */
269 
270  /* Aggregation Port is operating the lacp */
272 
273  /* MUX to indicate to the Selection Logic wait_while_timer expired */
275 
276  /* Selection Logic indicates al Aggregation Ports attached */
278 
279  /* Selection Logic selected an Aggregator */
280  int selected;
281 
282  /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
284 
285  /* timer used to detect whether received protocol information has expired */
287 
288  /* timer used to detect actor churn states */
290 
291  /* time last lacpdu was sent */
293 
294  /* time last lacpdu was received */
296 
297  /* time last marker pdu was sent */
299 
300  /* time last marker pdu was received */
302 
303  /* timer used to generate periodic transmission */
305 
306  /* timer used to detect partner churn states */
308 
309  /* provides hysteresis before performing an aggregation change */
311 
312  /* Implemention variables, not in the spec */
313  int rx_state;
314  int tx_state;
317 
318  /* actor admin key */
320 
322 
324 
326 
327  /* bond mode */
329 
330  /* good lacp pdu received */
332 
333  /* bad lacp pdu received */
335 
336  /* pdu sent */
338 
339  /* good marker pdu received */
341 
342  /* bad marker pdu received */
344 
345  /* pdu sent */
347 
348  /* member is numa node */
350 } member_if_t;
351 
353  member_if_t * mif, u8 enable);
354 
355 typedef struct
356 {
359 } lacp_stats_t;
360 
361 typedef struct
362 {
363  /* pool of bonding interfaces */
365 
366  /* record used interface IDs */
368 
369  /* pool of member interfaces */
371 
372  /* rapidly find a bond by vlib software interface index */
374 
375  /* convenience variables */
378 
379  /* lacp plugin is loaded */
381 
383 
385 
387 
389 } bond_main_t;
390 
391 /* bond packet trace capture */
392 typedef struct
393 {
398 
401  vlib_buffer_t * b0, uword member_count);
402 
403 typedef struct
404 {
407 
411 extern bond_main_t bond_main;
412 
414  member_if_t * mif);
416  member_if_t * mif);
417 u8 *format_bond_interface_name (u8 * s, va_list * args);
418 
425 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
427  u32 bond_sw_if_index);
428 
429 static inline uword
430 unformat_bond_mode (unformat_input_t * input, va_list * args)
431 {
432  u8 *r = va_arg (*args, u8 *);
433 
434  if (0);
435 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
437 #undef _
438  else
439  return 0;
440 
441  return 1;
442 }
443 
444 static inline u8 *
445 format_bond_mode (u8 * s, va_list * args)
446 {
447  u32 i = va_arg (*args, u32);
448  u8 *t = 0;
449 
450  switch (i)
451  {
452 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
454 #undef _
455  default:
456  return format (s, "unknown");
457  }
458  return format (s, "%s", t);
459 }
460 
461 static inline uword
463 {
464  u8 *r = va_arg (*args, u8 *);
465 
466  if (0);
467 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
469 #undef _
470  else
471  return 0;
472 
473  return 1;
474 }
475 
476 static inline u8 *
477 format_bond_load_balance (u8 * s, va_list * args)
478 {
479  u32 i = va_arg (*args, u32);
480  u8 *t = 0;
481 
482  switch (i)
483  {
484 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
486 #undef _
487  default:
488  return format (s, "unknown");
489  }
490  return format (s, "%s", t);
491 }
492 
493 static inline void
495 {
496  bond_main_t *bm = &bond_main;
497 
498  bm->lacp_plugin_loaded = 1;
499  bm->lacp_enable_disable = func;
500 }
501 
502 static inline bond_if_t *
504 {
505  bond_main_t *bm = &bond_main;
506  uword *p;
507 
508  p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
509  if (!p)
510  {
511  return 0;
512  }
513  return pool_elt_at_index (bm->interfaces, p[0]);
514 }
515 
516 static inline bond_if_t *
518 {
519  bond_main_t *bm = &bond_main;
520 
521  return pool_elt_at_index (bm->interfaces, dev_instance);
522 }
523 
524 static inline member_if_t *
526 {
527  bond_main_t *bm = &bond_main;
528  member_if_t *mif = 0;
529  uword p;
530 
531  if (sw_if_index < vec_len (bm->member_by_sw_if_index))
532  {
534  if (p)
535  mif = pool_elt_at_index (bm->neighbors, p >> 1);
536  }
537 
538  return mif;
539 }
540 
541 #endif /* __included_vnet_bonding_node_h__ */
542 
543 /*
544  * fd.io coding-style-patch-verification: ON
545  *
546  * Local Variables:
547  * eval: (c-set-style "gnu")
548  * End:
549  */
void bond_set_intf_weight(vlib_main_t *vm, bond_set_intf_weight_args_t *args)
Definition: cli.c:996
u8 is_local_numa
Definition: node.h:349
vnet_main_t * vnet_main
Definition: node.h:377
bond_mode_t
Definition: node.h:44
u8 gso
Definition: node.h:200
u32 dev_instance
Definition: node.h:178
u32 group
Definition: node.h:205
u32 hw_if_index
Definition: node.h:183
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:430
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u8 begin
Definition: node.h:268
lacp_stats_t ** stats
Definition: node.h:388
u64 marker_bad_pdu_received
Definition: node.h:343
u64 marker_pdu_sent
Definition: node.h:346
u8 individual_aggregator
Definition: node.h:194
int bond_dump_member_ifs(member_interface_details_t **out_memberids, u32 bond_sw_if_index)
Definition: cli.c:212
member interface details struct
Definition: node.h:137
u8 lb
Definition: node.h:172
clib_error_t * error
Definition: node.h:90
u32 marker_tx_id
Definition: node.h:321
uword * id_used
Definition: node.h:367
unsigned long u64
Definition: types.h:89
clib_error_t * error
Definition: node.h:103
void bond_add_member(vlib_main_t *vm, bond_add_member_args_t *args)
Definition: cli.c:599
clib_error_t * error
Definition: node.h:120
u32 group
Definition: node.h:319
f64 current_while_timer
Definition: node.h:286
static bond_if_t * bond_get_bond_if_by_dev_instance(u32 dev_instance)
Definition: node.h:517
static bond_if_t * bond_get_bond_if_by_sw_if_index(u32 sw_if_index)
Definition: node.h:503
void bond_disable_collecting_distributing(vlib_main_t *vm, member_if_t *mif)
Definition: cli.c:26
u8 lacp_enabled
Definition: node.h:271
int ptx_state
Definition: node.h:316
vlib_main_t * vm
Definition: in2out_ed.c:1580
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:382
int selected
Definition: node.h:280
lacp_port_info_t partner_admin
Definition: node.h:255
struct _vnet_device_class vnet_device_class_t
u32 id
Definition: node.h:181
unsigned char u8
Definition: types.h:56
bond_per_thread_data_t * per_thread_data
Definition: node.h:386
#define foreach_bond_lb
Definition: node.h:52
u32 weight
Definition: node.h:248
double f64
Definition: types.h:142
static void bond_register_callback(lacp_enable_disable_func func)
Definition: node.h:494
u8 numa_only
Definition: node.h:199
i64 word
Definition: types.h:111
u8 ready_n
Definition: node.h:274
f64 last_lacpdu_recd_time
Definition: node.h:295
u8 use_custom_mac
Definition: node.h:207
bond_main_t bond_main
Definition: node.c:25
u32 sw_if_index
Definition: node.h:184
description fragment has unexpected format
Definition: map.api:433
vlib_main_t * vlib_main
Definition: node.h:376
lacp_port_info_t actor
Definition: node.h:193
u64 pdu_received
Definition: node.h:331
unsigned int u32
Definition: types.h:88
u32 lb_rr_last_index
Definition: node.h:175
#define VLIB_FRAME_SIZE
Definition: node.h:378
u8 is_long_timeout
Definition: node.h:224
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:377
bond_load_balance_t
Definition: node.h:66
#define hash_get(h, key)
Definition: hash.h:249
vnet_device_class_t bond_dev_class
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
u8 admin_up
Definition: node.h:170
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:336
u8 mode
Definition: node.h:328
f64 actor_churn_timer
Definition: node.h:289
u8 ntt
Definition: node.h:262
void bond_enable_collecting_distributing(vlib_main_t *vm, member_if_t *mif)
Definition: cli.c:134
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static uword unformat_bond_load_balance(unformat_input_t *input, va_list *args)
Definition: node.h:462
uword * member_by_sw_if_index
Definition: node.h:384
f64 last_lacpdu_sent_time
Definition: node.h:292
lacp_port_info_t partner
Definition: node.h:254
u8 last_packet_signature_valid
Definition: node.h:235
bond_if_t * interfaces
Definition: node.h:364
vlib_node_registration_t bond_input_node
(constructor) VLIB_REGISTER_NODE (bond_input_node)
Definition: node.c:408
u8 is_passive
Definition: node.h:251
clib_error_t * error
Definition: node.h:111
member_if_t * neighbors
Definition: node.h:370
u32 partner_state
Definition: node.h:357
void bond_detach_member(vlib_main_t *vm, bond_detach_member_args_t *args)
Definition: cli.c:829
u8 mode
Definition: node.h:171
u32 * members
Definition: node.h:187
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
uword * bond_by_sw_if_index
Definition: node.h:373
ethernet_header_t ethernet
Definition: node.h:394
f32 ttl_in_seconds
Definition: node.h:221
int mux_state
Definition: node.h:315
uword last_packet_signature
Definition: node.h:236
f64 partner_churn_timer
Definition: node.h:307
void(* lacp_enable_disable_func)(vlib_main_t *vm, bond_if_t *bif, member_if_t *mif, u8 enable)
Definition: node.h:352
u32 * active_members
Definition: node.h:190
clib_spinlock_t lockp
Definition: node.h:210
f64 last_marker_pdu_sent_time
Definition: node.h:298
BOND interface details struct.
Definition: node.h:124
#define foreach_bond_lb_algo
Definition: node.h:58
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
u8 packet_template_index
Definition: node.h:230
typedef CLIB_PACKED(struct { u16 system_priority;u8 system[6];u16 key;u16 port_priority;u16 port_number;u8 state;}) lacp_port_info_t
u8 lacp_plugin_loaded
Definition: node.h:380
static member_if_t * bond_get_member_by_sw_if_index(u32 sw_if_index)
Definition: node.h:525
int rx_state
Definition: node.h:313
int tx_state
Definition: node.h:314
u8 ready
Definition: node.h:277
f64 wait_while_timer
Definition: node.h:310
bond_send_garp_na_process_event_t
Definition: node.h:73
float f32
Definition: types.h:143
int bond_dump_ifs(bond_interface_details_t **out_bondids)
Definition: cli.c:177
typedef key
Definition: ipsec_types.api:86
struct _vlib_node_registration vlib_node_registration_t
f64 periodic_timer
Definition: node.h:304
u8 debug
Definition: node.h:227
word n_numa_members
Definition: node.h:203
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_bond_interface_name(u8 *s, va_list *args)
Definition: device.c:71
lacp_port_info_t actor_admin
Definition: node.h:259
VLIB buffer representation.
Definition: buffer.h:102
uword * port_number_bitmap
Definition: node.h:206
u64 uword
Definition: types.h:112
u8 loopback_port
Definition: node.h:325
static u8 * format_bond_mode(u8 *s, va_list *args)
Definition: node.h:445
u8 port_enabled
Definition: node.h:265
#define foreach_bond_mode
Definition: node.h:37
u64 pdu_sent
Definition: node.h:337
u32 sw_if_index
Definition: node.h:218
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
u32(* load_balance_func)(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword member_count)
Definition: node.h:399
u32 actor_state
Definition: node.h:358
u64 bad_pdu_received
Definition: node.h:334
u32 hw_if_index
Definition: node.h:245
f64 last_marker_pdu_recd_time
Definition: node.h:301
static u8 * format_bond_load_balance(u8 *s, va_list *args)
Definition: node.h:477
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:840
u32 bond_sw_if_index
Definition: node.h:396
u8 * last_marker_pkt
Definition: node.h:242
load_balance_func load_balance
Definition: node.h:405
u8 port_moved
Definition: node.h:283
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
u8 * last_rx_pkt
Definition: node.h:239
bond_per_port_queue_t * per_port_queue
Definition: node.h:165
lacp_port_info_t partner
Definition: node.h:192
u64 marker_pdu_received
Definition: node.h:340
u32 bif_dev_instance
Definition: node.h:323