Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * api.h |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 4 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 29 | typedef enum |
| 30 | { |
| 31 | REGISTRATION_TYPE_FREE = 0, |
| 32 | REGISTRATION_TYPE_SHMEM, |
| 33 | REGISTRATION_TYPE_SOCKET_LISTEN, |
| 34 | REGISTRATION_TYPE_SOCKET_SERVER, |
| 35 | REGISTRATION_TYPE_SOCKET_CLIENT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | } vl_registration_type_t; |
| 37 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 38 | typedef struct vl_api_registration_ |
| 39 | { |
| 40 | vl_registration_type_t registration_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 42 | /* Index in VLIB's brain (not shared memory). */ |
| 43 | u32 vl_api_registration_pool_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 45 | u8 *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 47 | /* |
| 48 | * The following groups of data could be unioned, but my fingers are |
| 49 | * going to be sore enough. |
| 50 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 52 | /* shared memory only */ |
| 53 | unix_shared_memory_queue_t *vl_input_queue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 55 | /* socket server and client */ |
| 56 | u32 unix_file_index; |
| 57 | i8 *unprocessed_input; |
| 58 | u32 unprocessed_msg_length; |
| 59 | u8 *output_vector; |
| 60 | |
| 61 | /* socket client only */ |
| 62 | u32 server_handle; |
| 63 | u32 server_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | |
| 65 | } vl_api_registration_t; |
| 66 | |
| 67 | |
| 68 | /* Trace configuration for a single message */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 69 | typedef struct |
| 70 | { |
| 71 | int size; |
| 72 | int trace_enable; |
| 73 | int replay_enable; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 74 | } trace_cfg_t; |
| 75 | |
| 76 | /* |
| 77 | * API recording |
| 78 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 79 | typedef struct |
| 80 | { |
| 81 | u8 endian; |
| 82 | u8 enabled; |
| 83 | u8 wrapped; |
| 84 | u8 pad; |
| 85 | u32 nitems; |
| 86 | u32 curindex; |
| 87 | u8 **traces; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | } vl_api_trace_t; |
| 89 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 90 | typedef CLIB_PACKED (struct |
| 91 | { |
| 92 | u8 endian; u8 wrapped; |
| 93 | u32 nitems; |
| 94 | }) vl_api_trace_file_header_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 96 | typedef enum |
| 97 | { |
| 98 | VL_API_TRACE_TX, |
| 99 | VL_API_TRACE_RX, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | } vl_api_trace_which_t; |
| 101 | |
| 102 | #define VL_API_LITTLE_ENDIAN 0x00 |
| 103 | #define VL_API_BIG_ENDIAN 0x01 |
| 104 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 105 | typedef struct |
| 106 | { |
| 107 | u8 *name; |
| 108 | u16 first_msg_id; |
| 109 | u16 last_msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | } vl_api_msg_range_t; |
| 111 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 112 | typedef struct |
| 113 | { |
| 114 | void (**msg_handlers) (void *); |
| 115 | int (**pd_msg_handlers) (void *, int); |
| 116 | void (**msg_cleanup_handlers) (void *); |
| 117 | void (**msg_endian_handlers) (void *); |
| 118 | void (**msg_print_handlers) (void *, void *); |
| 119 | char **msg_names; |
| 120 | u8 *message_bounce; |
| 121 | u8 *is_mp_safe; |
| 122 | struct ring_alloc_ *arings; |
| 123 | u32 ring_misses; |
| 124 | u32 missing_clients; |
| 125 | vl_api_trace_t *rx_trace; |
| 126 | vl_api_trace_t *tx_trace; |
| 127 | int msg_print_flag; |
| 128 | trace_cfg_t *api_trace_cfg; |
| 129 | int our_pid; |
| 130 | svm_region_t *vlib_rp; |
| 131 | svm_region_t **mapped_shmem_regions; |
| 132 | struct vl_shmem_hdr_ *shmem_hdr; |
| 133 | vl_api_registration_t **vl_clients; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 135 | /* For plugin msg allocator */ |
| 136 | u16 first_available_msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 138 | /* message range by name hash */ |
| 139 | uword *msg_range_by_name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 141 | /* vector of message ranges */ |
| 142 | vl_api_msg_range_t *msg_ranges; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 144 | /* uid for the api shared memory region */ |
| 145 | int api_uid; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 146 | /* gid for the api shared memory region */ |
| 147 | int api_gid; |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 148 | |
| 149 | /* base virtual address for global VM region */ |
| 150 | u64 global_baseva; |
| 151 | |
| 152 | /* size of the global VM region */ |
| 153 | u64 global_size; |
| 154 | |
| 155 | /* size of the API region */ |
| 156 | u64 api_size; |
| 157 | |
| 158 | /* size of the global VM private mheap */ |
| 159 | u64 global_pvt_heap_size; |
| 160 | |
| 161 | /* size of the api private mheap */ |
| 162 | u64 api_pvt_heap_size; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 163 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 164 | /* Client-only data structures */ |
| 165 | unix_shared_memory_queue_t *vl_input_queue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 167 | /* |
| 168 | * All VLIB-side message handlers use my_client_index to identify |
| 169 | * the queue / client. This works in sim replay. |
| 170 | */ |
| 171 | int my_client_index; |
| 172 | /* |
| 173 | * This is the (shared VM) address of the registration, |
| 174 | * don't use it to id the connection since it can't possibly |
| 175 | * work in simulator replay. |
| 176 | */ |
| 177 | vl_api_registration_t *my_registration; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 179 | i32 vlib_signal; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 181 | char *region_name; |
| 182 | char *root_path; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | } api_main_t; |
| 184 | |
| 185 | api_main_t api_main; |
| 186 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 187 | typedef struct |
| 188 | { |
| 189 | int id; |
| 190 | char *name; |
| 191 | void *handler; |
| 192 | void *cleanup; |
| 193 | void *endian; |
| 194 | void *print; |
| 195 | int size; |
| 196 | int traced; |
| 197 | int replay; |
| 198 | int message_bounce; |
| 199 | int is_mp_safe; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | } vl_msg_api_msg_config_t; |
| 201 | |
| 202 | /* api_shared.c prototypes */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 203 | int vl_msg_api_rx_trace_enabled (api_main_t * am); |
| 204 | int vl_msg_api_tx_trace_enabled (api_main_t * am); |
| 205 | void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg); |
| 206 | int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, |
| 207 | int onoff); |
| 208 | int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which); |
| 209 | int vl_msg_api_trace_save (api_main_t * am, |
| 210 | vl_api_trace_which_t which, FILE * fp); |
| 211 | int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, |
| 212 | u32 nitems); |
| 213 | void vl_msg_api_handler_with_vm_node (api_main_t * am, |
| 214 | void *the_msg, vlib_main_t * vm, |
| 215 | vlib_node_runtime_t * node); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | void vl_msg_api_handler (void *the_msg); |
| 217 | void vl_msg_api_handler_no_free (void *the_msg); |
| 218 | void vl_msg_api_handler_no_trace_no_free (void *the_msg); |
| 219 | void vl_msg_api_trace_only (void *the_msg); |
| 220 | void vl_msg_api_cleanup_handler (void *the_msg); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 221 | void vl_msg_api_replay_handler (void *the_msg); |
| 222 | void vl_msg_api_socket_handler (void *the_msg); |
| 223 | void vl_msg_api_set_handlers (int msg_id, char *msg_name, |
| 224 | void *handler, |
| 225 | void *cleanup, |
| 226 | void *endian, |
| 227 | void *print, int msg_size, int traced); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | void vl_msg_api_config (vl_msg_api_msg_config_t *); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 229 | void vl_msg_api_set_cleanup_handler (int msg_id, void *fp); |
| 230 | void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q); |
| 231 | vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am, |
| 232 | vl_api_trace_which_t which); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
| 234 | void vl_msg_api_free (void *); |
| 235 | void vl_noop_handler (void *mp); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 236 | clib_error_t *vl_api_init (vlib_main_t * vm); |
| 237 | void vl_msg_api_increment_missing_client_counter (void); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 238 | void vl_msg_api_post_mortem_dump (void); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 239 | void vl_msg_api_register_pd_handler (void *handler, |
| 240 | u16 msg_id_host_byte_order); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | int vl_msg_api_pd_handler (void *mp, int rv); |
| 242 | |
| 243 | void vl_msg_api_set_first_available_msg_id (u16 first_avail); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 244 | u16 vl_msg_api_get_msg_ids (char *name, int n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 246 | /* node_serialize.c prototypes */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 247 | u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector, |
| 248 | u32 max_threads, int include_nexts, |
| 249 | int include_stats); |
| 250 | vlib_node_t **vlib_node_unserialize (u8 * vector); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 251 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init) |
| 253 | |
| 254 | #endif /* included_api_h */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * fd.io coding-style-patch-verification: ON |
| 258 | * |
| 259 | * Local Variables: |
| 260 | * eval: (c-set-style "gnu") |
| 261 | * End: |
| 262 | */ |