blob: b32d9ffc754304f468db2f9818b27f680d37ba33 [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
33typedef struct {
34 u8 * interface_name;
35 u32 sw_if_index;
36 /* Subinterface ID. A number 0-N to uniquely identify this subinterface under the super interface*/
37 u32 sub_id;
38
39 /* 0 = dot1q, 1=dot1ad */
40 u8 sub_dot1ad;
41
42 /* Number of tags 0-2 */
43 u8 sub_number_of_tags;
44 u16 sub_outer_vlan_id;
45 u16 sub_inner_vlan_id;
46 u8 sub_exact_match;
47 u8 sub_default;
48 u8 sub_outer_vlan_id_any;
49 u8 sub_inner_vlan_id_any;
50
51 /* vlan tag rewrite */
52 u32 vtr_op;
53 u32 vtr_push_dot1q;
54 u32 vtr_tag1;
55 u32 vtr_tag2;
56} sw_interface_subif_t;
57
58typedef struct {
59 u8 ip[16];
60 u8 prefix_length;
61} ip_address_details_t;
62
63typedef struct {
64 u8 present;
65 ip_address_details_t * addr;
66} ip_details_t;
67
68typedef struct {
69 u64 packets;
70 u64 bytes;
71} interface_counter_t;
72
73typedef struct {
74 struct in_addr address;
75 u8 address_length;
76 u64 packets;
77 u64 bytes;
78} ip4_fib_counter_t;
79
80typedef struct {
81 struct in6_addr address;
82 u8 address_length;
83 u64 packets;
84 u64 bytes;
85} ip6_fib_counter_t;
86
87typedef struct {
88 /* vpe input queue */
89 unix_shared_memory_queue_t * vl_input_queue;
90
91 /* interface name table */
92 uword * sw_if_index_by_interface_name;
93
94 /* subinterface table */
95 sw_interface_subif_t * sw_if_subif_table;
96
Dave Barachb44e9bc2016-02-19 09:06:23 -050097 /* Graph node table */
98 uword * graph_node_index_by_name;
99 vlib_node_t ** graph_nodes;
100
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101 /* ip tables */
102 ip_details_t * ip_details_by_sw_if_index[2];
103
104 /* sw_if_index of currently processed interface */
105 u32 current_sw_if_index;
106
107 /* remember that we are dumping ipv6 */
108 u8 is_ipv6;
109
110 /* function table */
111 uword * function_by_name;
112
113 /* help strings */
114 uword * help_by_name;
115
116 /* macro table */
117 macro_main_t macro_main;
118
119 /* Errors by number */
120 uword * error_string_by_error_number;
121
Dave Barachb44e9bc2016-02-19 09:06:23 -0500122
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123 /* Main thread can spin (w/ timeout) here if needed */
124 u32 async_mode;
125 u32 async_errors;
126 volatile u32 result_ready;
127 volatile i32 retval;
128 volatile u8 *shmem_result;
129
130 /* our client index */
131 u32 my_client_index;
132
133 /* Time is of the essence... */
134 clib_time_t clib_time;
135
136 /* Unwind (so we can quit) */
137 jmp_buf jump_buf;
138
139 /* temporary parse buffer */
140 unformat_input_t *input;
141
142 /* input buffer */
143 u8 * inbuf;
144
145 /* stdio input / output FILEs */
146 FILE *ifp, *ofp;
147 u8 * current_file;
148 u32 input_line_number;
149
150 /* exec mode toggle */
151 int exec_mode;
152
153 /* Regenerate the interface table */
154 volatile int regenerate_interface_table;
155
156 /* flag for JSON output format */
157 u8 json_output;
158
159 /* flag for interface event display */
160 u8 interface_event_display;
161
162 /* JSON tree used in composing dump api call results */
163 vat_json_node_t json_tree;
164
165 /* counters */
166 u64 **simple_interface_counters;
167 interface_counter_t **combined_interface_counters;
168 ip4_fib_counter_t **ip4_fib_counters;
169 u32 *ip4_fib_counters_vrf_id_by_index;
170 ip6_fib_counter_t **ip6_fib_counters;
171 u32 *ip6_fib_counters_vrf_id_by_index;
172
173} vat_main_t;
174
175vat_main_t vat_main;
176
177static inline f64 vat_time_now (vat_main_t *vam)
178{
179 return clib_time_now (&vam->clib_time);
180}
181
182#define errmsg(fmt,args...) \
183do { \
184 if(vam->ifp != stdin) \
185 fformat(vam->ofp,"%s(%d): ", vam->current_file, \
186 vam->input_line_number); \
187 fformat(vam->ofp, fmt, ##args); \
188 fflush(vam->ofp); \
189} while(0);
190
191void vat_api_hookup (vat_main_t *vam);
192int api_sw_interface_dump (vat_main_t * vam);
193void do_one_file (vat_main_t * vam);
194int exec (vat_main_t * vam);
195
196/* Plugin API library functions */
197char *vat_plugin_path;
198char *vat_plugin_name_filter;
199void vat_plugin_api_reference(void);
200uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
201uword unformat_ip4_address (unformat_input_t * input, va_list * args);
202uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
203uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
204 va_list * args);
205uword unformat_ip6_address (unformat_input_t * input, va_list * args);
206u8 * format_ip4_address (u8 * s, va_list * args);
207u8 * format_ethernet_address (u8 * s, va_list * args);
208
209
210#endif /* __included_vat_h__ */