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