4 * Copyright (c) 2017 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
24 #include <vppinfra/error.h>
25 #include <lacp/node.h>
27 #define __plugin_msg_base lacp_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
30 /* declare message IDs */
31 #include <lacp/lacp_msg_enum.h>
33 /* Get CRC codes of the messages defined outside of this plugin */
34 #define vl_msg_name_crc_list
35 #include <vpp/api/vpe_all_api_h.h>
36 #undef vl_msg_name_crc_list
38 /* define message structures */
40 #include <vpp/api/vpe_all_api_h.h>
41 #include <lacp/lacp_all_api_h.h>
44 /* declare message handlers for each api */
46 #define vl_endianfun /* define message structures */
47 #include <lacp/lacp_all_api_h.h>
50 /* instantiate all the print functions we know about */
51 #define vl_print(handle, ...)
53 #include <lacp/lacp_all_api_h.h>
56 /* Get the API version number. */
57 #define vl_api_version(n,v) static u32 api_version=(v);
58 #include <lacp/lacp_all_api_h.h>
63 /* API message ID base */
69 lacp_test_main_t lacp_test_main;
72 * Table of message reply handlers, must include boilerplate handlers
75 #define foreach_vpe_api_reply_msg \
76 _(SW_INTERFACE_LACP_DETAILS, sw_interface_lacp_details)
79 static void vl_api_sw_interface_lacp_details_t_handler
80 (vl_api_sw_interface_lacp_details_t * mp)
82 vat_main_t *vam = &vat_main;
85 "%-25s %-12d %-16s %3x %3x %3x %3x %3x %3x %3x %3x "
86 "%4x %3x %3x %3x %3x %3x %3x %3x\n",
87 mp->interface_name, ntohl (mp->sw_if_index),
88 mp->bond_interface_name,
89 lacp_bit_test (mp->actor_state, 7),
90 lacp_bit_test (mp->actor_state, 6),
91 lacp_bit_test (mp->actor_state, 5),
92 lacp_bit_test (mp->actor_state, 4),
93 lacp_bit_test (mp->actor_state, 3),
94 lacp_bit_test (mp->actor_state, 2),
95 lacp_bit_test (mp->actor_state, 1),
96 lacp_bit_test (mp->actor_state, 0),
97 lacp_bit_test (mp->partner_state, 7),
98 lacp_bit_test (mp->partner_state, 6),
99 lacp_bit_test (mp->partner_state, 5),
100 lacp_bit_test (mp->partner_state, 4),
101 lacp_bit_test (mp->partner_state, 3),
102 lacp_bit_test (mp->partner_state, 2),
103 lacp_bit_test (mp->partner_state, 1),
104 lacp_bit_test (mp->partner_state, 0));
106 " LAG ID: [(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
107 "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]\n",
108 ntohs (mp->actor_system_priority), mp->actor_system[0],
109 mp->actor_system[1], mp->actor_system[2], mp->actor_system[3],
110 mp->actor_system[4], mp->actor_system[5], ntohs (mp->actor_key),
111 ntohs (mp->actor_port_priority), ntohs (mp->actor_port_number),
112 ntohs (mp->partner_system_priority), mp->partner_system[0],
113 mp->partner_system[1], mp->partner_system[2],
114 mp->partner_system[3], mp->partner_system[4],
115 mp->partner_system[5], ntohs (mp->partner_key),
116 ntohs (mp->partner_port_priority),
117 ntohs (mp->partner_port_number));
119 " RX-state: %U, TX-state: %U, MUX-state: %U, PTX-state: %U\n",
120 format_rx_sm_state, ntohl (mp->rx_state), format_tx_sm_state,
121 ntohl (mp->tx_state), format_mux_sm_state, ntohl (mp->mux_state),
122 format_ptx_sm_state, ntohl (mp->ptx_state));
126 api_sw_interface_lacp_dump (vat_main_t * vam)
128 lacp_test_main_t *lm = &lacp_test_main;
129 vl_api_sw_interface_lacp_dump_t *mp;
130 vl_api_control_ping_t *mp_ping;
133 if (vam->json_output)
135 clib_warning ("JSON output not supported for sw_interface_lacp_dump");
139 fformat (vam->ofp, "%-55s %-32s %-32s\n", " ", "actor state",
141 fformat (vam->ofp, "%-25s %-12s %-16s %-31s %-31s\n", "interface name",
142 "sw_if_index", "bond interface", "exp/def/dis/col/syn/agg/tim/act",
143 "exp/def/dis/col/syn/agg/tim/act");
145 /* Get list of lacp interfaces */
146 M (SW_INTERFACE_LACP_DUMP, mp);
149 /* Use a control ping for synchronization */
150 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
151 mp_ping->_vl_msg_id = htons (lm->ping_id);
152 mp_ping->client_index = vam->my_client_index;
154 fformat (vam->ofp, "Sending ping id=%d\n", lm->ping_id);
156 vam->result_ready = 0;
164 * List of messages that the api test plugin sends,
165 * and that the data plane plugin processes
167 #define foreach_vpe_api_msg \
168 _(sw_interface_lacp_dump, "")
171 lacp_vat_api_hookup (vat_main_t * vam)
173 lacp_test_main_t *lm __attribute__ ((unused)) = &lacp_test_main;
174 /* Hook up handlers for replies from the data plane plug-in */
176 vl_msg_api_set_handlers((VL_API_##N + lm->msg_id_base), \
178 vl_api_##n##_t_handler, \
180 vl_api_##n##_t_endian, \
181 vl_api_##n##_t_print, \
182 sizeof(vl_api_##n##_t), 1);
183 foreach_vpe_api_reply_msg;
186 /* API messages we can send */
188 hash_set_mem (vam->function_by_name, #n, api_##n);
193 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
199 vat_plugin_register (vat_main_t * vam)
201 lacp_test_main_t *lm = &lacp_test_main;
206 /* Ask the vpp engine for the first assigned message-id */
207 name = format (0, "lacp_%08x%c", api_version, 0);
208 lm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
210 /* Get the control ping ID */
211 #define _(id,n,crc) \
212 const char *id ## _CRC __attribute__ ((unused)) = #n "_" #crc;
213 foreach_vl_msg_name_crc_vpe;
215 lm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
217 if (lm->msg_id_base != (u16) ~ 0)
218 lacp_vat_api_hookup (vam);
226 * fd.io coding-style-patch-verification: ON
229 * eval: (c-set-style "gnu")