FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
api_common.h
Go to the documentation of this file.
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>
26 
27 typedef enum
28 {
35 
36 typedef struct vl_api_registration_
37 {
39 
40  /* Index in VLIB's brain (not shared memory). */
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 */
52 
53  /* socket server and client */
58 
59  /* socket client only */
62 
64 
65 
66 /* Trace configuration for a single message */
67 typedef struct
68 {
69  int size;
72 } trace_cfg_t;
73 
74 /*
75  * API recording
76  */
77 typedef struct
78 {
87 
88 typedef enum
89 {
93 
94 #define VL_API_LITTLE_ENDIAN 0x00
95 #define VL_API_BIG_ENDIAN 0x01
96 
97 typedef struct
98 {
99  u8 *name;
103 
104 typedef struct
105 {
106  int id;
107  char *name;
109  void *handler;
110  void *cleanup;
111  void *endian;
112  void *print;
113  int size;
114  int traced;
115  int replay;
119 
120 typedef struct msgbuf_
121 {
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);
142 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
144 
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);
150 void vl_msg_api_post_mortem_dump (void);
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);
155 
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);
159 
160 typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
161 
162 typedef struct _vl_msg_api_init_function_list_elt
163 {
164  struct _vl_msg_api_init_function_list_elt *next_init_function;
166 } _vl_msg_api_function_list_elt_t;
167 
168 typedef struct
169 {
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;
186  int our_pid;
191 
193 
194  /* For plugin msg allocator */
196 
197  /* message range by name hash */
199 
200  /* vector of message ranges */
202 
203  /* uid for the api shared memory region */
204  int api_uid;
205  /* gid for the api shared memory region */
206  int api_gid;
207 
208  /* base virtual address for global VM region */
210 
211  /* size of the global VM region */
213 
214  /* size of the API region */
216 
217  /* size of the global VM private mheap */
219 
220  /* size of the api private mheap */
222 
223  /* Client-only data structures */
225 
226  /*
227  * All VLIB-side message handlers use my_client_index to identify
228  * the queue / client. This works in sim replay.
229  */
231  /*
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.
235  */
237 
239 
240  /* vlib input queue length */
242 
243  /* client side message index hash table */
245 
246  const char *region_name;
247  const char *root_path;
248 
249  /* Replay in progress? */
251 
252  /* List of API client reaper functions */
253  _vl_msg_api_function_list_elt_t *reaper_function_registrations;
254 
255 } api_main_t;
256 
257 extern api_main_t api_main;
258 
259 
260 #endif /* included_api_common_h */
261 
262 /*
263  * fd.io coding-style-patch-verification: ON
264  *
265  * Local Variables:
266  * eval: (c-set-style "gnu")
267  * End:
268  */
void vl_msg_api_config(vl_msg_api_msg_config_t *)
Definition: api_shared.c:658
u64 api_pvt_heap_size
Definition: api_common.h:221
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:837
struct msgbuf_ msgbuf_t
u64 api_size
Definition: api_common.h:215
int my_client_index
Definition: api_common.h:230
u8 * message_bounce
Definition: api_common.h:176
u32 gc_mark_timestamp
Definition: api_common.h:124
trace_cfg_t * api_trace_cfg
Definition: api_common.h:185
unix_shared_memory_queue_t * vl_input_queue
Definition: api_common.h:224
_vl_msg_api_function_list_elt_t * reaper_function_registrations
Definition: api_common.h:253
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
Definition: api_shared.c:712
vl_api_registration_t * my_registration
Definition: api_common.h:236
vl_api_trace_t * rx_trace
Definition: api_common.h:182
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:562
u32 ring_misses
Definition: api_common.h:179
vl_api_registration_t ** vl_clients
Definition: api_common.h:190
int i32
Definition: types.h:81
char i8
Definition: types.h:45
int replay_in_progress
Definition: api_common.h:250
const char * root_path
Definition: api_common.h:247
svm_region_t * vlib_rp
Definition: api_common.h:187
unsigned long u64
Definition: types.h:89
struct vl_shmem_hdr_ * shmem_hdr
Definition: api_common.h:189
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
Definition: api_shared.c:829
void vl_msg_api_post_mortem_dump(void)
Definition: api_shared.c:759
u32 vl_api_get_msg_index(u8 *name_and_crc)
vl_registration_type_t registration_type
Definition: api_common.h:38
struct vl_api_registration_ vl_api_registration_t
int replay_enable
Definition: api_common.h:71
void vl_msg_api_free(void *)
void vl_msg_api_handler(void *the_msg)
Definition: api_shared.c:541
static void cleanup(void)
Definition: client.c:90
void vl_msg_api_trace_only(void *the_msg)
Definition: api_shared.c:579
void vl_msg_api_barrier_sync(void)
Definition: api_shared.c:383
void vl_msg_api_socket_handler(void *the_msg)
Definition: api_shared.c:637
u64 global_size
Definition: api_common.h:212
api_main_t api_main
Definition: api_shared.c:35
vl_registration_type_t
Definition: api_common.h:27
void vl_msg_api_handler_no_free(void *the_msg)
Definition: threads.c:290
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:690
u64 global_baseva
Definition: api_common.h:209
unix_shared_memory_queue_t * vl_input_queue
Definition: api_common.h:51
unix_shared_memory_queue_t * q
Definition: api_common.h:122
vl_api_msg_range_t * msg_ranges
Definition: api_common.h:201
void vl_noop_handler(void *mp)
Definition: api_shared.c:745
int vl_msg_api_pd_handler(void *mp, int rv)
Definition: api_shared.c:808
const char ** msg_names
Definition: api_common.h:175
void vl_msg_api_barrier_release(void)
Definition: api_shared.c:388
void vl_msg_api_increment_missing_client_counter(void)
Definition: api_shared.c:44
vl_api_trace_t * tx_trace
Definition: api_common.h:183
u32 garbage_collects
Definition: api_common.h:180
unsigned int u32
Definition: types.h:88
u32 data_len
Definition: api_common.h:123
u8 * serialized_message_table_in_shmem
Definition: api_common.h:192
u64 global_pvt_heap_size
Definition: api_common.h:218
struct ring_alloc_ * arings
Definition: api_common.h:178
i32 vlib_signal
Definition: api_common.h:238
u64 uword
Definition: types.h:112
u32 missing_clients
Definition: api_common.h:181
void vl_msg_api_post_mortem_dump_enable_disable(int enable)
Definition: api_shared.c:753
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
u32 vl_api_registration_pool_index
Definition: api_common.h:41
void vl_msg_api_register_pd_handler(void *handler, u16 msg_id_host_byte_order)
Definition: api_shared.c:794
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
Definition: api_shared.c:722
u16 first_available_msg_id
Definition: api_common.h:195
u8 * is_mp_safe
Definition: api_common.h:177
int trace_enable
Definition: api_common.h:70
int msg_print_flag
Definition: api_common.h:184
void vl_msg_api_replay_handler(void *the_msg)
Definition: api_shared.c:610
void vl_msg_api_cleanup_handler(void *the_msg)
Definition: api_shared.c:590
vl_api_trace_which_t
Definition: api_common.h:88
const char * region_name
Definition: api_common.h:246
svm_region_t ** mapped_shmem_regions
Definition: api_common.h:188
uword * msg_index_by_name_and_crc
Definition: api_common.h:244
uword * msg_range_by_name
Definition: api_common.h:198
u32 vlib_input_queue_length
Definition: api_common.h:241
clib_error_t *( vl_msg_api_init_function_t)(u32 client_index)
Definition: api_common.h:160
struct _unix_shared_memory_queue unix_shared_memory_queue_t