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_common_h
21 #define included_api_common_h
23 #include <vppinfra/clib_error.h>
24 #include <svm/svm_common.h>
25 #include <vlibmemory/unix_shared_memory_queue.h>
29 REGISTRATION_TYPE_FREE = 0,
30 REGISTRATION_TYPE_SHMEM,
31 REGISTRATION_TYPE_SOCKET_LISTEN,
32 REGISTRATION_TYPE_SOCKET_SERVER,
33 REGISTRATION_TYPE_SOCKET_CLIENT,
34 } vl_registration_type_t;
36 typedef struct vl_api_registration_
38 vl_registration_type_t registration_type;
40 /* Index in VLIB's brain (not shared memory). */
41 u32 vl_api_registration_pool_index;
46 * The following groups of data could be unioned, but my fingers are
47 * going to be sore enough.
50 /* shared memory only */
51 unix_shared_memory_queue_t *vl_input_queue;
53 /* socket server and client */
55 i8 *unprocessed_input;
56 u32 unprocessed_msg_length;
59 /* socket client only */
63 } vl_api_registration_t;
66 /* Trace configuration for a single message */
92 } vl_api_trace_which_t;
94 #define VL_API_LITTLE_ENDIAN 0x00
95 #define VL_API_BIG_ENDIAN 0x01
102 } vl_api_msg_range_t;
118 } vl_msg_api_msg_config_t;
120 typedef struct msgbuf_
122 unix_shared_memory_queue_t *q;
124 u32 gc_mark_timestamp;
128 /* api_shared.c prototypes */
129 void vl_msg_api_handler (void *the_msg);
130 void vl_msg_api_handler_no_free (void *the_msg);
131 void vl_msg_api_handler_no_trace_no_free (void *the_msg);
132 void vl_msg_api_trace_only (void *the_msg);
133 void vl_msg_api_cleanup_handler (void *the_msg);
134 void vl_msg_api_replay_handler (void *the_msg);
135 void vl_msg_api_socket_handler (void *the_msg);
136 void vl_msg_api_set_handlers (int msg_id, char *msg_name,
140 void *print, int msg_size, int traced);
141 void vl_msg_api_config (vl_msg_api_msg_config_t *);
142 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
143 void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q);
145 void vl_msg_api_barrier_sync (void) __attribute__ ((weak));
146 void vl_msg_api_barrier_release (void) __attribute__ ((weak));
147 void vl_msg_api_free (void *);
148 void vl_noop_handler (void *mp);
149 void vl_msg_api_increment_missing_client_counter (void);
150 void vl_msg_api_post_mortem_dump (void);
151 void vl_msg_api_post_mortem_dump_enable_disable (int enable);
152 void vl_msg_api_register_pd_handler (void *handler,
153 u16 msg_id_host_byte_order);
154 int vl_msg_api_pd_handler (void *mp, int rv);
156 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
157 u16 vl_msg_api_get_msg_ids (const char *name, int n);
158 u32 vl_api_get_msg_index (u8 * name_and_crc);
160 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
162 typedef struct _vl_msg_api_init_function_list_elt
164 struct _vl_msg_api_init_function_list_elt *next_init_function;
165 vl_msg_api_init_function_t *f;
166 } _vl_msg_api_function_list_elt_t;
170 void (**msg_handlers) (void *);
171 int (**pd_msg_handlers) (void *, int);
172 void (**msg_cleanup_handlers) (void *);
173 void (**msg_endian_handlers) (void *);
174 void (**msg_print_handlers) (void *, void *);
175 const char **msg_names;
178 struct ring_alloc_ *arings;
180 u32 garbage_collects;
182 vl_api_trace_t *rx_trace;
183 vl_api_trace_t *tx_trace;
185 trace_cfg_t *api_trace_cfg;
187 svm_region_t *vlib_rp;
188 svm_region_t **mapped_shmem_regions;
189 struct vl_shmem_hdr_ *shmem_hdr;
190 vl_api_registration_t **vl_clients;
192 u8 *serialized_message_table_in_shmem;
194 /* For plugin msg allocator */
195 u16 first_available_msg_id;
197 /* message range by name hash */
198 uword *msg_range_by_name;
200 /* vector of message ranges */
201 vl_api_msg_range_t *msg_ranges;
203 /* uid for the api shared memory region */
205 /* gid for the api shared memory region */
208 /* base virtual address for global VM region */
211 /* size of the global VM region */
214 /* size of the API region */
217 /* size of the global VM private mheap */
218 u64 global_pvt_heap_size;
220 /* size of the api private mheap */
221 u64 api_pvt_heap_size;
223 /* Client-only data structures */
224 unix_shared_memory_queue_t *vl_input_queue;
227 * All VLIB-side message handlers use my_client_index to identify
228 * the queue / client. This works in sim replay.
232 * This is the (shared VM) address of the registration,
233 * don't use it to id the connection since it can't possibly
234 * work in simulator replay.
236 vl_api_registration_t *my_registration;
240 /* vlib input queue length */
241 u32 vlib_input_queue_length;
243 /* client side message index hash table */
244 uword *msg_index_by_name_and_crc;
246 const char *region_name;
247 const char *root_path;
249 /* Replay in progress? */
250 int replay_in_progress;
252 /* List of API client reaper functions */
253 _vl_msg_api_function_list_elt_t *reaper_function_registrations;
257 extern api_main_t api_main;
260 #endif /* included_api_common_h */
263 * fd.io coding-style-patch-verification: ON
266 * eval: (c-set-style "gnu")