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