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