FD.io VPP  v19.04.4-rc0-5-ge88582fac
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_lacp_node_h__
16 #define __included_lacp_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 <lacp/protocol.h>
23 #include <lacp/rx_machine.h>
24 #include <lacp/tx_machine.h>
25 #include <lacp/mux_machine.h>
26 #include <lacp/ptx_machine.h>
27 
28 typedef enum
29 {
33 
34 typedef enum
35 {
39 
40 enum
41 {
45 
46 #define LACP_DBG(n, args...) \
47  { \
48  lacp_main_t *_lm = &lacp_main; \
49  if (_lm->debug || n->debug) \
50  clib_warning (args); \
51  }
52 
53 #define LACP_DBG2(n, e, s, m, t) \
54  { \
55  lacp_main_t *_lm = &lacp_main; \
56  if ((m)->debug && (_lm->debug || (n)->debug)) \
57  (*m->debug)(n, e, s, t); \
58  }
59 
60 /* Packet counters */
61 #define foreach_lacp_error \
62 _ (NONE, "good lacp packets -- consumed") \
63 _ (CACHE_HIT, "good lacp packets -- cache hit") \
64 _ (UNSUPPORTED, "unsupported slow protocol packets") \
65 _ (TOO_SMALL, "bad lacp packets -- packet too small") \
66 _ (BAD_TLV, "bad lacp packets -- bad TLV length") \
67 _ (DISABLED, "lacp packets received on disabled interfaces")
68 
69 typedef enum
70 {
71 #define _(sym,str) LACP_ERROR_##sym,
73 #undef _
75 } lacp_error_t;
76 
77 /* lacp packet trace capture */
78 typedef struct
79 {
82  union
83  {
84  marker_pdu_t marker;
85  lacp_pdu_t lacpdu;
86  } pkt;
88 
89 /** LACP interface details struct */
90 typedef struct
91 {
93  u8 interface_name[64];
98  u8 bond_interface_name[64];
100  u8 actor_system[6];
106  u8 partner_system[6];
112 
113 typedef struct
114 {
115  /** API message ID base */
117 
118  /* convenience variables */
121 
122  /* Background process node index */
124 
125  /* Packet templates for different encap types */
127 
128  /* Packet templates for different encap types */
130 
131  /* LACP interface count */
133 
134  /* debug is on or off */
136 } lacp_main_t;
137 
138 extern lacp_state_struct lacp_state_array[];
139 extern lacp_main_t lacp_main;
140 
142 int lacp_dump_ifs (lacp_interface_details_t ** out_bondids);
144 void lacp_periodic (vlib_main_t * vm);
145 u8 *lacp_input_format_trace (u8 * s, va_list * args);
146 void lacp_init_neighbor (slave_if_t * sif, u8 * hw_address,
147  u16 port_number, u32 group);
155 
156 static inline void
158 {
159  *timer = 0.0;
160 }
161 
162 static inline u8
164 {
165  return (timer != 0.0);
166 }
167 
168 static inline u8
170 {
171  f64 now = vlib_time_now (vm);
172 
173  return (now >= timer);
174 }
175 
176 static inline u8 *
177 format_rx_sm_state (u8 * s, va_list * args)
178 {
179  lacp_state_struct lacp_rx_sm_state_array[] = {
180 #define _(b, s, n) {.bit = b, .str = #s, },
182 #undef _
183  {.str = NULL}
184  };
185  int state = va_arg (*args, int);
186  lacp_state_struct *state_entry =
187  (lacp_state_struct *) & lacp_rx_sm_state_array;
188 
189  if (state >= (sizeof (lacp_rx_sm_state_array) / sizeof (*state_entry)))
190  s = format (s, "Bad state %d", state);
191  else
192  s = format (s, "%s", state_entry[state].str);
193 
194  return s;
195 }
196 
197 static inline u8 *
198 format_tx_sm_state (u8 * s, va_list * args)
199 {
200  lacp_state_struct lacp_tx_sm_state_array[] = {
201 #define _(b, s, n) {.bit = b, .str = #s, },
203 #undef _
204  {.str = NULL}
205  };
206  int state = va_arg (*args, int);
207  lacp_state_struct *state_entry =
208  (lacp_state_struct *) & lacp_tx_sm_state_array;
209 
210  if (state >= (sizeof (lacp_tx_sm_state_array) / sizeof (*state_entry)))
211  s = format (s, "Bad state %d", state);
212  else
213  s = format (s, "%s", state_entry[state].str);
214 
215  return s;
216 }
217 
218 static inline u8 *
219 format_mux_sm_state (u8 * s, va_list * args)
220 {
221  lacp_state_struct lacp_mux_sm_state_array[] = {
222 #define _(b, s, n) {.bit = b, .str = #s, },
224 #undef _
225  {.str = NULL}
226  };
227  int state = va_arg (*args, int);
228  lacp_state_struct *state_entry =
229  (lacp_state_struct *) & lacp_mux_sm_state_array;
230 
231  if (state >= (sizeof (lacp_mux_sm_state_array) / sizeof (*state_entry)))
232  s = format (s, "Bad state %d", state);
233  else
234  s = format (s, "%s", state_entry[state].str);
235 
236  return s;
237 }
238 
239 static inline u8 *
240 format_ptx_sm_state (u8 * s, va_list * args)
241 {
242  lacp_state_struct lacp_ptx_sm_state_array[] = {
243 #define _(b, s, n) {.bit = b, .str = #s, },
245 #undef _
246  {.str = NULL}
247  };
248  int state = va_arg (*args, int);
249  lacp_state_struct *state_entry =
250  (lacp_state_struct *) & lacp_ptx_sm_state_array;
251 
252  if (state >= (sizeof (lacp_ptx_sm_state_array) / sizeof (*state_entry)))
253  s = format (s, "Bad state %d", state);
254  else
255  s = format (s, "%s", state_entry[state].str);
256 
257  return s;
258 }
259 
260 static inline int
261 lacp_bit_test (u8 val, u8 bit)
262 {
263  if (val & (1 << bit))
264  return 1;
265  else
266  return 0;
267 }
268 
269 #endif /* __included_lacp_node_h__ */
270 
271 /*
272  * fd.io coding-style-patch-verification: ON
273  *
274  * Local Variables:
275  * eval: (c-set-style "gnu")
276  * End:
277  */
void lacp_periodic(vlib_main_t *vm)
Definition: lacp.c:138
vlib_main_t * vlib_main
Definition: node.h:119
void lacp_init_ptx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: ptx_machine.c:209
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
int lacp_dump_ifs(lacp_interface_details_t **out_bondids)
Definition: cli.c:21
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u32 lacp_int
Definition: node.h:132
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
void lacp_init_neighbor(slave_if_t *sif, u8 *hw_address, u16 port_number, u32 group)
Definition: lacp.c:303
void lacp_init_mux_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: mux_machine.c:224
marker_pdu_t marker
Definition: node.h:84
static u8 * format_rx_sm_state(u8 *s, va_list *args)
Definition: node.h:177
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:163
vnet_main_t * vnet_main
Definition: node.h:120
static u8 lacp_timer_is_expired(vlib_main_t *vm, f64 timer)
Definition: node.h:169
vhost_vring_state_t state
Definition: vhost_user.h:120
unsigned int u32
Definition: types.h:88
lacp_error_t lacp_input(vlib_main_t *vm, vlib_buffer_t *b0, u32 bi0)
Definition: input.c:137
LACP interface details struct.
Definition: node.h:90
static void lacp_stop_timer(f64 *timer)
Definition: node.h:157
unsigned short u16
Definition: types.h:57
u8 debug
Definition: node.h:135
lacp_packet_template_id_t
Definition: node.h:28
vlib_main_t * vm
Definition: buffer.c:312
lacp_error_t
Definition: node.h:69
static u8 * format_mux_sm_state(u8 *s, va_list *args)
Definition: node.h:219
void lacp_init_rx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: rx_machine.c:415
void lacp_send_lacp_pdu(vlib_main_t *vm, slave_if_t *sif)
Definition: lacp.c:108
#define foreach_lacp_error
Definition: node.h:61
lacp_pdu_t lacpdu
Definition: node.h:85
lacp_main_t lacp_main
Definition: lacp.c:25
static u8 * format_ptx_sm_state(u8 *s, va_list *args)
Definition: node.h:240
void lacp_init_tx_machine(vlib_main_t *vm, slave_if_t *sif)
Definition: tx_machine.c:96
void lacp_selection_logic(vlib_main_t *vm, slave_if_t *sif)
Definition: selection.c:56
u8 * lacp_input_format_trace(u8 *s, va_list *args)
Definition: input.c:250
u32 lacp_process_node_index
Definition: node.h:123
u32 sw_if_index
Definition: node.h:80
VLIB buffer representation.
Definition: buffer.h:102
void lacp_init_state_machines(vlib_main_t *vm, slave_if_t *sif)
Definition: lacp.c:345
static int lacp_bit_test(u8 val, u8 bit)
Definition: node.h:261
clib_error_t * lacp_plugin_api_hookup(vlib_main_t *vm)
Definition: lacp_api.c:144
static u8 * format_tx_sm_state(u8 *s, va_list *args)
Definition: node.h:198
u16 msg_id_base
API message ID base.
Definition: node.h:116
marker_packet_template_id_t
Definition: node.h:34
enum @486 lacp_process_event_t