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 #ifdef BARRIER_TRACING
148 void vl_msg_api_barrier_trace_context (const char *context)
149 __attribute__ ((weak));
151 #define vl_msg_api_barrier_trace_context(X)
153 void vl_msg_api_free (void *);
154 void vl_noop_handler (void *mp);
155 void vl_msg_api_increment_missing_client_counter (void);
156 void vl_msg_api_post_mortem_dump (void);
157 void vl_msg_api_post_mortem_dump_enable_disable (int enable);
158 void vl_msg_api_register_pd_handler (void *handler,
159 u16 msg_id_host_byte_order);
160 int vl_msg_api_pd_handler (void *mp, int rv);
162 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
163 u16 vl_msg_api_get_msg_ids (const char *name, int n);
164 u32 vl_api_get_msg_index (u8 * name_and_crc);
166 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
168 typedef struct _vl_msg_api_init_function_list_elt
170 struct _vl_msg_api_init_function_list_elt *next_init_function;
171 vl_msg_api_init_function_t *f;
172 } _vl_msg_api_function_list_elt_t;
176 void (**msg_handlers) (void *);
177 int (**pd_msg_handlers) (void *, int);
178 void (**msg_cleanup_handlers) (void *);
179 void (**msg_endian_handlers) (void *);
180 void (**msg_print_handlers) (void *, void *);
181 const char **msg_names;
184 struct ring_alloc_ *arings;
186 u32 garbage_collects;
188 vl_api_trace_t *rx_trace;
189 vl_api_trace_t *tx_trace;
191 trace_cfg_t *api_trace_cfg;
193 svm_region_t *vlib_rp;
194 svm_region_t **mapped_shmem_regions;
195 struct vl_shmem_hdr_ *shmem_hdr;
196 vl_api_registration_t **vl_clients;
198 u8 *serialized_message_table_in_shmem;
200 /* For plugin msg allocator */
201 u16 first_available_msg_id;
203 /* message range by name hash */
204 uword *msg_range_by_name;
206 /* vector of message ranges */
207 vl_api_msg_range_t *msg_ranges;
209 /* uid for the api shared memory region */
211 /* gid for the api shared memory region */
214 /* base virtual address for global VM region */
217 /* size of the global VM region */
220 /* size of the API region */
223 /* size of the global VM private mheap */
224 u64 global_pvt_heap_size;
226 /* size of the api private mheap */
227 u64 api_pvt_heap_size;
229 /* Client-only data structures */
230 unix_shared_memory_queue_t *vl_input_queue;
233 * All VLIB-side message handlers use my_client_index to identify
234 * the queue / client. This works in sim replay.
238 * This is the (shared VM) address of the registration,
239 * don't use it to id the connection since it can't possibly
240 * work in simulator replay.
242 vl_api_registration_t *my_registration;
246 /* vlib input queue length */
247 u32 vlib_input_queue_length;
249 /* client side message index hash table */
250 uword *msg_index_by_name_and_crc;
252 const char *region_name;
253 const char *root_path;
255 /* Replay in progress? */
256 int replay_in_progress;
258 /* List of API client reaper functions */
259 _vl_msg_api_function_list_elt_t *reaper_function_registrations;
263 extern api_main_t api_main;
266 #endif /* included_api_common_h */
269 * fd.io coding-style-patch-verification: ON
272 * eval: (c-set-style "gnu")