blob: 0f93af5142117a7ab6503574dcf685e00b0eabb7 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Ed Warnickecb9cada2015-12-08 15:45:58 -07005 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016 * limitations under the License.
Ed Warnickecb9cada2015-12-08 15:45:58 -070017 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlibapi/api.h>
22#include <vlibmemory/api.h>
23#include <vlibsocket/api.h>
24#include <vnet/ip/ip.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/l2/l2_input.h>
27#include <vnet/l2tp/l2tp.h>
28#include <vnet/vxlan/vxlan.h>
Chris Luke27fe48f2016-04-28 13:44:38 -040029#include <vnet/gre/gre.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031#include <vnet/lisp-gpe/lisp_gpe.h>
32
Dave Barachaa6920e2016-06-27 09:25:13 -040033#include <vpp-api/vpe_msg_enum.h>
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080034#include <vnet/l2/l2_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#include <vnet/l2/l2_vtr.h>
36#include <vnet/classify/input_acl.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070037#include <vnet/classify/policer_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010038#include <vnet/mpls/mpls.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050039#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#include <vnet/ipsec/ipsec.h>
Matus Fabiane5f42fe2016-04-08 11:18:08 +020041#include <vnet/ipsec/ikev2.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050042#else
43#include <inttypes.h>
44#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070045#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050046#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000047#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040048#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070049#include <vnet/policer/xlate.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070050#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070051#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
53#include "vat/json_format.h"
54
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020055#include <sys/stat.h>
56
Dave Barach72d72232016-08-04 10:15:08 -040057#define vl_typedefs /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080058#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070059#undef vl_typedefs
60
61/* declare message handlers for each api */
62
Dave Barach72d72232016-08-04 10:15:08 -040063#define vl_endianfun /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080064#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070065#undef vl_endianfun
66
67/* instantiate all the print functions we know about */
68#define vl_print(handle, ...)
69#define vl_printfun
Dave Barachaa6920e2016-06-27 09:25:13 -040070#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#undef vl_printfun
72
Dave Barach72d72232016-08-04 10:15:08 -040073uword
74unformat_sw_if_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
Dave Barach72d72232016-08-04 10:15:08 -040076 vat_main_t *vam = va_arg (*args, vat_main_t *);
77 u32 *result = va_arg (*args, u32 *);
78 u8 *if_name;
79 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 if (!unformat (input, "%s", &if_name))
Dave Barach72d72232016-08-04 10:15:08 -040082 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
84 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
85 if (p == 0)
Dave Barach72d72232016-08-04 10:15:08 -040086 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 *result = p[0];
88 return 1;
89}
90
91/* Parse an IP4 address %d.%d.%d.%d. */
Dave Barach72d72232016-08-04 10:15:08 -040092uword
93unformat_ip4_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070094{
Dave Barach72d72232016-08-04 10:15:08 -040095 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 unsigned a[4];
97
Dave Barach72d72232016-08-04 10:15:08 -040098 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 return 0;
100
101 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 return 0;
103
104 result[0] = a[0];
105 result[1] = a[1];
106 result[2] = a[2];
107 result[3] = a[3];
108
109 return 1;
110}
111
112
113uword
114unformat_ethernet_address (unformat_input_t * input, va_list * args)
115{
Dave Barach72d72232016-08-04 10:15:08 -0400116 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u32 i, a[6];
118
Dave Barach72d72232016-08-04 10:15:08 -0400119 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
120 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 return 0;
122
123 /* Check range. */
124 for (i = 0; i < 6; i++)
125 if (a[i] >= (1 << 8))
126 return 0;
127
128 for (i = 0; i < 6; i++)
129 result[i] = a[i];
130
131 return 1;
132}
133
134/* Returns ethernet type as an int in host byte order. */
135uword
136unformat_ethernet_type_host_byte_order (unformat_input_t * input,
137 va_list * args)
138{
Dave Barach72d72232016-08-04 10:15:08 -0400139 u16 *result = va_arg (*args, u16 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140 int type;
141
142 /* Numeric type. */
Dave Barach72d72232016-08-04 10:15:08 -0400143 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 {
145 if (type >= (1 << 16))
146 return 0;
147 *result = type;
148 return 1;
149 }
150 return 0;
151}
152
153/* Parse an IP6 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400154uword
155unformat_ip6_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156{
Dave Barach72d72232016-08-04 10:15:08 -0400157 ip6_address_t *result = va_arg (*args, ip6_address_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 u16 hex_quads[8];
159 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
160 uword c, n_colon, double_colon_index;
161
162 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
163 double_colon_index = ARRAY_LEN (hex_quads);
164 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
165 {
166 hex_digit = 16;
167 if (c >= '0' && c <= '9')
168 hex_digit = c - '0';
169 else if (c >= 'a' && c <= 'f')
170 hex_digit = c + 10 - 'a';
171 else if (c >= 'A' && c <= 'F')
172 hex_digit = c + 10 - 'A';
173 else if (c == ':' && n_colon < 2)
174 n_colon++;
175 else
176 {
177 unformat_put_input (input);
178 break;
179 }
180
181 /* Too many hex quads. */
182 if (n_hex_quads >= ARRAY_LEN (hex_quads))
183 return 0;
184
185 if (hex_digit < 16)
186 {
187 hex_quad = (hex_quad << 4) | hex_digit;
188
189 /* Hex quad must fit in 16 bits. */
190 if (n_hex_digits >= 4)
191 return 0;
192
193 n_colon = 0;
194 n_hex_digits++;
195 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800196
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197 /* Save position of :: */
198 if (n_colon == 2)
199 {
200 /* More than one :: ? */
201 if (double_colon_index < ARRAY_LEN (hex_quads))
202 return 0;
203 double_colon_index = n_hex_quads;
204 }
205
206 if (n_colon > 0 && n_hex_digits > 0)
207 {
208 hex_quads[n_hex_quads++] = hex_quad;
209 hex_quad = 0;
210 n_hex_digits = 0;
211 }
212 }
213
214 if (n_hex_digits > 0)
215 hex_quads[n_hex_quads++] = hex_quad;
216
217 {
218 word i;
219
220 /* Expand :: to appropriate number of zero hex quads. */
221 if (double_colon_index < ARRAY_LEN (hex_quads))
222 {
223 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
224
225 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
226 hex_quads[n_zero + i] = hex_quads[i];
227
228 for (i = 0; i < n_zero; i++)
229 hex_quads[double_colon_index + i] = 0;
230
231 n_hex_quads = ARRAY_LEN (hex_quads);
232 }
233
234 /* Too few hex quads given. */
235 if (n_hex_quads < ARRAY_LEN (hex_quads))
236 return 0;
237
238 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
239 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
240
241 return 1;
242 }
243}
244
245uword
246unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
247{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500248#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400249 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
Dave Barach72d72232016-08-04 10:15:08 -0400251 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
253 foreach_ipsec_policy_action
254#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400255 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256 return 0;
257 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500258#else
259 return 0;
260#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261}
262
263uword
264unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
265{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500266#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400267 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268
Dave Barach72d72232016-08-04 10:15:08 -0400269 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
271 foreach_ipsec_crypto_alg
272#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400273 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274 return 0;
275 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500276#else
277 return 0;
278#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279}
280
281u8 *
282format_ipsec_crypto_alg (u8 * s, va_list * args)
283{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500284#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400286 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287
288 switch (i)
289 {
290#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400291 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400293 default:
294 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295 }
296 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500297#else
298 return format (s, "Unimplemented");
299#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300}
301
302uword
303unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
304{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500305#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400306 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307
Dave Barach72d72232016-08-04 10:15:08 -0400308 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
310 foreach_ipsec_integ_alg
311#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400312 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313 return 0;
314 return 1;
Dave Barachbfdedbd2016-01-20 09:11:55 -0500315#else
316 return 0;
317#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318}
319
320u8 *
321format_ipsec_integ_alg (u8 * s, va_list * args)
322{
Dave Barachbfdedbd2016-01-20 09:11:55 -0500323#if DPDK > 0
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400325 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700326
327 switch (i)
328 {
329#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400330 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400332 default:
333 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334 }
335 return format (s, "%s", t);
Dave Barachbfdedbd2016-01-20 09:11:55 -0500336#else
337 return format (s, "Unsupported");
338#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339}
340
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200341uword
342unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
343{
344#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400345 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200346
Dave Barach72d72232016-08-04 10:15:08 -0400347 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200348#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
349 foreach_ikev2_auth_method
350#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400351 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200352 return 0;
353 return 1;
354#else
355 return 0;
356#endif
357}
358
359uword
360unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
361{
362#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -0400363 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200364
Dave Barach72d72232016-08-04 10:15:08 -0400365 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200366#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
367 foreach_ikev2_id_type
368#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400369 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200370 return 0;
371 return 1;
372#else
373 return 0;
374#endif
375}
376
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700377uword
378unformat_policer_rate_type (unformat_input_t * input, va_list * args)
379{
Dave Barach72d72232016-08-04 10:15:08 -0400380 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700381
382 if (unformat (input, "kbps"))
383 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400384 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700385 *r = SSE2_QOS_RATE_PPS;
386 else
387 return 0;
388 return 1;
389}
390
391uword
392unformat_policer_round_type (unformat_input_t * input, va_list * args)
393{
Dave Barach72d72232016-08-04 10:15:08 -0400394 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700395
Dave Barach72d72232016-08-04 10:15:08 -0400396 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700397 *r = SSE2_QOS_ROUND_TO_CLOSEST;
398 else if (unformat (input, "up"))
399 *r = SSE2_QOS_ROUND_TO_UP;
400 else if (unformat (input, "down"))
401 *r = SSE2_QOS_ROUND_TO_DOWN;
402 else
403 return 0;
404 return 1;
405}
406
407uword
408unformat_policer_type (unformat_input_t * input, va_list * args)
409{
Dave Barach72d72232016-08-04 10:15:08 -0400410 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700411
412 if (unformat (input, "1r2c"))
413 *r = SSE2_QOS_POLICER_TYPE_1R2C;
414 else if (unformat (input, "1r3c"))
415 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
416 else if (unformat (input, "2r3c-2698"))
417 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
418 else if (unformat (input, "2r3c-4115"))
419 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
420 else if (unformat (input, "2r3c-mef5cf1"))
421 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
422 else
423 return 0;
424 return 1;
425}
426
Matus Fabian4ac74c92016-05-31 07:33:29 -0700427uword
428unformat_dscp (unformat_input_t * input, va_list * va)
429{
Dave Barach72d72232016-08-04 10:15:08 -0400430 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700431
Dave Barach72d72232016-08-04 10:15:08 -0400432 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700433#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400434 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700435#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400436 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700437 return 0;
438 return 1;
439}
440
441uword
442unformat_policer_action_type (unformat_input_t * input, va_list * va)
443{
Dave Barach72d72232016-08-04 10:15:08 -0400444 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700445 = va_arg (*va, sse2_qos_pol_action_params_st *);
446
447 if (unformat (input, "drop"))
448 a->action_type = SSE2_QOS_ACTION_DROP;
449 else if (unformat (input, "transmit"))
450 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
451 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
452 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
453 else
454 return 0;
455 return 1;
456}
457
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700458uword
459unformat_classify_table_type (unformat_input_t * input, va_list * va)
460{
Dave Barach72d72232016-08-04 10:15:08 -0400461 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700462 u32 tid;
463
464 if (unformat (input, "ip4"))
465 tid = POLICER_CLASSIFY_TABLE_IP4;
466 else if (unformat (input, "ip6"))
467 tid = POLICER_CLASSIFY_TABLE_IP6;
468 else if (unformat (input, "l2"))
469 tid = POLICER_CLASSIFY_TABLE_L2;
470 else
471 return 0;
472
473 *r = tid;
474 return 1;
475}
476
Dave Barach72d72232016-08-04 10:15:08 -0400477u8 *
478format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700479{
Dave Barach72d72232016-08-04 10:15:08 -0400480 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700481 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
482}
483
Dave Barach72d72232016-08-04 10:15:08 -0400484u8 *
485format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486{
Dave Barach72d72232016-08-04 10:15:08 -0400487 ip6_address_t *a = va_arg (*args, ip6_address_t *);
488 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700489
Dave Barach72d72232016-08-04 10:15:08 -0400490 i_max_n_zero = ARRAY_LEN (a->as_u16);
491 max_n_zeros = 0;
492 i_first_zero = i_max_n_zero;
493 n_zeros = 0;
494 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
495 {
496 u32 is_zero = a->as_u16[i] == 0;
497 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
498 {
499 i_first_zero = i;
500 n_zeros = 0;
501 }
502 n_zeros += is_zero;
503 if ((!is_zero && n_zeros > max_n_zeros)
504 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
505 {
506 i_max_n_zero = i_first_zero;
507 max_n_zeros = n_zeros;
508 i_first_zero = ARRAY_LEN (a->as_u16);
509 n_zeros = 0;
510 }
511 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700512
Dave Barach72d72232016-08-04 10:15:08 -0400513 last_double_colon = 0;
514 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
515 {
516 if (i == i_max_n_zero && max_n_zeros > 1)
517 {
518 s = format (s, "::");
519 i += max_n_zeros - 1;
520 last_double_colon = 1;
521 }
522 else
523 {
524 s = format (s, "%s%x",
525 (last_double_colon || i == 0) ? "" : ":",
526 clib_net_to_host_u16 (a->as_u16[i]));
527 last_double_colon = 0;
528 }
529 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700530
Dave Barach72d72232016-08-04 10:15:08 -0400531 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532}
533
Chris Luke99cb3352016-04-26 10:49:53 -0400534/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400535u8 *
536format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400537{
538 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200539 ip46_type_t type = va_arg (*args, ip46_type_t);
540 int is_ip4 = 1;
541
542 switch (type)
543 {
Dave Barach72d72232016-08-04 10:15:08 -0400544 case IP46_TYPE_ANY:
545 is_ip4 = ip46_address_is_ip4 (ip46);
546 break;
547 case IP46_TYPE_IP4:
548 is_ip4 = 1;
549 break;
550 case IP46_TYPE_IP6:
551 is_ip4 = 0;
552 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200553 }
554
555 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400556 format (s, "%U", format_ip4_address, &ip46->ip4) :
557 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400558}
559
Dave Barach72d72232016-08-04 10:15:08 -0400560u8 *
561format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562{
Dave Barach72d72232016-08-04 10:15:08 -0400563 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700564
565 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400566 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700567}
568
Dave Barach72d72232016-08-04 10:15:08 -0400569void
570increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571{
Dave Barach72d72232016-08-04 10:15:08 -0400572 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573
Dave Barach72d72232016-08-04 10:15:08 -0400574 v = ntohl (a->as_u32) + 1;
575 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576}
577
Dave Barach72d72232016-08-04 10:15:08 -0400578void
579increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580{
Dave Barach72d72232016-08-04 10:15:08 -0400581 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582
Dave Barach72d72232016-08-04 10:15:08 -0400583 v0 = clib_net_to_host_u64 (a->as_u64[0]);
584 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700585
Dave Barach72d72232016-08-04 10:15:08 -0400586 v1 += 1;
587 if (v1 == 0)
588 v0 += 1;
589 a->as_u64[0] = clib_net_to_host_u64 (v0);
590 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700591}
592
Dave Barach72d72232016-08-04 10:15:08 -0400593void
594increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700595{
Dave Barach72d72232016-08-04 10:15:08 -0400596 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700597
Dave Barach72d72232016-08-04 10:15:08 -0400598 tmp = clib_net_to_host_u64 (tmp);
599 tmp += 1 << 16; /* skip unused (least significant) octets */
600 tmp = clib_host_to_net_u64 (tmp);
601 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700602}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800604static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400605 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700606{
Dave Barach72d72232016-08-04 10:15:08 -0400607 vat_main_t *vam = &vat_main;
608 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700609
Dave Barach72d72232016-08-04 10:15:08 -0400610 vam->retval = retval;
611 vam->regenerate_interface_table = 1;
612 vam->sw_if_index = ntohl (mp->sw_if_index);
613 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614}
615
616static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400617 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618{
Dave Barach72d72232016-08-04 10:15:08 -0400619 vat_main_t *vam = &vat_main;
620 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621
Dave Barach72d72232016-08-04 10:15:08 -0400622 vat_json_init_object (&node);
623 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
624 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700625
Dave Barach72d72232016-08-04 10:15:08 -0400626 vat_json_print (vam->ofp, &node);
627 vat_json_free (&node);
628 vam->retval = ntohl (mp->retval);
629 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700630}
631
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800632static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400633 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700634{
Dave Barach72d72232016-08-04 10:15:08 -0400635 vat_main_t *vam = &vat_main;
636 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700637
Dave Barach72d72232016-08-04 10:15:08 -0400638 vam->retval = retval;
639 vam->regenerate_interface_table = 1;
640 vam->sw_if_index = ntohl (mp->sw_if_index);
641 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700642}
643
644static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400645 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700646{
Dave Barach72d72232016-08-04 10:15:08 -0400647 vat_main_t *vam = &vat_main;
648 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700649
Dave Barach72d72232016-08-04 10:15:08 -0400650 vat_json_init_object (&node);
651 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
652 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700653
Dave Barach72d72232016-08-04 10:15:08 -0400654 vat_json_print (vam->ofp, &node);
655 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700656
Dave Barach72d72232016-08-04 10:15:08 -0400657 vam->retval = ntohl (mp->retval);
658 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659}
660
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800661static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400662 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663{
Dave Barach72d72232016-08-04 10:15:08 -0400664 vat_main_t *vam = &vat_main;
665 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700666
Dave Barach72d72232016-08-04 10:15:08 -0400667 vam->retval = retval;
668 vam->regenerate_interface_table = 1;
669 vam->sw_if_index = ntohl (mp->sw_if_index);
670 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671}
672
673static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400674 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700675{
Dave Barach72d72232016-08-04 10:15:08 -0400676 vat_main_t *vam = &vat_main;
677 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700678
Dave Barach72d72232016-08-04 10:15:08 -0400679 vat_json_init_object (&node);
680 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
681 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700682
Dave Barach72d72232016-08-04 10:15:08 -0400683 vat_json_print (vam->ofp, &node);
684 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700685
Dave Barach72d72232016-08-04 10:15:08 -0400686 vam->retval = ntohl (mp->retval);
687 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700688}
689
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800690static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400691 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700692{
Dave Barach72d72232016-08-04 10:15:08 -0400693 vat_main_t *vam = &vat_main;
694 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700695
Dave Barach72d72232016-08-04 10:15:08 -0400696 vam->retval = retval;
697 vam->regenerate_interface_table = 1;
698 vam->sw_if_index = ntohl (mp->sw_if_index);
699 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700}
701
702static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400703 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700704{
Dave Barach72d72232016-08-04 10:15:08 -0400705 vat_main_t *vam = &vat_main;
706 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700707
Dave Barach72d72232016-08-04 10:15:08 -0400708 vat_json_init_object (&node);
709 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
710 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711
Dave Barach72d72232016-08-04 10:15:08 -0400712 vat_json_print (vam->ofp, &node);
713 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714
Dave Barach72d72232016-08-04 10:15:08 -0400715 vam->retval = ntohl (mp->retval);
716 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717}
718
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800719static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400720 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700721{
Dave Barach72d72232016-08-04 10:15:08 -0400722 vat_main_t *vam = &vat_main;
723 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
Dave Barach72d72232016-08-04 10:15:08 -0400725 vam->retval = retval;
726 vam->regenerate_interface_table = 1;
727 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700728}
729
730static void vl_api_interface_name_renumber_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400731 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732{
Dave Barach72d72232016-08-04 10:15:08 -0400733 vat_main_t *vam = &vat_main;
734 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700735
Dave Barach72d72232016-08-04 10:15:08 -0400736 vat_json_init_object (&node);
737 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738
Dave Barach72d72232016-08-04 10:15:08 -0400739 vat_json_print (vam->ofp, &node);
740 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741
Dave Barach72d72232016-08-04 10:15:08 -0400742 vam->retval = ntohl (mp->retval);
743 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744}
745
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800746/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747 * Special-case: build the interface table, maintain
748 * the next loopback sw_if_index vbl.
749 */
750static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400751 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752{
Dave Barach72d72232016-08-04 10:15:08 -0400753 vat_main_t *vam = &vat_main;
754 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700755
Dave Barach72d72232016-08-04 10:15:08 -0400756 hash_set_mem (vam->sw_if_index_by_interface_name, s,
757 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700758
Dave Barach72d72232016-08-04 10:15:08 -0400759 /* In sub interface case, fill the sub interface table entry */
760 if (mp->sw_if_index != mp->sup_sw_if_index)
761 {
762 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700763
Dave Barach72d72232016-08-04 10:15:08 -0400764 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765
Dave Barach72d72232016-08-04 10:15:08 -0400766 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
767 strncpy ((char *) sub->interface_name, (char *) s,
768 vec_len (sub->interface_name));
769 sub->sw_if_index = ntohl (mp->sw_if_index);
770 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771
Dave Barach72d72232016-08-04 10:15:08 -0400772 sub->sub_dot1ad = mp->sub_dot1ad;
773 sub->sub_number_of_tags = mp->sub_number_of_tags;
774 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
775 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
776 sub->sub_exact_match = mp->sub_exact_match;
777 sub->sub_default = mp->sub_default;
778 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
779 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780
Dave Barach72d72232016-08-04 10:15:08 -0400781 /* vlan tag rewrite */
782 sub->vtr_op = ntohl (mp->vtr_op);
783 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
784 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
785 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786 }
787}
788
789static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400790 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700791{
Dave Barach72d72232016-08-04 10:15:08 -0400792 vat_main_t *vam = &vat_main;
793 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794
Dave Barach72d72232016-08-04 10:15:08 -0400795 if (VAT_JSON_ARRAY != vam->json_tree.type)
796 {
797 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
798 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700799 }
Dave Barach72d72232016-08-04 10:15:08 -0400800 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801
Dave Barach72d72232016-08-04 10:15:08 -0400802 vat_json_init_object (node);
803 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
804 vat_json_object_add_uint (node, "sup_sw_if_index",
805 ntohl (mp->sup_sw_if_index));
806 vat_json_object_add_uint (node, "l2_address_length",
807 ntohl (mp->l2_address_length));
808 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
809 sizeof (mp->l2_address));
810 vat_json_object_add_string_copy (node, "interface_name",
811 mp->interface_name);
812 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
813 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
814 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
815 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
816 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
817 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
818 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
819 vat_json_object_add_uint (node, "sub_number_of_tags",
820 mp->sub_number_of_tags);
821 vat_json_object_add_uint (node, "sub_outer_vlan_id",
822 ntohs (mp->sub_outer_vlan_id));
823 vat_json_object_add_uint (node, "sub_inner_vlan_id",
824 ntohs (mp->sub_inner_vlan_id));
825 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
826 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
827 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
828 mp->sub_outer_vlan_id_any);
829 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
830 mp->sub_inner_vlan_id_any);
831 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
832 vat_json_object_add_uint (node, "vtr_push_dot1q",
833 ntohl (mp->vtr_push_dot1q));
834 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
835 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836}
837
838static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400839 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840{
Dave Barach72d72232016-08-04 10:15:08 -0400841 vat_main_t *vam = &vat_main;
842 if (vam->interface_event_display)
843 errmsg ("interface flags: sw_if_index %d %s %s\n",
844 ntohl (mp->sw_if_index),
845 mp->admin_up_down ? "admin-up" : "admin-down",
846 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700847}
848
849static void vl_api_sw_interface_set_flags_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400850 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700851{
Dave Barach72d72232016-08-04 10:15:08 -0400852 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853}
854
Dave Barach72d72232016-08-04 10:15:08 -0400855static void
856vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700857{
Dave Barach72d72232016-08-04 10:15:08 -0400858 vat_main_t *vam = &vat_main;
859 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700860
Dave Barach72d72232016-08-04 10:15:08 -0400861 vam->retval = retval;
862 vam->shmem_result = (u8 *) mp->reply_in_shmem;
863 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700864}
865
Dave Barach72d72232016-08-04 10:15:08 -0400866static void
867vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700868{
Dave Barach72d72232016-08-04 10:15:08 -0400869 vat_main_t *vam = &vat_main;
870 vat_json_node_t node;
871 api_main_t *am = &api_main;
872 void *oldheap;
873 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700874
Dave Barach72d72232016-08-04 10:15:08 -0400875 vat_json_init_object (&node);
876 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
877 vat_json_object_add_uint (&node, "reply_in_shmem",
878 ntohl (mp->reply_in_shmem));
879 /* Toss the shared-memory original... */
880 pthread_mutex_lock (&am->vlib_rp->mutex);
881 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500882
Dave Barach72d72232016-08-04 10:15:08 -0400883 reply = (u8 *) (mp->reply_in_shmem);
884 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800885
Dave Barach72d72232016-08-04 10:15:08 -0400886 svm_pop_heap (oldheap);
887 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700888
Dave Barach72d72232016-08-04 10:15:08 -0400889 vat_json_print (vam->ofp, &node);
890 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700891
Dave Barach72d72232016-08-04 10:15:08 -0400892 vam->retval = ntohl (mp->retval);
893 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700894}
895
Ole Troanc27213a2016-08-31 14:50:49 +0200896static void
897vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
898{
899 vat_main_t *vam = &vat_main;
900 i32 retval = ntohl (mp->retval);
901
902 vam->retval = retval;
903 vam->cmd_reply = mp->reply;
904 vam->result_ready = 1;
905}
906
907static void
908vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
909{
910 vat_main_t *vam = &vat_main;
911 vat_json_node_t node;
912
913 vat_json_init_object (&node);
914 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
915 vat_json_object_add_string_copy (&node, "reply", mp->reply);
916
917 vat_json_print (vam->ofp, &node);
918 vat_json_free (&node);
919
920 vam->retval = ntohl (mp->retval);
921 vam->result_ready = 1;
922}
923
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400925 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926{
Dave Barach72d72232016-08-04 10:15:08 -0400927 vat_main_t *vam = &vat_main;
928 i32 retval = ntohl (mp->retval);
929 if (vam->async_mode)
930 {
931 vam->async_errors += (retval < 0);
932 }
933 else
934 {
935 vam->retval = retval;
936 if (retval == 0 &&
937 ((mp->new_table_index != 0xFFFFFFFF) ||
938 (mp->skip_n_vectors != 0xFFFFFFFF) ||
939 (mp->match_n_vectors != 0xFFFFFFFF)))
940 /*
941 * Note: this is just barely thread-safe, depends on
942 * the main thread spinning waiting for an answer...
943 */
944 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
945 ntohl (mp->new_table_index),
946 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
947 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700948 }
949}
950
951static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400952 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700953{
Dave Barach72d72232016-08-04 10:15:08 -0400954 vat_main_t *vam = &vat_main;
955 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700956
Dave Barach72d72232016-08-04 10:15:08 -0400957 vat_json_init_object (&node);
958 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
959 vat_json_object_add_uint (&node, "new_table_index",
960 ntohl (mp->new_table_index));
961 vat_json_object_add_uint (&node, "skip_n_vectors",
962 ntohl (mp->skip_n_vectors));
963 vat_json_object_add_uint (&node, "match_n_vectors",
964 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
Dave Barach72d72232016-08-04 10:15:08 -0400966 vat_json_print (vam->ofp, &node);
967 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
Dave Barach72d72232016-08-04 10:15:08 -0400969 vam->retval = ntohl (mp->retval);
970 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700971}
972
973static void vl_api_get_node_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400974 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975{
Dave Barach72d72232016-08-04 10:15:08 -0400976 vat_main_t *vam = &vat_main;
977 i32 retval = ntohl (mp->retval);
978 if (vam->async_mode)
979 {
980 vam->async_errors += (retval < 0);
981 }
982 else
983 {
984 vam->retval = retval;
985 if (retval == 0)
986 errmsg ("node index %d\n", ntohl (mp->node_index));
987 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700988 }
989}
990
991static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400992 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700993{
Dave Barach72d72232016-08-04 10:15:08 -0400994 vat_main_t *vam = &vat_main;
995 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700996
Dave Barach72d72232016-08-04 10:15:08 -0400997 vat_json_init_object (&node);
998 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
999 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001000
Dave Barach72d72232016-08-04 10:15:08 -04001001 vat_json_print (vam->ofp, &node);
1002 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003
Dave Barach72d72232016-08-04 10:15:08 -04001004 vam->retval = ntohl (mp->retval);
1005 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006}
1007
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001008static void vl_api_get_next_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001009 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001010{
Dave Barach72d72232016-08-04 10:15:08 -04001011 vat_main_t *vam = &vat_main;
1012 i32 retval = ntohl (mp->retval);
1013 if (vam->async_mode)
1014 {
1015 vam->async_errors += (retval < 0);
1016 }
1017 else
1018 {
1019 vam->retval = retval;
1020 if (retval == 0)
1021 errmsg ("next node index %d\n", ntohl (mp->next_index));
1022 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001023 }
1024}
1025
1026static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001027 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001028{
Dave Barach72d72232016-08-04 10:15:08 -04001029 vat_main_t *vam = &vat_main;
1030 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001031
Dave Barach72d72232016-08-04 10:15:08 -04001032 vat_json_init_object (&node);
1033 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1034 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001035
Dave Barach72d72232016-08-04 10:15:08 -04001036 vat_json_print (vam->ofp, &node);
1037 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001038
Dave Barach72d72232016-08-04 10:15:08 -04001039 vam->retval = ntohl (mp->retval);
1040 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001041}
1042
Ed Warnickecb9cada2015-12-08 15:45:58 -07001043static void vl_api_add_node_next_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001044 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045{
Dave Barach72d72232016-08-04 10:15:08 -04001046 vat_main_t *vam = &vat_main;
1047 i32 retval = ntohl (mp->retval);
1048 if (vam->async_mode)
1049 {
1050 vam->async_errors += (retval < 0);
1051 }
1052 else
1053 {
1054 vam->retval = retval;
1055 if (retval == 0)
1056 errmsg ("next index %d\n", ntohl (mp->next_index));
1057 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001058 }
1059}
1060
1061static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001062 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001063{
Dave Barach72d72232016-08-04 10:15:08 -04001064 vat_main_t *vam = &vat_main;
1065 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066
Dave Barach72d72232016-08-04 10:15:08 -04001067 vat_json_init_object (&node);
1068 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1069 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001070
Dave Barach72d72232016-08-04 10:15:08 -04001071 vat_json_print (vam->ofp, &node);
1072 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073
Dave Barach72d72232016-08-04 10:15:08 -04001074 vam->retval = ntohl (mp->retval);
1075 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076}
1077
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001078static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001079 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080{
Dave Barach72d72232016-08-04 10:15:08 -04001081 vat_main_t *vam = &vat_main;
1082 i32 retval = ntohl (mp->retval);
1083 u32 sw_if_index = ntohl (mp->tunnel_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084
Dave Barach72d72232016-08-04 10:15:08 -04001085 if (retval >= 0 && sw_if_index != (u32) ~ 0)
1086 {
1087 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001088 }
Dave Barach72d72232016-08-04 10:15:08 -04001089 vam->retval = retval;
1090 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091}
1092
1093static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001094 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001095{
Dave Barach72d72232016-08-04 10:15:08 -04001096 vat_main_t *vam = &vat_main;
1097 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098
Dave Barach72d72232016-08-04 10:15:08 -04001099 vat_json_init_object (&node);
1100 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1101 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1102 ntohl (mp->tunnel_sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103
Dave Barach72d72232016-08-04 10:15:08 -04001104 vat_json_print (vam->ofp, &node);
1105 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001106
Dave Barach72d72232016-08-04 10:15:08 -04001107 vam->retval = ntohl (mp->retval);
1108 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001109}
1110
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001112static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001113 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001114{
Dave Barach72d72232016-08-04 10:15:08 -04001115 vat_main_t *vam = &vat_main;
1116 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117
Dave Barach72d72232016-08-04 10:15:08 -04001118 if (retval >= 0)
1119 {
1120 errmsg (" program: %s\n", mp->program);
1121 errmsg (" version: %s\n", mp->version);
1122 errmsg (" build date: %s\n", mp->build_date);
1123 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001124 }
Dave Barach72d72232016-08-04 10:15:08 -04001125 vam->retval = retval;
1126 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001127}
1128
1129static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001130 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001131{
Dave Barach72d72232016-08-04 10:15:08 -04001132 vat_main_t *vam = &vat_main;
1133 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134
Dave Barach72d72232016-08-04 10:15:08 -04001135 vat_json_init_object (&node);
1136 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1137 vat_json_object_add_string_copy (&node, "program", mp->program);
1138 vat_json_object_add_string_copy (&node, "version", mp->version);
1139 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1140 vat_json_object_add_string_copy (&node, "build_directory",
1141 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001142
Dave Barach72d72232016-08-04 10:15:08 -04001143 vat_json_print (vam->ofp, &node);
1144 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001145
Dave Barach72d72232016-08-04 10:15:08 -04001146 vam->retval = ntohl (mp->retval);
1147 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001148}
1149
Dave Barach72d72232016-08-04 10:15:08 -04001150static void
1151vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001152{
Dave Barach72d72232016-08-04 10:15:08 -04001153 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001154 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1155 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001156 format_ip4_address, &mp->address,
1157 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001158}
1159
Dave Barach72d72232016-08-04 10:15:08 -04001160static void
1161vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001162{
Dave Barach72d72232016-08-04 10:15:08 -04001163 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001164}
1165
John Lo1edfba92016-08-27 01:11:57 -04001166static void
1167vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1168{
1169 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001170 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1171 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001172 format_ip6_address, mp->address,
1173 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1174}
1175
1176static void
1177vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1178{
1179 /* JSON output not supported */
1180}
1181
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001182/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001183 * Special-case: build the bridge domain table, maintain
1184 * the next bd id vbl.
1185 */
1186static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001187 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001188{
Dave Barach72d72232016-08-04 10:15:08 -04001189 vat_main_t *vam = &vat_main;
1190 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001191
Dave Barach72d72232016-08-04 10:15:08 -04001192 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1193 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
Dave Barach72d72232016-08-04 10:15:08 -04001195 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1196 ntohl (mp->bd_id), mp->learn, mp->forward,
1197 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001198
Dave Barach72d72232016-08-04 10:15:08 -04001199 if (n_sw_ifs)
1200 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1201 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001202}
1203
1204static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001205 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001206{
Dave Barach72d72232016-08-04 10:15:08 -04001207 vat_main_t *vam = &vat_main;
1208 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001209
Dave Barach72d72232016-08-04 10:15:08 -04001210 if (VAT_JSON_ARRAY != vam->json_tree.type)
1211 {
1212 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1213 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214 }
Dave Barach72d72232016-08-04 10:15:08 -04001215 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001216
Dave Barach72d72232016-08-04 10:15:08 -04001217 vat_json_init_object (node);
1218 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1219 vat_json_object_add_uint (node, "flood", mp->flood);
1220 vat_json_object_add_uint (node, "forward", mp->forward);
1221 vat_json_object_add_uint (node, "learn", mp->learn);
1222 vat_json_object_add_uint (node, "bvi_sw_if_index",
1223 ntohl (mp->bvi_sw_if_index));
1224 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1225 array = vat_json_object_add (node, "sw_if");
1226 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001227}
1228
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001229/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001230 * Special-case: build the bridge domain sw if table.
1231 */
1232static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001233 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001234{
Dave Barach72d72232016-08-04 10:15:08 -04001235 vat_main_t *vam = &vat_main;
1236 hash_pair_t *p;
1237 u8 *sw_if_name = 0;
1238 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001239
Dave Barach72d72232016-08-04 10:15:08 -04001240 sw_if_index = ntohl (mp->sw_if_index);
1241 /* *INDENT-OFF* */
1242 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1243 ({
1244 if ((u32) p->value[0] == sw_if_index)
1245 {
1246 sw_if_name = (u8 *)(p->key);
1247 break;
1248 }
1249 }));
1250 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001251
Dave Barach72d72232016-08-04 10:15:08 -04001252 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1253 mp->shg, sw_if_name ? (char *) sw_if_name :
1254 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001255}
1256
1257static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001258 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001259{
Dave Barach72d72232016-08-04 10:15:08 -04001260 vat_main_t *vam = &vat_main;
1261 vat_json_node_t *node = NULL;
1262 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001263
Dave Barach72d72232016-08-04 10:15:08 -04001264 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1265 ASSERT (vec_len (vam->json_tree.array) >= 1);
1266 last_index = vec_len (vam->json_tree.array) - 1;
1267 node = &vam->json_tree.array[last_index];
1268 node = vat_json_object_get_element (node, "sw_if");
1269 ASSERT (NULL != node);
1270 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271
Dave Barach72d72232016-08-04 10:15:08 -04001272 vat_json_init_object (node);
1273 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1274 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1275 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001276}
1277
1278static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001279 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001280{
Dave Barach72d72232016-08-04 10:15:08 -04001281 vat_main_t *vam = &vat_main;
1282 i32 retval = ntohl (mp->retval);
1283 if (vam->async_mode)
1284 {
1285 vam->async_errors += (retval < 0);
1286 }
1287 else
1288 {
1289 vam->retval = retval;
1290 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001291 }
1292}
1293
1294static void vl_api_control_ping_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001295 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001296{
Dave Barach72d72232016-08-04 10:15:08 -04001297 vat_main_t *vam = &vat_main;
1298 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299
Dave Barach72d72232016-08-04 10:15:08 -04001300 if (VAT_JSON_NONE != vam->json_tree.type)
1301 {
1302 vat_json_print (vam->ofp, &vam->json_tree);
1303 vat_json_free (&vam->json_tree);
1304 vam->json_tree.type = VAT_JSON_NONE;
1305 }
1306 else
1307 {
1308 /* just print [] */
1309 vat_json_init_array (&vam->json_tree);
1310 vat_json_print (vam->ofp, &vam->json_tree);
1311 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001312 }
1313
Dave Barach72d72232016-08-04 10:15:08 -04001314 vam->retval = retval;
1315 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001316}
1317
Dave Barach72d72232016-08-04 10:15:08 -04001318static void
1319vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001320{
Dave Barach72d72232016-08-04 10:15:08 -04001321 vat_main_t *vam = &vat_main;
1322 i32 retval = ntohl (mp->retval);
1323 if (vam->async_mode)
1324 {
1325 vam->async_errors += (retval < 0);
1326 }
1327 else
1328 {
1329 vam->retval = retval;
1330 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001331 }
1332}
1333
1334static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001335 (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336{
Dave Barach72d72232016-08-04 10:15:08 -04001337 vat_main_t *vam = &vat_main;
1338 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339
Dave Barach72d72232016-08-04 10:15:08 -04001340 vat_json_init_object (&node);
1341 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1342 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1343 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001344
Dave Barach72d72232016-08-04 10:15:08 -04001345 vat_json_print (vam->ofp, &node);
1346 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001347
Dave Barach72d72232016-08-04 10:15:08 -04001348 vam->retval = ntohl (mp->retval);
1349 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001350}
1351
1352static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001353 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001354{
Dave Barach72d72232016-08-04 10:15:08 -04001355 vat_main_t *vam = &vat_main;
1356 i32 retval = ntohl (mp->retval);
1357 if (vam->async_mode)
1358 {
1359 vam->async_errors += (retval < 0);
1360 }
1361 else
1362 {
1363 vam->retval = retval;
1364 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001365 }
1366}
1367
1368static void vl_api_bridge_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001369 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001370{
Dave Barach72d72232016-08-04 10:15:08 -04001371 vat_main_t *vam = &vat_main;
1372 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001373
Dave Barach72d72232016-08-04 10:15:08 -04001374 vat_json_init_object (&node);
1375 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1376 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1377 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001378
Dave Barach72d72232016-08-04 10:15:08 -04001379 vat_json_print (vam->ofp, &node);
1380 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001381
Dave Barach72d72232016-08-04 10:15:08 -04001382 vam->retval = ntohl (mp->retval);
1383 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001384}
1385
1386static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001387 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001388{
Dave Barach72d72232016-08-04 10:15:08 -04001389 vat_main_t *vam = &vat_main;
1390 i32 retval = ntohl (mp->retval);
1391 if (vam->async_mode)
1392 {
1393 vam->async_errors += (retval < 0);
1394 }
1395 else
1396 {
1397 vam->retval = retval;
1398 vam->sw_if_index = ntohl (mp->sw_if_index);
1399 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001400 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001401
Ed Warnickecb9cada2015-12-08 15:45:58 -07001402}
1403
1404static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001405 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001406{
Dave Barach72d72232016-08-04 10:15:08 -04001407 vat_main_t *vam = &vat_main;
1408 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409
Dave Barach72d72232016-08-04 10:15:08 -04001410 vat_json_init_object (&node);
1411 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1412 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413
Dave Barach72d72232016-08-04 10:15:08 -04001414 vat_json_print (vam->ofp, &node);
1415 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001416
Dave Barach72d72232016-08-04 10:15:08 -04001417 vam->retval = ntohl (mp->retval);
1418 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001419
Ed Warnickecb9cada2015-12-08 15:45:58 -07001420}
1421
Dave Barach72d72232016-08-04 10:15:08 -04001422static void
1423vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424{
Dave Barach72d72232016-08-04 10:15:08 -04001425 vat_main_t *vam = &vat_main;
1426 i32 retval = ntohl (mp->retval);
1427 if (vam->async_mode)
1428 {
1429 vam->async_errors += (retval < 0);
1430 }
1431 else
1432 {
1433 vam->retval = retval;
1434 vam->sw_if_index = ntohl (mp->sw_if_index);
1435 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001436 }
1437}
1438
1439static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001440 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001441{
Dave Barach72d72232016-08-04 10:15:08 -04001442 vat_main_t *vam = &vat_main;
1443 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001444
Dave Barach72d72232016-08-04 10:15:08 -04001445 vat_json_init_object (&node);
1446 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1447 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001448
Dave Barach72d72232016-08-04 10:15:08 -04001449 vat_json_print (vam->ofp, &node);
1450 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001451
Dave Barach72d72232016-08-04 10:15:08 -04001452 vam->retval = ntohl (mp->retval);
1453 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001454}
1455
Dave Barach72d72232016-08-04 10:15:08 -04001456static void
1457vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001458{
Dave Barach72d72232016-08-04 10:15:08 -04001459 vat_main_t *vam = &vat_main;
1460 i32 retval = ntohl (mp->retval);
1461 if (vam->async_mode)
1462 {
1463 vam->async_errors += (retval < 0);
1464 }
1465 else
1466 {
1467 vam->retval = retval;
1468 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469 }
1470}
1471
1472static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001473 (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001474{
Dave Barach72d72232016-08-04 10:15:08 -04001475 vat_main_t *vam = &vat_main;
1476 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001477
Dave Barach72d72232016-08-04 10:15:08 -04001478 vat_json_init_object (&node);
1479 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001480
Dave Barach72d72232016-08-04 10:15:08 -04001481 vat_json_print (vam->ofp, &node);
1482 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001483
Dave Barach72d72232016-08-04 10:15:08 -04001484 vam->retval = ntohl (mp->retval);
1485 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001486}
1487
1488static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001489 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001490{
Dave Barach72d72232016-08-04 10:15:08 -04001491 vat_main_t *vam = &vat_main;
1492 i32 retval = ntohl (mp->retval);
1493 if (vam->async_mode)
1494 {
1495 vam->async_errors += (retval < 0);
1496 }
1497 else
1498 {
1499 vam->retval = retval;
1500 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001501 }
1502}
1503
1504static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001505 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001506{
Dave Barach72d72232016-08-04 10:15:08 -04001507 vat_main_t *vam = &vat_main;
1508 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001509
Dave Barach72d72232016-08-04 10:15:08 -04001510 vat_json_init_object (&node);
1511 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1512 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1513 ntohl (mp->tunnel_sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001514
Dave Barach72d72232016-08-04 10:15:08 -04001515 vat_json_print (vam->ofp, &node);
1516 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001517
Dave Barach72d72232016-08-04 10:15:08 -04001518 vam->retval = ntohl (mp->retval);
1519 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001520}
1521
1522static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001523 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001524{
Dave Barach72d72232016-08-04 10:15:08 -04001525 vat_main_t *vam = &vat_main;
1526 i32 retval = ntohl (mp->retval);
1527 if (vam->async_mode)
1528 {
1529 vam->async_errors += (retval < 0);
1530 }
1531 else
1532 {
1533 vam->retval = retval;
1534 vam->sw_if_index = ntohl (mp->sw_if_index);
1535 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001536 }
1537}
1538
1539static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001540 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001541{
Dave Barach72d72232016-08-04 10:15:08 -04001542 vat_main_t *vam = &vat_main;
1543 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001544
Dave Barach72d72232016-08-04 10:15:08 -04001545 vat_json_init_object (&node);
1546 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1547 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001548
Dave Barach72d72232016-08-04 10:15:08 -04001549 vat_json_print (vam->ofp, &node);
1550 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001551
Dave Barach72d72232016-08-04 10:15:08 -04001552 vam->retval = ntohl (mp->retval);
1553 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001554}
1555
Filip Tehlar3a834602016-08-11 12:21:37 +02001556
1557static void vl_api_lisp_add_del_locator_set_reply_t_handler
1558 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1559{
1560 vat_main_t *vam = &vat_main;
1561 i32 retval = ntohl (mp->retval);
1562 if (vam->async_mode)
1563 {
1564 vam->async_errors += (retval < 0);
1565 }
1566 else
1567 {
1568 vam->retval = retval;
1569 vam->result_ready = 1;
1570 }
1571}
1572
1573static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1574 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1575{
1576 vat_main_t *vam = &vat_main;
1577 vat_json_node_t node;
1578
1579 vat_json_init_object (&node);
1580 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1581 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1582
1583 vat_json_print (vam->ofp, &node);
1584 vat_json_free (&node);
1585
1586 vam->retval = ntohl (mp->retval);
1587 vam->result_ready = 1;
1588}
1589
Ed Warnickecb9cada2015-12-08 15:45:58 -07001590static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001591 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001592{
Dave Barach72d72232016-08-04 10:15:08 -04001593 vat_main_t *vam = &vat_main;
1594 i32 retval = ntohl (mp->retval);
1595 if (vam->async_mode)
1596 {
1597 vam->async_errors += (retval < 0);
1598 }
1599 else
1600 {
1601 vam->retval = retval;
1602 vam->sw_if_index = ntohl (mp->sw_if_index);
1603 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001604 }
1605}
1606
1607static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001608 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001609{
Dave Barach72d72232016-08-04 10:15:08 -04001610 vat_main_t *vam = &vat_main;
1611 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001612
Dave Barach72d72232016-08-04 10:15:08 -04001613 vat_json_init_object (&node);
1614 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1615 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001616
Dave Barach72d72232016-08-04 10:15:08 -04001617 vat_json_print (vam->ofp, &node);
1618 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001619
Dave Barach72d72232016-08-04 10:15:08 -04001620 vam->retval = ntohl (mp->retval);
1621 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001622}
1623
Chris Luke27fe48f2016-04-28 13:44:38 -04001624static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001625 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001626{
Dave Barach72d72232016-08-04 10:15:08 -04001627 vat_main_t *vam = &vat_main;
1628 i32 retval = ntohl (mp->retval);
1629 if (vam->async_mode)
1630 {
1631 vam->async_errors += (retval < 0);
1632 }
1633 else
1634 {
1635 vam->retval = retval;
1636 vam->sw_if_index = ntohl (mp->sw_if_index);
1637 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001638 }
1639}
1640
1641static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001642 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001643{
Dave Barach72d72232016-08-04 10:15:08 -04001644 vat_main_t *vam = &vat_main;
1645 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001646
Dave Barach72d72232016-08-04 10:15:08 -04001647 vat_json_init_object (&node);
1648 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1649 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001650
Dave Barach72d72232016-08-04 10:15:08 -04001651 vat_json_print (vam->ofp, &node);
1652 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001653
Dave Barach72d72232016-08-04 10:15:08 -04001654 vam->retval = ntohl (mp->retval);
1655 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001656}
1657
Ed Warnickecb9cada2015-12-08 15:45:58 -07001658static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001659 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001660{
Dave Barach72d72232016-08-04 10:15:08 -04001661 vat_main_t *vam = &vat_main;
1662 i32 retval = ntohl (mp->retval);
1663 if (vam->async_mode)
1664 {
1665 vam->async_errors += (retval < 0);
1666 }
1667 else
1668 {
1669 vam->retval = retval;
1670 vam->sw_if_index = ntohl (mp->sw_if_index);
1671 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672 }
1673}
1674
1675static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001676 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677{
Dave Barach72d72232016-08-04 10:15:08 -04001678 vat_main_t *vam = &vat_main;
1679 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001680
Dave Barach72d72232016-08-04 10:15:08 -04001681 vat_json_init_object (&node);
1682 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1683 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001684
Dave Barach72d72232016-08-04 10:15:08 -04001685 vat_json_print (vam->ofp, &node);
1686 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barach72d72232016-08-04 10:15:08 -04001688 vam->retval = ntohl (mp->retval);
1689 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001690}
1691
1692static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001693 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001694{
Dave Barach72d72232016-08-04 10:15:08 -04001695 vat_main_t *vam = &vat_main;
1696 static ip_address_details_t empty_ip_address_details = { {0} };
1697 ip_address_details_t *address = NULL;
1698 ip_details_t *current_ip_details = NULL;
1699 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700
Dave Barach72d72232016-08-04 10:15:08 -04001701 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001702
Dave Barach72d72232016-08-04 10:15:08 -04001703 if (!details || vam->current_sw_if_index >= vec_len (details)
1704 || !details[vam->current_sw_if_index].present)
1705 {
1706 errmsg ("ip address details arrived but not stored\n");
1707 errmsg ("ip_dump should be called first\n");
1708 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001709 }
1710
Dave Barach72d72232016-08-04 10:15:08 -04001711 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001712
1713#define addresses (current_ip_details->addr)
1714
Dave Barach72d72232016-08-04 10:15:08 -04001715 vec_validate_init_empty (addresses, vec_len (addresses),
1716 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001717
Dave Barach72d72232016-08-04 10:15:08 -04001718 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001719
Dave Barach72d72232016-08-04 10:15:08 -04001720 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1721 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001722#undef addresses
1723}
1724
1725static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001726 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001727{
Dave Barach72d72232016-08-04 10:15:08 -04001728 vat_main_t *vam = &vat_main;
1729 vat_json_node_t *node = NULL;
1730 struct in6_addr ip6;
1731 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001732
Dave Barach72d72232016-08-04 10:15:08 -04001733 if (VAT_JSON_ARRAY != vam->json_tree.type)
1734 {
1735 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1736 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001737 }
Dave Barach72d72232016-08-04 10:15:08 -04001738 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001739
Dave Barach72d72232016-08-04 10:15:08 -04001740 vat_json_init_object (node);
1741 if (vam->is_ipv6)
1742 {
1743 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1744 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001745 }
Dave Barach72d72232016-08-04 10:15:08 -04001746 else
1747 {
1748 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1749 vat_json_object_add_ip4 (node, "ip", ip4);
1750 }
1751 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001752}
1753
Dave Barach72d72232016-08-04 10:15:08 -04001754static void
1755vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001756{
Dave Barach72d72232016-08-04 10:15:08 -04001757 vat_main_t *vam = &vat_main;
1758 static ip_details_t empty_ip_details = { 0 };
1759 ip_details_t *ip = NULL;
1760 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001761
Dave Barach72d72232016-08-04 10:15:08 -04001762 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001763
Dave Barach72d72232016-08-04 10:15:08 -04001764 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1765 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001766
Dave Barach72d72232016-08-04 10:15:08 -04001767 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1768 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001769
Dave Barach72d72232016-08-04 10:15:08 -04001770 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001771}
1772
Dave Barach72d72232016-08-04 10:15:08 -04001773static void
1774vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001775{
Dave Barach72d72232016-08-04 10:15:08 -04001776 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001777
Dave Barach72d72232016-08-04 10:15:08 -04001778 if (VAT_JSON_ARRAY != vam->json_tree.type)
1779 {
1780 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1781 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001782 }
Dave Barach72d72232016-08-04 10:15:08 -04001783 vat_json_array_add_uint (&vam->json_tree,
1784 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001785}
1786
1787static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001788 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001789{
Dave Barach72d72232016-08-04 10:15:08 -04001790 vat_json_node_t *node = NULL;
1791 vat_main_t *vam = &vat_main;
1792 struct in6_addr ip6;
1793 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001794
Dave Barach72d72232016-08-04 10:15:08 -04001795 if (VAT_JSON_ARRAY != vam->json_tree.type)
1796 {
1797 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1798 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001799 }
1800
Dave Barach72d72232016-08-04 10:15:08 -04001801 node = vat_json_array_add (&vam->json_tree);
1802 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001803
Dave Barach72d72232016-08-04 10:15:08 -04001804 vat_json_object_add_uint (node, "domain_index",
1805 clib_net_to_host_u32 (mp->domain_index));
1806 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1807 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1808 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1809 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1810 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1811 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1812 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1813 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1814 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1815 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1816 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1817 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1818 vat_json_object_add_uint (node, "flags", mp->flags);
1819 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1820 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001821}
1822
1823static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001824 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825{
Dave Barach72d72232016-08-04 10:15:08 -04001826 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001827
Dave Barach72d72232016-08-04 10:15:08 -04001828 if (mp->is_translation)
1829 {
1830 fformat (vam->ofp,
1831 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1832 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1833 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1834 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1835 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001836 }
Dave Barach72d72232016-08-04 10:15:08 -04001837 else
1838 {
1839 fformat (vam->ofp,
1840 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1841 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1842 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1843 format_ip6_address, mp->ip6_src,
1844 clib_net_to_host_u32 (mp->domain_index));
1845 }
1846 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1847 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1848 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849}
1850
1851static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001852 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001853{
Dave Barach72d72232016-08-04 10:15:08 -04001854 struct in6_addr ip6;
1855 vat_json_node_t *node = NULL;
1856 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001857
Dave Barach72d72232016-08-04 10:15:08 -04001858 if (VAT_JSON_ARRAY != vam->json_tree.type)
1859 {
1860 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1861 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001862 }
1863
Dave Barach72d72232016-08-04 10:15:08 -04001864 node = vat_json_array_add (&vam->json_tree);
1865 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001866
Dave Barach72d72232016-08-04 10:15:08 -04001867 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1868 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1869 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870}
1871
Dave Barach72d72232016-08-04 10:15:08 -04001872static void
1873vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001874{
Dave Barach72d72232016-08-04 10:15:08 -04001875 vat_main_t *vam = &vat_main;
1876 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1877 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001878}
1879
Dave Barach72d72232016-08-04 10:15:08 -04001880static void
1881vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001882{
Dave Barach72d72232016-08-04 10:15:08 -04001883 vat_main_t *vam = &vat_main;
1884 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1885 "router_addr %U host_mac %U\n",
1886 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1887 format_ip4_address, &mp->host_address,
1888 format_ip4_address, &mp->router_address,
1889 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001890}
1891
1892static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001893 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001894{
Dave Barach72d72232016-08-04 10:15:08 -04001895 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001896}
1897
Dave Barach72d72232016-08-04 10:15:08 -04001898static void
1899set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1900 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001901{
Dave Barach72d72232016-08-04 10:15:08 -04001902 vat_main_t *vam = &vat_main;
1903 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001904
Dave Barach72d72232016-08-04 10:15:08 -04001905 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1906 NULL);
1907 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1908 sw_if_index, default_counter);
1909 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001910}
1911
Dave Barach72d72232016-08-04 10:15:08 -04001912static void
1913set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1914 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001915{
Dave Barach72d72232016-08-04 10:15:08 -04001916 vat_main_t *vam = &vat_main;
1917 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001918
Dave Barach72d72232016-08-04 10:15:08 -04001919 vec_validate_init_empty (vam->combined_interface_counters,
1920 vnet_counter_type, NULL);
1921 vec_validate_init_empty (vam->combined_interface_counters
1922 [vnet_counter_type], sw_if_index, default_counter);
1923 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001924}
1925
1926static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001927 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001928{
Dave Barach72d72232016-08-04 10:15:08 -04001929 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001930}
1931
1932static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001933 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001934{
Dave Barach72d72232016-08-04 10:15:08 -04001935 interface_counter_t counter;
1936 vlib_counter_t *v;
1937 u64 *v_packets;
1938 u64 packets;
1939 u32 count;
1940 u32 first_sw_if_index;
1941 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001942
Dave Barach72d72232016-08-04 10:15:08 -04001943 count = ntohl (mp->count);
1944 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001945
Dave Barach72d72232016-08-04 10:15:08 -04001946 if (!mp->is_combined)
1947 {
1948 v_packets = (u64 *) & mp->data;
1949 for (i = 0; i < count; i++)
1950 {
1951 packets =
1952 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1953 set_simple_interface_counter (mp->vnet_counter_type,
1954 first_sw_if_index + i, packets);
1955 v_packets++;
1956 }
1957 }
1958 else
1959 {
1960 v = (vlib_counter_t *) & mp->data;
1961 for (i = 0; i < count; i++)
1962 {
1963 counter.packets =
1964 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1965 counter.bytes =
1966 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1967 set_combined_interface_counter (mp->vnet_counter_type,
1968 first_sw_if_index + i, counter);
1969 v++;
1970 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001971 }
1972}
1973
Dave Barach72d72232016-08-04 10:15:08 -04001974static u32
1975ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001976{
Dave Barach72d72232016-08-04 10:15:08 -04001977 vat_main_t *vam = &vat_main;
1978 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001979
Dave Barach72d72232016-08-04 10:15:08 -04001980 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1981 {
1982 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1983 {
1984 return i;
1985 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001986 }
Dave Barach72d72232016-08-04 10:15:08 -04001987 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001988}
1989
Dave Barach72d72232016-08-04 10:15:08 -04001990static u32
1991ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001992{
Dave Barach72d72232016-08-04 10:15:08 -04001993 vat_main_t *vam = &vat_main;
1994 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001995
Dave Barach72d72232016-08-04 10:15:08 -04001996 for (i = 0; i < vec_len (vam->ip6_fib_counters_vrf_id_by_index); i++)
1997 {
1998 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id)
1999 {
2000 return i;
2001 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002002 }
Dave Barach72d72232016-08-04 10:15:08 -04002003 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002004}
2005
2006static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002007 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002008{
Dave Barach72d72232016-08-04 10:15:08 -04002009 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010}
2011
2012static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002013 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014{
Dave Barach72d72232016-08-04 10:15:08 -04002015 vat_main_t *vam = &vat_main;
2016 vl_api_ip4_fib_counter_t *v;
2017 ip4_fib_counter_t *counter;
2018 struct in_addr ip4;
2019 u32 vrf_id;
2020 u32 vrf_index;
2021 u32 count;
2022 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002023
Dave Barach72d72232016-08-04 10:15:08 -04002024 vrf_id = ntohl (mp->vrf_id);
2025 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2026 if (~0 == vrf_index)
2027 {
2028 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
2029 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
2030 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2031 vec_validate (vam->ip4_fib_counters, vrf_index);
2032 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002033 }
2034
Dave Barach72d72232016-08-04 10:15:08 -04002035 vec_free (vam->ip4_fib_counters[vrf_index]);
2036 v = (vl_api_ip4_fib_counter_t *) & mp->c;
2037 count = ntohl (mp->count);
2038 for (i = 0; i < count; i++)
2039 {
2040 vec_validate (vam->ip4_fib_counters[vrf_index], i);
2041 counter = &vam->ip4_fib_counters[vrf_index][i];
2042 clib_memcpy (&ip4, &v->address, sizeof (ip4));
2043 counter->address = ip4;
2044 counter->address_length = v->address_length;
2045 counter->packets = clib_net_to_host_u64 (v->packets);
2046 counter->bytes = clib_net_to_host_u64 (v->bytes);
2047 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002048 }
2049}
2050
2051static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002052 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053{
Dave Barach72d72232016-08-04 10:15:08 -04002054 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002055}
2056
2057static void vl_api_vnet_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002058 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002059{
Dave Barach72d72232016-08-04 10:15:08 -04002060 vat_main_t *vam = &vat_main;
2061 vl_api_ip6_fib_counter_t *v;
2062 ip6_fib_counter_t *counter;
2063 struct in6_addr ip6;
2064 u32 vrf_id;
2065 u32 vrf_index;
2066 u32 count;
2067 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002068
Dave Barach72d72232016-08-04 10:15:08 -04002069 vrf_id = ntohl (mp->vrf_id);
2070 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2071 if (~0 == vrf_index)
2072 {
2073 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2074 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2075 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2076 vec_validate (vam->ip6_fib_counters, vrf_index);
2077 vam->ip6_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002078 }
2079
Dave Barach72d72232016-08-04 10:15:08 -04002080 vec_free (vam->ip6_fib_counters[vrf_index]);
2081 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2082 count = ntohl (mp->count);
2083 for (i = 0; i < count; i++)
2084 {
2085 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2086 counter = &vam->ip6_fib_counters[vrf_index][i];
2087 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2088 counter->address = ip6;
2089 counter->address_length = v->address_length;
2090 counter->packets = clib_net_to_host_u64 (v->packets);
2091 counter->bytes = clib_net_to_host_u64 (v->bytes);
2092 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002093 }
2094}
2095
2096static void vl_api_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002097 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002098{
Dave Barach72d72232016-08-04 10:15:08 -04002099 vat_main_t *vam = &vat_main;
2100 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002101
Dave Barach72d72232016-08-04 10:15:08 -04002102 if (vam->async_mode)
2103 {
2104 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002105 }
Dave Barach72d72232016-08-04 10:15:08 -04002106 else
2107 {
2108 vam->retval = retval;
2109 vam->result_ready = 1;
2110 }
2111 if (retval >= 0)
2112 {
2113 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002114 }
2115}
2116
2117static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002118 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002119{
Dave Barach72d72232016-08-04 10:15:08 -04002120 vat_main_t *vam = &vat_main;
2121 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002122
Dave Barach72d72232016-08-04 10:15:08 -04002123 vat_json_init_object (&node);
2124 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2125 vat_json_object_add_uint (&node, "first_msg_id",
2126 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002127
Dave Barach72d72232016-08-04 10:15:08 -04002128 vat_json_print (vam->ofp, &node);
2129 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002130
Dave Barach72d72232016-08-04 10:15:08 -04002131 vam->retval = ntohl (mp->retval);
2132 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002133}
2134
Dave Barachb44e9bc2016-02-19 09:06:23 -05002135static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002136 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002137{
Dave Barach72d72232016-08-04 10:15:08 -04002138 vat_main_t *vam = &vat_main;
2139 api_main_t *am = &api_main;
2140 i32 retval = ntohl (mp->retval);
2141 u8 *pvt_copy, *reply;
2142 void *oldheap;
2143 vlib_node_t *node;
2144 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002145
Dave Barach72d72232016-08-04 10:15:08 -04002146 if (vam->async_mode)
2147 {
2148 vam->async_errors += (retval < 0);
2149 }
2150 else
2151 {
2152 vam->retval = retval;
2153 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002154 }
2155
Dave Barach72d72232016-08-04 10:15:08 -04002156 /* "Should never happen..." */
2157 if (retval != 0)
2158 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002159
Dave Barach72d72232016-08-04 10:15:08 -04002160 reply = (u8 *) (mp->reply_in_shmem);
2161 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002162
Dave Barach72d72232016-08-04 10:15:08 -04002163 /* Toss the shared-memory original... */
2164 pthread_mutex_lock (&am->vlib_rp->mutex);
2165 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002166
Dave Barach72d72232016-08-04 10:15:08 -04002167 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002168
Dave Barach72d72232016-08-04 10:15:08 -04002169 svm_pop_heap (oldheap);
2170 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002171
Dave Barach72d72232016-08-04 10:15:08 -04002172 if (vam->graph_nodes)
2173 {
2174 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002175
Dave Barach72d72232016-08-04 10:15:08 -04002176 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2177 {
2178 node = vam->graph_nodes[i];
2179 vec_free (node->name);
2180 vec_free (node->next_nodes);
2181 vec_free (node);
2182 }
2183 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002184 }
2185
Dave Barach72d72232016-08-04 10:15:08 -04002186 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2187 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2188 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002189
Dave Barach72d72232016-08-04 10:15:08 -04002190 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2191 {
2192 node = vam->graph_nodes[i];
2193 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002194 }
2195}
2196
2197static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002198 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002199{
Dave Barach72d72232016-08-04 10:15:08 -04002200 vat_main_t *vam = &vat_main;
2201 api_main_t *am = &api_main;
2202 void *oldheap;
2203 vat_json_node_t node;
2204 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002205
Dave Barach72d72232016-08-04 10:15:08 -04002206 /* $$$$ make this real? */
2207 vat_json_init_object (&node);
2208 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2209 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002210
Dave Barach72d72232016-08-04 10:15:08 -04002211 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002212
Dave Barach72d72232016-08-04 10:15:08 -04002213 /* Toss the shared-memory original... */
2214 pthread_mutex_lock (&am->vlib_rp->mutex);
2215 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002216
Dave Barach72d72232016-08-04 10:15:08 -04002217 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002218
Dave Barach72d72232016-08-04 10:15:08 -04002219 svm_pop_heap (oldheap);
2220 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002221
Dave Barach72d72232016-08-04 10:15:08 -04002222 vat_json_print (vam->ofp, &node);
2223 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002224
Dave Barach72d72232016-08-04 10:15:08 -04002225 vam->retval = ntohl (mp->retval);
2226 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002227}
2228
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002229static void
Dave Barach72d72232016-08-04 10:15:08 -04002230vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002231{
Dave Barach72d72232016-08-04 10:15:08 -04002232 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002233 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002234
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002235 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002236 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002237 s = format (s, "%=16d%=16d%=16d\n",
2238 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002239 }
2240 else
2241 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002242 s = format (s, "%=16U%=16d%=16d\n",
2243 mp->is_ipv6 ? format_ip6_address :
2244 format_ip4_address,
2245 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002246 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002247
2248 fformat (vam->ofp, "%v", s);
2249 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002250}
2251
2252static void
Dave Barach72d72232016-08-04 10:15:08 -04002253vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2254 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002255{
Dave Barach72d72232016-08-04 10:15:08 -04002256 vat_main_t *vam = &vat_main;
2257 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002258 struct in6_addr ip6;
2259 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002260
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002261 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002262 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002263 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2264 vat_json_init_array (&vam->json_tree);
2265 }
2266 node = vat_json_array_add (&vam->json_tree);
2267 vat_json_init_object (node);
2268
2269 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2270 vat_json_object_add_uint (node, "priority", mp->priority);
2271 vat_json_object_add_uint (node, "weight", mp->weight);
2272
2273 if (mp->local)
2274 vat_json_object_add_uint (node, "sw_if_index",
2275 clib_net_to_host_u32 (mp->sw_if_index));
2276 else
2277 {
2278 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002279 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002280 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2281 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002282 }
2283 else
2284 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002285 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2286 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002287 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002288 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002289}
2290
2291static void
2292vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2293 mp)
2294{
2295 vat_main_t *vam = &vat_main;
2296 u8 *ls_name = 0;
2297
2298 ls_name = format (0, "%s", mp->ls_name);
2299
2300 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2301 ls_name);
2302 vec_free (ls_name);
2303}
2304
2305static void
2306 vl_api_lisp_locator_set_details_t_handler_json
2307 (vl_api_lisp_locator_set_details_t * mp)
2308{
2309 vat_main_t *vam = &vat_main;
2310 vat_json_node_t *node = 0;
2311 u8 *ls_name = 0;
2312
2313 ls_name = format (0, "%s", mp->ls_name);
2314 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002315
Dave Barach72d72232016-08-04 10:15:08 -04002316 if (VAT_JSON_ARRAY != vam->json_tree.type)
2317 {
2318 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2319 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002320 }
Dave Barach72d72232016-08-04 10:15:08 -04002321 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002322
Dave Barach72d72232016-08-04 10:15:08 -04002323 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002324 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2325 vat_json_object_add_uint (node, "ls_index",
2326 clib_net_to_host_u32 (mp->ls_index));
2327 vec_free (ls_name);
2328}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002329
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002330static u8 *
2331format_lisp_flat_eid (u8 * s, va_list * args)
2332{
2333 u32 type = va_arg (*args, u32);
2334 u8 *eid = va_arg (*args, u8 *);
2335 u32 eid_len = va_arg (*args, u32);
2336
2337 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002338 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002339 case 0:
2340 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2341 case 1:
2342 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2343 case 2:
2344 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002345 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002346 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002347}
2348
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002349static u8 *
2350format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002351{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002352 u32 type = va_arg (*args, u32);
2353 u8 *eid = va_arg (*args, u8 *);
2354 u32 eid_len = va_arg (*args, u32);
2355 u8 *seid = va_arg (*args, u8 *);
2356 u32 seid_len = va_arg (*args, u32);
2357 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002358
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002359 if (is_src_dst)
2360 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002361
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002362 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002363
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002364 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002365}
2366
2367static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002368vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2369{
2370 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002371 u8 *s = 0, *eid = 0;
2372
2373 if (~0 == mp->locator_set_index)
2374 s = format (0, "action: %d", mp->action);
2375 else
2376 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2377
2378 eid = format (0, "%U", format_lisp_eid_vat,
2379 mp->eid_type,
2380 mp->eid,
2381 mp->eid_prefix_len,
2382 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2383 vec_add1 (eid, 0);
2384
2385 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-d\n",
2386 clib_net_to_host_u32 (mp->vni),
2387 eid,
2388 mp->is_local ? "local" : "remote",
2389 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative);
2390 vec_free (s);
2391 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002392}
2393
2394static void
Dave Barach72d72232016-08-04 10:15:08 -04002395vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2396 * mp)
2397{
2398 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002399 vat_json_node_t *node = 0;
2400 u8 *eid = 0;
2401
2402 if (VAT_JSON_ARRAY != vam->json_tree.type)
2403 {
2404 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2405 vat_json_init_array (&vam->json_tree);
2406 }
2407 node = vat_json_array_add (&vam->json_tree);
2408
2409 vat_json_init_object (node);
2410 if (~0 == mp->locator_set_index)
2411 vat_json_object_add_uint (node, "action", mp->action);
2412 else
2413 vat_json_object_add_uint (node, "locator_set_index",
2414 clib_net_to_host_u32 (mp->locator_set_index));
2415
2416 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2417 eid = format (0, "%U", format_lisp_eid_vat,
2418 mp->eid_type,
2419 mp->eid,
2420 mp->eid_prefix_len,
2421 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2422 vec_add1 (eid, 0);
2423 vat_json_object_add_string_copy (node, "eid", eid);
2424 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2425 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2426 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
2427 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002428}
2429
2430static void
2431 vl_api_lisp_eid_table_map_details_t_handler
2432 (vl_api_lisp_eid_table_map_details_t * mp)
2433{
2434 vat_main_t *vam = &vat_main;
2435
2436 u8 *line = format (0, "%=10d%=10d",
2437 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002438 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002439 fformat (vam->ofp, "%v\n", line);
2440 vec_free (line);
2441}
2442
2443static void
2444 vl_api_lisp_eid_table_map_details_t_handler_json
2445 (vl_api_lisp_eid_table_map_details_t * mp)
2446{
2447 vat_main_t *vam = &vat_main;
2448 vat_json_node_t *node = NULL;
2449
2450 if (VAT_JSON_ARRAY != vam->json_tree.type)
2451 {
2452 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2453 vat_json_init_array (&vam->json_tree);
2454 }
2455 node = vat_json_array_add (&vam->json_tree);
2456 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002457 vat_json_object_add_uint (node, "dp_table",
2458 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002459 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002460}
2461
Filip Tehlar50a4e142016-08-24 11:28:02 +02002462static void
2463 vl_api_lisp_eid_table_vni_details_t_handler
2464 (vl_api_lisp_eid_table_vni_details_t * mp)
2465{
2466 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002467
Filip Tehlar50a4e142016-08-24 11:28:02 +02002468 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2469 fformat (vam->ofp, "%v\n", line);
2470 vec_free (line);
2471}
2472
2473static void
2474 vl_api_lisp_eid_table_vni_details_t_handler_json
2475 (vl_api_lisp_eid_table_vni_details_t * mp)
2476{
2477 vat_main_t *vam = &vat_main;
2478 vat_json_node_t *node = NULL;
2479
2480 if (VAT_JSON_ARRAY != vam->json_tree.type)
2481 {
2482 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2483 vat_json_init_array (&vam->json_tree);
2484 }
2485 node = vat_json_array_add (&vam->json_tree);
2486 vat_json_init_object (node);
2487 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2488}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002489
2490static u8 *
2491format_decap_next (u8 * s, va_list * args)
2492{
2493 u32 next_index = va_arg (*args, u32);
2494
2495 switch (next_index)
2496 {
2497 case LISP_GPE_INPUT_NEXT_DROP:
2498 return format (s, "drop");
2499 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2500 return format (s, "ip4");
2501 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2502 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002503 default:
2504 return format (s, "unknown %d", next_index);
2505 }
2506 return s;
2507}
2508
2509static void
Dave Barach72d72232016-08-04 10:15:08 -04002510vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2511 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002512{
Dave Barach72d72232016-08-04 10:15:08 -04002513 vat_main_t *vam = &vat_main;
2514 u8 *iid_str;
2515 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002516
Dave Barach72d72232016-08-04 10:15:08 -04002517 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002518
2519#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2520 foreach_lisp_gpe_flag_bit;
2521#undef _
2522
Dave Barach72d72232016-08-04 10:15:08 -04002523 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2524 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2525 mp->tunnels,
2526 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2527 mp->source_ip,
2528 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2529 mp->destination_ip,
2530 ntohl (mp->encap_fib_id),
2531 ntohl (mp->decap_fib_id),
2532 format_decap_next, ntohl (mp->dcap_next),
2533 mp->ver_res >> 6,
2534 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002535
Dave Barach72d72232016-08-04 10:15:08 -04002536 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002537}
2538
2539static void
Dave Barach72d72232016-08-04 10:15:08 -04002540 vl_api_lisp_gpe_tunnel_details_t_handler_json
2541 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002542{
Dave Barach72d72232016-08-04 10:15:08 -04002543 vat_main_t *vam = &vat_main;
2544 vat_json_node_t *node = NULL;
2545 struct in6_addr ip6;
2546 struct in_addr ip4;
2547 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002548
Dave Barach72d72232016-08-04 10:15:08 -04002549 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002550
Dave Barach72d72232016-08-04 10:15:08 -04002551 if (VAT_JSON_ARRAY != vam->json_tree.type)
2552 {
2553 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2554 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002555 }
Dave Barach72d72232016-08-04 10:15:08 -04002556 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002557
Dave Barach72d72232016-08-04 10:15:08 -04002558 vat_json_init_object (node);
2559 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2560 if (mp->is_ipv6)
2561 {
2562 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2563 vat_json_object_add_ip6 (node, "source address", ip6);
2564 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2565 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002566 }
Dave Barach72d72232016-08-04 10:15:08 -04002567 else
2568 {
2569 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2570 vat_json_object_add_ip4 (node, "source address", ip4);
2571 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2572 vat_json_object_add_ip4 (node, "destination address", ip4);
2573 }
2574 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2575 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2576 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2577 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2578 vat_json_object_add_uint (node, "flags", mp->flags);
2579 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2580 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2581 vat_json_object_add_uint (node, "res", mp->res);
2582 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002583
Dave Barach72d72232016-08-04 10:15:08 -04002584 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002585}
2586
2587static void
Dave Barach72d72232016-08-04 10:15:08 -04002588vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2589 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002590{
Dave Barach72d72232016-08-04 10:15:08 -04002591 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002592
Dave Barach72d72232016-08-04 10:15:08 -04002593 fformat (vam->ofp, "%=20U\n",
2594 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2595 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002596}
2597
2598static void
Dave Barach72d72232016-08-04 10:15:08 -04002599 vl_api_lisp_map_resolver_details_t_handler_json
2600 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002601{
Dave Barach72d72232016-08-04 10:15:08 -04002602 vat_main_t *vam = &vat_main;
2603 vat_json_node_t *node = NULL;
2604 struct in6_addr ip6;
2605 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002606
Dave Barach72d72232016-08-04 10:15:08 -04002607 if (VAT_JSON_ARRAY != vam->json_tree.type)
2608 {
2609 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2610 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002611 }
Dave Barach72d72232016-08-04 10:15:08 -04002612 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002613
Dave Barach72d72232016-08-04 10:15:08 -04002614 vat_json_init_object (node);
2615 if (mp->is_ipv6)
2616 {
2617 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2618 vat_json_object_add_ip6 (node, "map resolver", ip6);
2619 }
2620 else
2621 {
2622 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2623 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002624 }
2625}
2626
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002627static void
Dave Barach72d72232016-08-04 10:15:08 -04002628 vl_api_show_lisp_status_reply_t_handler
2629 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002630{
Dave Barach72d72232016-08-04 10:15:08 -04002631 vat_main_t *vam = &vat_main;
2632 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002633
Dave Barach72d72232016-08-04 10:15:08 -04002634 if (0 <= retval)
2635 {
2636 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2637 mp->feature_status ? "enabled" : "disabled",
2638 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002639 }
2640
Dave Barach72d72232016-08-04 10:15:08 -04002641 vam->retval = retval;
2642 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002643}
2644
2645static void
Dave Barach72d72232016-08-04 10:15:08 -04002646 vl_api_show_lisp_status_reply_t_handler_json
2647 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002648{
Dave Barach72d72232016-08-04 10:15:08 -04002649 vat_main_t *vam = &vat_main;
2650 vat_json_node_t node;
2651 u8 *gpe_status = NULL;
2652 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002653
Dave Barach72d72232016-08-04 10:15:08 -04002654 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2655 feature_status = format (0, "%s",
2656 mp->feature_status ? "enabled" : "disabled");
2657 vec_add1 (gpe_status, 0);
2658 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002659
Dave Barach72d72232016-08-04 10:15:08 -04002660 vat_json_init_object (&node);
2661 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2662 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002663
Dave Barach72d72232016-08-04 10:15:08 -04002664 vec_free (gpe_status);
2665 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002666
Dave Barach72d72232016-08-04 10:15:08 -04002667 vat_json_print (vam->ofp, &node);
2668 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002669
Dave Barach72d72232016-08-04 10:15:08 -04002670 vam->retval = ntohl (mp->retval);
2671 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002672}
2673
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002674static void
Dave Barach72d72232016-08-04 10:15:08 -04002675 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2676 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002677{
Dave Barach72d72232016-08-04 10:15:08 -04002678 vat_main_t *vam = &vat_main;
2679 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002680
Dave Barach72d72232016-08-04 10:15:08 -04002681 if (retval >= 0)
2682 {
2683 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002684 }
2685
Dave Barach72d72232016-08-04 10:15:08 -04002686 vam->retval = retval;
2687 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002688}
2689
2690static void
Dave Barach72d72232016-08-04 10:15:08 -04002691 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2692 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002693{
Dave Barach72d72232016-08-04 10:15:08 -04002694 vat_main_t *vam = &vat_main;
2695 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002696
Dave Barach72d72232016-08-04 10:15:08 -04002697 if (VAT_JSON_ARRAY != vam->json_tree.type)
2698 {
2699 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2700 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002701 }
Dave Barach72d72232016-08-04 10:15:08 -04002702 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002703
Dave Barach72d72232016-08-04 10:15:08 -04002704 vat_json_init_object (node);
2705 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002706
Dave Barach72d72232016-08-04 10:15:08 -04002707 vat_json_print (vam->ofp, node);
2708 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002709
Dave Barach72d72232016-08-04 10:15:08 -04002710 vam->retval = ntohl (mp->retval);
2711 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002712}
2713
Florin Corasdca88042016-09-14 16:01:38 +02002714static u8 *
2715format_lisp_map_request_mode (u8 * s, va_list * args)
2716{
2717 u32 mode = va_arg (*args, u32);
2718
2719 switch (mode)
2720 {
2721 case 0:
2722 return format (0, "dst-only");
2723 case 1:
2724 return format (0, "src-dst");
2725 }
2726 return 0;
2727}
2728
2729static void
2730 vl_api_show_lisp_map_request_mode_reply_t_handler
2731 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2732{
2733 vat_main_t *vam = &vat_main;
2734 i32 retval = ntohl (mp->retval);
2735
2736 if (0 <= retval)
2737 {
2738 u32 mode = mp->mode;
2739 fformat (vam->ofp, "map_request_mode: %U\n",
2740 format_lisp_map_request_mode, mode);
2741 }
2742
2743 vam->retval = retval;
2744 vam->result_ready = 1;
2745}
2746
2747static void
2748 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2749 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2750{
2751 vat_main_t *vam = &vat_main;
2752 vat_json_node_t node;
2753 u8 *s = 0;
2754 u32 mode;
2755
2756 mode = mp->mode;
2757 s = format (0, "%U", format_lisp_map_request_mode, mode);
2758 vec_add1 (s, 0);
2759
2760 vat_json_init_object (&node);
2761 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2762 vat_json_print (vam->ofp, &node);
2763 vat_json_free (&node);
2764
2765 vec_free (s);
2766 vam->retval = ntohl (mp->retval);
2767 vam->result_ready = 1;
2768}
2769
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002770static void
2771vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2772{
Dave Barach72d72232016-08-04 10:15:08 -04002773 vat_main_t *vam = &vat_main;
2774 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002775
Dave Barach72d72232016-08-04 10:15:08 -04002776 if (0 <= retval)
2777 {
2778 fformat (vam->ofp, "%-20s%-16s\n",
2779 mp->status ? "enabled" : "disabled",
2780 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002781 }
2782
Dave Barach72d72232016-08-04 10:15:08 -04002783 vam->retval = retval;
2784 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002785}
2786
2787static void
Dave Barach72d72232016-08-04 10:15:08 -04002788vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2789 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002790{
Dave Barach72d72232016-08-04 10:15:08 -04002791 vat_main_t *vam = &vat_main;
2792 vat_json_node_t node;
2793 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002794
Dave Barach72d72232016-08-04 10:15:08 -04002795 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2796 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002797
Dave Barach72d72232016-08-04 10:15:08 -04002798 vat_json_init_object (&node);
2799 vat_json_object_add_string_copy (&node, "status", status);
2800 if (mp->status)
2801 {
2802 vat_json_object_add_string_copy (&node, "locator_set",
2803 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002804 }
2805
Dave Barach72d72232016-08-04 10:15:08 -04002806 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002807
Dave Barach72d72232016-08-04 10:15:08 -04002808 vat_json_print (vam->ofp, &node);
2809 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002810
Dave Barach72d72232016-08-04 10:15:08 -04002811 vam->retval = ntohl (mp->retval);
2812 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002813}
2814
Dave Barach72d72232016-08-04 10:15:08 -04002815static u8 *
2816format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002817{
Dave Barach72d72232016-08-04 10:15:08 -04002818 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002819
Dave Barach72d72232016-08-04 10:15:08 -04002820 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2821 s = format (s, "1r2c");
2822 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2823 s = format (s, "1r3c");
2824 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2825 s = format (s, "2r3c-2698");
2826 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2827 s = format (s, "2r3c-4115");
2828 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2829 s = format (s, "2r3c-mef5cf1");
2830 else
2831 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002832 return s;
2833}
2834
Dave Barach72d72232016-08-04 10:15:08 -04002835static u8 *
2836format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002837{
2838 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002839
Dave Barach72d72232016-08-04 10:15:08 -04002840 if (i == SSE2_QOS_RATE_KBPS)
2841 s = format (s, "kbps");
2842 else if (i == SSE2_QOS_RATE_PPS)
2843 s = format (s, "pps");
2844 else
2845 s = format (s, "ILLEGAL");
2846 return s;
2847}
2848
2849static u8 *
2850format_policer_round_type (u8 * s, va_list * va)
2851{
2852 u32 i = va_arg (*va, u32);
2853
2854 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2855 s = format (s, "closest");
2856 else if (i == SSE2_QOS_ROUND_TO_UP)
2857 s = format (s, "up");
2858 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2859 s = format (s, "down");
2860 else
2861 s = format (s, "ILLEGAL");
2862 return s;
2863}
2864
2865static u8 *
2866format_policer_action_type (u8 * s, va_list * va)
2867{
2868 u32 i = va_arg (*va, u32);
2869
2870 if (i == SSE2_QOS_ACTION_DROP)
2871 s = format (s, "drop");
2872 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2873 s = format (s, "transmit");
2874 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2875 s = format (s, "mark-and-transmit");
2876 else
2877 s = format (s, "ILLEGAL");
2878 return s;
2879}
2880
2881static u8 *
2882format_dscp (u8 * s, va_list * va)
2883{
2884 u32 i = va_arg (*va, u32);
2885 char *t = 0;
2886
2887 switch (i)
2888 {
2889#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2890 foreach_vnet_dscp
2891#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07002892 default:
2893 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04002894 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07002895 s = format (s, "%s", t);
2896 return s;
2897}
2898
Dave Barach72d72232016-08-04 10:15:08 -04002899static void
2900vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002901{
Dave Barach72d72232016-08-04 10:15:08 -04002902 vat_main_t *vam = &vat_main;
2903 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07002904
Dave Barach72d72232016-08-04 10:15:08 -04002905 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2906 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
2907 else
2908 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002909
Dave Barach72d72232016-08-04 10:15:08 -04002910 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2911 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
2912 else
2913 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002914
Dave Barach72d72232016-08-04 10:15:08 -04002915 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2916 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
2917 else
2918 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07002919
Dave Barach72d72232016-08-04 10:15:08 -04002920 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2921 "rate type %U, round type %U, %s rate, %s color-aware, "
2922 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2923 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2924 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2925 mp->name,
2926 format_policer_type, mp->type,
2927 ntohl (mp->cir),
2928 ntohl (mp->eir),
2929 clib_net_to_host_u64 (mp->cb),
2930 clib_net_to_host_u64 (mp->eb),
2931 format_policer_rate_type, mp->rate_type,
2932 format_policer_round_type, mp->round_type,
2933 mp->single_rate ? "single" : "dual",
2934 mp->color_aware ? "is" : "not",
2935 ntohl (mp->cir_tokens_per_period),
2936 ntohl (mp->pir_tokens_per_period),
2937 ntohl (mp->scale),
2938 ntohl (mp->current_limit),
2939 ntohl (mp->current_bucket),
2940 ntohl (mp->extended_limit),
2941 ntohl (mp->extended_bucket),
2942 clib_net_to_host_u64 (mp->last_update_time),
2943 format_policer_action_type, mp->conform_action_type,
2944 conform_dscp_str,
2945 format_policer_action_type, mp->exceed_action_type,
2946 exceed_dscp_str,
2947 format_policer_action_type, mp->violate_action_type,
2948 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002949
Dave Barach72d72232016-08-04 10:15:08 -04002950 vec_free (conform_dscp_str);
2951 vec_free (exceed_dscp_str);
2952 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07002953}
2954
2955static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002956 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002957{
Dave Barach72d72232016-08-04 10:15:08 -04002958 vat_main_t *vam = &vat_main;
2959 vat_json_node_t *node;
2960 u8 *rate_type_str, *round_type_str, *type_str;
2961 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07002962
Dave Barach72d72232016-08-04 10:15:08 -04002963 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2964 round_type_str =
2965 format (0, "%U", format_policer_round_type, mp->round_type);
2966 type_str = format (0, "%U", format_policer_type, mp->type);
2967 conform_action_str = format (0, "%U", format_policer_action_type,
2968 mp->conform_action_type);
2969 exceed_action_str = format (0, "%U", format_policer_action_type,
2970 mp->exceed_action_type);
2971 violate_action_str = format (0, "%U", format_policer_action_type,
2972 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07002973
Dave Barach72d72232016-08-04 10:15:08 -04002974 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002975 {
Dave Barach72d72232016-08-04 10:15:08 -04002976 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2977 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002978 }
Dave Barach72d72232016-08-04 10:15:08 -04002979 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02002980
Dave Barach72d72232016-08-04 10:15:08 -04002981 vat_json_init_object (node);
2982 vat_json_object_add_string_copy (node, "name", mp->name);
2983 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2984 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2985 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
2986 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
2987 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2988 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2989 vat_json_object_add_string_copy (node, "type", type_str);
2990 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2991 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2992 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2993 vat_json_object_add_uint (node, "cir_tokens_per_period",
2994 ntohl (mp->cir_tokens_per_period));
2995 vat_json_object_add_uint (node, "eir_tokens_per_period",
2996 ntohl (mp->pir_tokens_per_period));
2997 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2998 vat_json_object_add_uint (node, "current_bucket",
2999 ntohl (mp->current_bucket));
3000 vat_json_object_add_uint (node, "extended_limit",
3001 ntohl (mp->extended_limit));
3002 vat_json_object_add_uint (node, "extended_bucket",
3003 ntohl (mp->extended_bucket));
3004 vat_json_object_add_uint (node, "last_update_time",
3005 ntohl (mp->last_update_time));
3006 vat_json_object_add_string_copy (node, "conform_action",
3007 conform_action_str);
3008 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3009 {
3010 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3011 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3012 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003013 }
Dave Barach72d72232016-08-04 10:15:08 -04003014 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3015 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3016 {
3017 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3018 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3019 vec_free (dscp_str);
3020 }
3021 vat_json_object_add_string_copy (node, "violate_action",
3022 violate_action_str);
3023 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3024 {
3025 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3026 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3027 vec_free (dscp_str);
3028 }
3029
3030 vec_free (rate_type_str);
3031 vec_free (round_type_str);
3032 vec_free (type_str);
3033 vec_free (conform_action_str);
3034 vec_free (exceed_action_str);
3035 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003036}
3037
Dave Barach72d72232016-08-04 10:15:08 -04003038static void
3039vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3040 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003041{
Dave Barach72d72232016-08-04 10:15:08 -04003042 vat_main_t *vam = &vat_main;
3043 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003044
Dave Barach72d72232016-08-04 10:15:08 -04003045 if (count > 0)
3046 fformat (vam->ofp, "classify table ids (%d) : ", count);
3047 for (i = 0; i < count; i++)
3048 {
3049 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3050 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3051 }
3052 vam->retval = ntohl (mp->retval);
3053 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003054}
3055
Dave Barach72d72232016-08-04 10:15:08 -04003056static void
3057 vl_api_classify_table_ids_reply_t_handler_json
3058 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003059{
Dave Barach72d72232016-08-04 10:15:08 -04003060 vat_main_t *vam = &vat_main;
3061 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003062
Dave Barach72d72232016-08-04 10:15:08 -04003063 if (count > 0)
3064 {
3065 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003066
Dave Barach72d72232016-08-04 10:15:08 -04003067 vat_json_init_object (&node);
3068 for (i = 0; i < count; i++)
3069 {
3070 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3071 }
3072 vat_json_print (vam->ofp, &node);
3073 vat_json_free (&node);
3074 }
3075 vam->retval = ntohl (mp->retval);
3076 vam->result_ready = 1;
3077}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003078
Dave Barach72d72232016-08-04 10:15:08 -04003079static void
3080 vl_api_classify_table_by_interface_reply_t_handler
3081 (vl_api_classify_table_by_interface_reply_t * mp)
3082{
3083 vat_main_t *vam = &vat_main;
3084 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003085
Dave Barach72d72232016-08-04 10:15:08 -04003086 table_id = ntohl (mp->l2_table_id);
3087 if (table_id != ~0)
3088 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3089 else
3090 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3091 table_id = ntohl (mp->ip4_table_id);
3092 if (table_id != ~0)
3093 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3094 else
3095 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3096 table_id = ntohl (mp->ip6_table_id);
3097 if (table_id != ~0)
3098 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3099 else
3100 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3101 vam->retval = ntohl (mp->retval);
3102 vam->result_ready = 1;
3103}
3104
3105static void
3106 vl_api_classify_table_by_interface_reply_t_handler_json
3107 (vl_api_classify_table_by_interface_reply_t * mp)
3108{
3109 vat_main_t *vam = &vat_main;
3110 vat_json_node_t node;
3111
3112 vat_json_init_object (&node);
3113
3114 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3115 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3116 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3117
3118 vat_json_print (vam->ofp, &node);
3119 vat_json_free (&node);
3120
3121 vam->retval = ntohl (mp->retval);
3122 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003123}
3124
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003125static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003126 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003127{
Dave Barach72d72232016-08-04 10:15:08 -04003128 vat_main_t *vam = &vat_main;
3129 i32 retval = ntohl (mp->retval);
3130 if (vam->async_mode)
3131 {
3132 vam->async_errors += (retval < 0);
3133 }
3134 else
3135 {
3136 vam->retval = retval;
3137 vam->result_ready = 1;
3138 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3139 /*
3140 * Note: this is just barely thread-safe, depends on
3141 * the main thread spinning waiting for an answer...
3142 */
3143 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003144 }
3145}
3146
3147static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003148 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003149{
Dave Barach72d72232016-08-04 10:15:08 -04003150 vat_main_t *vam = &vat_main;
3151 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003152
Dave Barach72d72232016-08-04 10:15:08 -04003153 vat_json_init_object (&node);
3154 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3155 vat_json_object_add_uint (&node, "policer_index",
3156 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003157
Dave Barach72d72232016-08-04 10:15:08 -04003158 vat_json_print (vam->ofp, &node);
3159 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003160
Dave Barach72d72232016-08-04 10:15:08 -04003161 vam->retval = ntohl (mp->retval);
3162 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003163}
3164
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003165/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003166u8 *
3167format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003168{
Dave Barach72d72232016-08-04 10:15:08 -04003169 u8 *bytes = va_arg (*va, u8 *);
3170 int n_bytes = va_arg (*va, int);
3171 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003172
Dave Barach72d72232016-08-04 10:15:08 -04003173 /* Print short or long form depending on byte count. */
3174 uword short_form = n_bytes <= 32;
3175 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003176
Dave Barach72d72232016-08-04 10:15:08 -04003177 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003178 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003179
Dave Barach72d72232016-08-04 10:15:08 -04003180 for (i = 0; i < n_bytes; i++)
3181 {
3182 if (!short_form && (i % 32) == 0)
3183 s = format (s, "%08x: ", i);
3184 s = format (s, "%02x", bytes[i]);
3185 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3186 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003187 }
Dave Barach72d72232016-08-04 10:15:08 -04003188
3189 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003190}
3191
Dave Barach72d72232016-08-04 10:15:08 -04003192static void
3193vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3194 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003195{
Dave Barach72d72232016-08-04 10:15:08 -04003196 vat_main_t *vam = &vat_main;
3197 i32 retval = ntohl (mp->retval);
3198 if (retval == 0)
3199 {
3200 fformat (vam->ofp, "classify table info :\n");
3201 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3202 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3203 ntohl (mp->miss_next_index));
3204 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3205 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3206 ntohl (mp->match_n_vectors));
3207 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3208 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003209 }
Dave Barach72d72232016-08-04 10:15:08 -04003210 vam->retval = retval;
3211 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003212}
3213
Dave Barach72d72232016-08-04 10:15:08 -04003214static void
3215 vl_api_classify_table_info_reply_t_handler_json
3216 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003217{
Dave Barach72d72232016-08-04 10:15:08 -04003218 vat_main_t *vam = &vat_main;
3219 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003220
Dave Barach72d72232016-08-04 10:15:08 -04003221 i32 retval = ntohl (mp->retval);
3222 if (retval == 0)
3223 {
3224 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003225
Dave Barach72d72232016-08-04 10:15:08 -04003226 vat_json_object_add_int (&node, "sessions",
3227 ntohl (mp->active_sessions));
3228 vat_json_object_add_int (&node, "nexttbl",
3229 ntohl (mp->next_table_index));
3230 vat_json_object_add_int (&node, "nextnode",
3231 ntohl (mp->miss_next_index));
3232 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3233 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3234 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3235 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3236 ntohl (mp->mask_length), 0);
3237 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003238
Dave Barach72d72232016-08-04 10:15:08 -04003239 vat_json_print (vam->ofp, &node);
3240 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003241 }
Dave Barach72d72232016-08-04 10:15:08 -04003242 vam->retval = ntohl (mp->retval);
3243 vam->result_ready = 1;
3244}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003245
Dave Barach72d72232016-08-04 10:15:08 -04003246static void
3247vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3248 mp)
3249{
3250 vat_main_t *vam = &vat_main;
3251
3252 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3253 ntohl (mp->hit_next_index), ntohl (mp->advance),
3254 ntohl (mp->opaque_index));
3255 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3256 ntohl (mp->match_length));
3257}
3258
3259static void
3260 vl_api_classify_session_details_t_handler_json
3261 (vl_api_classify_session_details_t * mp)
3262{
3263 vat_main_t *vam = &vat_main;
3264 vat_json_node_t *node = NULL;
3265
3266 if (VAT_JSON_ARRAY != vam->json_tree.type)
3267 {
3268 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3269 vat_json_init_array (&vam->json_tree);
3270 }
3271 node = vat_json_array_add (&vam->json_tree);
3272
3273 vat_json_init_object (node);
3274 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3275 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3276 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3277 u8 *s =
3278 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3279 0);
3280 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003281}
Matus Fabiane8554802016-05-18 23:40:37 -07003282
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003283static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003284 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003285{
Dave Barach72d72232016-08-04 10:15:08 -04003286 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003287
Dave Barach72d72232016-08-04 10:15:08 -04003288 vam->retval = ntohl (mp->retval);
3289 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003290}
3291
3292static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003293 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003294{
Dave Barach72d72232016-08-04 10:15:08 -04003295 vat_main_t *vam = &vat_main;
3296 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003297
Dave Barach72d72232016-08-04 10:15:08 -04003298 i32 retval = ntohl (mp->retval);
3299 if (retval == 0)
3300 {
3301 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003302
Dave Barach72d72232016-08-04 10:15:08 -04003303 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003304
Dave Barach72d72232016-08-04 10:15:08 -04003305 vat_json_print (vam->ofp, &node);
3306 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003307 }
Dave Barach72d72232016-08-04 10:15:08 -04003308 vam->retval = ntohl (mp->retval);
3309 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003310}
3311
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003312static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003313 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003314{
Dave Barach72d72232016-08-04 10:15:08 -04003315 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003316
Dave Barach72d72232016-08-04 10:15:08 -04003317 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3318 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003319}
3320
3321static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003322 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003323{
Dave Barach72d72232016-08-04 10:15:08 -04003324 vat_main_t *vam = &vat_main;
3325 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003326
Dave Barach72d72232016-08-04 10:15:08 -04003327 if (VAT_JSON_ARRAY != vam->json_tree.type)
3328 {
3329 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3330 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003331 }
Dave Barach72d72232016-08-04 10:15:08 -04003332 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003333
Dave Barach72d72232016-08-04 10:15:08 -04003334 vat_json_init_object (node);
3335 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3336 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003337}
3338
Matus Fabian694265d2016-08-10 01:55:36 -07003339static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3340 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3341{
3342 vat_main_t *vam = &vat_main;
3343 i32 retval = ntohl (mp->retval);
3344 if (vam->async_mode)
3345 {
3346 vam->async_errors += (retval < 0);
3347 }
3348 else
3349 {
3350 vam->retval = retval;
3351 vam->sw_if_index = ntohl (mp->sw_if_index);
3352 vam->result_ready = 1;
3353 }
3354}
3355
3356static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3357 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3358{
3359 vat_main_t *vam = &vat_main;
3360 vat_json_node_t node;
3361
3362 vat_json_init_object (&node);
3363 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3364 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3365
3366 vat_json_print (vam->ofp, &node);
3367 vat_json_free (&node);
3368
3369 vam->retval = ntohl (mp->retval);
3370 vam->result_ready = 1;
3371}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003372
Ed Warnickecb9cada2015-12-08 15:45:58 -07003373#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3374#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3375#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3376#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
3377
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003378/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003379 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003380 * dig the return value out of the xxx_reply_t API message,
3381 * stick it into vam->retval, and set vam->result_ready
3382 *
3383 * Could also do this by pointing N message decode slots at
3384 * a single function, but that could break in subtle ways.
3385 */
3386
3387#define foreach_standard_reply_retval_handler \
3388_(sw_interface_set_flags_reply) \
3389_(sw_interface_add_del_address_reply) \
3390_(sw_interface_set_table_reply) \
3391_(sw_interface_set_vpath_reply) \
3392_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003393_(sw_interface_set_dpdk_hqos_pipe_reply) \
3394_(sw_interface_set_dpdk_hqos_subport_reply) \
3395_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003396_(bridge_domain_add_del_reply) \
3397_(sw_interface_set_l2_xconnect_reply) \
3398_(l2fib_add_del_reply) \
3399_(ip_add_del_route_reply) \
3400_(proxy_arp_add_del_reply) \
3401_(proxy_arp_intfc_enable_disable_reply) \
3402_(mpls_add_del_encap_reply) \
3403_(mpls_add_del_decap_reply) \
3404_(mpls_ethernet_add_del_tunnel_2_reply) \
3405_(sw_interface_set_unnumbered_reply) \
3406_(ip_neighbor_add_del_reply) \
3407_(reset_vrf_reply) \
3408_(oam_add_del_reply) \
3409_(reset_fib_reply) \
3410_(dhcp_proxy_config_reply) \
3411_(dhcp_proxy_config_2_reply) \
3412_(dhcp_proxy_set_vss_reply) \
3413_(dhcp_client_config_reply) \
3414_(set_ip_flow_hash_reply) \
3415_(sw_interface_ip6_enable_disable_reply) \
3416_(sw_interface_ip6_set_link_local_address_reply) \
3417_(sw_interface_ip6nd_ra_prefix_reply) \
3418_(sw_interface_ip6nd_ra_config_reply) \
3419_(set_arp_neighbor_limit_reply) \
3420_(l2_patch_add_del_reply) \
3421_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003422_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003423_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003424_(classify_add_del_session_reply) \
3425_(classify_set_interface_ip_table_reply) \
3426_(classify_set_interface_l2_tables_reply) \
3427_(l2tpv3_set_tunnel_cookies_reply) \
3428_(l2tpv3_interface_enable_disable_reply) \
3429_(l2tpv3_set_lookup_key_reply) \
3430_(l2_fib_clear_table_reply) \
3431_(l2_interface_efp_filter_reply) \
3432_(l2_interface_vlan_tag_rewrite_reply) \
3433_(modify_vhost_user_if_reply) \
3434_(delete_vhost_user_if_reply) \
3435_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003436_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003437_(input_acl_set_interface_reply) \
3438_(ipsec_spd_add_del_reply) \
3439_(ipsec_interface_add_del_spd_reply) \
3440_(ipsec_spd_add_del_entry_reply) \
3441_(ipsec_sad_add_del_entry_reply) \
3442_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003443_(ikev2_profile_add_del_reply) \
3444_(ikev2_profile_set_auth_reply) \
3445_(ikev2_profile_set_id_reply) \
3446_(ikev2_profile_set_ts_reply) \
3447_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003448_(delete_loopback_reply) \
3449_(bd_ip_mac_add_del_reply) \
3450_(map_del_domain_reply) \
3451_(map_add_del_rule_reply) \
3452_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003453_(want_stats_reply) \
3454_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003455_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003456_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003457_(ioam_enable_reply) \
3458_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003459_(lisp_add_del_locator_reply) \
3460_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003461_(lisp_add_del_remote_mapping_reply) \
3462_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003463_(lisp_gpe_add_del_fwd_entry_reply) \
3464_(lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003465_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003466_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003467_(lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003468_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003469_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003470_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003471_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003472_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003473_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003474_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003475_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003476_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003477_(set_ipfix_exporter_reply) \
3478_(set_ipfix_classify_stream_reply) \
3479_(ipfix_classify_table_add_del_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003480_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003481_(pg_enable_disable_reply) \
3482_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003483_(ip_source_and_port_range_check_interface_add_del_reply)\
3484_(delete_subif_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003485
3486#define _(n) \
3487 static void vl_api_##n##_t_handler \
3488 (vl_api_##n##_t * mp) \
3489 { \
3490 vat_main_t * vam = &vat_main; \
3491 i32 retval = ntohl(mp->retval); \
3492 if (vam->async_mode) { \
3493 vam->async_errors += (retval < 0); \
3494 } else { \
3495 vam->retval = retval; \
3496 vam->result_ready = 1; \
3497 } \
3498 }
3499foreach_standard_reply_retval_handler;
3500#undef _
3501
3502#define _(n) \
3503 static void vl_api_##n##_t_handler_json \
3504 (vl_api_##n##_t * mp) \
3505 { \
3506 vat_main_t * vam = &vat_main; \
3507 vat_json_node_t node; \
3508 vat_json_init_object(&node); \
3509 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3510 vat_json_print(vam->ofp, &node); \
3511 vam->retval = ntohl(mp->retval); \
3512 vam->result_ready = 1; \
3513 }
3514foreach_standard_reply_retval_handler;
3515#undef _
3516
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003517/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003518 * Table of message reply handlers, must include boilerplate handlers
3519 * we just generated
3520 */
3521
3522#define foreach_vpe_api_reply_msg \
3523_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3524_(SW_INTERFACE_DETAILS, sw_interface_details) \
3525_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3526_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3527_(CONTROL_PING_REPLY, control_ping_reply) \
3528_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003529_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003530_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3531 sw_interface_add_del_address_reply) \
3532_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3533_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3534_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3535 sw_interface_set_l2_xconnect_reply) \
3536_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3537 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003538_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3539 sw_interface_set_dpdk_hqos_pipe_reply) \
3540_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3541 sw_interface_set_dpdk_hqos_subport_reply) \
3542_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3543 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003544_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3545_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3546_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3547_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3548_(L2_FLAGS_REPLY, l2_flags_reply) \
3549_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3550_(TAP_CONNECT_REPLY, tap_connect_reply) \
3551_(TAP_MODIFY_REPLY, tap_modify_reply) \
3552_(TAP_DELETE_REPLY, tap_delete_reply) \
3553_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3554_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3555_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3556_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3557 proxy_arp_intfc_enable_disable_reply) \
3558_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3559_(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3560_(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3561_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3562 mpls_ethernet_add_del_tunnel_reply) \
3563_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3564 mpls_ethernet_add_del_tunnel_2_reply) \
3565_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3566 sw_interface_set_unnumbered_reply) \
3567_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3568_(RESET_VRF_REPLY, reset_vrf_reply) \
3569_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3570_(CREATE_SUBIF_REPLY, create_subif_reply) \
3571_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3572_(RESET_FIB_REPLY, reset_fib_reply) \
3573_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3574_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3575_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3576_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3577_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3578_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3579 sw_interface_ip6_enable_disable_reply) \
3580_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3581 sw_interface_ip6_set_link_local_address_reply) \
3582_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3583 sw_interface_ip6nd_ra_prefix_reply) \
3584_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3585 sw_interface_ip6nd_ra_config_reply) \
3586_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3587_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3588_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003589_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3590_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003591_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3592_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3593_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3594classify_set_interface_ip_table_reply) \
3595_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3596 classify_set_interface_l2_tables_reply) \
3597_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3598_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3599_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3600_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3601_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3602 l2tpv3_interface_enable_disable_reply) \
3603_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3604_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3605_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003606_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003607_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3608_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003609_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3610_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3611_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3612_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3613_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3614_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3615_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3616_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003617_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003618_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3619_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003620_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3621_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3622_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003623_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3624_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003625_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3626_(IP_ADDRESS_DETAILS, ip_address_details) \
3627_(IP_DETAILS, ip_details) \
3628_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3629_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3630_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3631_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3632_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003633_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3634_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3635_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3636_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3637_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003638_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3639_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3640_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3641_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3642_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3643_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3644_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3645_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003646_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003647_(MAP_DOMAIN_DETAILS, map_domain_details) \
3648_(MAP_RULE_DETAILS, map_rule_details) \
3649_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3650_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003651_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3652_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003653_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003654_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003655_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003656_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3657_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003658_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3659_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3660_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003661_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3662_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003663_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3664_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003665_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003666_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003667_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003668_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003669_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003670_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3671_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003672_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003673_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003674_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003675_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003676_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003677_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003678_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003679_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3680 lisp_add_del_map_request_itr_rlocs_reply) \
3681_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3682 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003683_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003684_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003685_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003686_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003687_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003688_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003689_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3690_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003691_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003692_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3693_(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3694_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3695_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003696_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3697_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3698_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3699_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003700_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003701_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3702_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3703_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3704_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3705_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3706_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003707_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3708_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3709_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003710_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3711_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3712 ip_source_and_port_range_check_add_del_reply) \
3713_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003714 ip_source_and_port_range_check_interface_add_del_reply) \
3715_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003716_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
3717_(DELETE_SUBIF_REPLY, delete_subif_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003718
3719/* M: construct, but don't yet send a message */
3720
3721#define M(T,t) \
3722do { \
3723 vam->result_ready = 0; \
3724 mp = vl_msg_api_alloc(sizeof(*mp)); \
3725 memset (mp, 0, sizeof (*mp)); \
3726 mp->_vl_msg_id = ntohs (VL_API_##T); \
3727 mp->client_index = vam->my_client_index; \
3728} while(0);
3729
3730#define M2(T,t,n) \
3731do { \
3732 vam->result_ready = 0; \
3733 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3734 memset (mp, 0, sizeof (*mp)); \
3735 mp->_vl_msg_id = ntohs (VL_API_##T); \
3736 mp->client_index = vam->my_client_index; \
3737} while(0);
3738
3739
3740/* S: send a message */
3741#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3742
3743/* W: wait for results, with timeout */
3744#define W \
3745do { \
3746 timeout = vat_time_now (vam) + 1.0; \
3747 \
3748 while (vat_time_now (vam) < timeout) { \
3749 if (vam->result_ready == 1) { \
3750 return (vam->retval); \
3751 } \
3752 } \
3753 return -99; \
3754} while(0);
3755
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003756/* W2: wait for results, with timeout */
3757#define W2(body) \
3758do { \
3759 timeout = vat_time_now (vam) + 1.0; \
3760 \
3761 while (vat_time_now (vam) < timeout) { \
3762 if (vam->result_ready == 1) { \
3763 (body); \
3764 return (vam->retval); \
3765 } \
3766 } \
3767 return -99; \
3768} while(0);
3769
Dave Barach72d72232016-08-04 10:15:08 -04003770typedef struct
3771{
3772 u8 *name;
3773 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003774} name_sort_t;
3775
3776
3777#define STR_VTR_OP_CASE(op) \
3778 case L2_VTR_ ## op: \
3779 return "" # op;
3780
Dave Barach72d72232016-08-04 10:15:08 -04003781static const char *
3782str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003783{
Dave Barach72d72232016-08-04 10:15:08 -04003784 switch (vtr_op)
3785 {
3786 STR_VTR_OP_CASE (DISABLED);
3787 STR_VTR_OP_CASE (PUSH_1);
3788 STR_VTR_OP_CASE (PUSH_2);
3789 STR_VTR_OP_CASE (POP_1);
3790 STR_VTR_OP_CASE (POP_2);
3791 STR_VTR_OP_CASE (TRANSLATE_1_1);
3792 STR_VTR_OP_CASE (TRANSLATE_1_2);
3793 STR_VTR_OP_CASE (TRANSLATE_2_1);
3794 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003795 }
3796
Dave Barach72d72232016-08-04 10:15:08 -04003797 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003798}
3799
Dave Barach72d72232016-08-04 10:15:08 -04003800static int
3801dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003802{
Dave Barach72d72232016-08-04 10:15:08 -04003803 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003804
Dave Barach72d72232016-08-04 10:15:08 -04003805 if (vam->json_output)
3806 {
3807 clib_warning
3808 ("JSON output supported only for VPE API calls and dump_stats_table");
3809 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003810 }
3811
Dave Barach72d72232016-08-04 10:15:08 -04003812 fformat (vam->ofp,
3813 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3814 "Interface", "sw_if_index",
3815 "sub id", "dot1ad", "tags", "outer id",
3816 "inner id", "exact", "default", "outer any", "inner any");
3817
3818 vec_foreach (sub, vam->sw_if_subif_table)
3819 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003820 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003821 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3822 sub->interface_name,
3823 sub->sw_if_index,
3824 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3825 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3826 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3827 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3828 if (sub->vtr_op != L2_VTR_DISABLED)
3829 {
3830 fformat (vam->ofp,
3831 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3832 "tag1: %d tag2: %d ]\n",
3833 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3834 sub->vtr_tag1, sub->vtr_tag2);
3835 }
3836 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003837
Dave Barach72d72232016-08-04 10:15:08 -04003838 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003839}
3840
Dave Barach72d72232016-08-04 10:15:08 -04003841static int
3842name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003843{
Dave Barach72d72232016-08-04 10:15:08 -04003844 name_sort_t *n1 = a1;
3845 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003846
Dave Barach72d72232016-08-04 10:15:08 -04003847 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003848}
3849
Dave Barach72d72232016-08-04 10:15:08 -04003850static int
3851dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003852{
Dave Barach72d72232016-08-04 10:15:08 -04003853 hash_pair_t *p;
3854 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003855
Dave Barach72d72232016-08-04 10:15:08 -04003856 if (vam->json_output)
3857 {
3858 clib_warning
3859 ("JSON output supported only for VPE API calls and dump_stats_table");
3860 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003861 }
3862
Dave Barach72d72232016-08-04 10:15:08 -04003863 /* *INDENT-OFF* */
3864 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3865 ({
3866 vec_add2 (nses, ns, 1);
3867 ns->name = (u8 *)(p->key);
3868 ns->value = (u32) p->value[0];
3869 }));
3870 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003871
Dave Barach72d72232016-08-04 10:15:08 -04003872 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003873
Dave Barach72d72232016-08-04 10:15:08 -04003874 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3875 vec_foreach (ns, nses)
3876 {
3877 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3878 }
3879 vec_free (nses);
3880 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003881}
3882
Dave Barach72d72232016-08-04 10:15:08 -04003883static int
3884dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003885{
Dave Barach72d72232016-08-04 10:15:08 -04003886 const ip_details_t *det = NULL;
3887 const ip_address_details_t *address = NULL;
3888 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003889
Dave Barach72d72232016-08-04 10:15:08 -04003890 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3891
Dave Barach72d72232016-08-04 10:15:08 -04003892 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3893 {
3894 i++;
3895 if (!det->present)
3896 {
3897 continue;
3898 }
3899 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003900 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003901 " %-30s%-13s\n", "Address", "Prefix length");
3902 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003903 {
Dave Barach72d72232016-08-04 10:15:08 -04003904 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003905 }
Dave Barach72d72232016-08-04 10:15:08 -04003906 vec_foreach (address, det->addr)
3907 {
3908 fformat (vam->ofp,
3909 " %-30U%-13d\n",
3910 is_ipv6 ? format_ip6_address : format_ip4_address,
3911 address->ip, address->prefix_length);
3912 }
3913 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003914
Dave Barach72d72232016-08-04 10:15:08 -04003915 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003916}
3917
Dave Barach72d72232016-08-04 10:15:08 -04003918static int
3919dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003920{
Dave Barach72d72232016-08-04 10:15:08 -04003921 if (vam->json_output)
3922 {
3923 clib_warning
3924 ("JSON output supported only for VPE API calls and dump_stats_table");
3925 return -99;
3926 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003927
Dave Barach72d72232016-08-04 10:15:08 -04003928 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003929}
3930
Dave Barach72d72232016-08-04 10:15:08 -04003931static int
3932dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003933{
Dave Barach72d72232016-08-04 10:15:08 -04003934 if (vam->json_output)
3935 {
3936 clib_warning
3937 ("JSON output supported only for VPE API calls and dump_stats_table");
3938 return -99;
3939 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003940
Dave Barach72d72232016-08-04 10:15:08 -04003941 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003942}
3943
Dave Barach72d72232016-08-04 10:15:08 -04003944static char *
3945counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003946{
Dave Barach72d72232016-08-04 10:15:08 -04003947 if (!is_combined)
3948 {
3949 switch (counter_type)
3950 {
3951 case VNET_INTERFACE_COUNTER_DROP:
3952 return "drop";
3953 case VNET_INTERFACE_COUNTER_PUNT:
3954 return "punt";
3955 case VNET_INTERFACE_COUNTER_IP4:
3956 return "ip4";
3957 case VNET_INTERFACE_COUNTER_IP6:
3958 return "ip6";
3959 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3960 return "rx-no-buf";
3961 case VNET_INTERFACE_COUNTER_RX_MISS:
3962 return "rx-miss";
3963 case VNET_INTERFACE_COUNTER_RX_ERROR:
3964 return "rx-error";
3965 case VNET_INTERFACE_COUNTER_TX_ERROR:
3966 return "tx-error";
3967 default:
3968 return "INVALID-COUNTER-TYPE";
3969 }
3970 }
3971 else
3972 {
3973 switch (counter_type)
3974 {
3975 case VNET_INTERFACE_COUNTER_RX:
3976 return "rx";
3977 case VNET_INTERFACE_COUNTER_TX:
3978 return "tx";
3979 default:
3980 return "INVALID-COUNTER-TYPE";
3981 }
3982 }
3983}
Ed Warnickecb9cada2015-12-08 15:45:58 -07003984
Dave Barach72d72232016-08-04 10:15:08 -04003985static int
3986dump_stats_table (vat_main_t * vam)
3987{
3988 vat_json_node_t node;
3989 vat_json_node_t *msg_array;
3990 vat_json_node_t *msg;
3991 vat_json_node_t *counter_array;
3992 vat_json_node_t *counter;
3993 interface_counter_t c;
3994 u64 packets;
3995 ip4_fib_counter_t *c4;
3996 ip6_fib_counter_t *c6;
3997 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003998
Dave Barach72d72232016-08-04 10:15:08 -04003999 if (!vam->json_output)
4000 {
4001 clib_warning ("dump_stats_table supported only in JSON format");
4002 return -99;
4003 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004004
Dave Barach72d72232016-08-04 10:15:08 -04004005 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004006
Dave Barach72d72232016-08-04 10:15:08 -04004007 /* interface counters */
4008 msg_array = vat_json_object_add (&node, "interface_counters");
4009 vat_json_init_array (msg_array);
4010 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4011 {
4012 msg = vat_json_array_add (msg_array);
4013 vat_json_init_object (msg);
4014 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4015 (u8 *) counter_type_to_str (i, 0));
4016 vat_json_object_add_int (msg, "is_combined", 0);
4017 counter_array = vat_json_object_add (msg, "data");
4018 vat_json_init_array (counter_array);
4019 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4020 {
4021 packets = vam->simple_interface_counters[i][j];
4022 vat_json_array_add_uint (counter_array, packets);
4023 }
4024 }
4025 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4026 {
4027 msg = vat_json_array_add (msg_array);
4028 vat_json_init_object (msg);
4029 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4030 (u8 *) counter_type_to_str (i, 1));
4031 vat_json_object_add_int (msg, "is_combined", 1);
4032 counter_array = vat_json_object_add (msg, "data");
4033 vat_json_init_array (counter_array);
4034 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4035 {
4036 c = vam->combined_interface_counters[i][j];
4037 counter = vat_json_array_add (counter_array);
4038 vat_json_init_object (counter);
4039 vat_json_object_add_uint (counter, "packets", c.packets);
4040 vat_json_object_add_uint (counter, "bytes", c.bytes);
4041 }
4042 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004043
Dave Barach72d72232016-08-04 10:15:08 -04004044 /* ip4 fib counters */
4045 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4046 vat_json_init_array (msg_array);
4047 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4048 {
4049 msg = vat_json_array_add (msg_array);
4050 vat_json_init_object (msg);
4051 vat_json_object_add_uint (msg, "vrf_id",
4052 vam->ip4_fib_counters_vrf_id_by_index[i]);
4053 counter_array = vat_json_object_add (msg, "c");
4054 vat_json_init_array (counter_array);
4055 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4056 {
4057 counter = vat_json_array_add (counter_array);
4058 vat_json_init_object (counter);
4059 c4 = &vam->ip4_fib_counters[i][j];
4060 vat_json_object_add_ip4 (counter, "address", c4->address);
4061 vat_json_object_add_uint (counter, "address_length",
4062 c4->address_length);
4063 vat_json_object_add_uint (counter, "packets", c4->packets);
4064 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4065 }
4066 }
4067
4068 /* ip6 fib counters */
4069 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4070 vat_json_init_array (msg_array);
4071 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4072 {
4073 msg = vat_json_array_add (msg_array);
4074 vat_json_init_object (msg);
4075 vat_json_object_add_uint (msg, "vrf_id",
4076 vam->ip6_fib_counters_vrf_id_by_index[i]);
4077 counter_array = vat_json_object_add (msg, "c");
4078 vat_json_init_array (counter_array);
4079 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4080 {
4081 counter = vat_json_array_add (counter_array);
4082 vat_json_init_object (counter);
4083 c6 = &vam->ip6_fib_counters[i][j];
4084 vat_json_object_add_ip6 (counter, "address", c6->address);
4085 vat_json_object_add_uint (counter, "address_length",
4086 c6->address_length);
4087 vat_json_object_add_uint (counter, "packets", c6->packets);
4088 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4089 }
4090 }
4091
4092 vat_json_print (vam->ofp, &node);
4093 vat_json_free (&node);
4094
4095 return 0;
4096}
4097
4098int
4099exec (vat_main_t * vam)
4100{
4101 api_main_t *am = &api_main;
4102 vl_api_cli_request_t *mp;
4103 f64 timeout;
4104 void *oldheap;
4105 u8 *cmd = 0;
4106 unformat_input_t *i = vam->input;
4107
4108 if (vec_len (i->buffer) == 0)
4109 return -1;
4110
4111 if (vam->exec_mode == 0 && unformat (i, "mode"))
4112 {
4113 vam->exec_mode = 1;
4114 return 0;
4115 }
4116 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4117 {
4118 vam->exec_mode = 0;
4119 return 0;
4120 }
4121
4122
4123 M (CLI_REQUEST, cli_request);
4124
4125 /*
4126 * Copy cmd into shared memory.
4127 * In order for the CLI command to work, it
4128 * must be a vector ending in \n, not a C-string ending
4129 * in \n\0.
4130 */
4131 pthread_mutex_lock (&am->vlib_rp->mutex);
4132 oldheap = svm_push_data_heap (am->vlib_rp);
4133
4134 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4135 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4136
4137 svm_pop_heap (oldheap);
4138 pthread_mutex_unlock (&am->vlib_rp->mutex);
4139
4140 mp->cmd_in_shmem = (u64) cmd;
4141 S;
4142 timeout = vat_time_now (vam) + 10.0;
4143
4144 while (vat_time_now (vam) < timeout)
4145 {
4146 if (vam->result_ready == 1)
4147 {
4148 u8 *free_me;
4149 if (vam->shmem_result != NULL)
4150 fformat (vam->ofp, "%s", vam->shmem_result);
4151 pthread_mutex_lock (&am->vlib_rp->mutex);
4152 oldheap = svm_push_data_heap (am->vlib_rp);
4153
4154 free_me = (u8 *) vam->shmem_result;
4155 vec_free (free_me);
4156
4157 svm_pop_heap (oldheap);
4158 pthread_mutex_unlock (&am->vlib_rp->mutex);
4159 return 0;
4160 }
4161 }
4162 return -99;
4163}
4164
Ole Troanc27213a2016-08-31 14:50:49 +02004165/*
4166 * Future replacement of exec() that passes CLI buffers directly in
4167 * the API messages instead of an additional shared memory area.
4168 */
4169static int
4170exec_inband (vat_main_t * vam)
4171{
4172 vl_api_cli_inband_t *mp;
4173 f64 timeout;
4174 unformat_input_t *i = vam->input;
4175
4176 if (vec_len (i->buffer) == 0)
4177 return -1;
4178
4179 if (vam->exec_mode == 0 && unformat (i, "mode"))
4180 {
4181 vam->exec_mode = 1;
4182 return 0;
4183 }
4184 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4185 {
4186 vam->exec_mode = 0;
4187 return 0;
4188 }
4189
4190 /*
4191 * In order for the CLI command to work, it
4192 * must be a vector ending in \n, not a C-string ending
4193 * in \n\0.
4194 */
4195 u32 len = vec_len (vam->input->buffer);
4196 M2 (CLI_INBAND, cli_inband, len);
4197 clib_memcpy (mp->cmd, vam->input->buffer, len);
4198 mp->length = htonl (len);
4199
4200 S;
4201 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4202}
4203
Dave Barach72d72232016-08-04 10:15:08 -04004204static int
4205api_create_loopback (vat_main_t * vam)
4206{
4207 unformat_input_t *i = vam->input;
4208 vl_api_create_loopback_t *mp;
4209 f64 timeout;
4210 u8 mac_address[6];
4211 u8 mac_set = 0;
4212
4213 memset (mac_address, 0, sizeof (mac_address));
4214
4215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4216 {
4217 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4218 mac_set = 1;
4219 else
4220 break;
4221 }
4222
4223 /* Construct the API message */
4224 M (CREATE_LOOPBACK, create_loopback);
4225 if (mac_set)
4226 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4227
4228 S;
4229 W;
4230}
4231
4232static int
4233api_delete_loopback (vat_main_t * vam)
4234{
4235 unformat_input_t *i = vam->input;
4236 vl_api_delete_loopback_t *mp;
4237 f64 timeout;
4238 u32 sw_if_index = ~0;
4239
4240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4241 {
4242 if (unformat (i, "sw_if_index %d", &sw_if_index))
4243 ;
4244 else
4245 break;
4246 }
4247
4248 if (sw_if_index == ~0)
4249 {
4250 errmsg ("missing sw_if_index\n");
4251 return -99;
4252 }
4253
4254 /* Construct the API message */
4255 M (DELETE_LOOPBACK, delete_loopback);
4256 mp->sw_if_index = ntohl (sw_if_index);
4257
4258 S;
4259 W;
4260}
4261
4262static int
4263api_want_stats (vat_main_t * vam)
4264{
4265 unformat_input_t *i = vam->input;
4266 vl_api_want_stats_t *mp;
4267 f64 timeout;
4268 int enable = -1;
4269
4270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4271 {
4272 if (unformat (i, "enable"))
4273 enable = 1;
4274 else if (unformat (i, "disable"))
4275 enable = 0;
4276 else
4277 break;
4278 }
4279
4280 if (enable == -1)
4281 {
4282 errmsg ("missing enable|disable\n");
4283 return -99;
4284 }
4285
4286 M (WANT_STATS, want_stats);
4287 mp->enable_disable = enable;
4288
4289 S;
4290 W;
4291}
4292
4293static int
4294api_want_interface_events (vat_main_t * vam)
4295{
4296 unformat_input_t *i = vam->input;
4297 vl_api_want_interface_events_t *mp;
4298 f64 timeout;
4299 int enable = -1;
4300
4301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4302 {
4303 if (unformat (i, "enable"))
4304 enable = 1;
4305 else if (unformat (i, "disable"))
4306 enable = 0;
4307 else
4308 break;
4309 }
4310
4311 if (enable == -1)
4312 {
4313 errmsg ("missing enable|disable\n");
4314 return -99;
4315 }
4316
4317 M (WANT_INTERFACE_EVENTS, want_interface_events);
4318 mp->enable_disable = enable;
4319
4320 vam->interface_event_display = enable;
4321
4322 S;
4323 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004324}
4325
4326
4327/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004328int
4329api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004330{
Dave Barach72d72232016-08-04 10:15:08 -04004331 vl_api_sw_interface_dump_t *mp;
4332 f64 timeout;
4333 hash_pair_t *p;
4334 name_sort_t *nses = 0, *ns;
4335 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004336
Dave Barach72d72232016-08-04 10:15:08 -04004337 /* Toss the old name table */
4338 /* *INDENT-OFF* */
4339 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4340 ({
4341 vec_add2 (nses, ns, 1);
4342 ns->name = (u8 *)(p->key);
4343 ns->value = (u32) p->value[0];
4344 }));
4345 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004346
Dave Barach72d72232016-08-04 10:15:08 -04004347 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004348
Dave Barach72d72232016-08-04 10:15:08 -04004349 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004350
Dave Barach72d72232016-08-04 10:15:08 -04004351 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004352
Dave Barach72d72232016-08-04 10:15:08 -04004353 vec_foreach (sub, vam->sw_if_subif_table)
4354 {
4355 vec_free (sub->interface_name);
4356 }
4357 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004358
Dave Barach72d72232016-08-04 10:15:08 -04004359 /* recreate the interface name hash table */
4360 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004361
Dave Barach72d72232016-08-04 10:15:08 -04004362 /* Get list of ethernets */
4363 M (SW_INTERFACE_DUMP, sw_interface_dump);
4364 mp->name_filter_valid = 1;
4365 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4366 S;
4367
4368 /* and local / loopback interfaces */
4369 M (SW_INTERFACE_DUMP, sw_interface_dump);
4370 mp->name_filter_valid = 1;
4371 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4372 S;
4373
4374
4375 /* and vxlan-gpe tunnel interfaces */
4376 M (SW_INTERFACE_DUMP, sw_interface_dump);
4377 mp->name_filter_valid = 1;
4378 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4379 sizeof (mp->name_filter) - 1);
4380 S;
4381
4382 /* and vxlan tunnel interfaces */
4383 M (SW_INTERFACE_DUMP, sw_interface_dump);
4384 mp->name_filter_valid = 1;
4385 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4386 S;
4387
4388 /* and host (af_packet) interfaces */
4389 M (SW_INTERFACE_DUMP, sw_interface_dump);
4390 mp->name_filter_valid = 1;
4391 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4392 S;
4393
4394 /* and l2tpv3 tunnel interfaces */
4395 M (SW_INTERFACE_DUMP, sw_interface_dump);
4396 mp->name_filter_valid = 1;
4397 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4398 sizeof (mp->name_filter) - 1);
4399 S;
4400
4401 /* and GRE tunnel interfaces */
4402 M (SW_INTERFACE_DUMP, sw_interface_dump);
4403 mp->name_filter_valid = 1;
4404 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4405 S;
4406
Florin Corasce982752016-09-06 13:36:11 +02004407 /* and LISP-GPE interfaces */
4408 M (SW_INTERFACE_DUMP, sw_interface_dump);
4409 mp->name_filter_valid = 1;
4410 strncpy ((char *) mp->name_filter, "lisp_gpe",
4411 sizeof (mp->name_filter) - 1);
4412 S;
4413
Matus Fabian8fce3e32016-09-06 23:19:43 -07004414 /* and IPSEC tunnel interfaces */
4415 M (SW_INTERFACE_DUMP, sw_interface_dump);
4416 mp->name_filter_valid = 1;
4417 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4418 S;
4419
Dave Barach72d72232016-08-04 10:15:08 -04004420 /* Use a control ping for synchronization */
4421 {
4422 vl_api_control_ping_t *mp;
4423 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004424 S;
Dave Barach72d72232016-08-04 10:15:08 -04004425 }
4426 W;
4427}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004428
Dave Barach72d72232016-08-04 10:15:08 -04004429static int
4430api_sw_interface_set_flags (vat_main_t * vam)
4431{
4432 unformat_input_t *i = vam->input;
4433 vl_api_sw_interface_set_flags_t *mp;
4434 f64 timeout;
4435 u32 sw_if_index;
4436 u8 sw_if_index_set = 0;
4437 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004438
Dave Barach72d72232016-08-04 10:15:08 -04004439 /* Parse args required to build the message */
4440 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004441 {
Dave Barach72d72232016-08-04 10:15:08 -04004442 if (unformat (i, "admin-up"))
4443 admin_up = 1;
4444 else if (unformat (i, "admin-down"))
4445 admin_up = 0;
4446 else if (unformat (i, "link-up"))
4447 link_up = 1;
4448 else if (unformat (i, "link-down"))
4449 link_up = 0;
4450 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4451 sw_if_index_set = 1;
4452 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4453 sw_if_index_set = 1;
4454 else
4455 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004456 }
4457
Dave Barach72d72232016-08-04 10:15:08 -04004458 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004459 {
Dave Barach72d72232016-08-04 10:15:08 -04004460 errmsg ("missing interface name or sw_if_index\n");
4461 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004462 }
4463
Dave Barach72d72232016-08-04 10:15:08 -04004464 /* Construct the API message */
4465 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4466 mp->sw_if_index = ntohl (sw_if_index);
4467 mp->admin_up_down = admin_up;
4468 mp->link_up_down = link_up;
4469
4470 /* send it... */
4471 S;
4472
4473 /* Wait for a reply, return the good/bad news... */
4474 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004475}
4476
Dave Barach72d72232016-08-04 10:15:08 -04004477static int
4478api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004479{
Dave Barach72d72232016-08-04 10:15:08 -04004480 unformat_input_t *i = vam->input;
4481 vl_api_sw_interface_clear_stats_t *mp;
4482 f64 timeout;
4483 u32 sw_if_index;
4484 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004485
Dave Barach72d72232016-08-04 10:15:08 -04004486 /* Parse args required to build the message */
4487 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4488 {
4489 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4490 sw_if_index_set = 1;
4491 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4492 sw_if_index_set = 1;
4493 else
4494 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004495 }
4496
Dave Barach72d72232016-08-04 10:15:08 -04004497 /* Construct the API message */
4498 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004499
Dave Barach72d72232016-08-04 10:15:08 -04004500 if (sw_if_index_set == 1)
4501 mp->sw_if_index = ntohl (sw_if_index);
4502 else
4503 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004504
Dave Barach72d72232016-08-04 10:15:08 -04004505 /* send it... */
4506 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004507
Dave Barach72d72232016-08-04 10:15:08 -04004508 /* Wait for a reply, return the good/bad news... */
4509 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004510}
4511
Dave Barach72d72232016-08-04 10:15:08 -04004512static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004513api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4514{
4515 unformat_input_t *i = vam->input;
4516 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4517 f64 timeout;
4518 u32 sw_if_index;
4519 u8 sw_if_index_set = 0;
4520 u32 subport;
4521 u8 subport_set = 0;
4522 u32 pipe;
4523 u8 pipe_set = 0;
4524 u32 profile;
4525 u8 profile_set = 0;
4526
4527 /* Parse args required to build the message */
4528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4529 {
4530 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4531 sw_if_index_set = 1;
4532 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4533 sw_if_index_set = 1;
4534 else if (unformat (i, "subport %u", &subport))
4535 subport_set = 1;
4536 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4537 sw_if_index_set = 1;
4538 else if (unformat (i, "pipe %u", &pipe))
4539 pipe_set = 1;
4540 else if (unformat (i, "profile %u", &profile))
4541 profile_set = 1;
4542 else
4543 break;
4544 }
4545
4546 if (sw_if_index_set == 0)
4547 {
4548 errmsg ("missing interface name or sw_if_index\n");
4549 return -99;
4550 }
4551
4552 if (subport_set == 0)
4553 {
4554 errmsg ("missing subport \n");
4555 return -99;
4556 }
4557
4558 if (pipe_set == 0)
4559 {
4560 errmsg ("missing pipe\n");
4561 return -99;
4562 }
4563
4564 if (profile_set == 0)
4565 {
4566 errmsg ("missing profile\n");
4567 return -99;
4568 }
4569
4570 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4571
4572 mp->sw_if_index = ntohl (sw_if_index);
4573 mp->subport = ntohl (subport);
4574 mp->pipe = ntohl (pipe);
4575 mp->profile = ntohl (profile);
4576
4577
4578 S;
4579 W;
4580 /* NOTREACHED */
4581 return 0;
4582}
4583
4584static int
4585api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4586{
4587 unformat_input_t *i = vam->input;
4588 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4589 f64 timeout;
4590 u32 sw_if_index;
4591 u8 sw_if_index_set = 0;
4592 u32 subport;
4593 u8 subport_set = 0;
4594 u32 tb_rate = 1250000000; /* 10GbE */
4595 u32 tb_size = 1000000;
4596 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4597 u32 tc_period = 10;
4598
4599 /* Parse args required to build the message */
4600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4601 {
4602 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4603 sw_if_index_set = 1;
4604 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4605 sw_if_index_set = 1;
4606 else if (unformat (i, "subport %u", &subport))
4607 subport_set = 1;
4608 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4609 sw_if_index_set = 1;
4610 else if (unformat (i, "rate %u", &tb_rate))
4611 {
4612 u32 tc_id;
4613
4614 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4615 tc_id++)
4616 tc_rate[tc_id] = tb_rate;
4617 }
4618 else if (unformat (i, "bktsize %u", &tb_size))
4619 ;
4620 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4621 ;
4622 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4623 ;
4624 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4625 ;
4626 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4627 ;
4628 else if (unformat (i, "period %u", &tc_period))
4629 ;
4630 else
4631 break;
4632 }
4633
4634 if (sw_if_index_set == 0)
4635 {
4636 errmsg ("missing interface name or sw_if_index\n");
4637 return -99;
4638 }
4639
4640 if (subport_set == 0)
4641 {
4642 errmsg ("missing subport \n");
4643 return -99;
4644 }
4645
4646 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4647
4648 mp->sw_if_index = ntohl (sw_if_index);
4649 mp->subport = ntohl (subport);
4650 mp->tb_rate = ntohl (tb_rate);
4651 mp->tb_size = ntohl (tb_size);
4652 mp->tc_rate[0] = ntohl (tc_rate[0]);
4653 mp->tc_rate[1] = ntohl (tc_rate[1]);
4654 mp->tc_rate[2] = ntohl (tc_rate[2]);
4655 mp->tc_rate[3] = ntohl (tc_rate[3]);
4656 mp->tc_period = ntohl (tc_period);
4657
4658 S;
4659 W;
4660 /* NOTREACHED */
4661 return 0;
4662}
4663
4664static int
4665api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4666{
4667 unformat_input_t *i = vam->input;
4668 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4669 f64 timeout;
4670 u32 sw_if_index;
4671 u8 sw_if_index_set = 0;
4672 u8 entry_set = 0;
4673 u8 tc_set = 0;
4674 u8 queue_set = 0;
4675 u32 entry, tc, queue;
4676
4677 /* Parse args required to build the message */
4678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4679 {
4680 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4681 sw_if_index_set = 1;
4682 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4683 sw_if_index_set = 1;
4684 else if (unformat (i, "entry %d", &entry))
4685 entry_set = 1;
4686 else if (unformat (i, "tc %d", &tc))
4687 tc_set = 1;
4688 else if (unformat (i, "queue %d", &queue))
4689 queue_set = 1;
4690 else
4691 break;
4692 }
4693
4694 if (sw_if_index_set == 0)
4695 {
4696 errmsg ("missing interface name or sw_if_index\n");
4697 return -99;
4698 }
4699
4700 if (entry_set == 0)
4701 {
4702 errmsg ("missing entry \n");
4703 return -99;
4704 }
4705
4706 if (tc_set == 0)
4707 {
4708 errmsg ("missing traffic class \n");
4709 return -99;
4710 }
4711
4712 if (queue_set == 0)
4713 {
4714 errmsg ("missing queue \n");
4715 return -99;
4716 }
4717
4718 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4719
4720 mp->sw_if_index = ntohl (sw_if_index);
4721 mp->entry = ntohl (entry);
4722 mp->tc = ntohl (tc);
4723 mp->queue = ntohl (queue);
4724
4725 S;
4726 W;
4727 /* NOTREACHED */
4728 return 0;
4729}
4730
4731static int
Dave Barach72d72232016-08-04 10:15:08 -04004732api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004733{
Dave Barach72d72232016-08-04 10:15:08 -04004734 unformat_input_t *i = vam->input;
4735 vl_api_sw_interface_add_del_address_t *mp;
4736 f64 timeout;
4737 u32 sw_if_index;
4738 u8 sw_if_index_set = 0;
4739 u8 is_add = 1, del_all = 0;
4740 u32 address_length = 0;
4741 u8 v4_address_set = 0;
4742 u8 v6_address_set = 0;
4743 ip4_address_t v4address;
4744 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004745
Dave Barach72d72232016-08-04 10:15:08 -04004746 /* Parse args required to build the message */
4747 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4748 {
4749 if (unformat (i, "del-all"))
4750 del_all = 1;
4751 else if (unformat (i, "del"))
4752 is_add = 0;
4753 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4754 sw_if_index_set = 1;
4755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4756 sw_if_index_set = 1;
4757 else if (unformat (i, "%U/%d",
4758 unformat_ip4_address, &v4address, &address_length))
4759 v4_address_set = 1;
4760 else if (unformat (i, "%U/%d",
4761 unformat_ip6_address, &v6address, &address_length))
4762 v6_address_set = 1;
4763 else
4764 break;
4765 }
4766
4767 if (sw_if_index_set == 0)
4768 {
4769 errmsg ("missing interface name or sw_if_index\n");
4770 return -99;
4771 }
4772 if (v4_address_set && v6_address_set)
4773 {
4774 errmsg ("both v4 and v6 addresses set\n");
4775 return -99;
4776 }
4777 if (!v4_address_set && !v6_address_set && !del_all)
4778 {
4779 errmsg ("no addresses set\n");
4780 return -99;
4781 }
4782
4783 /* Construct the API message */
4784 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4785
4786 mp->sw_if_index = ntohl (sw_if_index);
4787 mp->is_add = is_add;
4788 mp->del_all = del_all;
4789 if (v6_address_set)
4790 {
4791 mp->is_ipv6 = 1;
4792 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4793 }
4794 else
4795 {
4796 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4797 }
4798 mp->address_length = address_length;
4799
4800 /* send it... */
4801 S;
4802
4803 /* Wait for a reply, return good/bad news */
4804 W;
4805}
4806
4807static int
4808api_sw_interface_set_table (vat_main_t * vam)
4809{
4810 unformat_input_t *i = vam->input;
4811 vl_api_sw_interface_set_table_t *mp;
4812 f64 timeout;
4813 u32 sw_if_index, vrf_id = 0;
4814 u8 sw_if_index_set = 0;
4815 u8 is_ipv6 = 0;
4816
4817 /* Parse args required to build the message */
4818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4819 {
4820 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4821 sw_if_index_set = 1;
4822 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4823 sw_if_index_set = 1;
4824 else if (unformat (i, "vrf %d", &vrf_id))
4825 ;
4826 else if (unformat (i, "ipv6"))
4827 is_ipv6 = 1;
4828 else
4829 break;
4830 }
4831
4832 if (sw_if_index_set == 0)
4833 {
4834 errmsg ("missing interface name or sw_if_index\n");
4835 return -99;
4836 }
4837
4838 /* Construct the API message */
4839 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4840
4841 mp->sw_if_index = ntohl (sw_if_index);
4842 mp->is_ipv6 = is_ipv6;
4843 mp->vrf_id = ntohl (vrf_id);
4844
4845 /* send it... */
4846 S;
4847
4848 /* Wait for a reply... */
4849 W;
4850}
4851
4852static int
4853api_sw_interface_set_vpath (vat_main_t * vam)
4854{
4855 unformat_input_t *i = vam->input;
4856 vl_api_sw_interface_set_vpath_t *mp;
4857 f64 timeout;
4858 u32 sw_if_index = 0;
4859 u8 sw_if_index_set = 0;
4860 u8 is_enable = 0;
4861
4862 /* Parse args required to build the message */
4863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4864 {
4865 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4866 sw_if_index_set = 1;
4867 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4868 sw_if_index_set = 1;
4869 else if (unformat (i, "enable"))
4870 is_enable = 1;
4871 else if (unformat (i, "disable"))
4872 is_enable = 0;
4873 else
4874 break;
4875 }
4876
4877 if (sw_if_index_set == 0)
4878 {
4879 errmsg ("missing interface name or sw_if_index\n");
4880 return -99;
4881 }
4882
4883 /* Construct the API message */
4884 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4885
4886 mp->sw_if_index = ntohl (sw_if_index);
4887 mp->enable = is_enable;
4888
4889 /* send it... */
4890 S;
4891
4892 /* Wait for a reply... */
4893 W;
4894}
4895
4896static int
4897api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4898{
4899 unformat_input_t *i = vam->input;
4900 vl_api_sw_interface_set_l2_xconnect_t *mp;
4901 f64 timeout;
4902 u32 rx_sw_if_index;
4903 u8 rx_sw_if_index_set = 0;
4904 u32 tx_sw_if_index;
4905 u8 tx_sw_if_index_set = 0;
4906 u8 enable = 1;
4907
4908 /* Parse args required to build the message */
4909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4910 {
4911 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4912 rx_sw_if_index_set = 1;
4913 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4914 tx_sw_if_index_set = 1;
4915 else if (unformat (i, "rx"))
4916 {
4917 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4918 {
4919 if (unformat (i, "%U", unformat_sw_if_index, vam,
4920 &rx_sw_if_index))
4921 rx_sw_if_index_set = 1;
4922 }
4923 else
Dave Barach41da02d2016-07-11 16:48:42 -07004924 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004925 }
Dave Barach72d72232016-08-04 10:15:08 -04004926 else if (unformat (i, "tx"))
4927 {
4928 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4929 {
4930 if (unformat (i, "%U", unformat_sw_if_index, vam,
4931 &tx_sw_if_index))
4932 tx_sw_if_index_set = 1;
4933 }
4934 else
4935 break;
4936 }
4937 else if (unformat (i, "enable"))
4938 enable = 1;
4939 else if (unformat (i, "disable"))
4940 enable = 0;
4941 else
4942 break;
Dave Barach41da02d2016-07-11 16:48:42 -07004943 }
4944
Dave Barach72d72232016-08-04 10:15:08 -04004945 if (rx_sw_if_index_set == 0)
4946 {
4947 errmsg ("missing rx interface name or rx_sw_if_index\n");
4948 return -99;
4949 }
Dave Barach41da02d2016-07-11 16:48:42 -07004950
Dave Barach72d72232016-08-04 10:15:08 -04004951 if (enable && (tx_sw_if_index_set == 0))
4952 {
4953 errmsg ("missing tx interface name or tx_sw_if_index\n");
4954 return -99;
4955 }
Dave Barach41da02d2016-07-11 16:48:42 -07004956
Dave Barach72d72232016-08-04 10:15:08 -04004957 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07004958
Dave Barach72d72232016-08-04 10:15:08 -04004959 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4960 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4961 mp->enable = enable;
4962
4963 S;
4964 W;
4965 /* NOTREACHED */
4966 return 0;
4967}
4968
4969static int
4970api_sw_interface_set_l2_bridge (vat_main_t * vam)
4971{
4972 unformat_input_t *i = vam->input;
4973 vl_api_sw_interface_set_l2_bridge_t *mp;
4974 f64 timeout;
4975 u32 rx_sw_if_index;
4976 u8 rx_sw_if_index_set = 0;
4977 u32 bd_id;
4978 u8 bd_id_set = 0;
4979 u8 bvi = 0;
4980 u32 shg = 0;
4981 u8 enable = 1;
4982
4983 /* Parse args required to build the message */
4984 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4985 {
4986 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4987 rx_sw_if_index_set = 1;
4988 else if (unformat (i, "bd_id %d", &bd_id))
4989 bd_id_set = 1;
4990 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
4991 rx_sw_if_index_set = 1;
4992 else if (unformat (i, "shg %d", &shg))
4993 ;
4994 else if (unformat (i, "bvi"))
4995 bvi = 1;
4996 else if (unformat (i, "enable"))
4997 enable = 1;
4998 else if (unformat (i, "disable"))
4999 enable = 0;
5000 else
5001 break;
5002 }
5003
5004 if (rx_sw_if_index_set == 0)
5005 {
5006 errmsg ("missing rx interface name or sw_if_index\n");
5007 return -99;
5008 }
5009
5010 if (enable && (bd_id_set == 0))
5011 {
5012 errmsg ("missing bridge domain\n");
5013 return -99;
5014 }
5015
5016 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5017
5018 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5019 mp->bd_id = ntohl (bd_id);
5020 mp->shg = (u8) shg;
5021 mp->bvi = bvi;
5022 mp->enable = enable;
5023
5024 S;
5025 W;
5026 /* NOTREACHED */
5027 return 0;
5028}
5029
5030static int
5031api_bridge_domain_dump (vat_main_t * vam)
5032{
5033 unformat_input_t *i = vam->input;
5034 vl_api_bridge_domain_dump_t *mp;
5035 f64 timeout;
5036 u32 bd_id = ~0;
5037
5038 /* Parse args required to build the message */
5039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5040 {
5041 if (unformat (i, "bd_id %d", &bd_id))
5042 ;
5043 else
5044 break;
5045 }
5046
5047 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5048 mp->bd_id = ntohl (bd_id);
5049 S;
5050
5051 /* Use a control ping for synchronization */
5052 {
5053 vl_api_control_ping_t *mp;
5054 M (CONTROL_PING, control_ping);
5055 S;
5056 }
5057
5058 W;
5059 /* NOTREACHED */
5060 return 0;
5061}
5062
5063static int
5064api_bridge_domain_add_del (vat_main_t * vam)
5065{
5066 unformat_input_t *i = vam->input;
5067 vl_api_bridge_domain_add_del_t *mp;
5068 f64 timeout;
5069 u32 bd_id = ~0;
5070 u8 is_add = 1;
5071 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5072
5073 /* Parse args required to build the message */
5074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5075 {
5076 if (unformat (i, "bd_id %d", &bd_id))
5077 ;
5078 else if (unformat (i, "flood %d", &flood))
5079 ;
5080 else if (unformat (i, "uu-flood %d", &uu_flood))
5081 ;
5082 else if (unformat (i, "forward %d", &forward))
5083 ;
5084 else if (unformat (i, "learn %d", &learn))
5085 ;
5086 else if (unformat (i, "arp-term %d", &arp_term))
5087 ;
5088 else if (unformat (i, "del"))
5089 {
5090 is_add = 0;
5091 flood = uu_flood = forward = learn = 0;
5092 }
5093 else
5094 break;
5095 }
5096
5097 if (bd_id == ~0)
5098 {
5099 errmsg ("missing bridge domain\n");
5100 return -99;
5101 }
5102
5103 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5104
5105 mp->bd_id = ntohl (bd_id);
5106 mp->flood = flood;
5107 mp->uu_flood = uu_flood;
5108 mp->forward = forward;
5109 mp->learn = learn;
5110 mp->arp_term = arp_term;
5111 mp->is_add = is_add;
5112
5113 S;
5114 W;
5115 /* NOTREACHED */
5116 return 0;
5117}
5118
5119static int
5120api_l2fib_add_del (vat_main_t * vam)
5121{
5122 unformat_input_t *i = vam->input;
5123 vl_api_l2fib_add_del_t *mp;
5124 f64 timeout;
5125 u64 mac = 0;
5126 u8 mac_set = 0;
5127 u32 bd_id;
5128 u8 bd_id_set = 0;
5129 u32 sw_if_index;
5130 u8 sw_if_index_set = 0;
5131 u8 is_add = 1;
5132 u8 static_mac = 0;
5133 u8 filter_mac = 0;
5134 u8 bvi_mac = 0;
5135 int count = 1;
5136 f64 before = 0;
5137 int j;
5138
5139 /* Parse args required to build the message */
5140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5141 {
5142 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5143 mac_set = 1;
5144 else if (unformat (i, "bd_id %d", &bd_id))
5145 bd_id_set = 1;
5146 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5147 sw_if_index_set = 1;
5148 else if (unformat (i, "sw_if"))
5149 {
5150 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5151 {
5152 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5153 sw_if_index_set = 1;
5154 }
5155 else
5156 break;
5157 }
5158 else if (unformat (i, "static"))
5159 static_mac = 1;
5160 else if (unformat (i, "filter"))
5161 {
5162 filter_mac = 1;
5163 static_mac = 1;
5164 }
5165 else if (unformat (i, "bvi"))
5166 {
5167 bvi_mac = 1;
5168 static_mac = 1;
5169 }
5170 else if (unformat (i, "del"))
5171 is_add = 0;
5172 else if (unformat (i, "count %d", &count))
5173 ;
5174 else
5175 break;
5176 }
5177
5178 if (mac_set == 0)
5179 {
5180 errmsg ("missing mac address\n");
5181 return -99;
5182 }
5183
5184 if (bd_id_set == 0)
5185 {
5186 errmsg ("missing bridge domain\n");
5187 return -99;
5188 }
5189
5190 if (is_add && (sw_if_index_set == 0))
5191 {
5192 errmsg ("missing interface name or sw_if_index\n");
5193 return -99;
5194 }
5195
5196 if (count > 1)
5197 {
5198 /* Turn on async mode */
5199 vam->async_mode = 1;
5200 vam->async_errors = 0;
5201 before = vat_time_now (vam);
5202 }
5203
5204 for (j = 0; j < count; j++)
5205 {
5206 M (L2FIB_ADD_DEL, l2fib_add_del);
5207
5208 mp->mac = mac;
5209 mp->bd_id = ntohl (bd_id);
5210 mp->is_add = is_add;
5211
5212 if (is_add)
5213 {
5214 mp->sw_if_index = ntohl (sw_if_index);
5215 mp->static_mac = static_mac;
5216 mp->filter_mac = filter_mac;
5217 mp->bvi_mac = bvi_mac;
5218 }
5219 increment_mac_address (&mac);
5220 /* send it... */
5221 S;
5222 }
5223
5224 if (count > 1)
5225 {
5226 vl_api_control_ping_t *mp;
5227 f64 after;
5228
5229 /* Shut off async mode */
5230 vam->async_mode = 0;
5231
5232 M (CONTROL_PING, control_ping);
5233 S;
5234
5235 timeout = vat_time_now (vam) + 1.0;
5236 while (vat_time_now (vam) < timeout)
5237 if (vam->result_ready == 1)
5238 goto out;
5239 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005240
5241 out:
Dave Barach72d72232016-08-04 10:15:08 -04005242 if (vam->retval == -99)
5243 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005244
Dave Barach72d72232016-08-04 10:15:08 -04005245 if (vam->async_errors > 0)
5246 {
5247 errmsg ("%d asynchronous errors\n", vam->async_errors);
5248 vam->retval = -98;
5249 }
5250 vam->async_errors = 0;
5251 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005252
Dave Barach72d72232016-08-04 10:15:08 -04005253 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5254 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005255 }
Dave Barach72d72232016-08-04 10:15:08 -04005256 else
5257 {
5258 /* Wait for a reply... */
5259 W;
5260 }
5261 /* Return the good/bad news */
5262 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005263}
5264
Dave Barach72d72232016-08-04 10:15:08 -04005265static int
5266api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005267{
Dave Barach72d72232016-08-04 10:15:08 -04005268 unformat_input_t *i = vam->input;
5269 vl_api_l2_flags_t *mp;
5270 f64 timeout;
5271 u32 sw_if_index;
5272 u32 feature_bitmap = 0;
5273 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005274
Dave Barach72d72232016-08-04 10:15:08 -04005275 /* Parse args required to build the message */
5276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5277 {
5278 if (unformat (i, "sw_if_index %d", &sw_if_index))
5279 sw_if_index_set = 1;
5280 else if (unformat (i, "sw_if"))
5281 {
5282 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5283 {
5284 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5285 sw_if_index_set = 1;
5286 }
5287 else
5288 break;
5289 }
5290 else if (unformat (i, "learn"))
5291 feature_bitmap |= L2INPUT_FEAT_LEARN;
5292 else if (unformat (i, "forward"))
5293 feature_bitmap |= L2INPUT_FEAT_FWD;
5294 else if (unformat (i, "flood"))
5295 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5296 else if (unformat (i, "uu-flood"))
5297 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5298 else
5299 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005300 }
5301
Dave Barach72d72232016-08-04 10:15:08 -04005302 if (sw_if_index_set == 0)
5303 {
5304 errmsg ("missing interface name or sw_if_index\n");
5305 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005306 }
5307
Dave Barach72d72232016-08-04 10:15:08 -04005308 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005309
Dave Barach72d72232016-08-04 10:15:08 -04005310 mp->sw_if_index = ntohl (sw_if_index);
5311 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005312
Dave Barach72d72232016-08-04 10:15:08 -04005313 S;
5314 W;
5315 /* NOTREACHED */
5316 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005317}
5318
Dave Barach72d72232016-08-04 10:15:08 -04005319static int
5320api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005321{
Dave Barach72d72232016-08-04 10:15:08 -04005322 unformat_input_t *i = vam->input;
5323 vl_api_bridge_flags_t *mp;
5324 f64 timeout;
5325 u32 bd_id;
5326 u8 bd_id_set = 0;
5327 u8 is_set = 1;
5328 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005329
Dave Barach72d72232016-08-04 10:15:08 -04005330 /* Parse args required to build the message */
5331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5332 {
5333 if (unformat (i, "bd_id %d", &bd_id))
5334 bd_id_set = 1;
5335 else if (unformat (i, "learn"))
5336 flags |= L2_LEARN;
5337 else if (unformat (i, "forward"))
5338 flags |= L2_FWD;
5339 else if (unformat (i, "flood"))
5340 flags |= L2_FLOOD;
5341 else if (unformat (i, "uu-flood"))
5342 flags |= L2_UU_FLOOD;
5343 else if (unformat (i, "arp-term"))
5344 flags |= L2_ARP_TERM;
5345 else if (unformat (i, "off"))
5346 is_set = 0;
5347 else if (unformat (i, "disable"))
5348 is_set = 0;
5349 else
5350 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005351 }
5352
Dave Barach72d72232016-08-04 10:15:08 -04005353 if (bd_id_set == 0)
5354 {
5355 errmsg ("missing bridge domain\n");
5356 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005357 }
5358
Dave Barach72d72232016-08-04 10:15:08 -04005359 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005360
Dave Barach72d72232016-08-04 10:15:08 -04005361 mp->bd_id = ntohl (bd_id);
5362 mp->feature_bitmap = ntohl (flags);
5363 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005364
Dave Barach72d72232016-08-04 10:15:08 -04005365 S;
5366 W;
5367 /* NOTREACHED */
5368 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005369}
5370
Dave Barach72d72232016-08-04 10:15:08 -04005371static int
5372api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005373{
Dave Barach72d72232016-08-04 10:15:08 -04005374 unformat_input_t *i = vam->input;
5375 vl_api_bd_ip_mac_add_del_t *mp;
5376 f64 timeout;
5377 u32 bd_id;
5378 u8 is_ipv6 = 0;
5379 u8 is_add = 1;
5380 u8 bd_id_set = 0;
5381 u8 ip_set = 0;
5382 u8 mac_set = 0;
5383 ip4_address_t v4addr;
5384 ip6_address_t v6addr;
5385 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005386
Ed Warnickecb9cada2015-12-08 15:45:58 -07005387
Dave Barach72d72232016-08-04 10:15:08 -04005388 /* Parse args required to build the message */
5389 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5390 {
5391 if (unformat (i, "bd_id %d", &bd_id))
5392 {
5393 bd_id_set++;
5394 }
5395 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5396 {
5397 ip_set++;
5398 }
5399 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5400 {
5401 ip_set++;
5402 is_ipv6++;
5403 }
5404 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5405 {
5406 mac_set++;
5407 }
5408 else if (unformat (i, "del"))
5409 is_add = 0;
5410 else
5411 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005412 }
5413
Dave Barach72d72232016-08-04 10:15:08 -04005414 if (bd_id_set == 0)
5415 {
5416 errmsg ("missing bridge domain\n");
5417 return -99;
5418 }
5419 else if (ip_set == 0)
5420 {
5421 errmsg ("missing IP address\n");
5422 return -99;
5423 }
5424 else if (mac_set == 0)
5425 {
5426 errmsg ("missing MAC address\n");
5427 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005428 }
5429
Dave Barach72d72232016-08-04 10:15:08 -04005430 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005431
Dave Barach72d72232016-08-04 10:15:08 -04005432 mp->bd_id = ntohl (bd_id);
5433 mp->is_ipv6 = is_ipv6;
5434 mp->is_add = is_add;
5435 if (is_ipv6)
5436 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5437 else
5438 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5439 clib_memcpy (mp->mac_address, macaddr, 6);
5440 S;
5441 W;
5442 /* NOTREACHED */
5443 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005444}
5445
Dave Barach72d72232016-08-04 10:15:08 -04005446static int
5447api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005448{
Dave Barach72d72232016-08-04 10:15:08 -04005449 unformat_input_t *i = vam->input;
5450 vl_api_tap_connect_t *mp;
5451 f64 timeout;
5452 u8 mac_address[6];
5453 u8 random_mac = 1;
5454 u8 name_set = 0;
5455 u8 *tap_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005456
Dave Barach72d72232016-08-04 10:15:08 -04005457 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005458
Dave Barach72d72232016-08-04 10:15:08 -04005459 /* Parse args required to build the message */
5460 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5461 {
5462 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5463 {
5464 random_mac = 0;
5465 }
5466 else if (unformat (i, "random-mac"))
5467 random_mac = 1;
5468 else if (unformat (i, "tapname %s", &tap_name))
5469 name_set = 1;
5470 else
5471 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005472 }
5473
Dave Barach72d72232016-08-04 10:15:08 -04005474 if (name_set == 0)
5475 {
5476 errmsg ("missing tap name\n");
5477 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005478 }
Dave Barach72d72232016-08-04 10:15:08 -04005479 if (vec_len (tap_name) > 63)
5480 {
5481 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005482 }
Dave Barach72d72232016-08-04 10:15:08 -04005483 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005484
Dave Barach72d72232016-08-04 10:15:08 -04005485 /* Construct the API message */
5486 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005487
Dave Barach72d72232016-08-04 10:15:08 -04005488 mp->use_random_mac = random_mac;
5489 clib_memcpy (mp->mac_address, mac_address, 6);
5490 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5491 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005492
Dave Barach72d72232016-08-04 10:15:08 -04005493 /* send it... */
5494 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005495
Dave Barach72d72232016-08-04 10:15:08 -04005496 /* Wait for a reply... */
5497 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005498}
5499
Dave Barach72d72232016-08-04 10:15:08 -04005500static int
5501api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005502{
Dave Barach72d72232016-08-04 10:15:08 -04005503 unformat_input_t *i = vam->input;
5504 vl_api_tap_modify_t *mp;
5505 f64 timeout;
5506 u8 mac_address[6];
5507 u8 random_mac = 1;
5508 u8 name_set = 0;
5509 u8 *tap_name;
5510 u32 sw_if_index = ~0;
5511 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005512
Dave Barach72d72232016-08-04 10:15:08 -04005513 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005514
Dave Barach72d72232016-08-04 10:15:08 -04005515 /* Parse args required to build the message */
5516 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5517 {
5518 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5519 sw_if_index_set = 1;
5520 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5521 sw_if_index_set = 1;
5522 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5523 {
5524 random_mac = 0;
5525 }
5526 else if (unformat (i, "random-mac"))
5527 random_mac = 1;
5528 else if (unformat (i, "tapname %s", &tap_name))
5529 name_set = 1;
5530 else
5531 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005532 }
5533
Dave Barach72d72232016-08-04 10:15:08 -04005534 if (sw_if_index_set == 0)
5535 {
5536 errmsg ("missing vpp interface name");
5537 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005538 }
Dave Barach72d72232016-08-04 10:15:08 -04005539 if (name_set == 0)
5540 {
5541 errmsg ("missing tap name\n");
5542 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005543 }
Dave Barach72d72232016-08-04 10:15:08 -04005544 if (vec_len (tap_name) > 63)
5545 {
5546 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005547 }
Dave Barach72d72232016-08-04 10:15:08 -04005548 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005549
Dave Barach72d72232016-08-04 10:15:08 -04005550 /* Construct the API message */
5551 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005552
Dave Barach72d72232016-08-04 10:15:08 -04005553 mp->use_random_mac = random_mac;
5554 mp->sw_if_index = ntohl (sw_if_index);
5555 clib_memcpy (mp->mac_address, mac_address, 6);
5556 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5557 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005558
Dave Barach72d72232016-08-04 10:15:08 -04005559 /* send it... */
5560 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005561
Dave Barach72d72232016-08-04 10:15:08 -04005562 /* Wait for a reply... */
5563 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005564}
5565
Dave Barach72d72232016-08-04 10:15:08 -04005566static int
5567api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005568{
Dave Barach72d72232016-08-04 10:15:08 -04005569 unformat_input_t *i = vam->input;
5570 vl_api_tap_delete_t *mp;
5571 f64 timeout;
5572 u32 sw_if_index = ~0;
5573 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005574
Dave Barach72d72232016-08-04 10:15:08 -04005575 /* Parse args required to build the message */
5576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5577 {
5578 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5579 sw_if_index_set = 1;
5580 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5581 sw_if_index_set = 1;
5582 else
5583 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005584 }
5585
Dave Barach72d72232016-08-04 10:15:08 -04005586 if (sw_if_index_set == 0)
5587 {
5588 errmsg ("missing vpp interface name");
5589 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005590 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005591
Dave Barach72d72232016-08-04 10:15:08 -04005592 /* Construct the API message */
5593 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005594
Dave Barach72d72232016-08-04 10:15:08 -04005595 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005596
Dave Barach72d72232016-08-04 10:15:08 -04005597 /* send it... */
5598 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005599
Dave Barach72d72232016-08-04 10:15:08 -04005600 /* Wait for a reply... */
5601 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005602}
5603
Dave Barach72d72232016-08-04 10:15:08 -04005604static int
5605api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005606{
Dave Barach72d72232016-08-04 10:15:08 -04005607 unformat_input_t *i = vam->input;
5608 vl_api_ip_add_del_route_t *mp;
5609 f64 timeout;
5610 u32 sw_if_index = ~0, vrf_id = 0;
5611 u8 sw_if_index_set = 0;
5612 u8 is_ipv6 = 0;
5613 u8 is_local = 0, is_drop = 0;
5614 u8 create_vrf_if_needed = 0;
5615 u8 is_add = 1;
5616 u8 next_hop_weight = 1;
5617 u8 not_last = 0;
5618 u8 is_multipath = 0;
5619 u8 address_set = 0;
5620 u8 address_length_set = 0;
5621 u32 lookup_in_vrf = 0;
5622 u32 resolve_attempts = 0;
5623 u32 dst_address_length = 0;
5624 u8 next_hop_set = 0;
5625 ip4_address_t v4_dst_address, v4_next_hop_address;
5626 ip6_address_t v6_dst_address, v6_next_hop_address;
5627 int count = 1;
5628 int j;
5629 f64 before = 0;
5630 u32 random_add_del = 0;
5631 u32 *random_vector = 0;
5632 uword *random_hash;
5633 u32 random_seed = 0xdeaddabe;
5634 u32 classify_table_index = ~0;
5635 u8 is_classify = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005636 u8 resolve_host, resolve_attached;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005637
Dave Barach72d72232016-08-04 10:15:08 -04005638 /* Parse args required to build the message */
5639 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5640 {
5641 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5642 sw_if_index_set = 1;
5643 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5644 sw_if_index_set = 1;
5645 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5646 {
5647 address_set = 1;
5648 is_ipv6 = 0;
5649 }
5650 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5651 {
5652 address_set = 1;
5653 is_ipv6 = 1;
5654 }
5655 else if (unformat (i, "/%d", &dst_address_length))
5656 {
5657 address_length_set = 1;
5658 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005659
Dave Barach72d72232016-08-04 10:15:08 -04005660 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5661 &v4_next_hop_address))
5662 {
5663 next_hop_set = 1;
5664 }
5665 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5666 &v6_next_hop_address))
5667 {
5668 next_hop_set = 1;
5669 }
5670 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5671 ;
5672 else if (unformat (i, "weight %d", &next_hop_weight))
5673 ;
5674 else if (unformat (i, "drop"))
5675 {
5676 is_drop = 1;
5677 }
5678 else if (unformat (i, "local"))
5679 {
5680 is_local = 1;
5681 }
5682 else if (unformat (i, "classify %d", &classify_table_index))
5683 {
5684 is_classify = 1;
5685 }
5686 else if (unformat (i, "del"))
5687 is_add = 0;
5688 else if (unformat (i, "add"))
5689 is_add = 1;
5690 else if (unformat (i, "not-last"))
5691 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005692 else if (unformat (i, "resolve-via-host"))
5693 resolve_host = 1;
5694 else if (unformat (i, "resolve-via-attached"))
5695 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005696 else if (unformat (i, "multipath"))
5697 is_multipath = 1;
5698 else if (unformat (i, "vrf %d", &vrf_id))
5699 ;
5700 else if (unformat (i, "create-vrf"))
5701 create_vrf_if_needed = 1;
5702 else if (unformat (i, "count %d", &count))
5703 ;
5704 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
5705 ;
5706 else if (unformat (i, "random"))
5707 random_add_del = 1;
5708 else if (unformat (i, "seed %d", &random_seed))
5709 ;
5710 else
5711 {
5712 clib_warning ("parse error '%U'", format_unformat_error, i);
5713 return -99;
5714 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005715 }
5716
Dave Barach72d72232016-08-04 10:15:08 -04005717 if (resolve_attempts > 0 && sw_if_index_set == 0)
5718 {
5719 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
5720 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005721 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005722
Dave Barach72d72232016-08-04 10:15:08 -04005723 if (!next_hop_set && !is_drop && !is_local && !is_classify)
5724 {
5725 errmsg ("next hop / local / drop / classify not set\n");
5726 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005727 }
5728
Dave Barach72d72232016-08-04 10:15:08 -04005729 if (address_set == 0)
5730 {
5731 errmsg ("missing addresses\n");
5732 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005733 }
5734
Dave Barach72d72232016-08-04 10:15:08 -04005735 if (address_length_set == 0)
5736 {
5737 errmsg ("missing address length\n");
5738 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005739 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005740
Dave Barach72d72232016-08-04 10:15:08 -04005741 /* Generate a pile of unique, random routes */
5742 if (random_add_del)
5743 {
5744 u32 this_random_address;
5745 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005746
Dave Barach72d72232016-08-04 10:15:08 -04005747 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5748 for (j = 0; j <= count; j++)
5749 {
5750 do
5751 {
5752 this_random_address = random_u32 (&random_seed);
5753 this_random_address =
5754 clib_host_to_net_u32 (this_random_address);
5755 }
5756 while (hash_get (random_hash, this_random_address));
5757 vec_add1 (random_vector, this_random_address);
5758 hash_set (random_hash, this_random_address, 1);
5759 }
5760 hash_free (random_hash);
5761 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005762 }
5763
Dave Barach72d72232016-08-04 10:15:08 -04005764 if (count > 1)
5765 {
5766 /* Turn on async mode */
5767 vam->async_mode = 1;
5768 vam->async_errors = 0;
5769 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005770 }
5771
Dave Barach72d72232016-08-04 10:15:08 -04005772 for (j = 0; j < count; j++)
5773 {
5774 /* Construct the API message */
5775 M (IP_ADD_DEL_ROUTE, ip_add_del_route);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005776
Dave Barach72d72232016-08-04 10:15:08 -04005777 mp->next_hop_sw_if_index = ntohl (sw_if_index);
5778 mp->vrf_id = ntohl (vrf_id);
5779 if (resolve_attempts > 0)
5780 {
5781 mp->resolve_attempts = ntohl (resolve_attempts);
5782 mp->resolve_if_needed = 1;
5783 }
5784 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005785
Dave Barach72d72232016-08-04 10:15:08 -04005786 mp->is_add = is_add;
5787 mp->is_drop = is_drop;
5788 mp->is_ipv6 = is_ipv6;
5789 mp->is_local = is_local;
5790 mp->is_classify = is_classify;
5791 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005792 mp->is_resolve_host = resolve_host;
5793 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005794 mp->not_last = not_last;
5795 mp->next_hop_weight = next_hop_weight;
5796 mp->dst_address_length = dst_address_length;
5797 mp->lookup_in_vrf = ntohl (lookup_in_vrf);
5798 mp->classify_table_index = ntohl (classify_table_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005799
Dave Barach72d72232016-08-04 10:15:08 -04005800 if (is_ipv6)
5801 {
5802 clib_memcpy (mp->dst_address, &v6_dst_address,
5803 sizeof (v6_dst_address));
5804 if (next_hop_set)
5805 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
5806 sizeof (v6_next_hop_address));
5807 increment_v6_address (&v6_dst_address);
5808 }
5809 else
5810 {
5811 clib_memcpy (mp->dst_address, &v4_dst_address,
5812 sizeof (v4_dst_address));
5813 if (next_hop_set)
5814 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
5815 sizeof (v4_next_hop_address));
5816 if (random_add_del)
5817 v4_dst_address.as_u32 = random_vector[j + 1];
5818 else
5819 increment_v4_address (&v4_dst_address);
5820 }
5821 /* send it... */
5822 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005823 }
5824
Dave Barach72d72232016-08-04 10:15:08 -04005825 /* When testing multiple add/del ops, use a control-ping to sync */
5826 if (count > 1)
5827 {
5828 vl_api_control_ping_t *mp;
5829 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005830
Dave Barach72d72232016-08-04 10:15:08 -04005831 /* Shut off async mode */
5832 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005833
Dave Barach72d72232016-08-04 10:15:08 -04005834 M (CONTROL_PING, control_ping);
5835 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005836
Dave Barach72d72232016-08-04 10:15:08 -04005837 timeout = vat_time_now (vam) + 1.0;
5838 while (vat_time_now (vam) < timeout)
5839 if (vam->result_ready == 1)
5840 goto out;
5841 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005842
5843 out:
Dave Barach72d72232016-08-04 10:15:08 -04005844 if (vam->retval == -99)
5845 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005846
Dave Barach72d72232016-08-04 10:15:08 -04005847 if (vam->async_errors > 0)
5848 {
5849 errmsg ("%d asynchronous errors\n", vam->async_errors);
5850 vam->retval = -98;
5851 }
5852 vam->async_errors = 0;
5853 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005854
Dave Barach72d72232016-08-04 10:15:08 -04005855 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5856 count, after - before, count / (after - before));
5857 }
5858 else
5859 {
5860 /* Wait for a reply... */
5861 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005862 }
5863
Dave Barach72d72232016-08-04 10:15:08 -04005864 /* Return the good/bad news */
5865 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005866}
5867
Dave Barach72d72232016-08-04 10:15:08 -04005868static int
5869api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005870{
Dave Barach72d72232016-08-04 10:15:08 -04005871 unformat_input_t *i = vam->input;
5872 vl_api_proxy_arp_add_del_t *mp;
5873 f64 timeout;
5874 u32 vrf_id = 0;
5875 u8 is_add = 1;
5876 ip4_address_t lo, hi;
5877 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005878
Dave Barach72d72232016-08-04 10:15:08 -04005879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5880 {
5881 if (unformat (i, "vrf %d", &vrf_id))
5882 ;
5883 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
5884 unformat_ip4_address, &hi))
5885 range_set = 1;
5886 else if (unformat (i, "del"))
5887 is_add = 0;
5888 else
5889 {
5890 clib_warning ("parse error '%U'", format_unformat_error, i);
5891 return -99;
5892 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005893 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005894
Dave Barach72d72232016-08-04 10:15:08 -04005895 if (range_set == 0)
5896 {
5897 errmsg ("address range not set\n");
5898 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005899 }
5900
Dave Barach72d72232016-08-04 10:15:08 -04005901 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005902
Dave Barach72d72232016-08-04 10:15:08 -04005903 mp->vrf_id = ntohl (vrf_id);
5904 mp->is_add = is_add;
5905 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
5906 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005907
Dave Barach72d72232016-08-04 10:15:08 -04005908 S;
5909 W;
5910 /* NOTREACHED */
5911 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005912}
5913
Dave Barach72d72232016-08-04 10:15:08 -04005914static int
5915api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005916{
Dave Barach72d72232016-08-04 10:15:08 -04005917 unformat_input_t *i = vam->input;
5918 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5919 f64 timeout;
5920 u32 sw_if_index;
5921 u8 enable = 1;
5922 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005923
Dave Barach72d72232016-08-04 10:15:08 -04005924 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5925 {
5926 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5927 sw_if_index_set = 1;
5928 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5929 sw_if_index_set = 1;
5930 else if (unformat (i, "enable"))
5931 enable = 1;
5932 else if (unformat (i, "disable"))
5933 enable = 0;
5934 else
5935 {
5936 clib_warning ("parse error '%U'", format_unformat_error, i);
5937 return -99;
5938 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005939 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005940
Dave Barach72d72232016-08-04 10:15:08 -04005941 if (sw_if_index_set == 0)
5942 {
5943 errmsg ("missing interface name or sw_if_index\n");
5944 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005945 }
5946
Dave Barach72d72232016-08-04 10:15:08 -04005947 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005948
Dave Barach72d72232016-08-04 10:15:08 -04005949 mp->sw_if_index = ntohl (sw_if_index);
5950 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005951
Dave Barach72d72232016-08-04 10:15:08 -04005952 S;
5953 W;
5954 /* NOTREACHED */
5955 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005956}
5957
Dave Barach72d72232016-08-04 10:15:08 -04005958static int
5959api_mpls_add_del_decap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005960{
Dave Barach72d72232016-08-04 10:15:08 -04005961 unformat_input_t *i = vam->input;
5962 vl_api_mpls_add_del_decap_t *mp;
5963 f64 timeout;
5964 u32 rx_vrf_id = 0;
5965 u32 tx_vrf_id = 0;
5966 u32 label = 0;
5967 u8 is_add = 1;
5968 u8 s_bit = 1;
5969 u32 next_index = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005970
Dave Barach72d72232016-08-04 10:15:08 -04005971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5972 {
5973 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5974 ;
5975 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5976 ;
5977 else if (unformat (i, "label %d", &label))
5978 ;
5979 else if (unformat (i, "next-index %d", &next_index))
5980 ;
5981 else if (unformat (i, "del"))
5982 is_add = 0;
5983 else if (unformat (i, "s-bit-clear"))
5984 s_bit = 0;
5985 else
5986 {
5987 clib_warning ("parse error '%U'", format_unformat_error, i);
5988 return -99;
5989 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005990 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005991
Dave Barach72d72232016-08-04 10:15:08 -04005992 M (MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005993
Dave Barach72d72232016-08-04 10:15:08 -04005994 mp->rx_vrf_id = ntohl (rx_vrf_id);
5995 mp->tx_vrf_id = ntohl (tx_vrf_id);
5996 mp->label = ntohl (label);
5997 mp->next_index = ntohl (next_index);
5998 mp->s_bit = s_bit;
5999 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006000
Dave Barach72d72232016-08-04 10:15:08 -04006001 S;
6002 W;
6003 /* NOTREACHED */
6004 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006005}
6006
Dave Barach72d72232016-08-04 10:15:08 -04006007static int
6008api_mpls_add_del_encap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006009{
Dave Barach72d72232016-08-04 10:15:08 -04006010 unformat_input_t *i = vam->input;
6011 vl_api_mpls_add_del_encap_t *mp;
6012 f64 timeout;
6013 u32 vrf_id = 0;
6014 u32 *labels = 0;
6015 u32 label;
6016 ip4_address_t dst_address;
6017 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006018
Dave Barach72d72232016-08-04 10:15:08 -04006019 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6020 {
6021 if (unformat (i, "vrf %d", &vrf_id))
6022 ;
6023 else if (unformat (i, "label %d", &label))
6024 vec_add1 (labels, ntohl (label));
6025 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6026 ;
6027 else if (unformat (i, "del"))
6028 is_add = 0;
6029 else
6030 {
6031 clib_warning ("parse error '%U'", format_unformat_error, i);
6032 return -99;
6033 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006034 }
6035
Dave Barach72d72232016-08-04 10:15:08 -04006036 if (vec_len (labels) == 0)
6037 {
6038 errmsg ("missing encap label stack\n");
6039 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006040 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006041
Dave Barach72d72232016-08-04 10:15:08 -04006042 M2 (MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
6043 sizeof (u32) * vec_len (labels));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006044
Dave Barach72d72232016-08-04 10:15:08 -04006045 mp->vrf_id = ntohl (vrf_id);
6046 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6047 mp->is_add = is_add;
6048 mp->nlabels = vec_len (labels);
6049 clib_memcpy (mp->labels, labels, sizeof (u32) * mp->nlabels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006050
Dave Barach72d72232016-08-04 10:15:08 -04006051 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006052
Dave Barach72d72232016-08-04 10:15:08 -04006053 S;
6054 W;
6055 /* NOTREACHED */
6056 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006057}
6058
Dave Barach72d72232016-08-04 10:15:08 -04006059static int
6060api_mpls_gre_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006061{
Dave Barach72d72232016-08-04 10:15:08 -04006062 unformat_input_t *i = vam->input;
6063 vl_api_mpls_gre_add_del_tunnel_t *mp;
6064 f64 timeout;
6065 u32 inner_vrf_id = 0;
6066 u32 outer_vrf_id = 0;
6067 ip4_address_t src_address;
6068 ip4_address_t dst_address;
6069 ip4_address_t intfc_address;
6070 u32 tmp;
6071 u8 intfc_address_length = 0;
6072 u8 is_add = 1;
6073 u8 l2_only = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006074
Dave Barach72d72232016-08-04 10:15:08 -04006075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6076 {
6077 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6078 ;
6079 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6080 ;
6081 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
6082 ;
6083 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6084 ;
6085 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6086 &intfc_address, &tmp))
6087 intfc_address_length = tmp;
6088 else if (unformat (i, "l2-only"))
6089 l2_only = 1;
6090 else if (unformat (i, "del"))
6091 is_add = 0;
6092 else
6093 {
6094 clib_warning ("parse error '%U'", format_unformat_error, i);
6095 return -99;
6096 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006097 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006098
Dave Barach72d72232016-08-04 10:15:08 -04006099 M (MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006100
Dave Barach72d72232016-08-04 10:15:08 -04006101 mp->inner_vrf_id = ntohl (inner_vrf_id);
6102 mp->outer_vrf_id = ntohl (outer_vrf_id);
6103 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
6104 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6105 clib_memcpy (mp->intfc_address, &intfc_address, sizeof (intfc_address));
6106 mp->intfc_address_length = intfc_address_length;
6107 mp->l2_only = l2_only;
6108 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006109
Dave Barach72d72232016-08-04 10:15:08 -04006110 S;
6111 W;
6112 /* NOTREACHED */
6113 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006114}
6115
Dave Barach72d72232016-08-04 10:15:08 -04006116static int
6117api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006118{
Dave Barach72d72232016-08-04 10:15:08 -04006119 unformat_input_t *i = vam->input;
6120 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
6121 f64 timeout;
6122 u32 inner_vrf_id = 0;
6123 ip4_address_t intfc_address;
6124 u8 dst_mac_address[6];
6125 int dst_set = 1;
6126 u32 tmp;
6127 u8 intfc_address_length = 0;
6128 u8 is_add = 1;
6129 u8 l2_only = 0;
6130 u32 tx_sw_if_index;
6131 int tx_sw_if_index_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006132
Dave Barach72d72232016-08-04 10:15:08 -04006133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6134 {
6135 if (unformat (i, "vrf %d", &inner_vrf_id))
6136 ;
6137 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6138 &intfc_address, &tmp))
6139 intfc_address_length = tmp;
6140 else if (unformat (i, "%U", unformat_sw_if_index, vam, &tx_sw_if_index))
6141 tx_sw_if_index_set = 1;
6142 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6143 tx_sw_if_index_set = 1;
6144 else if (unformat (i, "dst %U", unformat_ethernet_address,
6145 dst_mac_address))
6146 dst_set = 1;
6147 else if (unformat (i, "l2-only"))
6148 l2_only = 1;
6149 else if (unformat (i, "del"))
6150 is_add = 0;
6151 else
6152 {
6153 clib_warning ("parse error '%U'", format_unformat_error, i);
6154 return -99;
6155 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006156 }
6157
Dave Barach72d72232016-08-04 10:15:08 -04006158 if (!dst_set)
6159 {
6160 errmsg ("dst (mac address) not set\n");
6161 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006162 }
Dave Barach72d72232016-08-04 10:15:08 -04006163 if (!tx_sw_if_index_set)
6164 {
6165 errmsg ("tx-intfc not set\n");
6166 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006167 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006168
Dave Barach72d72232016-08-04 10:15:08 -04006169 M (MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006170
Dave Barach72d72232016-08-04 10:15:08 -04006171 mp->vrf_id = ntohl (inner_vrf_id);
6172 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
6173 mp->adj_address_length = intfc_address_length;
6174 clib_memcpy (mp->dst_mac_address, dst_mac_address,
6175 sizeof (dst_mac_address));
6176 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6177 mp->l2_only = l2_only;
6178 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006179
Dave Barach72d72232016-08-04 10:15:08 -04006180 S;
6181 W;
6182 /* NOTREACHED */
6183 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006184}
6185
Dave Barach72d72232016-08-04 10:15:08 -04006186static int
6187api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006188{
Dave Barach72d72232016-08-04 10:15:08 -04006189 unformat_input_t *i = vam->input;
6190 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
6191 f64 timeout;
6192 u32 inner_vrf_id = 0;
6193 u32 outer_vrf_id = 0;
6194 ip4_address_t adj_address;
6195 int adj_address_set = 0;
6196 ip4_address_t next_hop_address;
6197 int next_hop_address_set = 0;
6198 u32 tmp;
6199 u8 adj_address_length = 0;
6200 u8 l2_only = 0;
6201 u8 is_add = 1;
6202 u32 resolve_attempts = 5;
6203 u8 resolve_if_needed = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006204
Dave Barach72d72232016-08-04 10:15:08 -04006205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6206 {
6207 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6208 ;
6209 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6210 ;
6211 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6212 &adj_address, &tmp))
6213 {
6214 adj_address_length = tmp;
6215 adj_address_set = 1;
6216 }
6217 else if (unformat (i, "next-hop %U", unformat_ip4_address,
6218 &next_hop_address))
6219 next_hop_address_set = 1;
6220 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6221 ;
6222 else if (unformat (i, "resolve-if-needed %d", &tmp))
6223 resolve_if_needed = tmp;
6224 else if (unformat (i, "l2-only"))
6225 l2_only = 1;
6226 else if (unformat (i, "del"))
6227 is_add = 0;
6228 else
6229 {
6230 clib_warning ("parse error '%U'", format_unformat_error, i);
6231 return -99;
6232 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006233 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006234
Dave Barach72d72232016-08-04 10:15:08 -04006235 if (!adj_address_set)
6236 {
6237 errmsg ("adjacency address/mask not set\n");
6238 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006239 }
Dave Barach72d72232016-08-04 10:15:08 -04006240 if (!next_hop_address_set)
6241 {
6242 errmsg ("ip4 next hop address (in outer fib) not set\n");
6243 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006244 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006245
Dave Barach72d72232016-08-04 10:15:08 -04006246 M (MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006247
Dave Barach72d72232016-08-04 10:15:08 -04006248 mp->inner_vrf_id = ntohl (inner_vrf_id);
6249 mp->outer_vrf_id = ntohl (outer_vrf_id);
6250 mp->resolve_attempts = ntohl (resolve_attempts);
6251 mp->resolve_if_needed = resolve_if_needed;
6252 mp->is_add = is_add;
6253 mp->l2_only = l2_only;
6254 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
6255 mp->adj_address_length = adj_address_length;
6256 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
6257 sizeof (next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006258
Dave Barach72d72232016-08-04 10:15:08 -04006259 S;
6260 W;
6261 /* NOTREACHED */
6262 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006263}
6264
Dave Barach72d72232016-08-04 10:15:08 -04006265static int
6266api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006267{
Dave Barach72d72232016-08-04 10:15:08 -04006268 unformat_input_t *i = vam->input;
6269 vl_api_sw_interface_set_unnumbered_t *mp;
6270 f64 timeout;
6271 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006272 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006273 u8 is_add = 1;
6274 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006275
Dave Barach72d72232016-08-04 10:15:08 -04006276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6277 {
6278 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6279 sw_if_index_set = 1;
6280 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6281 sw_if_index_set = 1;
6282 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6283 ;
6284 else if (unformat (i, "del"))
6285 is_add = 0;
6286 else
6287 {
6288 clib_warning ("parse error '%U'", format_unformat_error, i);
6289 return -99;
6290 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006291 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006292
Dave Barach72d72232016-08-04 10:15:08 -04006293 if (sw_if_index_set == 0)
6294 {
6295 errmsg ("missing interface name or sw_if_index\n");
6296 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006297 }
6298
Dave Barach72d72232016-08-04 10:15:08 -04006299 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006300
Dave Barach72d72232016-08-04 10:15:08 -04006301 mp->sw_if_index = ntohl (sw_if_index);
6302 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6303 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006304
Dave Barach72d72232016-08-04 10:15:08 -04006305 S;
6306 W;
6307 /* NOTREACHED */
6308 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006309}
6310
Dave Barach72d72232016-08-04 10:15:08 -04006311static int
6312api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006313{
Dave Barach72d72232016-08-04 10:15:08 -04006314 unformat_input_t *i = vam->input;
6315 vl_api_ip_neighbor_add_del_t *mp;
6316 f64 timeout;
6317 u32 sw_if_index;
6318 u8 sw_if_index_set = 0;
6319 u32 vrf_id = 0;
6320 u8 is_add = 1;
6321 u8 is_static = 0;
6322 u8 mac_address[6];
6323 u8 mac_set = 0;
6324 u8 v4_address_set = 0;
6325 u8 v6_address_set = 0;
6326 ip4_address_t v4address;
6327 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006328
Dave Barach72d72232016-08-04 10:15:08 -04006329 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006330
Dave Barach72d72232016-08-04 10:15:08 -04006331 /* Parse args required to build the message */
6332 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6333 {
6334 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6335 {
6336 mac_set = 1;
6337 }
6338 else if (unformat (i, "del"))
6339 is_add = 0;
6340 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6341 sw_if_index_set = 1;
6342 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6343 sw_if_index_set = 1;
6344 else if (unformat (i, "is_static"))
6345 is_static = 1;
6346 else if (unformat (i, "vrf %d", &vrf_id))
6347 ;
6348 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6349 v4_address_set = 1;
6350 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6351 v6_address_set = 1;
6352 else
6353 {
6354 clib_warning ("parse error '%U'", format_unformat_error, i);
6355 return -99;
6356 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006357 }
6358
Dave Barach72d72232016-08-04 10:15:08 -04006359 if (sw_if_index_set == 0)
6360 {
6361 errmsg ("missing interface name or sw_if_index\n");
6362 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006363 }
Dave Barach72d72232016-08-04 10:15:08 -04006364 if (v4_address_set && v6_address_set)
6365 {
6366 errmsg ("both v4 and v6 addresses set\n");
6367 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006368 }
Dave Barach72d72232016-08-04 10:15:08 -04006369 if (!v4_address_set && !v6_address_set)
6370 {
6371 errmsg ("no address set\n");
6372 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006373 }
6374
Dave Barach72d72232016-08-04 10:15:08 -04006375 /* Construct the API message */
6376 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006377
Dave Barach72d72232016-08-04 10:15:08 -04006378 mp->sw_if_index = ntohl (sw_if_index);
6379 mp->is_add = is_add;
6380 mp->vrf_id = ntohl (vrf_id);
6381 mp->is_static = is_static;
6382 if (mac_set)
6383 clib_memcpy (mp->mac_address, mac_address, 6);
6384 if (v6_address_set)
6385 {
6386 mp->is_ipv6 = 1;
6387 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6388 }
6389 else
6390 {
6391 /* mp->is_ipv6 = 0; via memset in M macro above */
6392 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006393 }
6394
Dave Barach72d72232016-08-04 10:15:08 -04006395 /* send it... */
6396 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006397
Dave Barach72d72232016-08-04 10:15:08 -04006398 /* Wait for a reply, return good/bad news */
6399 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006400
Dave Barach72d72232016-08-04 10:15:08 -04006401 /* NOTREACHED */
6402 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006403}
6404
Dave Barach72d72232016-08-04 10:15:08 -04006405static int
6406api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006407{
Dave Barach72d72232016-08-04 10:15:08 -04006408 unformat_input_t *i = vam->input;
6409 vl_api_reset_vrf_t *mp;
6410 f64 timeout;
6411 u32 vrf_id = 0;
6412 u8 is_ipv6 = 0;
6413 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006414
Dave Barach72d72232016-08-04 10:15:08 -04006415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6416 {
6417 if (unformat (i, "vrf %d", &vrf_id))
6418 vrf_id_set = 1;
6419 else if (unformat (i, "ipv6"))
6420 is_ipv6 = 1;
6421 else
6422 {
6423 clib_warning ("parse error '%U'", format_unformat_error, i);
6424 return -99;
6425 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006426 }
6427
Dave Barach72d72232016-08-04 10:15:08 -04006428 if (vrf_id_set == 0)
6429 {
6430 errmsg ("missing vrf id\n");
6431 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006432 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006433
Dave Barach72d72232016-08-04 10:15:08 -04006434 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006435
Dave Barach72d72232016-08-04 10:15:08 -04006436 mp->vrf_id = ntohl (vrf_id);
6437 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006438
Dave Barach72d72232016-08-04 10:15:08 -04006439 S;
6440 W;
6441 /* NOTREACHED */
6442 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006443}
6444
Dave Barach72d72232016-08-04 10:15:08 -04006445static int
6446api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006447{
Dave Barach72d72232016-08-04 10:15:08 -04006448 unformat_input_t *i = vam->input;
6449 vl_api_create_vlan_subif_t *mp;
6450 f64 timeout;
6451 u32 sw_if_index;
6452 u8 sw_if_index_set = 0;
6453 u32 vlan_id;
6454 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006455
Dave Barach72d72232016-08-04 10:15:08 -04006456 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6457 {
6458 if (unformat (i, "sw_if_index %d", &sw_if_index))
6459 sw_if_index_set = 1;
6460 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6461 sw_if_index_set = 1;
6462 else if (unformat (i, "vlan %d", &vlan_id))
6463 vlan_id_set = 1;
6464 else
6465 {
6466 clib_warning ("parse error '%U'", format_unformat_error, i);
6467 return -99;
6468 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006469 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006470
Dave Barach72d72232016-08-04 10:15:08 -04006471 if (sw_if_index_set == 0)
6472 {
6473 errmsg ("missing interface name or sw_if_index\n");
6474 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006475 }
6476
Dave Barach72d72232016-08-04 10:15:08 -04006477 if (vlan_id_set == 0)
6478 {
6479 errmsg ("missing vlan_id\n");
6480 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006481 }
Dave Barach72d72232016-08-04 10:15:08 -04006482 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006483
Dave Barach72d72232016-08-04 10:15:08 -04006484 mp->sw_if_index = ntohl (sw_if_index);
6485 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006486
Dave Barach72d72232016-08-04 10:15:08 -04006487 S;
6488 W;
6489 /* NOTREACHED */
6490 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006491}
6492
6493#define foreach_create_subif_bit \
6494_(no_tags) \
6495_(one_tag) \
6496_(two_tags) \
6497_(dot1ad) \
6498_(exact_match) \
6499_(default_sub) \
6500_(outer_vlan_id_any) \
6501_(inner_vlan_id_any)
6502
Dave Barach72d72232016-08-04 10:15:08 -04006503static int
6504api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006505{
Dave Barach72d72232016-08-04 10:15:08 -04006506 unformat_input_t *i = vam->input;
6507 vl_api_create_subif_t *mp;
6508 f64 timeout;
6509 u32 sw_if_index;
6510 u8 sw_if_index_set = 0;
6511 u32 sub_id;
6512 u8 sub_id_set = 0;
6513 u32 no_tags = 0;
6514 u32 one_tag = 0;
6515 u32 two_tags = 0;
6516 u32 dot1ad = 0;
6517 u32 exact_match = 0;
6518 u32 default_sub = 0;
6519 u32 outer_vlan_id_any = 0;
6520 u32 inner_vlan_id_any = 0;
6521 u32 tmp;
6522 u16 outer_vlan_id = 0;
6523 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006524
Dave Barach72d72232016-08-04 10:15:08 -04006525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6526 {
6527 if (unformat (i, "sw_if_index %d", &sw_if_index))
6528 sw_if_index_set = 1;
6529 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6530 sw_if_index_set = 1;
6531 else if (unformat (i, "sub_id %d", &sub_id))
6532 sub_id_set = 1;
6533 else if (unformat (i, "outer_vlan_id %d", &tmp))
6534 outer_vlan_id = tmp;
6535 else if (unformat (i, "inner_vlan_id %d", &tmp))
6536 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006537
6538#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006539 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006540#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006541 else
6542 {
6543 clib_warning ("parse error '%U'", format_unformat_error, i);
6544 return -99;
6545 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006546 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006547
Dave Barach72d72232016-08-04 10:15:08 -04006548 if (sw_if_index_set == 0)
6549 {
6550 errmsg ("missing interface name or sw_if_index\n");
6551 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006552 }
6553
Dave Barach72d72232016-08-04 10:15:08 -04006554 if (sub_id_set == 0)
6555 {
6556 errmsg ("missing sub_id\n");
6557 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006558 }
Dave Barach72d72232016-08-04 10:15:08 -04006559 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006560
Dave Barach72d72232016-08-04 10:15:08 -04006561 mp->sw_if_index = ntohl (sw_if_index);
6562 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006563
Ed Warnickecb9cada2015-12-08 15:45:58 -07006564#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006565 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006566#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006567
Dave Barach72d72232016-08-04 10:15:08 -04006568 mp->outer_vlan_id = ntohs (outer_vlan_id);
6569 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006570
Dave Barach72d72232016-08-04 10:15:08 -04006571 S;
6572 W;
6573 /* NOTREACHED */
6574 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006575}
6576
Dave Barach72d72232016-08-04 10:15:08 -04006577static int
6578api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006579{
Dave Barach72d72232016-08-04 10:15:08 -04006580 unformat_input_t *i = vam->input;
6581 vl_api_oam_add_del_t *mp;
6582 f64 timeout;
6583 u32 vrf_id = 0;
6584 u8 is_add = 1;
6585 ip4_address_t src, dst;
6586 u8 src_set = 0;
6587 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006588
Dave Barach72d72232016-08-04 10:15:08 -04006589 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6590 {
6591 if (unformat (i, "vrf %d", &vrf_id))
6592 ;
6593 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6594 src_set = 1;
6595 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6596 dst_set = 1;
6597 else if (unformat (i, "del"))
6598 is_add = 0;
6599 else
6600 {
6601 clib_warning ("parse error '%U'", format_unformat_error, i);
6602 return -99;
6603 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006604 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006605
Dave Barach72d72232016-08-04 10:15:08 -04006606 if (src_set == 0)
6607 {
6608 errmsg ("missing src addr\n");
6609 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006610 }
6611
Dave Barach72d72232016-08-04 10:15:08 -04006612 if (dst_set == 0)
6613 {
6614 errmsg ("missing dst addr\n");
6615 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006616 }
6617
Dave Barach72d72232016-08-04 10:15:08 -04006618 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006619
Dave Barach72d72232016-08-04 10:15:08 -04006620 mp->vrf_id = ntohl (vrf_id);
6621 mp->is_add = is_add;
6622 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6623 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006624
Dave Barach72d72232016-08-04 10:15:08 -04006625 S;
6626 W;
6627 /* NOTREACHED */
6628 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006629}
6630
Dave Barach72d72232016-08-04 10:15:08 -04006631static int
6632api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006633{
Dave Barach72d72232016-08-04 10:15:08 -04006634 unformat_input_t *i = vam->input;
6635 vl_api_reset_fib_t *mp;
6636 f64 timeout;
6637 u32 vrf_id = 0;
6638 u8 is_ipv6 = 0;
6639 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006640
Dave Barach72d72232016-08-04 10:15:08 -04006641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6642 {
6643 if (unformat (i, "vrf %d", &vrf_id))
6644 vrf_id_set = 1;
6645 else if (unformat (i, "ipv6"))
6646 is_ipv6 = 1;
6647 else
6648 {
6649 clib_warning ("parse error '%U'", format_unformat_error, i);
6650 return -99;
6651 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006652 }
6653
Dave Barach72d72232016-08-04 10:15:08 -04006654 if (vrf_id_set == 0)
6655 {
6656 errmsg ("missing vrf id\n");
6657 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006658 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006659
Dave Barach72d72232016-08-04 10:15:08 -04006660 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006661
Dave Barach72d72232016-08-04 10:15:08 -04006662 mp->vrf_id = ntohl (vrf_id);
6663 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006664
Dave Barach72d72232016-08-04 10:15:08 -04006665 S;
6666 W;
6667 /* NOTREACHED */
6668 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006669}
6670
Dave Barach72d72232016-08-04 10:15:08 -04006671static int
6672api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006673{
Dave Barach72d72232016-08-04 10:15:08 -04006674 unformat_input_t *i = vam->input;
6675 vl_api_dhcp_proxy_config_t *mp;
6676 f64 timeout;
6677 u32 vrf_id = 0;
6678 u8 is_add = 1;
6679 u8 insert_cid = 1;
6680 u8 v4_address_set = 0;
6681 u8 v6_address_set = 0;
6682 ip4_address_t v4address;
6683 ip6_address_t v6address;
6684 u8 v4_src_address_set = 0;
6685 u8 v6_src_address_set = 0;
6686 ip4_address_t v4srcaddress;
6687 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006688
Dave Barach72d72232016-08-04 10:15:08 -04006689 /* Parse args required to build the message */
6690 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6691 {
6692 if (unformat (i, "del"))
6693 is_add = 0;
6694 else if (unformat (i, "vrf %d", &vrf_id))
6695 ;
6696 else if (unformat (i, "insert-cid %d", &insert_cid))
6697 ;
6698 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6699 v4_address_set = 1;
6700 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6701 v6_address_set = 1;
6702 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6703 v4_src_address_set = 1;
6704 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6705 v6_src_address_set = 1;
6706 else
6707 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006708 }
6709
Dave Barach72d72232016-08-04 10:15:08 -04006710 if (v4_address_set && v6_address_set)
6711 {
6712 errmsg ("both v4 and v6 server addresses set\n");
6713 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006714 }
Dave Barach72d72232016-08-04 10:15:08 -04006715 if (!v4_address_set && !v6_address_set)
6716 {
6717 errmsg ("no server addresses set\n");
6718 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006719 }
6720
Dave Barach72d72232016-08-04 10:15:08 -04006721 if (v4_src_address_set && v6_src_address_set)
6722 {
6723 errmsg ("both v4 and v6 src addresses set\n");
6724 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006725 }
Dave Barach72d72232016-08-04 10:15:08 -04006726 if (!v4_src_address_set && !v6_src_address_set)
6727 {
6728 errmsg ("no src addresses set\n");
6729 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006730 }
6731
Dave Barach72d72232016-08-04 10:15:08 -04006732 if (!(v4_src_address_set && v4_address_set) &&
6733 !(v6_src_address_set && v6_address_set))
6734 {
6735 errmsg ("no matching server and src addresses set\n");
6736 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006737 }
6738
Dave Barach72d72232016-08-04 10:15:08 -04006739 /* Construct the API message */
6740 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006741
Dave Barach72d72232016-08-04 10:15:08 -04006742 mp->insert_circuit_id = insert_cid;
6743 mp->is_add = is_add;
6744 mp->vrf_id = ntohl (vrf_id);
6745 if (v6_address_set)
6746 {
6747 mp->is_ipv6 = 1;
6748 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6749 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6750 }
6751 else
6752 {
6753 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6754 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006755 }
6756
Dave Barach72d72232016-08-04 10:15:08 -04006757 /* send it... */
6758 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006759
Dave Barach72d72232016-08-04 10:15:08 -04006760 /* Wait for a reply, return good/bad news */
6761 W;
6762 /* NOTREACHED */
6763 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006764}
6765
Dave Barach72d72232016-08-04 10:15:08 -04006766static int
6767api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006768{
Dave Barach72d72232016-08-04 10:15:08 -04006769 unformat_input_t *i = vam->input;
6770 vl_api_dhcp_proxy_config_2_t *mp;
6771 f64 timeout;
6772 u32 rx_vrf_id = 0;
6773 u32 server_vrf_id = 0;
6774 u8 is_add = 1;
6775 u8 insert_cid = 1;
6776 u8 v4_address_set = 0;
6777 u8 v6_address_set = 0;
6778 ip4_address_t v4address;
6779 ip6_address_t v6address;
6780 u8 v4_src_address_set = 0;
6781 u8 v6_src_address_set = 0;
6782 ip4_address_t v4srcaddress;
6783 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006784
Dave Barach72d72232016-08-04 10:15:08 -04006785 /* Parse args required to build the message */
6786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6787 {
6788 if (unformat (i, "del"))
6789 is_add = 0;
6790 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
6791 ;
6792 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
6793 ;
6794 else if (unformat (i, "insert-cid %d", &insert_cid))
6795 ;
6796 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
6797 v4_address_set = 1;
6798 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
6799 v6_address_set = 1;
6800 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
6801 v4_src_address_set = 1;
6802 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
6803 v6_src_address_set = 1;
6804 else
6805 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006806 }
6807
Dave Barach72d72232016-08-04 10:15:08 -04006808 if (v4_address_set && v6_address_set)
6809 {
6810 errmsg ("both v4 and v6 server addresses set\n");
6811 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006812 }
Dave Barach72d72232016-08-04 10:15:08 -04006813 if (!v4_address_set && !v6_address_set)
6814 {
6815 errmsg ("no server addresses set\n");
6816 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006817 }
6818
Dave Barach72d72232016-08-04 10:15:08 -04006819 if (v4_src_address_set && v6_src_address_set)
6820 {
6821 errmsg ("both v4 and v6 src addresses set\n");
6822 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006823 }
Dave Barach72d72232016-08-04 10:15:08 -04006824 if (!v4_src_address_set && !v6_src_address_set)
6825 {
6826 errmsg ("no src addresses set\n");
6827 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006828 }
6829
Dave Barach72d72232016-08-04 10:15:08 -04006830 if (!(v4_src_address_set && v4_address_set) &&
6831 !(v6_src_address_set && v6_address_set))
6832 {
6833 errmsg ("no matching server and src addresses set\n");
6834 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006835 }
6836
Dave Barach72d72232016-08-04 10:15:08 -04006837 /* Construct the API message */
6838 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006839
Dave Barach72d72232016-08-04 10:15:08 -04006840 mp->insert_circuit_id = insert_cid;
6841 mp->is_add = is_add;
6842 mp->rx_vrf_id = ntohl (rx_vrf_id);
6843 mp->server_vrf_id = ntohl (server_vrf_id);
6844 if (v6_address_set)
6845 {
6846 mp->is_ipv6 = 1;
6847 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
6848 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
6849 }
6850 else
6851 {
6852 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
6853 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006854 }
6855
Dave Barach72d72232016-08-04 10:15:08 -04006856 /* send it... */
6857 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006858
Dave Barach72d72232016-08-04 10:15:08 -04006859 /* Wait for a reply, return good/bad news */
6860 W;
6861 /* NOTREACHED */
6862 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006863}
6864
Dave Barach72d72232016-08-04 10:15:08 -04006865static int
6866api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006867{
Dave Barach72d72232016-08-04 10:15:08 -04006868 unformat_input_t *i = vam->input;
6869 vl_api_dhcp_proxy_set_vss_t *mp;
6870 f64 timeout;
6871 u8 is_ipv6 = 0;
6872 u8 is_add = 1;
6873 u32 tbl_id;
6874 u8 tbl_id_set = 0;
6875 u32 oui;
6876 u8 oui_set = 0;
6877 u32 fib_id;
6878 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006879
Dave Barach72d72232016-08-04 10:15:08 -04006880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6881 {
6882 if (unformat (i, "tbl_id %d", &tbl_id))
6883 tbl_id_set = 1;
6884 if (unformat (i, "fib_id %d", &fib_id))
6885 fib_id_set = 1;
6886 if (unformat (i, "oui %d", &oui))
6887 oui_set = 1;
6888 else if (unformat (i, "ipv6"))
6889 is_ipv6 = 1;
6890 else if (unformat (i, "del"))
6891 is_add = 0;
6892 else
6893 {
6894 clib_warning ("parse error '%U'", format_unformat_error, i);
6895 return -99;
6896 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006897 }
6898
Dave Barach72d72232016-08-04 10:15:08 -04006899 if (tbl_id_set == 0)
6900 {
6901 errmsg ("missing tbl id\n");
6902 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006903 }
6904
Dave Barach72d72232016-08-04 10:15:08 -04006905 if (fib_id_set == 0)
6906 {
6907 errmsg ("missing fib id\n");
6908 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006909 }
Dave Barach72d72232016-08-04 10:15:08 -04006910 if (oui_set == 0)
6911 {
6912 errmsg ("missing oui\n");
6913 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006914 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006915
Dave Barach72d72232016-08-04 10:15:08 -04006916 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
6917 mp->tbl_id = ntohl (tbl_id);
6918 mp->fib_id = ntohl (fib_id);
6919 mp->oui = ntohl (oui);
6920 mp->is_ipv6 = is_ipv6;
6921 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006922
Dave Barach72d72232016-08-04 10:15:08 -04006923 S;
6924 W;
6925 /* NOTREACHED */
6926 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006927}
6928
Dave Barach72d72232016-08-04 10:15:08 -04006929static int
6930api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006931{
Dave Barach72d72232016-08-04 10:15:08 -04006932 unformat_input_t *i = vam->input;
6933 vl_api_dhcp_client_config_t *mp;
6934 f64 timeout;
6935 u32 sw_if_index;
6936 u8 sw_if_index_set = 0;
6937 u8 is_add = 1;
6938 u8 *hostname = 0;
6939 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006940
Dave Barach72d72232016-08-04 10:15:08 -04006941 /* Parse args required to build the message */
6942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6943 {
6944 if (unformat (i, "del"))
6945 is_add = 0;
6946 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6947 sw_if_index_set = 1;
6948 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6949 sw_if_index_set = 1;
6950 else if (unformat (i, "hostname %s", &hostname))
6951 ;
6952 else if (unformat (i, "disable_event"))
6953 disable_event = 1;
6954 else
6955 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006956 }
6957
Dave Barach72d72232016-08-04 10:15:08 -04006958 if (sw_if_index_set == 0)
6959 {
6960 errmsg ("missing interface name or sw_if_index\n");
6961 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006962 }
6963
Dave Barach72d72232016-08-04 10:15:08 -04006964 if (vec_len (hostname) > 63)
6965 {
6966 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006967 }
Dave Barach72d72232016-08-04 10:15:08 -04006968 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006969
Dave Barach72d72232016-08-04 10:15:08 -04006970 /* Construct the API message */
6971 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006972
Dave Barach72d72232016-08-04 10:15:08 -04006973 mp->sw_if_index = ntohl (sw_if_index);
6974 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
6975 vec_free (hostname);
6976 mp->is_add = is_add;
6977 mp->want_dhcp_event = disable_event ? 0 : 1;
6978 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006979
Dave Barach72d72232016-08-04 10:15:08 -04006980 /* send it... */
6981 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006982
Dave Barach72d72232016-08-04 10:15:08 -04006983 /* Wait for a reply, return good/bad news */
6984 W;
6985 /* NOTREACHED */
6986 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006987}
6988
Dave Barach72d72232016-08-04 10:15:08 -04006989static int
6990api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006991{
Dave Barach72d72232016-08-04 10:15:08 -04006992 unformat_input_t *i = vam->input;
6993 vl_api_set_ip_flow_hash_t *mp;
6994 f64 timeout;
6995 u32 vrf_id = 0;
6996 u8 is_ipv6 = 0;
6997 u8 vrf_id_set = 0;
6998 u8 src = 0;
6999 u8 dst = 0;
7000 u8 sport = 0;
7001 u8 dport = 0;
7002 u8 proto = 0;
7003 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007004
Dave Barach72d72232016-08-04 10:15:08 -04007005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7006 {
7007 if (unformat (i, "vrf %d", &vrf_id))
7008 vrf_id_set = 1;
7009 else if (unformat (i, "ipv6"))
7010 is_ipv6 = 1;
7011 else if (unformat (i, "src"))
7012 src = 1;
7013 else if (unformat (i, "dst"))
7014 dst = 1;
7015 else if (unformat (i, "sport"))
7016 sport = 1;
7017 else if (unformat (i, "dport"))
7018 dport = 1;
7019 else if (unformat (i, "proto"))
7020 proto = 1;
7021 else if (unformat (i, "reverse"))
7022 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007023
Dave Barach72d72232016-08-04 10:15:08 -04007024 else
7025 {
7026 clib_warning ("parse error '%U'", format_unformat_error, i);
7027 return -99;
7028 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007029 }
7030
Dave Barach72d72232016-08-04 10:15:08 -04007031 if (vrf_id_set == 0)
7032 {
7033 errmsg ("missing vrf id\n");
7034 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007035 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007036
Dave Barach72d72232016-08-04 10:15:08 -04007037 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7038 mp->src = src;
7039 mp->dst = dst;
7040 mp->sport = sport;
7041 mp->dport = dport;
7042 mp->proto = proto;
7043 mp->reverse = reverse;
7044 mp->vrf_id = ntohl (vrf_id);
7045 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007046
Dave Barach72d72232016-08-04 10:15:08 -04007047 S;
7048 W;
7049 /* NOTREACHED */
7050 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007051}
7052
Dave Barach72d72232016-08-04 10:15:08 -04007053static int
7054api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007055{
Dave Barach72d72232016-08-04 10:15:08 -04007056 unformat_input_t *i = vam->input;
7057 vl_api_sw_interface_ip6_enable_disable_t *mp;
7058 f64 timeout;
7059 u32 sw_if_index;
7060 u8 sw_if_index_set = 0;
7061 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007062
Dave Barach72d72232016-08-04 10:15:08 -04007063 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7064 {
7065 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7066 sw_if_index_set = 1;
7067 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7068 sw_if_index_set = 1;
7069 else if (unformat (i, "enable"))
7070 enable = 1;
7071 else if (unformat (i, "disable"))
7072 enable = 0;
7073 else
7074 {
7075 clib_warning ("parse error '%U'", format_unformat_error, i);
7076 return -99;
7077 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007078 }
7079
Dave Barach72d72232016-08-04 10:15:08 -04007080 if (sw_if_index_set == 0)
7081 {
7082 errmsg ("missing interface name or sw_if_index\n");
7083 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007084 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007085
Dave Barach72d72232016-08-04 10:15:08 -04007086 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007087
Dave Barach72d72232016-08-04 10:15:08 -04007088 mp->sw_if_index = ntohl (sw_if_index);
7089 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007090
Dave Barach72d72232016-08-04 10:15:08 -04007091 S;
7092 W;
7093 /* NOTREACHED */
7094 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007095}
7096
Dave Barach72d72232016-08-04 10:15:08 -04007097static int
7098api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007099{
Dave Barach72d72232016-08-04 10:15:08 -04007100 unformat_input_t *i = vam->input;
7101 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7102 f64 timeout;
7103 u32 sw_if_index;
7104 u8 sw_if_index_set = 0;
7105 u32 address_length = 0;
7106 u8 v6_address_set = 0;
7107 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007108
Dave Barach72d72232016-08-04 10:15:08 -04007109 /* Parse args required to build the message */
7110 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7111 {
7112 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7113 sw_if_index_set = 1;
7114 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7115 sw_if_index_set = 1;
7116 else if (unformat (i, "%U/%d",
7117 unformat_ip6_address, &v6address, &address_length))
7118 v6_address_set = 1;
7119 else
7120 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007121 }
7122
Dave Barach72d72232016-08-04 10:15:08 -04007123 if (sw_if_index_set == 0)
7124 {
7125 errmsg ("missing interface name or sw_if_index\n");
7126 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007127 }
Dave Barach72d72232016-08-04 10:15:08 -04007128 if (!v6_address_set)
7129 {
7130 errmsg ("no address set\n");
7131 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007132 }
7133
Dave Barach72d72232016-08-04 10:15:08 -04007134 /* Construct the API message */
7135 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7136 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007137
Dave Barach72d72232016-08-04 10:15:08 -04007138 mp->sw_if_index = ntohl (sw_if_index);
7139 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7140 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007141
Dave Barach72d72232016-08-04 10:15:08 -04007142 /* send it... */
7143 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007144
Dave Barach72d72232016-08-04 10:15:08 -04007145 /* Wait for a reply, return good/bad news */
7146 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007147
Dave Barach72d72232016-08-04 10:15:08 -04007148 /* NOTREACHED */
7149 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007150}
7151
7152
Dave Barach72d72232016-08-04 10:15:08 -04007153static int
7154api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007155{
Dave Barach72d72232016-08-04 10:15:08 -04007156 unformat_input_t *i = vam->input;
7157 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7158 f64 timeout;
7159 u32 sw_if_index;
7160 u8 sw_if_index_set = 0;
7161 u32 address_length = 0;
7162 u8 v6_address_set = 0;
7163 ip6_address_t v6address;
7164 u8 use_default = 0;
7165 u8 no_advertise = 0;
7166 u8 off_link = 0;
7167 u8 no_autoconfig = 0;
7168 u8 no_onlink = 0;
7169 u8 is_no = 0;
7170 u32 val_lifetime = 0;
7171 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007172
Dave Barach72d72232016-08-04 10:15:08 -04007173 /* Parse args required to build the message */
7174 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7175 {
7176 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7177 sw_if_index_set = 1;
7178 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7179 sw_if_index_set = 1;
7180 else if (unformat (i, "%U/%d",
7181 unformat_ip6_address, &v6address, &address_length))
7182 v6_address_set = 1;
7183 else if (unformat (i, "val_life %d", &val_lifetime))
7184 ;
7185 else if (unformat (i, "pref_life %d", &pref_lifetime))
7186 ;
7187 else if (unformat (i, "def"))
7188 use_default = 1;
7189 else if (unformat (i, "noadv"))
7190 no_advertise = 1;
7191 else if (unformat (i, "offl"))
7192 off_link = 1;
7193 else if (unformat (i, "noauto"))
7194 no_autoconfig = 1;
7195 else if (unformat (i, "nolink"))
7196 no_onlink = 1;
7197 else if (unformat (i, "isno"))
7198 is_no = 1;
7199 else
7200 {
7201 clib_warning ("parse error '%U'", format_unformat_error, i);
7202 return -99;
7203 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007204 }
7205
Dave Barach72d72232016-08-04 10:15:08 -04007206 if (sw_if_index_set == 0)
7207 {
7208 errmsg ("missing interface name or sw_if_index\n");
7209 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007210 }
Dave Barach72d72232016-08-04 10:15:08 -04007211 if (!v6_address_set)
7212 {
7213 errmsg ("no address set\n");
7214 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007215 }
7216
Dave Barach72d72232016-08-04 10:15:08 -04007217 /* Construct the API message */
7218 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007219
Dave Barach72d72232016-08-04 10:15:08 -04007220 mp->sw_if_index = ntohl (sw_if_index);
7221 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7222 mp->address_length = address_length;
7223 mp->use_default = use_default;
7224 mp->no_advertise = no_advertise;
7225 mp->off_link = off_link;
7226 mp->no_autoconfig = no_autoconfig;
7227 mp->no_onlink = no_onlink;
7228 mp->is_no = is_no;
7229 mp->val_lifetime = ntohl (val_lifetime);
7230 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007231
Dave Barach72d72232016-08-04 10:15:08 -04007232 /* send it... */
7233 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007234
Dave Barach72d72232016-08-04 10:15:08 -04007235 /* Wait for a reply, return good/bad news */
7236 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007237
Dave Barach72d72232016-08-04 10:15:08 -04007238 /* NOTREACHED */
7239 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007240}
7241
Dave Barach72d72232016-08-04 10:15:08 -04007242static int
7243api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007244{
Dave Barach72d72232016-08-04 10:15:08 -04007245 unformat_input_t *i = vam->input;
7246 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7247 f64 timeout;
7248 u32 sw_if_index;
7249 u8 sw_if_index_set = 0;
7250 u8 suppress = 0;
7251 u8 managed = 0;
7252 u8 other = 0;
7253 u8 ll_option = 0;
7254 u8 send_unicast = 0;
7255 u8 cease = 0;
7256 u8 is_no = 0;
7257 u8 default_router = 0;
7258 u32 max_interval = 0;
7259 u32 min_interval = 0;
7260 u32 lifetime = 0;
7261 u32 initial_count = 0;
7262 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007263
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007264
Dave Barach72d72232016-08-04 10:15:08 -04007265 /* Parse args required to build the message */
7266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7267 {
7268 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7269 sw_if_index_set = 1;
7270 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7271 sw_if_index_set = 1;
7272 else if (unformat (i, "maxint %d", &max_interval))
7273 ;
7274 else if (unformat (i, "minint %d", &min_interval))
7275 ;
7276 else if (unformat (i, "life %d", &lifetime))
7277 ;
7278 else if (unformat (i, "count %d", &initial_count))
7279 ;
7280 else if (unformat (i, "interval %d", &initial_interval))
7281 ;
7282 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7283 suppress = 1;
7284 else if (unformat (i, "managed"))
7285 managed = 1;
7286 else if (unformat (i, "other"))
7287 other = 1;
7288 else if (unformat (i, "ll"))
7289 ll_option = 1;
7290 else if (unformat (i, "send"))
7291 send_unicast = 1;
7292 else if (unformat (i, "cease"))
7293 cease = 1;
7294 else if (unformat (i, "isno"))
7295 is_no = 1;
7296 else if (unformat (i, "def"))
7297 default_router = 1;
7298 else
7299 {
7300 clib_warning ("parse error '%U'", format_unformat_error, i);
7301 return -99;
7302 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007303 }
7304
Dave Barach72d72232016-08-04 10:15:08 -04007305 if (sw_if_index_set == 0)
7306 {
7307 errmsg ("missing interface name or sw_if_index\n");
7308 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007309 }
7310
Dave Barach72d72232016-08-04 10:15:08 -04007311 /* Construct the API message */
7312 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007313
Dave Barach72d72232016-08-04 10:15:08 -04007314 mp->sw_if_index = ntohl (sw_if_index);
7315 mp->max_interval = ntohl (max_interval);
7316 mp->min_interval = ntohl (min_interval);
7317 mp->lifetime = ntohl (lifetime);
7318 mp->initial_count = ntohl (initial_count);
7319 mp->initial_interval = ntohl (initial_interval);
7320 mp->suppress = suppress;
7321 mp->managed = managed;
7322 mp->other = other;
7323 mp->ll_option = ll_option;
7324 mp->send_unicast = send_unicast;
7325 mp->cease = cease;
7326 mp->is_no = is_no;
7327 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007328
Dave Barach72d72232016-08-04 10:15:08 -04007329 /* send it... */
7330 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007331
Dave Barach72d72232016-08-04 10:15:08 -04007332 /* Wait for a reply, return good/bad news */
7333 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007334
Dave Barach72d72232016-08-04 10:15:08 -04007335 /* NOTREACHED */
7336 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007337}
7338
Dave Barach72d72232016-08-04 10:15:08 -04007339static int
7340api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007341{
Dave Barach72d72232016-08-04 10:15:08 -04007342 unformat_input_t *i = vam->input;
7343 vl_api_set_arp_neighbor_limit_t *mp;
7344 f64 timeout;
7345 u32 arp_nbr_limit;
7346 u8 limit_set = 0;
7347 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007348
Dave Barach72d72232016-08-04 10:15:08 -04007349 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7350 {
7351 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7352 limit_set = 1;
7353 else if (unformat (i, "ipv6"))
7354 is_ipv6 = 1;
7355 else
7356 {
7357 clib_warning ("parse error '%U'", format_unformat_error, i);
7358 return -99;
7359 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007360 }
7361
Dave Barach72d72232016-08-04 10:15:08 -04007362 if (limit_set == 0)
7363 {
7364 errmsg ("missing limit value\n");
7365 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007366 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007367
Dave Barach72d72232016-08-04 10:15:08 -04007368 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007369
Dave Barach72d72232016-08-04 10:15:08 -04007370 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7371 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007372
Dave Barach72d72232016-08-04 10:15:08 -04007373 S;
7374 W;
7375 /* NOTREACHED */
7376 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007377}
7378
Dave Barach72d72232016-08-04 10:15:08 -04007379static int
7380api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007381{
Dave Barach72d72232016-08-04 10:15:08 -04007382 unformat_input_t *i = vam->input;
7383 vl_api_l2_patch_add_del_t *mp;
7384 f64 timeout;
7385 u32 rx_sw_if_index;
7386 u8 rx_sw_if_index_set = 0;
7387 u32 tx_sw_if_index;
7388 u8 tx_sw_if_index_set = 0;
7389 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007390
Dave Barach72d72232016-08-04 10:15:08 -04007391 /* Parse args required to build the message */
7392 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7393 {
7394 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7395 rx_sw_if_index_set = 1;
7396 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7397 tx_sw_if_index_set = 1;
7398 else if (unformat (i, "rx"))
7399 {
7400 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7401 {
7402 if (unformat (i, "%U", unformat_sw_if_index, vam,
7403 &rx_sw_if_index))
7404 rx_sw_if_index_set = 1;
7405 }
7406 else
7407 break;
7408 }
7409 else if (unformat (i, "tx"))
7410 {
7411 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7412 {
7413 if (unformat (i, "%U", unformat_sw_if_index, vam,
7414 &tx_sw_if_index))
7415 tx_sw_if_index_set = 1;
7416 }
7417 else
7418 break;
7419 }
7420 else if (unformat (i, "del"))
7421 is_add = 0;
7422 else
7423 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007424 }
7425
Dave Barach72d72232016-08-04 10:15:08 -04007426 if (rx_sw_if_index_set == 0)
7427 {
7428 errmsg ("missing rx interface name or rx_sw_if_index\n");
7429 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007430 }
7431
Dave Barach72d72232016-08-04 10:15:08 -04007432 if (tx_sw_if_index_set == 0)
7433 {
7434 errmsg ("missing tx interface name or tx_sw_if_index\n");
7435 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007436 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007437
Dave Barach72d72232016-08-04 10:15:08 -04007438 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007439
Dave Barach72d72232016-08-04 10:15:08 -04007440 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7441 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7442 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007443
Dave Barach72d72232016-08-04 10:15:08 -04007444 S;
7445 W;
7446 /* NOTREACHED */
7447 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007448}
Dave Barach72d72232016-08-04 10:15:08 -04007449
7450static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007451api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007452{
Dave Barach72d72232016-08-04 10:15:08 -04007453 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007454 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007455 f64 timeout;
7456 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007457 int has_trace_option = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007458 int has_pow_option = 0;
7459 int has_ppc_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007460
Shwetha20a64f52016-03-25 10:55:01 +00007461 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7462 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007463 if (unformat (input, "trace"))
7464 has_trace_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007465 else if (unformat (input, "pow"))
Dave Barach72d72232016-08-04 10:15:08 -04007466 has_pow_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007467 else if (unformat (input, "ppc encap"))
Dave Barach72d72232016-08-04 10:15:08 -04007468 has_ppc_option = PPC_ENCAP;
Shwetha20a64f52016-03-25 10:55:01 +00007469 else if (unformat (input, "ppc decap"))
Dave Barach72d72232016-08-04 10:15:08 -04007470 has_ppc_option = PPC_DECAP;
Shwetha20a64f52016-03-25 10:55:01 +00007471 else if (unformat (input, "ppc none"))
Dave Barach72d72232016-08-04 10:15:08 -04007472 has_ppc_option = PPC_NONE;
Shwetha20a64f52016-03-25 10:55:01 +00007473 else
Dave Barach72d72232016-08-04 10:15:08 -04007474 break;
Shwetha20a64f52016-03-25 10:55:01 +00007475 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007476 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007477 mp->id = htons (id);
Shwetha20a64f52016-03-25 10:55:01 +00007478 mp->trace_ppc = has_ppc_option;
Shwetha20a64f52016-03-25 10:55:01 +00007479 mp->pow_enable = has_pow_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007480 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007481
Dave Barach72d72232016-08-04 10:15:08 -04007482 S;
7483 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007484
Dave Barach72d72232016-08-04 10:15:08 -04007485 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007486
Shwetha20a64f52016-03-25 10:55:01 +00007487}
Dave Barach72d72232016-08-04 10:15:08 -04007488
Shwetha20a64f52016-03-25 10:55:01 +00007489
Dave Barach72d72232016-08-04 10:15:08 -04007490static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007491api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007492{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007493 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007494 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007495
Vengada Govindan07d2f842016-08-25 10:34:34 -07007496 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007497 S;
7498 W;
7499 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007500}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007501
Dave Barach72d72232016-08-04 10:15:08 -04007502static int
7503api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007504{
Dave Barach72d72232016-08-04 10:15:08 -04007505 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007506 vl_api_sr_tunnel_add_del_t *mp;
7507 f64 timeout;
7508 int is_del = 0;
7509 int pl_index;
7510 ip6_address_t src_address;
7511 int src_address_set = 0;
7512 ip6_address_t dst_address;
7513 u32 dst_mask_width;
7514 int dst_address_set = 0;
7515 u16 flags = 0;
7516 u32 rx_table_id = 0;
7517 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007518 ip6_address_t *segments = 0;
7519 ip6_address_t *this_seg;
7520 ip6_address_t *tags = 0;
7521 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007522 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007523 u8 *name = 0;
7524 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007525
7526 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7527 {
7528 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007529 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007530 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007531 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007532 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007533 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007534 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007535 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007536 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007537 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007538 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007539 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007540 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007541 unformat_ip6_address, &dst_address, &dst_mask_width))
7542 dst_address_set = 1;
7543 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7544 {
7545 vec_add2 (segments, this_seg, 1);
7546 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7547 sizeof (*this_seg));
7548 }
7549 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7550 {
7551 vec_add2 (tags, this_tag, 1);
7552 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7553 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007554 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007555 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007556 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007557 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007558 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007559 {
7560 if (pl_index <= 0 || pl_index > 4)
7561 {
7562 pl_index_range_error:
7563 errmsg ("pl index %d out of range\n", pl_index);
7564 return -99;
7565 }
7566 flags |=
7567 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7568 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007569 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007570 {
7571 if (pl_index <= 0 || pl_index > 4)
7572 goto pl_index_range_error;
7573 flags |=
7574 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7575 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007576 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007577 {
7578 if (pl_index <= 0 || pl_index > 4)
7579 goto pl_index_range_error;
7580 flags |=
7581 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7582 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007583 else
Dave Barach72d72232016-08-04 10:15:08 -04007584 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007585 }
7586
7587 if (!src_address_set)
7588 {
7589 errmsg ("src address required\n");
7590 return -99;
7591 }
7592
7593 if (!dst_address_set)
7594 {
7595 errmsg ("dst address required\n");
7596 return -99;
7597 }
7598
7599 if (!segments)
7600 {
7601 errmsg ("at least one sr segment required\n");
7602 return -99;
7603 }
7604
Dave Barach72d72232016-08-04 10:15:08 -04007605 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7606 vec_len (segments) * sizeof (ip6_address_t)
7607 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007608
Damjan Marionf1213b82016-03-13 02:22:06 +01007609 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7610 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007611 mp->dst_mask_width = dst_mask_width;
7612 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7613 mp->n_segments = vec_len (segments);
7614 mp->n_tags = vec_len (tags);
7615 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007616 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007617 vec_len (segments) * sizeof (ip6_address_t));
7618 clib_memcpy (mp->segs_and_tags +
7619 vec_len (segments) * sizeof (ip6_address_t), tags,
7620 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007621
7622 mp->outer_vrf_id = ntohl (rx_table_id);
7623 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007624 memcpy (mp->name, name, vec_len (name));
7625 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007626
7627 vec_free (segments);
7628 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007629
Dave Barach72d72232016-08-04 10:15:08 -04007630 S;
7631 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007632 /* NOTREACHED */
7633}
7634
Dave Barach72d72232016-08-04 10:15:08 -04007635static int
7636api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007637{
Dave Barach72d72232016-08-04 10:15:08 -04007638 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007639 vl_api_sr_policy_add_del_t *mp;
7640 f64 timeout;
7641 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007642 u8 *name = 0;
7643 u8 *tunnel_name = 0;
7644 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007645
Dave Barach72d72232016-08-04 10:15:08 -04007646 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007647 int tunnel_set = 0;
7648 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007649 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7650 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007651
7652 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7653 {
7654 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007655 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007656 else if (unformat (input, "name %s", &name))
7657 name_set = 1;
7658 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04007659 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007660 if (tunnel_name)
7661 {
7662 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007663 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04007664 - length = #bytes to store in serial vector
7665 - +1 = byte to store that length
7666 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007667 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007668 tunnel_set = 1;
7669 tunnel_name = 0;
7670 }
Dave Barach72d72232016-08-04 10:15:08 -04007671 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007672 else
Dave Barach72d72232016-08-04 10:15:08 -04007673 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007674 }
7675
7676 if (!name_set)
7677 {
7678 errmsg ("policy name required\n");
7679 return -99;
7680 }
7681
7682 if ((!tunnel_set) && (!is_del))
7683 {
7684 errmsg ("tunnel name required\n");
7685 return -99;
7686 }
7687
Dave Barach72d72232016-08-04 10:15:08 -04007688 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007689
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007690
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007691
7692 mp->is_add = !is_del;
7693
Dave Barach72d72232016-08-04 10:15:08 -04007694 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007695 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
Dave Barach72d72232016-08-04 10:15:08 -04007696 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007697 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04007698 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
7699 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007700
Dave Barach72d72232016-08-04 10:15:08 -04007701 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007702 {
7703 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04007704 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
7705 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007706 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04007707 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007708 }
Dave Barach72d72232016-08-04 10:15:08 -04007709 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007710
7711 vec_free (tunnel_names);
7712 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007713
Dave Barach72d72232016-08-04 10:15:08 -04007714 S;
7715 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007716 /* NOTREACHED */
7717}
7718
Dave Barach72d72232016-08-04 10:15:08 -04007719static int
7720api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007721{
Dave Barach72d72232016-08-04 10:15:08 -04007722 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007723 vl_api_sr_multicast_map_add_del_t *mp;
7724 f64 timeout;
7725 int is_del = 0;
7726 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04007727 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007728 int multicast_address_set = 0;
7729
7730 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7731 {
7732 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007733 is_del = 1;
7734 else
7735 if (unformat
7736 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007737 multicast_address_set = 1;
7738 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007739 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007740 else
Dave Barach72d72232016-08-04 10:15:08 -04007741 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007742 }
7743
7744 if (!is_del && !policy_name)
7745 {
7746 errmsg ("sr-policy name required\n");
7747 return -99;
7748 }
7749
7750
7751 if (!multicast_address_set)
7752 {
7753 errmsg ("address required\n");
7754 return -99;
7755 }
7756
Dave Barach72d72232016-08-04 10:15:08 -04007757 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007758
7759 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04007760 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
7761 clib_memcpy (mp->multicast_address, &multicast_address,
7762 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007763
7764
7765 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007766
Dave Barach72d72232016-08-04 10:15:08 -04007767 S;
7768 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007769 /* NOTREACHED */
7770}
7771
Ed Warnickecb9cada2015-12-08 15:45:58 -07007772
7773#define foreach_ip4_proto_field \
7774_(src_address) \
7775_(dst_address) \
7776_(tos) \
7777_(length) \
7778_(fragment_id) \
7779_(ttl) \
7780_(protocol) \
7781_(checksum)
7782
Dave Barach72d72232016-08-04 10:15:08 -04007783uword
7784unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007785{
Dave Barach72d72232016-08-04 10:15:08 -04007786 u8 **maskp = va_arg (*args, u8 **);
7787 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007788 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007789 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007790
Ed Warnickecb9cada2015-12-08 15:45:58 -07007791#define _(a) u8 a=0;
7792 foreach_ip4_proto_field;
7793#undef _
7794 u8 version = 0;
7795 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007796
7797
7798 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007799 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007800 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007801 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007802 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04007803 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007804 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007805 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007807 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007808 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007809 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007810
Ed Warnickecb9cada2015-12-08 15:45:58 -07007811#define _(a) else if (unformat (input, #a)) a=1;
7812 foreach_ip4_proto_field
7813#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007814 else
7815 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007816 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007817
Ed Warnickecb9cada2015-12-08 15:45:58 -07007818#define _(a) found_something += a;
7819 foreach_ip4_proto_field;
7820#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007821
Ed Warnickecb9cada2015-12-08 15:45:58 -07007822 if (found_something == 0)
7823 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007824
Ed Warnickecb9cada2015-12-08 15:45:58 -07007825 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007826
Ed Warnickecb9cada2015-12-08 15:45:58 -07007827 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007828
Ed Warnickecb9cada2015-12-08 15:45:58 -07007829#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7830 foreach_ip4_proto_field;
7831#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007832
Ed Warnickecb9cada2015-12-08 15:45:58 -07007833 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007834
Ed Warnickecb9cada2015-12-08 15:45:58 -07007835 if (version)
7836 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007837
Ed Warnickecb9cada2015-12-08 15:45:58 -07007838 if (hdr_length)
7839 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007840
Ed Warnickecb9cada2015-12-08 15:45:58 -07007841 *maskp = mask;
7842 return 1;
7843}
7844
7845#define foreach_ip6_proto_field \
7846_(src_address) \
7847_(dst_address) \
7848_(payload_length) \
7849_(hop_limit) \
7850_(protocol)
7851
Dave Barach72d72232016-08-04 10:15:08 -04007852uword
7853unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007854{
Dave Barach72d72232016-08-04 10:15:08 -04007855 u8 **maskp = va_arg (*args, u8 **);
7856 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007857 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007858 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007859 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007860
Ed Warnickecb9cada2015-12-08 15:45:58 -07007861#define _(a) u8 a=0;
7862 foreach_ip6_proto_field;
7863#undef _
7864 u8 version = 0;
7865 u8 traffic_class = 0;
7866 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007867
7868 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007869 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007870 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04007871 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007872 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04007873 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007874 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04007875 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007876 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04007877 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007878 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04007879 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007880 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04007881 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007882
Ed Warnickecb9cada2015-12-08 15:45:58 -07007883#define _(a) else if (unformat (input, #a)) a=1;
7884 foreach_ip6_proto_field
7885#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007886 else
7887 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007888 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007889
Ed Warnickecb9cada2015-12-08 15:45:58 -07007890#define _(a) found_something += a;
7891 foreach_ip6_proto_field;
7892#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007893
Ed Warnickecb9cada2015-12-08 15:45:58 -07007894 if (found_something == 0)
7895 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007896
Ed Warnickecb9cada2015-12-08 15:45:58 -07007897 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007898
Ed Warnickecb9cada2015-12-08 15:45:58 -07007899 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007900
Ed Warnickecb9cada2015-12-08 15:45:58 -07007901#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
7902 foreach_ip6_proto_field;
7903#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007904
Ed Warnickecb9cada2015-12-08 15:45:58 -07007905 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007906
Ed Warnickecb9cada2015-12-08 15:45:58 -07007907 if (version)
7908 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7909
7910 if (traffic_class)
7911 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7912
7913 if (flow_label)
7914 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7915
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007916 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07007917 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007918
Ed Warnickecb9cada2015-12-08 15:45:58 -07007919 *maskp = mask;
7920 return 1;
7921}
7922
Dave Barach72d72232016-08-04 10:15:08 -04007923uword
7924unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007925{
Dave Barach72d72232016-08-04 10:15:08 -04007926 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007927
Dave Barach72d72232016-08-04 10:15:08 -04007928 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7929 {
7930 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7931 return 1;
7932 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7933 return 1;
7934 else
7935 break;
7936 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007937 return 0;
7938}
7939
Dave Barach72d72232016-08-04 10:15:08 -04007940uword
7941unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007942{
Dave Barach72d72232016-08-04 10:15:08 -04007943 u8 **maskp = va_arg (*args, u8 **);
7944 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007945 u8 src = 0;
7946 u8 dst = 0;
7947 u8 proto = 0;
7948 u8 tag1 = 0;
7949 u8 tag2 = 0;
7950 u8 ignore_tag1 = 0;
7951 u8 ignore_tag2 = 0;
7952 u8 cos1 = 0;
7953 u8 cos2 = 0;
7954 u8 dot1q = 0;
7955 u8 dot1ad = 0;
7956 int len = 14;
7957
Dave Barach72d72232016-08-04 10:15:08 -04007958 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7959 {
7960 if (unformat (input, "src"))
7961 src = 1;
7962 else if (unformat (input, "dst"))
7963 dst = 1;
7964 else if (unformat (input, "proto"))
7965 proto = 1;
7966 else if (unformat (input, "tag1"))
7967 tag1 = 1;
7968 else if (unformat (input, "tag2"))
7969 tag2 = 1;
7970 else if (unformat (input, "ignore-tag1"))
7971 ignore_tag1 = 1;
7972 else if (unformat (input, "ignore-tag2"))
7973 ignore_tag2 = 1;
7974 else if (unformat (input, "cos1"))
7975 cos1 = 1;
7976 else if (unformat (input, "cos2"))
7977 cos2 = 1;
7978 else if (unformat (input, "dot1q"))
7979 dot1q = 1;
7980 else if (unformat (input, "dot1ad"))
7981 dot1ad = 1;
7982 else
7983 break;
7984 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007985 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04007986 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007987 return 0;
7988
7989 if (tag1 || ignore_tag1 || cos1 || dot1q)
7990 len = 18;
7991 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7992 len = 22;
7993
Dave Barach72d72232016-08-04 10:15:08 -04007994 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007995
7996 if (dst)
7997 memset (mask, 0xff, 6);
7998
7999 if (src)
8000 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008001
Ed Warnickecb9cada2015-12-08 15:45:58 -07008002 if (tag2 || dot1ad)
8003 {
8004 /* inner vlan tag */
8005 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008006 {
8007 mask[19] = 0xff;
8008 mask[18] = 0x0f;
8009 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008010 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008011 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008012 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008013 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008014 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008015 {
8016 mask[15] = 0xff;
8017 mask[14] = 0x0f;
8018 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008019 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008020 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008021 *maskp = mask;
8022 return 1;
8023 }
8024 if (tag1 | dot1q)
8025 {
8026 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008027 {
8028 mask[15] = 0xff;
8029 mask[14] = 0x0f;
8030 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008031 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008032 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008033 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008034 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008035
8036 *maskp = mask;
8037 return 1;
8038 }
8039 if (cos2)
8040 mask[18] |= 0xe0;
8041 if (cos1)
8042 mask[14] |= 0xe0;
8043 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008044 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008045
Ed Warnickecb9cada2015-12-08 15:45:58 -07008046 *maskp = mask;
8047 return 1;
8048}
8049
Dave Barach72d72232016-08-04 10:15:08 -04008050uword
8051unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008052{
Dave Barach72d72232016-08-04 10:15:08 -04008053 u8 **maskp = va_arg (*args, u8 **);
8054 u32 *skipp = va_arg (*args, u32 *);
8055 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008056 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008057 u8 *mask = 0;
8058 u8 *l2 = 0;
8059 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008060 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008061
Dave Barach72d72232016-08-04 10:15:08 -04008062 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8063 {
8064 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8065 ;
8066 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8067 ;
8068 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8069 ;
8070 else
8071 break;
8072 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008073
8074 if (mask || l2 || l3)
8075 {
8076 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008077 {
8078 /* "With a free Ethernet header in every package" */
8079 if (l2 == 0)
8080 vec_validate (l2, 13);
8081 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008082 if (vec_len (l3))
8083 {
8084 vec_append (mask, l3);
8085 vec_free (l3);
8086 }
Dave Barach72d72232016-08-04 10:15:08 -04008087 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008088
8089 /* Scan forward looking for the first significant mask octet */
8090 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008091 if (mask[i])
8092 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008093
8094 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008095 *skipp = i / sizeof (u32x4);
8096 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008097
8098 /* Pad mask to an even multiple of the vector size */
8099 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008100 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008101
8102 match = vec_len (mask) / sizeof (u32x4);
8103
Dave Barach72d72232016-08-04 10:15:08 -04008104 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8105 {
8106 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8107 if (*tmp || *(tmp + 1))
8108 break;
8109 match--;
8110 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008111 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008112 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008113
Dave Barach72d72232016-08-04 10:15:08 -04008114 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008115
8116 *matchp = match;
8117 *maskp = mask;
8118
8119 return 1;
8120 }
8121
8122 return 0;
8123}
8124
8125#define foreach_l2_next \
8126_(drop, DROP) \
8127_(ethernet, ETHERNET_INPUT) \
8128_(ip4, IP4_INPUT) \
8129_(ip6, IP6_INPUT)
8130
Dave Barach72d72232016-08-04 10:15:08 -04008131uword
8132unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008133{
Dave Barach72d72232016-08-04 10:15:08 -04008134 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008135 u32 next_index = 0;
8136 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008137
Ed Warnickecb9cada2015-12-08 15:45:58 -07008138#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008139 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008140 foreach_l2_next;
8141#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008142
Ed Warnickecb9cada2015-12-08 15:45:58 -07008143 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008144 {
8145 next_index = tmp;
8146 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008147 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008148
Ed Warnickecb9cada2015-12-08 15:45:58 -07008149 return 0;
8150
Dave Barach72d72232016-08-04 10:15:08 -04008151out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008152 *miss_next_indexp = next_index;
8153 return 1;
8154}
8155
8156#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008157_(drop, DROP) \
8158_(local, LOCAL) \
8159_(rewrite, REWRITE)
8160
Dave Barach72d72232016-08-04 10:15:08 -04008161uword
8162unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008163{
Dave Barach72d72232016-08-04 10:15:08 -04008164 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008165 u32 next_index = 0;
8166 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008167
Ed Warnickecb9cada2015-12-08 15:45:58 -07008168#define _(n,N) \
8169 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8170 foreach_ip_next;
8171#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008172
Ed Warnickecb9cada2015-12-08 15:45:58 -07008173 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008174 {
8175 next_index = tmp;
8176 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008177 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008178
Ed Warnickecb9cada2015-12-08 15:45:58 -07008179 return 0;
8180
Dave Barach72d72232016-08-04 10:15:08 -04008181out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008182 *miss_next_indexp = next_index;
8183 return 1;
8184}
8185
8186#define foreach_acl_next \
8187_(deny, DENY)
8188
Dave Barach72d72232016-08-04 10:15:08 -04008189uword
8190unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008191{
Dave Barach72d72232016-08-04 10:15:08 -04008192 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008193 u32 next_index = 0;
8194 u32 tmp;
8195
8196#define _(n,N) \
8197 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8198 foreach_acl_next;
8199#undef _
8200
8201 if (unformat (input, "permit"))
8202 {
8203 next_index = ~0;
8204 goto out;
8205 }
8206 else if (unformat (input, "%d", &tmp))
8207 {
8208 next_index = tmp;
8209 goto out;
8210 }
8211
8212 return 0;
8213
Dave Barach72d72232016-08-04 10:15:08 -04008214out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008215 *miss_next_indexp = next_index;
8216 return 1;
8217}
8218
Dave Barach72d72232016-08-04 10:15:08 -04008219uword
8220unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008221{
Dave Barach72d72232016-08-04 10:15:08 -04008222 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008223
8224 if (unformat (input, "conform-color"))
8225 *r = POLICE_CONFORM;
8226 else if (unformat (input, "exceed-color"))
8227 *r = POLICE_EXCEED;
8228 else
8229 return 0;
8230
8231 return 1;
8232}
8233
Dave Barach72d72232016-08-04 10:15:08 -04008234static int
8235api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008236{
Dave Barach72d72232016-08-04 10:15:08 -04008237 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008238 vl_api_classify_add_del_table_t *mp;
8239
8240 u32 nbuckets = 2;
8241 u32 skip = ~0;
8242 u32 match = ~0;
8243 int is_add = 1;
8244 u32 table_index = ~0;
8245 u32 next_table_index = ~0;
8246 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008247 u32 memory_size = 32 << 20;
8248 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008249 f64 timeout;
8250
Dave Barach72d72232016-08-04 10:15:08 -04008251 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8252 {
8253 if (unformat (i, "del"))
8254 is_add = 0;
8255 else if (unformat (i, "buckets %d", &nbuckets))
8256 ;
8257 else if (unformat (i, "memory_size %d", &memory_size))
8258 ;
8259 else if (unformat (i, "skip %d", &skip))
8260 ;
8261 else if (unformat (i, "match %d", &match))
8262 ;
8263 else if (unformat (i, "table %d", &table_index))
8264 ;
8265 else if (unformat (i, "mask %U", unformat_classify_mask,
8266 &mask, &skip, &match))
8267 ;
8268 else if (unformat (i, "next-table %d", &next_table_index))
8269 ;
8270 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8271 &miss_next_index))
8272 ;
8273 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8274 &miss_next_index))
8275 ;
8276 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8277 &miss_next_index))
8278 ;
8279 else
8280 break;
8281 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008282
Dave Barach72d72232016-08-04 10:15:08 -04008283 if (is_add && mask == 0)
8284 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008285 errmsg ("Mask required\n");
8286 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008287 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008288
Dave Barach72d72232016-08-04 10:15:08 -04008289 if (is_add && skip == ~0)
8290 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008291 errmsg ("skip count required\n");
8292 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008293 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008294
Dave Barach72d72232016-08-04 10:15:08 -04008295 if (is_add && match == ~0)
8296 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008297 errmsg ("match count required\n");
8298 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008299 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008300
Dave Barach72d72232016-08-04 10:15:08 -04008301 if (!is_add && table_index == ~0)
8302 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008303 errmsg ("table index required for delete\n");
8304 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008305 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008306
Dave Barach72d72232016-08-04 10:15:08 -04008307 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008308
8309 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008310 mp->table_index = ntohl (table_index);
8311 mp->nbuckets = ntohl (nbuckets);
8312 mp->memory_size = ntohl (memory_size);
8313 mp->skip_n_vectors = ntohl (skip);
8314 mp->match_n_vectors = ntohl (match);
8315 mp->next_table_index = ntohl (next_table_index);
8316 mp->miss_next_index = ntohl (miss_next_index);
8317 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008318
Dave Barach72d72232016-08-04 10:15:08 -04008319 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008320
Dave Barach72d72232016-08-04 10:15:08 -04008321 S;
8322 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008323 /* NOTREACHED */
8324}
8325
Dave Barach72d72232016-08-04 10:15:08 -04008326uword
8327unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008328{
Dave Barach72d72232016-08-04 10:15:08 -04008329 u8 **matchp = va_arg (*args, u8 **);
8330 u8 *match = 0;
8331 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008332 int version = 0;
8333 u32 version_val;
8334 int hdr_length = 0;
8335 u32 hdr_length_val;
8336 int src = 0, dst = 0;
8337 ip4_address_t src_val, dst_val;
8338 int proto = 0;
8339 u32 proto_val;
8340 int tos = 0;
8341 u32 tos_val;
8342 int length = 0;
8343 u32 length_val;
8344 int fragment_id = 0;
8345 u32 fragment_id_val;
8346 int ttl = 0;
8347 int ttl_val;
8348 int checksum = 0;
8349 u32 checksum_val;
8350
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008351 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008352 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008353 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008354 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008355 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008356 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008357 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008358 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008359 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008360 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008361 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008362 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008363 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008364 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008365 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008366 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008367 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008368 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008369 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008370 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008371 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008372 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008373 else
Dave Barach72d72232016-08-04 10:15:08 -04008374 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008375 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008376
Ed Warnickecb9cada2015-12-08 15:45:58 -07008377 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8378 + ttl + checksum == 0)
8379 return 0;
8380
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008381 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008382 * Aligned because we use the real comparison functions
8383 */
Dave Barach72d72232016-08-04 10:15:08 -04008384 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008385
Ed Warnickecb9cada2015-12-08 15:45:58 -07008386 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008387
Ed Warnickecb9cada2015-12-08 15:45:58 -07008388 /* These are realistically matched in practice */
8389 if (src)
8390 ip->src_address.as_u32 = src_val.as_u32;
8391
8392 if (dst)
8393 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008394
Ed Warnickecb9cada2015-12-08 15:45:58 -07008395 if (proto)
8396 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008397
Ed Warnickecb9cada2015-12-08 15:45:58 -07008398
8399 /* These are not, but they're included for completeness */
8400 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008401 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008402
8403 if (hdr_length)
8404 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008405
Ed Warnickecb9cada2015-12-08 15:45:58 -07008406 if (tos)
8407 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008408
Ed Warnickecb9cada2015-12-08 15:45:58 -07008409 if (length)
8410 ip->length = length_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008411
Ed Warnickecb9cada2015-12-08 15:45:58 -07008412 if (ttl)
8413 ip->ttl = ttl_val;
8414
8415 if (checksum)
8416 ip->checksum = checksum_val;
8417
8418 *matchp = match;
8419 return 1;
8420}
8421
Dave Barach72d72232016-08-04 10:15:08 -04008422uword
8423unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008424{
Dave Barach72d72232016-08-04 10:15:08 -04008425 u8 **matchp = va_arg (*args, u8 **);
8426 u8 *match = 0;
8427 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008428 int version = 0;
8429 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008430 u8 traffic_class = 0;
8431 u32 traffic_class_val = 0;
8432 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008433 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008434 int src = 0, dst = 0;
8435 ip6_address_t src_val, dst_val;
8436 int proto = 0;
8437 u32 proto_val;
8438 int payload_length = 0;
8439 u32 payload_length_val;
8440 int hop_limit = 0;
8441 int hop_limit_val;
8442 u32 ip_version_traffic_class_and_flow_label;
8443
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008444 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008445 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008446 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008447 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008448 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008449 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008450 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008451 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008452 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008453 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008454 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008455 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008456 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008457 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008458 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008459 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008460 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008461 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008462 else
Dave Barach72d72232016-08-04 10:15:08 -04008463 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008464 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008465
Ed Warnickecb9cada2015-12-08 15:45:58 -07008466 if (version + traffic_class + flow_label + src + dst + proto +
8467 payload_length + hop_limit == 0)
8468 return 0;
8469
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008470 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008471 * Aligned because we use the real comparison functions
8472 */
Dave Barach72d72232016-08-04 10:15:08 -04008473 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008474
Ed Warnickecb9cada2015-12-08 15:45:58 -07008475 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008476
Ed Warnickecb9cada2015-12-08 15:45:58 -07008477 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008478 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008479
8480 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008481 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008482
Ed Warnickecb9cada2015-12-08 15:45:58 -07008483 if (proto)
8484 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008485
Ed Warnickecb9cada2015-12-08 15:45:58 -07008486 ip_version_traffic_class_and_flow_label = 0;
8487
8488 if (version)
8489 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8490
8491 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04008492 ip_version_traffic_class_and_flow_label |=
8493 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008494
8495 if (flow_label)
8496 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008497
8498 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008499 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8500
8501 if (payload_length)
8502 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008503
Ed Warnickecb9cada2015-12-08 15:45:58 -07008504 if (hop_limit)
8505 ip->hop_limit = hop_limit_val;
8506
8507 *matchp = match;
8508 return 1;
8509}
8510
Dave Barach72d72232016-08-04 10:15:08 -04008511uword
8512unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008513{
Dave Barach72d72232016-08-04 10:15:08 -04008514 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008515
Dave Barach72d72232016-08-04 10:15:08 -04008516 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8517 {
8518 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8519 return 1;
8520 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8521 return 1;
8522 else
8523 break;
8524 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008525 return 0;
8526}
8527
Dave Barach72d72232016-08-04 10:15:08 -04008528uword
8529unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008530{
Dave Barach72d72232016-08-04 10:15:08 -04008531 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008532 u32 tag;
8533
Dave Barach72d72232016-08-04 10:15:08 -04008534 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07008535 {
Dave Barach72d72232016-08-04 10:15:08 -04008536 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008537 tagp[1] = tag & 0xFF;
8538 return 1;
8539 }
8540
8541 return 0;
8542}
8543
Dave Barach72d72232016-08-04 10:15:08 -04008544uword
8545unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008546{
Dave Barach72d72232016-08-04 10:15:08 -04008547 u8 **matchp = va_arg (*args, u8 **);
8548 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008549 u8 src = 0;
8550 u8 src_val[6];
8551 u8 dst = 0;
8552 u8 dst_val[6];
8553 u8 proto = 0;
8554 u16 proto_val;
8555 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008556 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008557 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008558 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008559 int len = 14;
8560 u8 ignore_tag1 = 0;
8561 u8 ignore_tag2 = 0;
8562 u8 cos1 = 0;
8563 u8 cos2 = 0;
8564 u32 cos1_val = 0;
8565 u32 cos2_val = 0;
8566
Dave Barach72d72232016-08-04 10:15:08 -04008567 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8568 {
8569 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8570 src = 1;
8571 else
8572 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8573 dst = 1;
8574 else if (unformat (input, "proto %U",
8575 unformat_ethernet_type_host_byte_order, &proto_val))
8576 proto = 1;
8577 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8578 tag1 = 1;
8579 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8580 tag2 = 1;
8581 else if (unformat (input, "ignore-tag1"))
8582 ignore_tag1 = 1;
8583 else if (unformat (input, "ignore-tag2"))
8584 ignore_tag2 = 1;
8585 else if (unformat (input, "cos1 %d", &cos1_val))
8586 cos1 = 1;
8587 else if (unformat (input, "cos2 %d", &cos2_val))
8588 cos2 = 1;
8589 else
8590 break;
8591 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008592 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04008593 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008594 return 0;
8595
8596 if (tag1 || ignore_tag1 || cos1)
8597 len = 18;
8598 if (tag2 || ignore_tag2 || cos2)
8599 len = 22;
8600
Dave Barach72d72232016-08-04 10:15:08 -04008601 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008602
8603 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008604 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008605
8606 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008607 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008608
Ed Warnickecb9cada2015-12-08 15:45:58 -07008609 if (tag2)
8610 {
8611 /* inner vlan tag */
8612 match[19] = tag2_val[1];
8613 match[18] = tag2_val[0];
8614 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008615 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008616 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008617 {
8618 match[21] = proto_val & 0xff;
8619 match[20] = proto_val >> 8;
8620 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008621 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008622 {
8623 match[15] = tag1_val[1];
8624 match[14] = tag1_val[0];
8625 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008626 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008627 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008628 *matchp = match;
8629 return 1;
8630 }
8631 if (tag1)
8632 {
Dave Barach72d72232016-08-04 10:15:08 -04008633 match[15] = tag1_val[1];
8634 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07008635 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008636 {
8637 match[17] = proto_val & 0xff;
8638 match[16] = proto_val >> 8;
8639 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008640 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008641 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008642
8643 *matchp = match;
8644 return 1;
8645 }
8646 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008647 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008648 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008649 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008650 if (proto)
8651 {
8652 match[13] = proto_val & 0xff;
8653 match[12] = proto_val >> 8;
8654 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008655
Ed Warnickecb9cada2015-12-08 15:45:58 -07008656 *matchp = match;
8657 return 1;
8658}
8659
8660
Dave Barach72d72232016-08-04 10:15:08 -04008661uword
8662unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008663{
Dave Barach72d72232016-08-04 10:15:08 -04008664 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008665 u32 skip_n_vectors = va_arg (*args, u32);
8666 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008667
Dave Barach72d72232016-08-04 10:15:08 -04008668 u8 *match = 0;
8669 u8 *l2 = 0;
8670 u8 *l3 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008671
Dave Barach72d72232016-08-04 10:15:08 -04008672 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8673 {
8674 if (unformat (input, "hex %U", unformat_hex_string, &match))
8675 ;
8676 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8677 ;
8678 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8679 ;
8680 else
8681 break;
8682 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008683
8684 if (match || l2 || l3)
8685 {
8686 if (l2 || l3)
Dave Barach72d72232016-08-04 10:15:08 -04008687 {
8688 /* "Win a free Ethernet header in every packet" */
8689 if (l2 == 0)
8690 vec_validate_aligned (l2, 13, sizeof (u32x4));
8691 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008692 if (vec_len (l3))
8693 {
8694 vec_append_aligned (match, l3, sizeof (u32x4));
8695 vec_free (l3);
8696 }
Dave Barach72d72232016-08-04 10:15:08 -04008697 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008698
8699 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008700 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04008701 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8702 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008703
Dave Barach72d72232016-08-04 10:15:08 -04008704 /* Set size, include skipped vectors */
8705 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008706
8707 *matchp = match;
8708
8709 return 1;
8710 }
8711
8712 return 0;
8713}
8714
Dave Barach72d72232016-08-04 10:15:08 -04008715static int
8716api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008717{
Dave Barach72d72232016-08-04 10:15:08 -04008718 unformat_input_t *i = vam->input;
8719 vl_api_classify_add_del_session_t *mp;
8720 int is_add = 1;
8721 u32 table_index = ~0;
8722 u32 hit_next_index = ~0;
8723 u32 opaque_index = ~0;
8724 u8 *match = 0;
8725 i32 advance = 0;
8726 f64 timeout;
8727 u32 skip_n_vectors = 0;
8728 u32 match_n_vectors = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008729
Dave Barach72d72232016-08-04 10:15:08 -04008730 /*
8731 * Warning: you have to supply skip_n and match_n
8732 * because the API client cant simply look at the classify
8733 * table object.
8734 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008735
Dave Barach72d72232016-08-04 10:15:08 -04008736 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8737 {
8738 if (unformat (i, "del"))
8739 is_add = 0;
8740 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
8741 &hit_next_index))
8742 ;
8743 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8744 &hit_next_index))
8745 ;
8746 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
8747 &hit_next_index))
8748 ;
8749 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8750 ;
8751 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8752 ;
8753 else if (unformat (i, "opaque-index %d", &opaque_index))
8754 ;
8755 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8756 ;
8757 else if (unformat (i, "match_n %d", &match_n_vectors))
8758 ;
8759 else if (unformat (i, "match %U", unformat_classify_match,
8760 &match, skip_n_vectors, match_n_vectors))
8761 ;
8762 else if (unformat (i, "advance %d", &advance))
8763 ;
8764 else if (unformat (i, "table-index %d", &table_index))
8765 ;
8766 else
8767 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008768 }
8769
Dave Barach72d72232016-08-04 10:15:08 -04008770 if (table_index == ~0)
8771 {
8772 errmsg ("Table index required\n");
8773 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008774 }
8775
Dave Barach72d72232016-08-04 10:15:08 -04008776 if (is_add && match == 0)
8777 {
8778 errmsg ("Match value required\n");
8779 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008780 }
8781
Dave Barach72d72232016-08-04 10:15:08 -04008782 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008783
Dave Barach72d72232016-08-04 10:15:08 -04008784 mp->is_add = is_add;
8785 mp->table_index = ntohl (table_index);
8786 mp->hit_next_index = ntohl (hit_next_index);
8787 mp->opaque_index = ntohl (opaque_index);
8788 mp->advance = ntohl (advance);
8789 clib_memcpy (mp->match, match, vec_len (match));
8790 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008791
Dave Barach72d72232016-08-04 10:15:08 -04008792 S;
8793 W;
8794 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07008795}
8796
Dave Barach72d72232016-08-04 10:15:08 -04008797static int
8798api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008799{
Dave Barach72d72232016-08-04 10:15:08 -04008800 unformat_input_t *i = vam->input;
8801 vl_api_classify_set_interface_ip_table_t *mp;
8802 f64 timeout;
8803 u32 sw_if_index;
8804 int sw_if_index_set;
8805 u32 table_index = ~0;
8806 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008807
Dave Barach72d72232016-08-04 10:15:08 -04008808 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8809 {
8810 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8811 sw_if_index_set = 1;
8812 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8813 sw_if_index_set = 1;
8814 else if (unformat (i, "table %d", &table_index))
8815 ;
8816 else
8817 {
8818 clib_warning ("parse error '%U'", format_unformat_error, i);
8819 return -99;
8820 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008821 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008822
Dave Barach72d72232016-08-04 10:15:08 -04008823 if (sw_if_index_set == 0)
8824 {
8825 errmsg ("missing interface name or sw_if_index\n");
8826 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008827 }
8828
8829
Dave Barach72d72232016-08-04 10:15:08 -04008830 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008831
Dave Barach72d72232016-08-04 10:15:08 -04008832 mp->sw_if_index = ntohl (sw_if_index);
8833 mp->table_index = ntohl (table_index);
8834 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008835
Dave Barach72d72232016-08-04 10:15:08 -04008836 S;
8837 W;
8838 /* NOTREACHED */
8839 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008840}
8841
Dave Barach72d72232016-08-04 10:15:08 -04008842static int
8843api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008844{
Dave Barach72d72232016-08-04 10:15:08 -04008845 unformat_input_t *i = vam->input;
8846 vl_api_classify_set_interface_l2_tables_t *mp;
8847 f64 timeout;
8848 u32 sw_if_index;
8849 int sw_if_index_set;
8850 u32 ip4_table_index = ~0;
8851 u32 ip6_table_index = ~0;
8852 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04008853 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008854
Dave Barach72d72232016-08-04 10:15:08 -04008855 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8856 {
8857 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8858 sw_if_index_set = 1;
8859 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8860 sw_if_index_set = 1;
8861 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8862 ;
8863 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8864 ;
8865 else if (unformat (i, "other-table %d", &other_table_index))
8866 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04008867 else if (unformat (i, "is-input %d", &is_input))
8868 ;
Dave Barach72d72232016-08-04 10:15:08 -04008869 else
8870 {
8871 clib_warning ("parse error '%U'", format_unformat_error, i);
8872 return -99;
8873 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008874 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008875
Dave Barach72d72232016-08-04 10:15:08 -04008876 if (sw_if_index_set == 0)
8877 {
8878 errmsg ("missing interface name or sw_if_index\n");
8879 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008880 }
8881
8882
Dave Barach72d72232016-08-04 10:15:08 -04008883 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008884
Dave Barach72d72232016-08-04 10:15:08 -04008885 mp->sw_if_index = ntohl (sw_if_index);
8886 mp->ip4_table_index = ntohl (ip4_table_index);
8887 mp->ip6_table_index = ntohl (ip6_table_index);
8888 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04008889 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008890
Dave Barach72d72232016-08-04 10:15:08 -04008891 S;
8892 W;
8893 /* NOTREACHED */
8894 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008895}
8896
Dave Barach72d72232016-08-04 10:15:08 -04008897static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008898api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008899{
Dave Barach72d72232016-08-04 10:15:08 -04008900 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008901 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04008902 ip4_address_t collector_address;
8903 u8 collector_address_set = 0;
8904 u32 collector_port = ~0;
8905 ip4_address_t src_address;
8906 u8 src_address_set = 0;
8907 u32 vrf_id = ~0;
8908 u32 path_mtu = ~0;
8909 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008910 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008911 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008912
Dave Barach72d72232016-08-04 10:15:08 -04008913 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8914 {
8915 if (unformat (i, "collector_address %U", unformat_ip4_address,
8916 &collector_address))
8917 collector_address_set = 1;
8918 else if (unformat (i, "collector_port %d", &collector_port))
8919 ;
8920 else if (unformat (i, "src_address %U", unformat_ip4_address,
8921 &src_address))
8922 src_address_set = 1;
8923 else if (unformat (i, "vrf_id %d", &vrf_id))
8924 ;
8925 else if (unformat (i, "path_mtu %d", &path_mtu))
8926 ;
8927 else if (unformat (i, "template_interval %d", &template_interval))
8928 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008929 else if (unformat (i, "udp_checksum"))
8930 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04008931 else
8932 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008933 }
8934
Dave Barach72d72232016-08-04 10:15:08 -04008935 if (collector_address_set == 0)
8936 {
8937 errmsg ("collector_address required\n");
8938 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008939 }
8940
Dave Barach72d72232016-08-04 10:15:08 -04008941 if (src_address_set == 0)
8942 {
8943 errmsg ("src_address required\n");
8944 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008945 }
8946
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008947 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07008948
Dave Barach72d72232016-08-04 10:15:08 -04008949 memcpy (mp->collector_address, collector_address.data,
8950 sizeof (collector_address.data));
8951 mp->collector_port = htons ((u16) collector_port);
8952 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
8953 mp->vrf_id = htonl (vrf_id);
8954 mp->path_mtu = htonl (path_mtu);
8955 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07008956 mp->udp_checksum = udp_checksum;
8957
8958 S;
8959 W;
8960 /* NOTREACHED */
8961}
8962
8963static int
8964api_set_ipfix_classify_stream (vat_main_t * vam)
8965{
8966 unformat_input_t *i = vam->input;
8967 vl_api_set_ipfix_classify_stream_t *mp;
8968 u32 domain_id = 0;
8969 u32 src_port = UDP_DST_PORT_ipfix;
8970 f64 timeout;
8971
8972 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8973 {
8974 if (unformat (i, "domain %d", &domain_id))
8975 ;
8976 else if (unformat (i, "src_port %d", &src_port))
8977 ;
8978 else
8979 {
8980 errmsg ("unknown input `%U'", format_unformat_error, i);
8981 return -99;
8982 }
8983 }
8984
8985 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
8986
8987 mp->domain_id = htonl (domain_id);
8988 mp->src_port = htons ((u16) src_port);
8989
8990 S;
8991 W;
8992 /* NOTREACHED */
8993}
8994
8995static int
8996api_ipfix_classify_table_add_del (vat_main_t * vam)
8997{
8998 unformat_input_t *i = vam->input;
8999 vl_api_ipfix_classify_table_add_del_t *mp;
9000 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009001 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009002 u8 ip_version = 0;
9003 u8 transport_protocol = 255;
9004 f64 timeout;
9005
9006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9007 {
9008 if (unformat (i, "add"))
9009 is_add = 1;
9010 else if (unformat (i, "del"))
9011 is_add = 0;
9012 else if (unformat (i, "table %d", &classify_table_index))
9013 ;
9014 else if (unformat (i, "ip4"))
9015 ip_version = 4;
9016 else if (unformat (i, "ip6"))
9017 ip_version = 6;
9018 else if (unformat (i, "tcp"))
9019 transport_protocol = 6;
9020 else if (unformat (i, "udp"))
9021 transport_protocol = 17;
9022 else
9023 {
9024 errmsg ("unknown input `%U'", format_unformat_error, i);
9025 return -99;
9026 }
9027 }
9028
9029 if (is_add == -1)
9030 {
9031 errmsg ("expecting: add|del");
9032 return -99;
9033 }
9034 if (classify_table_index == ~0)
9035 {
9036 errmsg ("classifier table not specified");
9037 return -99;
9038 }
9039 if (ip_version == 0)
9040 {
9041 errmsg ("IP version not specified");
9042 return -99;
9043 }
9044
9045 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9046
9047 mp->is_add = is_add;
9048 mp->table_id = htonl (classify_table_index);
9049 mp->ip_version = ip_version;
9050 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009051
Dave Barach72d72232016-08-04 10:15:08 -04009052 S;
9053 W;
9054 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009055}
9056
Dave Barach72d72232016-08-04 10:15:08 -04009057static int
9058api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009059{
Dave Barach72d72232016-08-04 10:15:08 -04009060 unformat_input_t *i = vam->input;
9061 vl_api_get_node_index_t *mp;
9062 f64 timeout;
9063 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009064
Dave Barach72d72232016-08-04 10:15:08 -04009065 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9066 {
9067 if (unformat (i, "node %s", &name))
9068 ;
9069 else
9070 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009071 }
Dave Barach72d72232016-08-04 10:15:08 -04009072 if (name == 0)
9073 {
9074 errmsg ("node name required\n");
9075 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009076 }
Dave Barach72d72232016-08-04 10:15:08 -04009077 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9078 {
9079 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9080 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009081 }
9082
Dave Barach72d72232016-08-04 10:15:08 -04009083 M (GET_NODE_INDEX, get_node_index);
9084 clib_memcpy (mp->node_name, name, vec_len (name));
9085 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009086
Dave Barach72d72232016-08-04 10:15:08 -04009087 S;
9088 W;
9089 /* NOTREACHED */
9090 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009091}
9092
Dave Barach72d72232016-08-04 10:15:08 -04009093static int
9094api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009095{
Dave Barach72d72232016-08-04 10:15:08 -04009096 unformat_input_t *i = vam->input;
9097 vl_api_get_next_index_t *mp;
9098 f64 timeout;
9099 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009100
Dave Barach72d72232016-08-04 10:15:08 -04009101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9102 {
9103 if (unformat (i, "node-name %s", &node_name))
9104 ;
9105 else if (unformat (i, "next-node-name %s", &next_node_name))
9106 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009107 }
9108
Dave Barach72d72232016-08-04 10:15:08 -04009109 if (node_name == 0)
9110 {
9111 errmsg ("node name required\n");
9112 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009113 }
Dave Barach72d72232016-08-04 10:15:08 -04009114 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9115 {
9116 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9117 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009118 }
9119
Dave Barach72d72232016-08-04 10:15:08 -04009120 if (next_node_name == 0)
9121 {
9122 errmsg ("next node name required\n");
9123 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009124 }
Dave Barach72d72232016-08-04 10:15:08 -04009125 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9126 {
9127 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9128 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009129 }
9130
Dave Barach72d72232016-08-04 10:15:08 -04009131 M (GET_NEXT_INDEX, get_next_index);
9132 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9133 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9134 vec_free (node_name);
9135 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009136
Dave Barach72d72232016-08-04 10:15:08 -04009137 S;
9138 W;
9139 /* NOTREACHED */
9140 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009141}
9142
Dave Barach72d72232016-08-04 10:15:08 -04009143static int
9144api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009145{
Dave Barach72d72232016-08-04 10:15:08 -04009146 unformat_input_t *i = vam->input;
9147 vl_api_add_node_next_t *mp;
9148 f64 timeout;
9149 u8 *name = 0;
9150 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009151
Dave Barach72d72232016-08-04 10:15:08 -04009152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9153 {
9154 if (unformat (i, "node %s", &name))
9155 ;
9156 else if (unformat (i, "next %s", &next))
9157 ;
9158 else
9159 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160 }
Dave Barach72d72232016-08-04 10:15:08 -04009161 if (name == 0)
9162 {
9163 errmsg ("node name required\n");
9164 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009165 }
Dave Barach72d72232016-08-04 10:15:08 -04009166 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9167 {
9168 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9169 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009170 }
Dave Barach72d72232016-08-04 10:15:08 -04009171 if (next == 0)
9172 {
9173 errmsg ("next node required\n");
9174 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009175 }
Dave Barach72d72232016-08-04 10:15:08 -04009176 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9177 {
9178 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9179 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009180 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009181
Dave Barach72d72232016-08-04 10:15:08 -04009182 M (ADD_NODE_NEXT, add_node_next);
9183 clib_memcpy (mp->node_name, name, vec_len (name));
9184 clib_memcpy (mp->next_name, next, vec_len (next));
9185 vec_free (name);
9186 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009187
Dave Barach72d72232016-08-04 10:15:08 -04009188 S;
9189 W;
9190 /* NOTREACHED */
9191 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009192}
9193
Dave Barach72d72232016-08-04 10:15:08 -04009194static int
9195api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009196{
Dave Barach72d72232016-08-04 10:15:08 -04009197 unformat_input_t *i = vam->input;
9198 ip6_address_t client_address, our_address;
9199 int client_address_set = 0;
9200 int our_address_set = 0;
9201 u32 local_session_id = 0;
9202 u32 remote_session_id = 0;
9203 u64 local_cookie = 0;
9204 u64 remote_cookie = 0;
9205 u8 l2_sublayer_present = 0;
9206 vl_api_l2tpv3_create_tunnel_t *mp;
9207 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009208
Dave Barach72d72232016-08-04 10:15:08 -04009209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9210 {
9211 if (unformat (i, "client_address %U", unformat_ip6_address,
9212 &client_address))
9213 client_address_set = 1;
9214 else if (unformat (i, "our_address %U", unformat_ip6_address,
9215 &our_address))
9216 our_address_set = 1;
9217 else if (unformat (i, "local_session_id %d", &local_session_id))
9218 ;
9219 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9220 ;
9221 else if (unformat (i, "local_cookie %lld", &local_cookie))
9222 ;
9223 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9224 ;
9225 else if (unformat (i, "l2-sublayer-present"))
9226 l2_sublayer_present = 1;
9227 else
9228 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009229 }
9230
Dave Barach72d72232016-08-04 10:15:08 -04009231 if (client_address_set == 0)
9232 {
9233 errmsg ("client_address required\n");
9234 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009235 }
9236
Dave Barach72d72232016-08-04 10:15:08 -04009237 if (our_address_set == 0)
9238 {
9239 errmsg ("our_address required\n");
9240 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009241 }
9242
Dave Barach72d72232016-08-04 10:15:08 -04009243 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009244
Dave Barach72d72232016-08-04 10:15:08 -04009245 clib_memcpy (mp->client_address, client_address.as_u8,
9246 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009247
Dave Barach72d72232016-08-04 10:15:08 -04009248 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009249
Dave Barach72d72232016-08-04 10:15:08 -04009250 mp->local_session_id = ntohl (local_session_id);
9251 mp->remote_session_id = ntohl (remote_session_id);
9252 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9253 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9254 mp->l2_sublayer_present = l2_sublayer_present;
9255 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009256
Dave Barach72d72232016-08-04 10:15:08 -04009257 S;
9258 W;
9259 /* NOTREACHED */
9260 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009261}
9262
Dave Barach72d72232016-08-04 10:15:08 -04009263static int
9264api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009265{
Dave Barach72d72232016-08-04 10:15:08 -04009266 unformat_input_t *i = vam->input;
9267 u32 sw_if_index;
9268 u8 sw_if_index_set = 0;
9269 u64 new_local_cookie = 0;
9270 u64 new_remote_cookie = 0;
9271 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9272 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009273
Dave Barach72d72232016-08-04 10:15:08 -04009274 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9275 {
9276 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9277 sw_if_index_set = 1;
9278 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9279 sw_if_index_set = 1;
9280 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9281 ;
9282 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9283 ;
9284 else
9285 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009286 }
9287
Dave Barach72d72232016-08-04 10:15:08 -04009288 if (sw_if_index_set == 0)
9289 {
9290 errmsg ("missing interface name or sw_if_index\n");
9291 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009292 }
9293
Dave Barach72d72232016-08-04 10:15:08 -04009294 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009295
Dave Barach72d72232016-08-04 10:15:08 -04009296 mp->sw_if_index = ntohl (sw_if_index);
9297 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9298 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009299
Dave Barach72d72232016-08-04 10:15:08 -04009300 S;
9301 W;
9302 /* NOTREACHED */
9303 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009304}
9305
Dave Barach72d72232016-08-04 10:15:08 -04009306static int
9307api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009308{
Dave Barach72d72232016-08-04 10:15:08 -04009309 unformat_input_t *i = vam->input;
9310 vl_api_l2tpv3_interface_enable_disable_t *mp;
9311 f64 timeout;
9312 u32 sw_if_index;
9313 u8 sw_if_index_set = 0;
9314 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009315
Dave Barach72d72232016-08-04 10:15:08 -04009316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9317 {
9318 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9319 sw_if_index_set = 1;
9320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9321 sw_if_index_set = 1;
9322 else if (unformat (i, "enable"))
9323 enable_disable = 1;
9324 else if (unformat (i, "disable"))
9325 enable_disable = 0;
9326 else
9327 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009328 }
9329
Dave Barach72d72232016-08-04 10:15:08 -04009330 if (sw_if_index_set == 0)
9331 {
9332 errmsg ("missing interface name or sw_if_index\n");
9333 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009334 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009335
Dave Barach72d72232016-08-04 10:15:08 -04009336 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009337
Dave Barach72d72232016-08-04 10:15:08 -04009338 mp->sw_if_index = ntohl (sw_if_index);
9339 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009340
Dave Barach72d72232016-08-04 10:15:08 -04009341 S;
9342 W;
9343 /* NOTREACHED */
9344 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009345}
9346
Dave Barach72d72232016-08-04 10:15:08 -04009347static int
9348api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009349{
Dave Barach72d72232016-08-04 10:15:08 -04009350 unformat_input_t *i = vam->input;
9351 vl_api_l2tpv3_set_lookup_key_t *mp;
9352 f64 timeout;
9353 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009354
Dave Barach72d72232016-08-04 10:15:08 -04009355 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9356 {
9357 if (unformat (i, "lookup_v6_src"))
9358 key = L2T_LOOKUP_SRC_ADDRESS;
9359 else if (unformat (i, "lookup_v6_dst"))
9360 key = L2T_LOOKUP_DST_ADDRESS;
9361 else if (unformat (i, "lookup_session_id"))
9362 key = L2T_LOOKUP_SESSION_ID;
9363 else
9364 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009365 }
9366
Dave Barach72d72232016-08-04 10:15:08 -04009367 if (key == (u8) ~ 0)
9368 {
9369 errmsg ("l2tp session lookup key unset\n");
9370 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009371 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009372
Dave Barach72d72232016-08-04 10:15:08 -04009373 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009374
Dave Barach72d72232016-08-04 10:15:08 -04009375 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009376
Dave Barach72d72232016-08-04 10:15:08 -04009377 S;
9378 W;
9379 /* NOTREACHED */
9380 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009381}
9382
9383static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009384 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009385{
Dave Barach72d72232016-08-04 10:15:08 -04009386 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009387
Dave Barach72d72232016-08-04 10:15:08 -04009388 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9389 format_ip6_address, mp->our_address,
9390 format_ip6_address, mp->client_address,
9391 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009392
Dave Barach72d72232016-08-04 10:15:08 -04009393 fformat (vam->ofp,
9394 " local cookies %016llx %016llx remote cookie %016llx\n",
9395 clib_net_to_host_u64 (mp->local_cookie[0]),
9396 clib_net_to_host_u64 (mp->local_cookie[1]),
9397 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009398
Dave Barach72d72232016-08-04 10:15:08 -04009399 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9400 clib_net_to_host_u32 (mp->local_session_id),
9401 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009402
Dave Barach72d72232016-08-04 10:15:08 -04009403 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9404 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009405
9406}
9407
9408static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009409 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009410{
Dave Barach72d72232016-08-04 10:15:08 -04009411 vat_main_t *vam = &vat_main;
9412 vat_json_node_t *node = NULL;
9413 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009414
Dave Barach72d72232016-08-04 10:15:08 -04009415 if (VAT_JSON_ARRAY != vam->json_tree.type)
9416 {
9417 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9418 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009419 }
Dave Barach72d72232016-08-04 10:15:08 -04009420 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009421
Dave Barach72d72232016-08-04 10:15:08 -04009422 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009423
Dave Barach72d72232016-08-04 10:15:08 -04009424 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9425 vat_json_object_add_ip6 (node, "our_address", addr);
9426 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9427 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009428
Dave Barach72d72232016-08-04 10:15:08 -04009429 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9430 vat_json_init_array (lc);
9431 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9432 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9433 vat_json_object_add_uint (node, "remote_cookie",
9434 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009435
Dave Barach72d72232016-08-04 10:15:08 -04009436 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9437 vat_json_object_add_uint (node, "local_session_id",
9438 clib_net_to_host_u32 (mp->local_session_id));
9439 vat_json_object_add_uint (node, "remote_session_id",
9440 clib_net_to_host_u32 (mp->remote_session_id));
9441 vat_json_object_add_string_copy (node, "l2_sublayer",
9442 mp->l2_sublayer_present ? (u8 *) "present"
9443 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009444}
9445
Dave Barach72d72232016-08-04 10:15:08 -04009446static int
9447api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009448{
Dave Barach72d72232016-08-04 10:15:08 -04009449 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
9450 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009451
Dave Barach72d72232016-08-04 10:15:08 -04009452 /* Get list of l2tpv3-tunnel interfaces */
9453 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
9454 S;
9455
9456 /* Use a control ping for synchronization */
9457 {
9458 vl_api_control_ping_t *mp;
9459 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009460 S;
Dave Barach72d72232016-08-04 10:15:08 -04009461 }
9462 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009463}
9464
9465
9466static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009467 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009468{
Dave Barach72d72232016-08-04 10:15:08 -04009469 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009470
Dave Barach72d72232016-08-04 10:15:08 -04009471 fformat (vam->ofp, "%-16s %d\n",
9472 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009473}
9474
9475static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009476 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009477{
Dave Barach72d72232016-08-04 10:15:08 -04009478 vat_main_t *vam = &vat_main;
9479 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009480
Dave Barach72d72232016-08-04 10:15:08 -04009481 if (VAT_JSON_ARRAY != vam->json_tree.type)
9482 {
9483 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9484 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009485 }
Dave Barach72d72232016-08-04 10:15:08 -04009486 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009487
Dave Barach72d72232016-08-04 10:15:08 -04009488 vat_json_init_object (node);
9489 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9490 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009491}
9492
Dave Barach72d72232016-08-04 10:15:08 -04009493static int
9494api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009495{
Dave Barach72d72232016-08-04 10:15:08 -04009496 vl_api_sw_interface_tap_dump_t *mp;
9497 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009498
Dave Barach72d72232016-08-04 10:15:08 -04009499 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
9500 /* Get list of tap interfaces */
9501 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
9502 S;
9503
9504 /* Use a control ping for synchronization */
9505 {
9506 vl_api_control_ping_t *mp;
9507 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009508 S;
Dave Barach72d72232016-08-04 10:15:08 -04009509 }
9510 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009511}
9512
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009513static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -04009514 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009515{
Dave Barach72d72232016-08-04 10:15:08 -04009516 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009517 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009518
Ed Warnickecb9cada2015-12-08 15:45:58 -07009519 if (unformat (input, "drop"))
9520 *result = VXLAN_INPUT_NEXT_DROP;
9521 else if (unformat (input, "ip4"))
9522 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
9523 else if (unformat (input, "ip6"))
9524 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
9525 else if (unformat (input, "l2"))
9526 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9527 else if (unformat (input, "%d", &tmp))
9528 *result = tmp;
9529 else
9530 return 0;
9531 return 1;
9532}
9533
Dave Barach72d72232016-08-04 10:15:08 -04009534static int
9535api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009536{
Dave Barach72d72232016-08-04 10:15:08 -04009537 unformat_input_t *line_input = vam->input;
9538 vl_api_vxlan_add_del_tunnel_t *mp;
9539 f64 timeout;
9540 ip4_address_t src4, dst4;
9541 ip6_address_t src6, dst6;
9542 u8 is_add = 1;
9543 u8 ipv4_set = 0, ipv6_set = 0;
9544 u8 src_set = 0;
9545 u8 dst_set = 0;
9546 u32 encap_vrf_id = 0;
9547 u32 decap_next_index = ~0;
9548 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009549
Dave Barach72d72232016-08-04 10:15:08 -04009550 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9551 {
9552 if (unformat (line_input, "del"))
9553 is_add = 0;
9554 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9555 {
9556 ipv4_set = 1;
9557 src_set = 1;
9558 }
9559 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9560 {
9561 ipv4_set = 1;
9562 dst_set = 1;
9563 }
9564 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
9565 {
9566 ipv6_set = 1;
9567 src_set = 1;
9568 }
9569 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
9570 {
9571 ipv6_set = 1;
9572 dst_set = 1;
9573 }
9574 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9575 ;
9576 else if (unformat (line_input, "decap-next %U",
9577 unformat_vxlan_decap_next, &decap_next_index))
9578 ;
9579 else if (unformat (line_input, "vni %d", &vni))
9580 ;
9581 else
9582 {
9583 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9584 return -99;
9585 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009586 }
9587
Dave Barach72d72232016-08-04 10:15:08 -04009588 if (src_set == 0)
9589 {
9590 errmsg ("tunnel src address not specified\n");
9591 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009592 }
Dave Barach72d72232016-08-04 10:15:08 -04009593 if (dst_set == 0)
9594 {
9595 errmsg ("tunnel dst address not specified\n");
9596 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009597 }
9598
Dave Barach72d72232016-08-04 10:15:08 -04009599 if (ipv4_set && ipv6_set)
9600 {
9601 errmsg ("both IPv4 and IPv6 addresses specified");
9602 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -04009603 }
9604
Dave Barach72d72232016-08-04 10:15:08 -04009605 if ((vni == 0) || (vni >> 24))
9606 {
9607 errmsg ("vni not specified or out of range\n");
9608 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009609 }
9610
Dave Barach72d72232016-08-04 10:15:08 -04009611 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -04009612
Dave Barach72d72232016-08-04 10:15:08 -04009613 if (ipv6_set)
9614 {
9615 clib_memcpy (&mp->src_address, &src6, sizeof (src6));
9616 clib_memcpy (&mp->dst_address, &dst6, sizeof (dst6));
Chris Luke99cb3352016-04-26 10:49:53 -04009617 }
Dave Barach72d72232016-08-04 10:15:08 -04009618 else
9619 {
9620 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9621 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9622 }
9623 mp->encap_vrf_id = ntohl (encap_vrf_id);
9624 mp->decap_next_index = ntohl (decap_next_index);
9625 mp->vni = ntohl (vni);
9626 mp->is_add = is_add;
9627 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009628
Dave Barach72d72232016-08-04 10:15:08 -04009629 S;
9630 W;
9631 /* NOTREACHED */
9632 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009633}
9634
Dave Wallace60231f32015-12-17 21:04:30 -05009635static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009636 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009637{
Dave Barach72d72232016-08-04 10:15:08 -04009638 vat_main_t *vam = &vat_main;
Dave Wallace60231f32015-12-17 21:04:30 -05009639
Dave Barach72d72232016-08-04 10:15:08 -04009640 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
9641 ntohl (mp->sw_if_index),
9642 format_ip46_address, &(mp->src_address[0]),
9643 IP46_TYPE_ANY,
9644 format_ip46_address, &(mp->dst_address[0]),
9645 IP46_TYPE_ANY,
9646 ntohl (mp->encap_vrf_id),
9647 ntohl (mp->decap_next_index), ntohl (mp->vni));
Dave Wallace60231f32015-12-17 21:04:30 -05009648}
9649
9650static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009651 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -05009652{
Dave Barach72d72232016-08-04 10:15:08 -04009653 vat_main_t *vam = &vat_main;
9654 vat_json_node_t *node = NULL;
9655 struct in_addr ip4;
9656 struct in6_addr ip6;
Dave Wallace60231f32015-12-17 21:04:30 -05009657
Dave Barach72d72232016-08-04 10:15:08 -04009658 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -05009659 {
Dave Barach72d72232016-08-04 10:15:08 -04009660 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9661 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -05009662 }
Dave Barach72d72232016-08-04 10:15:08 -04009663 node = vat_json_array_add (&vam->json_tree);
9664
9665 vat_json_init_object (node);
9666 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9667 if (mp->is_ipv6)
9668 {
9669 clib_memcpy (&ip6, &(mp->src_address[0]), sizeof (ip6));
9670 vat_json_object_add_ip6 (node, "src_address", ip6);
9671 clib_memcpy (&ip6, &(mp->dst_address[0]), sizeof (ip6));
9672 vat_json_object_add_ip6 (node, "dst_address", ip6);
9673 }
9674 else
9675 {
9676 clib_memcpy (&ip4, &(mp->src_address[0]), sizeof (ip4));
9677 vat_json_object_add_ip4 (node, "src_address", ip4);
9678 clib_memcpy (&ip4, &(mp->dst_address[0]), sizeof (ip4));
9679 vat_json_object_add_ip4 (node, "dst_address", ip4);
9680 }
9681 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9682 vat_json_object_add_uint (node, "decap_next_index",
9683 ntohl (mp->decap_next_index));
9684 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9685 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Dave Wallace60231f32015-12-17 21:04:30 -05009686}
9687
Dave Barach72d72232016-08-04 10:15:08 -04009688static int
9689api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -04009690{
Dave Barach72d72232016-08-04 10:15:08 -04009691 unformat_input_t *i = vam->input;
9692 vl_api_vxlan_tunnel_dump_t *mp;
9693 f64 timeout;
9694 u32 sw_if_index;
9695 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009696
Dave Barach72d72232016-08-04 10:15:08 -04009697 /* Parse args required to build the message */
9698 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9699 {
9700 if (unformat (i, "sw_if_index %d", &sw_if_index))
9701 sw_if_index_set = 1;
9702 else
9703 break;
Chris Luke27fe48f2016-04-28 13:44:38 -04009704 }
9705
Dave Barach72d72232016-08-04 10:15:08 -04009706 if (sw_if_index_set == 0)
9707 {
9708 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009709 }
Dave Barach72d72232016-08-04 10:15:08 -04009710
9711 if (!vam->json_output)
9712 {
9713 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
9714 "sw_if_index", "src_address", "dst_address",
9715 "encap_vrf_id", "decap_next_index", "vni");
9716 }
9717
9718 /* Get list of vxlan-tunnel interfaces */
9719 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
9720
9721 mp->sw_if_index = htonl (sw_if_index);
9722
9723 S;
9724
9725 /* Use a control ping for synchronization */
9726 {
9727 vl_api_control_ping_t *mp;
9728 M (CONTROL_PING, control_ping);
9729 S;
9730 }
9731 W;
9732}
9733
9734static int
9735api_gre_add_del_tunnel (vat_main_t * vam)
9736{
9737 unformat_input_t *line_input = vam->input;
9738 vl_api_gre_add_del_tunnel_t *mp;
9739 f64 timeout;
9740 ip4_address_t src4, dst4;
9741 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -07009742 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009743 u8 src_set = 0;
9744 u8 dst_set = 0;
9745 u32 outer_fib_id = 0;
9746
9747 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9748 {
9749 if (unformat (line_input, "del"))
9750 is_add = 0;
9751 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
9752 src_set = 1;
9753 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
9754 dst_set = 1;
9755 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
9756 ;
David Hothama8cd3092016-09-19 09:55:07 -07009757 else if (unformat (line_input, "teb"))
9758 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009759 else
9760 {
9761 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9762 return -99;
9763 }
9764 }
9765
9766 if (src_set == 0)
9767 {
9768 errmsg ("tunnel src address not specified\n");
9769 return -99;
9770 }
9771 if (dst_set == 0)
9772 {
9773 errmsg ("tunnel dst address not specified\n");
9774 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -04009775 }
9776
9777
Dave Barach72d72232016-08-04 10:15:08 -04009778 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -04009779
Dave Barach72d72232016-08-04 10:15:08 -04009780 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
9781 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
9782 mp->outer_fib_id = ntohl (outer_fib_id);
9783 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -07009784 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -04009785
Dave Barach72d72232016-08-04 10:15:08 -04009786 S;
9787 W;
9788 /* NOTREACHED */
9789 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -04009790}
9791
9792static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009793 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009794{
Dave Barach72d72232016-08-04 10:15:08 -04009795 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -04009796
David Hothama8cd3092016-09-19 09:55:07 -07009797 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -04009798 ntohl (mp->sw_if_index),
9799 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -07009800 format_ip4_address, &mp->dst_address,
9801 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009802}
9803
9804static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009805 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04009806{
Dave Barach72d72232016-08-04 10:15:08 -04009807 vat_main_t *vam = &vat_main;
9808 vat_json_node_t *node = NULL;
9809 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -04009810
Dave Barach72d72232016-08-04 10:15:08 -04009811 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -04009812 {
Dave Barach72d72232016-08-04 10:15:08 -04009813 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9814 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -04009815 }
Dave Barach72d72232016-08-04 10:15:08 -04009816 node = vat_json_array_add (&vam->json_tree);
9817
9818 vat_json_init_object (node);
9819 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9820 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
9821 vat_json_object_add_ip4 (node, "src_address", ip4);
9822 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
9823 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -07009824 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -04009825 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -04009826}
9827
Dave Barach72d72232016-08-04 10:15:08 -04009828static int
9829api_gre_tunnel_dump (vat_main_t * vam)
9830{
9831 unformat_input_t *i = vam->input;
9832 vl_api_gre_tunnel_dump_t *mp;
9833 f64 timeout;
9834 u32 sw_if_index;
9835 u8 sw_if_index_set = 0;
9836
9837 /* Parse args required to build the message */
9838 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9839 {
9840 if (unformat (i, "sw_if_index %d", &sw_if_index))
9841 sw_if_index_set = 1;
9842 else
9843 break;
9844 }
9845
9846 if (sw_if_index_set == 0)
9847 {
9848 sw_if_index = ~0;
9849 }
9850
9851 if (!vam->json_output)
9852 {
David Hothama8cd3092016-09-19 09:55:07 -07009853 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
9854 "sw_if_index", "src_address", "dst_address", "teb",
9855 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -04009856 }
9857
9858 /* Get list of gre-tunnel interfaces */
9859 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
9860
9861 mp->sw_if_index = htonl (sw_if_index);
9862
9863 S;
9864
9865 /* Use a control ping for synchronization */
9866 {
9867 vl_api_control_ping_t *mp;
9868 M (CONTROL_PING, control_ping);
9869 S;
9870 }
9871 W;
9872}
9873
9874static int
9875api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009876{
9877// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -04009878 vl_api_l2_fib_clear_table_t *mp;
9879 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009880
Dave Barach72d72232016-08-04 10:15:08 -04009881 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009882
Dave Barach72d72232016-08-04 10:15:08 -04009883 S;
9884 W;
9885 /* NOTREACHED */
9886 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009887}
9888
Dave Barach72d72232016-08-04 10:15:08 -04009889static int
9890api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009891{
Dave Barach72d72232016-08-04 10:15:08 -04009892 unformat_input_t *i = vam->input;
9893 vl_api_l2_interface_efp_filter_t *mp;
9894 f64 timeout;
9895 u32 sw_if_index;
9896 u8 enable = 1;
9897 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009898
Dave Barach72d72232016-08-04 10:15:08 -04009899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9900 {
9901 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9902 sw_if_index_set = 1;
9903 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9904 sw_if_index_set = 1;
9905 else if (unformat (i, "enable"))
9906 enable = 1;
9907 else if (unformat (i, "disable"))
9908 enable = 0;
9909 else
9910 {
9911 clib_warning ("parse error '%U'", format_unformat_error, i);
9912 return -99;
9913 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009914 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009915
Dave Barach72d72232016-08-04 10:15:08 -04009916 if (sw_if_index_set == 0)
9917 {
9918 errmsg ("missing sw_if_index\n");
9919 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009920 }
9921
Dave Barach72d72232016-08-04 10:15:08 -04009922 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009923
Dave Barach72d72232016-08-04 10:15:08 -04009924 mp->sw_if_index = ntohl (sw_if_index);
9925 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009926
Dave Barach72d72232016-08-04 10:15:08 -04009927 S;
9928 W;
9929 /* NOTREACHED */
9930 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009931}
9932
9933#define foreach_vtr_op \
9934_("disable", L2_VTR_DISABLED) \
9935_("push-1", L2_VTR_PUSH_1) \
9936_("push-2", L2_VTR_PUSH_2) \
9937_("pop-1", L2_VTR_POP_1) \
9938_("pop-2", L2_VTR_POP_2) \
9939_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9940_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9941_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9942_("translate-2-2", L2_VTR_TRANSLATE_2_2)
9943
Dave Barach72d72232016-08-04 10:15:08 -04009944static int
9945api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009946{
Dave Barach72d72232016-08-04 10:15:08 -04009947 unformat_input_t *i = vam->input;
9948 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9949 f64 timeout;
9950 u32 sw_if_index;
9951 u8 sw_if_index_set = 0;
9952 u8 vtr_op_set = 0;
9953 u32 vtr_op = 0;
9954 u32 push_dot1q = 1;
9955 u32 tag1 = ~0;
9956 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009957
Dave Barach72d72232016-08-04 10:15:08 -04009958 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9959 {
9960 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9961 sw_if_index_set = 1;
9962 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9963 sw_if_index_set = 1;
9964 else if (unformat (i, "vtr_op %d", &vtr_op))
9965 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009966#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -04009967 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -07009968#undef _
Dave Barach72d72232016-08-04 10:15:08 -04009969 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9970 ;
9971 else if (unformat (i, "tag1 %d", &tag1))
9972 ;
9973 else if (unformat (i, "tag2 %d", &tag2))
9974 ;
9975 else
9976 {
9977 clib_warning ("parse error '%U'", format_unformat_error, i);
9978 return -99;
9979 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009980 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009981
Dave Barach72d72232016-08-04 10:15:08 -04009982 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9983 {
9984 errmsg ("missing vtr operation or sw_if_index\n");
9985 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009986 }
9987
Dave Barach72d72232016-08-04 10:15:08 -04009988 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
9989 mp->sw_if_index = ntohl (sw_if_index);
9990 mp->vtr_op = ntohl (vtr_op);
9991 mp->push_dot1q = ntohl (push_dot1q);
9992 mp->tag1 = ntohl (tag1);
9993 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009994
Dave Barach72d72232016-08-04 10:15:08 -04009995 S;
9996 W;
9997 /* NOTREACHED */
9998 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009999}
10000
Dave Barach72d72232016-08-04 10:15:08 -040010001static int
10002api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010003{
Dave Barach72d72232016-08-04 10:15:08 -040010004 unformat_input_t *i = vam->input;
10005 vl_api_create_vhost_user_if_t *mp;
10006 f64 timeout;
10007 u8 *file_name;
10008 u8 is_server = 0;
10009 u8 file_name_set = 0;
10010 u32 custom_dev_instance = ~0;
10011 u8 hwaddr[6];
10012 u8 use_custom_mac = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010013
Dave Barach72d72232016-08-04 10:15:08 -040010014 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10015 {
10016 if (unformat (i, "socket %s", &file_name))
10017 {
10018 file_name_set = 1;
10019 }
10020 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10021 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010022 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010023 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010024 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010025 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010026 else
Dave Barach72d72232016-08-04 10:15:08 -040010027 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010028 }
10029
Dave Barach72d72232016-08-04 10:15:08 -040010030 if (file_name_set == 0)
10031 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010032 errmsg ("missing socket file name\n");
10033 return -99;
10034 }
10035
Dave Barach72d72232016-08-04 10:15:08 -040010036 if (vec_len (file_name) > 255)
10037 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010038 errmsg ("socket file name too long\n");
10039 return -99;
10040 }
Dave Barach72d72232016-08-04 10:15:08 -040010041 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010042
Dave Barach72d72232016-08-04 10:15:08 -040010043 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010044
Dave Barach72d72232016-08-04 10:15:08 -040010045 mp->is_server = is_server;
10046 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10047 vec_free (file_name);
10048 if (custom_dev_instance != ~0)
10049 {
10050 mp->renumber = 1;
10051 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010052 }
Dave Barach72d72232016-08-04 10:15:08 -040010053 mp->use_custom_mac = use_custom_mac;
10054 clib_memcpy (mp->mac_address, hwaddr, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010055
Dave Barach72d72232016-08-04 10:15:08 -040010056 S;
10057 W;
10058 /* NOTREACHED */
10059 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010060}
10061
Dave Barach72d72232016-08-04 10:15:08 -040010062static int
10063api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010064{
Dave Barach72d72232016-08-04 10:15:08 -040010065 unformat_input_t *i = vam->input;
10066 vl_api_modify_vhost_user_if_t *mp;
10067 f64 timeout;
10068 u8 *file_name;
10069 u8 is_server = 0;
10070 u8 file_name_set = 0;
10071 u32 custom_dev_instance = ~0;
10072 u8 sw_if_index_set = 0;
10073 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010074
Dave Barach72d72232016-08-04 10:15:08 -040010075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10076 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010077 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010078 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010079 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010080 sw_if_index_set = 1;
10081 else if (unformat (i, "socket %s", &file_name))
10082 {
10083 file_name_set = 1;
10084 }
10085 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10086 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010087 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010088 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010089 else
Dave Barach72d72232016-08-04 10:15:08 -040010090 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010091 }
10092
Dave Barach72d72232016-08-04 10:15:08 -040010093 if (sw_if_index_set == 0)
10094 {
10095 errmsg ("missing sw_if_index or interface name\n");
10096 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010097 }
10098
Dave Barach72d72232016-08-04 10:15:08 -040010099 if (file_name_set == 0)
10100 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010101 errmsg ("missing socket file name\n");
10102 return -99;
10103 }
10104
Dave Barach72d72232016-08-04 10:15:08 -040010105 if (vec_len (file_name) > 255)
10106 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010107 errmsg ("socket file name too long\n");
10108 return -99;
10109 }
Dave Barach72d72232016-08-04 10:15:08 -040010110 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010111
Dave Barach72d72232016-08-04 10:15:08 -040010112 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010113
Dave Barach72d72232016-08-04 10:15:08 -040010114 mp->sw_if_index = ntohl (sw_if_index);
10115 mp->is_server = is_server;
10116 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10117 vec_free (file_name);
10118 if (custom_dev_instance != ~0)
10119 {
10120 mp->renumber = 1;
10121 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010122 }
10123
Dave Barach72d72232016-08-04 10:15:08 -040010124 S;
10125 W;
10126 /* NOTREACHED */
10127 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010128}
10129
Dave Barach72d72232016-08-04 10:15:08 -040010130static int
10131api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010132{
Dave Barach72d72232016-08-04 10:15:08 -040010133 unformat_input_t *i = vam->input;
10134 vl_api_delete_vhost_user_if_t *mp;
10135 f64 timeout;
10136 u32 sw_if_index = ~0;
10137 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010138
Dave Barach72d72232016-08-04 10:15:08 -040010139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10140 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010141 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010142 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010143 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010144 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010145 else
Dave Barach72d72232016-08-04 10:15:08 -040010146 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010147 }
10148
Dave Barach72d72232016-08-04 10:15:08 -040010149 if (sw_if_index_set == 0)
10150 {
10151 errmsg ("missing sw_if_index or interface name\n");
10152 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010153 }
10154
10155
Dave Barach72d72232016-08-04 10:15:08 -040010156 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010157
Dave Barach72d72232016-08-04 10:15:08 -040010158 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010159
Dave Barach72d72232016-08-04 10:15:08 -040010160 S;
10161 W;
10162 /* NOTREACHED */
10163 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010164}
10165
10166static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010167 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168{
Dave Barach72d72232016-08-04 10:15:08 -040010169 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010170
Dave Barach72d72232016-08-04 10:15:08 -040010171 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10172 (char *) mp->interface_name,
10173 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10174 clib_net_to_host_u64 (mp->features), mp->is_server,
10175 ntohl (mp->num_regions), (char *) mp->sock_filename);
10176 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010177}
10178
10179static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010180 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010181{
Dave Barach72d72232016-08-04 10:15:08 -040010182 vat_main_t *vam = &vat_main;
10183 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010184
Dave Barach72d72232016-08-04 10:15:08 -040010185 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010186 {
Dave Barach72d72232016-08-04 10:15:08 -040010187 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10188 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010189 }
Dave Barach72d72232016-08-04 10:15:08 -040010190 node = vat_json_array_add (&vam->json_tree);
10191
10192 vat_json_init_object (node);
10193 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10194 vat_json_object_add_string_copy (node, "interface_name",
10195 mp->interface_name);
10196 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10197 ntohl (mp->virtio_net_hdr_sz));
10198 vat_json_object_add_uint (node, "features",
10199 clib_net_to_host_u64 (mp->features));
10200 vat_json_object_add_uint (node, "is_server", mp->is_server);
10201 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10202 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10203 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010204}
10205
Dave Barach72d72232016-08-04 10:15:08 -040010206static int
10207api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010208{
Dave Barach72d72232016-08-04 10:15:08 -040010209 vl_api_sw_interface_vhost_user_dump_t *mp;
10210 f64 timeout;
10211 fformat (vam->ofp,
10212 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010213
Dave Barach72d72232016-08-04 10:15:08 -040010214 /* Get list of vhost-user interfaces */
10215 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10216 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010217
Dave Barach72d72232016-08-04 10:15:08 -040010218 /* Use a control ping for synchronization */
10219 {
10220 vl_api_control_ping_t *mp;
10221 M (CONTROL_PING, control_ping);
10222 S;
10223 }
10224 W;
10225}
10226
10227static int
10228api_show_version (vat_main_t * vam)
10229{
10230 vl_api_show_version_t *mp;
10231 f64 timeout;
10232
10233 M (SHOW_VERSION, show_version);
10234
10235 S;
10236 W;
10237 /* NOTREACHED */
10238 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010239}
10240
Ed Warnickecb9cada2015-12-08 15:45:58 -070010241
Dave Barach72d72232016-08-04 10:15:08 -040010242static int
10243api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010244{
Dave Barach72d72232016-08-04 10:15:08 -040010245 unformat_input_t *line_input = vam->input;
10246 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10247 f64 timeout;
10248 ip4_address_t local4, remote4;
10249 ip6_address_t local6, remote6;
10250 u8 is_add = 1;
10251 u8 ipv4_set = 0, ipv6_set = 0;
10252 u8 local_set = 0;
10253 u8 remote_set = 0;
10254 u32 encap_vrf_id = 0;
10255 u32 decap_vrf_id = 0;
10256 u8 protocol = ~0;
10257 u32 vni;
10258 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010259
Dave Barach72d72232016-08-04 10:15:08 -040010260 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10261 {
10262 if (unformat (line_input, "del"))
10263 is_add = 0;
10264 else if (unformat (line_input, "local %U",
10265 unformat_ip4_address, &local4))
10266 {
10267 local_set = 1;
10268 ipv4_set = 1;
10269 }
10270 else if (unformat (line_input, "remote %U",
10271 unformat_ip4_address, &remote4))
10272 {
10273 remote_set = 1;
10274 ipv4_set = 1;
10275 }
10276 else if (unformat (line_input, "local %U",
10277 unformat_ip6_address, &local6))
10278 {
10279 local_set = 1;
10280 ipv6_set = 1;
10281 }
10282 else if (unformat (line_input, "remote %U",
10283 unformat_ip6_address, &remote6))
10284 {
10285 remote_set = 1;
10286 ipv6_set = 1;
10287 }
10288 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10289 ;
10290 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10291 ;
10292 else if (unformat (line_input, "vni %d", &vni))
10293 vni_set = 1;
10294 else if (unformat (line_input, "next-ip4"))
10295 protocol = 1;
10296 else if (unformat (line_input, "next-ip6"))
10297 protocol = 2;
10298 else if (unformat (line_input, "next-ethernet"))
10299 protocol = 3;
10300 else if (unformat (line_input, "next-nsh"))
10301 protocol = 4;
10302 else
10303 {
10304 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10305 return -99;
10306 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010307 }
10308
Dave Barach72d72232016-08-04 10:15:08 -040010309 if (local_set == 0)
10310 {
10311 errmsg ("tunnel local address not specified\n");
10312 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010313 }
Dave Barach72d72232016-08-04 10:15:08 -040010314 if (remote_set == 0)
10315 {
10316 errmsg ("tunnel remote address not specified\n");
10317 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010318 }
Dave Barach72d72232016-08-04 10:15:08 -040010319 if (ipv4_set && ipv6_set)
10320 {
10321 errmsg ("both IPv4 and IPv6 addresses specified");
10322 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010323 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010324
Dave Barach72d72232016-08-04 10:15:08 -040010325 if (vni_set == 0)
10326 {
10327 errmsg ("vni not specified\n");
10328 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010329 }
10330
Dave Barach72d72232016-08-04 10:15:08 -040010331 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010332
Hongjun Nidf921cc2016-05-25 01:16:19 +080010333
Dave Barach72d72232016-08-04 10:15:08 -040010334 if (ipv6_set)
10335 {
10336 clib_memcpy (&mp->local, &local6, sizeof (local6));
10337 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10338 }
10339 else
10340 {
10341 clib_memcpy (&mp->local, &local4, sizeof (local4));
10342 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010343 }
10344
Dave Barach72d72232016-08-04 10:15:08 -040010345 mp->encap_vrf_id = ntohl (encap_vrf_id);
10346 mp->decap_vrf_id = ntohl (decap_vrf_id);
10347 mp->protocol = ntohl (protocol);
10348 mp->vni = ntohl (vni);
10349 mp->is_add = is_add;
10350 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010351
Dave Barach72d72232016-08-04 10:15:08 -040010352 S;
10353 W;
10354 /* NOTREACHED */
10355 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010356}
10357
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010358static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010359 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010360{
Dave Barach72d72232016-08-04 10:15:08 -040010361 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010362
Dave Barach72d72232016-08-04 10:15:08 -040010363 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10364 ntohl (mp->sw_if_index),
10365 format_ip46_address, &(mp->local[0]),
10366 format_ip46_address, &(mp->remote[0]),
10367 ntohl (mp->vni),
10368 ntohl (mp->protocol),
10369 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010370}
10371
10372static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010373 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010374{
Dave Barach72d72232016-08-04 10:15:08 -040010375 vat_main_t *vam = &vat_main;
10376 vat_json_node_t *node = NULL;
10377 struct in_addr ip4;
10378 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010379
Dave Barach72d72232016-08-04 10:15:08 -040010380 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010381 {
Dave Barach72d72232016-08-04 10:15:08 -040010382 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10383 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010384 }
Dave Barach72d72232016-08-04 10:15:08 -040010385 node = vat_json_array_add (&vam->json_tree);
10386
10387 vat_json_init_object (node);
10388 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10389 if (mp->is_ipv6)
10390 {
10391 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10392 vat_json_object_add_ip6 (node, "local", ip6);
10393 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10394 vat_json_object_add_ip6 (node, "remote", ip6);
10395 }
10396 else
10397 {
10398 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10399 vat_json_object_add_ip4 (node, "local", ip4);
10400 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10401 vat_json_object_add_ip4 (node, "remote", ip4);
10402 }
10403 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10404 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10405 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10406 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10407 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010408}
10409
Dave Barach72d72232016-08-04 10:15:08 -040010410static int
10411api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010412{
Dave Barach72d72232016-08-04 10:15:08 -040010413 unformat_input_t *i = vam->input;
10414 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10415 f64 timeout;
10416 u32 sw_if_index;
10417 u8 sw_if_index_set = 0;
10418
10419 /* Parse args required to build the message */
10420 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10421 {
10422 if (unformat (i, "sw_if_index %d", &sw_if_index))
10423 sw_if_index_set = 1;
10424 else
10425 break;
10426 }
10427
10428 if (sw_if_index_set == 0)
10429 {
10430 sw_if_index = ~0;
10431 }
10432
10433 if (!vam->json_output)
10434 {
10435 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
10436 "sw_if_index", "local", "remote", "vni",
10437 "protocol", "encap_vrf_id", "decap_vrf_id");
10438 }
10439
10440 /* Get list of vxlan-tunnel interfaces */
10441 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
10442
10443 mp->sw_if_index = htonl (sw_if_index);
10444
10445 S;
10446
10447 /* Use a control ping for synchronization */
10448 {
10449 vl_api_control_ping_t *mp;
10450 M (CONTROL_PING, control_ping);
10451 S;
10452 }
10453 W;
10454}
10455
10456u8 *
10457format_l2_fib_mac_address (u8 * s, va_list * args)
10458{
10459 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010460
10461 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040010462 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010463}
10464
10465static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010466 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010467{
Dave Barach72d72232016-08-04 10:15:08 -040010468 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010469
Dave Barach72d72232016-08-04 10:15:08 -040010470 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10471 " %d %d %d\n",
10472 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
10473 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10474 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010475}
10476
10477static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010478 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010479{
Dave Barach72d72232016-08-04 10:15:08 -040010480 vat_main_t *vam = &vat_main;
10481 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010482
Dave Barach72d72232016-08-04 10:15:08 -040010483 if (VAT_JSON_ARRAY != vam->json_tree.type)
10484 {
10485 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10486 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010487 }
Dave Barach72d72232016-08-04 10:15:08 -040010488 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010489
Dave Barach72d72232016-08-04 10:15:08 -040010490 vat_json_init_object (node);
10491 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10492 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
10493 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10494 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10495 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10496 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010497}
10498
Dave Barach72d72232016-08-04 10:15:08 -040010499static int
10500api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010501{
Dave Barach72d72232016-08-04 10:15:08 -040010502 unformat_input_t *i = vam->input;
10503 vl_api_l2_fib_table_dump_t *mp;
10504 f64 timeout;
10505 u32 bd_id;
10506 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010507
Dave Barach72d72232016-08-04 10:15:08 -040010508 /* Parse args required to build the message */
10509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010510 {
Dave Barach72d72232016-08-04 10:15:08 -040010511 if (unformat (i, "bd_id %d", &bd_id))
10512 bd_id_set = 1;
10513 else
10514 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010515 }
Dave Barach72d72232016-08-04 10:15:08 -040010516
10517 if (bd_id_set == 0)
10518 {
10519 errmsg ("missing bridge domain\n");
10520 return -99;
10521 }
10522
10523 fformat (vam->ofp,
10524 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
10525
10526 /* Get list of l2 fib entries */
10527 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
10528
10529 mp->bd_id = ntohl (bd_id);
10530 S;
10531
10532 /* Use a control ping for synchronization */
10533 {
10534 vl_api_control_ping_t *mp;
10535 M (CONTROL_PING, control_ping);
10536 S;
10537 }
10538 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010539}
10540
10541
10542static int
10543api_interface_name_renumber (vat_main_t * vam)
10544{
Dave Barach72d72232016-08-04 10:15:08 -040010545 unformat_input_t *line_input = vam->input;
10546 vl_api_interface_name_renumber_t *mp;
10547 u32 sw_if_index = ~0;
10548 f64 timeout;
10549 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010550
Dave Barach72d72232016-08-04 10:15:08 -040010551 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10552 {
10553 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
10554 &sw_if_index))
10555 ;
10556 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10557 ;
10558 else if (unformat (line_input, "new_show_dev_instance %d",
10559 &new_show_dev_instance))
10560 ;
10561 else
10562 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010563 }
10564
Dave Barach72d72232016-08-04 10:15:08 -040010565 if (sw_if_index == ~0)
10566 {
10567 errmsg ("missing interface name or sw_if_index\n");
10568 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010569 }
10570
Dave Barach72d72232016-08-04 10:15:08 -040010571 if (new_show_dev_instance == ~0)
10572 {
10573 errmsg ("missing new_show_dev_instance\n");
10574 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010575 }
10576
Dave Barach72d72232016-08-04 10:15:08 -040010577 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010578
Dave Barach72d72232016-08-04 10:15:08 -040010579 mp->sw_if_index = ntohl (sw_if_index);
10580 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010581
Dave Barach72d72232016-08-04 10:15:08 -040010582 S;
10583 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010584}
10585
10586static int
10587api_want_ip4_arp_events (vat_main_t * vam)
10588{
Dave Barach72d72232016-08-04 10:15:08 -040010589 unformat_input_t *line_input = vam->input;
10590 vl_api_want_ip4_arp_events_t *mp;
10591 f64 timeout;
10592 ip4_address_t address;
10593 int address_set = 0;
10594 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010595
Dave Barach72d72232016-08-04 10:15:08 -040010596 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10597 {
10598 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
10599 address_set = 1;
10600 else if (unformat (line_input, "del"))
10601 enable_disable = 0;
10602 else
10603 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010604 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010605
Dave Barach72d72232016-08-04 10:15:08 -040010606 if (address_set == 0)
10607 {
10608 errmsg ("missing addresses\n");
10609 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010610 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010611
Dave Barach72d72232016-08-04 10:15:08 -040010612 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
10613 mp->enable_disable = enable_disable;
10614 mp->pid = getpid ();
10615 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010616
Dave Barach72d72232016-08-04 10:15:08 -040010617 S;
10618 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010619}
10620
Dave Barach72d72232016-08-04 10:15:08 -040010621static int
John Lo1edfba92016-08-27 01:11:57 -040010622api_want_ip6_nd_events (vat_main_t * vam)
10623{
10624 unformat_input_t *line_input = vam->input;
10625 vl_api_want_ip6_nd_events_t *mp;
10626 f64 timeout;
10627 ip6_address_t address;
10628 int address_set = 0;
10629 u32 enable_disable = 1;
10630
10631 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10632 {
10633 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
10634 address_set = 1;
10635 else if (unformat (line_input, "del"))
10636 enable_disable = 0;
10637 else
10638 break;
10639 }
10640
10641 if (address_set == 0)
10642 {
10643 errmsg ("missing addresses\n");
10644 return -99;
10645 }
10646
10647 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
10648 mp->enable_disable = enable_disable;
10649 mp->pid = getpid ();
10650 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
10651
10652 S;
10653 W;
10654}
10655
10656static int
Dave Barach72d72232016-08-04 10:15:08 -040010657api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010658{
Dave Barach72d72232016-08-04 10:15:08 -040010659 unformat_input_t *i = vam->input;
10660 vl_api_input_acl_set_interface_t *mp;
10661 f64 timeout;
10662 u32 sw_if_index;
10663 int sw_if_index_set;
10664 u32 ip4_table_index = ~0;
10665 u32 ip6_table_index = ~0;
10666 u32 l2_table_index = ~0;
10667 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010668
Dave Barach72d72232016-08-04 10:15:08 -040010669 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10670 {
10671 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10672 sw_if_index_set = 1;
10673 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10674 sw_if_index_set = 1;
10675 else if (unformat (i, "del"))
10676 is_add = 0;
10677 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10678 ;
10679 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10680 ;
10681 else if (unformat (i, "l2-table %d", &l2_table_index))
10682 ;
10683 else
10684 {
10685 clib_warning ("parse error '%U'", format_unformat_error, i);
10686 return -99;
10687 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010688 }
10689
Dave Barach72d72232016-08-04 10:15:08 -040010690 if (sw_if_index_set == 0)
10691 {
10692 errmsg ("missing interface name or sw_if_index\n");
10693 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010694 }
10695
Dave Barach72d72232016-08-04 10:15:08 -040010696 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010697
Dave Barach72d72232016-08-04 10:15:08 -040010698 mp->sw_if_index = ntohl (sw_if_index);
10699 mp->ip4_table_index = ntohl (ip4_table_index);
10700 mp->ip6_table_index = ntohl (ip6_table_index);
10701 mp->l2_table_index = ntohl (l2_table_index);
10702 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010703
Dave Barach72d72232016-08-04 10:15:08 -040010704 S;
10705 W;
10706 /* NOTREACHED */
10707 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010708}
10709
10710static int
10711api_ip_address_dump (vat_main_t * vam)
10712{
Dave Barach72d72232016-08-04 10:15:08 -040010713 unformat_input_t *i = vam->input;
10714 vl_api_ip_address_dump_t *mp;
10715 u32 sw_if_index = ~0;
10716 u8 sw_if_index_set = 0;
10717 u8 ipv4_set = 0;
10718 u8 ipv6_set = 0;
10719 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010720
Dave Barach72d72232016-08-04 10:15:08 -040010721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010722 {
Dave Barach72d72232016-08-04 10:15:08 -040010723 if (unformat (i, "sw_if_index %d", &sw_if_index))
10724 sw_if_index_set = 1;
10725 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10726 sw_if_index_set = 1;
10727 else if (unformat (i, "ipv4"))
10728 ipv4_set = 1;
10729 else if (unformat (i, "ipv6"))
10730 ipv6_set = 1;
10731 else
10732 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010733 }
Dave Barach72d72232016-08-04 10:15:08 -040010734
10735 if (ipv4_set && ipv6_set)
10736 {
10737 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10738 return -99;
10739 }
10740
10741 if ((!ipv4_set) && (!ipv6_set))
10742 {
10743 errmsg ("no ipv4 nor ipv6 flag set\n");
10744 return -99;
10745 }
10746
10747 if (sw_if_index_set == 0)
10748 {
10749 errmsg ("missing interface name or sw_if_index\n");
10750 return -99;
10751 }
10752
10753 vam->current_sw_if_index = sw_if_index;
10754 vam->is_ipv6 = ipv6_set;
10755
10756 M (IP_ADDRESS_DUMP, ip_address_dump);
10757 mp->sw_if_index = ntohl (sw_if_index);
10758 mp->is_ipv6 = ipv6_set;
10759 S;
10760
10761 /* Use a control ping for synchronization */
10762 {
10763 vl_api_control_ping_t *mp;
10764 M (CONTROL_PING, control_ping);
10765 S;
10766 }
10767 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010768}
10769
10770static int
10771api_ip_dump (vat_main_t * vam)
10772{
Dave Barach72d72232016-08-04 10:15:08 -040010773 vl_api_ip_dump_t *mp;
10774 unformat_input_t *in = vam->input;
10775 int ipv4_set = 0;
10776 int ipv6_set = 0;
10777 int is_ipv6;
10778 f64 timeout;
10779 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010780
Dave Barach72d72232016-08-04 10:15:08 -040010781 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010782 {
Dave Barach72d72232016-08-04 10:15:08 -040010783 if (unformat (in, "ipv4"))
10784 ipv4_set = 1;
10785 else if (unformat (in, "ipv6"))
10786 ipv6_set = 1;
10787 else
10788 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010789 }
Dave Barach72d72232016-08-04 10:15:08 -040010790
10791 if (ipv4_set && ipv6_set)
10792 {
10793 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
10794 return -99;
10795 }
10796
10797 if ((!ipv4_set) && (!ipv6_set))
10798 {
10799 errmsg ("no ipv4 nor ipv6 flag set\n");
10800 return -99;
10801 }
10802
10803 is_ipv6 = ipv6_set;
10804 vam->is_ipv6 = is_ipv6;
10805
10806 /* free old data */
10807 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10808 {
10809 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10810 }
10811 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10812
10813 M (IP_DUMP, ip_dump);
10814 mp->is_ipv6 = ipv6_set;
10815 S;
10816
10817 /* Use a control ping for synchronization */
10818 {
10819 vl_api_control_ping_t *mp;
10820 M (CONTROL_PING, control_ping);
10821 S;
10822 }
10823 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010824}
10825
10826static int
10827api_ipsec_spd_add_del (vat_main_t * vam)
10828{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010829#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010830 unformat_input_t *i = vam->input;
10831 vl_api_ipsec_spd_add_del_t *mp;
10832 f64 timeout;
10833 u32 spd_id = ~0;
10834 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010835
Dave Barach72d72232016-08-04 10:15:08 -040010836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10837 {
10838 if (unformat (i, "spd_id %d", &spd_id))
10839 ;
10840 else if (unformat (i, "del"))
10841 is_add = 0;
10842 else
10843 {
10844 clib_warning ("parse error '%U'", format_unformat_error, i);
10845 return -99;
10846 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010847 }
Dave Barach72d72232016-08-04 10:15:08 -040010848 if (spd_id == ~0)
10849 {
10850 errmsg ("spd_id must be set\n");
10851 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010852 }
10853
Dave Barach72d72232016-08-04 10:15:08 -040010854 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010855
Dave Barach72d72232016-08-04 10:15:08 -040010856 mp->spd_id = ntohl (spd_id);
10857 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010858
Dave Barach72d72232016-08-04 10:15:08 -040010859 S;
10860 W;
10861 /* NOTREACHED */
10862 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010863#else
Dave Barach72d72232016-08-04 10:15:08 -040010864 clib_warning ("unsupported (no dpdk)");
10865 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010866#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010867}
10868
10869static int
10870api_ipsec_interface_add_del_spd (vat_main_t * vam)
10871{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010872#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010873 unformat_input_t *i = vam->input;
10874 vl_api_ipsec_interface_add_del_spd_t *mp;
10875 f64 timeout;
10876 u32 sw_if_index;
10877 u8 sw_if_index_set = 0;
10878 u32 spd_id = (u32) ~ 0;
10879 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010880
Dave Barach72d72232016-08-04 10:15:08 -040010881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10882 {
10883 if (unformat (i, "del"))
10884 is_add = 0;
10885 else if (unformat (i, "spd_id %d", &spd_id))
10886 ;
10887 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10888 sw_if_index_set = 1;
10889 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10890 sw_if_index_set = 1;
10891 else
10892 {
10893 clib_warning ("parse error '%U'", format_unformat_error, i);
10894 return -99;
10895 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010896
10897 }
10898
Dave Barach72d72232016-08-04 10:15:08 -040010899 if (spd_id == (u32) ~ 0)
10900 {
10901 errmsg ("spd_id must be set\n");
10902 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010903 }
10904
Dave Barach72d72232016-08-04 10:15:08 -040010905 if (sw_if_index_set == 0)
10906 {
10907 errmsg ("missing interface name or sw_if_index\n");
10908 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010909 }
10910
Dave Barach72d72232016-08-04 10:15:08 -040010911 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010912
Dave Barach72d72232016-08-04 10:15:08 -040010913 mp->spd_id = ntohl (spd_id);
10914 mp->sw_if_index = ntohl (sw_if_index);
10915 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010916
Dave Barach72d72232016-08-04 10:15:08 -040010917 S;
10918 W;
10919 /* NOTREACHED */
10920 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010921#else
Dave Barach72d72232016-08-04 10:15:08 -040010922 clib_warning ("unsupported (no dpdk)");
10923 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050010924#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070010925}
10926
10927static int
10928api_ipsec_spd_add_del_entry (vat_main_t * vam)
10929{
Dave Barachbfdedbd2016-01-20 09:11:55 -050010930#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040010931 unformat_input_t *i = vam->input;
10932 vl_api_ipsec_spd_add_del_entry_t *mp;
10933 f64 timeout;
10934 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040010935 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040010936 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010937 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10938 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10939 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
10940 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010941
Dave Barach72d72232016-08-04 10:15:08 -040010942 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
10943 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
10944 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
10945 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
10946 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
10947 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010948
Dave Barach72d72232016-08-04 10:15:08 -040010949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10950 {
10951 if (unformat (i, "del"))
10952 is_add = 0;
10953 if (unformat (i, "outbound"))
10954 is_outbound = 1;
10955 if (unformat (i, "inbound"))
10956 is_outbound = 0;
10957 else if (unformat (i, "spd_id %d", &spd_id))
10958 ;
10959 else if (unformat (i, "sa_id %d", &sa_id))
10960 ;
10961 else if (unformat (i, "priority %d", &priority))
10962 ;
10963 else if (unformat (i, "protocol %d", &protocol))
10964 ;
10965 else if (unformat (i, "lport_start %d", &lport_start))
10966 ;
10967 else if (unformat (i, "lport_stop %d", &lport_stop))
10968 ;
10969 else if (unformat (i, "rport_start %d", &rport_start))
10970 ;
10971 else if (unformat (i, "rport_stop %d", &rport_stop))
10972 ;
10973 else
10974 if (unformat
10975 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
10976 {
10977 is_ipv6 = 0;
10978 is_ip_any = 0;
10979 }
10980 else
10981 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
10982 {
10983 is_ipv6 = 0;
10984 is_ip_any = 0;
10985 }
10986 else
10987 if (unformat
10988 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
10989 {
10990 is_ipv6 = 0;
10991 is_ip_any = 0;
10992 }
10993 else
10994 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
10995 {
10996 is_ipv6 = 0;
10997 is_ip_any = 0;
10998 }
10999 else
11000 if (unformat
11001 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11002 {
11003 is_ipv6 = 1;
11004 is_ip_any = 0;
11005 }
11006 else
11007 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11008 {
11009 is_ipv6 = 1;
11010 is_ip_any = 0;
11011 }
11012 else
11013 if (unformat
11014 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11015 {
11016 is_ipv6 = 1;
11017 is_ip_any = 0;
11018 }
11019 else
11020 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11021 {
11022 is_ipv6 = 1;
11023 is_ip_any = 0;
11024 }
11025 else
11026 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11027 {
11028 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11029 {
11030 clib_warning ("unsupported action: 'resolve'");
11031 return -99;
11032 }
11033 }
11034 else
11035 {
11036 clib_warning ("parse error '%U'", format_unformat_error, i);
11037 return -99;
11038 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011039
11040 }
11041
Dave Barach72d72232016-08-04 10:15:08 -040011042 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011043
Dave Barach72d72232016-08-04 10:15:08 -040011044 mp->spd_id = ntohl (spd_id);
11045 mp->priority = ntohl (priority);
11046 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011047
Dave Barach72d72232016-08-04 10:15:08 -040011048 mp->is_ipv6 = is_ipv6;
11049 if (is_ipv6 || is_ip_any)
11050 {
11051 clib_memcpy (mp->remote_address_start, &raddr6_start,
11052 sizeof (ip6_address_t));
11053 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11054 sizeof (ip6_address_t));
11055 clib_memcpy (mp->local_address_start, &laddr6_start,
11056 sizeof (ip6_address_t));
11057 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11058 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011059 }
Dave Barach72d72232016-08-04 10:15:08 -040011060 else
11061 {
11062 clib_memcpy (mp->remote_address_start, &raddr4_start,
11063 sizeof (ip4_address_t));
11064 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11065 sizeof (ip4_address_t));
11066 clib_memcpy (mp->local_address_start, &laddr4_start,
11067 sizeof (ip4_address_t));
11068 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11069 sizeof (ip4_address_t));
11070 }
11071 mp->protocol = (u8) protocol;
11072 mp->local_port_start = ntohs ((u16) lport_start);
11073 mp->local_port_stop = ntohs ((u16) lport_stop);
11074 mp->remote_port_start = ntohs ((u16) rport_start);
11075 mp->remote_port_stop = ntohs ((u16) rport_stop);
11076 mp->policy = (u8) policy;
11077 mp->sa_id = ntohl (sa_id);
11078 mp->is_add = is_add;
11079 mp->is_ip_any = is_ip_any;
11080 S;
11081 W;
11082 /* NOTREACHED */
11083 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011084#else
Dave Barach72d72232016-08-04 10:15:08 -040011085 clib_warning ("unsupported (no dpdk)");
11086 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011087#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011088}
11089
11090static int
11091api_ipsec_sad_add_del_entry (vat_main_t * vam)
11092{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011093#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011094 unformat_input_t *i = vam->input;
11095 vl_api_ipsec_sad_add_del_entry_t *mp;
11096 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011097 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011098 u8 *ck = 0, *ik = 0;
11099 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011100
Dave Barach72d72232016-08-04 10:15:08 -040011101 u8 protocol = IPSEC_PROTOCOL_AH;
11102 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11103 u32 crypto_alg = 0, integ_alg = 0;
11104 ip4_address_t tun_src4;
11105 ip4_address_t tun_dst4;
11106 ip6_address_t tun_src6;
11107 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011108
Dave Barach72d72232016-08-04 10:15:08 -040011109 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11110 {
11111 if (unformat (i, "del"))
11112 is_add = 0;
11113 else if (unformat (i, "sad_id %d", &sad_id))
11114 ;
11115 else if (unformat (i, "spi %d", &spi))
11116 ;
11117 else if (unformat (i, "esp"))
11118 protocol = IPSEC_PROTOCOL_ESP;
11119 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11120 {
11121 is_tunnel = 1;
11122 is_tunnel_ipv6 = 0;
11123 }
11124 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11125 {
11126 is_tunnel = 1;
11127 is_tunnel_ipv6 = 0;
11128 }
11129 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11130 {
11131 is_tunnel = 1;
11132 is_tunnel_ipv6 = 1;
11133 }
11134 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11135 {
11136 is_tunnel = 1;
11137 is_tunnel_ipv6 = 1;
11138 }
11139 else
11140 if (unformat
11141 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11142 {
11143 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
11144 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256)
11145 {
11146 clib_warning ("unsupported crypto-alg: '%U'",
11147 format_ipsec_crypto_alg, crypto_alg);
11148 return -99;
11149 }
11150 }
11151 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11152 ;
11153 else
11154 if (unformat
11155 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11156 {
11157 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
11158 integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
11159 {
11160 clib_warning ("unsupported integ-alg: '%U'",
11161 format_ipsec_integ_alg, integ_alg);
11162 return -99;
11163 }
11164 }
11165 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11166 ;
11167 else
11168 {
11169 clib_warning ("parse error '%U'", format_unformat_error, i);
11170 return -99;
11171 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011172
11173 }
11174
Dave Barach72d72232016-08-04 10:15:08 -040011175 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011176
Dave Barach72d72232016-08-04 10:15:08 -040011177 mp->sad_id = ntohl (sad_id);
11178 mp->is_add = is_add;
11179 mp->protocol = protocol;
11180 mp->spi = ntohl (spi);
11181 mp->is_tunnel = is_tunnel;
11182 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11183 mp->crypto_algorithm = crypto_alg;
11184 mp->integrity_algorithm = integ_alg;
11185 mp->crypto_key_length = vec_len (ck);
11186 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011187
Dave Barach72d72232016-08-04 10:15:08 -040011188 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11189 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011190
Dave Barach72d72232016-08-04 10:15:08 -040011191 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11192 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011193
Dave Barach839fe3e2016-08-10 11:35:54 -040011194 if (ck)
11195 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11196 if (ik)
11197 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011198
Dave Barach72d72232016-08-04 10:15:08 -040011199 if (is_tunnel)
11200 {
11201 if (is_tunnel_ipv6)
11202 {
11203 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11204 sizeof (ip6_address_t));
11205 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11206 sizeof (ip6_address_t));
11207 }
11208 else
11209 {
11210 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11211 sizeof (ip4_address_t));
11212 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11213 sizeof (ip4_address_t));
11214 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011215 }
11216
Dave Barach72d72232016-08-04 10:15:08 -040011217 S;
11218 W;
11219 /* NOTREACHED */
11220 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011221#else
Dave Barach72d72232016-08-04 10:15:08 -040011222 clib_warning ("unsupported (no dpdk)");
11223 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011224#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011225}
11226
11227static int
11228api_ipsec_sa_set_key (vat_main_t * vam)
11229{
Dave Barachbfdedbd2016-01-20 09:11:55 -050011230#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011231 unformat_input_t *i = vam->input;
11232 vl_api_ipsec_sa_set_key_t *mp;
11233 f64 timeout;
11234 u32 sa_id;
11235 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011236
Dave Barach72d72232016-08-04 10:15:08 -040011237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11238 {
11239 if (unformat (i, "sa_id %d", &sa_id))
11240 ;
11241 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11242 ;
11243 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11244 ;
11245 else
11246 {
11247 clib_warning ("parse error '%U'", format_unformat_error, i);
11248 return -99;
11249 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011250 }
11251
Dave Barach72d72232016-08-04 10:15:08 -040011252 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011253
Dave Barach72d72232016-08-04 10:15:08 -040011254 mp->sa_id = ntohl (sa_id);
11255 mp->crypto_key_length = vec_len (ck);
11256 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011257
Dave Barach72d72232016-08-04 10:15:08 -040011258 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11259 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011260
Dave Barach72d72232016-08-04 10:15:08 -040011261 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11262 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011263
Dave Barach839fe3e2016-08-10 11:35:54 -040011264 if (ck)
11265 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11266 if (ik)
11267 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011268
Dave Barach72d72232016-08-04 10:15:08 -040011269 S;
11270 W;
11271 /* NOTREACHED */
11272 return 0;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011273#else
Dave Barach72d72232016-08-04 10:15:08 -040011274 clib_warning ("unsupported (no dpdk)");
11275 return -99;
Dave Barachbfdedbd2016-01-20 09:11:55 -050011276#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070011277}
11278
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011279static int
11280api_ikev2_profile_add_del (vat_main_t * vam)
11281{
11282#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011283 unformat_input_t *i = vam->input;
11284 vl_api_ikev2_profile_add_del_t *mp;
11285 f64 timeout;
11286 u8 is_add = 1;
11287 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011288
Dave Barach72d72232016-08-04 10:15:08 -040011289 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011290
Dave Barach72d72232016-08-04 10:15:08 -040011291 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11292 {
11293 if (unformat (i, "del"))
11294 is_add = 0;
11295 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11296 vec_add1 (name, 0);
11297 else
11298 {
11299 errmsg ("parse error '%U'", format_unformat_error, i);
11300 return -99;
11301 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011302 }
11303
Dave Barach72d72232016-08-04 10:15:08 -040011304 if (!vec_len (name))
11305 {
11306 errmsg ("profile name must be specified");
11307 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011308 }
11309
Dave Barach72d72232016-08-04 10:15:08 -040011310 if (vec_len (name) > 64)
11311 {
11312 errmsg ("profile name too long");
11313 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011314 }
11315
Dave Barach72d72232016-08-04 10:15:08 -040011316 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011317
Dave Barach72d72232016-08-04 10:15:08 -040011318 clib_memcpy (mp->name, name, vec_len (name));
11319 mp->is_add = is_add;
11320 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011321
Dave Barach72d72232016-08-04 10:15:08 -040011322 S;
11323 W;
11324 /* NOTREACHED */
11325 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011326#else
Dave Barach72d72232016-08-04 10:15:08 -040011327 clib_warning ("unsupported (no dpdk)");
11328 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011329#endif
11330}
11331
11332static int
11333api_ikev2_profile_set_auth (vat_main_t * vam)
11334{
11335#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011336 unformat_input_t *i = vam->input;
11337 vl_api_ikev2_profile_set_auth_t *mp;
11338 f64 timeout;
11339 u8 *name = 0;
11340 u8 *data = 0;
11341 u32 auth_method = 0;
11342 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011343
Dave Barach72d72232016-08-04 10:15:08 -040011344 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011345
Dave Barach72d72232016-08-04 10:15:08 -040011346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11347 {
11348 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11349 vec_add1 (name, 0);
11350 else if (unformat (i, "auth_method %U",
11351 unformat_ikev2_auth_method, &auth_method))
11352 ;
11353 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11354 is_hex = 1;
11355 else if (unformat (i, "auth_data %v", &data))
11356 ;
11357 else
11358 {
11359 errmsg ("parse error '%U'", format_unformat_error, i);
11360 return -99;
11361 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011362 }
11363
Dave Barach72d72232016-08-04 10:15:08 -040011364 if (!vec_len (name))
11365 {
11366 errmsg ("profile name must be specified");
11367 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011368 }
11369
Dave Barach72d72232016-08-04 10:15:08 -040011370 if (vec_len (name) > 64)
11371 {
11372 errmsg ("profile name too long");
11373 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011374 }
11375
Dave Barach72d72232016-08-04 10:15:08 -040011376 if (!vec_len (data))
11377 {
11378 errmsg ("auth_data must be specified");
11379 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011380 }
11381
Dave Barach72d72232016-08-04 10:15:08 -040011382 if (!auth_method)
11383 {
11384 errmsg ("auth_method must be specified");
11385 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011386 }
11387
Dave Barach72d72232016-08-04 10:15:08 -040011388 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011389
Dave Barach72d72232016-08-04 10:15:08 -040011390 mp->is_hex = is_hex;
11391 mp->auth_method = (u8) auth_method;
11392 mp->data_len = vec_len (data);
11393 clib_memcpy (mp->name, name, vec_len (name));
11394 clib_memcpy (mp->data, data, vec_len (data));
11395 vec_free (name);
11396 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011397
Dave Barach72d72232016-08-04 10:15:08 -040011398 S;
11399 W;
11400 /* NOTREACHED */
11401 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011402#else
Dave Barach72d72232016-08-04 10:15:08 -040011403 clib_warning ("unsupported (no dpdk)");
11404 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011405#endif
11406}
11407
11408static int
11409api_ikev2_profile_set_id (vat_main_t * vam)
11410{
11411#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011412 unformat_input_t *i = vam->input;
11413 vl_api_ikev2_profile_set_id_t *mp;
11414 f64 timeout;
11415 u8 *name = 0;
11416 u8 *data = 0;
11417 u8 is_local = 0;
11418 u32 id_type = 0;
11419 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011420
Dave Barach72d72232016-08-04 10:15:08 -040011421 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011422
Dave Barach72d72232016-08-04 10:15:08 -040011423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11424 {
11425 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11426 vec_add1 (name, 0);
11427 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
11428 ;
11429 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
11430 {
11431 data = vec_new (u8, 4);
11432 clib_memcpy (data, ip4.as_u8, 4);
11433 }
11434 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
11435 ;
11436 else if (unformat (i, "id_data %v", &data))
11437 ;
11438 else if (unformat (i, "local"))
11439 is_local = 1;
11440 else if (unformat (i, "remote"))
11441 is_local = 0;
11442 else
11443 {
11444 errmsg ("parse error '%U'", format_unformat_error, i);
11445 return -99;
11446 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011447 }
11448
Dave Barach72d72232016-08-04 10:15:08 -040011449 if (!vec_len (name))
11450 {
11451 errmsg ("profile name must be specified");
11452 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011453 }
11454
Dave Barach72d72232016-08-04 10:15:08 -040011455 if (vec_len (name) > 64)
11456 {
11457 errmsg ("profile name too long");
11458 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011459 }
11460
Dave Barach72d72232016-08-04 10:15:08 -040011461 if (!vec_len (data))
11462 {
11463 errmsg ("id_data must be specified");
11464 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011465 }
11466
Dave Barach72d72232016-08-04 10:15:08 -040011467 if (!id_type)
11468 {
11469 errmsg ("id_type must be specified");
11470 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011471 }
11472
Dave Barach72d72232016-08-04 10:15:08 -040011473 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011474
Dave Barach72d72232016-08-04 10:15:08 -040011475 mp->is_local = is_local;
11476 mp->id_type = (u8) id_type;
11477 mp->data_len = vec_len (data);
11478 clib_memcpy (mp->name, name, vec_len (name));
11479 clib_memcpy (mp->data, data, vec_len (data));
11480 vec_free (name);
11481 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011482
Dave Barach72d72232016-08-04 10:15:08 -040011483 S;
11484 W;
11485 /* NOTREACHED */
11486 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011487#else
Dave Barach72d72232016-08-04 10:15:08 -040011488 clib_warning ("unsupported (no dpdk)");
11489 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011490#endif
11491}
11492
11493static int
11494api_ikev2_profile_set_ts (vat_main_t * vam)
11495{
11496#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011497 unformat_input_t *i = vam->input;
11498 vl_api_ikev2_profile_set_ts_t *mp;
11499 f64 timeout;
11500 u8 *name = 0;
11501 u8 is_local = 0;
11502 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
11503 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011504
Dave Barach72d72232016-08-04 10:15:08 -040011505 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011506
Dave Barach72d72232016-08-04 10:15:08 -040011507 start_addr.as_u32 = 0;
11508 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011509
Dave Barach72d72232016-08-04 10:15:08 -040011510 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11511 {
11512 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11513 vec_add1 (name, 0);
11514 else if (unformat (i, "protocol %d", &proto))
11515 ;
11516 else if (unformat (i, "start_port %d", &start_port))
11517 ;
11518 else if (unformat (i, "end_port %d", &end_port))
11519 ;
11520 else
11521 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
11522 ;
11523 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
11524 ;
11525 else if (unformat (i, "local"))
11526 is_local = 1;
11527 else if (unformat (i, "remote"))
11528 is_local = 0;
11529 else
11530 {
11531 errmsg ("parse error '%U'", format_unformat_error, i);
11532 return -99;
11533 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011534 }
11535
Dave Barach72d72232016-08-04 10:15:08 -040011536 if (!vec_len (name))
11537 {
11538 errmsg ("profile name must be specified");
11539 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011540 }
11541
Dave Barach72d72232016-08-04 10:15:08 -040011542 if (vec_len (name) > 64)
11543 {
11544 errmsg ("profile name too long");
11545 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011546 }
11547
Dave Barach72d72232016-08-04 10:15:08 -040011548 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011549
Dave Barach72d72232016-08-04 10:15:08 -040011550 mp->is_local = is_local;
11551 mp->proto = (u8) proto;
11552 mp->start_port = (u16) start_port;
11553 mp->end_port = (u16) end_port;
11554 mp->start_addr = start_addr.as_u32;
11555 mp->end_addr = end_addr.as_u32;
11556 clib_memcpy (mp->name, name, vec_len (name));
11557 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011558
Dave Barach72d72232016-08-04 10:15:08 -040011559 S;
11560 W;
11561 /* NOTREACHED */
11562 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011563#else
Dave Barach72d72232016-08-04 10:15:08 -040011564 clib_warning ("unsupported (no dpdk)");
11565 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011566#endif
11567}
11568
11569static int
11570api_ikev2_set_local_key (vat_main_t * vam)
11571{
11572#if DPDK > 0
Dave Barach72d72232016-08-04 10:15:08 -040011573 unformat_input_t *i = vam->input;
11574 vl_api_ikev2_set_local_key_t *mp;
11575 f64 timeout;
11576 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011577
Dave Barach72d72232016-08-04 10:15:08 -040011578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11579 {
11580 if (unformat (i, "file %v", &file))
11581 vec_add1 (file, 0);
11582 else
11583 {
11584 errmsg ("parse error '%U'", format_unformat_error, i);
11585 return -99;
11586 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011587 }
11588
Dave Barach72d72232016-08-04 10:15:08 -040011589 if (!vec_len (file))
11590 {
11591 errmsg ("RSA key file must be specified");
11592 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011593 }
11594
Dave Barach72d72232016-08-04 10:15:08 -040011595 if (vec_len (file) > 256)
11596 {
11597 errmsg ("file name too long");
11598 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011599 }
11600
Dave Barach72d72232016-08-04 10:15:08 -040011601 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011602
Dave Barach72d72232016-08-04 10:15:08 -040011603 clib_memcpy (mp->key_file, file, vec_len (file));
11604 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011605
Dave Barach72d72232016-08-04 10:15:08 -040011606 S;
11607 W;
11608 /* NOTREACHED */
11609 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011610#else
Dave Barach72d72232016-08-04 10:15:08 -040011611 clib_warning ("unsupported (no dpdk)");
11612 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011613#endif
11614}
11615
Ed Warnickecb9cada2015-12-08 15:45:58 -070011616/*
11617 * MAP
11618 */
Dave Barach72d72232016-08-04 10:15:08 -040011619static int
11620api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011621{
11622 unformat_input_t *i = vam->input;
11623 vl_api_map_add_domain_t *mp;
11624 f64 timeout;
11625
11626 ip4_address_t ip4_prefix;
11627 ip6_address_t ip6_prefix;
11628 ip6_address_t ip6_src;
11629 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011630 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
11631 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011632 u8 is_translation = 0;
11633 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020011634 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011635
Dave Barach72d72232016-08-04 10:15:08 -040011636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11637 {
11638 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
11639 &ip4_prefix, &ip4_prefix_len))
11640 num_m_args++;
11641 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
11642 &ip6_prefix, &ip6_prefix_len))
11643 num_m_args++;
11644 else
11645 if (unformat
11646 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
11647 &ip6_src_len))
11648 num_m_args++;
11649 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
11650 num_m_args++;
11651 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
11652 num_m_args++;
11653 else if (unformat (i, "psid-offset %d", &psid_offset))
11654 num_m_args++;
11655 else if (unformat (i, "psid-len %d", &psid_length))
11656 num_m_args++;
11657 else if (unformat (i, "mtu %d", &mtu))
11658 num_m_args++;
11659 else if (unformat (i, "map-t"))
11660 is_translation = 1;
11661 else
11662 {
11663 clib_warning ("parse error '%U'", format_unformat_error, i);
11664 return -99;
11665 }
11666 }
11667
Ole Troan07e7eab2016-08-25 00:24:08 +020011668 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040011669 {
11670 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011671 return -99;
11672 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011673
11674 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011675 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011676
Dave Barach72d72232016-08-04 10:15:08 -040011677 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011678 mp->ip4_prefix_len = ip4_prefix_len;
11679
Dave Barach72d72232016-08-04 10:15:08 -040011680 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011681 mp->ip6_prefix_len = ip6_prefix_len;
11682
Dave Barach72d72232016-08-04 10:15:08 -040011683 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011684 mp->ip6_src_prefix_len = ip6_src_len;
11685
11686 mp->ea_bits_len = ea_bits_len;
11687 mp->psid_offset = psid_offset;
11688 mp->psid_length = psid_length;
11689 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040011690 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011691
11692 /* send it... */
11693 S;
11694
11695 /* Wait for a reply, return good/bad news */
11696 W;
11697}
11698
Dave Barach72d72232016-08-04 10:15:08 -040011699static int
11700api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011701{
11702 unformat_input_t *i = vam->input;
11703 vl_api_map_del_domain_t *mp;
11704 f64 timeout;
11705
11706 u32 num_m_args = 0;
11707 u32 index;
11708
Dave Barach72d72232016-08-04 10:15:08 -040011709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11710 {
11711 if (unformat (i, "index %d", &index))
11712 num_m_args++;
11713 else
11714 {
11715 clib_warning ("parse error '%U'", format_unformat_error, i);
11716 return -99;
11717 }
11718 }
11719
11720 if (num_m_args != 1)
11721 {
11722 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070011723 return -99;
11724 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011725
11726 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011727 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011728
Dave Barach72d72232016-08-04 10:15:08 -040011729 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011730
11731 /* send it... */
11732 S;
11733
11734 /* Wait for a reply, return good/bad news */
11735 W;
11736}
11737
Dave Barach72d72232016-08-04 10:15:08 -040011738static int
11739api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011740{
11741 unformat_input_t *i = vam->input;
11742 vl_api_map_add_del_rule_t *mp;
11743 f64 timeout;
11744 u8 is_add = 1;
11745 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040011746 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011747
Dave Barach72d72232016-08-04 10:15:08 -040011748 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11749 {
11750 if (unformat (i, "index %d", &index))
11751 num_m_args++;
11752 else if (unformat (i, "psid %d", &psid))
11753 num_m_args++;
11754 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
11755 num_m_args++;
11756 else if (unformat (i, "del"))
11757 {
11758 is_add = 0;
11759 }
11760 else
11761 {
11762 clib_warning ("parse error '%U'", format_unformat_error, i);
11763 return -99;
11764 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011765 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011766
11767 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040011768 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011769
Dave Barach72d72232016-08-04 10:15:08 -040011770 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011771 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040011772 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
11773 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011774
11775 /* send it... */
11776 S;
11777
11778 /* Wait for a reply, return good/bad news */
11779 W;
11780}
11781
Dave Barach72d72232016-08-04 10:15:08 -040011782static int
11783api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011784{
Dave Barach72d72232016-08-04 10:15:08 -040011785 vl_api_map_domain_dump_t *mp;
11786 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011787
Dave Barach72d72232016-08-04 10:15:08 -040011788 /* Construct the API message */
11789 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011790
Dave Barach72d72232016-08-04 10:15:08 -040011791 /* send it... */
11792 S;
11793
11794 /* Use a control ping for synchronization */
11795 {
11796 vl_api_control_ping_t *mp;
11797 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011798 S;
Dave Barach72d72232016-08-04 10:15:08 -040011799 }
11800 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011801}
11802
Dave Barach72d72232016-08-04 10:15:08 -040011803static int
11804api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011805{
Dave Barach72d72232016-08-04 10:15:08 -040011806 unformat_input_t *i = vam->input;
11807 vl_api_map_rule_dump_t *mp;
11808 f64 timeout;
11809 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011810
Dave Barach72d72232016-08-04 10:15:08 -040011811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011812 {
Dave Barach72d72232016-08-04 10:15:08 -040011813 if (unformat (i, "index %u", &domain_index))
11814 ;
11815 else
11816 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011817 }
Dave Barach72d72232016-08-04 10:15:08 -040011818
11819 if (domain_index == ~0)
11820 {
11821 clib_warning ("parse error: domain index expected");
11822 return -99;
11823 }
11824
11825 /* Construct the API message */
11826 M (MAP_RULE_DUMP, map_rule_dump);
11827
11828 mp->domain_index = htonl (domain_index);
11829
11830 /* send it... */
11831 S;
11832
11833 /* Use a control ping for synchronization */
11834 {
11835 vl_api_control_ping_t *mp;
11836 M (CONTROL_PING, control_ping);
11837 S;
11838 }
11839 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011840}
11841
11842static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011843 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011844{
Dave Barach72d72232016-08-04 10:15:08 -040011845 vat_main_t *vam = &vat_main;
11846 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011847
Dave Barach72d72232016-08-04 10:15:08 -040011848 if (vam->async_mode)
11849 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011850 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040011851 }
11852 else
11853 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070011854 vam->retval = retval;
11855 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040011856 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011857}
11858
11859static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011860 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011861{
Dave Barach72d72232016-08-04 10:15:08 -040011862 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011863 vat_json_node_t node;
11864
Dave Barach72d72232016-08-04 10:15:08 -040011865 vat_json_init_object (&node);
11866 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11867 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011868
Dave Barach72d72232016-08-04 10:15:08 -040011869 vat_json_print (vam->ofp, &node);
11870 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011871
Dave Barach72d72232016-08-04 10:15:08 -040011872 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011873 vam->result_ready = 1;
11874}
11875
11876static int
11877api_get_first_msg_id (vat_main_t * vam)
11878{
Dave Barach72d72232016-08-04 10:15:08 -040011879 vl_api_get_first_msg_id_t *mp;
11880 f64 timeout;
11881 unformat_input_t *i = vam->input;
11882 u8 *name;
11883 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011884
Dave Barach72d72232016-08-04 10:15:08 -040011885 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11886 {
11887 if (unformat (i, "client %s", &name))
11888 name_set = 1;
11889 else
11890 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011891 }
11892
Dave Barach72d72232016-08-04 10:15:08 -040011893 if (name_set == 0)
11894 {
11895 errmsg ("missing client name\n");
11896 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011897 }
Dave Barach72d72232016-08-04 10:15:08 -040011898 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011899
Dave Barach72d72232016-08-04 10:15:08 -040011900 if (vec_len (name) > 63)
11901 {
11902 errmsg ("client name too long\n");
11903 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011904 }
11905
Dave Barach72d72232016-08-04 10:15:08 -040011906 M (GET_FIRST_MSG_ID, get_first_msg_id);
11907 clib_memcpy (mp->name, name, vec_len (name));
11908 S;
11909 W;
11910 /* NOTREACHED */
11911 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011912}
11913
Dave Barach72d72232016-08-04 10:15:08 -040011914static int
11915api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011916{
Dave Barach72d72232016-08-04 10:15:08 -040011917 unformat_input_t *line_input = vam->input;
11918 vl_api_cop_interface_enable_disable_t *mp;
11919 f64 timeout;
11920 u32 sw_if_index = ~0;
11921 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011922
Dave Barach72d72232016-08-04 10:15:08 -040011923 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11924 {
11925 if (unformat (line_input, "disable"))
11926 enable_disable = 0;
11927 if (unformat (line_input, "enable"))
11928 enable_disable = 1;
11929 else if (unformat (line_input, "%U", unformat_sw_if_index,
11930 vam, &sw_if_index))
11931 ;
11932 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11933 ;
11934 else
11935 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011936 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011937
Dave Barach72d72232016-08-04 10:15:08 -040011938 if (sw_if_index == ~0)
11939 {
11940 errmsg ("missing interface name or sw_if_index\n");
11941 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011942 }
11943
Dave Barach72d72232016-08-04 10:15:08 -040011944 /* Construct the API message */
11945 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
11946 mp->sw_if_index = ntohl (sw_if_index);
11947 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011948
Dave Barach72d72232016-08-04 10:15:08 -040011949 /* send it... */
11950 S;
11951 /* Wait for the reply */
11952 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011953}
11954
Dave Barach72d72232016-08-04 10:15:08 -040011955static int
11956api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050011957{
Dave Barach72d72232016-08-04 10:15:08 -040011958 unformat_input_t *line_input = vam->input;
11959 vl_api_cop_whitelist_enable_disable_t *mp;
11960 f64 timeout;
11961 u32 sw_if_index = ~0;
11962 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040011963 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011964
Dave Barach72d72232016-08-04 10:15:08 -040011965 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11966 {
11967 if (unformat (line_input, "ip4"))
11968 ip4 = 1;
11969 else if (unformat (line_input, "ip6"))
11970 ip6 = 1;
11971 else if (unformat (line_input, "default"))
11972 default_cop = 1;
11973 else if (unformat (line_input, "%U", unformat_sw_if_index,
11974 vam, &sw_if_index))
11975 ;
11976 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11977 ;
11978 else if (unformat (line_input, "fib-id %d", &fib_id))
11979 ;
11980 else
11981 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011982 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011983
Dave Barach72d72232016-08-04 10:15:08 -040011984 if (sw_if_index == ~0)
11985 {
11986 errmsg ("missing interface name or sw_if_index\n");
11987 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011988 }
11989
Dave Barach72d72232016-08-04 10:15:08 -040011990 /* Construct the API message */
11991 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
11992 mp->sw_if_index = ntohl (sw_if_index);
11993 mp->fib_id = ntohl (fib_id);
11994 mp->ip4 = ip4;
11995 mp->ip6 = ip6;
11996 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050011997
Dave Barach72d72232016-08-04 10:15:08 -040011998 /* send it... */
11999 S;
12000 /* Wait for the reply */
12001 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012002}
12003
Dave Barach72d72232016-08-04 10:15:08 -040012004static int
12005api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012006{
Dave Barach72d72232016-08-04 10:15:08 -040012007 vl_api_get_node_graph_t *mp;
12008 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012009
Dave Barach72d72232016-08-04 10:15:08 -040012010 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012011
Dave Barach72d72232016-08-04 10:15:08 -040012012 /* send it... */
12013 S;
12014 /* Wait for the reply */
12015 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012016}
12017
Dave Barach72d72232016-08-04 10:15:08 -040012018/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012019/** Used for parsing LISP eids */
12020typedef CLIB_PACKED(struct{
12021 u8 addr[16]; /**< eid address */
12022 u32 len; /**< prefix length if IP */
12023 u8 type; /**< type of eid */
12024}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012025/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012026
12027static uword
12028unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12029{
Dave Barach72d72232016-08-04 10:15:08 -040012030 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012031
Dave Barach72d72232016-08-04 10:15:08 -040012032 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012033
Dave Barach72d72232016-08-04 10:15:08 -040012034 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12035 {
12036 a->type = 0; /* ipv4 type */
12037 }
12038 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12039 {
12040 a->type = 1; /* ipv6 type */
12041 }
12042 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12043 {
12044 a->type = 2; /* mac type */
12045 }
12046 else
12047 {
Florin Coras429e7952016-08-02 02:31:03 +020012048 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012049 }
Florin Coras429e7952016-08-02 02:31:03 +020012050
Dave Barach72d72232016-08-04 10:15:08 -040012051 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12052 {
Florin Coras429e7952016-08-02 02:31:03 +020012053 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012054 }
Florin Coras429e7952016-08-02 02:31:03 +020012055
12056 return 1;
12057}
12058
12059static int
12060lisp_eid_size_vat (u8 type)
12061{
Dave Barach72d72232016-08-04 10:15:08 -040012062 switch (type)
12063 {
Florin Coras429e7952016-08-02 02:31:03 +020012064 case 0:
12065 return 4;
12066 case 1:
12067 return 16;
12068 case 2:
12069 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012070 }
Florin Coras429e7952016-08-02 02:31:03 +020012071 return 0;
12072}
12073
12074static void
12075lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12076{
Dave Barach72d72232016-08-04 10:15:08 -040012077 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012078}
12079
Dave Barach72d72232016-08-04 10:15:08 -040012080/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012081/** Used for transferring locators via VPP API */
12082typedef CLIB_PACKED(struct
12083{
Dave Barach72d72232016-08-04 10:15:08 -040012084 u32 sw_if_index; /**< locator sw_if_index */
12085 u8 priority; /**< locator priority */
12086 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012087}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012088/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012089
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012090static int
Dave Barach72d72232016-08-04 10:15:08 -040012091api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012092{
Dave Barach72d72232016-08-04 10:15:08 -040012093 unformat_input_t *input = vam->input;
12094 vl_api_lisp_add_del_locator_set_t *mp;
12095 f64 timeout = ~0;
12096 u8 is_add = 1;
12097 u8 *locator_set_name = NULL;
12098 u8 locator_set_name_set = 0;
12099 ls_locator_t locator, *locators = 0;
12100 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012101 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012102
Dave Barach72d72232016-08-04 10:15:08 -040012103 /* Parse args required to build the message */
12104 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12105 {
12106 if (unformat (input, "del"))
12107 {
12108 is_add = 0;
12109 }
12110 else if (unformat (input, "locator-set %s", &locator_set_name))
12111 {
12112 locator_set_name_set = 1;
12113 }
12114 else if (unformat (input, "sw_if_index %u p %u w %u",
12115 &sw_if_index, &priority, &weight))
12116 {
12117 locator.sw_if_index = htonl (sw_if_index);
12118 locator.priority = priority;
12119 locator.weight = weight;
12120 vec_add1 (locators, locator);
12121 }
12122 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12123 vam, &sw_if_index, &priority, &weight))
12124 {
12125 locator.sw_if_index = htonl (sw_if_index);
12126 locator.priority = priority;
12127 locator.weight = weight;
12128 vec_add1 (locators, locator);
12129 }
12130 else
12131 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012132 }
12133
Dave Barach72d72232016-08-04 10:15:08 -040012134 if (locator_set_name_set == 0)
12135 {
12136 errmsg ("missing locator-set name");
12137 vec_free (locators);
12138 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012139 }
12140
Dave Barach72d72232016-08-04 10:15:08 -040012141 if (vec_len (locator_set_name) > 64)
12142 {
12143 errmsg ("locator-set name too long\n");
12144 vec_free (locator_set_name);
12145 vec_free (locators);
12146 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012147 }
Dave Barach72d72232016-08-04 10:15:08 -040012148 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012149
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012150 data_len = sizeof (ls_locator_t) * vec_len (locators);
12151
Dave Barach72d72232016-08-04 10:15:08 -040012152 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012153 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012154
Dave Barach72d72232016-08-04 10:15:08 -040012155 mp->is_add = is_add;
12156 clib_memcpy (mp->locator_set_name, locator_set_name,
12157 vec_len (locator_set_name));
12158 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012159
Filip Tehlare3552c42016-08-26 12:44:38 +020012160 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012161 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012162 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012163 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012164
Dave Barach72d72232016-08-04 10:15:08 -040012165 /* send it... */
12166 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012167
Dave Barach72d72232016-08-04 10:15:08 -040012168 /* Wait for a reply... */
12169 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012170
Dave Barach72d72232016-08-04 10:15:08 -040012171 /* NOTREACHED */
12172 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012173}
12174
12175static int
Dave Barach72d72232016-08-04 10:15:08 -040012176api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012177{
Dave Barach72d72232016-08-04 10:15:08 -040012178 unformat_input_t *input = vam->input;
12179 vl_api_lisp_add_del_locator_t *mp;
12180 f64 timeout = ~0;
12181 u32 tmp_if_index = ~0;
12182 u32 sw_if_index = ~0;
12183 u8 sw_if_index_set = 0;
12184 u8 sw_if_index_if_name_set = 0;
12185 u32 priority = ~0;
12186 u8 priority_set = 0;
12187 u32 weight = ~0;
12188 u8 weight_set = 0;
12189 u8 is_add = 1;
12190 u8 *locator_set_name = NULL;
12191 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012192
Dave Barach72d72232016-08-04 10:15:08 -040012193 /* Parse args required to build the message */
12194 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12195 {
12196 if (unformat (input, "del"))
12197 {
12198 is_add = 0;
12199 }
12200 else if (unformat (input, "locator-set %s", &locator_set_name))
12201 {
12202 locator_set_name_set = 1;
12203 }
12204 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12205 &tmp_if_index))
12206 {
12207 sw_if_index_if_name_set = 1;
12208 sw_if_index = tmp_if_index;
12209 }
12210 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12211 {
12212 sw_if_index_set = 1;
12213 sw_if_index = tmp_if_index;
12214 }
12215 else if (unformat (input, "p %d", &priority))
12216 {
12217 priority_set = 1;
12218 }
12219 else if (unformat (input, "w %d", &weight))
12220 {
12221 weight_set = 1;
12222 }
12223 else
12224 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012225 }
12226
Dave Barach72d72232016-08-04 10:15:08 -040012227 if (locator_set_name_set == 0)
12228 {
12229 errmsg ("missing locator-set name");
12230 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012231 }
12232
Dave Barach72d72232016-08-04 10:15:08 -040012233 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12234 {
12235 errmsg ("missing sw_if_index");
12236 vec_free (locator_set_name);
12237 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012238 }
12239
Dave Barach72d72232016-08-04 10:15:08 -040012240 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12241 {
12242 errmsg ("cannot use both params interface name and sw_if_index");
12243 vec_free (locator_set_name);
12244 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012245 }
12246
Dave Barach72d72232016-08-04 10:15:08 -040012247 if (priority_set == 0)
12248 {
12249 errmsg ("missing locator-set priority\n");
12250 vec_free (locator_set_name);
12251 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012252 }
12253
Dave Barach72d72232016-08-04 10:15:08 -040012254 if (weight_set == 0)
12255 {
12256 errmsg ("missing locator-set weight\n");
12257 vec_free (locator_set_name);
12258 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012259 }
12260
Dave Barach72d72232016-08-04 10:15:08 -040012261 if (vec_len (locator_set_name) > 64)
12262 {
12263 errmsg ("locator-set name too long\n");
12264 vec_free (locator_set_name);
12265 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012266 }
Dave Barach72d72232016-08-04 10:15:08 -040012267 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012268
Dave Barach72d72232016-08-04 10:15:08 -040012269 /* Construct the API message */
12270 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012271
Dave Barach72d72232016-08-04 10:15:08 -040012272 mp->is_add = is_add;
12273 mp->sw_if_index = ntohl (sw_if_index);
12274 mp->priority = priority;
12275 mp->weight = weight;
12276 clib_memcpy (mp->locator_set_name, locator_set_name,
12277 vec_len (locator_set_name));
12278 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012279
Dave Barach72d72232016-08-04 10:15:08 -040012280 /* send it... */
12281 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012282
Dave Barach72d72232016-08-04 10:15:08 -040012283 /* Wait for a reply... */
12284 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012285
Dave Barach72d72232016-08-04 10:15:08 -040012286 /* NOTREACHED */
12287 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012288}
12289
12290static int
Dave Barach72d72232016-08-04 10:15:08 -040012291api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012292{
Dave Barach72d72232016-08-04 10:15:08 -040012293 unformat_input_t *input = vam->input;
12294 vl_api_lisp_add_del_local_eid_t *mp;
12295 f64 timeout = ~0;
12296 u8 is_add = 1;
12297 u8 eid_set = 0;
12298 lisp_eid_vat_t _eid, *eid = &_eid;
12299 u8 *locator_set_name = 0;
12300 u8 locator_set_name_set = 0;
12301 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012302
Dave Barach72d72232016-08-04 10:15:08 -040012303 /* Parse args required to build the message */
12304 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12305 {
12306 if (unformat (input, "del"))
12307 {
12308 is_add = 0;
12309 }
12310 else if (unformat (input, "vni %d", &vni))
12311 {
12312 ;
12313 }
12314 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12315 {
12316 eid_set = 1;
12317 }
12318 else if (unformat (input, "locator-set %s", &locator_set_name))
12319 {
12320 locator_set_name_set = 1;
12321 }
12322 else
12323 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012324 }
12325
Dave Barach72d72232016-08-04 10:15:08 -040012326 if (locator_set_name_set == 0)
12327 {
12328 errmsg ("missing locator-set name\n");
12329 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012330 }
12331
Dave Barach72d72232016-08-04 10:15:08 -040012332 if (0 == eid_set)
12333 {
12334 errmsg ("EID address not set!");
12335 vec_free (locator_set_name);
12336 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012337 }
12338
Dave Barach72d72232016-08-04 10:15:08 -040012339 if (vec_len (locator_set_name) > 64)
12340 {
12341 errmsg ("locator-set name too long\n");
12342 vec_free (locator_set_name);
12343 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012344 }
Dave Barach72d72232016-08-04 10:15:08 -040012345 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012346
Dave Barach72d72232016-08-04 10:15:08 -040012347 /* Construct the API message */
12348 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012349
Dave Barach72d72232016-08-04 10:15:08 -040012350 mp->is_add = is_add;
12351 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12352 mp->eid_type = eid->type;
12353 mp->prefix_len = eid->len;
12354 mp->vni = clib_host_to_net_u32 (vni);
12355 clib_memcpy (mp->locator_set_name, locator_set_name,
12356 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012357
Dave Barach72d72232016-08-04 10:15:08 -040012358 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012359
Dave Barach72d72232016-08-04 10:15:08 -040012360 /* send it... */
12361 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012362
Dave Barach72d72232016-08-04 10:15:08 -040012363 /* Wait for a reply... */
12364 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012365
Dave Barach72d72232016-08-04 10:15:08 -040012366 /* NOTREACHED */
12367 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012368}
12369
Dave Barach72d72232016-08-04 10:15:08 -040012370/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012371/** Used for transferring locators via VPP API */
12372typedef CLIB_PACKED(struct
12373{
Dave Barach72d72232016-08-04 10:15:08 -040012374 u8 is_ip4; /**< is locator an IPv4 address? */
12375 u8 priority; /**< locator priority */
12376 u8 weight; /**< locator weight */
12377 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012378}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012379/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012380
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012381static int
Dave Barach72d72232016-08-04 10:15:08 -040012382api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012383{
Dave Barach72d72232016-08-04 10:15:08 -040012384 unformat_input_t *input = vam->input;
12385 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12386 f64 timeout = ~0;
12387 u8 is_add = 1;
12388 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12389 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12390 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12391 u32 action = ~0, p, w;
12392 ip4_address_t rmt_rloc4, lcl_rloc4;
12393 ip6_address_t rmt_rloc6, lcl_rloc6;
12394 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012395
Dave Barach839fe3e2016-08-10 11:35:54 -040012396 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012397
Dave Barach72d72232016-08-04 10:15:08 -040012398 /* Parse args required to build the message */
12399 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12400 {
12401 if (unformat (input, "del"))
12402 {
12403 is_add = 0;
12404 }
12405 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12406 {
12407 rmt_eid_set = 1;
12408 }
12409 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12410 {
12411 lcl_eid_set = 1;
12412 }
12413 else if (unformat (input, "p %d w %d", &p, &w))
12414 {
12415 if (!curr_rloc)
12416 {
12417 errmsg ("No RLOC configured for setting priority/weight!");
12418 return -99;
12419 }
12420 curr_rloc->priority = p;
12421 curr_rloc->weight = w;
12422 }
12423 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12424 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12425 {
12426 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012427
Dave Barach72d72232016-08-04 10:15:08 -040012428 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012429 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012430 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012431
Dave Barach72d72232016-08-04 10:15:08 -040012432 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12433 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012434 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012435 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12436 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012437 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012438 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12439 {
12440 rloc.is_ip4 = 0;
12441 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020012442 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012443 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012444
Dave Barach72d72232016-08-04 10:15:08 -040012445 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
12446 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012447 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012448 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12449 }
12450 else if (unformat (input, "action %d", &action))
12451 {
12452 ;
12453 }
12454 else
12455 {
12456 clib_warning ("parse error '%U'", format_unformat_error, input);
12457 return -99;
12458 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012459 }
12460
Dave Barach72d72232016-08-04 10:15:08 -040012461 if (!rmt_eid_set)
12462 {
12463 errmsg ("remote eid addresses not set\n");
12464 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012465 }
12466
Dave Barach72d72232016-08-04 10:15:08 -040012467 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
12468 {
12469 errmsg ("eid types don't match\n");
12470 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012471 }
12472
Dave Barach839fe3e2016-08-10 11:35:54 -040012473 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020012474 {
12475 errmsg ("action not set for negative mapping\n");
12476 return -99;
12477 }
12478
Dave Barach72d72232016-08-04 10:15:08 -040012479 /* Construct the API message */
12480 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012481
Dave Barach72d72232016-08-04 10:15:08 -040012482 mp->is_add = is_add;
12483 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
12484 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
12485 mp->eid_type = rmt_eid->type;
12486 mp->rmt_len = rmt_eid->len;
12487 mp->lcl_len = lcl_eid->len;
12488 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020012489
Florin Coras7fbfad32016-08-05 16:57:33 +020012490 if (0 != rmt_locs && 0 != lcl_locs)
12491 {
Dave Barach839fe3e2016-08-10 11:35:54 -040012492 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020012493 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012494 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012495 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012496 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012497 }
Dave Barach72d72232016-08-04 10:15:08 -040012498 vec_free (lcl_locs);
12499 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012500
Dave Barach72d72232016-08-04 10:15:08 -040012501 /* send it... */
12502 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012503
Dave Barach72d72232016-08-04 10:15:08 -040012504 /* Wait for a reply... */
12505 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012506
Dave Barach72d72232016-08-04 10:15:08 -040012507 /* NOTREACHED */
12508 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012509}
12510
12511static int
Dave Barach72d72232016-08-04 10:15:08 -040012512api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012513{
Dave Barach72d72232016-08-04 10:15:08 -040012514 unformat_input_t *input = vam->input;
12515 vl_api_lisp_add_del_map_resolver_t *mp;
12516 f64 timeout = ~0;
12517 u8 is_add = 1;
12518 u8 ipv4_set = 0;
12519 u8 ipv6_set = 0;
12520 ip4_address_t ipv4;
12521 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012522
Dave Barach72d72232016-08-04 10:15:08 -040012523 /* Parse args required to build the message */
12524 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12525 {
12526 if (unformat (input, "del"))
12527 {
12528 is_add = 0;
12529 }
12530 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
12531 {
12532 ipv4_set = 1;
12533 }
12534 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
12535 {
12536 ipv6_set = 1;
12537 }
12538 else
12539 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012540 }
12541
Dave Barach72d72232016-08-04 10:15:08 -040012542 if (ipv4_set && ipv6_set)
12543 {
12544 errmsg ("both eid v4 and v6 addresses set\n");
12545 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012546 }
12547
Dave Barach72d72232016-08-04 10:15:08 -040012548 if (!ipv4_set && !ipv6_set)
12549 {
12550 errmsg ("eid addresses not set\n");
12551 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012552 }
12553
Dave Barach72d72232016-08-04 10:15:08 -040012554 /* Construct the API message */
12555 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012556
Dave Barach72d72232016-08-04 10:15:08 -040012557 mp->is_add = is_add;
12558 if (ipv6_set)
12559 {
12560 mp->is_ipv6 = 1;
12561 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
12562 }
12563 else
12564 {
12565 mp->is_ipv6 = 0;
12566 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012567 }
12568
Dave Barach72d72232016-08-04 10:15:08 -040012569 /* send it... */
12570 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012571
Dave Barach72d72232016-08-04 10:15:08 -040012572 /* Wait for a reply... */
12573 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012574
Dave Barach72d72232016-08-04 10:15:08 -040012575 /* NOTREACHED */
12576 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012577}
12578
12579static int
Florin Coras577c3552016-04-21 00:45:40 +020012580api_lisp_gpe_enable_disable (vat_main_t * vam)
12581{
Dave Barach72d72232016-08-04 10:15:08 -040012582 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020012583 vl_api_lisp_gpe_enable_disable_t *mp;
12584 f64 timeout = ~0;
12585 u8 is_set = 0;
12586 u8 is_en = 1;
12587
12588 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040012589 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12590 {
12591 if (unformat (input, "enable"))
12592 {
12593 is_set = 1;
12594 is_en = 1;
12595 }
12596 else if (unformat (input, "disable"))
12597 {
12598 is_set = 1;
12599 is_en = 0;
12600 }
12601 else
12602 break;
12603 }
Florin Coras577c3552016-04-21 00:45:40 +020012604
Dave Barach72d72232016-08-04 10:15:08 -040012605 if (is_set == 0)
12606 {
12607 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020012608 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040012609 }
Florin Coras577c3552016-04-21 00:45:40 +020012610
12611 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012612 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020012613
12614 mp->is_en = is_en;
12615
12616 /* send it... */
12617 S;
12618
12619 /* Wait for a reply... */
12620 W;
12621
12622 /* NOTREACHED */
12623 return 0;
12624}
12625
12626static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020012627api_lisp_enable_disable (vat_main_t * vam)
12628{
Dave Barach72d72232016-08-04 10:15:08 -040012629 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012630 vl_api_lisp_enable_disable_t *mp;
12631 f64 timeout = ~0;
12632 u8 is_set = 0;
12633 u8 is_en = 0;
12634
12635 /* Parse args required to build the message */
12636 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12637 {
12638 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040012639 {
12640 is_set = 1;
12641 is_en = 1;
12642 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012643 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040012644 {
12645 is_set = 1;
12646 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020012647 else
Dave Barach72d72232016-08-04 10:15:08 -040012648 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020012649 }
12650
12651 if (!is_set)
12652 {
12653 errmsg ("Value not set\n");
12654 return -99;
12655 }
12656
12657 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012658 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020012659
12660 mp->is_en = is_en;
12661
12662 /* send it... */
12663 S;
12664
12665 /* Wait for a reply... */
12666 W;
12667
12668 /* NOTREACHED */
12669 return 0;
12670}
12671
Florin Corasdca88042016-09-14 16:01:38 +020012672static int
12673api_show_lisp_map_request_mode (vat_main_t * vam)
12674{
12675 f64 timeout = ~0;
12676 vl_api_show_lisp_map_request_mode_t *mp;
12677
12678 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
12679
12680 /* send */
12681 S;
12682
12683 /* wait for reply */
12684 W;
12685
12686 return 0;
12687}
12688
12689static int
12690api_lisp_map_request_mode (vat_main_t * vam)
12691{
12692 f64 timeout = ~0;
12693 unformat_input_t *input = vam->input;
12694 vl_api_lisp_map_request_mode_t *mp;
12695 u8 mode = 0;
12696
12697 /* Parse args required to build the message */
12698 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12699 {
12700 if (unformat (input, "dst-only"))
12701 mode = 0;
12702 else if (unformat (input, "src-dst"))
12703 mode = 1;
12704 else
12705 {
12706 errmsg ("parse error '%U'", format_unformat_error, input);
12707 return -99;
12708 }
12709 }
12710
12711 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
12712
12713 mp->mode = mode;
12714
12715 /* send */
12716 S;
12717
12718 /* wait for reply */
12719 W;
12720
12721 /* notreached */
12722 return 0;
12723}
12724
Filip Tehlar195bcee2016-05-13 17:37:35 +020012725/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020012726 * Enable/disable LISP proxy ITR.
12727 *
12728 * @param vam vpp API test context
12729 * @return return code
12730 */
12731static int
12732api_lisp_pitr_set_locator_set (vat_main_t * vam)
12733{
12734 f64 timeout = ~0;
12735 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012736 unformat_input_t *input = vam->input;
12737 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012738 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012739 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012740
12741 /* Parse args required to build the message */
12742 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12743 {
12744 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012745 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012746 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040012747 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020012748 else
Dave Barach72d72232016-08-04 10:15:08 -040012749 {
12750 errmsg ("parse error '%U'", format_unformat_error, input);
12751 return -99;
12752 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020012753 }
12754
12755 if (!ls_name_set)
12756 {
12757 errmsg ("locator-set name not set!");
12758 return -99;
12759 }
12760
Dave Barach72d72232016-08-04 10:15:08 -040012761 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020012762
12763 mp->is_add = is_add;
12764 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
12765 vec_free (ls_name);
12766
12767 /* send */
12768 S;
12769
12770 /* wait for reply */
12771 W;
12772
Dave Barach72d72232016-08-04 10:15:08 -040012773 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020012774 return 0;
12775}
12776
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012777static int
12778api_show_lisp_pitr (vat_main_t * vam)
12779{
Dave Barach72d72232016-08-04 10:15:08 -040012780 vl_api_show_lisp_pitr_t *mp;
12781 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012782
Dave Barach72d72232016-08-04 10:15:08 -040012783 if (!vam->json_output)
12784 {
12785 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012786 }
12787
Dave Barach72d72232016-08-04 10:15:08 -040012788 M (SHOW_LISP_PITR, show_lisp_pitr);
12789 /* send it... */
12790 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012791
Dave Barach72d72232016-08-04 10:15:08 -040012792 /* Wait for a reply... */
12793 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012794
Dave Barach72d72232016-08-04 10:15:08 -040012795 /* NOTREACHED */
12796 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020012797}
12798
Filip Tehlar53f09e32016-05-19 14:25:44 +020012799/**
Filip Tehlar324112f2016-06-02 16:07:38 +020012800 * Add/delete mapping between vni and vrf
12801 */
12802static int
12803api_lisp_eid_table_add_del_map (vat_main_t * vam)
12804{
12805 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040012806 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020012807 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020012808 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
12809 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020012810
12811 /* Parse args required to build the message */
12812 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12813 {
12814 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040012815 is_add = 0;
12816 else if (unformat (input, "vrf %d", &vrf))
12817 vrf_set = 1;
12818 else if (unformat (input, "bd_index %d", &bd_index))
12819 bd_index_set = 1;
12820 else if (unformat (input, "vni %d", &vni))
12821 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020012822 else
Dave Barach72d72232016-08-04 10:15:08 -040012823 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020012824 }
12825
Florin Coras1a1adc72016-07-22 01:45:30 +020012826 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020012827 {
12828 errmsg ("missing arguments!");
12829 return -99;
12830 }
12831
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012832 if (vrf_set && bd_index_set)
12833 {
12834 errmsg ("error: both vrf and bd entered!");
12835 return -99;
12836 }
12837
Dave Barach72d72232016-08-04 10:15:08 -040012838 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020012839
12840 mp->is_add = is_add;
12841 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020012842 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020012843 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020012844
12845 /* send */
12846 S;
12847
12848 /* wait for reply */
12849 W;
12850
Dave Barach72d72232016-08-04 10:15:08 -040012851 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020012852 return 0;
12853}
12854
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012855uword
12856unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
12857{
12858 u32 *action = va_arg (*args, u32 *);
12859 u8 *s = 0;
12860
12861 if (unformat (input, "%s", &s))
12862 {
12863 if (!strcmp ((char *) s, "no-action"))
12864 action[0] = 0;
12865 else if (!strcmp ((char *) s, "natively-forward"))
12866 action[0] = 1;
12867 else if (!strcmp ((char *) s, "send-map-request"))
12868 action[0] = 2;
12869 else if (!strcmp ((char *) s, "drop"))
12870 action[0] = 3;
12871 else
12872 {
12873 clib_warning ("invalid action: '%s'", s);
12874 action[0] = 3;
12875 }
12876 }
12877 else
12878 return 0;
12879
12880 vec_free (s);
12881 return 1;
12882}
12883
Filip Tehlar324112f2016-06-02 16:07:38 +020012884/**
Florin Corasf727db92016-06-23 15:01:58 +020012885 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020012886 *
12887 * @param vam vpp API test context
12888 * @return return code
12889 */
12890static int
12891api_lisp_add_del_remote_mapping (vat_main_t * vam)
12892{
Dave Barach72d72232016-08-04 10:15:08 -040012893 unformat_input_t *input = vam->input;
12894 vl_api_lisp_add_del_remote_mapping_t *mp;
12895 f64 timeout = ~0;
12896 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012897 lisp_eid_vat_t _eid, *eid = &_eid;
12898 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012899 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012900 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040012901 ip4_address_t rloc4;
12902 ip6_address_t rloc6;
12903 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012904
Dave Barach839fe3e2016-08-10 11:35:54 -040012905 memset (&rloc, 0, sizeof (rloc));
12906
Dave Barach72d72232016-08-04 10:15:08 -040012907 /* Parse args required to build the message */
12908 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12909 {
12910 if (unformat (input, "del-all"))
12911 {
12912 del_all = 1;
12913 }
12914 else if (unformat (input, "del"))
12915 {
12916 is_add = 0;
12917 }
12918 else if (unformat (input, "add"))
12919 {
12920 is_add = 1;
12921 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020012922 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040012923 {
12924 eid_set = 1;
12925 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012926 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040012927 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012928 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012929 }
12930 else if (unformat (input, "vni %d", &vni))
12931 {
12932 ;
12933 }
12934 else if (unformat (input, "p %d w %d", &p, &w))
12935 {
12936 if (!curr_rloc)
12937 {
12938 errmsg ("No RLOC configured for setting priority/weight!");
12939 return -99;
12940 }
12941 curr_rloc->priority = p;
12942 curr_rloc->weight = w;
12943 }
12944 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
12945 {
12946 rloc.is_ip4 = 1;
12947 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
12948 vec_add1 (rlocs, rloc);
12949 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12950 }
12951 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
12952 {
12953 rloc.is_ip4 = 0;
12954 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
12955 vec_add1 (rlocs, rloc);
12956 curr_rloc = &rlocs[vec_len (rlocs) - 1];
12957 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012958 else if (unformat (input, "action %U",
12959 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040012960 {
12961 ;
12962 }
12963 else
12964 {
12965 clib_warning ("parse error '%U'", format_unformat_error, input);
12966 return -99;
12967 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020012968 }
12969
Dave Barach72d72232016-08-04 10:15:08 -040012970 if (0 == eid_set)
12971 {
12972 errmsg ("missing params!");
12973 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012974 }
12975
Dave Barach72d72232016-08-04 10:15:08 -040012976 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
12977 {
12978 errmsg ("no action set for negative map-reply!");
12979 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020012980 }
12981
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012982 data_len = vec_len (rlocs) * sizeof (rloc_t);
12983
12984 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012985 mp->is_add = is_add;
12986 mp->vni = htonl (vni);
12987 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012988 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040012989 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012990 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040012991 mp->del_all = del_all;
12992 mp->eid_type = eid->type;
12993 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020012994 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020012995
Filip Tehlare3552c42016-08-26 12:44:38 +020012996 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012997 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012998 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020012999
Dave Barach72d72232016-08-04 10:15:08 -040013000 /* send it... */
13001 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013002
Dave Barach72d72232016-08-04 10:15:08 -040013003 /* Wait for a reply... */
13004 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013005
Dave Barach72d72232016-08-04 10:15:08 -040013006 /* NOTREACHED */
13007 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013008}
13009
Florin Corasf727db92016-06-23 15:01:58 +020013010/**
13011 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13012 * forwarding entries in data-plane accordingly.
13013 *
13014 * @param vam vpp API test context
13015 * @return return code
13016 */
13017static int
13018api_lisp_add_del_adjacency (vat_main_t * vam)
13019{
Dave Barach72d72232016-08-04 10:15:08 -040013020 unformat_input_t *input = vam->input;
13021 vl_api_lisp_add_del_adjacency_t *mp;
13022 f64 timeout = ~0;
13023 u32 vni = 0;
13024 ip4_address_t seid4, deid4;
13025 ip6_address_t seid6, deid6;
13026 u8 deid_mac[6] = { 0 };
13027 u8 seid_mac[6] = { 0 };
13028 u8 deid_type, seid_type;
13029 u32 seid_len = 0, deid_len = 0, len;
13030 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013031
Dave Barach72d72232016-08-04 10:15:08 -040013032 seid_type = deid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013033
Dave Barach72d72232016-08-04 10:15:08 -040013034 /* Parse args required to build the message */
13035 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13036 {
13037 if (unformat (input, "del"))
13038 {
13039 is_add = 0;
13040 }
13041 else if (unformat (input, "add"))
13042 {
13043 is_add = 1;
13044 }
13045 else if (unformat (input, "deid %U/%d", unformat_ip4_address,
13046 &deid4, &len))
13047 {
13048 deid_type = 0; /* ipv4 */
13049 deid_len = len;
13050 }
13051 else if (unformat (input, "deid %U/%d", unformat_ip6_address,
13052 &deid6, &len))
13053 {
13054 deid_type = 1; /* ipv6 */
13055 deid_len = len;
13056 }
13057 else if (unformat (input, "deid %U", unformat_ethernet_address,
13058 deid_mac))
13059 {
13060 deid_type = 2; /* mac */
13061 }
13062 else if (unformat (input, "seid %U/%d", unformat_ip4_address,
13063 &seid4, &len))
13064 {
13065 seid_type = 0; /* ipv4 */
13066 seid_len = len;
13067 }
13068 else if (unformat (input, "seid %U/%d", unformat_ip6_address,
13069 &seid6, &len))
13070 {
13071 seid_type = 1; /* ipv6 */
13072 seid_len = len;
13073 }
13074 else if (unformat (input, "seid %U", unformat_ethernet_address,
13075 seid_mac))
13076 {
13077 seid_type = 2; /* mac */
13078 }
13079 else if (unformat (input, "vni %d", &vni))
13080 {
13081 ;
13082 }
13083 else
13084 {
13085 errmsg ("parse error '%U'", format_unformat_error, input);
13086 return -99;
13087 }
Florin Corasf727db92016-06-23 15:01:58 +020013088 }
13089
Dave Barach72d72232016-08-04 10:15:08 -040013090 if ((u8) ~ 0 == deid_type)
13091 {
13092 errmsg ("missing params!");
13093 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013094 }
13095
Dave Barach72d72232016-08-04 10:15:08 -040013096 if (seid_type != deid_type)
13097 {
13098 errmsg ("source and destination EIDs are of different types!");
13099 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013100 }
13101
Dave Barach72d72232016-08-04 10:15:08 -040013102 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13103 mp->is_add = is_add;
13104 mp->vni = htonl (vni);
13105 mp->seid_len = seid_len;
13106 mp->deid_len = deid_len;
13107 mp->eid_type = deid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013108
Dave Barach72d72232016-08-04 10:15:08 -040013109 switch (mp->eid_type)
13110 {
Florin Corasf727db92016-06-23 15:01:58 +020013111 case 0:
Dave Barach72d72232016-08-04 10:15:08 -040013112 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
13113 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
13114 break;
Florin Corasf727db92016-06-23 15:01:58 +020013115 case 1:
Dave Barach72d72232016-08-04 10:15:08 -040013116 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
13117 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
13118 break;
Florin Corasf727db92016-06-23 15:01:58 +020013119 case 2:
Dave Barach72d72232016-08-04 10:15:08 -040013120 clib_memcpy (mp->seid, seid_mac, 6);
13121 clib_memcpy (mp->deid, deid_mac, 6);
13122 break;
Florin Corasf727db92016-06-23 15:01:58 +020013123 default:
Dave Barach72d72232016-08-04 10:15:08 -040013124 errmsg ("unknown EID type %d!", mp->eid_type);
13125 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013126 }
13127
Dave Barach72d72232016-08-04 10:15:08 -040013128 /* send it... */
13129 S;
Florin Corasf727db92016-06-23 15:01:58 +020013130
Dave Barach72d72232016-08-04 10:15:08 -040013131 /* Wait for a reply... */
13132 W;
Florin Corasf727db92016-06-23 15:01:58 +020013133
Dave Barach72d72232016-08-04 10:15:08 -040013134 /* NOTREACHED */
13135 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013136}
13137
Filip Tehlar46d4e362016-05-09 09:39:26 +020013138static int
Dave Barach72d72232016-08-04 10:15:08 -040013139api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013140{
Dave Barach72d72232016-08-04 10:15:08 -040013141 unformat_input_t *input = vam->input;
13142 vl_api_lisp_gpe_add_del_iface_t *mp;
13143 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013144 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013145 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013146
Dave Barach72d72232016-08-04 10:15:08 -040013147 /* Parse args required to build the message */
13148 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13149 {
13150 if (unformat (input, "up"))
13151 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013152 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013153 is_add = 1;
13154 }
13155 else if (unformat (input, "down"))
13156 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013157 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013158 is_add = 0;
13159 }
13160 else if (unformat (input, "table_id %d", &dp_table))
13161 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013162 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013163 }
13164 else if (unformat (input, "bd_id %d", &dp_table))
13165 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013166 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013167 is_l2 = 1;
13168 }
13169 else if (unformat (input, "vni %d", &vni))
13170 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013171 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013172 }
13173 else
13174 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013175 }
13176
Florin Coras7fbfad32016-08-05 16:57:33 +020013177 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013178 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013179 errmsg ("Action not set\n");
13180 return -99;
13181 }
13182 if (dp_table_set == 0 || vni_set == 0)
13183 {
13184 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013185 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013186 }
13187
Dave Barach72d72232016-08-04 10:15:08 -040013188 /* Construct the API message */
13189 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013190
Dave Barach72d72232016-08-04 10:15:08 -040013191 mp->is_add = is_add;
13192 mp->dp_table = dp_table;
13193 mp->is_l2 = is_l2;
13194 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013195
Dave Barach72d72232016-08-04 10:15:08 -040013196 /* send it... */
13197 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013198
Dave Barach72d72232016-08-04 10:15:08 -040013199 /* Wait for a reply... */
13200 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013201
Dave Barach72d72232016-08-04 10:15:08 -040013202 /* NOTREACHED */
13203 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013204}
13205
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013206/**
13207 * Add/del map request itr rlocs from LISP control plane and updates
13208 *
13209 * @param vam vpp API test context
13210 * @return return code
13211 */
13212static int
Dave Barach72d72232016-08-04 10:15:08 -040013213api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013214{
Dave Barach72d72232016-08-04 10:15:08 -040013215 unformat_input_t *input = vam->input;
13216 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13217 f64 timeout = ~0;
13218 u8 *locator_set_name = 0;
13219 u8 locator_set_name_set = 0;
13220 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013221
Dave Barach72d72232016-08-04 10:15:08 -040013222 /* Parse args required to build the message */
13223 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013224 {
Dave Barach72d72232016-08-04 10:15:08 -040013225 if (unformat (input, "del"))
13226 {
13227 is_add = 0;
13228 }
13229 else if (unformat (input, "%_%v%_", &locator_set_name))
13230 {
13231 locator_set_name_set = 1;
13232 }
13233 else
13234 {
13235 clib_warning ("parse error '%U'", format_unformat_error, input);
13236 return -99;
13237 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013238 }
13239
Dave Barach72d72232016-08-04 10:15:08 -040013240 if (is_add && !locator_set_name_set)
13241 {
13242 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013243 return -99;
13244 }
13245
Dave Barach72d72232016-08-04 10:15:08 -040013246 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013247 {
Dave Barach72d72232016-08-04 10:15:08 -040013248 errmsg ("itr-rloc locator-set name too long\n");
13249 vec_free (locator_set_name);
13250 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013251 }
13252
Dave Barach72d72232016-08-04 10:15:08 -040013253 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13254 mp->is_add = is_add;
13255 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013256 {
Dave Barach72d72232016-08-04 10:15:08 -040013257 clib_memcpy (mp->locator_set_name, locator_set_name,
13258 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013259 }
Dave Barach72d72232016-08-04 10:15:08 -040013260 else
13261 {
13262 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013263 }
Dave Barach72d72232016-08-04 10:15:08 -040013264 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013265
Dave Barach72d72232016-08-04 10:15:08 -040013266 /* send it... */
13267 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013268
Dave Barach72d72232016-08-04 10:15:08 -040013269 /* Wait for a reply... */
13270 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013271
Dave Barach72d72232016-08-04 10:15:08 -040013272 /* NOTREACHED */
13273 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013274}
13275
13276static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013277api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013278{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013279 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013280 vl_api_lisp_locator_dump_t *mp;
13281 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013282 u8 is_index_set = 0, is_name_set = 0;
13283 u8 *ls_name = 0;
13284 u32 ls_index = ~0;
13285
13286 /* Parse args required to build the message */
13287 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13288 {
13289 if (unformat (input, "ls_name %_%v%_", &ls_name))
13290 {
13291 is_name_set = 1;
13292 }
13293 else if (unformat (input, "ls_index %d", &ls_index))
13294 {
13295 is_index_set = 1;
13296 }
13297 else
13298 {
13299 errmsg ("parse error '%U'", format_unformat_error, input);
13300 return -99;
13301 }
13302 }
13303
13304 if (!is_index_set && !is_name_set)
13305 {
13306 errmsg ("error: expected one of index or name!\n");
13307 return -99;
13308 }
13309
13310 if (is_index_set && is_name_set)
13311 {
13312 errmsg ("error: only one param expected!\n");
13313 return -99;
13314 }
13315
Florin Coras042d2122016-09-21 16:38:19 +020013316 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013317 {
13318 errmsg ("error: locator set name too long!");
13319 return -99;
13320 }
13321
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013322 if (!vam->json_output)
13323 {
13324 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13325 "weight");
13326 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013327
Dave Barach72d72232016-08-04 10:15:08 -040013328 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013329 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013330
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013331 if (is_index_set)
13332 mp->ls_index = clib_host_to_net_u32 (ls_index);
13333 else
13334 {
13335 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013336 strncpy ((char *) mp->ls_name, (char *) ls_name,
13337 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013338 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013339
Dave Barach72d72232016-08-04 10:15:08 -040013340 /* send it... */
13341 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013342
Dave Barach72d72232016-08-04 10:15:08 -040013343 /* Use a control ping for synchronization */
13344 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013345 vl_api_control_ping_t *mp;
13346 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013347 S;
13348 }
13349 /* Wait for a reply... */
13350 W;
Dave Barach72d72232016-08-04 10:15:08 -040013351
13352 /* NOTREACHED */
13353 return 0;
13354}
13355
13356static int
13357api_lisp_locator_set_dump (vat_main_t * vam)
13358{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013359 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013360 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013361 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013362 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013363
13364 /* Parse args required to build the message */
13365 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13366 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013367 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013368 {
13369 filter = 1;
13370 }
13371 else if (unformat (input, "remote"))
13372 {
13373 filter = 2;
13374 }
13375 else
13376 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013377 errmsg ("parse error '%U'", format_unformat_error, input);
13378 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013379 }
13380 }
13381
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013382 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013383 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013384 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013385 }
13386
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013387 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013388
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013389 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013390
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013391 /* send it... */
13392 S;
13393
13394 /* Use a control ping for synchronization */
13395 {
13396 vl_api_control_ping_t *mp;
13397 M (CONTROL_PING, control_ping);
13398 S;
13399 }
13400 /* Wait for a reply... */
13401 W;
13402
13403 /* NOTREACHED */
13404 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013405}
13406
13407static int
13408api_lisp_eid_table_map_dump (vat_main_t * vam)
13409{
Filip Tehlarc0681792016-08-24 14:11:07 +020013410 u8 is_l2 = 0;
13411 u8 mode_set = 0;
13412 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013413 vl_api_lisp_eid_table_map_dump_t *mp;
13414 f64 timeout = ~0;
13415
Filip Tehlarc0681792016-08-24 14:11:07 +020013416 /* Parse args required to build the message */
13417 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13418 {
13419 if (unformat (input, "l2"))
13420 {
13421 is_l2 = 1;
13422 mode_set = 1;
13423 }
13424 else if (unformat (input, "l3"))
13425 {
13426 is_l2 = 0;
13427 mode_set = 1;
13428 }
13429 else
13430 {
13431 errmsg ("parse error '%U'", format_unformat_error, input);
13432 return -99;
13433 }
13434 }
13435
13436 if (!mode_set)
13437 {
13438 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13439 return -99;
13440 }
13441
Dave Barach72d72232016-08-04 10:15:08 -040013442 if (!vam->json_output)
13443 {
Filip Tehlarc0681792016-08-24 14:11:07 +020013444 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040013445 }
13446
13447 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020013448 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040013449
13450 /* send it... */
13451 S;
13452
13453 /* Use a control ping for synchronization */
13454 {
13455 vl_api_control_ping_t *mp;
13456 M (CONTROL_PING, control_ping);
13457 S;
13458 }
13459 /* Wait for a reply... */
13460 W;
13461
13462 /* NOTREACHED */
13463 return 0;
13464}
13465
13466static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020013467api_lisp_eid_table_vni_dump (vat_main_t * vam)
13468{
13469 vl_api_lisp_eid_table_vni_dump_t *mp;
13470 f64 timeout = ~0;
13471
13472 if (!vam->json_output)
13473 {
13474 fformat (vam->ofp, "VNI\n");
13475 }
13476
13477 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
13478
13479 /* send it... */
13480 S;
13481
13482 /* Use a control ping for synchronization */
13483 {
13484 vl_api_control_ping_t *mp;
13485 M (CONTROL_PING, control_ping);
13486 S;
13487 }
13488 /* Wait for a reply... */
13489 W;
13490
13491 /* NOTREACHED */
13492 return 0;
13493}
13494
13495static int
Dave Barach72d72232016-08-04 10:15:08 -040013496api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013497{
Dave Barach72d72232016-08-04 10:15:08 -040013498 unformat_input_t *i = vam->input;
13499 vl_api_lisp_eid_table_dump_t *mp;
13500 f64 timeout = ~0;
13501 struct in_addr ip4;
13502 struct in6_addr ip6;
13503 u8 mac[6];
13504 u8 eid_type = ~0, eid_set = 0;
13505 u32 prefix_length = ~0, t, vni = 0;
13506 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013507
Dave Barach72d72232016-08-04 10:15:08 -040013508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013509 {
Dave Barach72d72232016-08-04 10:15:08 -040013510 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
13511 {
13512 eid_set = 1;
13513 eid_type = 0;
13514 prefix_length = t;
13515 }
13516 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
13517 {
13518 eid_set = 1;
13519 eid_type = 1;
13520 prefix_length = t;
13521 }
13522 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
13523 {
13524 eid_set = 1;
13525 eid_type = 2;
13526 }
13527 else if (unformat (i, "vni %d", &t))
13528 {
13529 vni = t;
13530 }
13531 else if (unformat (i, "local"))
13532 {
13533 filter = 1;
13534 }
13535 else if (unformat (i, "remote"))
13536 {
13537 filter = 2;
13538 }
13539 else
13540 {
13541 errmsg ("parse error '%U'", format_unformat_error, i);
13542 return -99;
13543 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013544 }
13545
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013546 if (!vam->json_output)
13547 {
13548 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
13549 "ls_index", "ttl", "authoritative");
13550 }
13551
Dave Barach72d72232016-08-04 10:15:08 -040013552 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013553
Dave Barach72d72232016-08-04 10:15:08 -040013554 mp->filter = filter;
13555 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013556 {
Dave Barach72d72232016-08-04 10:15:08 -040013557 mp->eid_set = 1;
13558 mp->vni = htonl (vni);
13559 mp->eid_type = eid_type;
13560 switch (eid_type)
13561 {
13562 case 0:
13563 mp->prefix_length = prefix_length;
13564 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
13565 break;
13566 case 1:
13567 mp->prefix_length = prefix_length;
13568 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
13569 break;
13570 case 2:
13571 clib_memcpy (mp->eid, mac, sizeof (mac));
13572 break;
13573 default:
13574 errmsg ("unknown EID type %d!", eid_type);
13575 return -99;
13576 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013577 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013578
Dave Barach72d72232016-08-04 10:15:08 -040013579 /* send it... */
13580 S;
13581
13582 /* Use a control ping for synchronization */
13583 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013584 vl_api_control_ping_t *mp;
13585 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013586 S;
13587 }
13588
13589 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013590 W;
Dave Barach72d72232016-08-04 10:15:08 -040013591
13592 /* NOTREACHED */
13593 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013594}
13595
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013596static int
Dave Barach72d72232016-08-04 10:15:08 -040013597api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013598{
Dave Barach72d72232016-08-04 10:15:08 -040013599 vl_api_lisp_gpe_tunnel_dump_t *mp;
13600 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013601
Dave Barach72d72232016-08-04 10:15:08 -040013602 if (!vam->json_output)
13603 {
13604 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
13605 "%=16s%=16s%=16s%=16s%=16s\n",
13606 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
13607 "Decap next", "Lisp version", "Flags", "Next protocol",
13608 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013609 }
13610
Dave Barach72d72232016-08-04 10:15:08 -040013611 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
13612 /* send it... */
13613 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013614
Dave Barach72d72232016-08-04 10:15:08 -040013615 /* Use a control ping for synchronization */
13616 {
13617 vl_api_control_ping_t *mp;
13618 M (CONTROL_PING, control_ping);
13619 S;
13620 }
13621 /* Wait for a reply... */
13622 W;
13623
13624 /* NOTREACHED */
13625 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020013626}
13627
Matus Fabian8a95a482016-05-06 15:14:13 +020013628static int
Dave Barach72d72232016-08-04 10:15:08 -040013629api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013630{
Dave Barach72d72232016-08-04 10:15:08 -040013631 vl_api_lisp_map_resolver_dump_t *mp;
13632 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013633
Dave Barach72d72232016-08-04 10:15:08 -040013634 if (!vam->json_output)
13635 {
13636 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013637 }
13638
Dave Barach72d72232016-08-04 10:15:08 -040013639 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
13640 /* send it... */
13641 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013642
Dave Barach72d72232016-08-04 10:15:08 -040013643 /* Use a control ping for synchronization */
13644 {
13645 vl_api_control_ping_t *mp;
13646 M (CONTROL_PING, control_ping);
13647 S;
13648 }
13649 /* Wait for a reply... */
13650 W;
13651
13652 /* NOTREACHED */
13653 return 0;
13654}
13655
13656static int
13657api_show_lisp_status (vat_main_t * vam)
13658{
13659 vl_api_show_lisp_status_t *mp;
13660 f64 timeout = ~0;
13661
13662 if (!vam->json_output)
13663 {
13664 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
13665 }
13666
13667 M (SHOW_LISP_STATUS, show_lisp_status);
13668 /* send it... */
13669 S;
13670 /* Wait for a reply... */
13671 W;
13672
13673 /* NOTREACHED */
13674 return 0;
13675}
13676
13677static int
13678api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
13679{
13680 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
13681 f64 timeout = ~0;
13682
13683 if (!vam->json_output)
13684 {
13685 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
13686 }
13687
13688 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
13689 /* send it... */
13690 S;
13691 /* Wait for a reply... */
13692 W;
13693
13694 /* NOTREACHED */
13695 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013696}
13697
13698static int
Matus Fabian8a95a482016-05-06 15:14:13 +020013699api_af_packet_create (vat_main_t * vam)
13700{
Dave Barach72d72232016-08-04 10:15:08 -040013701 unformat_input_t *i = vam->input;
13702 vl_api_af_packet_create_t *mp;
13703 f64 timeout;
13704 u8 *host_if_name = 0;
13705 u8 hw_addr[6];
13706 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020013707
Dave Barach72d72232016-08-04 10:15:08 -040013708 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020013709
Dave Barach72d72232016-08-04 10:15:08 -040013710 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13711 {
13712 if (unformat (i, "name %s", &host_if_name))
13713 vec_add1 (host_if_name, 0);
13714 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
13715 random_hw_addr = 0;
13716 else
13717 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013718 }
13719
Dave Barach72d72232016-08-04 10:15:08 -040013720 if (!vec_len (host_if_name))
13721 {
13722 errmsg ("host-interface name must be specified");
13723 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013724 }
13725
Dave Barach72d72232016-08-04 10:15:08 -040013726 if (vec_len (host_if_name) > 64)
13727 {
13728 errmsg ("host-interface name too long");
13729 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013730 }
13731
Dave Barach72d72232016-08-04 10:15:08 -040013732 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020013733
Dave Barach72d72232016-08-04 10:15:08 -040013734 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13735 clib_memcpy (mp->hw_addr, hw_addr, 6);
13736 mp->use_random_hw_addr = random_hw_addr;
13737 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013738
Dave Barach72d72232016-08-04 10:15:08 -040013739 S;
13740 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
13741 /* NOTREACHED */
13742 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013743}
13744
13745static int
13746api_af_packet_delete (vat_main_t * vam)
13747{
Dave Barach72d72232016-08-04 10:15:08 -040013748 unformat_input_t *i = vam->input;
13749 vl_api_af_packet_delete_t *mp;
13750 f64 timeout;
13751 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013752
Dave Barach72d72232016-08-04 10:15:08 -040013753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13754 {
13755 if (unformat (i, "name %s", &host_if_name))
13756 vec_add1 (host_if_name, 0);
13757 else
13758 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020013759 }
13760
Dave Barach72d72232016-08-04 10:15:08 -040013761 if (!vec_len (host_if_name))
13762 {
13763 errmsg ("host-interface name must be specified");
13764 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013765 }
13766
Dave Barach72d72232016-08-04 10:15:08 -040013767 if (vec_len (host_if_name) > 64)
13768 {
13769 errmsg ("host-interface name too long");
13770 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020013771 }
13772
Dave Barach72d72232016-08-04 10:15:08 -040013773 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020013774
Dave Barach72d72232016-08-04 10:15:08 -040013775 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
13776 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020013777
Dave Barach72d72232016-08-04 10:15:08 -040013778 S;
13779 W;
13780 /* NOTREACHED */
13781 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020013782}
13783
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013784static int
13785api_policer_add_del (vat_main_t * vam)
13786{
Dave Barach72d72232016-08-04 10:15:08 -040013787 unformat_input_t *i = vam->input;
13788 vl_api_policer_add_del_t *mp;
13789 f64 timeout;
13790 u8 is_add = 1;
13791 u8 *name = 0;
13792 u32 cir = 0;
13793 u32 eir = 0;
13794 u64 cb = 0;
13795 u64 eb = 0;
13796 u8 rate_type = 0;
13797 u8 round_type = 0;
13798 u8 type = 0;
13799 u8 color_aware = 0;
13800 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013801
Dave Barach839fe3e2016-08-10 11:35:54 -040013802 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
13803 conform_action.dscp = 0;
13804 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
13805 exceed_action.dscp = 0;
13806 violate_action.action_type = SSE2_QOS_ACTION_DROP;
13807 violate_action.dscp = 0;
13808
Dave Barach72d72232016-08-04 10:15:08 -040013809 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13810 {
13811 if (unformat (i, "del"))
13812 is_add = 0;
13813 else if (unformat (i, "name %s", &name))
13814 vec_add1 (name, 0);
13815 else if (unformat (i, "cir %u", &cir))
13816 ;
13817 else if (unformat (i, "eir %u", &eir))
13818 ;
13819 else if (unformat (i, "cb %u", &cb))
13820 ;
13821 else if (unformat (i, "eb %u", &eb))
13822 ;
13823 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
13824 &rate_type))
13825 ;
13826 else if (unformat (i, "round_type %U", unformat_policer_round_type,
13827 &round_type))
13828 ;
13829 else if (unformat (i, "type %U", unformat_policer_type, &type))
13830 ;
13831 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
13832 &conform_action))
13833 ;
13834 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
13835 &exceed_action))
13836 ;
13837 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
13838 &violate_action))
13839 ;
13840 else if (unformat (i, "color-aware"))
13841 color_aware = 1;
13842 else
13843 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013844 }
13845
Dave Barach72d72232016-08-04 10:15:08 -040013846 if (!vec_len (name))
13847 {
13848 errmsg ("policer name must be specified");
13849 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013850 }
13851
Dave Barach72d72232016-08-04 10:15:08 -040013852 if (vec_len (name) > 64)
13853 {
13854 errmsg ("policer name too long");
13855 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013856 }
13857
Dave Barach72d72232016-08-04 10:15:08 -040013858 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013859
Dave Barach72d72232016-08-04 10:15:08 -040013860 clib_memcpy (mp->name, name, vec_len (name));
13861 vec_free (name);
13862 mp->is_add = is_add;
13863 mp->cir = cir;
13864 mp->eir = eir;
13865 mp->cb = cb;
13866 mp->eb = eb;
13867 mp->rate_type = rate_type;
13868 mp->round_type = round_type;
13869 mp->type = type;
13870 mp->conform_action_type = conform_action.action_type;
13871 mp->conform_dscp = conform_action.dscp;
13872 mp->exceed_action_type = exceed_action.action_type;
13873 mp->exceed_dscp = exceed_action.dscp;
13874 mp->violate_action_type = violate_action.action_type;
13875 mp->violate_dscp = violate_action.dscp;
13876 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013877
Dave Barach72d72232016-08-04 10:15:08 -040013878 S;
13879 W;
13880 /* NOTREACHED */
13881 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070013882}
13883
Matus Fabian82e29c42016-05-11 04:49:46 -070013884static int
Dave Barach72d72232016-08-04 10:15:08 -040013885api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070013886{
Dave Barach72d72232016-08-04 10:15:08 -040013887 unformat_input_t *i = vam->input;
13888 vl_api_policer_dump_t *mp;
13889 f64 timeout = ~0;
13890 u8 *match_name = 0;
13891 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013892
Dave Barach72d72232016-08-04 10:15:08 -040013893 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070013894 {
Dave Barach72d72232016-08-04 10:15:08 -040013895 if (unformat (i, "name %s", &match_name))
13896 {
13897 vec_add1 (match_name, 0);
13898 match_name_valid = 1;
13899 }
13900 else
13901 break;
Matus Fabiane8554802016-05-18 23:40:37 -070013902 }
Matus Fabiane8554802016-05-18 23:40:37 -070013903
Dave Barach72d72232016-08-04 10:15:08 -040013904 M (POLICER_DUMP, policer_dump);
13905 mp->match_name_valid = match_name_valid;
13906 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
13907 vec_free (match_name);
13908 /* send it... */
13909 S;
13910
13911 /* Use a control ping for synchronization */
13912 {
13913 vl_api_control_ping_t *mp;
13914 M (CONTROL_PING, control_ping);
13915 S;
13916 }
13917 /* Wait for a reply... */
13918 W;
13919
13920 /* NOTREACHED */
13921 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070013922}
13923
13924static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013925api_policer_classify_set_interface (vat_main_t * vam)
13926{
Dave Barach72d72232016-08-04 10:15:08 -040013927 unformat_input_t *i = vam->input;
13928 vl_api_policer_classify_set_interface_t *mp;
13929 f64 timeout;
13930 u32 sw_if_index;
13931 int sw_if_index_set;
13932 u32 ip4_table_index = ~0;
13933 u32 ip6_table_index = ~0;
13934 u32 l2_table_index = ~0;
13935 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013936
Dave Barach72d72232016-08-04 10:15:08 -040013937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13938 {
13939 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
13940 sw_if_index_set = 1;
13941 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13942 sw_if_index_set = 1;
13943 else if (unformat (i, "del"))
13944 is_add = 0;
13945 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13946 ;
13947 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13948 ;
13949 else if (unformat (i, "l2-table %d", &l2_table_index))
13950 ;
13951 else
13952 {
13953 clib_warning ("parse error '%U'", format_unformat_error, i);
13954 return -99;
13955 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013956 }
13957
Dave Barach72d72232016-08-04 10:15:08 -040013958 if (sw_if_index_set == 0)
13959 {
13960 errmsg ("missing interface name or sw_if_index\n");
13961 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013962 }
13963
Dave Barach72d72232016-08-04 10:15:08 -040013964 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013965
Dave Barach72d72232016-08-04 10:15:08 -040013966 mp->sw_if_index = ntohl (sw_if_index);
13967 mp->ip4_table_index = ntohl (ip4_table_index);
13968 mp->ip6_table_index = ntohl (ip6_table_index);
13969 mp->l2_table_index = ntohl (l2_table_index);
13970 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013971
Dave Barach72d72232016-08-04 10:15:08 -040013972 S;
13973 W;
13974 /* NOTREACHED */
13975 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013976}
13977
13978static int
Dave Barach72d72232016-08-04 10:15:08 -040013979api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013980{
Dave Barach72d72232016-08-04 10:15:08 -040013981 unformat_input_t *i = vam->input;
13982 vl_api_policer_classify_dump_t *mp;
13983 f64 timeout = ~0;
13984 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013985
Dave Barach72d72232016-08-04 10:15:08 -040013986 if (unformat (i, "type %U", unformat_classify_table_type, &type))
13987 ;
13988 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013989 {
Dave Barach72d72232016-08-04 10:15:08 -040013990 errmsg ("classify table type must be specified\n");
13991 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013992 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070013993
Dave Barach72d72232016-08-04 10:15:08 -040013994 if (!vam->json_output)
13995 {
13996 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
13997 }
13998
13999 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14000 mp->type = type;
14001 /* send it... */
14002 S;
14003
14004 /* Use a control ping for synchronization */
14005 {
14006 vl_api_control_ping_t *mp;
14007 M (CONTROL_PING, control_ping);
14008 S;
14009 }
14010 /* Wait for a reply... */
14011 W;
14012
14013 /* NOTREACHED */
14014 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014015}
14016
14017static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014018api_netmap_create (vat_main_t * vam)
14019{
Dave Barach72d72232016-08-04 10:15:08 -040014020 unformat_input_t *i = vam->input;
14021 vl_api_netmap_create_t *mp;
14022 f64 timeout;
14023 u8 *if_name = 0;
14024 u8 hw_addr[6];
14025 u8 random_hw_addr = 1;
14026 u8 is_pipe = 0;
14027 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014028
Dave Barach72d72232016-08-04 10:15:08 -040014029 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014030
Dave Barach72d72232016-08-04 10:15:08 -040014031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14032 {
14033 if (unformat (i, "name %s", &if_name))
14034 vec_add1 (if_name, 0);
14035 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14036 random_hw_addr = 0;
14037 else if (unformat (i, "pipe"))
14038 is_pipe = 1;
14039 else if (unformat (i, "master"))
14040 is_master = 1;
14041 else if (unformat (i, "slave"))
14042 is_master = 0;
14043 else
14044 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014045 }
14046
Dave Barach72d72232016-08-04 10:15:08 -040014047 if (!vec_len (if_name))
14048 {
14049 errmsg ("interface name must be specified");
14050 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014051 }
14052
Dave Barach72d72232016-08-04 10:15:08 -040014053 if (vec_len (if_name) > 64)
14054 {
14055 errmsg ("interface name too long");
14056 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014057 }
14058
Dave Barach72d72232016-08-04 10:15:08 -040014059 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014060
Dave Barach72d72232016-08-04 10:15:08 -040014061 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14062 clib_memcpy (mp->hw_addr, hw_addr, 6);
14063 mp->use_random_hw_addr = random_hw_addr;
14064 mp->is_pipe = is_pipe;
14065 mp->is_master = is_master;
14066 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014067
Dave Barach72d72232016-08-04 10:15:08 -040014068 S;
14069 W;
14070 /* NOTREACHED */
14071 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014072}
14073
14074static int
14075api_netmap_delete (vat_main_t * vam)
14076{
Dave Barach72d72232016-08-04 10:15:08 -040014077 unformat_input_t *i = vam->input;
14078 vl_api_netmap_delete_t *mp;
14079 f64 timeout;
14080 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014081
Dave Barach72d72232016-08-04 10:15:08 -040014082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14083 {
14084 if (unformat (i, "name %s", &if_name))
14085 vec_add1 (if_name, 0);
14086 else
14087 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014088 }
14089
Dave Barach72d72232016-08-04 10:15:08 -040014090 if (!vec_len (if_name))
14091 {
14092 errmsg ("interface name must be specified");
14093 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014094 }
14095
Dave Barach72d72232016-08-04 10:15:08 -040014096 if (vec_len (if_name) > 64)
14097 {
14098 errmsg ("interface name too long");
14099 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014100 }
14101
Dave Barach72d72232016-08-04 10:15:08 -040014102 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014103
Dave Barach72d72232016-08-04 10:15:08 -040014104 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14105 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014106
Dave Barach72d72232016-08-04 10:15:08 -040014107 S;
14108 W;
14109 /* NOTREACHED */
14110 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014111}
14112
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014113static void vl_api_mpls_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014114 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014115{
Dave Barach72d72232016-08-04 10:15:08 -040014116 vat_main_t *vam = &vat_main;
14117 i32 i;
14118 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014119
Dave Barach72d72232016-08-04 10:15:08 -040014120 if (mp->l2_only == 0)
14121 {
14122 fformat (vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
14123 ntohl (mp->tunnel_index),
14124 format_ip4_address, &mp->tunnel_src,
14125 format_ip4_address, &mp->tunnel_dst,
14126 format_ip4_address, &mp->intfc_address,
14127 ntohl (mp->mask_width));
14128 for (i = 0; i < len; i++)
14129 {
14130 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14131 }
14132 fformat (vam->ofp, "\n");
14133 fformat (vam->ofp, " inner fib index %d, outer fib index %d\n",
14134 ntohl (mp->inner_fib_index), ntohl (mp->outer_fib_index));
14135 }
14136 else
14137 {
14138 fformat (vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
14139 ntohl (mp->tunnel_index),
14140 format_ip4_address, &mp->tunnel_src,
14141 format_ip4_address, &mp->tunnel_dst,
14142 format_ip4_address, &mp->intfc_address);
14143 for (i = 0; i < len; i++)
14144 {
14145 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
14146 }
14147 fformat (vam->ofp, "\n");
14148 fformat (vam->ofp, " l2 interface %d, outer fib index %d\n",
14149 ntohl (mp->hw_if_index), ntohl (mp->outer_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014150 }
14151}
14152
14153static void vl_api_mpls_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014154 (vl_api_mpls_gre_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014155{
Dave Barach72d72232016-08-04 10:15:08 -040014156 vat_main_t *vam = &vat_main;
14157 vat_json_node_t *node = NULL;
14158 struct in_addr ip4;
14159 i32 i;
14160 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014161
Dave Barach72d72232016-08-04 10:15:08 -040014162 if (VAT_JSON_ARRAY != vam->json_tree.type)
14163 {
14164 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14165 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014166 }
Dave Barach72d72232016-08-04 10:15:08 -040014167 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014168
Dave Barach72d72232016-08-04 10:15:08 -040014169 vat_json_init_object (node);
14170 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14171 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14172 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14173 vat_json_object_add_uint (node, "inner_fib_index",
14174 ntohl (mp->inner_fib_index));
14175 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14176 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14177 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14178 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14179 clib_memcpy (&ip4, &(mp->tunnel_src), sizeof (ip4));
14180 vat_json_object_add_ip4 (node, "tunnel_src", ip4);
14181 clib_memcpy (&ip4, &(mp->tunnel_dst), sizeof (ip4));
14182 vat_json_object_add_ip4 (node, "tunnel_dst", ip4);
14183 vat_json_object_add_uint (node, "outer_fib_index",
14184 ntohl (mp->outer_fib_index));
14185 vat_json_object_add_uint (node, "label_count", len);
14186 for (i = 0; i < len; i++)
14187 {
14188 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014189 }
14190}
14191
Dave Barach72d72232016-08-04 10:15:08 -040014192static int
14193api_mpls_gre_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014194{
Dave Barach72d72232016-08-04 10:15:08 -040014195 vl_api_mpls_gre_tunnel_dump_t *mp;
14196 f64 timeout;
14197 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014198
Dave Barach72d72232016-08-04 10:15:08 -040014199 /* Parse args required to build the message */
14200 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014201 {
Dave Barach72d72232016-08-04 10:15:08 -040014202 if (!unformat (vam->input, "tunnel_index %d", &index))
14203 {
14204 index = -1;
14205 break;
14206 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014207 }
Dave Barach72d72232016-08-04 10:15:08 -040014208
14209 fformat (vam->ofp, " tunnel_index %d\n", index);
14210
14211 M (MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
14212 mp->tunnel_index = htonl (index);
14213 S;
14214
14215 /* Use a control ping for synchronization */
14216 {
14217 vl_api_control_ping_t *mp;
14218 M (CONTROL_PING, control_ping);
14219 S;
14220 }
14221 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014222}
14223
14224static void vl_api_mpls_eth_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014225 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014226{
Dave Barach72d72232016-08-04 10:15:08 -040014227 vat_main_t *vam = &vat_main;
14228 i32 i;
14229 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014230
Dave Barach72d72232016-08-04 10:15:08 -040014231 fformat (vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
14232 ntohl (mp->tunnel_index),
14233 format_ethernet_address, &mp->tunnel_dst_mac,
14234 format_ip4_address, &mp->intfc_address, ntohl (mp->mask_width));
14235 for (i = 0; i < len; i++)
14236 {
14237 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014238 }
Dave Barach72d72232016-08-04 10:15:08 -040014239 fformat (vam->ofp, "\n");
14240 fformat (vam->ofp, " tx on %d, rx fib index %d\n",
14241 ntohl (mp->tx_sw_if_index), ntohl (mp->inner_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014242}
14243
14244static void vl_api_mpls_eth_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014245 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014246{
Dave Barach72d72232016-08-04 10:15:08 -040014247 vat_main_t *vam = &vat_main;
14248 vat_json_node_t *node = NULL;
14249 struct in_addr ip4;
14250 i32 i;
14251 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014252
Dave Barach72d72232016-08-04 10:15:08 -040014253 if (VAT_JSON_ARRAY != vam->json_tree.type)
14254 {
14255 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14256 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014257 }
Dave Barach72d72232016-08-04 10:15:08 -040014258 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014259
Dave Barach72d72232016-08-04 10:15:08 -040014260 vat_json_init_object (node);
14261 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14262 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14263 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14264 vat_json_object_add_uint (node, "inner_fib_index",
14265 ntohl (mp->inner_fib_index));
14266 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14267 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14268 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14269 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14270 vat_json_object_add_string_copy (node, "tunnel_dst_mac",
14271 format (0, "%U", format_ethernet_address,
14272 &mp->tunnel_dst_mac));
14273 vat_json_object_add_uint (node, "tx_sw_if_index",
14274 ntohl (mp->tx_sw_if_index));
14275 vat_json_object_add_uint (node, "label_count", len);
14276 for (i = 0; i < len; i++)
14277 {
14278 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014279 }
14280}
14281
Dave Barach72d72232016-08-04 10:15:08 -040014282static int
14283api_mpls_eth_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014284{
Dave Barach72d72232016-08-04 10:15:08 -040014285 vl_api_mpls_eth_tunnel_dump_t *mp;
14286 f64 timeout;
14287 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014288
Dave Barach72d72232016-08-04 10:15:08 -040014289 /* Parse args required to build the message */
14290 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014291 {
Dave Barach72d72232016-08-04 10:15:08 -040014292 if (!unformat (vam->input, "tunnel_index %d", &index))
14293 {
14294 index = -1;
14295 break;
14296 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014297 }
Dave Barach72d72232016-08-04 10:15:08 -040014298
14299 fformat (vam->ofp, " tunnel_index %d\n", index);
14300
14301 M (MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
14302 mp->tunnel_index = htonl (index);
14303 S;
14304
14305 /* Use a control ping for synchronization */
14306 {
14307 vl_api_control_ping_t *mp;
14308 M (CONTROL_PING, control_ping);
14309 S;
14310 }
14311 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014312}
14313
14314static void vl_api_mpls_fib_encap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014315 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014316{
Dave Barach72d72232016-08-04 10:15:08 -040014317 vat_main_t *vam = &vat_main;
14318 i32 i;
14319 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014320
Dave Barach72d72232016-08-04 10:15:08 -040014321 fformat (vam->ofp, "table %d, dest %U, label ",
14322 ntohl (mp->fib_index), format_ip4_address, &mp->dest, len);
14323 for (i = 0; i < len; i++)
14324 {
14325 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014326 }
Dave Barach72d72232016-08-04 10:15:08 -040014327 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014328}
14329
14330static void vl_api_mpls_fib_encap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014331 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014332{
Dave Barach72d72232016-08-04 10:15:08 -040014333 vat_main_t *vam = &vat_main;
14334 vat_json_node_t *node = NULL;
14335 i32 i;
14336 i32 len = ntohl (mp->nlabels);
14337 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014338
Dave Barach72d72232016-08-04 10:15:08 -040014339 if (VAT_JSON_ARRAY != vam->json_tree.type)
14340 {
14341 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14342 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014343 }
Dave Barach72d72232016-08-04 10:15:08 -040014344 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014345
Dave Barach72d72232016-08-04 10:15:08 -040014346 vat_json_init_object (node);
14347 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14348 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14349 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14350 vat_json_object_add_ip4 (node, "dest", ip4);
14351 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14352 vat_json_object_add_uint (node, "label_count", len);
14353 for (i = 0; i < len; i++)
14354 {
14355 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014356 }
14357}
14358
Dave Barach72d72232016-08-04 10:15:08 -040014359static int
14360api_mpls_fib_encap_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014361{
Dave Barach72d72232016-08-04 10:15:08 -040014362 vl_api_mpls_fib_encap_dump_t *mp;
14363 f64 timeout;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014364
Dave Barach72d72232016-08-04 10:15:08 -040014365 M (MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
14366 S;
14367
14368 /* Use a control ping for synchronization */
14369 {
14370 vl_api_control_ping_t *mp;
14371 M (CONTROL_PING, control_ping);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014372 S;
Dave Barach72d72232016-08-04 10:15:08 -040014373 }
14374 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014375}
14376
14377static void vl_api_mpls_fib_decap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014378 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014379{
Dave Barach72d72232016-08-04 10:15:08 -040014380 vat_main_t *vam = &vat_main;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014381
Dave Barach72d72232016-08-04 10:15:08 -040014382 fformat (vam->ofp,
14383 "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
14384 ntohl (mp->rx_table_id), ntohl (mp->tx_table_id), mp->swif_tag,
14385 ntohl (mp->label), ntohl (mp->s_bit));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014386}
14387
14388static void vl_api_mpls_fib_decap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014389 (vl_api_mpls_fib_decap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014390{
Dave Barach72d72232016-08-04 10:15:08 -040014391 vat_main_t *vam = &vat_main;
14392 vat_json_node_t *node = NULL;
14393 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014394
Dave Barach72d72232016-08-04 10:15:08 -040014395 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014396 {
Dave Barach72d72232016-08-04 10:15:08 -040014397 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14398 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014399 }
Dave Barach72d72232016-08-04 10:15:08 -040014400 node = vat_json_array_add (&vam->json_tree);
14401
14402 vat_json_init_object (node);
14403 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14404 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14405 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14406 vat_json_object_add_ip4 (node, "dest", ip4);
14407 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14408 vat_json_object_add_uint (node, "label", ntohl (mp->label));
14409 vat_json_object_add_uint (node, "rx_table_id", ntohl (mp->rx_table_id));
14410 vat_json_object_add_uint (node, "tx_table_id", ntohl (mp->tx_table_id));
14411 vat_json_object_add_string_copy (node, "swif_tag", mp->swif_tag);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014412}
14413
Dave Barach72d72232016-08-04 10:15:08 -040014414static int
14415api_mpls_fib_decap_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014416{
Dave Barach72d72232016-08-04 10:15:08 -040014417 vl_api_mpls_fib_decap_dump_t *mp;
14418 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014419
Dave Barach72d72232016-08-04 10:15:08 -040014420 M (MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
14421 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014422
Dave Barach72d72232016-08-04 10:15:08 -040014423 /* Use a control ping for synchronization */
14424 {
14425 vl_api_control_ping_t *mp;
14426 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014427 S;
Dave Barach72d72232016-08-04 10:15:08 -040014428 }
14429 W;
14430}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014431
Dave Barach72d72232016-08-04 10:15:08 -040014432int
14433api_classify_table_ids (vat_main_t * vam)
14434{
14435 vl_api_classify_table_ids_t *mp;
14436 f64 timeout;
14437
14438 /* Construct the API message */
14439 M (CLASSIFY_TABLE_IDS, classify_table_ids);
14440 mp->context = 0;
14441
14442 S;
14443 W;
14444 /* NOTREACHED */
14445 return 0;
14446}
14447
14448int
14449api_classify_table_by_interface (vat_main_t * vam)
14450{
14451 unformat_input_t *input = vam->input;
14452 vl_api_classify_table_by_interface_t *mp;
14453 f64 timeout;
14454
14455 u32 sw_if_index = ~0;
14456 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014457 {
Dave Barach72d72232016-08-04 10:15:08 -040014458 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
14459 ;
14460 else if (unformat (input, "sw_if_index %d", &sw_if_index))
14461 ;
14462 else
14463 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014464 }
Dave Barach72d72232016-08-04 10:15:08 -040014465 if (sw_if_index == ~0)
14466 {
14467 errmsg ("missing interface name or sw_if_index\n");
14468 return -99;
14469 }
14470
14471 /* Construct the API message */
14472 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
14473 mp->context = 0;
14474 mp->sw_if_index = ntohl (sw_if_index);
14475
14476 S;
14477 W;
14478 /* NOTREACHED */
14479 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014480}
14481
Dave Barach72d72232016-08-04 10:15:08 -040014482int
14483api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014484{
Dave Barach72d72232016-08-04 10:15:08 -040014485 unformat_input_t *input = vam->input;
14486 vl_api_classify_table_info_t *mp;
14487 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014488
Dave Barach72d72232016-08-04 10:15:08 -040014489 u32 table_id = ~0;
14490 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14491 {
14492 if (unformat (input, "table_id %d", &table_id))
14493 ;
14494 else
14495 break;
14496 }
14497 if (table_id == ~0)
14498 {
14499 errmsg ("missing table id\n");
14500 return -99;
14501 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014502
Dave Barach72d72232016-08-04 10:15:08 -040014503 /* Construct the API message */
14504 M (CLASSIFY_TABLE_INFO, classify_table_info);
14505 mp->context = 0;
14506 mp->table_id = ntohl (table_id);
14507
14508 S;
14509 W;
14510 /* NOTREACHED */
14511 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014512}
14513
Dave Barach72d72232016-08-04 10:15:08 -040014514int
14515api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014516{
Dave Barach72d72232016-08-04 10:15:08 -040014517 unformat_input_t *input = vam->input;
14518 vl_api_classify_session_dump_t *mp;
14519 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070014520
Dave Barach72d72232016-08-04 10:15:08 -040014521 u32 table_id = ~0;
14522 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14523 {
14524 if (unformat (input, "table_id %d", &table_id))
14525 ;
14526 else
14527 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014528 }
Dave Barach72d72232016-08-04 10:15:08 -040014529 if (table_id == ~0)
14530 {
14531 errmsg ("missing table id\n");
14532 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014533 }
14534
Dave Barach72d72232016-08-04 10:15:08 -040014535 /* Construct the API message */
14536 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
14537 mp->context = 0;
14538 mp->table_id = ntohl (table_id);
14539 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020014540
Dave Barach72d72232016-08-04 10:15:08 -040014541 /* Use a control ping for synchronization */
14542 {
14543 vl_api_control_ping_t *mp;
14544 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040014545 S;
Dave Barach72d72232016-08-04 10:15:08 -040014546 }
14547 W;
14548 /* NOTREACHED */
14549 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040014550}
14551
Dave Barach72d72232016-08-04 10:15:08 -040014552static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014553vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014554{
Dave Barach72d72232016-08-04 10:15:08 -040014555 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014556
Dave Barach72d72232016-08-04 10:15:08 -040014557 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014558 "src_address %U, vrf_id %d, path_mtu %u, "
14559 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040014560 format_ip4_address, mp->collector_address,
14561 ntohs (mp->collector_port),
14562 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014563 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
14564 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014565
14566 vam->retval = 0;
14567 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014568}
14569
Dave Barach72d72232016-08-04 10:15:08 -040014570static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014571 vl_api_ipfix_exporter_details_t_handler_json
14572 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014573{
Dave Barach72d72232016-08-04 10:15:08 -040014574 vat_main_t *vam = &vat_main;
14575 vat_json_node_t node;
14576 struct in_addr collector_address;
14577 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014578
Dave Barach72d72232016-08-04 10:15:08 -040014579 vat_json_init_object (&node);
14580 clib_memcpy (&collector_address, &mp->collector_address,
14581 sizeof (collector_address));
14582 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
14583 vat_json_object_add_uint (&node, "collector_port",
14584 ntohs (mp->collector_port));
14585 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
14586 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014587 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040014588 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
14589 vat_json_object_add_uint (&node, "template_interval",
14590 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014591 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040014592
14593 vat_json_print (vam->ofp, &node);
14594 vat_json_free (&node);
14595 vam->retval = 0;
14596 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050014597}
14598
Dave Barach72d72232016-08-04 10:15:08 -040014599int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014600api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070014601{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014602 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014603 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014604
Dave Barach72d72232016-08-04 10:15:08 -040014605 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014606 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014607 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014608
Dave Barach72d72232016-08-04 10:15:08 -040014609 S;
14610 W;
14611 /* NOTREACHED */
14612 return 0;
14613}
Ed Warnickecb9cada2015-12-08 15:45:58 -070014614
Juraj Slobodaffa652a2016-08-07 23:43:42 -070014615static int
14616api_ipfix_classify_stream_dump (vat_main_t * vam)
14617{
14618 vl_api_ipfix_classify_stream_dump_t *mp;
14619 f64 timeout;
14620
14621 /* Construct the API message */
14622 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
14623 mp->context = 0;
14624
14625 S;
14626 W;
14627 /* NOTREACHED */
14628 return 0;
14629}
14630
14631static void
14632 vl_api_ipfix_classify_stream_details_t_handler
14633 (vl_api_ipfix_classify_stream_details_t * mp)
14634{
14635 vat_main_t *vam = &vat_main;
14636 fformat (vam->ofp, "domain_id %d, src_port %d\n",
14637 ntohl (mp->domain_id), ntohs (mp->src_port));
14638 vam->retval = 0;
14639 vam->result_ready = 1;
14640}
14641
14642static void
14643 vl_api_ipfix_classify_stream_details_t_handler_json
14644 (vl_api_ipfix_classify_stream_details_t * mp)
14645{
14646 vat_main_t *vam = &vat_main;
14647 vat_json_node_t node;
14648
14649 vat_json_init_object (&node);
14650 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
14651 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
14652
14653 vat_json_print (vam->ofp, &node);
14654 vat_json_free (&node);
14655 vam->retval = 0;
14656 vam->result_ready = 1;
14657}
14658
14659static int
14660api_ipfix_classify_table_dump (vat_main_t * vam)
14661{
14662 vl_api_ipfix_classify_table_dump_t *mp;
14663 f64 timeout;
14664
14665 if (!vam->json_output)
14666 {
14667 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
14668 "transport_protocol");
14669 }
14670
14671 /* Construct the API message */
14672 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
14673
14674 /* send it... */
14675 S;
14676
14677 /* Use a control ping for synchronization */
14678 {
14679 vl_api_control_ping_t *mp;
14680 M (CONTROL_PING, control_ping);
14681 S;
14682 }
14683 W;
14684}
14685
14686static void
14687 vl_api_ipfix_classify_table_details_t_handler
14688 (vl_api_ipfix_classify_table_details_t * mp)
14689{
14690 vat_main_t *vam = &vat_main;
14691 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
14692 mp->transport_protocol);
14693}
14694
14695static void
14696 vl_api_ipfix_classify_table_details_t_handler_json
14697 (vl_api_ipfix_classify_table_details_t * mp)
14698{
14699 vat_json_node_t *node = NULL;
14700 vat_main_t *vam = &vat_main;
14701
14702 if (VAT_JSON_ARRAY != vam->json_tree.type)
14703 {
14704 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14705 vat_json_init_array (&vam->json_tree);
14706 }
14707
14708 node = vat_json_array_add (&vam->json_tree);
14709 vat_json_init_object (node);
14710
14711 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
14712 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
14713 vat_json_object_add_uint (node, "transport_protocol",
14714 mp->transport_protocol);
14715}
14716
Dave Barach72d72232016-08-04 10:15:08 -040014717int
14718api_pg_create_interface (vat_main_t * vam)
14719{
14720 unformat_input_t *input = vam->input;
14721 vl_api_pg_create_interface_t *mp;
14722 f64 timeout;
14723
14724 u32 if_id = ~0;
14725 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14726 {
14727 if (unformat (input, "if_id %d", &if_id))
14728 ;
14729 else
14730 break;
14731 }
14732 if (if_id == ~0)
14733 {
14734 errmsg ("missing pg interface index\n");
14735 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070014736 }
14737
Dave Barach72d72232016-08-04 10:15:08 -040014738 /* Construct the API message */
14739 M (PG_CREATE_INTERFACE, pg_create_interface);
14740 mp->context = 0;
14741 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070014742
Dave Barach72d72232016-08-04 10:15:08 -040014743 S;
14744 W;
14745 /* NOTREACHED */
14746 return 0;
14747}
14748
14749int
14750api_pg_capture (vat_main_t * vam)
14751{
14752 unformat_input_t *input = vam->input;
14753 vl_api_pg_capture_t *mp;
14754 f64 timeout;
14755
14756 u32 if_id = ~0;
14757 u8 enable = 1;
14758 u32 count = 1;
14759 u8 pcap_file_set = 0;
14760 u8 *pcap_file = 0;
14761 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14762 {
14763 if (unformat (input, "if_id %d", &if_id))
14764 ;
14765 else if (unformat (input, "pcap %s", &pcap_file))
14766 pcap_file_set = 1;
14767 else if (unformat (input, "count %d", &count))
14768 ;
14769 else if (unformat (input, "disable"))
14770 enable = 0;
14771 else
14772 break;
14773 }
14774 if (if_id == ~0)
14775 {
14776 errmsg ("missing pg interface index\n");
14777 return -99;
14778 }
14779 if (pcap_file_set > 0)
14780 {
14781 if (vec_len (pcap_file) > 255)
14782 {
14783 errmsg ("pcap file name is too long\n");
14784 return -99;
14785 }
14786 }
14787
14788 u32 name_len = vec_len (pcap_file);
14789 /* Construct the API message */
14790 M (PG_CAPTURE, pg_capture);
14791 mp->context = 0;
14792 mp->interface_id = ntohl (if_id);
14793 mp->is_enabled = enable;
14794 mp->count = ntohl (count);
14795 mp->pcap_name_length = ntohl (name_len);
14796 if (pcap_file_set != 0)
14797 {
14798 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
14799 }
14800 vec_free (pcap_file);
14801
14802 S;
14803 W;
14804 /* NOTREACHED */
14805 return 0;
14806}
14807
14808int
14809api_pg_enable_disable (vat_main_t * vam)
14810{
14811 unformat_input_t *input = vam->input;
14812 vl_api_pg_enable_disable_t *mp;
14813 f64 timeout;
14814
14815 u8 enable = 1;
14816 u8 stream_name_set = 0;
14817 u8 *stream_name = 0;
14818 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14819 {
14820 if (unformat (input, "stream %s", &stream_name))
14821 stream_name_set = 1;
14822 else if (unformat (input, "disable"))
14823 enable = 0;
14824 else
14825 break;
14826 }
14827
14828 if (stream_name_set > 0)
14829 {
14830 if (vec_len (stream_name) > 255)
14831 {
14832 errmsg ("stream name too long\n");
14833 return -99;
14834 }
14835 }
14836
14837 u32 name_len = vec_len (stream_name);
14838 /* Construct the API message */
14839 M (PG_ENABLE_DISABLE, pg_enable_disable);
14840 mp->context = 0;
14841 mp->is_enabled = enable;
14842 if (stream_name_set != 0)
14843 {
14844 mp->stream_name_length = ntohl (name_len);
14845 clib_memcpy (mp->stream_name, stream_name, name_len);
14846 }
14847 vec_free (stream_name);
14848
14849 S;
14850 W;
14851 /* NOTREACHED */
14852 return 0;
14853}
14854
14855int
14856api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
14857{
14858 unformat_input_t *input = vam->input;
14859 vl_api_ip_source_and_port_range_check_add_del_t *mp;
14860 f64 timeout;
14861
14862 u16 *low_ports = 0;
14863 u16 *high_ports = 0;
14864 u16 this_low;
14865 u16 this_hi;
14866 ip4_address_t ip4_addr;
14867 ip6_address_t ip6_addr;
14868 u32 length;
14869 u32 tmp, tmp2;
14870 u8 prefix_set = 0;
14871 u32 vrf_id = ~0;
14872 u8 is_add = 1;
14873 u8 is_ipv6 = 0;
14874
14875 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14876 {
14877 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
14878 {
14879 prefix_set = 1;
14880 }
14881 else
14882 if (unformat
14883 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
14884 {
14885 prefix_set = 1;
14886 is_ipv6 = 1;
14887 }
14888 else if (unformat (input, "vrf %d", &vrf_id))
14889 ;
14890 else if (unformat (input, "del"))
14891 is_add = 0;
14892 else if (unformat (input, "port %d", &tmp))
14893 {
14894 if (tmp == 0 || tmp > 65535)
14895 {
14896 errmsg ("port %d out of range", tmp);
14897 return -99;
14898 }
14899 this_low = tmp;
14900 this_hi = this_low + 1;
14901 vec_add1 (low_ports, this_low);
14902 vec_add1 (high_ports, this_hi);
14903 }
14904 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
14905 {
14906 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
14907 {
14908 errmsg ("incorrect range parameters\n");
14909 return -99;
14910 }
14911 this_low = tmp;
14912 /* Note: in debug CLI +1 is added to high before
14913 passing to real fn that does "the work"
14914 (ip_source_and_port_range_check_add_del).
14915 This fn is a wrapper around the binary API fn a
14916 control plane will call, which expects this increment
14917 to have occurred. Hence letting the binary API control
14918 plane fn do the increment for consistency between VAT
14919 and other control planes.
14920 */
14921 this_hi = tmp2;
14922 vec_add1 (low_ports, this_low);
14923 vec_add1 (high_ports, this_hi);
14924 }
14925 else
14926 break;
14927 }
14928
14929 if (prefix_set == 0)
14930 {
14931 errmsg ("<address>/<mask> not specified\n");
14932 return -99;
14933 }
14934
14935 if (vrf_id == ~0)
14936 {
14937 errmsg ("VRF ID required, not specified\n");
14938 return -99;
14939 }
14940
14941 if (vrf_id == 0)
14942 {
14943 errmsg
14944 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
14945 return -99;
14946 }
14947
14948 if (vec_len (low_ports) == 0)
14949 {
14950 errmsg ("At least one port or port range required\n");
14951 return -99;
14952 }
14953
14954 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
14955 ip_source_and_port_range_check_add_del);
14956
14957 mp->is_add = is_add;
14958
14959 if (is_ipv6)
14960 {
14961 mp->is_ipv6 = 1;
14962 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
14963 }
14964 else
14965 {
14966 mp->is_ipv6 = 0;
14967 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
14968 }
14969
14970 mp->mask_length = length;
14971 mp->number_of_ranges = vec_len (low_ports);
14972
14973 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
14974 vec_free (low_ports);
14975
14976 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
14977 vec_free (high_ports);
14978
14979 mp->vrf_id = ntohl (vrf_id);
14980
14981 S;
14982 W;
14983 /* NOTREACHED */
14984 return 0;
14985}
14986
14987int
14988api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
14989{
14990 unformat_input_t *input = vam->input;
14991 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
14992 f64 timeout;
14993 u32 sw_if_index = ~0;
14994 int vrf_set = 0;
14995 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
14996 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
14997 u8 is_add = 1;
14998
14999 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15000 {
15001 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15002 ;
15003 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15004 ;
15005 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15006 vrf_set = 1;
15007 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15008 vrf_set = 1;
15009 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15010 vrf_set = 1;
15011 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15012 vrf_set = 1;
15013 else if (unformat (input, "del"))
15014 is_add = 0;
15015 else
15016 break;
15017 }
15018
15019 if (sw_if_index == ~0)
15020 {
15021 errmsg ("Interface required but not specified\n");
15022 return -99;
15023 }
15024
15025 if (vrf_set == 0)
15026 {
15027 errmsg ("VRF ID required but not specified\n");
15028 return -99;
15029 }
15030
15031 if (tcp_out_vrf_id == 0
15032 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15033 {
15034 errmsg
15035 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15036 return -99;
15037 }
15038
15039 /* Construct the API message */
15040 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15041 ip_source_and_port_range_check_interface_add_del);
15042
15043 mp->sw_if_index = ntohl (sw_if_index);
15044 mp->is_add = is_add;
15045 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15046 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15047 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15048 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15049
15050 /* send it... */
15051 S;
15052
15053 /* Wait for a reply... */
15054 W;
15055}
15056
15057static int
Matus Fabian694265d2016-08-10 01:55:36 -070015058api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15059{
15060 unformat_input_t *i = vam->input;
15061 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15062 f64 timeout;
15063 u32 local_sa_id = 0;
15064 u32 remote_sa_id = 0;
15065 ip4_address_t src_address;
15066 ip4_address_t dst_address;
15067 u8 is_add = 1;
15068
15069 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15070 {
15071 if (unformat (i, "local_sa %d", &local_sa_id))
15072 ;
15073 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15074 ;
15075 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15076 ;
15077 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15078 ;
15079 else if (unformat (i, "del"))
15080 is_add = 0;
15081 else
15082 {
15083 clib_warning ("parse error '%U'", format_unformat_error, i);
15084 return -99;
15085 }
15086 }
15087
15088 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15089
15090 mp->local_sa_id = ntohl (local_sa_id);
15091 mp->remote_sa_id = ntohl (remote_sa_id);
15092 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15093 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15094 mp->is_add = is_add;
15095
15096 S;
15097 W;
15098 /* NOTREACHED */
15099 return 0;
15100}
15101
15102static void vl_api_ipsec_gre_tunnel_details_t_handler
15103 (vl_api_ipsec_gre_tunnel_details_t * mp)
15104{
15105 vat_main_t *vam = &vat_main;
15106
15107 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15108 ntohl (mp->sw_if_index),
15109 format_ip4_address, &mp->src_address,
15110 format_ip4_address, &mp->dst_address,
15111 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15112}
15113
15114static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15115 (vl_api_ipsec_gre_tunnel_details_t * mp)
15116{
15117 vat_main_t *vam = &vat_main;
15118 vat_json_node_t *node = NULL;
15119 struct in_addr ip4;
15120
15121 if (VAT_JSON_ARRAY != vam->json_tree.type)
15122 {
15123 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15124 vat_json_init_array (&vam->json_tree);
15125 }
15126 node = vat_json_array_add (&vam->json_tree);
15127
15128 vat_json_init_object (node);
15129 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15130 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15131 vat_json_object_add_ip4 (node, "src_address", ip4);
15132 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15133 vat_json_object_add_ip4 (node, "dst_address", ip4);
15134 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15135 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15136}
15137
15138static int
15139api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15140{
15141 unformat_input_t *i = vam->input;
15142 vl_api_ipsec_gre_tunnel_dump_t *mp;
15143 f64 timeout;
15144 u32 sw_if_index;
15145 u8 sw_if_index_set = 0;
15146
15147 /* Parse args required to build the message */
15148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15149 {
15150 if (unformat (i, "sw_if_index %d", &sw_if_index))
15151 sw_if_index_set = 1;
15152 else
15153 break;
15154 }
15155
15156 if (sw_if_index_set == 0)
15157 {
15158 sw_if_index = ~0;
15159 }
15160
15161 if (!vam->json_output)
15162 {
15163 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15164 "sw_if_index", "src_address", "dst_address",
15165 "local_sa_id", "remote_sa_id");
15166 }
15167
15168 /* Get list of gre-tunnel interfaces */
15169 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15170
15171 mp->sw_if_index = htonl (sw_if_index);
15172
15173 S;
15174
15175 /* Use a control ping for synchronization */
15176 {
15177 vl_api_control_ping_t *mp;
15178 M (CONTROL_PING, control_ping);
15179 S;
15180 }
15181 W;
15182}
15183
15184static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015185api_delete_subif (vat_main_t * vam)
15186{
15187 unformat_input_t *i = vam->input;
15188 vl_api_delete_subif_t *mp;
15189 f64 timeout;
15190 u32 sw_if_index = ~0;
15191
15192 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15193 {
15194 if (unformat (i, "sw_if_index %d", &sw_if_index))
15195 ;
15196 else
15197 break;
15198 }
15199
15200 if (sw_if_index == ~0)
15201 {
15202 errmsg ("missing sw_if_index\n");
15203 return -99;
15204 }
15205
15206 /* Construct the API message */
15207 M (DELETE_SUBIF, delete_subif);
15208 mp->sw_if_index = ntohl (sw_if_index);
15209
15210 S;
15211 W;
15212}
15213
15214static int
Dave Barach72d72232016-08-04 10:15:08 -040015215q_or_quit (vat_main_t * vam)
15216{
15217 longjmp (vam->jump_buf, 1);
15218 return 0; /* not so much */
15219}
15220
15221static int
15222q (vat_main_t * vam)
15223{
15224 return q_or_quit (vam);
15225}
15226
15227static int
15228quit (vat_main_t * vam)
15229{
15230 return q_or_quit (vam);
15231}
15232
15233static int
15234comment (vat_main_t * vam)
15235{
15236 return 0;
15237}
15238
15239static int
15240cmd_cmp (void *a1, void *a2)
15241{
15242 u8 **c1 = a1;
15243 u8 **c2 = a2;
15244
15245 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
15246}
15247
15248static int
15249help (vat_main_t * vam)
15250{
15251 u8 **cmds = 0;
15252 u8 *name = 0;
15253 hash_pair_t *p;
15254 unformat_input_t *i = vam->input;
15255 int j;
15256
15257 if (unformat (i, "%s", &name))
15258 {
15259 uword *hs;
15260
15261 vec_add1 (name, 0);
15262
15263 hs = hash_get_mem (vam->help_by_name, name);
15264 if (hs)
15265 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
15266 else
15267 fformat (vam->ofp, "No such msg / command '%s'\n", name);
15268 vec_free (name);
15269 return 0;
15270 }
15271
15272 fformat (vam->ofp, "Help is available for the following:\n");
15273
15274 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015275 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015276 ({
Dave Barach72d72232016-08-04 10:15:08 -040015277 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015278 }));
Dave Barach72d72232016-08-04 10:15:08 -040015279 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015280
Dave Barach72d72232016-08-04 10:15:08 -040015281 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015282
Dave Barach72d72232016-08-04 10:15:08 -040015283 for (j = 0; j < vec_len (cmds); j++)
15284 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015285
Dave Barach72d72232016-08-04 10:15:08 -040015286 vec_free (cmds);
15287 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015288}
15289
Dave Barach72d72232016-08-04 10:15:08 -040015290static int
15291set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015292{
Dave Barach72d72232016-08-04 10:15:08 -040015293 u8 *name = 0, *value = 0;
15294 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015295
Dave Barach72d72232016-08-04 10:15:08 -040015296 if (unformat (i, "%s", &name))
15297 {
15298 /* The input buffer is a vector, not a string. */
15299 value = vec_dup (i->buffer);
15300 vec_delete (value, i->index, 0);
15301 /* Almost certainly has a trailing newline */
15302 if (value[vec_len (value) - 1] == '\n')
15303 value[vec_len (value) - 1] = 0;
15304 /* Make sure it's a proper string, one way or the other */
15305 vec_add1 (value, 0);
15306 (void) clib_macro_set_value (&vam->macro_main,
15307 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015308 }
Dave Barach72d72232016-08-04 10:15:08 -040015309 else
15310 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015311
Dave Barach72d72232016-08-04 10:15:08 -040015312 vec_free (name);
15313 vec_free (value);
15314 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015315}
15316
Dave Barach72d72232016-08-04 10:15:08 -040015317static int
15318unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015319{
Dave Barach72d72232016-08-04 10:15:08 -040015320 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015321
Dave Barach72d72232016-08-04 10:15:08 -040015322 if (unformat (vam->input, "%s", &name))
15323 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
15324 errmsg ("unset: %s wasn't set\n", name);
15325 vec_free (name);
15326 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015327}
15328
Dave Barach72d72232016-08-04 10:15:08 -040015329typedef struct
15330{
15331 u8 *name;
15332 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015333} macro_sort_t;
15334
15335
Dave Barach72d72232016-08-04 10:15:08 -040015336static int
15337macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015338{
Dave Barach72d72232016-08-04 10:15:08 -040015339 macro_sort_t *s1 = a1;
15340 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015341
Dave Barach72d72232016-08-04 10:15:08 -040015342 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015343}
15344
Dave Barach72d72232016-08-04 10:15:08 -040015345static int
15346dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015347{
Dave Barach72d72232016-08-04 10:15:08 -040015348 macro_sort_t *sort_me = 0, *sm;
15349 int i;
15350 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015351
Dave Barach72d72232016-08-04 10:15:08 -040015352 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015353 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070015354 ({
Dave Barach72d72232016-08-04 10:15:08 -040015355 vec_add2 (sort_me, sm, 1);
15356 sm->name = (u8 *)(p->key);
15357 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015358 }));
Dave Barach72d72232016-08-04 10:15:08 -040015359 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015360
Dave Barach72d72232016-08-04 10:15:08 -040015361 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015362
Dave Barach72d72232016-08-04 10:15:08 -040015363 if (vec_len (sort_me))
15364 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
15365 else
15366 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070015367
Dave Barach72d72232016-08-04 10:15:08 -040015368 for (i = 0; i < vec_len (sort_me); i++)
15369 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
15370 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015371}
15372
Dave Barach72d72232016-08-04 10:15:08 -040015373static int
15374dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015375{
Dave Barach72d72232016-08-04 10:15:08 -040015376 int i, j;
15377 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015378
Dave Barach72d72232016-08-04 10:15:08 -040015379 if (vec_len (vam->graph_nodes) == 0)
15380 {
15381 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15382 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015383 }
15384
Dave Barach72d72232016-08-04 10:15:08 -040015385 for (i = 0; i < vec_len (vam->graph_nodes); i++)
15386 {
15387 node = vam->graph_nodes[i];
15388 fformat (vam->ofp, "[%d] %s\n", i, node->name);
15389 for (j = 0; j < vec_len (node->next_nodes); j++)
15390 {
15391 if (node->next_nodes[j] != ~0)
15392 {
15393 next_node = vam->graph_nodes[node->next_nodes[j]];
15394 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15395 }
15396 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015397 }
Dave Barach72d72232016-08-04 10:15:08 -040015398 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015399}
15400
Dave Barach72d72232016-08-04 10:15:08 -040015401static int
15402search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050015403{
Dave Barach72d72232016-08-04 10:15:08 -040015404 unformat_input_t *line_input = vam->input;
15405 u8 *node_to_find;
15406 int j;
15407 vlib_node_t *node, *next_node;
15408 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015409
Dave Barach72d72232016-08-04 10:15:08 -040015410 if (vam->graph_node_index_by_name == 0)
15411 {
15412 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
15413 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015414 }
15415
Dave Barach72d72232016-08-04 10:15:08 -040015416 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
15417 {
15418 if (unformat (line_input, "%s", &node_to_find))
15419 {
15420 vec_add1 (node_to_find, 0);
15421 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
15422 if (p == 0)
15423 {
15424 fformat (vam->ofp, "%s not found...\n", node_to_find);
15425 goto out;
15426 }
15427 node = vam->graph_nodes[p[0]];
15428 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
15429 for (j = 0; j < vec_len (node->next_nodes); j++)
15430 {
15431 if (node->next_nodes[j] != ~0)
15432 {
15433 next_node = vam->graph_nodes[node->next_nodes[j]];
15434 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
15435 }
15436 }
15437 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015438
Dave Barach72d72232016-08-04 10:15:08 -040015439 else
15440 {
15441 clib_warning ("parse error '%U'", format_unformat_error,
15442 line_input);
15443 return -99;
15444 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050015445
15446 out:
Dave Barach72d72232016-08-04 10:15:08 -040015447 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015448
Dave Barachb44e9bc2016-02-19 09:06:23 -050015449 }
15450
Dave Barach72d72232016-08-04 10:15:08 -040015451 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050015452}
15453
15454
Dave Barach72d72232016-08-04 10:15:08 -040015455static int
15456script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015457{
Dave Barach72d72232016-08-04 10:15:08 -040015458 u8 *s = 0;
15459 char *save_current_file;
15460 unformat_input_t save_input;
15461 jmp_buf save_jump_buf;
15462 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015463
Dave Barach72d72232016-08-04 10:15:08 -040015464 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015465
Dave Barach72d72232016-08-04 10:15:08 -040015466 if (unformat (vam->input, "%s", &s))
15467 {
15468 new_fp = fopen ((char *) s, "r");
15469 if (new_fp == 0)
15470 {
15471 errmsg ("Couldn't open script file %s\n", s);
15472 vec_free (s);
15473 return -99;
15474 }
15475 }
15476 else
15477 {
15478 errmsg ("Missing script name\n");
15479 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015480 }
15481
Dave Barach72d72232016-08-04 10:15:08 -040015482 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
15483 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
15484 save_ifp = vam->ifp;
15485 save_line_number = vam->input_line_number;
15486 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015487
Dave Barach72d72232016-08-04 10:15:08 -040015488 vam->input_line_number = 0;
15489 vam->ifp = new_fp;
15490 vam->current_file = s;
15491 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015492
Dave Barach72d72232016-08-04 10:15:08 -040015493 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
15494 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
15495 vam->ifp = save_ifp;
15496 vam->input_line_number = save_line_number;
15497 vam->current_file = (u8 *) save_current_file;
15498 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015499
Dave Barach72d72232016-08-04 10:15:08 -040015500 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015501}
15502
Dave Barach72d72232016-08-04 10:15:08 -040015503static int
15504echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015505{
Dave Barach72d72232016-08-04 10:15:08 -040015506 fformat (vam->ofp, "%v", vam->input->buffer);
15507 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015508}
15509
15510/* List of API message constructors, CLI names map to api_xxx */
15511#define foreach_vpe_api_msg \
15512_(create_loopback,"[mac <mac-addr>]") \
15513_(sw_interface_dump,"") \
15514_(sw_interface_set_flags, \
15515 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
15516_(sw_interface_add_del_address, \
15517 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
15518_(sw_interface_set_table, \
15519 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
15520_(sw_interface_set_vpath, \
15521 "<intfc> | sw_if_index <id> enable | disable") \
15522_(sw_interface_set_l2_xconnect, \
15523 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15524 "enable | disable") \
15525_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040015526 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015527 "[shg <split-horizon-group>] [bvi]\n" \
15528 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010015529_(sw_interface_set_dpdk_hqos_pipe, \
15530 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
15531 "profile <profile-id>\n") \
15532_(sw_interface_set_dpdk_hqos_subport, \
15533 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
15534 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
15535_(sw_interface_set_dpdk_hqos_tctbl, \
15536 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015537_(bridge_domain_add_del, \
15538 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
15539_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
15540_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070015541 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015542_(l2_flags, \
15543 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
15544_(bridge_flags, \
15545 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15546_(tap_connect, \
15547 "tapname <name> mac <mac-addr> | random-mac") \
15548_(tap_modify, \
15549 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
15550_(tap_delete, \
15551 "<vpp-if-name> | sw_if_index <id>") \
15552_(sw_interface_tap_dump, "") \
15553_(ip_add_del_route, \
15554 "<addr>/<mask> via <addr> [vrf <n>]\n" \
15555 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
15556 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
15557 "[multipath] [count <n>]") \
15558_(proxy_arp_add_del, \
15559 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
15560_(proxy_arp_intfc_enable_disable, \
15561 "<intfc> | sw_if_index <id> enable | disable") \
15562_(mpls_add_del_encap, \
15563 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
15564_(mpls_add_del_decap, \
15565 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
15566_(mpls_gre_add_del_tunnel, \
15567 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
15568 "adj <ip4-address>/<mask-width> [del]") \
15569_(sw_interface_set_unnumbered, \
15570 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
15571_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040015572 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
15573 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015574_(reset_vrf, "vrf <id> [ipv6]") \
15575_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
15576_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
15577 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
15578 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
15579 "[outer_vlan_id_any][inner_vlan_id_any]") \
15580_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
15581_(reset_fib, "vrf <n> [ipv6]") \
15582_(dhcp_proxy_config, \
15583 "svr <v46-address> src <v46-address>\n" \
15584 "insert-cid <n> [del]") \
15585_(dhcp_proxy_config_2, \
15586 "svr <v46-address> src <v46-address>\n" \
15587 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
15588_(dhcp_proxy_set_vss, \
15589 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
15590_(dhcp_client_config, \
15591 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
15592_(set_ip_flow_hash, \
15593 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
15594_(sw_interface_ip6_enable_disable, \
15595 "<intfc> | sw_if_index <id> enable | disable") \
15596_(sw_interface_ip6_set_link_local_address, \
15597 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
15598_(sw_interface_ip6nd_ra_prefix, \
15599 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
15600 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
15601 "[nolink] [isno]") \
15602_(sw_interface_ip6nd_ra_config, \
15603 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040015604 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015605 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
15606_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
15607_(l2_patch_add_del, \
15608 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15609 "enable | disable") \
15610_(mpls_ethernet_add_del_tunnel, \
15611 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
15612 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
15613_(mpls_ethernet_add_del_tunnel_2, \
15614 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
15615 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
15616_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070015617 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
15618 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
15619 "[policy <policy_name>]") \
15620_(sr_policy_add_del, \
15621 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
15622_(sr_multicast_map_add_del, \
15623 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015624_(classify_add_del_table, \
15625 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15626 "[del] mask <mask-value>\n" \
15627 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
15628_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015629 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15630 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15631 " [l3 [ip4|ip6]]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015632_(classify_set_interface_ip_table, \
15633 "<intfc> | sw_if_index <nn> table <nn>") \
15634_(classify_set_interface_l2_tables, \
15635 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15636 " [other-table <nn>]") \
15637_(get_node_index, "node <node-name") \
15638_(add_node_next, "node <node-name> next <next-node-name>") \
15639_(l2tpv3_create_tunnel, \
15640 "client_address <ip6-addr> our_address <ip6-addr>\n" \
15641 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
15642 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
15643_(l2tpv3_set_tunnel_cookies, \
15644 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
15645 "[new_remote_cookie <nn>]\n") \
15646_(l2tpv3_interface_enable_disable, \
15647 "<intfc> | sw_if_index <nn> enable | disable") \
15648_(l2tpv3_set_lookup_key, \
15649 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
15650_(sw_if_l2tpv3_tunnel_dump, "") \
15651_(vxlan_add_del_tunnel, \
Chris Luke404be662016-05-27 12:11:24 -040015652 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015653 " [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050015654_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015655_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070015656 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040015657_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015658_(l2_fib_clear_table, "") \
15659_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15660_(l2_interface_vlan_tag_rewrite, \
15661 "<intfc> | sw_if_index <nn> \n" \
15662 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15663 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15664_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000015665 "socket <filename> [server] [renumber <dev_instance>] " \
15666 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015667_(modify_vhost_user_if, \
15668 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15669 "[server] [renumber <dev_instance>]") \
15670_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15671_(sw_interface_vhost_user_dump, "") \
15672_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080015673_(vxlan_gpe_add_del_tunnel, \
15674 "local <addr> remote <addr> vni <nn>\n" \
15675 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
15676 "[next-ethernet] [next-nsh]\n") \
15677_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015678_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015679_(interface_name_renumber, \
15680 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15681_(input_acl_set_interface, \
15682 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15683 " [l2-table <nn>] [del]") \
15684_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040015685_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015686_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15687_(ip_dump, "ipv4 | ipv6") \
15688_(ipsec_spd_add_del, "spd_id <n> [del]") \
15689_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15690 " spid_id <n> ") \
15691_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15692 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15693 " integ_alg <alg> integ_key <hex>") \
15694_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
15695 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15696 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15697 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
15698_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020015699_(ikev2_profile_add_del, "name <profile_name> [del]") \
15700_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
15701 "(auth_data 0x<data> | auth_data <data>)") \
15702_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
15703 "(id_data 0x<data> | id_data <data>) (local|remote)") \
15704_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
15705 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
15706 "(local|remote)") \
15707_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015708_(delete_loopback,"sw_if_index <nn>") \
15709_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15710_(map_add_domain, \
15711 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
15712 "ip6-src <ip6addr> " \
15713 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
15714_(map_del_domain, "index <n>") \
15715_(map_add_del_rule, \
15716 "index <n> psid <n> dst <ip6addr> [del]") \
15717_(map_domain_dump, "") \
15718_(map_rule_dump, "index <map-domain>") \
15719_(want_interface_events, "enable|disable") \
15720_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050015721_(get_first_msg_id, "client <name>") \
15722_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15723_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015724 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010015725_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000015726_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070015727_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15728_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020015729_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
15730 " sw_if_index <sw_if_index> p <priority> " \
15731 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015732_(lisp_add_del_locator, "locator-set <locator_name> " \
15733 "iface <intf> | sw_if_index <sw_if_index> " \
15734 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015735_(lisp_add_del_local_eid,"vni <vni> eid " \
15736 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015737 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020015738_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
15739 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015740_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020015741_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020015742_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015743_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015744_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
15745 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015746 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020015747 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020015748 "action <action> [del-all]") \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020015749_(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid " \
15750 "<src-eid> rloc <locator> p <prio> w <weight>"\
15751 "[rloc <loc> ... ] action <action>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020015752_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020015753_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015754_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020015755_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020015756_(lisp_locator_set_dump, "[local | remote]") \
15757_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020015758_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
15759 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020015760_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020015761_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020015762_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020015763_(lisp_map_resolver_dump, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020015764_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020015765_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020015766_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020015767_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020015768_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070015769_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015770_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070015771_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015772_(policer_classify_set_interface, \
15773 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15774 " [l2-table <nn>] [del]") \
15775_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070015776_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
15777 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015778_(netmap_delete, "name <interface name>") \
15779_(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
15780_(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
15781_(mpls_fib_encap_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015782_(mpls_fib_decap_dump, "") \
15783_(classify_table_ids, "") \
15784_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15785_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015786_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015787_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15788 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15789 "[template_interval <nn>] [udp_checksum]") \
15790_(ipfix_exporter_dump, "") \
15791_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15792_(ipfix_classify_stream_dump, "") \
15793_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
15794_(ipfix_classify_table_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015795_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15796_(pg_create_interface, "if_id <nn>") \
15797_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040015798_(pg_enable_disable, "[stream <id>] disable") \
15799_(ip_source_and_port_range_check_add_del, \
15800 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15801_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070015802 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070015803 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15804_(ipsec_gre_add_del_tunnel, \
15805 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015806_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
15807_(delete_subif,"sub_sw_if_index <nn> sub_if_id <nn>")
Ed Warnickecb9cada2015-12-08 15:45:58 -070015808
15809/* List of command functions, CLI names map directly to functions */
15810#define foreach_cli_function \
15811_(comment, "usage: comment <ignore-rest-of-line>") \
15812_(dump_interface_table, "usage: dump_interface_table") \
15813_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15814_(dump_ipv4_table, "usage: dump_ipv4_table") \
15815_(dump_ipv6_table, "usage: dump_ipv6_table") \
15816_(dump_stats_table, "usage: dump_stats_table") \
15817_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015818_(dump_node_table, "usage: dump_node_table") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015819_(echo, "usage: echo <message>") \
15820_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020015821_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015822_(help, "usage: help") \
15823_(q, "usage: quit") \
15824_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050015825_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070015826_(set, "usage: set <variable-name> <value>") \
15827_(script, "usage: script <file-name>") \
15828_(unset, "usage: unset <variable-name>")
15829
15830#define _(N,n) \
15831 static void vl_api_##n##_t_handler_uni \
15832 (vl_api_##n##_t * mp) \
15833 { \
15834 vat_main_t * vam = &vat_main; \
15835 if (vam->json_output) { \
15836 vl_api_##n##_t_handler_json(mp); \
15837 } else { \
15838 vl_api_##n##_t_handler(mp); \
15839 } \
15840 }
15841foreach_vpe_api_reply_msg;
15842#undef _
15843
Dave Barach72d72232016-08-04 10:15:08 -040015844void
15845vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015846{
15847#define _(N,n) \
15848 vl_msg_api_set_handlers(VL_API_##N, #n, \
15849 vl_api_##n##_t_handler_uni, \
15850 vl_noop_handler, \
15851 vl_api_##n##_t_endian, \
15852 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080015853 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040015854 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015855#undef _
15856
Dave Barach72d72232016-08-04 10:15:08 -040015857 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015858
Dave Barach72d72232016-08-04 10:15:08 -040015859 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015860
Dave Barach72d72232016-08-04 10:15:08 -040015861 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015862
Dave Barach72d72232016-08-04 10:15:08 -040015863 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070015864
Dave Barach72d72232016-08-04 10:15:08 -040015865 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015866#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040015867 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015868#undef _
15869
Dave Barach72d72232016-08-04 10:15:08 -040015870 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015871#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040015872 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015873#undef _
15874
Dave Barach72d72232016-08-04 10:15:08 -040015875 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015876#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040015877 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015878#undef _
15879
Dave Barach72d72232016-08-04 10:15:08 -040015880 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070015881#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040015882 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015883#undef _
15884}
15885
15886#undef vl_api_version
15887#define vl_api_version(n,v) static u32 vpe_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040015888#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070015889#undef vl_api_version
15890
Dave Barach72d72232016-08-04 10:15:08 -040015891void
15892vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015893{
Dave Barach72d72232016-08-04 10:15:08 -040015894 /*
15895 * Send the main API signature in slot 0. This bit of code must
15896 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
15897 */
15898 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015899}
Dave Barach72d72232016-08-04 10:15:08 -040015900
15901/*
15902 * fd.io coding-style-patch-verification: ON
15903 *
15904 * Local Variables:
15905 * eval: (c-set-style "gnu")
15906 * End:
15907 */