Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_vat_h__ |
| 16 | #define __included_vat_h__ |
| 17 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 18 | #define _GNU_SOURCE |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <setjmp.h> |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/un.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 24 | #include <vppinfra/clib.h> |
| 25 | #include <vppinfra/format.h> |
| 26 | #include <vppinfra/error.h> |
| 27 | #include <vppinfra/time.h> |
| 28 | #include <vppinfra/macros.h> |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 29 | #include <vppinfra/socket.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 30 | #include <vnet/vnet.h> |
| 31 | #include <vlib/vlib.h> |
| 32 | #include <vlib/unix/unix.h> |
| 33 | #include <vlibapi/api.h> |
| 34 | #include <vlibmemory/api.h> |
| 35 | |
| 36 | #include "vat/json_format.h" |
| 37 | |
| 38 | #include <vlib/vlib.h> |
| 39 | |
| 40 | typedef struct |
| 41 | { |
| 42 | u8 *interface_name; |
| 43 | u32 sw_if_index; |
| 44 | /* |
| 45 | * Subinterface ID. A number 0-N to uniquely identify this |
| 46 | * subinterface under the super interface |
| 47 | */ |
| 48 | u32 sub_id; |
| 49 | |
| 50 | /* 0 = dot1q, 1=dot1ad */ |
| 51 | u8 sub_dot1ad; |
| 52 | |
| 53 | /* Number of tags 0-2 */ |
| 54 | u8 sub_number_of_tags; |
| 55 | u16 sub_outer_vlan_id; |
| 56 | u16 sub_inner_vlan_id; |
| 57 | u8 sub_exact_match; |
| 58 | u8 sub_default; |
| 59 | u8 sub_outer_vlan_id_any; |
| 60 | u8 sub_inner_vlan_id_any; |
| 61 | |
| 62 | /* vlan tag rewrite */ |
| 63 | u32 vtr_op; |
| 64 | u32 vtr_push_dot1q; |
| 65 | u32 vtr_tag1; |
| 66 | u32 vtr_tag2; |
| 67 | } sw_interface_subif_t; |
| 68 | |
| 69 | typedef struct |
| 70 | { |
| 71 | u8 ip[16]; |
| 72 | u8 prefix_length; |
| 73 | } ip_address_details_t; |
| 74 | |
| 75 | typedef struct |
| 76 | { |
| 77 | u8 present; |
| 78 | ip_address_details_t *addr; |
| 79 | } ip_details_t; |
| 80 | |
| 81 | typedef struct |
| 82 | { |
| 83 | u64 packets; |
| 84 | u64 bytes; |
| 85 | } interface_counter_t; |
| 86 | |
| 87 | typedef struct |
| 88 | { |
| 89 | struct in_addr address; |
| 90 | u8 address_length; |
| 91 | u64 packets; |
| 92 | u64 bytes; |
| 93 | } ip4_fib_counter_t; |
| 94 | |
| 95 | typedef struct |
| 96 | { |
| 97 | struct in6_addr address; |
| 98 | u8 address_length; |
| 99 | u64 packets; |
| 100 | u64 bytes; |
| 101 | } ip6_fib_counter_t; |
| 102 | |
| 103 | typedef struct |
| 104 | { |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 105 | struct in_addr address; |
| 106 | vnet_link_t linkt; |
| 107 | u64 packets; |
| 108 | u64 bytes; |
| 109 | } ip4_nbr_counter_t; |
| 110 | |
| 111 | typedef struct |
| 112 | { |
| 113 | struct in6_addr address; |
| 114 | vnet_link_t linkt; |
| 115 | u64 packets; |
| 116 | u64 bytes; |
| 117 | } ip6_nbr_counter_t; |
| 118 | |
| 119 | typedef struct |
| 120 | { |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 121 | /* vpe input queue */ |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 122 | svm_queue_t *vl_input_queue; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 123 | |
| 124 | /* interface name table */ |
| 125 | uword *sw_if_index_by_interface_name; |
| 126 | |
| 127 | /* subinterface table */ |
| 128 | sw_interface_subif_t *sw_if_subif_table; |
| 129 | |
| 130 | /* Graph node table */ |
| 131 | uword *graph_node_index_by_name; |
| 132 | vlib_node_t **graph_nodes; |
| 133 | |
| 134 | /* ip tables */ |
| 135 | ip_details_t *ip_details_by_sw_if_index[2]; |
| 136 | |
| 137 | /* sw_if_index of currently processed interface */ |
| 138 | u32 current_sw_if_index; |
| 139 | |
| 140 | /* remember that we are dumping ipv6 */ |
| 141 | u8 is_ipv6; |
| 142 | |
| 143 | /* function table */ |
| 144 | uword *function_by_name; |
| 145 | |
| 146 | /* help strings */ |
| 147 | uword *help_by_name; |
| 148 | |
| 149 | /* macro table */ |
| 150 | macro_main_t macro_main; |
| 151 | |
| 152 | /* Errors by number */ |
| 153 | uword *error_string_by_error_number; |
| 154 | |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 155 | /* Main thread can spin (w/ timeout) here if needed */ |
| 156 | u32 async_mode; |
| 157 | u32 async_errors; |
| 158 | volatile u32 result_ready; |
| 159 | volatile i32 retval; |
| 160 | volatile u32 sw_if_index; |
| 161 | volatile u8 *shmem_result; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 162 | u8 *cmd_reply; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 163 | |
| 164 | /* our client index */ |
| 165 | u32 my_client_index; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 166 | int client_index_invalid; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 167 | |
| 168 | /* Time is of the essence... */ |
| 169 | clib_time_t clib_time; |
| 170 | |
| 171 | /* Unwind (so we can quit) */ |
| 172 | jmp_buf jump_buf; |
| 173 | int jump_buf_set; |
| 174 | volatile int do_exit; |
| 175 | |
| 176 | /* temporary parse buffer */ |
| 177 | unformat_input_t *input; |
| 178 | |
| 179 | /* input buffer */ |
| 180 | u8 *inbuf; |
| 181 | |
| 182 | /* stdio input / output FILEs */ |
| 183 | FILE *ifp, *ofp; |
| 184 | u8 *current_file; |
| 185 | u32 input_line_number; |
| 186 | |
| 187 | /* exec mode toggle */ |
| 188 | int exec_mode; |
| 189 | |
| 190 | /* Regenerate the interface table */ |
| 191 | volatile int regenerate_interface_table; |
| 192 | |
| 193 | /* flag for JSON output format */ |
| 194 | u8 json_output; |
| 195 | |
| 196 | /* flag for interface event display */ |
| 197 | u8 interface_event_display; |
| 198 | |
| 199 | /* JSON tree used in composing dump api call results */ |
| 200 | vat_json_node_t json_tree; |
| 201 | |
| 202 | /* counters */ |
| 203 | u64 **simple_interface_counters; |
| 204 | interface_counter_t **combined_interface_counters; |
| 205 | ip4_fib_counter_t **ip4_fib_counters; |
| 206 | u32 *ip4_fib_counters_vrf_id_by_index; |
| 207 | ip6_fib_counter_t **ip6_fib_counters; |
| 208 | u32 *ip6_fib_counters_vrf_id_by_index; |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 209 | ip4_nbr_counter_t **ip4_nbr_counters; |
| 210 | ip6_nbr_counter_t **ip6_nbr_counters; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 211 | |
Florin Coras | 90a6398 | 2017-12-19 04:50:01 -0800 | [diff] [blame] | 212 | socket_client_main_t *socket_client_main; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 213 | u8 *socket_name; |
| 214 | |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 215 | /* Convenience */ |
| 216 | vlib_main_t *vlib_main; |
| 217 | } vat_main_t; |
| 218 | |
Dave Barach | fe6bdfd | 2017-01-20 19:50:09 -0500 | [diff] [blame] | 219 | extern vat_main_t vat_main; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 220 | |
Dave Barach | fe6bdfd | 2017-01-20 19:50:09 -0500 | [diff] [blame] | 221 | void vat_suspend (vlib_main_t * vm, f64 interval); |
| 222 | f64 vat_time_now (vat_main_t * vam); |
| 223 | void errmsg (char *fmt, ...); |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 224 | void vat_api_hookup (vat_main_t * vam); |
| 225 | int api_sw_interface_dump (vat_main_t * vam); |
| 226 | void do_one_file (vat_main_t * vam); |
| 227 | int exec (vat_main_t * vam); |
| 228 | |
| 229 | /* Plugin API library functions */ |
| 230 | char *vat_plugin_path; |
| 231 | char *vat_plugin_name_filter; |
| 232 | void vat_plugin_api_reference (void); |
| 233 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 234 | uword unformat_ip4_address (unformat_input_t * input, va_list * args); |
| 235 | uword unformat_ethernet_address (unformat_input_t * input, va_list * args); |
| 236 | uword unformat_ethernet_type_host_byte_order (unformat_input_t * input, |
| 237 | va_list * args); |
| 238 | uword unformat_ip6_address (unformat_input_t * input, va_list * args); |
| 239 | u8 *format_ip4_address (u8 * s, va_list * args); |
Jon Loeliger | 229a6b7 | 2017-05-08 16:53:44 -0500 | [diff] [blame] | 240 | u8 *format_ip6_address (u8 * s, va_list * args); |
| 241 | u8 *format_ip46_address (u8 * s, va_list * args); |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 242 | u8 *format_ethernet_address (u8 * s, va_list * args); |
| 243 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 244 | int vat_socket_connect (vat_main_t * vam); |
| 245 | |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 246 | #if VPP_API_TEST_BUILTIN |
| 247 | #define print api_cli_output |
| 248 | void api_cli_output (void *, const char *fmt, ...); |
| 249 | #else |
| 250 | #define print fformat_append_cr |
| 251 | void fformat_append_cr (FILE *, const char *fmt, ...); |
| 252 | #endif |
| 253 | |
| 254 | #endif /* __included_vat_h__ */ |
| 255 | |
| 256 | /* |
| 257 | * fd.io coding-style-patch-verification: ON |
| 258 | * |
| 259 | * Local Variables: |
| 260 | * eval: (c-set-style "gnu") |
| 261 | * End: |
| 262 | */ |