FD.io VPP  v20.05.1-6-gf53edbc3b
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  /* slave'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 /** slave 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 slave 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 slaves */
188 
189  /* Slaves 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 slaves
197  on local numa node works for lacp mode if have at least one,
198  otherwise it works as usual. */
201 
202  /* How many slaves 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  /* slave is numa node */
350 } slave_if_t;
351 
353  slave_if_t * sif, 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 slave 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 slave_count);
402 
403 typedef struct
404 {
407 
411 extern bond_main_t bond_main;
412 
414  slave_if_t * sif);
416 u8 *format_bond_interface_name (u8 * s, va_list * args);
417 
422 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
424 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
426  u32 bond_sw_if_index);
427 
428 static inline uword
429 unformat_bond_mode (unformat_input_t * input, va_list * args)
430 {
431  u8 *r = va_arg (*args, u8 *);
432 
433  if (0);
434 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
436 #undef _
437  else
438  return 0;
439 
440  return 1;
441 }
442 
443 static inline u8 *
444 format_bond_mode (u8 * s, va_list * args)
445 {
446  u32 i = va_arg (*args, u32);
447  u8 *t = 0;
448 
449  switch (i)
450  {
451 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
453 #undef _
454  default:
455  return format (s, "unknown");
456  }
457  return format (s, "%s", t);
458 }
459 
460 static inline uword
462 {
463  u8 *r = va_arg (*args, u8 *);
464 
465  if (0);
466 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
468 #undef _
469  else
470  return 0;
471 
472  return 1;
473 }
474 
475 static inline u8 *
476 format_bond_load_balance (u8 * s, va_list * args)
477 {
478  u32 i = va_arg (*args, u32);
479  u8 *t = 0;
480 
481  switch (i)
482  {
483 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
485 #undef _
486  default:
487  return format (s, "unknown");
488  }
489  return format (s, "%s", t);
490 }
491 
492 static inline void
494 {
495  bond_main_t *bm = &bond_main;
496 
497  bm->lacp_plugin_loaded = 1;
498  bm->lacp_enable_disable = func;
499 }
500 
501 static inline bond_if_t *
503 {
504  bond_main_t *bm = &bond_main;
505  uword *p;
506 
507  p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
508  if (!p)
509  {
510  return 0;
511  }
512  return pool_elt_at_index (bm->interfaces, p[0]);
513 }
514 
515 static inline bond_if_t *
517 {
518  bond_main_t *bm = &bond_main;
519 
520  return pool_elt_at_index (bm->interfaces, dev_instance);
521 }
522 
523 static inline slave_if_t *
525 {
526  bond_main_t *bm = &bond_main;
527  slave_if_t *sif = 0;
528  uword p;
529 
530  if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
531  {
533  if (p)
534  sif = pool_elt_at_index (bm->neighbors, p >> 1);
535  }
536 
537  return sif;
538 }
539 
540 #endif /* __included_vnet_bonding_node_h__ */
541 
542 /*
543  * fd.io coding-style-patch-verification: ON
544  *
545  * Local Variables:
546  * eval: (c-set-style "gnu")
547  * End:
548  */
u32 weight
Definition: node.h:248
void bond_set_intf_weight(vlib_main_t *vm, bond_set_intf_weight_args_t *args)
Definition: cli.c:992
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:429
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
lacp_stats_t ** stats
Definition: node.h:388
u64 marker_pdu_sent
Definition: node.h:346
u8 individual_aggregator
Definition: node.h:194
int selected
Definition: node.h:280
u8 last_packet_signature_valid
Definition: node.h:235
u8 lb
Definition: node.h:172
clib_error_t * error
Definition: node.h:90
f64 last_lacpdu_recd_time
Definition: node.h:295
uword * id_used
Definition: node.h:367
unsigned long u64
Definition: types.h:89
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:502
clib_error_t * error
Definition: node.h:120
u8 * last_marker_pkt
Definition: node.h:242
void(* lacp_enable_disable_func)(vlib_main_t *vm, bond_if_t *bif, slave_if_t *sif, u8 enable)
Definition: node.h:352
int tx_state
Definition: node.h:314
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:382
u64 pdu_received
Definition: node.h:331
struct _vnet_device_class vnet_device_class_t
u32 id
Definition: node.h:181
f64 current_while_timer
Definition: node.h:286
u8 mode
Definition: node.h:328
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
u8 ntt
Definition: node.h:262
double f64
Definition: types.h:142
f64 periodic_timer
Definition: node.h:304
u32(* load_balance_func)(vlib_main_t *vm, vlib_node_runtime_t *node, bond_if_t *bif, vlib_buffer_t *b0, uword slave_count)
Definition: node.h:399
static void bond_register_callback(lacp_enable_disable_func func)
Definition: node.h:493
f32 ttl_in_seconds
Definition: node.h:221
u8 numa_only
Definition: node.h:199
i64 word
Definition: types.h:111
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
u8 use_custom_mac
Definition: node.h:207
f64 last_marker_pdu_recd_time
Definition: node.h:301
bond_main_t bond_main
Definition: node.c:25
u32 sw_if_index
Definition: node.h:184
u64 bad_pdu_received
Definition: node.h:334
u64 marker_pdu_received
Definition: node.h:340
vlib_main_t * vlib_main
Definition: node.h:376
lacp_port_info_t actor
Definition: node.h:193
unsigned int u32
Definition: types.h:88
u32 lb_rr_last_index
Definition: node.h:175
f64 partner_churn_timer
Definition: node.h:307
#define VLIB_FRAME_SIZE
Definition: node.h:380
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:376
u8 * last_rx_pkt
Definition: node.h:239
bond_load_balance_t
Definition: node.h:66
#define hash_get(h, key)
Definition: hash.h:249
vnet_device_class_t bond_dev_class
u8 ready
Definition: node.h:277
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
u8 admin_up
Definition: node.h:170
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:335
f64 last_marker_pdu_sent_time
Definition: node.h:298
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 port_moved
Definition: node.h:283
static uword unformat_bond_load_balance(unformat_input_t *input, va_list *args)
Definition: node.h:461
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:404
vlib_main_t * vm
Definition: in2out_ed.c:1599
u8 is_long_timeout
Definition: node.h:224
int ptx_state
Definition: node.h:316
u32 marker_tx_id
Definition: node.h:321
u32 partner_state
Definition: node.h:357
u32 * slaves
Definition: node.h:187
u8 is_passive
Definition: node.h:251
u8 mode
Definition: node.h:171
u32 sw_if_index
Definition: node.h:218
word n_numa_slaves
Definition: node.h:203
lacp_port_info_t partner
Definition: node.h:254
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
u32 group
Definition: node.h:319
clib_spinlock_t lockp
Definition: node.h:210
int rx_state
Definition: node.h:313
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:826
f64 last_lacpdu_sent_time
Definition: node.h:292
BOND interface details struct.
Definition: node.h:124
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
#define foreach_bond_lb_algo
Definition: node.h:58
void bond_enable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:134
typedef CLIB_PACKED(struct { u16 system_priority;u8 system[6];u16 key;u16 port_priority;u16 port_number;u8 state;}) lacp_port_info_t
uword * slave_by_sw_if_index
Definition: node.h:384
u8 loopback_port
Definition: node.h:325
u8 is_local_numa
Definition: node.h:349
u8 lacp_plugin_loaded
Definition: node.h:380
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:516
u32 bif_dev_instance
Definition: node.h:323
u8 debug
Definition: node.h:227
u32 * active_slaves
Definition: node.h:190
u8 ready_n
Definition: node.h:274
bond_send_garp_na_process_event_t
Definition: node.h:73
clib_error_t * error
Definition: node.h:103
float f32
Definition: types.h:143
clib_error_t * error
Definition: node.h:111
int bond_dump_ifs(bond_interface_details_t **out_bondids)
Definition: cli.c:177
typedef key
Definition: ipsec_types.api:85
struct _vlib_node_registration vlib_node_registration_t
u8 lacp_enabled
Definition: node.h:271
u64 pdu_sent
Definition: node.h:337
u8 begin
Definition: node.h:268
#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:69
VLIB buffer representation.
Definition: buffer.h:102
uword * port_number_bitmap
Definition: node.h:206
u64 uword
Definition: types.h:112
lacp_port_info_t partner_admin
Definition: node.h:255
static u8 * format_bond_mode(u8 *s, va_list *args)
Definition: node.h:444
slave interface details struct
Definition: node.h:137
#define foreach_bond_mode
Definition: node.h:37
void bond_disable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:26
slave_if_t * neighbors
Definition: node.h:370
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
u32 actor_state
Definition: node.h:358
f64 actor_churn_timer
Definition: node.h:289
static u8 * format_bond_load_balance(u8 *s, va_list *args)
Definition: node.h:476
u8 port_enabled
Definition: node.h:265
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:831
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:524
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:598
lacp_port_info_t actor_admin
Definition: node.h:259
u32 bond_sw_if_index
Definition: node.h:396
uword last_packet_signature
Definition: node.h:236
u8 packet_template_index
Definition: node.h:230
f64 wait_while_timer
Definition: node.h:310
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveids, u32 bond_sw_if_index)
Definition: cli.c:212
load_balance_func load_balance
Definition: node.h:405
u32 hw_if_index
Definition: node.h:245
int mux_state
Definition: node.h:315
u64 marker_bad_pdu_received
Definition: node.h:343
bond_per_port_queue_t * per_port_queue
Definition: node.h:165
lacp_port_info_t partner
Definition: node.h:192