FD.io VPP  v21.10.1-2-g0a485f517
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 typedef 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  _ (BAD_KEY, "Bad key") \
68  _ (LOOPBACK_PORT, "loopback port") \
69  _ (DISABLED, "lacp packets received on disabled interfaces")
70 
71 typedef enum
72 {
73 #define _(sym,str) LACP_ERROR_##sym,
75 #undef _
77 } lacp_error_t;
78 
79 #define SECS_IN_A_DAY 86400.0
80 
81 /* lacp packet trace capture */
82 typedef struct
83 {
86  union
87  {
88  marker_pdu_t marker;
89  lacp_pdu_t lacpdu;
90  } pkt;
92 
93 /** LACP interface details struct */
94 typedef struct
95 {
97  u8 interface_name[64];
102  u8 bond_interface_name[64];
104  u8 actor_system[6];
110  u8 partner_system[6];
116 
117 typedef struct
118 {
119  /** API message ID base */
121 
122  /* convenience variables */
125 
126  /* Background process node index */
128 
129  /* Packet templates for different encap types */
131 
132  /* Packet templates for different encap types */
134 
135  /* LACP interface count */
136  volatile u32 lacp_int;
137 
138  /* debug is on or off */
140 } lacp_main_t;
141 
143 extern lacp_main_t lacp_main;
144 
145 void lacp_create_periodic_process (void);
147 int lacp_dump_ifs (lacp_interface_details_t ** out_bondids);
149 void lacp_periodic (vlib_main_t * vm);
150 u8 *lacp_input_format_trace (u8 * s, va_list * args);
151 void lacp_init_neighbor (member_if_t * mif, u8 * hw_address,
152  u16 port_number, u32 group);
160 
161 static inline void
163 {
164  *timer = 0.0;
165 }
166 
167 static inline u8
169 {
170  return (timer != 0.0);
171 }
172 
173 static inline u8
175 {
176  f64 now = vlib_time_now (vm);
177 
178  return (now >= timer);
179 }
180 
181 static inline u8 *
182 format_rx_sm_state (u8 * s, va_list * args)
183 {
184  lacp_state_struct lacp_rx_sm_state_array[] = {
185 #define _(b, s, n) {.bit = b, .str = #s, },
187 #undef _
188  {.str = NULL}
189  };
190  int state = va_arg (*args, int);
191  lacp_state_struct *state_entry = lacp_rx_sm_state_array;
192 
193  if (state >= (sizeof (lacp_rx_sm_state_array) / sizeof (*state_entry)))
194  s = format (s, "Bad state %d", state);
195  else
196  s = format (s, "%s", state_entry[state].str);
197 
198  return s;
199 }
200 
201 static inline u8 *
202 format_tx_sm_state (u8 * s, va_list * args)
203 {
204  lacp_state_struct lacp_tx_sm_state_array[] = {
205 #define _(b, s, n) {.bit = b, .str = #s, },
207 #undef _
208  {.str = NULL}
209  };
210  int state = va_arg (*args, int);
211  lacp_state_struct *state_entry = lacp_tx_sm_state_array;
212 
213  if (state >= (sizeof (lacp_tx_sm_state_array) / sizeof (*state_entry)))
214  s = format (s, "Bad state %d", state);
215  else
216  s = format (s, "%s", state_entry[state].str);
217 
218  return s;
219 }
220 
221 static inline u8 *
222 format_mux_sm_state (u8 * s, va_list * args)
223 {
224  lacp_state_struct lacp_mux_sm_state_array[] = {
225 #define _(b, s, n) {.bit = b, .str = #s, },
227 #undef _
228  {.str = NULL}
229  };
230  int state = va_arg (*args, int);
231  lacp_state_struct *state_entry = lacp_mux_sm_state_array;
232 
233  if (state >= (sizeof (lacp_mux_sm_state_array) / sizeof (*state_entry)))
234  s = format (s, "Bad state %d", state);
235  else
236  s = format (s, "%s", state_entry[state].str);
237 
238  return s;
239 }
240 
241 static inline u8 *
242 format_ptx_sm_state (u8 * s, va_list * args)
243 {
244  lacp_state_struct lacp_ptx_sm_state_array[] = {
245 #define _(b, s, n) {.bit = b, .str = #s, },
247 #undef _
248  {.str = NULL}
249  };
250  int state = va_arg (*args, int);
251  lacp_state_struct *state_entry = lacp_ptx_sm_state_array;
252 
253  if (state >= (sizeof (lacp_ptx_sm_state_array) / sizeof (*state_entry)))
254  s = format (s, "Bad state %d", state);
255  else
256  s = format (s, "%s", state_entry[state].str);
257 
258  return s;
259 }
260 
261 static inline int
262 lacp_bit_test (u8 val, u8 bit)
263 {
264  if (val & (1 << bit))
265  return 1;
266  else
267  return 0;
268 }
269 
270 #endif /* __included_lacp_node_h__ */
271 
272 /*
273  * fd.io coding-style-patch-verification: ON
274  *
275  * Local Variables:
276  * eval: (c-set-style "gnu")
277  * End:
278  */
vlib.h
lacp_periodic
void lacp_periodic(vlib_main_t *vm)
Definition: lacp.c:138
lacp_input_trace_t::lacpdu
lacp_pdu_t lacpdu
Definition: node.h:89
lacp_timer_is_expired
static u8 lacp_timer_is_expired(vlib_main_t *vm, f64 timer)
Definition: node.h:174
format_tx_sm_state
static u8 * format_tx_sm_state(u8 *s, va_list *args)
Definition: node.h:202
vlib_packet_template_t
Definition: buffer_funcs.h:1433
mux_machine.h
lacp_interface_details_t::actor_port_priority
u16 actor_port_priority
Definition: node.h:106
format_ptx_sm_state
static u8 * format_ptx_sm_state(u8 *s, va_list *args)
Definition: node.h:242
MARKER_N_PACKET_TEMPLATES
@ MARKER_N_PACKET_TEMPLATES
Definition: node.h:37
lacp_timer_is_running
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:168
lacp_init_ptx_machine
void lacp_init_ptx_machine(vlib_main_t *vm, member_if_t *mif)
Definition: ptx_machine.c:220
lacp_packet_template_id_t
lacp_packet_template_id_t
Definition: node.h:28
LACP_PACKET_TEMPLATE_ETHERNET
@ LACP_PACKET_TEMPLATE_ETHERNET
Definition: node.h:30
format_rx_sm_state
static u8 * format_rx_sm_state(u8 *s, va_list *args)
Definition: node.h:182
lacp_input_trace_t::sw_if_index
u32 sw_if_index
Definition: node.h:84
lacp_input_format_trace
u8 * lacp_input_format_trace(u8 *s, va_list *args)
Definition: input.c:255
foreach_lacp_ptx_sm_state
@ foreach_lacp_ptx_sm_state
Definition: ptx_machine.h:44
lacp_init_neighbor
void lacp_init_neighbor(member_if_t *mif, u8 *hw_address, u16 port_number, u32 group)
Definition: lacp.c:333
lacp_init_mux_machine
void lacp_init_mux_machine(vlib_main_t *vm, member_if_t *mif)
Definition: mux_machine.c:233
lacp_interface_details_t::partner_state
u8 partner_state
Definition: node.h:114
lacp_interface_details_t::partner_port_number
u16 partner_port_number
Definition: node.h:113
u16
unsigned short u16
Definition: types.h:57
LACP_PROCESS_EVENT_STOP
@ LACP_PROCESS_EVENT_STOP
Definition: node.h:43
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
LACP_PROCESS_EVENT_START
@ LACP_PROCESS_EVENT_START
Definition: node.h:42
lacp_interface_details_t::partner_port_priority
u16 partner_port_priority
Definition: node.h:112
lacp_interface_details_t::actor_state
u8 actor_state
Definition: node.h:108
lacp_send_lacp_pdu
void lacp_send_lacp_pdu(vlib_main_t *vm, member_if_t *mif)
Definition: lacp.c:108
lacp_interface_details_t::partner_system_priority
u16 partner_system_priority
Definition: node.h:109
marker_packet_template_id_t
marker_packet_template_id_t
Definition: node.h:34
lacp_main
lacp_main_t lacp_main
Definition: lacp.c:26
lacp_interface_details_t::sw_if_index
u32 sw_if_index
Definition: node.h:96
lacp_input_trace_t
Definition: node.h:82
lacp_state_array
lacp_state_struct lacp_state_array[]
Definition: node.c:21
hash.h
protocol.h
lacp_interface_details_t::actor_key
u16 actor_key
Definition: node.h:105
lacp_selection_logic
int lacp_selection_logic(vlib_main_t *vm, member_if_t *mif)
Definition: selection.c:76
lacp_input_trace_t::len
u32 len
Definition: node.h:85
lacp_interface_details_t::rx_state
u32 rx_state
Definition: node.h:98
LACP_N_ERROR
@ LACP_N_ERROR
Definition: node.h:76
lacp_create_periodic_process
void lacp_create_periodic_process(void)
Definition: node.c:229
foreach_lacp_tx_sm_state
@ foreach_lacp_tx_sm_state
Definition: tx_machine.h:39
tx_machine.h
f64
double f64
Definition: types.h:142
lacp_interface_details_t::tx_state
u32 tx_state
Definition: node.h:99
lacp_main_t::vnet_main
vnet_main_t * vnet_main
Definition: node.h:124
format.h
rx_machine.h
lacp_interface_details_t::actor_port_number
u16 actor_port_number
Definition: node.h:107
lacp_interface_details_t::partner_key
u16 partner_key
Definition: node.h:111
lacp_error_t
lacp_error_t
Definition: node.h:71
format_mux_sm_state
static u8 * format_mux_sm_state(u8 *s, va_list *args)
Definition: node.h:222
ptx_machine.h
vnet_main_t
Definition: vnet.h:76
lacp_main_t
Definition: node.h:117
LACP_N_PACKET_TEMPLATES
@ LACP_N_PACKET_TEMPLATES
Definition: node.h:31
lacp_main_t::msg_id_base
u16 msg_id_base
API message ID base.
Definition: node.h:120
lacp_state_struct
Definition: protocol.h:85
lacp_dump_ifs
int lacp_dump_ifs(lacp_interface_details_t **out_bondids)
Definition: cli.c:21
lacp_bit_test
static int lacp_bit_test(u8 val, u8 bit)
Definition: node.h:262
lacp_main_t::lacp_int
volatile u32 lacp_int
Definition: node.h:136
lacp_process_event_t
lacp_process_event_t
Definition: node.h:40
member_if_t
Definition: node.h:213
format
description fragment has unexpected format
Definition: map.api:433
lacp_main_t::debug
u8 debug
Definition: node.h:139
lacp_stop_timer
static void lacp_stop_timer(f64 *timer)
Definition: node.h:162
u32
unsigned int u32
Definition: types.h:88
lacp_init_tx_machine
void lacp_init_tx_machine(vlib_main_t *vm, member_if_t *mif)
Definition: tx_machine.c:108
lacp_interface_details_t
LACP interface details struct.
Definition: node.h:94
lacp_input
lacp_error_t lacp_input(vlib_main_t *vm, vlib_buffer_t *b0, u32 bi0)
Definition: input.c:135
lacp_init_state_machines
void lacp_init_state_machines(vlib_main_t *vm, member_if_t *mif)
Definition: lacp.c:374
now
f64 now
Definition: nat44_ei_out2in.c:710
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
unix.h
lacp_input_trace_t::marker
marker_pdu_t marker
Definition: node.h:88
MARKER_PACKET_TEMPLATE_ETHERNET
@ MARKER_PACKET_TEMPLATE_ETHERNET
Definition: node.h:36
lacp_interface_details_t::actor_system_priority
u16 actor_system_priority
Definition: node.h:103
lacp_plugin_api_hookup
clib_error_t * lacp_plugin_api_hookup(vlib_main_t *vm)
Definition: lacp_api.c:119
foreach_lacp_rx_sm_state
@ foreach_lacp_rx_sm_state
Definition: rx_machine.h:49
lacp_interface_details_t::ptx_state
u32 ptx_state
Definition: node.h:101
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
foreach_lacp_mux_sm_state
@ foreach_lacp_mux_sm_state
Definition: mux_machine.h:46
lacp_main_t::vlib_main
vlib_main_t * vlib_main
Definition: node.h:123
foreach_lacp_error
#define foreach_lacp_error
Definition: node.h:61
lacp_main_t::lacp_process_node_index
u32 lacp_process_node_index
Definition: node.h:127
lacp_interface_details_t::mux_state
u32 mux_state
Definition: node.h:100
lacp_init_rx_machine
void lacp_init_rx_machine(vlib_main_t *vm, member_if_t *mif)
Definition: rx_machine.c:424
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111