dpdk: Add support for Mellanox ConnectX-4 devices
[vpp.git] / vpp-api-test / 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 #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 "json_format.h"
32
33 #include <vlib/vlib.h>
34
35 typedef struct
36 {
37   u8 *interface_name;
38   u32 sw_if_index;
39   /*
40    * Subinterface ID. A number 0-N to uniquely identify this
41    * subinterface under the super interface
42    */
43   u32 sub_id;
44
45   /* 0 = dot1q, 1=dot1ad */
46   u8 sub_dot1ad;
47
48   /* Number of tags 0-2 */
49   u8 sub_number_of_tags;
50   u16 sub_outer_vlan_id;
51   u16 sub_inner_vlan_id;
52   u8 sub_exact_match;
53   u8 sub_default;
54   u8 sub_outer_vlan_id_any;
55   u8 sub_inner_vlan_id_any;
56
57   /* vlan tag rewrite */
58   u32 vtr_op;
59   u32 vtr_push_dot1q;
60   u32 vtr_tag1;
61   u32 vtr_tag2;
62 } sw_interface_subif_t;
63
64 typedef struct
65 {
66   u8 ip[16];
67   u8 prefix_length;
68 } ip_address_details_t;
69
70 typedef struct
71 {
72   u8 present;
73   ip_address_details_t *addr;
74 } ip_details_t;
75
76 typedef struct
77 {
78   u64 packets;
79   u64 bytes;
80 } interface_counter_t;
81
82 typedef struct
83 {
84   struct in_addr address;
85   u8 address_length;
86   u64 packets;
87   u64 bytes;
88 } ip4_fib_counter_t;
89
90 typedef struct
91 {
92   struct in6_addr address;
93   u8 address_length;
94   u64 packets;
95   u64 bytes;
96 } ip6_fib_counter_t;
97
98 typedef struct
99 {
100   /* vpe input queue */
101   unix_shared_memory_queue_t *vl_input_queue;
102
103   /* interface name table */
104   uword *sw_if_index_by_interface_name;
105
106   /* subinterface table */
107   sw_interface_subif_t *sw_if_subif_table;
108
109   /* Graph node table */
110   uword *graph_node_index_by_name;
111   vlib_node_t **graph_nodes;
112
113   /* ip tables */
114   ip_details_t *ip_details_by_sw_if_index[2];
115
116   /* sw_if_index of currently processed interface */
117   u32 current_sw_if_index;
118
119   /* remember that we are dumping ipv6 */
120   u8 is_ipv6;
121
122   /* function table */
123   uword *function_by_name;
124
125   /* help strings */
126   uword *help_by_name;
127
128   /* macro table */
129   macro_main_t macro_main;
130
131   /* Errors by number */
132   uword *error_string_by_error_number;
133
134
135   /* Main thread can spin (w/ timeout) here if needed */
136   u32 async_mode;
137   u32 async_errors;
138   volatile u32 result_ready;
139   volatile i32 retval;
140   volatile u32 sw_if_index;
141   volatile u8 *shmem_result;
142   volatile u8 *cmd_reply;
143
144   /* our client index */
145   u32 my_client_index;
146
147   /* Time is of the essence... */
148   clib_time_t clib_time;
149
150   /* Unwind (so we can quit) */
151   jmp_buf jump_buf;
152   int jump_buf_set;
153   volatile int do_exit;
154
155   /* temporary parse buffer */
156   unformat_input_t *input;
157
158   /* input buffer */
159   u8 *inbuf;
160
161   /* stdio input / output FILEs */
162   FILE *ifp, *ofp;
163   u8 *current_file;
164   u32 input_line_number;
165
166   /* exec mode toggle */
167   int exec_mode;
168
169   /* Regenerate the interface table */
170   volatile int regenerate_interface_table;
171
172   /* flag for JSON output format */
173   u8 json_output;
174
175   /* flag for interface event display */
176   u8 interface_event_display;
177
178   /* JSON tree used in composing dump api call results */
179   vat_json_node_t json_tree;
180
181   /* counters */
182   u64 **simple_interface_counters;
183   interface_counter_t **combined_interface_counters;
184   ip4_fib_counter_t **ip4_fib_counters;
185   u32 *ip4_fib_counters_vrf_id_by_index;
186   ip6_fib_counter_t **ip6_fib_counters;
187   u32 *ip6_fib_counters_vrf_id_by_index;
188
189   /* Convenience */
190   vlib_main_t *vlib_main;
191 } vat_main_t;
192
193 vat_main_t vat_main;
194
195 static inline f64
196 vat_time_now (vat_main_t * vam)
197 {
198 #if VPP_API_TEST_BUILTIN
199   return vlib_time_now (vam->vlib_main);
200 #else
201   return clib_time_now (&vam->clib_time);
202 #endif
203 }
204
205 #if VPP_API_TEST_BUILTIN
206 #define errmsg(fmt,args...)                             \
207 do {                                                    \
208   vat_main_t *__vam = &vat_main;                        \
209   vlib_cli_output (__vam->vlib_main, fmt, ##args);      \
210  } while(0);
211 #else
212 #define errmsg(fmt,args...)                                     \
213 do {                                                            \
214   vat_main_t *__vam = &vat_main;                                \
215     if(__vam->ifp != stdin)                                     \
216         fformat(__vam->ofp,"%s(%d): \n", __vam->current_file,   \
217                 __vam->input_line_number);                      \
218     fformat(__vam->ofp, fmt "\n", ##args);                      \
219     fflush(__vam->ofp);                                         \
220 } while(0);
221 #endif
222
223 void vat_api_hookup (vat_main_t * vam);
224 int api_sw_interface_dump (vat_main_t * vam);
225 void do_one_file (vat_main_t * vam);
226 int exec (vat_main_t * vam);
227
228 /* Plugin API library functions */
229 char *vat_plugin_path;
230 char *vat_plugin_name_filter;
231 void vat_plugin_api_reference (void);
232 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
233 uword unformat_ip4_address (unformat_input_t * input, va_list * args);
234 uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
235 uword unformat_ethernet_type_host_byte_order (unformat_input_t * input,
236                                               va_list * args);
237 uword unformat_ip6_address (unformat_input_t * input, va_list * args);
238 u8 *format_ip4_address (u8 * s, va_list * args);
239 u8 *format_ethernet_address (u8 * s, va_list * args);
240
241 #if VPP_API_TEST_BUILTIN
242 #define print api_cli_output
243 void api_cli_output (void *, const char *fmt, ...);
244 #else
245 #define print fformat_append_cr
246 void fformat_append_cr (FILE *, const char *fmt, ...);
247 #endif
248
249 #endif /* __included_vat_h__ */
250
251 /*
252  * fd.io coding-style-patch-verification: ON
253  *
254  * Local Variables:
255  * eval: (c-set-style "gnu")
256  * End:
257  */