FD.io VPP  v16.06
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.h>
25 #include <vlib/vlib.h>
27 #include <vlib/unix/unix.h>
28 
29 typedef enum {
36 
37 typedef struct vl_api_registration_ {
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  int size;
71 } trace_cfg_t;
72 
73 /*
74  * API recording
75  */
76 typedef struct {
85 
86 typedef CLIB_PACKED (struct {
87  u8 endian;
88  u8 wrapped;
89  u32 nitems;
90 }) vl_api_trace_file_header_t;
91 
92 typedef enum {
96 
97 #define VL_API_LITTLE_ENDIAN 0x00
98 #define VL_API_BIG_ENDIAN 0x01
99 
100 typedef struct {
101  u8 * name;
105 
106 typedef struct {
107  void (**msg_handlers)(void *);
108  int (**pd_msg_handlers)(void *, int);
109  void (**msg_cleanup_handlers)(void *);
110  void (**msg_endian_handlers)(void *);
111  void (**msg_print_handlers)(void *, void *);
112  char **msg_names;
122  int our_pid;
127 
128  /* For plugin msg allocator */
130 
131  /* message range by name hash */
133 
134  /* vector of message ranges */
136 
137  /* gid for the api shared memory region */
138  int api_gid;
139  int api_uid;
140 
141  /* Client-only data structures */
143 
144  /*
145  * All VLIB-side message handlers use my_client_index to identify
146  * the queue / client. This works in sim replay.
147  */
149  /*
150  * This is the (shared VM) address of the registration,
151  * don't use it to id the connection since it can't possibly
152  * work in simulator replay.
153  */
155 
157 
158  char *region_name;
159  char *root_path;
160 } api_main_t;
161 
163 
164 typedef struct {
165  int id;
166  char *name;
167  void *handler;
168  void *cleanup;
169  void *endian;
170  void *print;
171  int size;
172  int traced;
173  int replay;
177 
178 /* api_shared.c prototypes */
181 void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg);
182 int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which,
183  int onoff);
184 int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which);
186  vl_api_trace_which_t which, FILE *fp);
187 int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which,
188  u32 nitems);
190  void *the_msg, vlib_main_t *vm,
191  vlib_node_runtime_t *node);
192 void vl_msg_api_handler (void *the_msg);
193 void vl_msg_api_handler_no_free (void *the_msg);
194 void vl_msg_api_handler_no_trace_no_free (void *the_msg);
195 void vl_msg_api_trace_only (void *the_msg);
196 void vl_msg_api_cleanup_handler (void *the_msg);
197 void vl_msg_api_replay_handler(void *the_msg);
198 void vl_msg_api_socket_handler(void *the_msg);
199 void vl_msg_api_set_handlers(int msg_id, char *msg_name,
200  void *handler,
201  void *cleanup,
202  void *endian,
203  void *print,
204  int msg_size, int traced);
206 void vl_msg_api_set_cleanup_handler(int msg_id, void *fp);
209  vl_api_trace_which_t which);
210 
211 void vl_msg_api_free (void *);
212 void vl_noop_handler (void *mp);
215 void vl_msg_api_post_mortem_dump (void);
216 void vl_msg_api_register_pd_handler (void *handler, u16 msg_id_host_byte_order);
217 int vl_msg_api_pd_handler (void *mp, int rv);
218 
219 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
220 u16 vl_msg_api_get_msg_ids (char * name, int n);
221 
222 /* node_serialize.c prototypes */
223 u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector);
224 vlib_node_t ** vlib_node_unserialize (u8 * vector);
225 
226 #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
227 
228 #endif /* included_api_h */
u32 unix_file_index
Definition: api.h:54
char * region_name
Definition: api.h:158
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
u8 wrapped
Definition: api.h:79
int size
Definition: api.h:68
int my_client_index
Definition: api.h:148
u8 * message_bounce
Definition: api.h:113
vlib_node_t ** vlib_node_unserialize(u8 *vector)
int api_uid
Definition: api.h:139
u32 server_index
Definition: api.h:61
int api_gid
Definition: api.h:138
trace_cfg_t * api_trace_cfg
Definition: api.h:121
void vl_msg_api_config(vl_msg_api_msg_config_t *)
Definition: api_shared.c:559
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
Definition: api_shared.c:1101
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:142
void vl_msg_api_post_mortem_dump(void)
Definition: api_shared.c:1036
struct vl_api_registration_ vl_api_registration_t
u8 pad
Definition: api.h:80
api_main_t api_main
Definition: api.h:162
int our_pid
Definition: api.h:122
void vl_msg_api_handler_no_free(void *the_msg)
Definition: threads.c:316
vl_api_registration_t * my_registration
Definition: api.h:154
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:586
vl_api_trace_t * rx_trace
Definition: api.h:118
u32 ring_misses
Definition: api.h:116
void vl_msg_api_free(void *)
vl_api_registration_t ** vl_clients
Definition: api.h:126
int i32
Definition: types.h:81
char i8
Definition: types.h:45
svm_region_t * vlib_rp
Definition: api.h:123
struct vl_shmem_hdr_ * shmem_hdr
Definition: api.h:125
void vl_msg_api_cleanup_handler(void *the_msg)
Definition: api_shared.c:503
void vl_msg_api_replay_handler(void *the_msg)
Definition: api_shared.c:521
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:148
vl_registration_type_t registration_type
Definition: api.h:38
u16 last_msg_id
Definition: api.h:103
int vl_msg_api_tx_trace_enabled(api_main_t *am)
Definition: api_shared.c:64
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:623
int replay_enable
Definition: api.h:70
u32 curindex
Definition: api.h:82
u32 unprocessed_msg_length
Definition: api.h:56
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:398
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
Definition: api_shared.c:183
u8 enabled
Definition: api.h:78
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
Definition: api_shared.c:109
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
Definition: api_shared.c:606
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:51
vl_api_msg_range_t * msg_ranges
Definition: api.h:135
int vl_msg_api_pd_handler(void *mp, int rv)
Definition: api_shared.c:1081
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:72
u8 * output_vector
Definition: api.h:57
void vl_msg_api_register_pd_handler(void *handler, u16 msg_id_host_byte_order)
Definition: api_shared.c:1068
u8 ** traces
Definition: api.h:83
vl_api_trace_which_t
Definition: api.h:92
vl_registration_type_t
Definition: api.h:29
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:477
vl_api_trace_t * tx_trace
Definition: api.h:119
unsigned int u32
Definition: types.h:88
typedef CLIB_PACKED(struct{u8 endian;u8 wrapped;u32 nitems;}) vl_api_trace_file_header_t
i8 * unprocessed_input
Definition: api.h:55
char ** msg_names
Definition: api.h:112
struct ring_alloc_ * arings
Definition: api.h:115
u8 * vlib_node_serialize(vlib_node_main_t *nm, u8 *vector)
i32 vlib_signal
Definition: api.h:156
u64 uword
Definition: types.h:112
char * root_path
Definition: api.h:159
u32 missing_clients
Definition: api.h:117
unsigned short u16
Definition: types.h:57
void vl_msg_api_socket_handler(void *the_msg)
Definition: api_shared.c:539
u16 first_msg_id
Definition: api.h:102
unsigned char u8
Definition: types.h:56
void vl_msg_api_trace_only(void *the_msg)
Definition: api_shared.c:493
void vl_msg_api_handler(void *the_msg)
Definition: api_shared.c:458
u32 vl_api_registration_pool_index
Definition: api.h:41
int vl_msg_api_rx_trace_enabled(api_main_t *am)
Definition: api_shared.c:59
u16 first_available_msg_id
Definition: api.h:129
void vl_msg_api_increment_missing_client_counter(void)
Definition: api_shared.c:46
u8 endian
Definition: api.h:77
u8 * is_mp_safe
Definition: api.h:114
void vl_noop_handler(void *mp)
Definition: api_shared.c:636
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
Definition: api_shared.c:615
int trace_enable
Definition: api.h:69
int msg_print_flag
Definition: api.h:120
u32 server_handle
Definition: api.h:60
u16 vl_msg_api_get_msg_ids(char *name, int n)
Definition: api_shared.c:1108
svm_region_t ** mapped_shmem_regions
Definition: api.h:124
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
Definition: api_shared.c:279
uword * msg_range_by_name
Definition: api.h:132
u32 nitems
Definition: api.h:81
clib_error_t * vl_api_init(vlib_main_t *vm)
Definition: api_shared.c:639
struct _unix_shared_memory_queue unix_shared_memory_queue_t