blob: 0bae23c017d60652d03e3c9025207cc35477d11f [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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
Dave Barach72d72232016-08-04 10:15:08 -040033typedef struct
34{
35 u8 *interface_name;
36 u32 sw_if_index;
37 /*
38 * Subinterface ID. A number 0-N to uniquely identify this
39 * subinterface under the super interface
40 */
41 u32 sub_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
Dave Barach72d72232016-08-04 10:15:08 -040043 /* 0 = dot1q, 1=dot1ad */
44 u8 sub_dot1ad;
Ed Warnickecb9cada2015-12-08 15:45:58 -070045
Dave Barach72d72232016-08-04 10:15:08 -040046 /* Number of tags 0-2 */
47 u8 sub_number_of_tags;
48 u16 sub_outer_vlan_id;
49 u16 sub_inner_vlan_id;
50 u8 sub_exact_match;
51 u8 sub_default;
52 u8 sub_outer_vlan_id_any;
53 u8 sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -070054
Dave Barach72d72232016-08-04 10:15:08 -040055 /* vlan tag rewrite */
56 u32 vtr_op;
57 u32 vtr_push_dot1q;
58 u32 vtr_tag1;
59 u32 vtr_tag2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070060} sw_interface_subif_t;
61
Dave Barach72d72232016-08-04 10:15:08 -040062typedef struct
63{
64 u8 ip[16];
65 u8 prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -070066} ip_address_details_t;
67
Dave Barach72d72232016-08-04 10:15:08 -040068typedef struct
69{
70 u8 present;
71 ip_address_details_t *addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072} ip_details_t;
73
Dave Barach72d72232016-08-04 10:15:08 -040074typedef struct
75{
76 u64 packets;
77 u64 bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -070078} interface_counter_t;
79
Dave Barach72d72232016-08-04 10:15:08 -040080typedef struct
81{
82 struct in_addr address;
83 u8 address_length;
84 u64 packets;
85 u64 bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -070086} ip4_fib_counter_t;
87
Dave Barach72d72232016-08-04 10:15:08 -040088typedef struct
89{
90 struct in6_addr address;
91 u8 address_length;
92 u64 packets;
93 u64 bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -070094} ip6_fib_counter_t;
95
Dave Barach72d72232016-08-04 10:15:08 -040096typedef struct
97{
Dave Barach72d72232016-08-04 10:15:08 -040098 /* vpe input queue */
99 unix_shared_memory_queue_t *vl_input_queue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100
Dave Barach72d72232016-08-04 10:15:08 -0400101 /* interface name table */
102 uword *sw_if_index_by_interface_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103
Dave Barach72d72232016-08-04 10:15:08 -0400104 /* subinterface table */
105 sw_interface_subif_t *sw_if_subif_table;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106
Dave Barach72d72232016-08-04 10:15:08 -0400107 /* Graph node table */
108 uword *graph_node_index_by_name;
109 vlib_node_t **graph_nodes;
Dave Barachb44e9bc2016-02-19 09:06:23 -0500110
Dave Barach72d72232016-08-04 10:15:08 -0400111 /* ip tables */
112 ip_details_t *ip_details_by_sw_if_index[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113
Dave Barach72d72232016-08-04 10:15:08 -0400114 /* sw_if_index of currently processed interface */
115 u32 current_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116
Dave Barach72d72232016-08-04 10:15:08 -0400117 /* remember that we are dumping ipv6 */
118 u8 is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119
Dave Barach72d72232016-08-04 10:15:08 -0400120 /* function table */
121 uword *function_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122
Dave Barach72d72232016-08-04 10:15:08 -0400123 /* help strings */
124 uword *help_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Dave Barach72d72232016-08-04 10:15:08 -0400126 /* macro table */
127 macro_main_t macro_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Dave Barach72d72232016-08-04 10:15:08 -0400129 /* Errors by number */
130 uword *error_string_by_error_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Dave Barachb44e9bc2016-02-19 09:06:23 -0500132
Dave Barach72d72232016-08-04 10:15:08 -0400133 /* Main thread can spin (w/ timeout) here if needed */
134 u32 async_mode;
135 u32 async_errors;
136 volatile u32 result_ready;
137 volatile i32 retval;
138 volatile u32 sw_if_index;
139 volatile u8 *shmem_result;
Ole Troanc27213a2016-08-31 14:50:49 +0200140 volatile u8 *cmd_reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141
Dave Barach72d72232016-08-04 10:15:08 -0400142 /* our client index */
143 u32 my_client_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144
Dave Barach72d72232016-08-04 10:15:08 -0400145 /* Time is of the essence... */
146 clib_time_t clib_time;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147
Dave Barach72d72232016-08-04 10:15:08 -0400148 /* Unwind (so we can quit) */
149 jmp_buf jump_buf;
Dave Barach477570e2016-10-09 17:43:22 -0400150 int jump_buf_set;
151 volatile int do_exit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
Dave Barach72d72232016-08-04 10:15:08 -0400153 /* temporary parse buffer */
154 unformat_input_t *input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700155
Dave Barach72d72232016-08-04 10:15:08 -0400156 /* input buffer */
157 u8 *inbuf;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158
Dave Barach72d72232016-08-04 10:15:08 -0400159 /* stdio input / output FILEs */
160 FILE *ifp, *ofp;
161 u8 *current_file;
162 u32 input_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163
Dave Barach72d72232016-08-04 10:15:08 -0400164 /* exec mode toggle */
165 int exec_mode;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166
Dave Barach72d72232016-08-04 10:15:08 -0400167 /* Regenerate the interface table */
168 volatile int regenerate_interface_table;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169
Dave Barach72d72232016-08-04 10:15:08 -0400170 /* flag for JSON output format */
171 u8 json_output;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700172
Dave Barach72d72232016-08-04 10:15:08 -0400173 /* flag for interface event display */
174 u8 interface_event_display;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175
Dave Barach72d72232016-08-04 10:15:08 -0400176 /* JSON tree used in composing dump api call results */
177 vat_json_node_t json_tree;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
Dave Barach72d72232016-08-04 10:15:08 -0400179 /* counters */
180 u64 **simple_interface_counters;
181 interface_counter_t **combined_interface_counters;
182 ip4_fib_counter_t **ip4_fib_counters;
183 u32 *ip4_fib_counters_vrf_id_by_index;
184 ip6_fib_counter_t **ip6_fib_counters;
185 u32 *ip6_fib_counters_vrf_id_by_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186} vat_main_t;
187
188vat_main_t vat_main;
189
Dave Barach72d72232016-08-04 10:15:08 -0400190static inline f64
191vat_time_now (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700192{
Dave Barach72d72232016-08-04 10:15:08 -0400193 return clib_time_now (&vam->clib_time);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194}
195
196#define errmsg(fmt,args...) \
197do { \
198 if(vam->ifp != stdin) \
199 fformat(vam->ofp,"%s(%d): ", vam->current_file, \
200 vam->input_line_number); \
201 fformat(vam->ofp, fmt, ##args); \
202 fflush(vam->ofp); \
203} while(0);
204
Dave Barach72d72232016-08-04 10:15:08 -0400205void vat_api_hookup (vat_main_t * vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206int api_sw_interface_dump (vat_main_t * vam);
207void do_one_file (vat_main_t * vam);
208int exec (vat_main_t * vam);
209
210/* Plugin API library functions */
211char *vat_plugin_path;
212char *vat_plugin_name_filter;
Dave Barach72d72232016-08-04 10:15:08 -0400213void vat_plugin_api_reference (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
215uword unformat_ip4_address (unformat_input_t * input, va_list * args);
216uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
217uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
Dave Barach72d72232016-08-04 10:15:08 -0400218 va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219uword unformat_ip6_address (unformat_input_t * input, va_list * args);
Dave Barach72d72232016-08-04 10:15:08 -0400220u8 *format_ip4_address (u8 * s, va_list * args);
221u8 *format_ethernet_address (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222
223
224#endif /* __included_vat_h__ */
Dave Barach72d72232016-08-04 10:15:08 -0400225
226/*
227 * fd.io coding-style-patch-verification: ON
228 *
229 * Local Variables:
230 * eval: (c-set-style "gnu")
231 * End:
232 */