FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
lacp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * lacp_api.c - lacp api
4  *
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:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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  *------------------------------------------------------------------
18  */
19 
20 #include <vlib/vlib.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vlib/unix/unix.h>
23 #include <lacp/node.h>
24 
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 
28 
29 /* define message IDs */
30 #include <lacp/lacp_msg_enum.h>
31 
32 /* define message structures */
33 #define vl_typedefs
34 #include <lacp/lacp_all_api_h.h>
35 #undef vl_typedefs
36 
37 /* define generated endian-swappers */
38 #define vl_endianfun
39 #include <lacp/lacp_all_api_h.h>
40 #undef vl_endianfun
41 
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
44 
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>
48 #undef vl_api_version
49 
50 /* Macro to finish up custom dump fns */
51 #define FINISH \
52  vec_add1 (s, 0); \
53  vl_print (handle, (char *)s); \
54  vec_free (s); \
55  return handle;
56 
57 #define REPLY_MSG_ID_BASE lm->msg_id_base
59 
60 #define foreach_lacp_plugin_api_msg \
61 _(SW_INTERFACE_LACP_DUMP, sw_interface_lacp_dump)
62 
63 static void
65  lacp_interface_details_t * lacp_if,
66  u32 context)
67 {
68  lacp_main_t *lm = &lacp_main;
70 
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);
75 
76  /* These fields in network order already */
78  mp->actor_key = lacp_if->actor_key;
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);
84  mp->partner_key = lacp_if->partner_key;
87  mp->partner_state = lacp_if->partner_state;
88 
89  clib_memcpy (mp->partner_system, lacp_if->partner_system, 6);
91  MIN (ARRAY_LEN (mp->interface_name) - 1,
92  strlen ((const char *) lacp_if->interface_name)));
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);
100 
101  mp->context = context;
102  vl_api_send_msg (reg, (u8 *) mp);
103 }
104 
105 /**
106  * @brief Message handler for lacp_dump API.
107  * @param mp vl_api_lacp_dump_t * mp the api message
108  */
109 void
111 {
112  int rv;
114  lacp_interface_details_t *lacpifs = NULL;
115  lacp_interface_details_t *lacp_if = NULL;
116 
118  if (!reg)
119  return;
120 
121  rv = lacp_dump_ifs (&lacpifs);
122  if (rv)
123  return;
124 
125  vec_foreach (lacp_if, lacpifs)
126  {
127  lacp_send_sw_interface_details (reg, lacp_if, mp->context);
128  }
129 
130  vec_free (lacpifs);
131 }
132 
133 static void *
135  void *handle)
136 {
137  u8 *s;
138 
139  s = format (0, "SCRIPT: sw_interface_lacp_dump ");
140 
141  FINISH;
142 }
143 
144 #define vl_msg_name_crc_list
145 #include <lacp/lacp_all_api_h.h>
146 #undef vl_msg_name_crc_list
147 
148 static void
150 {
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;
154 #undef _
155 }
156 
157 static void
159 {
160 #define _(n,f) api_main.msg_print_handlers \
161  [VL_API_##n + lm->msg_id_base] \
162  = (void *) vl_api_##f##_t_print;
164 #undef _
165 }
166 
167 /* Set up the API message handling tables */
168 clib_error_t *
170 {
171  lacp_main_t *lm = &lacp_main;
172  api_main_t *am = &api_main;
173  u8 *name;
174 
175  /* Construct the API name */
176  name = format (0, "lacp_%08x%c", api_version, 0);
177 
178  /* Ask for a correctly-sized block of API message decode slots */
180  ((char *) name, VL_MSG_FIRST_AVAILABLE);
181 
182 #define _(N,n) \
183  vl_msg_api_set_handlers((VL_API_##N + lm->msg_id_base), \
184  #n, \
185  vl_api_##n##_t_handler, \
186  vl_noop_handler, \
187  vl_api_##n##_t_endian, \
188  vl_api_##n##_t_print, \
189  sizeof(vl_api_##n##_t), 1);
191 #undef _
192 
193  /* Mark these APIs as mp safe */
194  am->is_mp_safe[VL_API_SW_INTERFACE_LACP_DUMP] = 1;
195  am->is_mp_safe[VL_API_SW_INTERFACE_LACP_DETAILS] = 1;
196 
197  /*
198  * Set up the (msg_name, crc, message-id) table
199  */
200  setup_message_id_table (lm, am);
201 
203 
204  vec_free (name);
205  return 0;
206 }
207 
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "gnu")
213  * End:
214  */
u8 interface_name[64]
Definition: node.h:95
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
static void lacp_send_sw_interface_details(vl_api_registration_t *reg, lacp_interface_details_t *lacp_if, u32 context)
Definition: lacp_api.c:64
int lacp_dump_ifs(lacp_interface_details_t **out_lacpifs)
Definition: cli.c:21
void vl_api_sw_interface_lacp_dump_t_handler(vl_api_sw_interface_lacp_dump_t *mp)
Message handler for lacp_dump API.
Definition: lacp_api.c:110
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
#define FINISH
Definition: lacp_api.c:51
unsigned int u32
Definition: types.h:88
#define MIN(x, y)
Definition: node.h:31
LACP interface details struct.
Definition: node.h:92
static void * vl_api_sw_interface_lacp_dump_t_print(vl_api_sw_interface_lacp_dump_t *mp, void *handle)
Definition: lacp_api.c:134
Reply for lacp dump request.
Definition: lacp.api:52
static void setup_message_id_table(lacp_main_t *lm, api_main_t *am)
Definition: lacp_api.c:149
#define foreach_lacp_plugin_api_msg
Definition: lacp_api.c:60
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
Dump lacp interfaces request.
Definition: lacp.api:25
u8 bond_interface_name[64]
Definition: node.h:100
static void plugin_custom_dump_configure(lacp_main_t *lm)
Definition: lacp_api.c:158
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
#define ARRAY_LEN(x)
Definition: clib.h:63
lacp_main_t lacp_main
Definition: lacp.c:25
clib_error_t * lacp_plugin_api_hookup(vlib_main_t *vm)
Definition: lacp_api.c:169
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:226
#define vec_foreach(var, vec)
Vector iterator.
u16 msg_id_base
API message ID base.
Definition: node.h:118
u32 context
Definition: gre.api:45
api_main_t api_main
Definition: api_shared.c:35
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:957