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