2 *------------------------------------------------------------------
5 * Copyright (c) 2009-2015 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 #ifndef included_api_h
21 #define included_api_h
23 #include <vppinfra/error.h>
25 #include <vlib/vlib.h>
26 #include <vlibmemory/unix_shared_memory_queue.h>
27 #include <vlib/unix/unix.h>
32 REGISTRATION_TYPE_FREE = 0,
33 REGISTRATION_TYPE_SHMEM,
34 REGISTRATION_TYPE_SOCKET_LISTEN,
35 REGISTRATION_TYPE_SOCKET_SERVER,
36 REGISTRATION_TYPE_SOCKET_CLIENT,
37 } vl_registration_type_t;
39 typedef struct vl_api_registration_
41 vl_registration_type_t registration_type;
43 /* Index in VLIB's brain (not shared memory). */
44 u32 vl_api_registration_pool_index;
49 * The following groups of data could be unioned, but my fingers are
50 * going to be sore enough.
53 /* shared memory only */
54 unix_shared_memory_queue_t *vl_input_queue;
56 /* socket server and client */
58 i8 *unprocessed_input;
59 u32 unprocessed_msg_length;
62 /* socket client only */
66 } vl_api_registration_t;
69 /* Trace configuration for a single message */
95 u8 endian; u8 wrapped;
97 }) vl_api_trace_file_header_t;
104 } vl_api_trace_which_t;
106 #define VL_API_LITTLE_ENDIAN 0x00
107 #define VL_API_BIG_ENDIAN 0x01
114 } vl_api_msg_range_t;
116 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
118 typedef struct _vl_msg_api_init_function_list_elt
120 struct _vl_msg_api_init_function_list_elt *next_init_function;
121 vl_msg_api_init_function_t *f;
122 } _vl_msg_api_function_list_elt_t;
126 void (**msg_handlers) (void *);
127 int (**pd_msg_handlers) (void *, int);
128 void (**msg_cleanup_handlers) (void *);
129 void (**msg_endian_handlers) (void *);
130 void (**msg_print_handlers) (void *, void *);
131 const char **msg_names;
134 struct ring_alloc_ *arings;
136 u32 garbage_collects;
138 vl_api_trace_t *rx_trace;
139 vl_api_trace_t *tx_trace;
141 trace_cfg_t *api_trace_cfg;
143 svm_region_t *vlib_rp;
144 svm_region_t **mapped_shmem_regions;
145 struct vl_shmem_hdr_ *shmem_hdr;
146 vl_api_registration_t **vl_clients;
148 u8 *serialized_message_table_in_shmem;
150 /* For plugin msg allocator */
151 u16 first_available_msg_id;
153 /* message range by name hash */
154 uword *msg_range_by_name;
156 /* vector of message ranges */
157 vl_api_msg_range_t *msg_ranges;
159 /* uid for the api shared memory region */
161 /* gid for the api shared memory region */
164 /* base virtual address for global VM region */
167 /* size of the global VM region */
170 /* size of the API region */
173 /* size of the global VM private mheap */
174 u64 global_pvt_heap_size;
176 /* size of the api private mheap */
177 u64 api_pvt_heap_size;
179 /* Client-only data structures */
180 unix_shared_memory_queue_t *vl_input_queue;
183 * All VLIB-side message handlers use my_client_index to identify
184 * the queue / client. This works in sim replay.
188 * This is the (shared VM) address of the registration,
189 * don't use it to id the connection since it can't possibly
190 * work in simulator replay.
192 vl_api_registration_t *my_registration;
196 /* vlib input queue length */
197 u32 vlib_input_queue_length;
199 /* client side message index hash table */
200 uword *msg_index_by_name_and_crc;
202 const char *region_name;
203 const char *root_path;
205 /* Replay in progress? */
206 int replay_in_progress;
208 /* List of API client reaper functions */
209 _vl_msg_api_function_list_elt_t *reaper_function_registrations;
213 extern api_main_t api_main;
229 } vl_msg_api_msg_config_t;
231 typedef struct msgbuf_
233 unix_shared_memory_queue_t *q;
235 u32 gc_mark_timestamp;
239 /* api_shared.c prototypes */
240 int vl_msg_api_rx_trace_enabled (api_main_t * am);
241 int vl_msg_api_tx_trace_enabled (api_main_t * am);
242 void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg);
243 int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
245 int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which);
246 int vl_msg_api_trace_save (api_main_t * am,
247 vl_api_trace_which_t which, FILE * fp);
248 int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
250 void vl_msg_api_handler_with_vm_node (api_main_t * am,
251 void *the_msg, vlib_main_t * vm,
252 vlib_node_runtime_t * node);
253 void vl_msg_api_handler (void *the_msg);
254 void vl_msg_api_handler_no_free (void *the_msg);
255 void vl_msg_api_handler_no_trace_no_free (void *the_msg);
256 void vl_msg_api_trace_only (void *the_msg);
257 void vl_msg_api_cleanup_handler (void *the_msg);
258 void vl_msg_api_replay_handler (void *the_msg);
259 void vl_msg_api_socket_handler (void *the_msg);
260 void vl_msg_api_set_handlers (int msg_id, char *msg_name,
264 void *print, int msg_size, int traced);
265 void vl_msg_api_config (vl_msg_api_msg_config_t *);
266 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
267 void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q);
268 vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am,
269 vl_api_trace_which_t which);
271 void vl_msg_api_barrier_sync (void) __attribute__ ((weak));
272 void vl_msg_api_barrier_release (void) __attribute__ ((weak));
273 void vl_msg_api_free (void *);
274 void vl_noop_handler (void *mp);
275 void vl_msg_api_increment_missing_client_counter (void);
276 void vl_msg_api_post_mortem_dump (void);
277 void vl_msg_api_post_mortem_dump_enable_disable (int enable);
278 void vl_msg_api_register_pd_handler (void *handler,
279 u16 msg_id_host_byte_order);
280 int vl_msg_api_pd_handler (void *mp, int rv);
282 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
283 u16 vl_msg_api_get_msg_ids (const char *name, int n);
284 void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
286 u32 vl_api_get_msg_index (u8 * name_and_crc);
287 u32 vl_msg_api_get_msg_length (void *msg_arg);
289 /* node_serialize.c prototypes */
290 u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
291 u32 max_threads, int include_nexts,
293 vlib_node_t **vlib_node_unserialize (u8 * vector);
295 #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
297 /* Call given init function: used for init function dependencies. */
298 #define vlib_call_api_init_function(vm, x) \
300 extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
301 vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
302 clib_error_t * _error = 0; \
303 if (! hash_get (vm->init_functions_called, _f)) \
305 hash_set1 (vm->init_functions_called, _f); \
312 #define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
313 _vl_msg_api_##type##_function_##x
315 #define VL_MSG_API_FUNCTION_SYMBOL(x) \
316 _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
318 #define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \
319 vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \
320 static void __vl_msg_api_add_##tag##_function_##x (void) \
321 __attribute__((__constructor__)) ; \
323 static void __vl_msg_api_add_##tag##_function_##x (void) \
325 api_main_t * am = &api_main; \
326 static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \
327 _vl_msg_api_function.next_init_function \
328 = am->tag##_function_registrations; \
329 am->tag##_function_registrations = &_vl_msg_api_function; \
330 _vl_msg_api_function.f = &x; \
333 #define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
335 /* Call reaper function with client index */
336 #define vl_msg_api_call_reaper_function(ci) \
338 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \
339 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \
340 clib_error_t * _error = 0; \
345 vl_msg_api_get_msg_length_inline (void *msg_arg)
347 u8 *msg = (u8 *) msg_arg;
349 msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data));
351 return clib_net_to_host_u32 (header->data_len);
353 #endif /* included_api_h */
356 * fd.io coding-style-patch-verification: ON
359 * eval: (c-set-style "gnu")