Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame^] | 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> |
| 26 | #include <vlibmemory/unix_shared_memory_queue.h> |
| 27 | #include <vlib/unix/unix.h> |
| 28 | |
| 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, |
| 36 | } vl_registration_type_t; |
| 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). */ |
| 43 | u32 vl_api_registration_pool_index; |
| 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 */ |
| 53 | unix_shared_memory_queue_t *vl_input_queue; |
| 54 | |
| 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; |
| 64 | |
| 65 | } vl_api_registration_t; |
| 66 | |
| 67 | |
| 68 | /* Trace configuration for a single message */ |
| 69 | typedef struct |
| 70 | { |
| 71 | int size; |
| 72 | int trace_enable; |
| 73 | int replay_enable; |
| 74 | } trace_cfg_t; |
| 75 | |
| 76 | /* |
| 77 | * API recording |
| 78 | */ |
| 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; |
| 88 | } vl_api_trace_t; |
| 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 | { |
| 101 | VL_API_TRACE_TX, |
| 102 | VL_API_TRACE_RX, |
| 103 | } vl_api_trace_which_t; |
| 104 | |
| 105 | #define VL_API_LITTLE_ENDIAN 0x00 |
| 106 | #define VL_API_BIG_ENDIAN 0x01 |
| 107 | |
| 108 | typedef struct |
| 109 | { |
| 110 | u8 *name; |
| 111 | u16 first_msg_id; |
| 112 | u16 last_msg_id; |
| 113 | } vl_api_msg_range_t; |
| 114 | |
| 115 | typedef struct |
| 116 | { |
| 117 | void (**msg_handlers) (void *); |
| 118 | int (**pd_msg_handlers) (void *, int); |
| 119 | void (**msg_cleanup_handlers) (void *); |
| 120 | void (**msg_endian_handlers) (void *); |
| 121 | void (**msg_print_handlers) (void *, void *); |
| 122 | char **msg_names; |
| 123 | u8 *message_bounce; |
| 124 | u8 *is_mp_safe; |
| 125 | struct ring_alloc_ *arings; |
| 126 | u32 ring_misses; |
| 127 | u32 missing_clients; |
| 128 | vl_api_trace_t *rx_trace; |
| 129 | vl_api_trace_t *tx_trace; |
| 130 | int msg_print_flag; |
| 131 | trace_cfg_t *api_trace_cfg; |
| 132 | int our_pid; |
| 133 | svm_region_t *vlib_rp; |
| 134 | svm_region_t **mapped_shmem_regions; |
| 135 | struct vl_shmem_hdr_ *shmem_hdr; |
| 136 | vl_api_registration_t **vl_clients; |
| 137 | |
| 138 | u8 *serialized_message_table_in_shmem; |
| 139 | |
| 140 | /* For plugin msg allocator */ |
| 141 | u16 first_available_msg_id; |
| 142 | |
| 143 | /* message range by name hash */ |
| 144 | uword *msg_range_by_name; |
| 145 | |
| 146 | /* vector of message ranges */ |
| 147 | vl_api_msg_range_t *msg_ranges; |
| 148 | |
| 149 | /* uid for the api shared memory region */ |
| 150 | int api_uid; |
| 151 | /* gid for the api shared memory region */ |
| 152 | int api_gid; |
| 153 | |
| 154 | /* base virtual address for global VM region */ |
| 155 | u64 global_baseva; |
| 156 | |
| 157 | /* size of the global VM region */ |
| 158 | u64 global_size; |
| 159 | |
| 160 | /* size of the API region */ |
| 161 | u64 api_size; |
| 162 | |
| 163 | /* size of the global VM private mheap */ |
| 164 | u64 global_pvt_heap_size; |
| 165 | |
| 166 | /* size of the api private mheap */ |
| 167 | u64 api_pvt_heap_size; |
| 168 | |
| 169 | /* Client-only data structures */ |
| 170 | unix_shared_memory_queue_t *vl_input_queue; |
| 171 | |
| 172 | /* |
| 173 | * All VLIB-side message handlers use my_client_index to identify |
| 174 | * the queue / client. This works in sim replay. |
| 175 | */ |
| 176 | int my_client_index; |
| 177 | /* |
| 178 | * This is the (shared VM) address of the registration, |
| 179 | * don't use it to id the connection since it can't possibly |
| 180 | * work in simulator replay. |
| 181 | */ |
| 182 | vl_api_registration_t *my_registration; |
| 183 | |
| 184 | i32 vlib_signal; |
| 185 | |
| 186 | /* client side message index hash table */ |
| 187 | uword *msg_index_by_name_and_crc; |
| 188 | |
| 189 | char *region_name; |
| 190 | char *root_path; |
| 191 | } api_main_t; |
| 192 | |
| 193 | extern api_main_t api_main; |
| 194 | |
| 195 | typedef struct |
| 196 | { |
| 197 | int id; |
| 198 | char *name; |
| 199 | u32 crc; |
| 200 | void *handler; |
| 201 | void *cleanup; |
| 202 | void *endian; |
| 203 | void *print; |
| 204 | int size; |
| 205 | int traced; |
| 206 | int replay; |
| 207 | int message_bounce; |
| 208 | int is_mp_safe; |
| 209 | } vl_msg_api_msg_config_t; |
| 210 | |
| 211 | typedef struct msgbuf_ |
| 212 | { |
| 213 | unix_shared_memory_queue_t *q; |
| 214 | u32 data_len; |
| 215 | u32 pad; |
| 216 | u8 data[0]; |
| 217 | } msgbuf_t; |
| 218 | |
| 219 | /* api_shared.c prototypes */ |
| 220 | int vl_msg_api_rx_trace_enabled (api_main_t * am); |
| 221 | int vl_msg_api_tx_trace_enabled (api_main_t * am); |
| 222 | void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg); |
| 223 | int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, |
| 224 | int onoff); |
| 225 | int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which); |
| 226 | int vl_msg_api_trace_save (api_main_t * am, |
| 227 | vl_api_trace_which_t which, FILE * fp); |
| 228 | int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, |
| 229 | u32 nitems); |
| 230 | void vl_msg_api_handler_with_vm_node (api_main_t * am, |
| 231 | void *the_msg, vlib_main_t * vm, |
| 232 | vlib_node_runtime_t * node); |
| 233 | void vl_msg_api_handler (void *the_msg); |
| 234 | void vl_msg_api_handler_no_free (void *the_msg); |
| 235 | void vl_msg_api_handler_no_trace_no_free (void *the_msg); |
| 236 | void vl_msg_api_trace_only (void *the_msg); |
| 237 | void vl_msg_api_cleanup_handler (void *the_msg); |
| 238 | void vl_msg_api_replay_handler (void *the_msg); |
| 239 | void vl_msg_api_socket_handler (void *the_msg); |
| 240 | void vl_msg_api_set_handlers (int msg_id, char *msg_name, |
| 241 | void *handler, |
| 242 | void *cleanup, |
| 243 | void *endian, |
| 244 | void *print, int msg_size, int traced); |
| 245 | void vl_msg_api_config (vl_msg_api_msg_config_t *); |
| 246 | void vl_msg_api_set_cleanup_handler (int msg_id, void *fp); |
| 247 | void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q); |
| 248 | vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am, |
| 249 | vl_api_trace_which_t which); |
| 250 | |
| 251 | void vl_msg_api_free (void *); |
| 252 | void vl_noop_handler (void *mp); |
| 253 | clib_error_t *vl_api_init (vlib_main_t * vm); |
| 254 | void vl_msg_api_increment_missing_client_counter (void); |
| 255 | void vl_msg_api_post_mortem_dump (void); |
| 256 | void vl_msg_api_register_pd_handler (void *handler, |
| 257 | u16 msg_id_host_byte_order); |
| 258 | int vl_msg_api_pd_handler (void *mp, int rv); |
| 259 | |
| 260 | void vl_msg_api_set_first_available_msg_id (u16 first_avail); |
| 261 | u16 vl_msg_api_get_msg_ids (char *name, int n); |
| 262 | void vl_msg_api_add_msg_name_crc (api_main_t * am, char *string, u32 id); |
| 263 | u32 vl_api_get_msg_index (u8 * name_and_crc); |
| 264 | |
| 265 | /* node_serialize.c prototypes */ |
| 266 | u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector, |
| 267 | u32 max_threads, int include_nexts, |
| 268 | int include_stats); |
| 269 | vlib_node_t **vlib_node_unserialize (u8 * vector); |
| 270 | |
| 271 | #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init) |
| 272 | |
| 273 | #endif /* included_api_h */ |
| 274 | |
| 275 | /* |
| 276 | * fd.io coding-style-patch-verification: ON |
| 277 | * |
| 278 | * Local Variables: |
| 279 | * eval: (c-set-style "gnu") |
| 280 | * End: |
| 281 | */ |