blob: d380abeaf12e65ae22b79439668e5437a403e6e6 [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
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 Barach59b25652017-09-10 15:04:27 -040018#define _GNU_SOURCE
Damjan Marion7cd468a2016-12-19 23:05:39 +010019#include <stdio.h>
20#include <setjmp.h>
Dave Barach59b25652017-09-10 15:04:27 -040021#include <sys/types.h>
22#include <sys/socket.h>
23#include <sys/un.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010024#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 Barach59b25652017-09-10 15:04:27 -040029#include <vppinfra/socket.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010030#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
40typedef 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
Damjan Marion7cd468a2016-12-19 23:05:39 +010050 /* Number of tags 0-2 */
51 u8 sub_number_of_tags;
52 u16 sub_outer_vlan_id;
53 u16 sub_inner_vlan_id;
Jakub Grajciare63325e2019-03-01 08:55:49 +010054
55 union
56 {
57 u16 raw_flags;
58 struct
59 {
60 u16 no_tags:1;
61 u16 one_tag:1;
62 u16 two_tags:1;
63 /* 0 = dot1q, 1=dot1ad */
64 u16 sub_dot1ad:1;
65 u16 sub_exact_match:1;
66 u16 sub_default:1;
67 u16 sub_outer_vlan_id_any:1;
68 u16 sub_inner_vlan_id_any:1;
69 };
70 };
Damjan Marion7cd468a2016-12-19 23:05:39 +010071
72 /* vlan tag rewrite */
73 u32 vtr_op;
74 u32 vtr_push_dot1q;
75 u32 vtr_tag1;
76 u32 vtr_tag2;
77} sw_interface_subif_t;
78
79typedef struct
80{
81 u8 ip[16];
82 u8 prefix_length;
83} ip_address_details_t;
84
85typedef struct
86{
87 u8 present;
88 ip_address_details_t *addr;
89} ip_details_t;
90
91typedef struct
92{
93 u64 packets;
94 u64 bytes;
95} interface_counter_t;
96
97typedef struct
98{
99 struct in_addr address;
100 u8 address_length;
101 u64 packets;
102 u64 bytes;
103} ip4_fib_counter_t;
104
105typedef struct
106{
107 struct in6_addr address;
108 u8 address_length;
109 u64 packets;
110 u64 bytes;
111} ip6_fib_counter_t;
112
113typedef struct
114{
Neale Ranns044183f2017-01-24 01:34:25 -0800115 struct in_addr address;
116 vnet_link_t linkt;
117 u64 packets;
118 u64 bytes;
119} ip4_nbr_counter_t;
120
121typedef struct
122{
123 struct in6_addr address;
124 vnet_link_t linkt;
125 u64 packets;
126 u64 bytes;
127} ip6_nbr_counter_t;
128
129typedef struct
130{
Damjan Marion7cd468a2016-12-19 23:05:39 +0100131 /* vpe input queue */
Florin Corase86a8ed2018-01-05 03:20:25 -0800132 svm_queue_t *vl_input_queue;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100133
134 /* interface name table */
135 uword *sw_if_index_by_interface_name;
136
137 /* subinterface table */
138 sw_interface_subif_t *sw_if_subif_table;
139
140 /* Graph node table */
141 uword *graph_node_index_by_name;
Dave Barach1ddbc012018-06-13 09:26:05 -0400142 vlib_node_t ***graph_nodes;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100143
144 /* ip tables */
145 ip_details_t *ip_details_by_sw_if_index[2];
146
147 /* sw_if_index of currently processed interface */
148 u32 current_sw_if_index;
149
150 /* remember that we are dumping ipv6 */
151 u8 is_ipv6;
152
153 /* function table */
154 uword *function_by_name;
155
156 /* help strings */
157 uword *help_by_name;
158
159 /* macro table */
160 macro_main_t macro_main;
161
162 /* Errors by number */
163 uword *error_string_by_error_number;
164
Damjan Marion7cd468a2016-12-19 23:05:39 +0100165 /* Main thread can spin (w/ timeout) here if needed */
166 u32 async_mode;
167 u32 async_errors;
168 volatile u32 result_ready;
169 volatile i32 retval;
170 volatile u32 sw_if_index;
171 volatile u8 *shmem_result;
Dave Barach59b25652017-09-10 15:04:27 -0400172 u8 *cmd_reply;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100173
174 /* our client index */
175 u32 my_client_index;
Dave Barach59b25652017-09-10 15:04:27 -0400176 int client_index_invalid;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100177
178 /* Time is of the essence... */
179 clib_time_t clib_time;
180
181 /* Unwind (so we can quit) */
182 jmp_buf jump_buf;
183 int jump_buf_set;
184 volatile int do_exit;
185
186 /* temporary parse buffer */
187 unformat_input_t *input;
188
189 /* input buffer */
190 u8 *inbuf;
191
192 /* stdio input / output FILEs */
193 FILE *ifp, *ofp;
194 u8 *current_file;
195 u32 input_line_number;
196
197 /* exec mode toggle */
198 int exec_mode;
199
200 /* Regenerate the interface table */
201 volatile int regenerate_interface_table;
202
203 /* flag for JSON output format */
204 u8 json_output;
205
206 /* flag for interface event display */
207 u8 interface_event_display;
208
209 /* JSON tree used in composing dump api call results */
210 vat_json_node_t json_tree;
211
212 /* counters */
213 u64 **simple_interface_counters;
214 interface_counter_t **combined_interface_counters;
215 ip4_fib_counter_t **ip4_fib_counters;
216 u32 *ip4_fib_counters_vrf_id_by_index;
217 ip6_fib_counter_t **ip6_fib_counters;
218 u32 *ip6_fib_counters_vrf_id_by_index;
Neale Ranns044183f2017-01-24 01:34:25 -0800219 ip4_nbr_counter_t **ip4_nbr_counters;
220 ip6_nbr_counter_t **ip6_nbr_counters;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100221
Dave Barach048a4e52018-06-01 18:52:25 -0400222 ssvm_private_t stat_segment;
223 clib_spinlock_t *stat_segment_lockp;
224
Florin Coras90a63982017-12-19 04:50:01 -0800225 socket_client_main_t *socket_client_main;
Dave Barach59b25652017-09-10 15:04:27 -0400226 u8 *socket_name;
227
Damjan Marion7cd468a2016-12-19 23:05:39 +0100228 /* Convenience */
229 vlib_main_t *vlib_main;
230} vat_main_t;
231
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500232extern vat_main_t vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100233
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500234void vat_suspend (vlib_main_t * vm, f64 interval);
235f64 vat_time_now (vat_main_t * vam);
236void errmsg (char *fmt, ...);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100237void vat_api_hookup (vat_main_t * vam);
238int api_sw_interface_dump (vat_main_t * vam);
239void do_one_file (vat_main_t * vam);
240int exec (vat_main_t * vam);
241
242/* Plugin API library functions */
243char *vat_plugin_path;
244char *vat_plugin_name_filter;
245void vat_plugin_api_reference (void);
246uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
247uword unformat_ip4_address (unformat_input_t * input, va_list * args);
248uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
249uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
250 va_list * args);
251uword unformat_ip6_address (unformat_input_t * input, va_list * args);
252u8 *format_ip4_address (u8 * s, va_list * args);
Jon Loeliger229a6b72017-05-08 16:53:44 -0500253u8 *format_ip6_address (u8 * s, va_list * args);
254u8 *format_ip46_address (u8 * s, va_list * args);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100255u8 *format_ethernet_address (u8 * s, va_list * args);
256
Dave Barach59b25652017-09-10 15:04:27 -0400257int vat_socket_connect (vat_main_t * vam);
258
Damjan Marion7cd468a2016-12-19 23:05:39 +0100259#if VPP_API_TEST_BUILTIN
260#define print api_cli_output
261void api_cli_output (void *, const char *fmt, ...);
262#else
263#define print fformat_append_cr
264void fformat_append_cr (FILE *, const char *fmt, ...);
265#endif
266
267#endif /* __included_vat_h__ */
268
269/*
270 * fd.io coding-style-patch-verification: ON
271 *
272 * Local Variables:
273 * eval: (c-set-style "gnu")
274 * End:
275 */