blob: 3c4b68dc00624e3ab8aaaf41fd4f1974f89df753 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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>
26#include <vlibmemory/unix_shared_memory_queue.h>
27#include <vlib/unix/unix.h>
28
29typedef enum {
30 REGISTRATION_TYPE_FREE=0,
31 REGISTRATION_TYPE_SHMEM,
32 REGISTRATION_TYPE_SOCKET_LISTEN,
33 REGISTRATION_TYPE_SOCKET_SERVER,
34 REGISTRATION_TYPE_SOCKET_CLIENT,
35} vl_registration_type_t;
36
37typedef struct vl_api_registration_ {
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 unix_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 */
67typedef struct {
68 int size;
69 int trace_enable;
70 int replay_enable;
71} trace_cfg_t;
72
73/*
74 * API recording
75 */
76typedef struct {
77 u8 endian;
78 u8 enabled;
79 u8 wrapped;
80 u8 pad;
81 u32 nitems;
82 u32 curindex;
83 u8 **traces;
84} vl_api_trace_t;
85
86typedef CLIB_PACKED (struct {
87 u8 endian;
88 u8 wrapped;
89 u32 nitems;
90}) vl_api_trace_file_header_t;
91
92typedef enum {
93 VL_API_TRACE_TX,
94 VL_API_TRACE_RX,
95} vl_api_trace_which_t;
96
97#define VL_API_LITTLE_ENDIAN 0x00
98#define VL_API_BIG_ENDIAN 0x01
99
100typedef struct {
101 u8 * name;
102 u16 first_msg_id;
103 u16 last_msg_id;
104} vl_api_msg_range_t;
105
106typedef 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;
113 u8 *message_bounce;
114 u8 *is_mp_safe;
115 struct ring_alloc_ *arings;
116 u32 ring_misses;
117 u32 missing_clients;
118 vl_api_trace_t *rx_trace;
119 vl_api_trace_t *tx_trace;
120 int msg_print_flag;
121 trace_cfg_t *api_trace_cfg;
122 int our_pid;
123 svm_region_t *vlib_rp;
124 svm_region_t **mapped_shmem_regions;
125 struct vl_shmem_hdr_ *shmem_hdr;
126 vl_api_registration_t **vl_clients;
127
128 /* For plugin msg allocator */
129 u16 first_available_msg_id;
130
131 /* message range by name hash */
132 uword * msg_range_by_name;
133
134 /* vector of message ranges */
135 vl_api_msg_range_t *msg_ranges;
136
Dave Barach16c75df2016-05-31 14:05:46 -0400137 /* gid for the api shared memory region */
138 int api_gid;
139 int api_uid;
140
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 /* Client-only data structures */
142 unix_shared_memory_queue_t *vl_input_queue;
143
144 /*
145 * All VLIB-side message handlers use my_client_index to identify
146 * the queue / client. This works in sim replay.
147 */
148 int my_client_index;
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 */
154 vl_api_registration_t *my_registration;
155
156 i32 vlib_signal;
157
158 char *region_name;
159 char *root_path;
160} api_main_t;
161
162api_main_t api_main;
163
164typedef 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;
174 int message_bounce;
175 int is_mp_safe;
176} vl_msg_api_msg_config_t;
177
178/* api_shared.c prototypes */
179int vl_msg_api_rx_trace_enabled(api_main_t *am);
180int vl_msg_api_tx_trace_enabled(api_main_t *am);
181void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg);
182int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which,
183 int onoff);
184int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which);
185int vl_msg_api_trace_save(api_main_t *am,
186 vl_api_trace_which_t which, FILE *fp);
187int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which,
188 u32 nitems);
189void vl_msg_api_handler_with_vm_node (api_main_t *am,
190 void *the_msg, vlib_main_t *vm,
191 vlib_node_runtime_t *node);
192void vl_msg_api_handler (void *the_msg);
193void vl_msg_api_handler_no_free (void *the_msg);
194void vl_msg_api_handler_no_trace_no_free (void *the_msg);
195void vl_msg_api_trace_only (void *the_msg);
196void vl_msg_api_cleanup_handler (void *the_msg);
197void vl_msg_api_replay_handler(void *the_msg);
198void vl_msg_api_socket_handler(void *the_msg);
199void 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);
205void vl_msg_api_config (vl_msg_api_msg_config_t *);
206void vl_msg_api_set_cleanup_handler(int msg_id, void *fp);
207void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q);
208vl_api_trace_t *vl_msg_api_trace_get(api_main_t *am,
209 vl_api_trace_which_t which);
210
211void vl_msg_api_free (void *);
212void vl_noop_handler (void *mp);
213clib_error_t *vl_api_init (vlib_main_t *vm);
214void vl_msg_api_increment_missing_client_counter(void);
215void vl_msg_api_post_mortem_dump (void);
216void vl_msg_api_register_pd_handler (void *handler, u16 msg_id_host_byte_order);
217int vl_msg_api_pd_handler (void *mp, int rv);
218
219void vl_msg_api_set_first_available_msg_id (u16 first_avail);
220u16 vl_msg_api_get_msg_ids (char * name, int n);
221
Dave Barachb44e9bc2016-02-19 09:06:23 -0500222/* node_serialize.c prototypes */
Dave Barach6931f592016-05-13 12:55:01 -0400223u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
224 u32 max_threads, int include_nexts,
225 int include_stats);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500226vlib_node_t ** vlib_node_unserialize (u8 * vector);
227
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228#define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
229
230#endif /* included_api_h */