2 *------------------------------------------------------------------
3 * lacp_api.c - lacp api
5 * Copyright (c) 2017 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vlib/vlib.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vlib/unix/unix.h>
23 #include <lacp/node.h>
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
29 /* define message IDs */
30 #include <lacp/lacp_msg_enum.h>
32 /* define message structures */
34 #include <lacp/lacp_all_api_h.h>
37 /* define generated endian-swappers */
39 #include <lacp/lacp_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 /* Get the API version number */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <lacp/lacp_all_api_h.h>
50 /* Macro to finish up custom dump fns */
53 vl_print (handle, (char *)s); \
57 #define REPLY_MSG_ID_BASE lm->msg_id_base
58 #include <vlibapi/api_helper_macros.h>
60 #define foreach_lacp_plugin_api_msg \
61 _(SW_INTERFACE_LACP_DUMP, sw_interface_lacp_dump)
64 lacp_send_sw_interface_details (vl_api_registration_t * reg,
65 lacp_interface_details_t * lacp_if,
68 lacp_main_t *lm = &lacp_main;
69 vl_api_sw_interface_lacp_details_t *mp;
71 mp = vl_msg_api_alloc (sizeof (*mp));
72 clib_memset (mp, 0, sizeof (*mp));
73 mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_LACP_DETAILS + lm->msg_id_base);
74 mp->sw_if_index = htonl (lacp_if->sw_if_index);
76 /* These fields in network order already */
77 mp->actor_system_priority = lacp_if->actor_system_priority;
78 mp->actor_key = lacp_if->actor_key;
79 mp->actor_port_priority = lacp_if->actor_port_priority;
80 mp->actor_port_number = lacp_if->actor_port_number;
81 mp->actor_state = lacp_if->actor_state;
82 clib_memcpy (mp->actor_system, lacp_if->actor_system, 6);
83 mp->partner_system_priority = lacp_if->partner_system_priority;
84 mp->partner_key = lacp_if->partner_key;
85 mp->partner_port_priority = lacp_if->partner_port_priority;
86 mp->partner_port_number = lacp_if->partner_port_number;
87 mp->partner_state = lacp_if->partner_state;
89 clib_memcpy (mp->partner_system, lacp_if->partner_system, 6);
90 clib_memcpy (mp->interface_name, lacp_if->interface_name,
91 MIN (ARRAY_LEN (mp->interface_name) - 1,
92 strlen ((const char *) lacp_if->interface_name)));
93 clib_memcpy (mp->bond_interface_name, lacp_if->bond_interface_name,
94 MIN (ARRAY_LEN (mp->bond_interface_name) - 1,
95 strlen ((const char *) lacp_if->bond_interface_name)));
96 mp->rx_state = htonl (lacp_if->rx_state);
97 mp->tx_state = htonl (lacp_if->tx_state);
98 mp->mux_state = htonl (lacp_if->mux_state);
99 mp->ptx_state = htonl (lacp_if->ptx_state);
101 mp->context = context;
102 vl_api_send_msg (reg, (u8 *) mp);
106 * @brief Message handler for lacp_dump API.
107 * @param mp vl_api_lacp_dump_t * mp the api message
110 vl_api_sw_interface_lacp_dump_t_handler (vl_api_sw_interface_lacp_dump_t * mp)
113 vl_api_registration_t *reg;
114 lacp_interface_details_t *lacpifs = NULL;
115 lacp_interface_details_t *lacp_if = NULL;
117 reg = vl_api_client_index_to_registration (mp->client_index);
121 rv = lacp_dump_ifs (&lacpifs);
125 vec_foreach (lacp_if, lacpifs)
127 lacp_send_sw_interface_details (reg, lacp_if, mp->context);
134 vl_api_sw_interface_lacp_dump_t_print (vl_api_sw_interface_lacp_dump_t * mp,
139 s = format (0, "SCRIPT: sw_interface_lacp_dump ");
144 #define vl_msg_name_crc_list
145 #include <lacp/lacp_all_api_h.h>
146 #undef vl_msg_name_crc_list
149 setup_message_id_table (lacp_main_t * lm, api_main_t * am)
151 #define _(id,n,crc) \
152 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + lm->msg_id_base);
153 foreach_vl_msg_name_crc_lacp;
158 plugin_custom_dump_configure (lacp_main_t * lm)
160 #define _(n,f) api_main.msg_print_handlers \
161 [VL_API_##n + lm->msg_id_base] \
162 = (void *) vl_api_##f##_t_print;
163 foreach_lacp_plugin_api_msg;
167 /* Set up the API message handling tables */
169 lacp_plugin_api_hookup (vlib_main_t * vm)
171 lacp_main_t *lm = &lacp_main;
172 api_main_t *am = &api_main;
175 /* Construct the API name */
176 name = format (0, "lacp_%08x%c", api_version, 0);
178 /* Ask for a correctly-sized block of API message decode slots */
179 lm->msg_id_base = vl_msg_api_get_msg_ids
180 ((char *) name, VL_MSG_FIRST_AVAILABLE);
183 vl_msg_api_set_handlers((VL_API_##N + lm->msg_id_base), \
185 vl_api_##n##_t_handler, \
187 vl_api_##n##_t_endian, \
188 vl_api_##n##_t_print, \
189 sizeof(vl_api_##n##_t), 1);
190 foreach_lacp_plugin_api_msg;
194 * Set up the (msg_name, crc, message-id) table
196 setup_message_id_table (lm, am);
198 plugin_custom_dump_configure (lm);
205 * fd.io coding-style-patch-verification: ON
208 * eval: (c-set-style "gnu")