blob: 32de90e44117665bf8ecfa2df227c5049781e489 [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>
Dave Barachb09f4d02019-07-15 16:00:03 -040027#include <vppinfra/elog.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010028#include <vppinfra/time.h>
29#include <vppinfra/macros.h>
Dave Barach59b25652017-09-10 15:04:27 -040030#include <vppinfra/socket.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010031#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
41typedef 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
Damjan Marion7cd468a2016-12-19 23:05:39 +010051 /* Number of tags 0-2 */
52 u8 sub_number_of_tags;
53 u16 sub_outer_vlan_id;
54 u16 sub_inner_vlan_id;
Jakub Grajciar053204a2019-03-18 13:17:53 +010055
56 union
57 {
58 u16 raw_flags;
59 struct
60 {
61 u16 no_tags:1;
62 u16 one_tag:1;
63 u16 two_tags:1;
64 /* 0 = dot1q, 1=dot1ad */
65 u16 sub_dot1ad:1;
66 u16 sub_exact_match:1;
67 u16 sub_default:1;
68 u16 sub_outer_vlan_id_any:1;
69 u16 sub_inner_vlan_id_any:1;
70 };
71 };
Damjan Marion7cd468a2016-12-19 23:05:39 +010072
73 /* vlan tag rewrite */
74 u32 vtr_op;
75 u32 vtr_push_dot1q;
76 u32 vtr_tag1;
77 u32 vtr_tag2;
78} sw_interface_subif_t;
79
80typedef struct
81{
82 u8 ip[16];
83 u8 prefix_length;
84} ip_address_details_t;
85
86typedef struct
87{
88 u8 present;
89 ip_address_details_t *addr;
90} ip_details_t;
91
92typedef struct
93{
94 u64 packets;
95 u64 bytes;
96} interface_counter_t;
97
98typedef struct
99{
100 struct in_addr address;
101 u8 address_length;
102 u64 packets;
103 u64 bytes;
104} ip4_fib_counter_t;
105
106typedef struct
107{
108 struct in6_addr address;
109 u8 address_length;
110 u64 packets;
111 u64 bytes;
112} ip6_fib_counter_t;
113
114typedef struct
115{
Neale Ranns044183f2017-01-24 01:34:25 -0800116 struct in_addr address;
117 vnet_link_t linkt;
118 u64 packets;
119 u64 bytes;
120} ip4_nbr_counter_t;
121
122typedef struct
123{
124 struct in6_addr address;
125 vnet_link_t linkt;
126 u64 packets;
127 u64 bytes;
128} ip6_nbr_counter_t;
129
Ole Troan3d812672020-09-15 10:53:34 +0200130struct vat_registered_features_t;
131
Neale Ranns044183f2017-01-24 01:34:25 -0800132typedef struct
133{
Damjan Marion7cd468a2016-12-19 23:05:39 +0100134 /* vpe input queue */
Florin Corase86a8ed2018-01-05 03:20:25 -0800135 svm_queue_t *vl_input_queue;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100136
137 /* interface name table */
138 uword *sw_if_index_by_interface_name;
139
140 /* subinterface table */
141 sw_interface_subif_t *sw_if_subif_table;
142
143 /* Graph node table */
144 uword *graph_node_index_by_name;
Dave Barach1ddbc012018-06-13 09:26:05 -0400145 vlib_node_t ***graph_nodes;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100146
147 /* ip tables */
148 ip_details_t *ip_details_by_sw_if_index[2];
149
150 /* sw_if_index of currently processed interface */
151 u32 current_sw_if_index;
152
153 /* remember that we are dumping ipv6 */
154 u8 is_ipv6;
155
156 /* function table */
157 uword *function_by_name;
158
159 /* help strings */
160 uword *help_by_name;
161
162 /* macro table */
Dave Barach961e3c82020-06-18 17:04:18 -0400163 clib_macro_main_t macro_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100164
165 /* Errors by number */
166 uword *error_string_by_error_number;
167
Damjan Marion7cd468a2016-12-19 23:05:39 +0100168 /* Main thread can spin (w/ timeout) here if needed */
169 u32 async_mode;
170 u32 async_errors;
171 volatile u32 result_ready;
172 volatile i32 retval;
173 volatile u32 sw_if_index;
174 volatile u8 *shmem_result;
Dave Barach59b25652017-09-10 15:04:27 -0400175 u8 *cmd_reply;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100176
177 /* our client index */
178 u32 my_client_index;
Dave Barach59b25652017-09-10 15:04:27 -0400179 int client_index_invalid;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100180
181 /* Time is of the essence... */
182 clib_time_t clib_time;
183
184 /* Unwind (so we can quit) */
185 jmp_buf jump_buf;
186 int jump_buf_set;
187 volatile int do_exit;
188
189 /* temporary parse buffer */
190 unformat_input_t *input;
191
192 /* input buffer */
193 u8 *inbuf;
194
195 /* stdio input / output FILEs */
196 FILE *ifp, *ofp;
197 u8 *current_file;
198 u32 input_line_number;
199
200 /* exec mode toggle */
201 int exec_mode;
202
203 /* Regenerate the interface table */
204 volatile int regenerate_interface_table;
205
206 /* flag for JSON output format */
207 u8 json_output;
208
209 /* flag for interface event display */
210 u8 interface_event_display;
211
212 /* JSON tree used in composing dump api call results */
213 vat_json_node_t json_tree;
214
215 /* counters */
216 u64 **simple_interface_counters;
217 interface_counter_t **combined_interface_counters;
218 ip4_fib_counter_t **ip4_fib_counters;
219 u32 *ip4_fib_counters_vrf_id_by_index;
220 ip6_fib_counter_t **ip6_fib_counters;
221 u32 *ip6_fib_counters_vrf_id_by_index;
Neale Ranns044183f2017-01-24 01:34:25 -0800222 ip4_nbr_counter_t **ip4_nbr_counters;
223 ip6_nbr_counter_t **ip6_nbr_counters;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100224
Dave Barach048a4e52018-06-01 18:52:25 -0400225 ssvm_private_t stat_segment;
226 clib_spinlock_t *stat_segment_lockp;
227
Florin Coras90a63982017-12-19 04:50:01 -0800228 socket_client_main_t *socket_client_main;
Dave Barach59b25652017-09-10 15:04:27 -0400229 u8 *socket_name;
230
Dave Barachb09f4d02019-07-15 16:00:03 -0400231 elog_main_t elog_main;
Dave Barachb09f4d02019-07-15 16:00:03 -0400232
Ole Troan3d812672020-09-15 10:53:34 +0200233 struct vat_registered_features_t *feature_function_registrations;
234
Damjan Marion7cd468a2016-12-19 23:05:39 +0100235 /* Convenience */
236 vlib_main_t *vlib_main;
237} vat_main_t;
238
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500239extern vat_main_t vat_main;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100240
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500241void vat_suspend (vlib_main_t * vm, f64 interval);
242f64 vat_time_now (vat_main_t * vam);
243void errmsg (char *fmt, ...);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100244void vat_api_hookup (vat_main_t * vam);
245int api_sw_interface_dump (vat_main_t * vam);
246void do_one_file (vat_main_t * vam);
247int exec (vat_main_t * vam);
248
249/* Plugin API library functions */
BenoƮt Ganne49ee6842019-04-30 11:50:46 +0200250extern char *vat_plugin_path;
251extern char *vat_plugin_name_filter;
Damjan Marion7cd468a2016-12-19 23:05:39 +0100252void vat_plugin_api_reference (void);
253uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
254uword unformat_ip4_address (unformat_input_t * input, va_list * args);
255uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
256uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
257 va_list * args);
258uword unformat_ip6_address (unformat_input_t * input, va_list * args);
259u8 *format_ip4_address (u8 * s, va_list * args);
Jon Loeliger229a6b72017-05-08 16:53:44 -0500260u8 *format_ip6_address (u8 * s, va_list * args);
261u8 *format_ip46_address (u8 * s, va_list * args);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100262u8 *format_ethernet_address (u8 * s, va_list * args);
263
Dave Barach59b25652017-09-10 15:04:27 -0400264int vat_socket_connect (vat_main_t * vam);
265
Damjan Marion7cd468a2016-12-19 23:05:39 +0100266#if VPP_API_TEST_BUILTIN
267#define print api_cli_output
268void api_cli_output (void *, const char *fmt, ...);
269#else
270#define print fformat_append_cr
271void fformat_append_cr (FILE *, const char *fmt, ...);
272#endif
273
Ole Troan3d812672020-09-15 10:53:34 +0200274
275typedef clib_error_t *(vat_feature_function_t) (vat_main_t * vam);
276typedef struct vat_registered_features_t
277{
278 vat_feature_function_t *function;
279 struct vat_registered_features_t *next;
280} vat_registered_features_t;
281
282
283#define VAT_REGISTER_FEATURE_FUNCTION(x) \
284 vat_registered_features_t _vat_feature_function_##x; \
285static void __vlib_add_config_function_##x (void) \
286 __attribute__((__constructor__)) ; \
287static void __vlib_add_config_function_##x (void) \
288{ \
289 vat_main_t * vam = &vat_main; \
290 _vat_feature_function_##x.next = vam->feature_function_registrations; \
291 vam->feature_function_registrations = &_vat_feature_function_##x; \
292} \
293 vat_registered_features_t _vat_feature_function_##x = \
294 { \
295 .function = x, \
296 }
297
298
Damjan Marion7cd468a2016-12-19 23:05:39 +0100299#endif /* __included_vat_h__ */
300
301/*
302 * fd.io coding-style-patch-verification: ON
303 *
304 * Local Variables:
305 * eval: (c-set-style "gnu")
306 * End:
307 */