FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
api.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * api.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_h
21 #define included_api_h
22 
23 #include <vppinfra/error.h>
24 #include <svm/svm.h>
25 #include <vlib/vlib.h>
27 #include <vlib/unix/unix.h>
28 
29 typedef enum
30 {
37 
38 typedef struct vl_api_registration_
39 {
40  vl_registration_type_t registration_type;
41 
42  /* Index in VLIB's brain (not shared memory). */
44 
45  u8 *name;
46 
47  /*
48  * The following groups of data could be unioned, but my fingers are
49  * going to be sore enough.
50  */
51 
52  /* shared memory only */
54 
55  /* socket server and client */
60 
61  /* socket client only */
64 
66 
67 
68 /* Trace configuration for a single message */
69 typedef struct
70 {
71  int size;
74 } trace_cfg_t;
75 
76 /*
77  * API recording
78  */
79 typedef struct
80 {
89 
90 /* *INDENT-OFF* */
91 typedef CLIB_PACKED
92 (struct
93  {
94  u8 endian; u8 wrapped;
95  u32 nitems;
96 }) vl_api_trace_file_header_t;
97 /* *INDENT-ON* */
98 
99 typedef enum
100 {
104 
105 #define VL_API_LITTLE_ENDIAN 0x00
106 #define VL_API_BIG_ENDIAN 0x01
107 
108 typedef struct
109 {
114 
115 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
116 
117 typedef struct _vl_msg_api_init_function_list_elt
118 {
119  struct _vl_msg_api_init_function_list_elt *next_init_function;
121 } _vl_msg_api_function_list_elt_t;
122 
123 typedef struct
124 {
125  void (**msg_handlers) (void *);
126  int (**pd_msg_handlers) (void *, int);
127  void (**msg_cleanup_handlers) (void *);
128  void (**msg_endian_handlers) (void *);
129  void (**msg_print_handlers) (void *, void *);
130  char **msg_names;
141  int our_pid;
146 
148 
149  /* For plugin msg allocator */
151 
152  /* message range by name hash */
154 
155  /* vector of message ranges */
157 
158  /* uid for the api shared memory region */
159  int api_uid;
160  /* gid for the api shared memory region */
161  int api_gid;
162 
163  /* base virtual address for global VM region */
165 
166  /* size of the global VM region */
168 
169  /* size of the API region */
171 
172  /* size of the global VM private mheap */
174 
175  /* size of the api private mheap */
177 
178  /* Client-only data structures */
180 
181  /*
182  * All VLIB-side message handlers use my_client_index to identify
183  * the queue / client. This works in sim replay.
184  */
186  /*
187  * This is the (shared VM) address of the registration,
188  * don't use it to id the connection since it can't possibly
189  * work in simulator replay.
190  */
192 
194 
195  /* client side message index hash table */
197 
198  char *region_name;
199  char *root_path;
200 
201  /* Replay in progress? */
203 
204  /* List of API client reaper functions */
205  _vl_msg_api_function_list_elt_t *reaper_function_registrations;
206 
207 } api_main_t;
208 
209 extern api_main_t api_main;
210 
211 typedef struct
212 {
213  int id;
214  char *name;
216  void *handler;
217  void *cleanup;
218  void *endian;
219  void *print;
220  int size;
221  int traced;
222  int replay;
226 
227 typedef struct msgbuf_
228 {
232  u8 data[0];
233 } msgbuf_t;
234 
235 /* api_shared.c prototypes */
238 void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg);
239 int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
240  int onoff);
241 int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which);
243  vl_api_trace_which_t which, FILE * fp);
244 int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
245  u32 nitems);
247  void *the_msg, vlib_main_t * vm,
248  vlib_node_runtime_t * node);
249 void vl_msg_api_handler (void *the_msg);
250 void vl_msg_api_handler_no_free (void *the_msg);
251 void vl_msg_api_handler_no_trace_no_free (void *the_msg);
252 void vl_msg_api_trace_only (void *the_msg);
253 void vl_msg_api_cleanup_handler (void *the_msg);
254 void vl_msg_api_replay_handler (void *the_msg);
255 void vl_msg_api_socket_handler (void *the_msg);
256 void vl_msg_api_set_handlers (int msg_id, char *msg_name,
257  void *handler,
258  void *cleanup,
259  void *endian,
260  void *print, int msg_size, int traced);
262 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
265  vl_api_trace_which_t which);
266 
267 void vl_msg_api_barrier_sync (void) __attribute__ ((weak));
268 void vl_msg_api_barrier_release (void) __attribute__ ((weak));
269 void vl_msg_api_free (void *);
270 void vl_noop_handler (void *mp);
272 void vl_msg_api_post_mortem_dump (void);
274 void vl_msg_api_register_pd_handler (void *handler,
275  u16 msg_id_host_byte_order);
276 int vl_msg_api_pd_handler (void *mp, int rv);
277 
278 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
279 u16 vl_msg_api_get_msg_ids (char *name, int n);
280 void vl_msg_api_add_msg_name_crc (api_main_t * am, char *string, u32 id);
281 u32 vl_api_get_msg_index (u8 * name_and_crc);
282 
283 /* node_serialize.c prototypes */
284 u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
285  u32 max_threads, int include_nexts,
286  int include_stats);
288 
289 #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
290 
291 /* Call given init function: used for init function dependencies. */
292 #define vlib_call_api_init_function(vm, x) \
293  ({ \
294  extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
295  vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
296  clib_error_t * _error = 0; \
297  if (! hash_get (vm->init_functions_called, _f)) \
298  { \
299  hash_set1 (vm->init_functions_called, _f); \
300  _error = _f (vm); \
301  } \
302  _error; \
303  })
304 
305 
306 #define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
307  _vl_msg_api_##type##_function_##x
308 
309 #define VL_MSG_API_FUNCTION_SYMBOL(x) \
310  _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
311 
312 #define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \
313 vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \
314 static void __vl_msg_api_add_##tag##_function_##x (void) \
315  __attribute__((__constructor__)) ; \
316  \
317 static void __vl_msg_api_add_##tag##_function_##x (void) \
318 { \
319  api_main_t * am = &api_main; \
320  static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \
321  _vl_msg_api_function.next_init_function \
322  = am->tag##_function_registrations; \
323  am->tag##_function_registrations = &_vl_msg_api_function; \
324  _vl_msg_api_function.f = &x; \
325 }
326 
327 #define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
328 
329 /* Call reaper function with client index */
330 #define vl_msg_api_call_reaper_function(ci) \
331  ({ \
332  extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \
333  vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \
334  clib_error_t * _error = 0; \
335  _error = _f (ci); \
336  })
337 
338 #endif /* included_api_h */
339 
340 /*
341  * fd.io coding-style-patch-verification: ON
342  *
343  * Local Variables:
344  * eval: (c-set-style "gnu")
345  * End:
346  */
u32 unix_file_index
Definition: api.h:56
u64 api_pvt_heap_size
Definition: api.h:176
char * region_name
Definition: api.h:198
u64 api_size
Definition: api.h:170
u8 wrapped
Definition: api.h:83
int size
Definition: api.h:71
int my_client_index
Definition: api.h:185
u8 * message_bounce
Definition: api.h:131
u32 gc_mark_timestamp
Definition: api.h:231
void vl_msg_api_barrier_sync(void)
Definition: api_shared.c:383
vlib_node_t ** vlib_node_unserialize(u8 *vector)
int api_uid
Definition: api.h:159
u32 server_index
Definition: api.h:63
void vl_msg_api_post_mortem_dump_enable_disable(int enable)
Definition: api_shared.c:747
u8 * vlib_node_serialize(vlib_node_main_t *nm, u8 *vector, u32 max_threads, int include_nexts, int include_stats)
int api_gid
Definition: api.h:161
trace_cfg_t * api_trace_cfg
Definition: api.h:140
static void cleanup(void)
Definition: pneum.c:90
void vl_msg_api_config(vl_msg_api_msg_config_t *)
Definition: api_shared.c:652
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
Definition: api_shared.c:823
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:179
void vl_msg_api_post_mortem_dump(void)
Definition: api_shared.c:753
struct vl_api_registration_ vl_api_registration_t
_vl_msg_api_function_list_elt_t * reaper_function_registrations
Definition: api.h:205
u8 pad
Definition: api.h:84
api_main_t api_main
Definition: api_shared.c:35
int our_pid
Definition: api.h:141
void vl_msg_api_handler_no_free(void *the_msg)
Definition: threads.c:328
vl_api_registration_t * my_registration
Definition: api.h:191
void vl_msg_api_set_handlers(int msg_id, char *msg_name, void *handler, void *cleanup, void *endian, void *print, int msg_size, int traced)
Definition: api_shared.c:684
vl_api_trace_t * rx_trace
Definition: api.h:137
u32 ring_misses
Definition: api.h:134
void vl_msg_api_free(void *)
vl_api_registration_t ** vl_clients
Definition: api.h:145
int i32
Definition: types.h:81
char i8
Definition: types.h:45
int replay_in_progress
Definition: api.h:202
svm_region_t * vlib_rp
Definition: api.h:142
unsigned long u64
Definition: types.h:89
struct vl_shmem_hdr_ * shmem_hdr
Definition: api.h:144
void vl_msg_api_cleanup_handler(void *the_msg)
Definition: api_shared.c:590
void vl_msg_api_replay_handler(void *the_msg)
Definition: api_shared.c:610
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:154
vl_registration_type_t registration_type
Definition: api.h:40
u16 last_msg_id
Definition: api.h:112
int vl_msg_api_tx_trace_enabled(api_main_t *am)
Definition: api_shared.c:57
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:725
int replay_enable
Definition: api.h:73
void vl_msg_api_barrier_release(void)
Definition: api_shared.c:388
u32 curindex
Definition: api.h:86
u32 unprocessed_msg_length
Definition: api.h:58
struct msgbuf_ msgbuf_t
void vl_msg_api_handler_with_vm_node(api_main_t *am, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node)
Definition: api_shared.c:465
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
Definition: api_shared.c:191
u64 global_size
Definition: api.h:167
u8 enabled
Definition: api.h:82
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
Definition: api_shared.c:112
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
Definition: api_shared.c:706
clib_error_t *( vl_msg_api_init_function_t)(u32 client_index)
Definition: api.h:115
vlib_main_t * vm
Definition: buffer.c:276
u64 global_baseva
Definition: api.h:164
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:53
unix_shared_memory_queue_t * q
Definition: api.h:229
vl_api_msg_range_t * msg_ranges
Definition: api.h:156
int vl_msg_api_pd_handler(void *mp, int rv)
Definition: api_shared.c:802
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:66
u8 * output_vector
Definition: api.h:59
void vl_msg_api_register_pd_handler(void *handler, u16 msg_id_host_byte_order)
Definition: api_shared.c:788
u8 ** traces
Definition: api.h:87
u32 vl_api_get_msg_index(u8 *name_and_crc)
vl_api_trace_which_t
Definition: api.h:99
vl_registration_type_t
Definition: api.h:29
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:562
vl_api_trace_t * tx_trace
Definition: api.h:138
u32 garbage_collects
Definition: api.h:135
unsigned int u32
Definition: types.h:88
u32 data_len
Definition: api.h:230
Definition: api.h:227
void vl_msg_api_add_msg_name_crc(api_main_t *am, char *string, u32 id)
Definition: api_shared.c:875
u8 * serialized_message_table_in_shmem
Definition: api.h:147
typedef CLIB_PACKED(struct{u8 endian;u8 wrapped;u32 nitems;}) vl_api_trace_file_header_t
u64 global_pvt_heap_size
Definition: api.h:173
i8 * unprocessed_input
Definition: api.h:57
char ** msg_names
Definition: api.h:130
struct ring_alloc_ * arings
Definition: api.h:133
i32 vlib_signal
Definition: api.h:193
u64 uword
Definition: types.h:112
char * root_path
Definition: api.h:199
u32 missing_clients
Definition: api.h:136
unsigned short u16
Definition: types.h:57
void vl_msg_api_socket_handler(void *the_msg)
Definition: api_shared.c:631
u16 first_msg_id
Definition: api.h:111
unsigned char u8
Definition: types.h:56
void vl_msg_api_trace_only(void *the_msg)
Definition: api_shared.c:579
void vl_msg_api_handler(void *the_msg)
Definition: api_shared.c:541
u32 vl_api_registration_pool_index
Definition: api.h:43
int vl_msg_api_rx_trace_enabled(api_main_t *am)
Definition: api_shared.c:51
u16 first_available_msg_id
Definition: api.h:150
void vl_msg_api_increment_missing_client_counter(void)
Definition: api_shared.c:44
u8 endian
Definition: api.h:81
u8 * is_mp_safe
Definition: api.h:132
void vl_noop_handler(void *mp)
Definition: api_shared.c:739
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
Definition: api_shared.c:716
int trace_enable
Definition: api.h:72
int msg_print_flag
Definition: api.h:139
u32 server_handle
Definition: api.h:62
u16 vl_msg_api_get_msg_ids(char *name, int n)
Definition: api_shared.c:831
svm_region_t ** mapped_shmem_regions
Definition: api.h:143
uword * msg_index_by_name_and_crc
Definition: api.h:196
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
Definition: api_shared.c:322
uword * msg_range_by_name
Definition: api.h:153
u32 nitems
Definition: api.h:85
struct _unix_shared_memory_queue unix_shared_memory_queue_t