api: Cleanup APIs interface.api
[vpp.git] / src / vat / vat.h
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 #define _GNU_SOURCE
19 #include <stdio.h>
20 #include <setjmp.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <vppinfra/clib.h>
25 #include <vppinfra/format.h>
26 #include <vppinfra/error.h>
27 #include <vppinfra/elog.h>
28 #include <vppinfra/time.h>
29 #include <vppinfra/macros.h>
30 #include <vppinfra/socket.h>
31 #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
41 typedef 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
51   /* Number of tags 0-2 */
52   u8 sub_number_of_tags;
53   u16 sub_outer_vlan_id;
54   u16 sub_inner_vlan_id;
55
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   };
72
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
80 typedef struct
81 {
82   u8 ip[16];
83   u8 prefix_length;
84 } ip_address_details_t;
85
86 typedef struct
87 {
88   u8 present;
89   ip_address_details_t *addr;
90 } ip_details_t;
91
92 typedef struct
93 {
94   u64 packets;
95   u64 bytes;
96 } interface_counter_t;
97
98 typedef struct
99 {
100   struct in_addr address;
101   u8 address_length;
102   u64 packets;
103   u64 bytes;
104 } ip4_fib_counter_t;
105
106 typedef struct
107 {
108   struct in6_addr address;
109   u8 address_length;
110   u64 packets;
111   u64 bytes;
112 } ip6_fib_counter_t;
113
114 typedef struct
115 {
116   struct in_addr address;
117   vnet_link_t linkt;
118   u64 packets;
119   u64 bytes;
120 } ip4_nbr_counter_t;
121
122 typedef struct
123 {
124   struct in6_addr address;
125   vnet_link_t linkt;
126   u64 packets;
127   u64 bytes;
128 } ip6_nbr_counter_t;
129
130 typedef struct
131 {
132   /* vpe input queue */
133   svm_queue_t *vl_input_queue;
134
135   /* interface name table */
136   uword *sw_if_index_by_interface_name;
137
138   /* subinterface table */
139   sw_interface_subif_t *sw_if_subif_table;
140
141   /* Graph node table */
142   uword *graph_node_index_by_name;
143   vlib_node_t ***graph_nodes;
144
145   /* ip tables */
146   ip_details_t *ip_details_by_sw_if_index[2];
147
148   /* sw_if_index of currently processed interface */
149   u32 current_sw_if_index;
150
151   /* remember that we are dumping ipv6 */
152   u8 is_ipv6;
153
154   /* function table */
155   uword *function_by_name;
156
157   /* help strings */
158   uword *help_by_name;
159
160   /* macro table */
161   macro_main_t macro_main;
162
163   /* Errors by number */
164   uword *error_string_by_error_number;
165
166   /* Main thread can spin (w/ timeout) here if needed */
167   u32 async_mode;
168   u32 async_errors;
169   volatile u32 result_ready;
170   volatile i32 retval;
171   volatile u32 sw_if_index;
172   volatile u8 *shmem_result;
173   u8 *cmd_reply;
174
175   /* our client index */
176   u32 my_client_index;
177   int client_index_invalid;
178
179   /* Time is of the essence... */
180   clib_time_t clib_time;
181
182   /* Unwind (so we can quit) */
183   jmp_buf jump_buf;
184   int jump_buf_set;
185   volatile int do_exit;
186
187   /* temporary parse buffer */
188   unformat_input_t *input;
189
190   /* input buffer */
191   u8 *inbuf;
192
193   /* stdio input / output FILEs */
194   FILE *ifp, *ofp;
195   u8 *current_file;
196   u32 input_line_number;
197
198   /* exec mode toggle */
199   int exec_mode;
200
201   /* Regenerate the interface table */
202   volatile int regenerate_interface_table;
203
204   /* flag for JSON output format */
205   u8 json_output;
206
207   /* flag for interface event display */
208   u8 interface_event_display;
209
210   /* JSON tree used in composing dump api call results */
211   vat_json_node_t json_tree;
212
213   /* counters */
214   u64 **simple_interface_counters;
215   interface_counter_t **combined_interface_counters;
216   ip4_fib_counter_t **ip4_fib_counters;
217   u32 *ip4_fib_counters_vrf_id_by_index;
218   ip6_fib_counter_t **ip6_fib_counters;
219   u32 *ip6_fib_counters_vrf_id_by_index;
220   ip4_nbr_counter_t **ip4_nbr_counters;
221   ip6_nbr_counter_t **ip6_nbr_counters;
222
223   ssvm_private_t stat_segment;
224   clib_spinlock_t *stat_segment_lockp;
225
226   socket_client_main_t *socket_client_main;
227   u8 *socket_name;
228
229   elog_main_t elog_main;
230
231   /* Convenience */
232   vlib_main_t *vlib_main;
233 } vat_main_t;
234
235 extern vat_main_t vat_main;
236
237 void vat_suspend (vlib_main_t * vm, f64 interval);
238 f64 vat_time_now (vat_main_t * vam);
239 void errmsg (char *fmt, ...);
240 void vat_api_hookup (vat_main_t * vam);
241 int api_sw_interface_dump (vat_main_t * vam);
242 void do_one_file (vat_main_t * vam);
243 int exec (vat_main_t * vam);
244
245 /* Plugin API library functions */
246 extern char *vat_plugin_path;
247 extern char *vat_plugin_name_filter;
248 void vat_plugin_api_reference (void);
249 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
250 uword unformat_ip4_address (unformat_input_t * input, va_list * args);
251 uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
252 uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
253                                               va_list * args);
254 uword unformat_ip6_address (unformat_input_t * input, va_list * args);
255 u8 *format_ip4_address (u8 * s, va_list * args);
256 u8 *format_ip6_address (u8 * s, va_list * args);
257 u8 *format_ip46_address (u8 * s, va_list * args);
258 u8 *format_ethernet_address (u8 * s, va_list * args);
259
260 int vat_socket_connect (vat_main_t * vam);
261
262 #if VPP_API_TEST_BUILTIN
263 #define print api_cli_output
264 void api_cli_output (void *, const char *fmt, ...);
265 #else
266 #define print fformat_append_cr
267 void fformat_append_cr (FILE *, const char *fmt, ...);
268 #endif
269
270 #endif /* __included_vat_h__ */
271
272 /*
273  * fd.io coding-style-patch-verification: ON
274  *
275  * Local Variables:
276  * eval: (c-set-style "gnu")
277  * End:
278  */