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