FD.io VPP  v18.07-rc0-415-g6c78436
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  (((a) == 2) || ((a) == 4) || ((a) == 8) || ((a) == 16))
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 enum
74 {
77 
78 typedef struct
79 {
81  u8 hw_addr[6];
83  u8 lb;
84  /* return */
86  int rv;
89 
90 typedef struct
91 {
92  /* slave's sw_if_index */
94  /* bond's sw_if_index */
98  /* return */
99  int rv;
102 
103 typedef struct
104 {
106  /* return */
107  int rv;
110 
111 /** BOND interface details struct */
112 typedef struct
113 {
115  u8 interface_name[64];
121 
122 /** slave interface details struct */
123 typedef struct
124 {
126  u8 interface_name[64];
131 
132 typedef CLIB_PACKED (struct
133  {
134  u16 system_priority;
135  u8 system[6];
136  u16 key; u16 port_priority; u16 port_number;
137  u8 state;
138  }) lacp_port_info_t;
139 
140 typedef struct
141 {
143 
145 
146 typedef struct
147 {
151 
152  /* the last slave index for the rr lb */
154 
158 
159  /* Configured slaves */
161 
162  /* Slaves that are in DISTRIBUTING state */
164 
165  /* rapidly find an active slave */
167 
168  lacp_port_info_t partner;
169  lacp_port_info_t actor;
171 
175  u8 hw_address[6];
176 
179 } bond_if_t;
180 
181 typedef struct
182 {
183  u8 persistent_hw_address[6];
184 
185  /* neighbor's vlib software interface index */
187 
188  /* Neighbor time-to-live (usually 3s) */
190 
191  /* 1 = interface is configured with long timeout (60s) */
193 
194  /* 1 = debug is on; 0 = debug is off */
196 
197  /* tx packet template id for this neighbor */
199 
200  /* Info we actually keep about each neighbor */
201 
202  /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
205 
206  /* last received lacp packet, for the J-hash optimization */
208 
209  /* last marker packet */
211 
212  /* neighbor vlib hw_if_index */
214 
215  /* actor does not initiate the protocol exchange */
217 
218  /* Partner port information */
219  lacp_port_info_t partner;
220  lacp_port_info_t partner_admin;;
221 
222  /* Partner port information */
223  lacp_port_info_t actor;
224  lacp_port_info_t actor_admin;
225 
226  /* Need To Transmit flag */
228 
229  /* Link has been established and Aggregate Port is operable */
231 
232  /* Initialization or reinitialization of the lacp protocol entity */
234 
235  /* Aggregation Port is operating the lacp */
237 
238  /* MUX to indicate to the Selection Logic wait_while_timer expired */
240 
241  /* Selection Logic indicates al Aggregation Ports attached */
243 
244  /* Selection Logic selected an Aggregator */
245  int selected;
246 
247  /* RX machine indicates an Aggregation Port in PORT_DISABLED state */
249 
250  /* timer used to detect whether received protocol information has expired */
252 
253  /* timer used to detect actor churn states */
255 
256  /* time last lacpdu was sent */
258 
259  /* timer used to generate periodic transmission */
261 
262  /* timer used to detect partner churn states */
264 
265  /* provides hysteresis before performing an aggregation change */
267 
268  /* Implemention variables, not in the spec */
269  int rx_state;
270  int tx_state;
273 
274  /* actor admin key */
276 
278 
280 
282 
283  /* bond mode */
285 
287 } slave_if_t;
288 
290  slave_if_t * sif, u8 enable);
291 
292 typedef struct
293 {
294  /* pool of bonding interfaces */
296 
297  /* pool of lacp neighbors */
299 
300  /* rapidly find a bond by vlib software interface index */
302 
303  /* convenience variables */
306 
307  /* lacp plugin is loaded */
309 
311 
313 } bond_main_t;
314 
315 /* bond packet trace capture */
316 typedef struct
317 {
322 
324  vlib_node_runtime_t * node, bond_if_t * bif,
325  vlib_buffer_t * b0, uword slave_count);
326 
327 typedef struct
328 {
331 
335 extern bond_main_t bond_main;
336 
338  slave_if_t * sif);
340 u8 *format_bond_interface_name (u8 * s, va_list * args);
341 
343 int bond_delete_if (vlib_main_t * vm, u32 sw_if_index);
344 void bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args);
346 int bond_dump_ifs (bond_interface_details_t ** out_bondids);
348  u32 bond_sw_if_index);
349 
350 static inline uword
351 unformat_bond_mode (unformat_input_t * input, va_list * args)
352 {
353  u8 *r = va_arg (*args, u8 *);
354 
355  if (0);
356 #define _(v, f, s) else if (unformat (input, s)) *r = BOND_MODE_##f;
358 #undef _
359  else
360  return 0;
361 
362  return 1;
363 }
364 
365 static inline u8 *
366 format_bond_mode (u8 * s, va_list * args)
367 {
368  u32 i = va_arg (*args, u32);
369  u8 *t = 0;
370 
371  switch (i)
372  {
373 #define _(v, f, s) case BOND_MODE_##f: t = (u8 *) s; break;
375 #undef _
376  default:
377  return format (s, "unknown");
378  }
379  return format (s, "%s", t);
380 }
381 
382 static inline uword
384 {
385  u8 *r = va_arg (*args, u8 *);
386 
387  if (0);
388 #define _(v, f, s, p) else if (unformat (input, s)) *r = BOND_LB_##f;
390 #undef _
391  else
392  return 0;
393 
394  return 1;
395 }
396 
397 static inline u8 *
398 format_bond_load_balance (u8 * s, va_list * args)
399 {
400  u32 i = va_arg (*args, u32);
401  u8 *t = 0;
402 
403  switch (i)
404  {
405 #define _(v, f, s, p) case BOND_LB_##f: t = (u8 *) s; break;
407 #undef _
408  default:
409  return format (s, "unknown");
410  }
411  return format (s, "%s", t);
412 }
413 
414 static inline void
416 {
417  bond_main_t *bm = &bond_main;
418 
419  bm->lacp_plugin_loaded = 1;
420  bm->lacp_enable_disable = func;
421 }
422 
423 static inline bond_if_t *
425 {
426  bond_main_t *bm = &bond_main;
427  uword *p;
428 
429  p = hash_get (bm->bond_by_sw_if_index, sw_if_index);
430  if (!p)
431  {
432  return 0;
433  }
434  return pool_elt_at_index (bm->interfaces, p[0]);
435 }
436 
437 static inline bond_if_t *
439 {
440  bond_main_t *bm = &bond_main;
441 
442  return pool_elt_at_index (bm->interfaces, dev_instance);
443 }
444 
445 static inline slave_if_t *
447 {
448  bond_main_t *bm = &bond_main;
449  slave_if_t *sif = 0;
450  uword p;
451 
452  if (sw_if_index < vec_len (bm->slave_by_sw_if_index))
453  {
454  p = bm->slave_by_sw_if_index[sw_if_index];
455  if (p)
456  sif = pool_elt_at_index (bm->neighbors, p >> 1);
457  }
458 
459  return sif;
460 }
461 
462 #endif /* __included_vnet_bonding_node_h__ */
463 
464 /*
465  * fd.io coding-style-patch-verification: ON
466  *
467  * Local Variables:
468  * eval: (c-set-style "gnu")
469  * End:
470  */
vnet_main_t * vnet_main
Definition: node.h:305
bond_mode_t
Definition: node.h:44
u32 dev_instance
Definition: node.h:155
u32 group
Definition: node.h:172
u32 hw_if_index
Definition: node.h:156
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:351
u8 individual_aggregator
Definition: node.h:170
int selected
Definition: node.h:245
u8 last_packet_signature_valid
Definition: node.h:203
u8 lb
Definition: node.h:150
clib_error_t * error
Definition: node.h:87
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:424
u8 is_long_timeout
Definition: node.h:97
u8 * last_marker_pkt
Definition: node.h:210
void(* lacp_enable_disable_func)(vlib_main_t *vm, bond_if_t *bif, slave_if_t *sif, u8 enable)
Definition: node.h:289
int tx_state
Definition: node.h:270
vlib_frame_t ** frame
Definition: node.h:142
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:310
clib_spinlock_t lockp
Definition: node.h:286
enum @54 bond_send_garp_na_process_event_t
struct _vnet_device_class vnet_device_class_t
f64 current_while_timer
Definition: node.h:251
u8 mode
Definition: node.h:284
unsigned char u8
Definition: types.h:56
f64 last_lacpdu_time
Definition: node.h:257
typedef CLIB_PACKED(struct{u16 system_priority;u8 system[6];u16 key;u16 port_priority;u16 port_number;u8 state;}) lacp_port_info_t
#define foreach_bond_lb
Definition: node.h:52
u8 ntt
Definition: node.h:227
double f64
Definition: types.h:142
f64 periodic_timer
Definition: node.h:260
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:323
static void bond_register_callback(lacp_enable_disable_func func)
Definition: node.h:415
f32 ttl_in_seconds
Definition: node.h:189
u8 use_custom_mac
Definition: node.h:174
bond_main_t bond_main
Definition: node.c:24
u32 sw_if_index
Definition: node.h:157
uword * active_slave_by_sw_if_index
Definition: node.h:166
vlib_main_t * vlib_main
Definition: node.h:304
lacp_port_info_t actor
Definition: node.h:169
unsigned int u32
Definition: types.h:88
u32 lb_rr_last_index
Definition: node.h:153
f64 partner_churn_timer
Definition: node.h:263
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:245
u8 * last_rx_pkt
Definition: node.h:207
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:242
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
u8 admin_up
Definition: node.h:148
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:190
bond_if_per_thread_t * per_thread_info
Definition: node.h:178
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 port_moved
Definition: node.h:248
static uword unformat_bond_load_balance(unformat_input_t *input, va_list *args)
Definition: node.h:383
bond_if_t * interfaces
Definition: node.h:295
vlib_node_registration_t bond_input_node
(constructor) VLIB_REGISTER_NODE (bond_input_node)
Definition: node.c:371
u8 is_long_timeout
Definition: node.h:192
int ptx_state
Definition: node.h:272
u32 marker_tx_id
Definition: node.h:277
u32 * slaves
Definition: node.h:160
u8 is_passive
Definition: node.h:216
u8 mode
Definition: node.h:149
u32 sw_if_index
Definition: node.h:186
vlib_main_t * vm
Definition: buffer.c:294
lacp_port_info_t partner
Definition: node.h:219
uword * bond_by_sw_if_index
Definition: node.h:301
ethernet_header_t ethernet
Definition: node.h:318
u32 group
Definition: node.h:275
clib_spinlock_t lockp
Definition: node.h:177
int rx_state
Definition: node.h:269
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:594
BOND interface details struct.
Definition: node.h:112
#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:59
uword * slave_by_sw_if_index
Definition: node.h:312
u8 loopback_port
Definition: node.h:281
u8 lacp_plugin_loaded
Definition: node.h:308
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:438
vhost_vring_state_t state
Definition: vhost-user.h:82
u32 bif_dev_instance
Definition: node.h:279
u8 debug
Definition: node.h:195
u32 * active_slaves
Definition: node.h:163
u8 ready_n
Definition: node.h:239
clib_error_t * error
Definition: node.h:100
float f32
Definition: types.h:143
clib_error_t * error
Definition: node.h:108
int bond_dump_ifs(bond_interface_details_t **out_bondids)
Definition: cli.c:82
struct _vlib_node_registration vlib_node_registration_t
u8 lacp_enabled
Definition: node.h:236
u8 begin
Definition: node.h:233
#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:68
uword * port_number_bitmap
Definition: node.h:173
u64 uword
Definition: types.h:112
lacp_port_info_t partner_admin
Definition: node.h:220
static u8 * format_bond_mode(u8 *s, va_list *args)
Definition: node.h:366
slave interface details struct
Definition: node.h:123
#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:298
f64 actor_churn_timer
Definition: node.h:254
static u8 * format_bond_load_balance(u8 *s, va_list *args)
Definition: node.h:398
u8 port_enabled
Definition: node.h:230
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:744
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:446
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:422
lacp_port_info_t actor_admin
Definition: node.h:224
u32 bond_sw_if_index
Definition: node.h:320
uword last_packet_signature
Definition: node.h:204
u8 packet_template_index
Definition: node.h:198
f64 wait_while_timer
Definition: node.h:266
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveids, u32 bond_sw_if_index)
Definition: cli.c:113
load_balance_func load_balance
Definition: node.h:329
u32 hw_if_index
Definition: node.h:213
int mux_state
Definition: node.h:271
lacp_port_info_t partner
Definition: node.h:168