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 /* client side message index hash table */
197 uword *msg_index_by_name_and_crc;
199 const char *region_name;
200 const char *root_path;
202 /* Replay in progress? */
203 int replay_in_progress;
205 /* List of API client reaper functions */
206 _vl_msg_api_function_list_elt_t *reaper_function_registrations;
210 extern api_main_t api_main;
226 } vl_msg_api_msg_config_t;
228 typedef struct msgbuf_
230 unix_shared_memory_queue_t *q;
232 u32 gc_mark_timestamp;
236 /* api_shared.c prototypes */
237 int vl_msg_api_rx_trace_enabled (api_main_t * am);
238 int vl_msg_api_tx_trace_enabled (api_main_t * am);
239 void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg);
240 int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
242 int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which);
243 int vl_msg_api_trace_save (api_main_t * am,
244 vl_api_trace_which_t which, FILE * fp);
245 int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
247 void vl_msg_api_handler_with_vm_node (api_main_t * am,
248 void *the_msg, vlib_main_t * vm,
249 vlib_node_runtime_t * node);
250 void vl_msg_api_handler (void *the_msg);
251 void vl_msg_api_handler_no_free (void *the_msg);
252 void vl_msg_api_handler_no_trace_no_free (void *the_msg);
253 void vl_msg_api_trace_only (void *the_msg);
254 void vl_msg_api_cleanup_handler (void *the_msg);
255 void vl_msg_api_replay_handler (void *the_msg);
256 void vl_msg_api_socket_handler (void *the_msg);
257 void vl_msg_api_set_handlers (int msg_id, char *msg_name,
261 void *print, int msg_size, int traced);
262 void vl_msg_api_config (vl_msg_api_msg_config_t *);
263 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
264 void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q);
265 vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am,
266 vl_api_trace_which_t which);
268 void vl_msg_api_barrier_sync (void) __attribute__ ((weak));
269 void vl_msg_api_barrier_release (void) __attribute__ ((weak));
270 void vl_msg_api_free (void *);
271 void vl_noop_handler (void *mp);
272 void vl_msg_api_increment_missing_client_counter (void);
273 void vl_msg_api_post_mortem_dump (void);
274 void vl_msg_api_post_mortem_dump_enable_disable (int enable);
275 void vl_msg_api_register_pd_handler (void *handler,
276 u16 msg_id_host_byte_order);
277 int vl_msg_api_pd_handler (void *mp, int rv);
279 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
280 u16 vl_msg_api_get_msg_ids (const char *name, int n);
281 void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
283 u32 vl_api_get_msg_index (u8 * name_and_crc);
284 u32 vl_msg_api_get_msg_length (void *msg_arg);
286 /* node_serialize.c prototypes */
287 u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
288 u32 max_threads, int include_nexts,
290 vlib_node_t **vlib_node_unserialize (u8 * vector);
292 #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
294 /* Call given init function: used for init function dependencies. */
295 #define vlib_call_api_init_function(vm, x) \
297 extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
298 vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
299 clib_error_t * _error = 0; \
300 if (! hash_get (vm->init_functions_called, _f)) \
302 hash_set1 (vm->init_functions_called, _f); \
309 #define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
310 _vl_msg_api_##type##_function_##x
312 #define VL_MSG_API_FUNCTION_SYMBOL(x) \
313 _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
315 #define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \
316 vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \
317 static void __vl_msg_api_add_##tag##_function_##x (void) \
318 __attribute__((__constructor__)) ; \
320 static void __vl_msg_api_add_##tag##_function_##x (void) \
322 api_main_t * am = &api_main; \
323 static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \
324 _vl_msg_api_function.next_init_function \
325 = am->tag##_function_registrations; \
326 am->tag##_function_registrations = &_vl_msg_api_function; \
327 _vl_msg_api_function.f = &x; \
330 #define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
332 /* Call reaper function with client index */
333 #define vl_msg_api_call_reaper_function(ci) \
335 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \
336 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \
337 clib_error_t * _error = 0; \
342 vl_msg_api_get_msg_length_inline (void *msg_arg)
344 u8 *msg = (u8 *) msg_arg;
346 msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data));
348 return clib_net_to_host_u32 (header->data_len);
350 #endif /* included_api_h */
353 * fd.io coding-style-patch-verification: ON
356 * eval: (c-set-style "gnu")