Recombine diags and minimum barrier open time changes (VPP-968)
[vpp.git] / src / vlibapi / api_common.h
1 /*
2  *------------------------------------------------------------------
3  * api_common.h
4  *
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:
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 #ifndef included_api_common_h
21 #define included_api_common_h
22
23 #include <vppinfra/clib_error.h>
24 #include <svm/svm_common.h>
25 #include <vlibmemory/unix_shared_memory_queue.h>
26
27 typedef enum
28 {
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;
35
36 typedef struct vl_api_registration_
37 {
38   vl_registration_type_t registration_type;
39
40   /* Index in VLIB's brain (not shared memory). */
41   u32 vl_api_registration_pool_index;
42
43   u8 *name;
44
45   /*
46    * The following groups of data could be unioned, but my fingers are
47    * going to be sore enough.
48    */
49
50   /* shared memory only */
51   unix_shared_memory_queue_t *vl_input_queue;
52
53   /* socket server and client */
54   u32 clib_file_index;
55   i8 *unprocessed_input;
56   u32 unprocessed_msg_length;
57   u8 *output_vector;
58
59   /* socket client only */
60   u32 server_handle;
61   u32 server_index;
62
63 } vl_api_registration_t;
64
65
66 /* Trace configuration for a single message */
67 typedef struct
68 {
69   int size;
70   int trace_enable;
71   int replay_enable;
72 } trace_cfg_t;
73
74 /*
75  * API recording
76  */
77 typedef struct
78 {
79   u8 endian;
80   u8 enabled;
81   u8 wrapped;
82   u8 pad;
83   u32 nitems;
84   u32 curindex;
85   u8 **traces;
86 } vl_api_trace_t;
87
88 typedef enum
89 {
90   VL_API_TRACE_TX,
91   VL_API_TRACE_RX,
92 } vl_api_trace_which_t;
93
94 #define VL_API_LITTLE_ENDIAN 0x00
95 #define VL_API_BIG_ENDIAN 0x01
96
97 typedef struct
98 {
99   u8 *name;
100   u16 first_msg_id;
101   u16 last_msg_id;
102 } vl_api_msg_range_t;
103
104 typedef struct
105 {
106   int id;
107   char *name;
108   u32 crc;
109   void *handler;
110   void *cleanup;
111   void *endian;
112   void *print;
113   int size;
114   int traced;
115   int replay;
116   int message_bounce;
117   int is_mp_safe;
118 } vl_msg_api_msg_config_t;
119
120 typedef struct msgbuf_
121 {
122   unix_shared_memory_queue_t *q;
123   u32 data_len;
124   u32 gc_mark_timestamp;
125   u8 data[0];
126 } msgbuf_t;
127
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,
137                               void *handler,
138                               void *cleanup,
139                               void *endian,
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);
144
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));
150 #else
151 #define vl_msg_api_barrier_trace_context(X)
152 #endif
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);
161
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);
165
166 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
167
168 typedef struct _vl_msg_api_init_function_list_elt
169 {
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;
173
174 typedef struct
175 {
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;
182   u8 *message_bounce;
183   u8 *is_mp_safe;
184   struct ring_alloc_ *arings;
185   u32 ring_misses;
186   u32 garbage_collects;
187   u32 missing_clients;
188   vl_api_trace_t *rx_trace;
189   vl_api_trace_t *tx_trace;
190   int msg_print_flag;
191   trace_cfg_t *api_trace_cfg;
192   int our_pid;
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;
197
198   u8 *serialized_message_table_in_shmem;
199
200   /* For plugin msg allocator */
201   u16 first_available_msg_id;
202
203   /* message range by name hash */
204   uword *msg_range_by_name;
205
206   /* vector of message ranges */
207   vl_api_msg_range_t *msg_ranges;
208
209   /* uid for the api shared memory region */
210   int api_uid;
211   /* gid for the api shared memory region */
212   int api_gid;
213
214   /* base virtual address for global VM region */
215   u64 global_baseva;
216
217   /* size of the global VM region */
218   u64 global_size;
219
220   /* size of the API region */
221   u64 api_size;
222
223   /* size of the global VM private mheap */
224   u64 global_pvt_heap_size;
225
226   /* size of the api private mheap */
227   u64 api_pvt_heap_size;
228
229   /* Client-only data structures */
230   unix_shared_memory_queue_t *vl_input_queue;
231
232   /*
233    * All VLIB-side message handlers use my_client_index to identify
234    * the queue / client. This works in sim replay.
235    */
236   int my_client_index;
237   /*
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.
241    */
242   vl_api_registration_t *my_registration;
243
244   i32 vlib_signal;
245
246   /* vlib input queue length */
247   u32 vlib_input_queue_length;
248
249   /* client side message index hash table */
250   uword *msg_index_by_name_and_crc;
251
252   const char *region_name;
253   const char *root_path;
254
255   /* Replay in progress? */
256   int replay_in_progress;
257
258   /* List of API client reaper functions */
259   _vl_msg_api_function_list_elt_t *reaper_function_registrations;
260
261 } api_main_t;
262
263 extern api_main_t api_main;
264
265
266 #endif /* included_api_common_h */
267
268 /*
269  * fd.io coding-style-patch-verification: ON
270  *
271  * Local Variables:
272  * eval: (c-set-style "gnu")
273  * End:
274  */