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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __included_lacp_node_h__
16 #define __included_lacp_node_h__
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>
30 LACP_PACKET_TEMPLATE_ETHERNET,
31 LACP_N_PACKET_TEMPLATES,
32 } lacp_packet_template_id_t;
36 MARKER_PACKET_TEMPLATE_ETHERNET,
37 MARKER_N_PACKET_TEMPLATES,
38 } marker_packet_template_id_t;
42 LACP_PROCESS_EVENT_START = 1,
43 LACP_PROCESS_EVENT_STOP = 2,
44 } lacp_process_event_t;
46 #define LACP_DBG(n, args...) \
48 lacp_main_t *_lm = &lacp_main; \
49 if (_lm->debug || n->debug) \
50 clib_warning (args); \
53 #define LACP_DBG2(n, e, s, m, t) \
55 lacp_main_t *_lm = &lacp_main; \
56 if ((m)->debug && (_lm->debug || (n)->debug)) \
57 (*m->debug)(n, e, s, t); \
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")
73 #define _(sym,str) LACP_ERROR_##sym,
79 #define SECS_IN_A_DAY 86400.0
81 /* lacp packet trace capture */
93 /** LACP interface details struct */
97 u8 interface_name[64];
102 u8 bond_interface_name[64];
103 u16 actor_system_priority;
106 u16 actor_port_priority;
107 u16 actor_port_number;
109 u16 partner_system_priority;
110 u8 partner_system[6];
112 u16 partner_port_priority;
113 u16 partner_port_number;
115 } lacp_interface_details_t;
119 /** API message ID base */
122 /* convenience variables */
123 vlib_main_t *vlib_main;
124 vnet_main_t *vnet_main;
126 /* Background process node index */
127 u32 lacp_process_node_index;
129 /* Packet templates for different encap types */
130 vlib_packet_template_t packet_templates[LACP_N_PACKET_TEMPLATES];
132 /* Packet templates for different encap types */
133 vlib_packet_template_t marker_packet_templates[MARKER_N_PACKET_TEMPLATES];
135 /* LACP interface count */
136 volatile u32 lacp_int;
138 /* debug is on or off */
142 extern lacp_state_struct lacp_state_array[];
143 extern lacp_main_t lacp_main;
145 void lacp_create_periodic_process (void);
146 clib_error_t *lacp_plugin_api_hookup (vlib_main_t * vm);
147 int lacp_dump_ifs (lacp_interface_details_t ** out_bondids);
148 lacp_error_t lacp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
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);
153 void lacp_init_state_machines (vlib_main_t * vm, member_if_t * mif);
154 void lacp_init_rx_machine (vlib_main_t * vm, member_if_t * mif);
155 void lacp_init_tx_machine (vlib_main_t * vm, member_if_t * mif);
156 void lacp_init_ptx_machine (vlib_main_t * vm, member_if_t * mif);
157 void lacp_init_mux_machine (vlib_main_t * vm, member_if_t * mif);
158 int lacp_selection_logic (vlib_main_t *vm, member_if_t *mif);
159 void lacp_send_lacp_pdu (vlib_main_t * vm, member_if_t * mif);
162 lacp_stop_timer (f64 * timer)
168 lacp_timer_is_running (f64 timer)
170 return (timer != 0.0);
174 lacp_timer_is_expired (vlib_main_t * vm, f64 timer)
176 f64 now = vlib_time_now (vm);
178 return (now >= timer);
182 format_rx_sm_state (u8 * s, va_list * args)
184 lacp_state_struct lacp_rx_sm_state_array[] = {
185 #define _(b, s, n) {.bit = b, .str = #s, },
186 foreach_lacp_rx_sm_state
190 int state = va_arg (*args, int);
191 lacp_state_struct *state_entry = lacp_rx_sm_state_array;
193 if (state >= (sizeof (lacp_rx_sm_state_array) / sizeof (*state_entry)))
194 s = format (s, "Bad state %d", state);
196 s = format (s, "%s", state_entry[state].str);
202 format_tx_sm_state (u8 * s, va_list * args)
204 lacp_state_struct lacp_tx_sm_state_array[] = {
205 #define _(b, s, n) {.bit = b, .str = #s, },
206 foreach_lacp_tx_sm_state
210 int state = va_arg (*args, int);
211 lacp_state_struct *state_entry = lacp_tx_sm_state_array;
213 if (state >= (sizeof (lacp_tx_sm_state_array) / sizeof (*state_entry)))
214 s = format (s, "Bad state %d", state);
216 s = format (s, "%s", state_entry[state].str);
222 format_mux_sm_state (u8 * s, va_list * args)
224 lacp_state_struct lacp_mux_sm_state_array[] = {
225 #define _(b, s, n) {.bit = b, .str = #s, },
226 foreach_lacp_mux_sm_state
230 int state = va_arg (*args, int);
231 lacp_state_struct *state_entry = lacp_mux_sm_state_array;
233 if (state >= (sizeof (lacp_mux_sm_state_array) / sizeof (*state_entry)))
234 s = format (s, "Bad state %d", state);
236 s = format (s, "%s", state_entry[state].str);
242 format_ptx_sm_state (u8 * s, va_list * args)
244 lacp_state_struct lacp_ptx_sm_state_array[] = {
245 #define _(b, s, n) {.bit = b, .str = #s, },
246 foreach_lacp_ptx_sm_state
250 int state = va_arg (*args, int);
251 lacp_state_struct *state_entry = lacp_ptx_sm_state_array;
253 if (state >= (sizeof (lacp_ptx_sm_state_array) / sizeof (*state_entry)))
254 s = format (s, "Bad state %d", state);
256 s = format (s, "%s", state_entry[state].str);
262 lacp_bit_test (u8 val, u8 bit)
264 if (val & (1 << bit))
270 #endif /* __included_lacp_node_h__ */
273 * fd.io coding-style-patch-verification: ON
276 * eval: (c-set-style "gnu")