FD.io VPP  v19.08.3-2-gbabecb413
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 /** BOND interface details struct */
115 typedef struct
116 {
119  u8 interface_name[64];
126 
127 /** slave interface details struct */
128 typedef struct
129 {
131  u8 interface_name[64];
136 
137 typedef CLIB_PACKED (struct
138  {
139  u16 system_priority;
140  u8 system[6];
141  u16 key; u16 port_priority; u16 port_number;
142  u8 state;
143  }) lacp_port_info_t;
144 
145 typedef struct
146 {
147  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
151 
152 typedef struct
153 {
156 
157 typedef struct
158 {
162 
163  /* This flag works for active-backup mode only
164  and marks if the working port is local numa. */
166  /* current working sw_if_index in active-bakeup mode. */
168  /* the last slave index for the rr lb */
170 
171  /* Real device instance in interface vector */
173 
174  /* Interface ID being shown to user */
176 
179 
180  /* Configured slaves */
182 
183  /* Slaves that are in DISTRIBUTING state */
185 
186  lacp_port_info_t partner;
187  lacp_port_info_t actor;
189 
190  /* If the flag numa_only is set, it means that only slaves
191  on local numa node works for lacp mode if have at least one,
192  otherwise it works as usual. */
195 
196  /* How many slaves on local numa node are there in lacp mode? */
198 
202  u8 hw_address[6];
203 
205 } bond_if_t;
206 
207 typedef struct
208 {
209  u8 persistent_hw_address[6];
210 
211  /* neighbor's vlib software interface index */
213 
214  /* Neighbor time-to-live (usually 3s) */
216 
217  /* 1 = interface is configured with long timeout (60s) */
219 
220  /* 1 = debug is on; 0 = debug is off */
222 
223  /* tx packet template id for this neighbor */
225 
226  /* Info we actually keep about each neighbor */
227 
228  /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
231 
232  /* last received lacp packet, for the J-hash optimization */
234 
235  /* last marker packet */
237 
238  /* neighbor vlib hw_if_index */
240 
241  /* actor does not initiate the protocol exchange */
243 
244  /* Partner port information */
245  lacp_port_info_t partner;
246  lacp_port_info_t partner_admin;;
247 
248  /* Actor port information */
249  lacp_port_info_t actor;
250  lacp_port_info_t actor_admin;
251 
252  /* Need To Transmit flag */
254 
255  /* Link has been established and Aggregate Port is operable */
257 
258  /* Initialization or reinitialization of the lacp protocol entity */
260 
261  /* Aggregation Port is operating the lacp */
263 
264  /* MUX to indicate to the Selection Logic wait_while_timer expired */
266 
267  /* Selection Logic indicates al Aggregation Ports attached */
269 
270  /* Selection Logic selected an Aggregator */
271  int selected;
272 
273  /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
275 
276  /* timer used to detect whether received protocol information has expired */
278 
279  /* timer used to detect actor churn states */
281 
282  /* time last lacpdu was sent */
284 
285  /* time last lacpdu was received */
287 
288  /* time last marker pdu was sent */
290 
291  /* time last marker pdu was received */
293 
294  /* timer used to generate periodic transmission */
296 
297  /* timer used to detect partner churn states */
299 
300  /* provides hysteresis before performing an aggregation change */
302 
303  /* Implemention variables, not in the spec */
304  int rx_state;
305  int tx_state;
308 
309  /* actor admin key */
311 
313 
315 
317 
318  /* bond mode */
320 
321  /* good lacp pdu received */
323 
324  /* bad lacp pdu received */
326 
327  /* pdu sent */
329 
330  /* good marker pdu received */
332 
333  /* bad marker pdu received */
335 
336  /* pdu sent */
338 } slave_if_t;
339 
341  slave_if_t * sif, u8 enable);
342 
343 typedef struct
344 {
345  /* pool of bonding interfaces */
347 
348  /* record used interface IDs */
350 
351  /* pool of slave interfaces */
353 
354  /* rapidly find a bond by vlib software interface index */
356 
357  /* convenience variables */
360 
361  /* lacp plugin is loaded */
363 
365 
367 
369 
371 } bond_main_t;
372 
373 /* bond packet trace capture */
374 typedef struct
375 {
380 
382  vlib_node_runtime_t * node, bond_if_t * bif,
383  vlib_buffer_t * b0, uword slave_count);
384 
385 typedef struct
386 {
389 
393 extern bond_main_t bond_main;
394 
396  slave_if_t * sif);
398 u8 *format_bond_interface_name (u8 * s, va_list * args);
399 
402 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
404 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
406  u32 bond_sw_if_index);
407 
408 static inline uword
409 unformat_bond_mode (unformat_input_t * input, va_list * args)
410 {
411  u8 *r = va_arg (*args, u8 *);
412 
413  if (0);
414 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
416 #undef _
417  else
418  return 0;
419 
420  return 1;
421 }
422 
423 static inline u8 *
424 format_bond_mode (u8 * s, va_list * args)
425 {
426  u32 i = va_arg (*args, u32);
427  u8 *t = 0;
428 
429  switch (i)
430  {
431 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
433 #undef _
434  default:
435  return format (s, "unknown");
436  }
437  return format (s, "%s", t);
438 }
439 
440 static inline uword
442 {
443  u8 *r = va_arg (*args, u8 *);
444 
445  if (0);
446 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
448 #undef _
449  else
450  return 0;
451 
452  return 1;
453 }
454 
455 static inline u8 *
456 format_bond_load_balance (u8 * s, va_list * args)
457 {
458  u32 i = va_arg (*args, u32);
459  u8 *t = 0;
460 
461  switch (i)
462  {
463 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
465 #undef _
466  default:
467  return format (s, "unknown");
468  }
469  return format (s, "%s", t);
470 }
471 
472 static inline void
474 {
475  bond_main_t *bm = &bond_main;
476 
477  bm->lacp_plugin_loaded = 1;
478  bm->lacp_enable_disable = func;
479 }
480 
481 static inline bond_if_t *
483 {
484  bond_main_t *bm = &bond_main;
485  uword *p;
486 
487  p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
488  if (!p)
489  {
490  return 0;
491  }
492  return pool_elt_at_index (bm->interfaces, p[0]);
493 }
494 
495 static inline bond_if_t *
497 {
498  bond_main_t *bm = &bond_main;
499 
500  return pool_elt_at_index (bm->interfaces, dev_instance);
501 }
502 
503 static inline slave_if_t *
505 {
506  bond_main_t *bm = &bond_main;
507  slave_if_t *sif = 0;
508  uword p;
509 
510  if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
511  {
513  if (p)
514  sif = pool_elt_at_index (bm->neighbors, p >> 1);
515  }
516 
517  return sif;
518 }
519 
520 #endif /* __included_vnet_bonding_node_h__ */
521 
522 /*
523  * fd.io coding-style-patch-verification: ON
524  *
525  * Local Variables:
526  * eval: (c-set-style "gnu")
527  * End:
528  */
vnet_main_t * vnet_main
Definition: node.h:359
bond_mode_t
Definition: node.h:44
u8 gso
Definition: node.h:194
u32 dev_instance
Definition: node.h:172
u32 group
Definition: node.h:199
u32 hw_if_index
Definition: node.h:177
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:409
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u64 marker_pdu_sent
Definition: node.h:337
u8 individual_aggregator
Definition: node.h:188
int selected
Definition: node.h:271
u8 last_packet_signature_valid
Definition: node.h:229
u8 lb
Definition: node.h:161
clib_error_t * error
Definition: node.h:90
f64 last_lacpdu_recd_time
Definition: node.h:286
uword * id_used
Definition: node.h:349
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:482
u8 * last_marker_pkt
Definition: node.h:236
void(* lacp_enable_disable_func)(vlib_main_t *vm, bond_if_t *bif, slave_if_t *sif, u8 enable)
Definition: node.h:340
int tx_state
Definition: node.h:305
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:364
u64 pdu_received
Definition: node.h:322
struct _vnet_device_class vnet_device_class_t
u32 id
Definition: node.h:175
f64 current_while_timer
Definition: node.h:277
u8 mode
Definition: node.h:319
unsigned char u8
Definition: types.h:56
bond_per_thread_data_t * per_thread_data
Definition: node.h:368
#define foreach_bond_lb
Definition: node.h:52
u8 ntt
Definition: node.h:253
double f64
Definition: types.h:142
f64 periodic_timer
Definition: node.h:295
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:381
static void bond_register_callback(lacp_enable_disable_func func)
Definition: node.h:473
f32 ttl_in_seconds
Definition: node.h:215
u8 numa_only
Definition: node.h:193
u8 is_local_numa
Definition: node.h:165
i64 word
Definition: types.h:111
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
u8 use_custom_mac
Definition: node.h:201
f64 last_marker_pdu_recd_time
Definition: node.h:292
bond_main_t bond_main
Definition: node.c:25
u32 sw_if_index
Definition: node.h:178
u64 bad_pdu_received
Definition: node.h:325
u64 marker_pdu_received
Definition: node.h:331
vlib_main_t * vlib_main
Definition: node.h:358
lacp_port_info_t actor
Definition: node.h:187
vhost_vring_state_t state
Definition: vhost_user.h:146
unsigned int u32
Definition: types.h:88
u32 lb_rr_last_index
Definition: node.h:169
f64 partner_churn_timer
Definition: node.h:298
#define VLIB_FRAME_SIZE
Definition: node.h:378
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:339
u8 * last_rx_pkt
Definition: node.h:233
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:268
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
u8 admin_up
Definition: node.h:159
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:298
f64 last_marker_pdu_sent_time
Definition: node.h:289
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 port_moved
Definition: node.h:274
static uword unformat_bond_load_balance(unformat_input_t *input, va_list *args)
Definition: node.h:441
bond_if_t * interfaces
Definition: node.h:346
vlib_node_registration_t bond_input_node
(constructor) VLIB_REGISTER_NODE (bond_input_node)
Definition: node.c:404
u8 is_long_timeout
Definition: node.h:218
int ptx_state
Definition: node.h:307
u32 marker_tx_id
Definition: node.h:312
u32 * slaves
Definition: node.h:181
u8 is_passive
Definition: node.h:242
u8 mode
Definition: node.h:160
u32 sw_if_index
Definition: node.h:212
word n_numa_slaves
Definition: node.h:197
vlib_main_t * vm
Definition: buffer.c:323
lacp_port_info_t partner
Definition: node.h:245
uword * bond_by_sw_if_index
Definition: node.h:355
ethernet_header_t ethernet
Definition: node.h:376
u32 group
Definition: node.h:310
clib_spinlock_t lockp
Definition: node.h:204
int rx_state
Definition: node.h:304
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:774
f64 last_lacpdu_sent_time
Definition: node.h:283
BOND interface details struct.
Definition: node.h:115
#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:105
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:366
u8 loopback_port
Definition: node.h:316
u32 sw_if_index_working
Definition: node.h:167
u8 lacp_plugin_loaded
Definition: node.h:362
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:496
u32 bif_dev_instance
Definition: node.h:314
u8 debug
Definition: node.h:221
u32 * active_slaves
Definition: node.h:184
u8 ready_n
Definition: node.h:265
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:175
struct _vlib_node_registration vlib_node_registration_t
u8 lacp_enabled
Definition: node.h:262
u64 pdu_sent
Definition: node.h:328
u8 begin
Definition: node.h:259
#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:200
u64 uword
Definition: types.h:112
typedef key
Definition: ipsec.api:247
lacp_port_info_t partner_admin
Definition: node.h:246
static u8 * format_bond_mode(u8 *s, va_list *args)
Definition: node.h:424
slave interface details struct
Definition: node.h:128
#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:352
u32 ** stats
Definition: node.h:370
f64 actor_churn_timer
Definition: node.h:280
static u8 * format_bond_load_balance(u8 *s, va_list *args)
Definition: node.h:456
u8 port_enabled
Definition: node.h:256
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:788
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:504
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:561
lacp_port_info_t actor_admin
Definition: node.h:250
u32 bond_sw_if_index
Definition: node.h:378
uword last_packet_signature
Definition: node.h:230
u8 packet_template_index
Definition: node.h:224
f64 wait_while_timer
Definition: node.h:301
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveids, u32 bond_sw_if_index)
Definition: cli.c:210
load_balance_func load_balance
Definition: node.h:387
u32 hw_if_index
Definition: node.h:239
int mux_state
Definition: node.h:306
u64 marker_bad_pdu_received
Definition: node.h:334
bond_per_port_queue_t * per_port_queue
Definition: node.h:154
lacp_port_info_t partner
Definition: node.h:186