blob: 2a64958e6d4bd23e38cdc1b6c13f5808b9b148e6 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07005 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * 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>
Juraj Sloboda506b2452016-08-07 23:45:24 -070038#include <vnet/classify/flow_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039#include <vnet/mpls/mpls.h>
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#include <inttypes.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070043#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050044#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000045#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040046#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070047#include <vnet/policer/xlate.h>
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010048#include <vnet/span/span.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070049#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070050#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
52#include "vat/json_format.h"
53
Damjan Marion67655492016-11-15 12:50:28 +010054#include <inttypes.h>
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 Barach72d72232016-08-04 10:15:08 -0400248 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249
Dave Barach72d72232016-08-04 10:15:08 -0400250 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
252 foreach_ipsec_policy_action
253#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400254 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255 return 0;
256 return 1;
257}
258
259uword
260unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
261{
Dave Barach72d72232016-08-04 10:15:08 -0400262 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263
Dave Barach72d72232016-08-04 10:15:08 -0400264 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
266 foreach_ipsec_crypto_alg
267#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400268 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269 return 0;
270 return 1;
271}
272
273u8 *
274format_ipsec_crypto_alg (u8 * s, va_list * args)
275{
276 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400277 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
279 switch (i)
280 {
281#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400282 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400284 default:
285 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286 }
287 return format (s, "%s", t);
288}
289
290uword
291unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
292{
Dave Barach72d72232016-08-04 10:15:08 -0400293 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
Dave Barach72d72232016-08-04 10:15:08 -0400295 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
297 foreach_ipsec_integ_alg
298#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400299 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300 return 0;
301 return 1;
302}
303
304u8 *
305format_ipsec_integ_alg (u8 * s, va_list * args)
306{
307 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400308 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309
310 switch (i)
311 {
312#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400313 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400315 default:
316 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317 }
318 return format (s, "%s", t);
319}
320
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200321uword
322unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
323{
Dave Barach72d72232016-08-04 10:15:08 -0400324 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200325
Dave Barach72d72232016-08-04 10:15:08 -0400326 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200327#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
328 foreach_ikev2_auth_method
329#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400330 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200331 return 0;
332 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200333}
334
335uword
336unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
337{
Dave Barach72d72232016-08-04 10:15:08 -0400338 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200339
Dave Barach72d72232016-08-04 10:15:08 -0400340 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200341#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
342 foreach_ikev2_id_type
343#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400344 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200345 return 0;
346 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200347}
348
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700349uword
350unformat_policer_rate_type (unformat_input_t * input, va_list * args)
351{
Dave Barach72d72232016-08-04 10:15:08 -0400352 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700353
354 if (unformat (input, "kbps"))
355 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400356 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700357 *r = SSE2_QOS_RATE_PPS;
358 else
359 return 0;
360 return 1;
361}
362
363uword
364unformat_policer_round_type (unformat_input_t * input, va_list * args)
365{
Dave Barach72d72232016-08-04 10:15:08 -0400366 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700367
Dave Barach72d72232016-08-04 10:15:08 -0400368 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700369 *r = SSE2_QOS_ROUND_TO_CLOSEST;
370 else if (unformat (input, "up"))
371 *r = SSE2_QOS_ROUND_TO_UP;
372 else if (unformat (input, "down"))
373 *r = SSE2_QOS_ROUND_TO_DOWN;
374 else
375 return 0;
376 return 1;
377}
378
379uword
380unformat_policer_type (unformat_input_t * input, va_list * args)
381{
Dave Barach72d72232016-08-04 10:15:08 -0400382 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700383
384 if (unformat (input, "1r2c"))
385 *r = SSE2_QOS_POLICER_TYPE_1R2C;
386 else if (unformat (input, "1r3c"))
387 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
388 else if (unformat (input, "2r3c-2698"))
389 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
390 else if (unformat (input, "2r3c-4115"))
391 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
392 else if (unformat (input, "2r3c-mef5cf1"))
393 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
394 else
395 return 0;
396 return 1;
397}
398
Matus Fabian4ac74c92016-05-31 07:33:29 -0700399uword
400unformat_dscp (unformat_input_t * input, va_list * va)
401{
Dave Barach72d72232016-08-04 10:15:08 -0400402 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700403
Dave Barach72d72232016-08-04 10:15:08 -0400404 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700405#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400406 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700407#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400408 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700409 return 0;
410 return 1;
411}
412
413uword
414unformat_policer_action_type (unformat_input_t * input, va_list * va)
415{
Dave Barach72d72232016-08-04 10:15:08 -0400416 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700417 = va_arg (*va, sse2_qos_pol_action_params_st *);
418
419 if (unformat (input, "drop"))
420 a->action_type = SSE2_QOS_ACTION_DROP;
421 else if (unformat (input, "transmit"))
422 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
423 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
424 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
425 else
426 return 0;
427 return 1;
428}
429
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700430uword
Juraj Sloboda506b2452016-08-07 23:45:24 -0700431unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700432{
Dave Barach72d72232016-08-04 10:15:08 -0400433 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700434 u32 tid;
435
436 if (unformat (input, "ip4"))
437 tid = POLICER_CLASSIFY_TABLE_IP4;
438 else if (unformat (input, "ip6"))
439 tid = POLICER_CLASSIFY_TABLE_IP6;
440 else if (unformat (input, "l2"))
441 tid = POLICER_CLASSIFY_TABLE_L2;
442 else
443 return 0;
444
445 *r = tid;
446 return 1;
447}
448
Juraj Sloboda506b2452016-08-07 23:45:24 -0700449uword
450unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
451{
452 u32 *r = va_arg (*va, u32 *);
453 u32 tid;
454
455 if (unformat (input, "ip4"))
456 tid = FLOW_CLASSIFY_TABLE_IP4;
457 else if (unformat (input, "ip6"))
458 tid = FLOW_CLASSIFY_TABLE_IP6;
459 else
460 return 0;
461
462 *r = tid;
463 return 1;
464}
465
Dave Barach72d72232016-08-04 10:15:08 -0400466u8 *
467format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468{
Dave Barach72d72232016-08-04 10:15:08 -0400469 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
471}
472
Dave Barach72d72232016-08-04 10:15:08 -0400473u8 *
474format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475{
Dave Barach72d72232016-08-04 10:15:08 -0400476 ip6_address_t *a = va_arg (*args, ip6_address_t *);
477 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478
Dave Barach72d72232016-08-04 10:15:08 -0400479 i_max_n_zero = ARRAY_LEN (a->as_u16);
480 max_n_zeros = 0;
481 i_first_zero = i_max_n_zero;
482 n_zeros = 0;
483 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
484 {
485 u32 is_zero = a->as_u16[i] == 0;
486 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
487 {
488 i_first_zero = i;
489 n_zeros = 0;
490 }
491 n_zeros += is_zero;
492 if ((!is_zero && n_zeros > max_n_zeros)
493 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
494 {
495 i_max_n_zero = i_first_zero;
496 max_n_zeros = n_zeros;
497 i_first_zero = ARRAY_LEN (a->as_u16);
498 n_zeros = 0;
499 }
500 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501
Dave Barach72d72232016-08-04 10:15:08 -0400502 last_double_colon = 0;
503 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
504 {
505 if (i == i_max_n_zero && max_n_zeros > 1)
506 {
507 s = format (s, "::");
508 i += max_n_zeros - 1;
509 last_double_colon = 1;
510 }
511 else
512 {
513 s = format (s, "%s%x",
514 (last_double_colon || i == 0) ? "" : ":",
515 clib_net_to_host_u16 (a->as_u16[i]));
516 last_double_colon = 0;
517 }
518 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519
Dave Barach72d72232016-08-04 10:15:08 -0400520 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521}
522
Chris Luke99cb3352016-04-26 10:49:53 -0400523/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400524u8 *
525format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400526{
527 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200528 ip46_type_t type = va_arg (*args, ip46_type_t);
529 int is_ip4 = 1;
530
531 switch (type)
532 {
Dave Barach72d72232016-08-04 10:15:08 -0400533 case IP46_TYPE_ANY:
534 is_ip4 = ip46_address_is_ip4 (ip46);
535 break;
536 case IP46_TYPE_IP4:
537 is_ip4 = 1;
538 break;
539 case IP46_TYPE_IP6:
540 is_ip4 = 0;
541 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200542 }
543
544 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400545 format (s, "%U", format_ip4_address, &ip46->ip4) :
546 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400547}
548
Dave Barach72d72232016-08-04 10:15:08 -0400549u8 *
550format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700551{
Dave Barach72d72232016-08-04 10:15:08 -0400552 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553
554 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400555 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700556}
557
Dave Barach72d72232016-08-04 10:15:08 -0400558void
559increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700560{
Dave Barach72d72232016-08-04 10:15:08 -0400561 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562
Dave Barach72d72232016-08-04 10:15:08 -0400563 v = ntohl (a->as_u32) + 1;
564 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565}
566
Dave Barach72d72232016-08-04 10:15:08 -0400567void
568increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569{
Dave Barach72d72232016-08-04 10:15:08 -0400570 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571
Dave Barach72d72232016-08-04 10:15:08 -0400572 v0 = clib_net_to_host_u64 (a->as_u64[0]);
573 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700574
Dave Barach72d72232016-08-04 10:15:08 -0400575 v1 += 1;
576 if (v1 == 0)
577 v0 += 1;
578 a->as_u64[0] = clib_net_to_host_u64 (v0);
579 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580}
581
Dave Barach72d72232016-08-04 10:15:08 -0400582void
583increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700584{
Dave Barach72d72232016-08-04 10:15:08 -0400585 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700586
Dave Barach72d72232016-08-04 10:15:08 -0400587 tmp = clib_net_to_host_u64 (tmp);
588 tmp += 1 << 16; /* skip unused (least significant) octets */
589 tmp = clib_host_to_net_u64 (tmp);
590 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700591}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800593static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400594 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700595{
Dave Barach72d72232016-08-04 10:15:08 -0400596 vat_main_t *vam = &vat_main;
597 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598
Dave Barach72d72232016-08-04 10:15:08 -0400599 vam->retval = retval;
600 vam->regenerate_interface_table = 1;
601 vam->sw_if_index = ntohl (mp->sw_if_index);
602 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603}
604
605static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400606 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700607{
Dave Barach72d72232016-08-04 10:15:08 -0400608 vat_main_t *vam = &vat_main;
609 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610
Dave Barach72d72232016-08-04 10:15:08 -0400611 vat_json_init_object (&node);
612 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
613 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
Dave Barach72d72232016-08-04 10:15:08 -0400615 vat_json_print (vam->ofp, &node);
616 vat_json_free (&node);
617 vam->retval = ntohl (mp->retval);
618 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700619}
620
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800621static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400622 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700623{
Dave Barach72d72232016-08-04 10:15:08 -0400624 vat_main_t *vam = &vat_main;
625 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700626
Dave Barach72d72232016-08-04 10:15:08 -0400627 vam->retval = retval;
628 vam->regenerate_interface_table = 1;
629 vam->sw_if_index = ntohl (mp->sw_if_index);
630 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700631}
632
633static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400634 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700635{
Dave Barach72d72232016-08-04 10:15:08 -0400636 vat_main_t *vam = &vat_main;
637 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700638
Dave Barach72d72232016-08-04 10:15:08 -0400639 vat_json_init_object (&node);
640 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
641 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700642
Dave Barach72d72232016-08-04 10:15:08 -0400643 vat_json_print (vam->ofp, &node);
644 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700645
Dave Barach72d72232016-08-04 10:15:08 -0400646 vam->retval = ntohl (mp->retval);
647 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700648}
649
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800650static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400651 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700652{
Dave Barach72d72232016-08-04 10:15:08 -0400653 vat_main_t *vam = &vat_main;
654 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700655
Dave Barach72d72232016-08-04 10:15:08 -0400656 vam->retval = retval;
657 vam->regenerate_interface_table = 1;
658 vam->sw_if_index = ntohl (mp->sw_if_index);
659 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700660}
661
662static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400663 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700664{
Dave Barach72d72232016-08-04 10:15:08 -0400665 vat_main_t *vam = &vat_main;
666 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700667
Dave Barach72d72232016-08-04 10:15:08 -0400668 vat_json_init_object (&node);
669 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
670 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671
Dave Barach72d72232016-08-04 10:15:08 -0400672 vat_json_print (vam->ofp, &node);
673 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674
Dave Barach72d72232016-08-04 10:15:08 -0400675 vam->retval = ntohl (mp->retval);
676 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700677}
678
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800679static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400680 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681{
Dave Barach72d72232016-08-04 10:15:08 -0400682 vat_main_t *vam = &vat_main;
683 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700684
Dave Barach72d72232016-08-04 10:15:08 -0400685 vam->retval = retval;
686 vam->regenerate_interface_table = 1;
687 vam->sw_if_index = ntohl (mp->sw_if_index);
688 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700689}
690
691static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400692 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693{
Dave Barach72d72232016-08-04 10:15:08 -0400694 vat_main_t *vam = &vat_main;
695 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
Dave Barach72d72232016-08-04 10:15:08 -0400697 vat_json_init_object (&node);
698 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
699 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700
Dave Barach72d72232016-08-04 10:15:08 -0400701 vat_json_print (vam->ofp, &node);
702 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703
Dave Barach72d72232016-08-04 10:15:08 -0400704 vam->retval = ntohl (mp->retval);
705 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706}
707
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800708static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400709 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710{
Dave Barach72d72232016-08-04 10:15:08 -0400711 vat_main_t *vam = &vat_main;
712 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713
Dave Barach72d72232016-08-04 10:15:08 -0400714 vam->retval = retval;
715 vam->regenerate_interface_table = 1;
716 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717}
718
719static void vl_api_interface_name_renumber_reply_t_handler_json
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 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
Dave Barach72d72232016-08-04 10:15:08 -0400725 vat_json_init_object (&node);
726 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700727
Dave Barach72d72232016-08-04 10:15:08 -0400728 vat_json_print (vam->ofp, &node);
729 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700730
Dave Barach72d72232016-08-04 10:15:08 -0400731 vam->retval = ntohl (mp->retval);
732 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700733}
734
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800735/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736 * Special-case: build the interface table, maintain
737 * the next loopback sw_if_index vbl.
738 */
739static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400740 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741{
Dave Barach72d72232016-08-04 10:15:08 -0400742 vat_main_t *vam = &vat_main;
743 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744
Dave Barach72d72232016-08-04 10:15:08 -0400745 hash_set_mem (vam->sw_if_index_by_interface_name, s,
746 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747
Dave Barach72d72232016-08-04 10:15:08 -0400748 /* In sub interface case, fill the sub interface table entry */
749 if (mp->sw_if_index != mp->sup_sw_if_index)
750 {
751 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752
Dave Barach72d72232016-08-04 10:15:08 -0400753 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700754
Dave Barach72d72232016-08-04 10:15:08 -0400755 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
756 strncpy ((char *) sub->interface_name, (char *) s,
757 vec_len (sub->interface_name));
758 sub->sw_if_index = ntohl (mp->sw_if_index);
759 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760
Dave Barach72d72232016-08-04 10:15:08 -0400761 sub->sub_dot1ad = mp->sub_dot1ad;
762 sub->sub_number_of_tags = mp->sub_number_of_tags;
763 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
764 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
765 sub->sub_exact_match = mp->sub_exact_match;
766 sub->sub_default = mp->sub_default;
767 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
768 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769
Dave Barach72d72232016-08-04 10:15:08 -0400770 /* vlan tag rewrite */
771 sub->vtr_op = ntohl (mp->vtr_op);
772 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
773 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
774 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775 }
776}
777
778static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400779 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780{
Dave Barach72d72232016-08-04 10:15:08 -0400781 vat_main_t *vam = &vat_main;
782 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783
Dave Barach72d72232016-08-04 10:15:08 -0400784 if (VAT_JSON_ARRAY != vam->json_tree.type)
785 {
786 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
787 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 }
Dave Barach72d72232016-08-04 10:15:08 -0400789 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700790
Dave Barach72d72232016-08-04 10:15:08 -0400791 vat_json_init_object (node);
792 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
793 vat_json_object_add_uint (node, "sup_sw_if_index",
794 ntohl (mp->sup_sw_if_index));
795 vat_json_object_add_uint (node, "l2_address_length",
796 ntohl (mp->l2_address_length));
797 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
798 sizeof (mp->l2_address));
799 vat_json_object_add_string_copy (node, "interface_name",
800 mp->interface_name);
801 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
802 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
803 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
804 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
805 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
806 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
807 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
808 vat_json_object_add_uint (node, "sub_number_of_tags",
809 mp->sub_number_of_tags);
810 vat_json_object_add_uint (node, "sub_outer_vlan_id",
811 ntohs (mp->sub_outer_vlan_id));
812 vat_json_object_add_uint (node, "sub_inner_vlan_id",
813 ntohs (mp->sub_inner_vlan_id));
814 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
815 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
816 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
817 mp->sub_outer_vlan_id_any);
818 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
819 mp->sub_inner_vlan_id_any);
820 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
821 vat_json_object_add_uint (node, "vtr_push_dot1q",
822 ntohl (mp->vtr_push_dot1q));
823 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
824 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700825}
826
827static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400828 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700829{
Dave Barach72d72232016-08-04 10:15:08 -0400830 vat_main_t *vam = &vat_main;
831 if (vam->interface_event_display)
832 errmsg ("interface flags: sw_if_index %d %s %s\n",
833 ntohl (mp->sw_if_index),
834 mp->admin_up_down ? "admin-up" : "admin-down",
835 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836}
837
838static void vl_api_sw_interface_set_flags_t_handler_json
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 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700842}
843
Dave Barach72d72232016-08-04 10:15:08 -0400844static void
845vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700846{
Dave Barach72d72232016-08-04 10:15:08 -0400847 vat_main_t *vam = &vat_main;
848 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700849
Dave Barach72d72232016-08-04 10:15:08 -0400850 vam->retval = retval;
851 vam->shmem_result = (u8 *) mp->reply_in_shmem;
852 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853}
854
Dave Barach72d72232016-08-04 10:15:08 -0400855static void
856vl_api_cli_reply_t_handler_json (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 vat_json_node_t node;
860 api_main_t *am = &api_main;
861 void *oldheap;
862 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700863
Dave Barach72d72232016-08-04 10:15:08 -0400864 vat_json_init_object (&node);
865 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
866 vat_json_object_add_uint (&node, "reply_in_shmem",
867 ntohl (mp->reply_in_shmem));
868 /* Toss the shared-memory original... */
869 pthread_mutex_lock (&am->vlib_rp->mutex);
870 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500871
Dave Barach72d72232016-08-04 10:15:08 -0400872 reply = (u8 *) (mp->reply_in_shmem);
873 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800874
Dave Barach72d72232016-08-04 10:15:08 -0400875 svm_pop_heap (oldheap);
876 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877
Dave Barach72d72232016-08-04 10:15:08 -0400878 vat_json_print (vam->ofp, &node);
879 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700880
Dave Barach72d72232016-08-04 10:15:08 -0400881 vam->retval = ntohl (mp->retval);
882 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883}
884
Ole Troanc27213a2016-08-31 14:50:49 +0200885static void
886vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
887{
888 vat_main_t *vam = &vat_main;
889 i32 retval = ntohl (mp->retval);
890
891 vam->retval = retval;
892 vam->cmd_reply = mp->reply;
893 vam->result_ready = 1;
894}
895
896static void
897vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
898{
899 vat_main_t *vam = &vat_main;
900 vat_json_node_t node;
901
902 vat_json_init_object (&node);
903 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
904 vat_json_object_add_string_copy (&node, "reply", mp->reply);
905
906 vat_json_print (vam->ofp, &node);
907 vat_json_free (&node);
908
909 vam->retval = ntohl (mp->retval);
910 vam->result_ready = 1;
911}
912
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400914 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700915{
Dave Barach72d72232016-08-04 10:15:08 -0400916 vat_main_t *vam = &vat_main;
917 i32 retval = ntohl (mp->retval);
918 if (vam->async_mode)
919 {
920 vam->async_errors += (retval < 0);
921 }
922 else
923 {
924 vam->retval = retval;
925 if (retval == 0 &&
926 ((mp->new_table_index != 0xFFFFFFFF) ||
927 (mp->skip_n_vectors != 0xFFFFFFFF) ||
928 (mp->match_n_vectors != 0xFFFFFFFF)))
929 /*
930 * Note: this is just barely thread-safe, depends on
931 * the main thread spinning waiting for an answer...
932 */
933 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
934 ntohl (mp->new_table_index),
935 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
936 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937 }
938}
939
940static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400941 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942{
Dave Barach72d72232016-08-04 10:15:08 -0400943 vat_main_t *vam = &vat_main;
944 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700945
Dave Barach72d72232016-08-04 10:15:08 -0400946 vat_json_init_object (&node);
947 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
948 vat_json_object_add_uint (&node, "new_table_index",
949 ntohl (mp->new_table_index));
950 vat_json_object_add_uint (&node, "skip_n_vectors",
951 ntohl (mp->skip_n_vectors));
952 vat_json_object_add_uint (&node, "match_n_vectors",
953 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700954
Dave Barach72d72232016-08-04 10:15:08 -0400955 vat_json_print (vam->ofp, &node);
956 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700957
Dave Barach72d72232016-08-04 10:15:08 -0400958 vam->retval = ntohl (mp->retval);
959 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960}
961
962static void vl_api_get_node_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400963 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964{
Dave Barach72d72232016-08-04 10:15:08 -0400965 vat_main_t *vam = &vat_main;
966 i32 retval = ntohl (mp->retval);
967 if (vam->async_mode)
968 {
969 vam->async_errors += (retval < 0);
970 }
971 else
972 {
973 vam->retval = retval;
974 if (retval == 0)
975 errmsg ("node index %d\n", ntohl (mp->node_index));
976 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977 }
978}
979
980static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400981 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982{
Dave Barach72d72232016-08-04 10:15:08 -0400983 vat_main_t *vam = &vat_main;
984 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985
Dave Barach72d72232016-08-04 10:15:08 -0400986 vat_json_init_object (&node);
987 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
988 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989
Dave Barach72d72232016-08-04 10:15:08 -0400990 vat_json_print (vam->ofp, &node);
991 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992
Dave Barach72d72232016-08-04 10:15:08 -0400993 vam->retval = ntohl (mp->retval);
994 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995}
996
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700997static void vl_api_get_next_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400998 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700999{
Dave Barach72d72232016-08-04 10:15:08 -04001000 vat_main_t *vam = &vat_main;
1001 i32 retval = ntohl (mp->retval);
1002 if (vam->async_mode)
1003 {
1004 vam->async_errors += (retval < 0);
1005 }
1006 else
1007 {
1008 vam->retval = retval;
1009 if (retval == 0)
1010 errmsg ("next node index %d\n", ntohl (mp->next_index));
1011 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001012 }
1013}
1014
1015static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001016 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001017{
Dave Barach72d72232016-08-04 10:15:08 -04001018 vat_main_t *vam = &vat_main;
1019 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001020
Dave Barach72d72232016-08-04 10:15:08 -04001021 vat_json_init_object (&node);
1022 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1023 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001024
Dave Barach72d72232016-08-04 10:15:08 -04001025 vat_json_print (vam->ofp, &node);
1026 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001027
Dave Barach72d72232016-08-04 10:15:08 -04001028 vam->retval = ntohl (mp->retval);
1029 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001030}
1031
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032static void vl_api_add_node_next_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001033 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034{
Dave Barach72d72232016-08-04 10:15:08 -04001035 vat_main_t *vam = &vat_main;
1036 i32 retval = ntohl (mp->retval);
1037 if (vam->async_mode)
1038 {
1039 vam->async_errors += (retval < 0);
1040 }
1041 else
1042 {
1043 vam->retval = retval;
1044 if (retval == 0)
1045 errmsg ("next index %d\n", ntohl (mp->next_index));
1046 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001047 }
1048}
1049
1050static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001051 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052{
Dave Barach72d72232016-08-04 10:15:08 -04001053 vat_main_t *vam = &vat_main;
1054 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001055
Dave Barach72d72232016-08-04 10:15:08 -04001056 vat_json_init_object (&node);
1057 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1058 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001059
Dave Barach72d72232016-08-04 10:15:08 -04001060 vat_json_print (vam->ofp, &node);
1061 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001062
Dave Barach72d72232016-08-04 10:15:08 -04001063 vam->retval = ntohl (mp->retval);
1064 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001065}
1066
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001067static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001068 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069{
Dave Barach72d72232016-08-04 10:15:08 -04001070 vat_main_t *vam = &vat_main;
1071 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072
Dave Barach72d72232016-08-04 10:15:08 -04001073 if (retval >= 0)
1074 {
1075 errmsg (" program: %s\n", mp->program);
1076 errmsg (" version: %s\n", mp->version);
1077 errmsg (" build date: %s\n", mp->build_date);
1078 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001079 }
Dave Barach72d72232016-08-04 10:15:08 -04001080 vam->retval = retval;
1081 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001082}
1083
1084static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001085 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001086{
Dave Barach72d72232016-08-04 10:15:08 -04001087 vat_main_t *vam = &vat_main;
1088 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089
Dave Barach72d72232016-08-04 10:15:08 -04001090 vat_json_init_object (&node);
1091 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1092 vat_json_object_add_string_copy (&node, "program", mp->program);
1093 vat_json_object_add_string_copy (&node, "version", mp->version);
1094 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1095 vat_json_object_add_string_copy (&node, "build_directory",
1096 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001097
Dave Barach72d72232016-08-04 10:15:08 -04001098 vat_json_print (vam->ofp, &node);
1099 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100
Dave Barach72d72232016-08-04 10:15:08 -04001101 vam->retval = ntohl (mp->retval);
1102 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103}
1104
Dave Barach72d72232016-08-04 10:15:08 -04001105static void
1106vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001107{
Dave Barach72d72232016-08-04 10:15:08 -04001108 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001109 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1110 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001111 format_ip4_address, &mp->address,
1112 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001113}
1114
Dave Barach72d72232016-08-04 10:15:08 -04001115static void
1116vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117{
Dave Barach72d72232016-08-04 10:15:08 -04001118 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001119}
1120
John Lo1edfba92016-08-27 01:11:57 -04001121static void
1122vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1123{
1124 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001125 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1126 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001127 format_ip6_address, mp->address,
1128 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1129}
1130
1131static void
1132vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1133{
1134 /* JSON output not supported */
1135}
1136
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001137/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001138 * Special-case: build the bridge domain table, maintain
1139 * the next bd id vbl.
1140 */
1141static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001142 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001143{
Dave Barach72d72232016-08-04 10:15:08 -04001144 vat_main_t *vam = &vat_main;
1145 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146
Dave Barach72d72232016-08-04 10:15:08 -04001147 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1148 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149
Dave Barach72d72232016-08-04 10:15:08 -04001150 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1151 ntohl (mp->bd_id), mp->learn, mp->forward,
1152 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153
Dave Barach72d72232016-08-04 10:15:08 -04001154 if (n_sw_ifs)
1155 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1156 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001157}
1158
1159static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001160 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001161{
Dave Barach72d72232016-08-04 10:15:08 -04001162 vat_main_t *vam = &vat_main;
1163 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001164
Dave Barach72d72232016-08-04 10:15:08 -04001165 if (VAT_JSON_ARRAY != vam->json_tree.type)
1166 {
1167 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1168 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001169 }
Dave Barach72d72232016-08-04 10:15:08 -04001170 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001171
Dave Barach72d72232016-08-04 10:15:08 -04001172 vat_json_init_object (node);
1173 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1174 vat_json_object_add_uint (node, "flood", mp->flood);
1175 vat_json_object_add_uint (node, "forward", mp->forward);
1176 vat_json_object_add_uint (node, "learn", mp->learn);
1177 vat_json_object_add_uint (node, "bvi_sw_if_index",
1178 ntohl (mp->bvi_sw_if_index));
1179 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1180 array = vat_json_object_add (node, "sw_if");
1181 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001182}
1183
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001184/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001185 * Special-case: build the bridge domain sw if table.
1186 */
1187static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001188 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001189{
Dave Barach72d72232016-08-04 10:15:08 -04001190 vat_main_t *vam = &vat_main;
1191 hash_pair_t *p;
1192 u8 *sw_if_name = 0;
1193 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
Dave Barach72d72232016-08-04 10:15:08 -04001195 sw_if_index = ntohl (mp->sw_if_index);
1196 /* *INDENT-OFF* */
1197 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1198 ({
1199 if ((u32) p->value[0] == sw_if_index)
1200 {
1201 sw_if_name = (u8 *)(p->key);
1202 break;
1203 }
1204 }));
1205 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001206
Dave Barach72d72232016-08-04 10:15:08 -04001207 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1208 mp->shg, sw_if_name ? (char *) sw_if_name :
1209 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001210}
1211
1212static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001213 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214{
Dave Barach72d72232016-08-04 10:15:08 -04001215 vat_main_t *vam = &vat_main;
1216 vat_json_node_t *node = NULL;
1217 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218
Dave Barach72d72232016-08-04 10:15:08 -04001219 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1220 ASSERT (vec_len (vam->json_tree.array) >= 1);
1221 last_index = vec_len (vam->json_tree.array) - 1;
1222 node = &vam->json_tree.array[last_index];
1223 node = vat_json_object_get_element (node, "sw_if");
1224 ASSERT (NULL != node);
1225 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001226
Dave Barach72d72232016-08-04 10:15:08 -04001227 vat_json_init_object (node);
1228 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1229 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1230 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001231}
1232
1233static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001234 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001235{
Dave Barach72d72232016-08-04 10:15:08 -04001236 vat_main_t *vam = &vat_main;
1237 i32 retval = ntohl (mp->retval);
1238 if (vam->async_mode)
1239 {
1240 vam->async_errors += (retval < 0);
1241 }
1242 else
1243 {
1244 vam->retval = retval;
1245 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001246 }
1247}
1248
1249static void vl_api_control_ping_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001250 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001251{
Dave Barach72d72232016-08-04 10:15:08 -04001252 vat_main_t *vam = &vat_main;
1253 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001254
Dave Barach72d72232016-08-04 10:15:08 -04001255 if (VAT_JSON_NONE != vam->json_tree.type)
1256 {
1257 vat_json_print (vam->ofp, &vam->json_tree);
1258 vat_json_free (&vam->json_tree);
1259 vam->json_tree.type = VAT_JSON_NONE;
1260 }
1261 else
1262 {
1263 /* just print [] */
1264 vat_json_init_array (&vam->json_tree);
1265 vat_json_print (vam->ofp, &vam->json_tree);
1266 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001267 }
1268
Dave Barach72d72232016-08-04 10:15:08 -04001269 vam->retval = retval;
1270 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271}
1272
Dave Barach72d72232016-08-04 10:15:08 -04001273static void
1274vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001275{
Dave Barach72d72232016-08-04 10:15:08 -04001276 vat_main_t *vam = &vat_main;
1277 i32 retval = ntohl (mp->retval);
1278 if (vam->async_mode)
1279 {
1280 vam->async_errors += (retval < 0);
1281 }
1282 else
1283 {
1284 vam->retval = retval;
1285 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001286 }
1287}
1288
1289static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001290 (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001291{
Dave Barach72d72232016-08-04 10:15:08 -04001292 vat_main_t *vam = &vat_main;
1293 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001294
Dave Barach72d72232016-08-04 10:15:08 -04001295 vat_json_init_object (&node);
1296 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1297 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1298 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299
Dave Barach72d72232016-08-04 10:15:08 -04001300 vat_json_print (vam->ofp, &node);
1301 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001302
Dave Barach72d72232016-08-04 10:15:08 -04001303 vam->retval = ntohl (mp->retval);
1304 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001305}
1306
1307static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001308 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001309{
Dave Barach72d72232016-08-04 10:15:08 -04001310 vat_main_t *vam = &vat_main;
1311 i32 retval = ntohl (mp->retval);
1312 if (vam->async_mode)
1313 {
1314 vam->async_errors += (retval < 0);
1315 }
1316 else
1317 {
1318 vam->retval = retval;
1319 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001320 }
1321}
1322
1323static void vl_api_bridge_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001324 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001325{
Dave Barach72d72232016-08-04 10:15:08 -04001326 vat_main_t *vam = &vat_main;
1327 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328
Dave Barach72d72232016-08-04 10:15:08 -04001329 vat_json_init_object (&node);
1330 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1331 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1332 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001333
Dave Barach72d72232016-08-04 10:15:08 -04001334 vat_json_print (vam->ofp, &node);
1335 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336
Dave Barach72d72232016-08-04 10:15:08 -04001337 vam->retval = ntohl (mp->retval);
1338 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339}
1340
1341static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001342 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001343{
Dave Barach72d72232016-08-04 10:15:08 -04001344 vat_main_t *vam = &vat_main;
1345 i32 retval = ntohl (mp->retval);
1346 if (vam->async_mode)
1347 {
1348 vam->async_errors += (retval < 0);
1349 }
1350 else
1351 {
1352 vam->retval = retval;
1353 vam->sw_if_index = ntohl (mp->sw_if_index);
1354 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001355 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001356
Ed Warnickecb9cada2015-12-08 15:45:58 -07001357}
1358
1359static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001360 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001361{
Dave Barach72d72232016-08-04 10:15:08 -04001362 vat_main_t *vam = &vat_main;
1363 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001364
Dave Barach72d72232016-08-04 10:15:08 -04001365 vat_json_init_object (&node);
1366 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1367 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001368
Dave Barach72d72232016-08-04 10:15:08 -04001369 vat_json_print (vam->ofp, &node);
1370 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001371
Dave Barach72d72232016-08-04 10:15:08 -04001372 vam->retval = ntohl (mp->retval);
1373 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001374
Ed Warnickecb9cada2015-12-08 15:45:58 -07001375}
1376
Dave Barach72d72232016-08-04 10:15:08 -04001377static void
1378vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001379{
Dave Barach72d72232016-08-04 10:15:08 -04001380 vat_main_t *vam = &vat_main;
1381 i32 retval = ntohl (mp->retval);
1382 if (vam->async_mode)
1383 {
1384 vam->async_errors += (retval < 0);
1385 }
1386 else
1387 {
1388 vam->retval = retval;
1389 vam->sw_if_index = ntohl (mp->sw_if_index);
1390 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001391 }
1392}
1393
1394static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001395 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001396{
Dave Barach72d72232016-08-04 10:15:08 -04001397 vat_main_t *vam = &vat_main;
1398 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001399
Dave Barach72d72232016-08-04 10:15:08 -04001400 vat_json_init_object (&node);
1401 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1402 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001403
Dave Barach72d72232016-08-04 10:15:08 -04001404 vat_json_print (vam->ofp, &node);
1405 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001406
Dave Barach72d72232016-08-04 10:15:08 -04001407 vam->retval = ntohl (mp->retval);
1408 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409}
1410
Dave Barach72d72232016-08-04 10:15:08 -04001411static void
1412vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413{
Dave Barach72d72232016-08-04 10:15:08 -04001414 vat_main_t *vam = &vat_main;
1415 i32 retval = ntohl (mp->retval);
1416 if (vam->async_mode)
1417 {
1418 vam->async_errors += (retval < 0);
1419 }
1420 else
1421 {
1422 vam->retval = retval;
1423 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424 }
1425}
1426
1427static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001428 (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001429{
Dave Barach72d72232016-08-04 10:15:08 -04001430 vat_main_t *vam = &vat_main;
1431 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432
Dave Barach72d72232016-08-04 10:15:08 -04001433 vat_json_init_object (&node);
1434 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001435
Dave Barach72d72232016-08-04 10:15:08 -04001436 vat_json_print (vam->ofp, &node);
1437 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438
Dave Barach72d72232016-08-04 10:15:08 -04001439 vam->retval = ntohl (mp->retval);
1440 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001441}
1442
Neale Rannsad422ed2016-11-02 14:20:04 +00001443static void vl_api_mpls_tunnel_add_del_reply_t_handler
1444 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001445{
Dave Barach72d72232016-08-04 10:15:08 -04001446 vat_main_t *vam = &vat_main;
1447 i32 retval = ntohl (mp->retval);
1448 if (vam->async_mode)
1449 {
1450 vam->async_errors += (retval < 0);
1451 }
1452 else
1453 {
1454 vam->retval = retval;
1455 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001456 }
1457}
1458
Neale Rannsad422ed2016-11-02 14:20:04 +00001459static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
1460 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001461{
Dave Barach72d72232016-08-04 10:15:08 -04001462 vat_main_t *vam = &vat_main;
1463 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464
Dave Barach72d72232016-08-04 10:15:08 -04001465 vat_json_init_object (&node);
1466 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1467 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
Neale Rannsad422ed2016-11-02 14:20:04 +00001468 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469
Dave Barach72d72232016-08-04 10:15:08 -04001470 vat_json_print (vam->ofp, &node);
1471 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001472
Dave Barach72d72232016-08-04 10:15:08 -04001473 vam->retval = ntohl (mp->retval);
1474 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001475}
1476
1477static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001478 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001479{
Dave Barach72d72232016-08-04 10:15:08 -04001480 vat_main_t *vam = &vat_main;
1481 i32 retval = ntohl (mp->retval);
1482 if (vam->async_mode)
1483 {
1484 vam->async_errors += (retval < 0);
1485 }
1486 else
1487 {
1488 vam->retval = retval;
1489 vam->sw_if_index = ntohl (mp->sw_if_index);
1490 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001491 }
1492}
1493
1494static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001495 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001496{
Dave Barach72d72232016-08-04 10:15:08 -04001497 vat_main_t *vam = &vat_main;
1498 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001499
Dave Barach72d72232016-08-04 10:15:08 -04001500 vat_json_init_object (&node);
1501 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1502 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001503
Dave Barach72d72232016-08-04 10:15:08 -04001504 vat_json_print (vam->ofp, &node);
1505 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001506
Dave Barach72d72232016-08-04 10:15:08 -04001507 vam->retval = ntohl (mp->retval);
1508 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001509}
1510
Filip Tehlar3a834602016-08-11 12:21:37 +02001511
1512static void vl_api_lisp_add_del_locator_set_reply_t_handler
1513 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1514{
1515 vat_main_t *vam = &vat_main;
1516 i32 retval = ntohl (mp->retval);
1517 if (vam->async_mode)
1518 {
1519 vam->async_errors += (retval < 0);
1520 }
1521 else
1522 {
1523 vam->retval = retval;
1524 vam->result_ready = 1;
1525 }
1526}
1527
1528static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1529 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1530{
1531 vat_main_t *vam = &vat_main;
1532 vat_json_node_t node;
1533
1534 vat_json_init_object (&node);
1535 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1536 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1537
1538 vat_json_print (vam->ofp, &node);
1539 vat_json_free (&node);
1540
1541 vam->retval = ntohl (mp->retval);
1542 vam->result_ready = 1;
1543}
1544
Ed Warnickecb9cada2015-12-08 15:45:58 -07001545static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001546 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001547{
Dave Barach72d72232016-08-04 10:15:08 -04001548 vat_main_t *vam = &vat_main;
1549 i32 retval = ntohl (mp->retval);
1550 if (vam->async_mode)
1551 {
1552 vam->async_errors += (retval < 0);
1553 }
1554 else
1555 {
1556 vam->retval = retval;
1557 vam->sw_if_index = ntohl (mp->sw_if_index);
1558 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001559 }
1560}
1561
1562static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001563 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001564{
Dave Barach72d72232016-08-04 10:15:08 -04001565 vat_main_t *vam = &vat_main;
1566 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001567
Dave Barach72d72232016-08-04 10:15:08 -04001568 vat_json_init_object (&node);
1569 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1570 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001571
Dave Barach72d72232016-08-04 10:15:08 -04001572 vat_json_print (vam->ofp, &node);
1573 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001574
Dave Barach72d72232016-08-04 10:15:08 -04001575 vam->retval = ntohl (mp->retval);
1576 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001577}
1578
Chris Luke27fe48f2016-04-28 13:44:38 -04001579static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001580 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001581{
Dave Barach72d72232016-08-04 10:15:08 -04001582 vat_main_t *vam = &vat_main;
1583 i32 retval = ntohl (mp->retval);
1584 if (vam->async_mode)
1585 {
1586 vam->async_errors += (retval < 0);
1587 }
1588 else
1589 {
1590 vam->retval = retval;
1591 vam->sw_if_index = ntohl (mp->sw_if_index);
1592 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001593 }
1594}
1595
1596static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001597 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001598{
Dave Barach72d72232016-08-04 10:15:08 -04001599 vat_main_t *vam = &vat_main;
1600 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001601
Dave Barach72d72232016-08-04 10:15:08 -04001602 vat_json_init_object (&node);
1603 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1604 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001605
Dave Barach72d72232016-08-04 10:15:08 -04001606 vat_json_print (vam->ofp, &node);
1607 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001608
Dave Barach72d72232016-08-04 10:15:08 -04001609 vam->retval = ntohl (mp->retval);
1610 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001611}
1612
Ed Warnickecb9cada2015-12-08 15:45:58 -07001613static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001614 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001615{
Dave Barach72d72232016-08-04 10:15:08 -04001616 vat_main_t *vam = &vat_main;
1617 i32 retval = ntohl (mp->retval);
1618 if (vam->async_mode)
1619 {
1620 vam->async_errors += (retval < 0);
1621 }
1622 else
1623 {
1624 vam->retval = retval;
1625 vam->sw_if_index = ntohl (mp->sw_if_index);
1626 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001627 }
1628}
1629
1630static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001631 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001632{
Dave Barach72d72232016-08-04 10:15:08 -04001633 vat_main_t *vam = &vat_main;
1634 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001635
Dave Barach72d72232016-08-04 10:15:08 -04001636 vat_json_init_object (&node);
1637 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1638 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639
Dave Barach72d72232016-08-04 10:15:08 -04001640 vat_json_print (vam->ofp, &node);
1641 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001642
Dave Barach72d72232016-08-04 10:15:08 -04001643 vam->retval = ntohl (mp->retval);
1644 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001645}
1646
1647static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001648 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001649{
Dave Barach72d72232016-08-04 10:15:08 -04001650 vat_main_t *vam = &vat_main;
1651 static ip_address_details_t empty_ip_address_details = { {0} };
1652 ip_address_details_t *address = NULL;
1653 ip_details_t *current_ip_details = NULL;
1654 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001655
Dave Barach72d72232016-08-04 10:15:08 -04001656 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001657
Dave Barach72d72232016-08-04 10:15:08 -04001658 if (!details || vam->current_sw_if_index >= vec_len (details)
1659 || !details[vam->current_sw_if_index].present)
1660 {
1661 errmsg ("ip address details arrived but not stored\n");
1662 errmsg ("ip_dump should be called first\n");
1663 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664 }
1665
Dave Barach72d72232016-08-04 10:15:08 -04001666 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001667
1668#define addresses (current_ip_details->addr)
1669
Dave Barach72d72232016-08-04 10:15:08 -04001670 vec_validate_init_empty (addresses, vec_len (addresses),
1671 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672
Dave Barach72d72232016-08-04 10:15:08 -04001673 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001674
Dave Barach72d72232016-08-04 10:15:08 -04001675 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1676 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677#undef addresses
1678}
1679
1680static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001681 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001682{
Dave Barach72d72232016-08-04 10:15:08 -04001683 vat_main_t *vam = &vat_main;
1684 vat_json_node_t *node = NULL;
1685 struct in6_addr ip6;
1686 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barach72d72232016-08-04 10:15:08 -04001688 if (VAT_JSON_ARRAY != vam->json_tree.type)
1689 {
1690 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1691 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001692 }
Dave Barach72d72232016-08-04 10:15:08 -04001693 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001694
Dave Barach72d72232016-08-04 10:15:08 -04001695 vat_json_init_object (node);
1696 if (vam->is_ipv6)
1697 {
1698 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1699 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700 }
Dave Barach72d72232016-08-04 10:15:08 -04001701 else
1702 {
1703 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1704 vat_json_object_add_ip4 (node, "ip", ip4);
1705 }
1706 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001707}
1708
Dave Barach72d72232016-08-04 10:15:08 -04001709static void
1710vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001711{
Dave Barach72d72232016-08-04 10:15:08 -04001712 vat_main_t *vam = &vat_main;
1713 static ip_details_t empty_ip_details = { 0 };
1714 ip_details_t *ip = NULL;
1715 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001716
Dave Barach72d72232016-08-04 10:15:08 -04001717 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001718
Dave Barach72d72232016-08-04 10:15:08 -04001719 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1720 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001721
Dave Barach72d72232016-08-04 10:15:08 -04001722 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1723 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001724
Dave Barach72d72232016-08-04 10:15:08 -04001725 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001726}
1727
Dave Barach72d72232016-08-04 10:15:08 -04001728static void
1729vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001730{
Dave Barach72d72232016-08-04 10:15:08 -04001731 vat_main_t *vam = &vat_main;
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 vat_json_array_add_uint (&vam->json_tree,
1739 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001740}
1741
1742static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001743 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001744{
Dave Barach72d72232016-08-04 10:15:08 -04001745 vat_json_node_t *node = NULL;
1746 vat_main_t *vam = &vat_main;
1747 struct in6_addr ip6;
1748 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001749
Dave Barach72d72232016-08-04 10:15:08 -04001750 if (VAT_JSON_ARRAY != vam->json_tree.type)
1751 {
1752 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1753 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001754 }
1755
Dave Barach72d72232016-08-04 10:15:08 -04001756 node = vat_json_array_add (&vam->json_tree);
1757 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001758
Dave Barach72d72232016-08-04 10:15:08 -04001759 vat_json_object_add_uint (node, "domain_index",
1760 clib_net_to_host_u32 (mp->domain_index));
1761 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1762 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1763 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1764 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1765 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1766 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1767 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1768 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1769 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1770 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1771 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1772 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1773 vat_json_object_add_uint (node, "flags", mp->flags);
1774 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1775 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001776}
1777
1778static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001779 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001780{
Dave Barach72d72232016-08-04 10:15:08 -04001781 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001782
Dave Barach72d72232016-08-04 10:15:08 -04001783 if (mp->is_translation)
1784 {
1785 fformat (vam->ofp,
1786 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1787 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1788 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1789 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1790 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001791 }
Dave Barach72d72232016-08-04 10:15:08 -04001792 else
1793 {
1794 fformat (vam->ofp,
1795 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1796 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1797 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1798 format_ip6_address, mp->ip6_src,
1799 clib_net_to_host_u32 (mp->domain_index));
1800 }
1801 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1802 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1803 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001804}
1805
1806static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001807 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001808{
Dave Barach72d72232016-08-04 10:15:08 -04001809 struct in6_addr ip6;
1810 vat_json_node_t *node = NULL;
1811 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001812
Dave Barach72d72232016-08-04 10:15:08 -04001813 if (VAT_JSON_ARRAY != vam->json_tree.type)
1814 {
1815 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1816 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001817 }
1818
Dave Barach72d72232016-08-04 10:15:08 -04001819 node = vat_json_array_add (&vam->json_tree);
1820 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001821
Dave Barach72d72232016-08-04 10:15:08 -04001822 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1823 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1824 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825}
1826
Dave Barach72d72232016-08-04 10:15:08 -04001827static void
1828vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001829{
Dave Barach72d72232016-08-04 10:15:08 -04001830 vat_main_t *vam = &vat_main;
1831 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1832 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833}
1834
Dave Barach72d72232016-08-04 10:15:08 -04001835static void
1836vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001837{
Dave Barach72d72232016-08-04 10:15:08 -04001838 vat_main_t *vam = &vat_main;
1839 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1840 "router_addr %U host_mac %U\n",
1841 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1842 format_ip4_address, &mp->host_address,
1843 format_ip4_address, &mp->router_address,
1844 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845}
1846
1847static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001848 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849{
Dave Barach72d72232016-08-04 10:15:08 -04001850 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001851}
1852
Dave Barach72d72232016-08-04 10:15:08 -04001853static void
1854set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1855 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001856{
Dave Barach72d72232016-08-04 10:15:08 -04001857 vat_main_t *vam = &vat_main;
1858 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001859
Dave Barach72d72232016-08-04 10:15:08 -04001860 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1861 NULL);
1862 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1863 sw_if_index, default_counter);
1864 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001865}
1866
Dave Barach72d72232016-08-04 10:15:08 -04001867static void
1868set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1869 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870{
Dave Barach72d72232016-08-04 10:15:08 -04001871 vat_main_t *vam = &vat_main;
1872 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001873
Dave Barach72d72232016-08-04 10:15:08 -04001874 vec_validate_init_empty (vam->combined_interface_counters,
1875 vnet_counter_type, NULL);
1876 vec_validate_init_empty (vam->combined_interface_counters
1877 [vnet_counter_type], sw_if_index, default_counter);
1878 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001879}
1880
1881static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001882 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001883{
Dave Barach72d72232016-08-04 10:15:08 -04001884 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001885}
1886
1887static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001888 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001889{
Dave Barach72d72232016-08-04 10:15:08 -04001890 interface_counter_t counter;
1891 vlib_counter_t *v;
1892 u64 *v_packets;
1893 u64 packets;
1894 u32 count;
1895 u32 first_sw_if_index;
1896 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001897
Dave Barach72d72232016-08-04 10:15:08 -04001898 count = ntohl (mp->count);
1899 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900
Dave Barach72d72232016-08-04 10:15:08 -04001901 if (!mp->is_combined)
1902 {
1903 v_packets = (u64 *) & mp->data;
1904 for (i = 0; i < count; i++)
1905 {
1906 packets =
1907 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1908 set_simple_interface_counter (mp->vnet_counter_type,
1909 first_sw_if_index + i, packets);
1910 v_packets++;
1911 }
1912 }
1913 else
1914 {
1915 v = (vlib_counter_t *) & mp->data;
1916 for (i = 0; i < count; i++)
1917 {
1918 counter.packets =
1919 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1920 counter.bytes =
1921 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1922 set_combined_interface_counter (mp->vnet_counter_type,
1923 first_sw_if_index + i, counter);
1924 v++;
1925 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001926 }
1927}
1928
Dave Barach72d72232016-08-04 10:15:08 -04001929static u32
1930ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001931{
Dave Barach72d72232016-08-04 10:15:08 -04001932 vat_main_t *vam = &vat_main;
1933 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001934
Dave Barach72d72232016-08-04 10:15:08 -04001935 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1936 {
1937 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1938 {
1939 return i;
1940 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001941 }
Dave Barach72d72232016-08-04 10:15:08 -04001942 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001943}
1944
Dave Barach72d72232016-08-04 10:15:08 -04001945static u32
1946ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001947{
Dave Barach72d72232016-08-04 10:15:08 -04001948 vat_main_t *vam = &vat_main;
1949 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001950
Dave Barach72d72232016-08-04 10:15:08 -04001951 for (i = 0; i < vec_len (vam->ip6_fib_counters_vrf_id_by_index); i++)
1952 {
1953 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id)
1954 {
1955 return i;
1956 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001957 }
Dave Barach72d72232016-08-04 10:15:08 -04001958 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959}
1960
1961static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001962 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001963{
Dave Barach72d72232016-08-04 10:15:08 -04001964 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001965}
1966
1967static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001968 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001969{
Dave Barach72d72232016-08-04 10:15:08 -04001970 vat_main_t *vam = &vat_main;
1971 vl_api_ip4_fib_counter_t *v;
1972 ip4_fib_counter_t *counter;
1973 struct in_addr ip4;
1974 u32 vrf_id;
1975 u32 vrf_index;
1976 u32 count;
1977 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001978
Dave Barach72d72232016-08-04 10:15:08 -04001979 vrf_id = ntohl (mp->vrf_id);
1980 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
1981 if (~0 == vrf_index)
1982 {
1983 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
1984 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1985 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1986 vec_validate (vam->ip4_fib_counters, vrf_index);
1987 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001988 }
1989
Dave Barach72d72232016-08-04 10:15:08 -04001990 vec_free (vam->ip4_fib_counters[vrf_index]);
1991 v = (vl_api_ip4_fib_counter_t *) & mp->c;
1992 count = ntohl (mp->count);
1993 for (i = 0; i < count; i++)
1994 {
1995 vec_validate (vam->ip4_fib_counters[vrf_index], i);
1996 counter = &vam->ip4_fib_counters[vrf_index][i];
1997 clib_memcpy (&ip4, &v->address, sizeof (ip4));
1998 counter->address = ip4;
1999 counter->address_length = v->address_length;
2000 counter->packets = clib_net_to_host_u64 (v->packets);
2001 counter->bytes = clib_net_to_host_u64 (v->bytes);
2002 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002003 }
2004}
2005
2006static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002007 (vl_api_vnet_ip6_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_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002013 (vl_api_vnet_ip6_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_ip6_fib_counter_t *v;
2017 ip6_fib_counter_t *counter;
2018 struct in6_addr ip6;
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 = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2026 if (~0 == vrf_index)
2027 {
2028 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2029 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2030 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2031 vec_validate (vam->ip6_fib_counters, vrf_index);
2032 vam->ip6_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->ip6_fib_counters[vrf_index]);
2036 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2037 count = ntohl (mp->count);
2038 for (i = 0; i < count; i++)
2039 {
2040 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2041 counter = &vam->ip6_fib_counters[vrf_index][i];
2042 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2043 counter->address = ip6;
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_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002052 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053{
Dave Barach72d72232016-08-04 10:15:08 -04002054 vat_main_t *vam = &vat_main;
2055 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002056
Dave Barach72d72232016-08-04 10:15:08 -04002057 if (vam->async_mode)
2058 {
2059 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002060 }
Dave Barach72d72232016-08-04 10:15:08 -04002061 else
2062 {
2063 vam->retval = retval;
2064 vam->result_ready = 1;
2065 }
2066 if (retval >= 0)
2067 {
2068 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002069 }
2070}
2071
2072static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002073 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002074{
Dave Barach72d72232016-08-04 10:15:08 -04002075 vat_main_t *vam = &vat_main;
2076 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002077
Dave Barach72d72232016-08-04 10:15:08 -04002078 vat_json_init_object (&node);
2079 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2080 vat_json_object_add_uint (&node, "first_msg_id",
2081 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002082
Dave Barach72d72232016-08-04 10:15:08 -04002083 vat_json_print (vam->ofp, &node);
2084 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002085
Dave Barach72d72232016-08-04 10:15:08 -04002086 vam->retval = ntohl (mp->retval);
2087 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002088}
2089
Dave Barachb44e9bc2016-02-19 09:06:23 -05002090static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002091 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002092{
Dave Barach72d72232016-08-04 10:15:08 -04002093 vat_main_t *vam = &vat_main;
2094 api_main_t *am = &api_main;
2095 i32 retval = ntohl (mp->retval);
2096 u8 *pvt_copy, *reply;
2097 void *oldheap;
2098 vlib_node_t *node;
2099 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002100
Dave Barach72d72232016-08-04 10:15:08 -04002101 if (vam->async_mode)
2102 {
2103 vam->async_errors += (retval < 0);
2104 }
2105 else
2106 {
2107 vam->retval = retval;
2108 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002109 }
2110
Dave Barach72d72232016-08-04 10:15:08 -04002111 /* "Should never happen..." */
2112 if (retval != 0)
2113 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002114
Dave Barach72d72232016-08-04 10:15:08 -04002115 reply = (u8 *) (mp->reply_in_shmem);
2116 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002117
Dave Barach72d72232016-08-04 10:15:08 -04002118 /* Toss the shared-memory original... */
2119 pthread_mutex_lock (&am->vlib_rp->mutex);
2120 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002121
Dave Barach72d72232016-08-04 10:15:08 -04002122 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002123
Dave Barach72d72232016-08-04 10:15:08 -04002124 svm_pop_heap (oldheap);
2125 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002126
Dave Barach72d72232016-08-04 10:15:08 -04002127 if (vam->graph_nodes)
2128 {
2129 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002130
Dave Barach72d72232016-08-04 10:15:08 -04002131 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2132 {
2133 node = vam->graph_nodes[i];
2134 vec_free (node->name);
2135 vec_free (node->next_nodes);
2136 vec_free (node);
2137 }
2138 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002139 }
2140
Dave Barach72d72232016-08-04 10:15:08 -04002141 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2142 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2143 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002144
Dave Barach72d72232016-08-04 10:15:08 -04002145 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2146 {
2147 node = vam->graph_nodes[i];
2148 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002149 }
2150}
2151
2152static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002153 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002154{
Dave Barach72d72232016-08-04 10:15:08 -04002155 vat_main_t *vam = &vat_main;
2156 api_main_t *am = &api_main;
2157 void *oldheap;
2158 vat_json_node_t node;
2159 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002160
Dave Barach72d72232016-08-04 10:15:08 -04002161 /* $$$$ make this real? */
2162 vat_json_init_object (&node);
2163 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2164 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002165
Dave Barach72d72232016-08-04 10:15:08 -04002166 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002167
Dave Barach72d72232016-08-04 10:15:08 -04002168 /* Toss the shared-memory original... */
2169 pthread_mutex_lock (&am->vlib_rp->mutex);
2170 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002171
Dave Barach72d72232016-08-04 10:15:08 -04002172 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002173
Dave Barach72d72232016-08-04 10:15:08 -04002174 svm_pop_heap (oldheap);
2175 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002176
Dave Barach72d72232016-08-04 10:15:08 -04002177 vat_json_print (vam->ofp, &node);
2178 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002179
Dave Barach72d72232016-08-04 10:15:08 -04002180 vam->retval = ntohl (mp->retval);
2181 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002182}
2183
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002184static void
Dave Barach72d72232016-08-04 10:15:08 -04002185vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002186{
Dave Barach72d72232016-08-04 10:15:08 -04002187 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002188 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002189
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002190 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002191 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002192 s = format (s, "%=16d%=16d%=16d\n",
2193 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002194 }
2195 else
2196 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002197 s = format (s, "%=16U%=16d%=16d\n",
2198 mp->is_ipv6 ? format_ip6_address :
2199 format_ip4_address,
2200 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002201 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002202
2203 fformat (vam->ofp, "%v", s);
2204 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002205}
2206
2207static void
Dave Barach72d72232016-08-04 10:15:08 -04002208vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2209 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002210{
Dave Barach72d72232016-08-04 10:15:08 -04002211 vat_main_t *vam = &vat_main;
2212 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002213 struct in6_addr ip6;
2214 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002215
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002216 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002217 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002218 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2219 vat_json_init_array (&vam->json_tree);
2220 }
2221 node = vat_json_array_add (&vam->json_tree);
2222 vat_json_init_object (node);
2223
2224 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2225 vat_json_object_add_uint (node, "priority", mp->priority);
2226 vat_json_object_add_uint (node, "weight", mp->weight);
2227
2228 if (mp->local)
2229 vat_json_object_add_uint (node, "sw_if_index",
2230 clib_net_to_host_u32 (mp->sw_if_index));
2231 else
2232 {
2233 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002234 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002235 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2236 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002237 }
2238 else
2239 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002240 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2241 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002242 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002243 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002244}
2245
2246static void
2247vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2248 mp)
2249{
2250 vat_main_t *vam = &vat_main;
2251 u8 *ls_name = 0;
2252
2253 ls_name = format (0, "%s", mp->ls_name);
2254
2255 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2256 ls_name);
2257 vec_free (ls_name);
2258}
2259
2260static void
2261 vl_api_lisp_locator_set_details_t_handler_json
2262 (vl_api_lisp_locator_set_details_t * mp)
2263{
2264 vat_main_t *vam = &vat_main;
2265 vat_json_node_t *node = 0;
2266 u8 *ls_name = 0;
2267
2268 ls_name = format (0, "%s", mp->ls_name);
2269 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002270
Dave Barach72d72232016-08-04 10:15:08 -04002271 if (VAT_JSON_ARRAY != vam->json_tree.type)
2272 {
2273 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2274 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002275 }
Dave Barach72d72232016-08-04 10:15:08 -04002276 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002277
Dave Barach72d72232016-08-04 10:15:08 -04002278 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002279 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2280 vat_json_object_add_uint (node, "ls_index",
2281 clib_net_to_host_u32 (mp->ls_index));
2282 vec_free (ls_name);
2283}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002284
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002285static u8 *
2286format_lisp_flat_eid (u8 * s, va_list * args)
2287{
2288 u32 type = va_arg (*args, u32);
2289 u8 *eid = va_arg (*args, u8 *);
2290 u32 eid_len = va_arg (*args, u32);
2291
2292 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002293 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002294 case 0:
2295 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2296 case 1:
2297 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2298 case 2:
2299 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002300 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002301 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002302}
2303
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002304static u8 *
2305format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002306{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002307 u32 type = va_arg (*args, u32);
2308 u8 *eid = va_arg (*args, u8 *);
2309 u32 eid_len = va_arg (*args, u32);
2310 u8 *seid = va_arg (*args, u8 *);
2311 u32 seid_len = va_arg (*args, u32);
2312 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002313
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002314 if (is_src_dst)
2315 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002316
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002317 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002318
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002319 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002320}
2321
2322static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002323vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2324{
2325 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002326 u8 *s = 0, *eid = 0;
2327
2328 if (~0 == mp->locator_set_index)
2329 s = format (0, "action: %d", mp->action);
2330 else
2331 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2332
2333 eid = format (0, "%U", format_lisp_eid_vat,
2334 mp->eid_type,
2335 mp->eid,
2336 mp->eid_prefix_len,
2337 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2338 vec_add1 (eid, 0);
2339
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002340 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s\n",
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002341 clib_net_to_host_u32 (mp->vni),
2342 eid,
2343 mp->is_local ? "local" : "remote",
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002344 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
2345 clib_net_to_host_u16 (mp->key_id), mp->key);
2346
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002347 vec_free (s);
2348 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002349}
2350
2351static void
Dave Barach72d72232016-08-04 10:15:08 -04002352vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2353 * mp)
2354{
2355 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002356 vat_json_node_t *node = 0;
2357 u8 *eid = 0;
2358
2359 if (VAT_JSON_ARRAY != vam->json_tree.type)
2360 {
2361 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2362 vat_json_init_array (&vam->json_tree);
2363 }
2364 node = vat_json_array_add (&vam->json_tree);
2365
2366 vat_json_init_object (node);
2367 if (~0 == mp->locator_set_index)
2368 vat_json_object_add_uint (node, "action", mp->action);
2369 else
2370 vat_json_object_add_uint (node, "locator_set_index",
2371 clib_net_to_host_u32 (mp->locator_set_index));
2372
2373 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2374 eid = format (0, "%U", format_lisp_eid_vat,
2375 mp->eid_type,
2376 mp->eid,
2377 mp->eid_prefix_len,
2378 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2379 vec_add1 (eid, 0);
2380 vat_json_object_add_string_copy (node, "eid", eid);
2381 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2382 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2383 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002384
2385 if (mp->key_id)
2386 {
2387 vat_json_object_add_uint (node, "key_id",
2388 clib_net_to_host_u16 (mp->key_id));
2389 vat_json_object_add_string_copy (node, "key", mp->key);
2390 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002391 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002392}
2393
2394static void
2395 vl_api_lisp_eid_table_map_details_t_handler
2396 (vl_api_lisp_eid_table_map_details_t * mp)
2397{
2398 vat_main_t *vam = &vat_main;
2399
2400 u8 *line = format (0, "%=10d%=10d",
2401 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002402 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002403 fformat (vam->ofp, "%v\n", line);
2404 vec_free (line);
2405}
2406
2407static void
2408 vl_api_lisp_eid_table_map_details_t_handler_json
2409 (vl_api_lisp_eid_table_map_details_t * mp)
2410{
2411 vat_main_t *vam = &vat_main;
2412 vat_json_node_t *node = NULL;
2413
2414 if (VAT_JSON_ARRAY != vam->json_tree.type)
2415 {
2416 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2417 vat_json_init_array (&vam->json_tree);
2418 }
2419 node = vat_json_array_add (&vam->json_tree);
2420 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002421 vat_json_object_add_uint (node, "dp_table",
2422 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002423 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002424}
2425
Filip Tehlar50a4e142016-08-24 11:28:02 +02002426static void
2427 vl_api_lisp_eid_table_vni_details_t_handler
2428 (vl_api_lisp_eid_table_vni_details_t * mp)
2429{
2430 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002431
Filip Tehlar50a4e142016-08-24 11:28:02 +02002432 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2433 fformat (vam->ofp, "%v\n", line);
2434 vec_free (line);
2435}
2436
2437static void
2438 vl_api_lisp_eid_table_vni_details_t_handler_json
2439 (vl_api_lisp_eid_table_vni_details_t * mp)
2440{
2441 vat_main_t *vam = &vat_main;
2442 vat_json_node_t *node = NULL;
2443
2444 if (VAT_JSON_ARRAY != vam->json_tree.type)
2445 {
2446 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2447 vat_json_init_array (&vam->json_tree);
2448 }
2449 node = vat_json_array_add (&vam->json_tree);
2450 vat_json_init_object (node);
2451 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2452}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002453
2454static u8 *
2455format_decap_next (u8 * s, va_list * args)
2456{
2457 u32 next_index = va_arg (*args, u32);
2458
2459 switch (next_index)
2460 {
2461 case LISP_GPE_INPUT_NEXT_DROP:
2462 return format (s, "drop");
2463 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2464 return format (s, "ip4");
2465 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2466 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002467 default:
2468 return format (s, "unknown %d", next_index);
2469 }
2470 return s;
2471}
2472
2473static void
Dave Barach72d72232016-08-04 10:15:08 -04002474vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2475 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002476{
Dave Barach72d72232016-08-04 10:15:08 -04002477 vat_main_t *vam = &vat_main;
2478 u8 *iid_str;
2479 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002480
Dave Barach72d72232016-08-04 10:15:08 -04002481 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002482
2483#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2484 foreach_lisp_gpe_flag_bit;
2485#undef _
2486
Dave Barach72d72232016-08-04 10:15:08 -04002487 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2488 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2489 mp->tunnels,
2490 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2491 mp->source_ip,
2492 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2493 mp->destination_ip,
2494 ntohl (mp->encap_fib_id),
2495 ntohl (mp->decap_fib_id),
2496 format_decap_next, ntohl (mp->dcap_next),
2497 mp->ver_res >> 6,
2498 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002499
Dave Barach72d72232016-08-04 10:15:08 -04002500 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002501}
2502
2503static void
Dave Barach72d72232016-08-04 10:15:08 -04002504 vl_api_lisp_gpe_tunnel_details_t_handler_json
2505 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002506{
Dave Barach72d72232016-08-04 10:15:08 -04002507 vat_main_t *vam = &vat_main;
2508 vat_json_node_t *node = NULL;
2509 struct in6_addr ip6;
2510 struct in_addr ip4;
2511 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002512
Dave Barach72d72232016-08-04 10:15:08 -04002513 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002514
Dave Barach72d72232016-08-04 10:15:08 -04002515 if (VAT_JSON_ARRAY != vam->json_tree.type)
2516 {
2517 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2518 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002519 }
Dave Barach72d72232016-08-04 10:15:08 -04002520 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002521
Dave Barach72d72232016-08-04 10:15:08 -04002522 vat_json_init_object (node);
2523 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2524 if (mp->is_ipv6)
2525 {
2526 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2527 vat_json_object_add_ip6 (node, "source address", ip6);
2528 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2529 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002530 }
Dave Barach72d72232016-08-04 10:15:08 -04002531 else
2532 {
2533 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2534 vat_json_object_add_ip4 (node, "source address", ip4);
2535 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2536 vat_json_object_add_ip4 (node, "destination address", ip4);
2537 }
2538 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2539 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2540 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2541 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2542 vat_json_object_add_uint (node, "flags", mp->flags);
2543 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2544 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2545 vat_json_object_add_uint (node, "res", mp->res);
2546 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002547
Dave Barach72d72232016-08-04 10:15:08 -04002548 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002549}
2550
2551static void
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002552 vl_api_show_lisp_map_register_state_reply_t_handler
2553 (vl_api_show_lisp_map_register_state_reply_t * mp)
2554{
2555 vat_main_t *vam = &vat_main;
2556 int retval = clib_net_to_host_u32 (mp->retval);
2557
2558 fformat (vam->ofp, "%s\n", mp->is_enabled ? "enabled" : "disabled");
2559
2560 vam->retval = retval;
2561 vam->result_ready = 1;
2562}
2563
2564static void
2565 vl_api_show_lisp_map_register_state_reply_t_handler_json
2566 (vl_api_show_lisp_map_register_state_reply_t * mp)
2567{
2568 vat_main_t *vam = &vat_main;
2569 vat_json_node_t _node, *node = &_node;
2570 int retval = clib_net_to_host_u32 (mp->retval);
2571
2572 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
2573
2574 vat_json_init_object (node);
2575 vat_json_object_add_string_copy (node, "state", s);
2576
2577 vat_json_print (vam->ofp, node);
2578 vat_json_free (node);
2579
2580 vam->retval = retval;
2581 vam->result_ready = 1;
2582 vec_free (s);
2583}
2584
2585static void
2586 vl_api_show_lisp_rloc_probe_state_reply_t_handler
2587 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
2588{
2589 vat_main_t *vam = &vat_main;
2590 int retval = clib_net_to_host_u32 (mp->retval);
2591
2592 if (retval)
2593 goto end;
2594
2595 fformat (vam->ofp, "%s\n", mp->is_enabled ? "enabled" : "disabled");
2596end:
2597 vam->retval = retval;
2598 vam->result_ready = 1;
2599}
2600
2601static void
2602 vl_api_show_lisp_rloc_probe_state_reply_t_handler_json
2603 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
2604{
2605 vat_main_t *vam = &vat_main;
2606 vat_json_node_t _node, *node = &_node;
2607 int retval = clib_net_to_host_u32 (mp->retval);
2608
2609 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
2610 vat_json_init_object (node);
2611 vat_json_object_add_string_copy (node, "state", s);
2612
2613 vat_json_print (vam->ofp, node);
2614 vat_json_free (node);
2615
2616 vam->retval = retval;
2617 vam->result_ready = 1;
2618 vec_free (s);
2619}
2620
2621static void
Filip Tehlar69a9b762016-09-23 10:00:52 +02002622 vl_api_lisp_adjacencies_get_reply_t_handler
2623 (vl_api_lisp_adjacencies_get_reply_t * mp)
2624{
2625 vat_main_t *vam = &vat_main;
2626 u32 i, n;
2627 int retval = clib_net_to_host_u32 (mp->retval);
2628 vl_api_lisp_adjacency_t *a;
2629
2630 if (retval)
2631 goto end;
2632
2633 n = clib_net_to_host_u32 (mp->count);
2634
2635 for (i = 0; i < n; i++)
2636 {
2637 a = &mp->adjacencies[i];
2638 fformat (vam->ofp, "%U %40U\n",
2639 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
2640 format_lisp_flat_eid, a->eid_type, a->reid,
2641 a->reid_prefix_len);
2642 }
2643
2644end:
2645 vam->retval = retval;
2646 vam->result_ready = 1;
2647}
2648
2649static void
2650 vl_api_lisp_adjacencies_get_reply_t_handler_json
2651 (vl_api_lisp_adjacencies_get_reply_t * mp)
2652{
2653 u8 *s = 0;
2654 vat_main_t *vam = &vat_main;
2655 vat_json_node_t *e = 0, root;
2656 u32 i, n;
2657 int retval = clib_net_to_host_u32 (mp->retval);
2658 vl_api_lisp_adjacency_t *a;
2659
2660 if (retval)
2661 goto end;
2662
2663 n = clib_net_to_host_u32 (mp->count);
2664 vat_json_init_array (&root);
2665
2666 for (i = 0; i < n; i++)
2667 {
2668 e = vat_json_array_add (&root);
2669 a = &mp->adjacencies[i];
2670
2671 vat_json_init_object (e);
2672 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
2673 a->leid_prefix_len);
2674 vec_add1 (s, 0);
2675 vat_json_object_add_string_copy (e, "leid", s);
2676 vec_free (s);
2677
2678 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
2679 a->reid_prefix_len);
2680 vec_add1 (s, 0);
2681 vat_json_object_add_string_copy (e, "reid", s);
2682 vec_free (s);
2683 }
2684
2685 vat_json_print (vam->ofp, &root);
2686 vat_json_free (&root);
2687
2688end:
2689 vam->retval = retval;
2690 vam->result_ready = 1;
2691}
2692
2693static void
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002694vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t
2695 * mp)
2696{
2697 vat_main_t *vam = &vat_main;
2698
2699 fformat (vam->ofp, "%=20U\n",
2700 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2701 mp->ip_address);
2702}
2703
2704static void
2705 vl_api_lisp_map_server_details_t_handler_json
2706 (vl_api_lisp_map_server_details_t * mp)
2707{
2708 vat_main_t *vam = &vat_main;
2709 vat_json_node_t *node = NULL;
2710 struct in6_addr ip6;
2711 struct in_addr ip4;
2712
2713 if (VAT_JSON_ARRAY != vam->json_tree.type)
2714 {
2715 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2716 vat_json_init_array (&vam->json_tree);
2717 }
2718 node = vat_json_array_add (&vam->json_tree);
2719
2720 vat_json_init_object (node);
2721 if (mp->is_ipv6)
2722 {
2723 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2724 vat_json_object_add_ip6 (node, "map-server", ip6);
2725 }
2726 else
2727 {
2728 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2729 vat_json_object_add_ip4 (node, "map-server", ip4);
2730 }
2731}
2732
2733static void
Dave Barach72d72232016-08-04 10:15:08 -04002734vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2735 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002736{
Dave Barach72d72232016-08-04 10:15:08 -04002737 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002738
Dave Barach72d72232016-08-04 10:15:08 -04002739 fformat (vam->ofp, "%=20U\n",
2740 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2741 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002742}
2743
2744static void
Dave Barach72d72232016-08-04 10:15:08 -04002745 vl_api_lisp_map_resolver_details_t_handler_json
2746 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002747{
Dave Barach72d72232016-08-04 10:15:08 -04002748 vat_main_t *vam = &vat_main;
2749 vat_json_node_t *node = NULL;
2750 struct in6_addr ip6;
2751 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002752
Dave Barach72d72232016-08-04 10:15:08 -04002753 if (VAT_JSON_ARRAY != vam->json_tree.type)
2754 {
2755 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2756 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002757 }
Dave Barach72d72232016-08-04 10:15:08 -04002758 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002759
Dave Barach72d72232016-08-04 10:15:08 -04002760 vat_json_init_object (node);
2761 if (mp->is_ipv6)
2762 {
2763 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2764 vat_json_object_add_ip6 (node, "map resolver", ip6);
2765 }
2766 else
2767 {
2768 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2769 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002770 }
2771}
2772
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002773static void
Dave Barach72d72232016-08-04 10:15:08 -04002774 vl_api_show_lisp_status_reply_t_handler
2775 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002776{
Dave Barach72d72232016-08-04 10:15:08 -04002777 vat_main_t *vam = &vat_main;
2778 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002779
Dave Barach72d72232016-08-04 10:15:08 -04002780 if (0 <= retval)
2781 {
2782 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2783 mp->feature_status ? "enabled" : "disabled",
2784 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002785 }
2786
Dave Barach72d72232016-08-04 10:15:08 -04002787 vam->retval = retval;
2788 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002789}
2790
2791static void
Dave Barach72d72232016-08-04 10:15:08 -04002792 vl_api_show_lisp_status_reply_t_handler_json
2793 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002794{
Dave Barach72d72232016-08-04 10:15:08 -04002795 vat_main_t *vam = &vat_main;
2796 vat_json_node_t node;
2797 u8 *gpe_status = NULL;
2798 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002799
Dave Barach72d72232016-08-04 10:15:08 -04002800 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2801 feature_status = format (0, "%s",
2802 mp->feature_status ? "enabled" : "disabled");
2803 vec_add1 (gpe_status, 0);
2804 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002805
Dave Barach72d72232016-08-04 10:15:08 -04002806 vat_json_init_object (&node);
2807 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2808 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002809
Dave Barach72d72232016-08-04 10:15:08 -04002810 vec_free (gpe_status);
2811 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002812
Dave Barach72d72232016-08-04 10:15:08 -04002813 vat_json_print (vam->ofp, &node);
2814 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002815
Dave Barach72d72232016-08-04 10:15:08 -04002816 vam->retval = ntohl (mp->retval);
2817 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002818}
2819
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002820static void
Dave Barach72d72232016-08-04 10:15:08 -04002821 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2822 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002823{
Dave Barach72d72232016-08-04 10:15:08 -04002824 vat_main_t *vam = &vat_main;
2825 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002826
Dave Barach72d72232016-08-04 10:15:08 -04002827 if (retval >= 0)
2828 {
2829 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002830 }
2831
Dave Barach72d72232016-08-04 10:15:08 -04002832 vam->retval = retval;
2833 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002834}
2835
2836static void
Dave Barach72d72232016-08-04 10:15:08 -04002837 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2838 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002839{
Dave Barach72d72232016-08-04 10:15:08 -04002840 vat_main_t *vam = &vat_main;
2841 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002842
Dave Barach72d72232016-08-04 10:15:08 -04002843 if (VAT_JSON_ARRAY != vam->json_tree.type)
2844 {
2845 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2846 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002847 }
Dave Barach72d72232016-08-04 10:15:08 -04002848 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002849
Dave Barach72d72232016-08-04 10:15:08 -04002850 vat_json_init_object (node);
2851 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002852
Dave Barach72d72232016-08-04 10:15:08 -04002853 vat_json_print (vam->ofp, node);
2854 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002855
Dave Barach72d72232016-08-04 10:15:08 -04002856 vam->retval = ntohl (mp->retval);
2857 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002858}
2859
Florin Corasdca88042016-09-14 16:01:38 +02002860static u8 *
2861format_lisp_map_request_mode (u8 * s, va_list * args)
2862{
2863 u32 mode = va_arg (*args, u32);
2864
2865 switch (mode)
2866 {
2867 case 0:
2868 return format (0, "dst-only");
2869 case 1:
2870 return format (0, "src-dst");
2871 }
2872 return 0;
2873}
2874
2875static void
2876 vl_api_show_lisp_map_request_mode_reply_t_handler
2877 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2878{
2879 vat_main_t *vam = &vat_main;
2880 i32 retval = ntohl (mp->retval);
2881
2882 if (0 <= retval)
2883 {
2884 u32 mode = mp->mode;
2885 fformat (vam->ofp, "map_request_mode: %U\n",
2886 format_lisp_map_request_mode, mode);
2887 }
2888
2889 vam->retval = retval;
2890 vam->result_ready = 1;
2891}
2892
2893static void
2894 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2895 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2896{
2897 vat_main_t *vam = &vat_main;
2898 vat_json_node_t node;
2899 u8 *s = 0;
2900 u32 mode;
2901
2902 mode = mp->mode;
2903 s = format (0, "%U", format_lisp_map_request_mode, mode);
2904 vec_add1 (s, 0);
2905
2906 vat_json_init_object (&node);
2907 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2908 vat_json_print (vam->ofp, &node);
2909 vat_json_free (&node);
2910
2911 vec_free (s);
2912 vam->retval = ntohl (mp->retval);
2913 vam->result_ready = 1;
2914}
2915
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002916static void
2917vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2918{
Dave Barach72d72232016-08-04 10:15:08 -04002919 vat_main_t *vam = &vat_main;
2920 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002921
Dave Barach72d72232016-08-04 10:15:08 -04002922 if (0 <= retval)
2923 {
2924 fformat (vam->ofp, "%-20s%-16s\n",
2925 mp->status ? "enabled" : "disabled",
2926 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002927 }
2928
Dave Barach72d72232016-08-04 10:15:08 -04002929 vam->retval = retval;
2930 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002931}
2932
2933static void
Dave Barach72d72232016-08-04 10:15:08 -04002934vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2935 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002936{
Dave Barach72d72232016-08-04 10:15:08 -04002937 vat_main_t *vam = &vat_main;
2938 vat_json_node_t node;
2939 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002940
Dave Barach72d72232016-08-04 10:15:08 -04002941 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2942 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002943
Dave Barach72d72232016-08-04 10:15:08 -04002944 vat_json_init_object (&node);
2945 vat_json_object_add_string_copy (&node, "status", status);
2946 if (mp->status)
2947 {
2948 vat_json_object_add_string_copy (&node, "locator_set",
2949 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002950 }
2951
Dave Barach72d72232016-08-04 10:15:08 -04002952 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002953
Dave Barach72d72232016-08-04 10:15:08 -04002954 vat_json_print (vam->ofp, &node);
2955 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002956
Dave Barach72d72232016-08-04 10:15:08 -04002957 vam->retval = ntohl (mp->retval);
2958 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002959}
2960
Dave Barach72d72232016-08-04 10:15:08 -04002961static u8 *
2962format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002963{
Dave Barach72d72232016-08-04 10:15:08 -04002964 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002965
Dave Barach72d72232016-08-04 10:15:08 -04002966 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2967 s = format (s, "1r2c");
2968 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2969 s = format (s, "1r3c");
2970 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2971 s = format (s, "2r3c-2698");
2972 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2973 s = format (s, "2r3c-4115");
2974 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2975 s = format (s, "2r3c-mef5cf1");
2976 else
2977 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002978 return s;
2979}
2980
Dave Barach72d72232016-08-04 10:15:08 -04002981static u8 *
2982format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002983{
2984 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002985
Dave Barach72d72232016-08-04 10:15:08 -04002986 if (i == SSE2_QOS_RATE_KBPS)
2987 s = format (s, "kbps");
2988 else if (i == SSE2_QOS_RATE_PPS)
2989 s = format (s, "pps");
2990 else
2991 s = format (s, "ILLEGAL");
2992 return s;
2993}
2994
2995static u8 *
2996format_policer_round_type (u8 * s, va_list * va)
2997{
2998 u32 i = va_arg (*va, u32);
2999
3000 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
3001 s = format (s, "closest");
3002 else if (i == SSE2_QOS_ROUND_TO_UP)
3003 s = format (s, "up");
3004 else if (i == SSE2_QOS_ROUND_TO_DOWN)
3005 s = format (s, "down");
3006 else
3007 s = format (s, "ILLEGAL");
3008 return s;
3009}
3010
3011static u8 *
3012format_policer_action_type (u8 * s, va_list * va)
3013{
3014 u32 i = va_arg (*va, u32);
3015
3016 if (i == SSE2_QOS_ACTION_DROP)
3017 s = format (s, "drop");
3018 else if (i == SSE2_QOS_ACTION_TRANSMIT)
3019 s = format (s, "transmit");
3020 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3021 s = format (s, "mark-and-transmit");
3022 else
3023 s = format (s, "ILLEGAL");
3024 return s;
3025}
3026
3027static u8 *
3028format_dscp (u8 * s, va_list * va)
3029{
3030 u32 i = va_arg (*va, u32);
3031 char *t = 0;
3032
3033 switch (i)
3034 {
3035#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
3036 foreach_vnet_dscp
3037#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07003038 default:
3039 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04003040 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07003041 s = format (s, "%s", t);
3042 return s;
3043}
3044
Dave Barach72d72232016-08-04 10:15:08 -04003045static void
3046vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07003047{
Dave Barach72d72232016-08-04 10:15:08 -04003048 vat_main_t *vam = &vat_main;
3049 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07003050
Dave Barach72d72232016-08-04 10:15:08 -04003051 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3052 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3053 else
3054 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07003055
Dave Barach72d72232016-08-04 10:15:08 -04003056 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3057 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3058 else
3059 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07003060
Dave Barach72d72232016-08-04 10:15:08 -04003061 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3062 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3063 else
3064 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07003065
Dave Barach72d72232016-08-04 10:15:08 -04003066 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
3067 "rate type %U, round type %U, %s rate, %s color-aware, "
3068 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
3069 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
3070 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
3071 mp->name,
3072 format_policer_type, mp->type,
3073 ntohl (mp->cir),
3074 ntohl (mp->eir),
3075 clib_net_to_host_u64 (mp->cb),
3076 clib_net_to_host_u64 (mp->eb),
3077 format_policer_rate_type, mp->rate_type,
3078 format_policer_round_type, mp->round_type,
3079 mp->single_rate ? "single" : "dual",
3080 mp->color_aware ? "is" : "not",
3081 ntohl (mp->cir_tokens_per_period),
3082 ntohl (mp->pir_tokens_per_period),
3083 ntohl (mp->scale),
3084 ntohl (mp->current_limit),
3085 ntohl (mp->current_bucket),
3086 ntohl (mp->extended_limit),
3087 ntohl (mp->extended_bucket),
3088 clib_net_to_host_u64 (mp->last_update_time),
3089 format_policer_action_type, mp->conform_action_type,
3090 conform_dscp_str,
3091 format_policer_action_type, mp->exceed_action_type,
3092 exceed_dscp_str,
3093 format_policer_action_type, mp->violate_action_type,
3094 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07003095
Dave Barach72d72232016-08-04 10:15:08 -04003096 vec_free (conform_dscp_str);
3097 vec_free (exceed_dscp_str);
3098 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07003099}
3100
3101static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003102 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07003103{
Dave Barach72d72232016-08-04 10:15:08 -04003104 vat_main_t *vam = &vat_main;
3105 vat_json_node_t *node;
3106 u8 *rate_type_str, *round_type_str, *type_str;
3107 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07003108
Dave Barach72d72232016-08-04 10:15:08 -04003109 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
3110 round_type_str =
3111 format (0, "%U", format_policer_round_type, mp->round_type);
3112 type_str = format (0, "%U", format_policer_type, mp->type);
3113 conform_action_str = format (0, "%U", format_policer_action_type,
3114 mp->conform_action_type);
3115 exceed_action_str = format (0, "%U", format_policer_action_type,
3116 mp->exceed_action_type);
3117 violate_action_str = format (0, "%U", format_policer_action_type,
3118 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07003119
Dave Barach72d72232016-08-04 10:15:08 -04003120 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003121 {
Dave Barach72d72232016-08-04 10:15:08 -04003122 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3123 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003124 }
Dave Barach72d72232016-08-04 10:15:08 -04003125 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003126
Dave Barach72d72232016-08-04 10:15:08 -04003127 vat_json_init_object (node);
3128 vat_json_object_add_string_copy (node, "name", mp->name);
3129 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
3130 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
3131 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
3132 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
3133 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
3134 vat_json_object_add_string_copy (node, "round_type", round_type_str);
3135 vat_json_object_add_string_copy (node, "type", type_str);
3136 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
3137 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
3138 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
3139 vat_json_object_add_uint (node, "cir_tokens_per_period",
3140 ntohl (mp->cir_tokens_per_period));
3141 vat_json_object_add_uint (node, "eir_tokens_per_period",
3142 ntohl (mp->pir_tokens_per_period));
3143 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
3144 vat_json_object_add_uint (node, "current_bucket",
3145 ntohl (mp->current_bucket));
3146 vat_json_object_add_uint (node, "extended_limit",
3147 ntohl (mp->extended_limit));
3148 vat_json_object_add_uint (node, "extended_bucket",
3149 ntohl (mp->extended_bucket));
3150 vat_json_object_add_uint (node, "last_update_time",
3151 ntohl (mp->last_update_time));
3152 vat_json_object_add_string_copy (node, "conform_action",
3153 conform_action_str);
3154 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3155 {
3156 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3157 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3158 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003159 }
Dave Barach72d72232016-08-04 10:15:08 -04003160 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3161 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3162 {
3163 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3164 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3165 vec_free (dscp_str);
3166 }
3167 vat_json_object_add_string_copy (node, "violate_action",
3168 violate_action_str);
3169 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3170 {
3171 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3172 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3173 vec_free (dscp_str);
3174 }
3175
3176 vec_free (rate_type_str);
3177 vec_free (round_type_str);
3178 vec_free (type_str);
3179 vec_free (conform_action_str);
3180 vec_free (exceed_action_str);
3181 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003182}
3183
Dave Barach72d72232016-08-04 10:15:08 -04003184static void
3185vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3186 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003187{
Dave Barach72d72232016-08-04 10:15:08 -04003188 vat_main_t *vam = &vat_main;
3189 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003190
Dave Barach72d72232016-08-04 10:15:08 -04003191 if (count > 0)
3192 fformat (vam->ofp, "classify table ids (%d) : ", count);
3193 for (i = 0; i < count; i++)
3194 {
3195 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3196 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3197 }
3198 vam->retval = ntohl (mp->retval);
3199 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003200}
3201
Dave Barach72d72232016-08-04 10:15:08 -04003202static void
3203 vl_api_classify_table_ids_reply_t_handler_json
3204 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003205{
Dave Barach72d72232016-08-04 10:15:08 -04003206 vat_main_t *vam = &vat_main;
3207 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003208
Dave Barach72d72232016-08-04 10:15:08 -04003209 if (count > 0)
3210 {
3211 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003212
Dave Barach72d72232016-08-04 10:15:08 -04003213 vat_json_init_object (&node);
3214 for (i = 0; i < count; i++)
3215 {
3216 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3217 }
3218 vat_json_print (vam->ofp, &node);
3219 vat_json_free (&node);
3220 }
3221 vam->retval = ntohl (mp->retval);
3222 vam->result_ready = 1;
3223}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003224
Dave Barach72d72232016-08-04 10:15:08 -04003225static void
3226 vl_api_classify_table_by_interface_reply_t_handler
3227 (vl_api_classify_table_by_interface_reply_t * mp)
3228{
3229 vat_main_t *vam = &vat_main;
3230 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003231
Dave Barach72d72232016-08-04 10:15:08 -04003232 table_id = ntohl (mp->l2_table_id);
3233 if (table_id != ~0)
3234 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3235 else
3236 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3237 table_id = ntohl (mp->ip4_table_id);
3238 if (table_id != ~0)
3239 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3240 else
3241 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3242 table_id = ntohl (mp->ip6_table_id);
3243 if (table_id != ~0)
3244 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3245 else
3246 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3247 vam->retval = ntohl (mp->retval);
3248 vam->result_ready = 1;
3249}
3250
3251static void
3252 vl_api_classify_table_by_interface_reply_t_handler_json
3253 (vl_api_classify_table_by_interface_reply_t * mp)
3254{
3255 vat_main_t *vam = &vat_main;
3256 vat_json_node_t node;
3257
3258 vat_json_init_object (&node);
3259
3260 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3261 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3262 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3263
3264 vat_json_print (vam->ofp, &node);
3265 vat_json_free (&node);
3266
3267 vam->retval = ntohl (mp->retval);
3268 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003269}
3270
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003271static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003272 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003273{
Dave Barach72d72232016-08-04 10:15:08 -04003274 vat_main_t *vam = &vat_main;
3275 i32 retval = ntohl (mp->retval);
3276 if (vam->async_mode)
3277 {
3278 vam->async_errors += (retval < 0);
3279 }
3280 else
3281 {
3282 vam->retval = retval;
3283 vam->result_ready = 1;
3284 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3285 /*
3286 * Note: this is just barely thread-safe, depends on
3287 * the main thread spinning waiting for an answer...
3288 */
3289 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003290 }
3291}
3292
3293static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003294 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003295{
Dave Barach72d72232016-08-04 10:15:08 -04003296 vat_main_t *vam = &vat_main;
3297 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003298
Dave Barach72d72232016-08-04 10:15:08 -04003299 vat_json_init_object (&node);
3300 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3301 vat_json_object_add_uint (&node, "policer_index",
3302 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003303
Dave Barach72d72232016-08-04 10:15:08 -04003304 vat_json_print (vam->ofp, &node);
3305 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003306
Dave Barach72d72232016-08-04 10:15:08 -04003307 vam->retval = ntohl (mp->retval);
3308 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003309}
3310
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003311/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003312u8 *
3313format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003314{
Dave Barach72d72232016-08-04 10:15:08 -04003315 u8 *bytes = va_arg (*va, u8 *);
3316 int n_bytes = va_arg (*va, int);
3317 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003318
Dave Barach72d72232016-08-04 10:15:08 -04003319 /* Print short or long form depending on byte count. */
3320 uword short_form = n_bytes <= 32;
3321 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003322
Dave Barach72d72232016-08-04 10:15:08 -04003323 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003324 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003325
Dave Barach72d72232016-08-04 10:15:08 -04003326 for (i = 0; i < n_bytes; i++)
3327 {
3328 if (!short_form && (i % 32) == 0)
3329 s = format (s, "%08x: ", i);
3330 s = format (s, "%02x", bytes[i]);
3331 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3332 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003333 }
Dave Barach72d72232016-08-04 10:15:08 -04003334
3335 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003336}
3337
Dave Barach72d72232016-08-04 10:15:08 -04003338static void
3339vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3340 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003341{
Dave Barach72d72232016-08-04 10:15:08 -04003342 vat_main_t *vam = &vat_main;
3343 i32 retval = ntohl (mp->retval);
3344 if (retval == 0)
3345 {
3346 fformat (vam->ofp, "classify table info :\n");
3347 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3348 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3349 ntohl (mp->miss_next_index));
3350 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3351 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3352 ntohl (mp->match_n_vectors));
3353 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3354 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003355 }
Dave Barach72d72232016-08-04 10:15:08 -04003356 vam->retval = retval;
3357 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003358}
3359
Dave Barach72d72232016-08-04 10:15:08 -04003360static void
3361 vl_api_classify_table_info_reply_t_handler_json
3362 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003363{
Dave Barach72d72232016-08-04 10:15:08 -04003364 vat_main_t *vam = &vat_main;
3365 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003366
Dave Barach72d72232016-08-04 10:15:08 -04003367 i32 retval = ntohl (mp->retval);
3368 if (retval == 0)
3369 {
3370 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003371
Dave Barach72d72232016-08-04 10:15:08 -04003372 vat_json_object_add_int (&node, "sessions",
3373 ntohl (mp->active_sessions));
3374 vat_json_object_add_int (&node, "nexttbl",
3375 ntohl (mp->next_table_index));
3376 vat_json_object_add_int (&node, "nextnode",
3377 ntohl (mp->miss_next_index));
3378 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3379 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3380 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3381 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3382 ntohl (mp->mask_length), 0);
3383 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003384
Dave Barach72d72232016-08-04 10:15:08 -04003385 vat_json_print (vam->ofp, &node);
3386 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003387 }
Dave Barach72d72232016-08-04 10:15:08 -04003388 vam->retval = ntohl (mp->retval);
3389 vam->result_ready = 1;
3390}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003391
Dave Barach72d72232016-08-04 10:15:08 -04003392static void
3393vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3394 mp)
3395{
3396 vat_main_t *vam = &vat_main;
3397
3398 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3399 ntohl (mp->hit_next_index), ntohl (mp->advance),
3400 ntohl (mp->opaque_index));
3401 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3402 ntohl (mp->match_length));
3403}
3404
3405static void
3406 vl_api_classify_session_details_t_handler_json
3407 (vl_api_classify_session_details_t * mp)
3408{
3409 vat_main_t *vam = &vat_main;
3410 vat_json_node_t *node = NULL;
3411
3412 if (VAT_JSON_ARRAY != vam->json_tree.type)
3413 {
3414 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3415 vat_json_init_array (&vam->json_tree);
3416 }
3417 node = vat_json_array_add (&vam->json_tree);
3418
3419 vat_json_init_object (node);
3420 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3421 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3422 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3423 u8 *s =
3424 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3425 0);
3426 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003427}
Matus Fabiane8554802016-05-18 23:40:37 -07003428
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003429static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003430 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003431{
Dave Barach72d72232016-08-04 10:15:08 -04003432 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003433
Dave Barach72d72232016-08-04 10:15:08 -04003434 vam->retval = ntohl (mp->retval);
3435 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003436}
3437
3438static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003439 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003440{
Dave Barach72d72232016-08-04 10:15:08 -04003441 vat_main_t *vam = &vat_main;
3442 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003443
Dave Barach72d72232016-08-04 10:15:08 -04003444 i32 retval = ntohl (mp->retval);
3445 if (retval == 0)
3446 {
3447 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003448
Dave Barach72d72232016-08-04 10:15:08 -04003449 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003450
Dave Barach72d72232016-08-04 10:15:08 -04003451 vat_json_print (vam->ofp, &node);
3452 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003453 }
Dave Barach72d72232016-08-04 10:15:08 -04003454 vam->retval = ntohl (mp->retval);
3455 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003456}
3457
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003458static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003459 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003460{
Dave Barach72d72232016-08-04 10:15:08 -04003461 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003462
Dave Barach72d72232016-08-04 10:15:08 -04003463 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3464 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003465}
3466
3467static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003468 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003469{
Dave Barach72d72232016-08-04 10:15:08 -04003470 vat_main_t *vam = &vat_main;
3471 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003472
Dave Barach72d72232016-08-04 10:15:08 -04003473 if (VAT_JSON_ARRAY != vam->json_tree.type)
3474 {
3475 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3476 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003477 }
Dave Barach72d72232016-08-04 10:15:08 -04003478 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003479
Dave Barach72d72232016-08-04 10:15:08 -04003480 vat_json_init_object (node);
3481 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3482 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003483}
3484
Matus Fabian694265d2016-08-10 01:55:36 -07003485static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3486 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3487{
3488 vat_main_t *vam = &vat_main;
3489 i32 retval = ntohl (mp->retval);
3490 if (vam->async_mode)
3491 {
3492 vam->async_errors += (retval < 0);
3493 }
3494 else
3495 {
3496 vam->retval = retval;
3497 vam->sw_if_index = ntohl (mp->sw_if_index);
3498 vam->result_ready = 1;
3499 }
3500}
3501
3502static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3503 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3504{
3505 vat_main_t *vam = &vat_main;
3506 vat_json_node_t node;
3507
3508 vat_json_init_object (&node);
3509 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3510 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3511
3512 vat_json_print (vam->ofp, &node);
3513 vat_json_free (&node);
3514
3515 vam->retval = ntohl (mp->retval);
3516 vam->result_ready = 1;
3517}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003518
Juraj Sloboda506b2452016-08-07 23:45:24 -07003519static void vl_api_flow_classify_details_t_handler
3520 (vl_api_flow_classify_details_t * mp)
3521{
3522 vat_main_t *vam = &vat_main;
3523
3524 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3525 ntohl (mp->table_index));
3526}
3527
3528static void vl_api_flow_classify_details_t_handler_json
3529 (vl_api_flow_classify_details_t * mp)
3530{
3531 vat_main_t *vam = &vat_main;
3532 vat_json_node_t *node;
3533
3534 if (VAT_JSON_ARRAY != vam->json_tree.type)
3535 {
3536 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3537 vat_json_init_array (&vam->json_tree);
3538 }
3539 node = vat_json_array_add (&vam->json_tree);
3540
3541 vat_json_init_object (node);
3542 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3543 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3544}
3545
3546
3547
Ed Warnickecb9cada2015-12-08 15:45:58 -07003548#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3549#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3550#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3551#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
Filip Tehlar69a9b762016-09-23 10:00:52 +02003552#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler
3553#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler
Ed Warnickecb9cada2015-12-08 15:45:58 -07003554
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003555/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003556 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003557 * dig the return value out of the xxx_reply_t API message,
3558 * stick it into vam->retval, and set vam->result_ready
3559 *
3560 * Could also do this by pointing N message decode slots at
3561 * a single function, but that could break in subtle ways.
3562 */
3563
3564#define foreach_standard_reply_retval_handler \
3565_(sw_interface_set_flags_reply) \
3566_(sw_interface_add_del_address_reply) \
3567_(sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003568_(sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003569_(sw_interface_set_vpath_reply) \
John Lo37682e12016-11-30 12:51:39 -05003570_(sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003571_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003572_(sw_interface_set_dpdk_hqos_pipe_reply) \
3573_(sw_interface_set_dpdk_hqos_subport_reply) \
3574_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003575_(bridge_domain_add_del_reply) \
3576_(sw_interface_set_l2_xconnect_reply) \
3577_(l2fib_add_del_reply) \
3578_(ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003579_(mpls_route_add_del_reply) \
3580_(mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003581_(proxy_arp_add_del_reply) \
3582_(proxy_arp_intfc_enable_disable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003583_(sw_interface_set_unnumbered_reply) \
3584_(ip_neighbor_add_del_reply) \
3585_(reset_vrf_reply) \
3586_(oam_add_del_reply) \
3587_(reset_fib_reply) \
3588_(dhcp_proxy_config_reply) \
3589_(dhcp_proxy_config_2_reply) \
3590_(dhcp_proxy_set_vss_reply) \
3591_(dhcp_client_config_reply) \
3592_(set_ip_flow_hash_reply) \
3593_(sw_interface_ip6_enable_disable_reply) \
3594_(sw_interface_ip6_set_link_local_address_reply) \
3595_(sw_interface_ip6nd_ra_prefix_reply) \
3596_(sw_interface_ip6nd_ra_config_reply) \
3597_(set_arp_neighbor_limit_reply) \
3598_(l2_patch_add_del_reply) \
3599_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003600_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003601_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003602_(classify_add_del_session_reply) \
3603_(classify_set_interface_ip_table_reply) \
3604_(classify_set_interface_l2_tables_reply) \
3605_(l2tpv3_set_tunnel_cookies_reply) \
3606_(l2tpv3_interface_enable_disable_reply) \
3607_(l2tpv3_set_lookup_key_reply) \
3608_(l2_fib_clear_table_reply) \
3609_(l2_interface_efp_filter_reply) \
3610_(l2_interface_vlan_tag_rewrite_reply) \
3611_(modify_vhost_user_if_reply) \
3612_(delete_vhost_user_if_reply) \
3613_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003614_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003615_(input_acl_set_interface_reply) \
3616_(ipsec_spd_add_del_reply) \
3617_(ipsec_interface_add_del_spd_reply) \
3618_(ipsec_spd_add_del_entry_reply) \
3619_(ipsec_sad_add_del_entry_reply) \
3620_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003621_(ikev2_profile_add_del_reply) \
3622_(ikev2_profile_set_auth_reply) \
3623_(ikev2_profile_set_id_reply) \
3624_(ikev2_profile_set_ts_reply) \
3625_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003626_(delete_loopback_reply) \
3627_(bd_ip_mac_add_del_reply) \
3628_(map_del_domain_reply) \
3629_(map_add_del_rule_reply) \
3630_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003631_(want_stats_reply) \
3632_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003633_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003634_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003635_(ioam_enable_reply) \
3636_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003637_(lisp_add_del_locator_reply) \
3638_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003639_(lisp_add_del_remote_mapping_reply) \
3640_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003641_(lisp_gpe_add_del_fwd_entry_reply) \
3642_(lisp_add_del_map_resolver_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003643_(lisp_add_del_map_server_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003644_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003645_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003646_(lisp_enable_disable_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003647_(lisp_rloc_probe_enable_disable_reply) \
3648_(lisp_map_register_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003649_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003650_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003651_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003652_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003653_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003654_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003655_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003656_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003657_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003658_(set_ipfix_exporter_reply) \
3659_(set_ipfix_classify_stream_reply) \
3660_(ipfix_classify_table_add_del_reply) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003661_(flow_classify_set_interface_reply) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003662_(sw_interface_span_enable_disable_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003663_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003664_(pg_enable_disable_reply) \
3665_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003666_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003667_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003668_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003669_(punt_reply) \
Dave Barach7be864a2016-11-28 11:41:35 -05003670_(feature_enable_disable_reply) \
Matus Fabiand162f3d2016-12-05 01:05:35 -08003671_(sw_interface_tag_add_del_reply) \
3672_(sw_interface_set_mtu_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003673
3674#define _(n) \
3675 static void vl_api_##n##_t_handler \
3676 (vl_api_##n##_t * mp) \
3677 { \
3678 vat_main_t * vam = &vat_main; \
3679 i32 retval = ntohl(mp->retval); \
3680 if (vam->async_mode) { \
3681 vam->async_errors += (retval < 0); \
3682 } else { \
3683 vam->retval = retval; \
3684 vam->result_ready = 1; \
3685 } \
3686 }
3687foreach_standard_reply_retval_handler;
3688#undef _
3689
3690#define _(n) \
3691 static void vl_api_##n##_t_handler_json \
3692 (vl_api_##n##_t * mp) \
3693 { \
3694 vat_main_t * vam = &vat_main; \
3695 vat_json_node_t node; \
3696 vat_json_init_object(&node); \
3697 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3698 vat_json_print(vam->ofp, &node); \
3699 vam->retval = ntohl(mp->retval); \
3700 vam->result_ready = 1; \
3701 }
3702foreach_standard_reply_retval_handler;
3703#undef _
3704
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003705/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003706 * Table of message reply handlers, must include boilerplate handlers
3707 * we just generated
3708 */
3709
3710#define foreach_vpe_api_reply_msg \
3711_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3712_(SW_INTERFACE_DETAILS, sw_interface_details) \
3713_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3714_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3715_(CONTROL_PING_REPLY, control_ping_reply) \
3716_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003717_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003718_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3719 sw_interface_add_del_address_reply) \
3720_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003721_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003722_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
John Lo37682e12016-11-30 12:51:39 -05003723_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003724_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3725 sw_interface_set_l2_xconnect_reply) \
3726_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3727 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003728_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3729 sw_interface_set_dpdk_hqos_pipe_reply) \
3730_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3731 sw_interface_set_dpdk_hqos_subport_reply) \
3732_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3733 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003734_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3735_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3736_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3737_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3738_(L2_FLAGS_REPLY, l2_flags_reply) \
3739_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3740_(TAP_CONNECT_REPLY, tap_connect_reply) \
3741_(TAP_MODIFY_REPLY, tap_modify_reply) \
3742_(TAP_DELETE_REPLY, tap_delete_reply) \
3743_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3744_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003745_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3746_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003747_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3748_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3749 proxy_arp_intfc_enable_disable_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003750_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003751_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3752 sw_interface_set_unnumbered_reply) \
3753_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3754_(RESET_VRF_REPLY, reset_vrf_reply) \
3755_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3756_(CREATE_SUBIF_REPLY, create_subif_reply) \
3757_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3758_(RESET_FIB_REPLY, reset_fib_reply) \
3759_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3760_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3761_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3762_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3763_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3764_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3765 sw_interface_ip6_enable_disable_reply) \
3766_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3767 sw_interface_ip6_set_link_local_address_reply) \
3768_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3769 sw_interface_ip6nd_ra_prefix_reply) \
3770_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3771 sw_interface_ip6nd_ra_config_reply) \
3772_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3773_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3774_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003775_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3776_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003777_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3778_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3779_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3780classify_set_interface_ip_table_reply) \
3781_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3782 classify_set_interface_l2_tables_reply) \
3783_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3784_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3785_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3786_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3787_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3788 l2tpv3_interface_enable_disable_reply) \
3789_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3790_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3791_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003792_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003793_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3794_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003795_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3796_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3797_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3798_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3799_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3800_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3801_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3802_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003803_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003804_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3805_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003806_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3807_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3808_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003809_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3810_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003811_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3812_(IP_ADDRESS_DETAILS, ip_address_details) \
3813_(IP_DETAILS, ip_details) \
3814_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3815_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3816_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3817_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3818_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003819_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3820_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3821_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3822_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3823_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003824_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3825_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3826_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3827_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3828_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3829_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3830_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3831_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003832_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003833_(MAP_DOMAIN_DETAILS, map_domain_details) \
3834_(MAP_RULE_DETAILS, map_rule_details) \
3835_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3836_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003837_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3838_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003839_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003840_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003841_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003842_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3843_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003844_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3845_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3846_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003847_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3848_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003849_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3850_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003851_(LISP_ADD_DEL_MAP_SERVER_REPLY, lisp_add_del_map_server_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003852_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003853_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003854_(LISP_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
3855 lisp_map_register_enable_disable_reply) \
3856_(LISP_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
3857 lisp_rloc_probe_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003858_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003859_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003860_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003861_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3862_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003863_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003864_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003865_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003866_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003867_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003868_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003869_(LISP_MAP_SERVER_DETAILS, lisp_map_server_details) \
Filip Tehlar69a9b762016-09-23 10:00:52 +02003870_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003871_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003872_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3873 lisp_add_del_map_request_itr_rlocs_reply) \
3874_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3875 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003876_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003877_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003878_(SHOW_LISP_RLOC_PROBE_STATE_REPLY, show_lisp_rloc_probe_state_reply) \
3879_(SHOW_LISP_MAP_REGISTER_STATE_REPLY, \
3880 show_lisp_map_register_state_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003881_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003882_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003883_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003884_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003885_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3886_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003887_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003888_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003889_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003890_(MPLS_FIB_DETAILS, mpls_fib_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003891_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3892_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3893_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003894_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003895_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3896_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3897_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3898_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3899_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3900_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003901_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3902_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003903_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3904_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003905_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3906_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3907_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003908_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3909_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3910 ip_source_and_port_range_check_add_del_reply) \
3911_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003912 ip_source_and_port_range_check_interface_add_del_reply) \
3913_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003914_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003915_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003916_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Steven01b07122016-11-02 10:40:09 -07003917_(PUNT_REPLY, punt_reply) \
3918_(IP_FIB_DETAILS, ip_fib_details) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003919_(IP6_FIB_DETAILS, ip6_fib_details) \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +01003920_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
Matus Fabianf468e232016-12-02 06:00:53 -08003921_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +01003922_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3923_(SW_INTERFACE_SET_MTU_REPLY, sw_interface_set_mtu_reply) \
Juraj Slobodadfc19232016-12-05 13:20:37 +01003924_(IP_NEIGHBOR_DETAILS, ip_neighbor_details) \
3925_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003926
3927/* M: construct, but don't yet send a message */
3928
3929#define M(T,t) \
3930do { \
3931 vam->result_ready = 0; \
3932 mp = vl_msg_api_alloc(sizeof(*mp)); \
3933 memset (mp, 0, sizeof (*mp)); \
3934 mp->_vl_msg_id = ntohs (VL_API_##T); \
3935 mp->client_index = vam->my_client_index; \
3936} while(0);
3937
3938#define M2(T,t,n) \
3939do { \
3940 vam->result_ready = 0; \
3941 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3942 memset (mp, 0, sizeof (*mp)); \
3943 mp->_vl_msg_id = ntohs (VL_API_##T); \
3944 mp->client_index = vam->my_client_index; \
3945} while(0);
3946
3947
3948/* S: send a message */
3949#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3950
3951/* W: wait for results, with timeout */
3952#define W \
3953do { \
3954 timeout = vat_time_now (vam) + 1.0; \
3955 \
3956 while (vat_time_now (vam) < timeout) { \
3957 if (vam->result_ready == 1) { \
3958 return (vam->retval); \
3959 } \
3960 } \
3961 return -99; \
3962} while(0);
3963
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003964/* W2: wait for results, with timeout */
3965#define W2(body) \
3966do { \
3967 timeout = vat_time_now (vam) + 1.0; \
3968 \
3969 while (vat_time_now (vam) < timeout) { \
3970 if (vam->result_ready == 1) { \
3971 (body); \
3972 return (vam->retval); \
3973 } \
3974 } \
3975 return -99; \
3976} while(0);
3977
Dave Barach72d72232016-08-04 10:15:08 -04003978typedef struct
3979{
3980 u8 *name;
3981 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003982} name_sort_t;
3983
3984
3985#define STR_VTR_OP_CASE(op) \
3986 case L2_VTR_ ## op: \
3987 return "" # op;
3988
Dave Barach72d72232016-08-04 10:15:08 -04003989static const char *
3990str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003991{
Dave Barach72d72232016-08-04 10:15:08 -04003992 switch (vtr_op)
3993 {
3994 STR_VTR_OP_CASE (DISABLED);
3995 STR_VTR_OP_CASE (PUSH_1);
3996 STR_VTR_OP_CASE (PUSH_2);
3997 STR_VTR_OP_CASE (POP_1);
3998 STR_VTR_OP_CASE (POP_2);
3999 STR_VTR_OP_CASE (TRANSLATE_1_1);
4000 STR_VTR_OP_CASE (TRANSLATE_1_2);
4001 STR_VTR_OP_CASE (TRANSLATE_2_1);
4002 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004003 }
4004
Dave Barach72d72232016-08-04 10:15:08 -04004005 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07004006}
4007
Dave Barach72d72232016-08-04 10:15:08 -04004008static int
4009dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004010{
Dave Barach72d72232016-08-04 10:15:08 -04004011 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004012
Dave Barach72d72232016-08-04 10:15:08 -04004013 if (vam->json_output)
4014 {
4015 clib_warning
4016 ("JSON output supported only for VPE API calls and dump_stats_table");
4017 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004018 }
4019
Dave Barach72d72232016-08-04 10:15:08 -04004020 fformat (vam->ofp,
4021 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
4022 "Interface", "sw_if_index",
4023 "sub id", "dot1ad", "tags", "outer id",
4024 "inner id", "exact", "default", "outer any", "inner any");
4025
4026 vec_foreach (sub, vam->sw_if_subif_table)
4027 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07004028 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004029 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
4030 sub->interface_name,
4031 sub->sw_if_index,
4032 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
4033 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
4034 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
4035 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
4036 if (sub->vtr_op != L2_VTR_DISABLED)
4037 {
4038 fformat (vam->ofp,
4039 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
4040 "tag1: %d tag2: %d ]\n",
4041 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
4042 sub->vtr_tag1, sub->vtr_tag2);
4043 }
4044 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004045
Dave Barach72d72232016-08-04 10:15:08 -04004046 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004047}
4048
Dave Barach72d72232016-08-04 10:15:08 -04004049static int
4050name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004051{
Dave Barach72d72232016-08-04 10:15:08 -04004052 name_sort_t *n1 = a1;
4053 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004054
Dave Barach72d72232016-08-04 10:15:08 -04004055 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004056}
4057
Dave Barach72d72232016-08-04 10:15:08 -04004058static int
4059dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004060{
Dave Barach72d72232016-08-04 10:15:08 -04004061 hash_pair_t *p;
4062 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004063
Dave Barach72d72232016-08-04 10:15:08 -04004064 if (vam->json_output)
4065 {
4066 clib_warning
4067 ("JSON output supported only for VPE API calls and dump_stats_table");
4068 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004069 }
4070
Dave Barach72d72232016-08-04 10:15:08 -04004071 /* *INDENT-OFF* */
4072 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4073 ({
4074 vec_add2 (nses, ns, 1);
4075 ns->name = (u8 *)(p->key);
4076 ns->value = (u32) p->value[0];
4077 }));
4078 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004079
Dave Barach72d72232016-08-04 10:15:08 -04004080 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004081
Dave Barach72d72232016-08-04 10:15:08 -04004082 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
4083 vec_foreach (ns, nses)
4084 {
4085 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
4086 }
4087 vec_free (nses);
4088 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004089}
4090
Dave Barach72d72232016-08-04 10:15:08 -04004091static int
4092dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004093{
Dave Barach72d72232016-08-04 10:15:08 -04004094 const ip_details_t *det = NULL;
4095 const ip_address_details_t *address = NULL;
4096 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004097
Dave Barach72d72232016-08-04 10:15:08 -04004098 fformat (vam->ofp, "%-12s\n", "sw_if_index");
4099
Dave Barach72d72232016-08-04 10:15:08 -04004100 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
4101 {
4102 i++;
4103 if (!det->present)
4104 {
4105 continue;
4106 }
4107 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004108 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004109 " %-30s%-13s\n", "Address", "Prefix length");
4110 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004111 {
Dave Barach72d72232016-08-04 10:15:08 -04004112 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004113 }
Dave Barach72d72232016-08-04 10:15:08 -04004114 vec_foreach (address, det->addr)
4115 {
4116 fformat (vam->ofp,
4117 " %-30U%-13d\n",
4118 is_ipv6 ? format_ip6_address : format_ip4_address,
4119 address->ip, address->prefix_length);
4120 }
4121 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004122
Dave Barach72d72232016-08-04 10:15:08 -04004123 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004124}
4125
Dave Barach72d72232016-08-04 10:15:08 -04004126static int
4127dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004128{
Dave Barach72d72232016-08-04 10:15:08 -04004129 if (vam->json_output)
4130 {
4131 clib_warning
4132 ("JSON output supported only for VPE API calls and dump_stats_table");
4133 return -99;
4134 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004135
Dave Barach72d72232016-08-04 10:15:08 -04004136 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004137}
4138
Dave Barach72d72232016-08-04 10:15:08 -04004139static int
4140dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004141{
Dave Barach72d72232016-08-04 10:15:08 -04004142 if (vam->json_output)
4143 {
4144 clib_warning
4145 ("JSON output supported only for VPE API calls and dump_stats_table");
4146 return -99;
4147 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004148
Dave Barach72d72232016-08-04 10:15:08 -04004149 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004150}
4151
Dave Barach72d72232016-08-04 10:15:08 -04004152static char *
4153counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004154{
Dave Barach72d72232016-08-04 10:15:08 -04004155 if (!is_combined)
4156 {
4157 switch (counter_type)
4158 {
4159 case VNET_INTERFACE_COUNTER_DROP:
4160 return "drop";
4161 case VNET_INTERFACE_COUNTER_PUNT:
4162 return "punt";
4163 case VNET_INTERFACE_COUNTER_IP4:
4164 return "ip4";
4165 case VNET_INTERFACE_COUNTER_IP6:
4166 return "ip6";
4167 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4168 return "rx-no-buf";
4169 case VNET_INTERFACE_COUNTER_RX_MISS:
4170 return "rx-miss";
4171 case VNET_INTERFACE_COUNTER_RX_ERROR:
4172 return "rx-error";
4173 case VNET_INTERFACE_COUNTER_TX_ERROR:
4174 return "tx-error";
4175 default:
4176 return "INVALID-COUNTER-TYPE";
4177 }
4178 }
4179 else
4180 {
4181 switch (counter_type)
4182 {
4183 case VNET_INTERFACE_COUNTER_RX:
4184 return "rx";
4185 case VNET_INTERFACE_COUNTER_TX:
4186 return "tx";
4187 default:
4188 return "INVALID-COUNTER-TYPE";
4189 }
4190 }
4191}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004192
Dave Barach72d72232016-08-04 10:15:08 -04004193static int
4194dump_stats_table (vat_main_t * vam)
4195{
4196 vat_json_node_t node;
4197 vat_json_node_t *msg_array;
4198 vat_json_node_t *msg;
4199 vat_json_node_t *counter_array;
4200 vat_json_node_t *counter;
4201 interface_counter_t c;
4202 u64 packets;
4203 ip4_fib_counter_t *c4;
4204 ip6_fib_counter_t *c6;
4205 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004206
Dave Barach72d72232016-08-04 10:15:08 -04004207 if (!vam->json_output)
4208 {
4209 clib_warning ("dump_stats_table supported only in JSON format");
4210 return -99;
4211 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004212
Dave Barach72d72232016-08-04 10:15:08 -04004213 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004214
Dave Barach72d72232016-08-04 10:15:08 -04004215 /* interface counters */
4216 msg_array = vat_json_object_add (&node, "interface_counters");
4217 vat_json_init_array (msg_array);
4218 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4219 {
4220 msg = vat_json_array_add (msg_array);
4221 vat_json_init_object (msg);
4222 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4223 (u8 *) counter_type_to_str (i, 0));
4224 vat_json_object_add_int (msg, "is_combined", 0);
4225 counter_array = vat_json_object_add (msg, "data");
4226 vat_json_init_array (counter_array);
4227 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4228 {
4229 packets = vam->simple_interface_counters[i][j];
4230 vat_json_array_add_uint (counter_array, packets);
4231 }
4232 }
4233 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4234 {
4235 msg = vat_json_array_add (msg_array);
4236 vat_json_init_object (msg);
4237 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4238 (u8 *) counter_type_to_str (i, 1));
4239 vat_json_object_add_int (msg, "is_combined", 1);
4240 counter_array = vat_json_object_add (msg, "data");
4241 vat_json_init_array (counter_array);
4242 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4243 {
4244 c = vam->combined_interface_counters[i][j];
4245 counter = vat_json_array_add (counter_array);
4246 vat_json_init_object (counter);
4247 vat_json_object_add_uint (counter, "packets", c.packets);
4248 vat_json_object_add_uint (counter, "bytes", c.bytes);
4249 }
4250 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004251
Dave Barach72d72232016-08-04 10:15:08 -04004252 /* ip4 fib counters */
4253 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4254 vat_json_init_array (msg_array);
4255 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4256 {
4257 msg = vat_json_array_add (msg_array);
4258 vat_json_init_object (msg);
4259 vat_json_object_add_uint (msg, "vrf_id",
4260 vam->ip4_fib_counters_vrf_id_by_index[i]);
4261 counter_array = vat_json_object_add (msg, "c");
4262 vat_json_init_array (counter_array);
4263 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4264 {
4265 counter = vat_json_array_add (counter_array);
4266 vat_json_init_object (counter);
4267 c4 = &vam->ip4_fib_counters[i][j];
4268 vat_json_object_add_ip4 (counter, "address", c4->address);
4269 vat_json_object_add_uint (counter, "address_length",
4270 c4->address_length);
4271 vat_json_object_add_uint (counter, "packets", c4->packets);
4272 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4273 }
4274 }
4275
4276 /* ip6 fib counters */
4277 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4278 vat_json_init_array (msg_array);
4279 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4280 {
4281 msg = vat_json_array_add (msg_array);
4282 vat_json_init_object (msg);
4283 vat_json_object_add_uint (msg, "vrf_id",
4284 vam->ip6_fib_counters_vrf_id_by_index[i]);
4285 counter_array = vat_json_object_add (msg, "c");
4286 vat_json_init_array (counter_array);
4287 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4288 {
4289 counter = vat_json_array_add (counter_array);
4290 vat_json_init_object (counter);
4291 c6 = &vam->ip6_fib_counters[i][j];
4292 vat_json_object_add_ip6 (counter, "address", c6->address);
4293 vat_json_object_add_uint (counter, "address_length",
4294 c6->address_length);
4295 vat_json_object_add_uint (counter, "packets", c6->packets);
4296 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4297 }
4298 }
4299
4300 vat_json_print (vam->ofp, &node);
4301 vat_json_free (&node);
4302
4303 return 0;
4304}
4305
4306int
4307exec (vat_main_t * vam)
4308{
4309 api_main_t *am = &api_main;
4310 vl_api_cli_request_t *mp;
4311 f64 timeout;
4312 void *oldheap;
4313 u8 *cmd = 0;
4314 unformat_input_t *i = vam->input;
4315
4316 if (vec_len (i->buffer) == 0)
4317 return -1;
4318
4319 if (vam->exec_mode == 0 && unformat (i, "mode"))
4320 {
4321 vam->exec_mode = 1;
4322 return 0;
4323 }
4324 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4325 {
4326 vam->exec_mode = 0;
4327 return 0;
4328 }
4329
4330
4331 M (CLI_REQUEST, cli_request);
4332
4333 /*
4334 * Copy cmd into shared memory.
4335 * In order for the CLI command to work, it
4336 * must be a vector ending in \n, not a C-string ending
4337 * in \n\0.
4338 */
4339 pthread_mutex_lock (&am->vlib_rp->mutex);
4340 oldheap = svm_push_data_heap (am->vlib_rp);
4341
4342 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4343 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4344
4345 svm_pop_heap (oldheap);
4346 pthread_mutex_unlock (&am->vlib_rp->mutex);
4347
4348 mp->cmd_in_shmem = (u64) cmd;
4349 S;
4350 timeout = vat_time_now (vam) + 10.0;
4351
4352 while (vat_time_now (vam) < timeout)
4353 {
4354 if (vam->result_ready == 1)
4355 {
4356 u8 *free_me;
4357 if (vam->shmem_result != NULL)
4358 fformat (vam->ofp, "%s", vam->shmem_result);
4359 pthread_mutex_lock (&am->vlib_rp->mutex);
4360 oldheap = svm_push_data_heap (am->vlib_rp);
4361
4362 free_me = (u8 *) vam->shmem_result;
4363 vec_free (free_me);
4364
4365 svm_pop_heap (oldheap);
4366 pthread_mutex_unlock (&am->vlib_rp->mutex);
4367 return 0;
4368 }
4369 }
4370 return -99;
4371}
4372
Ole Troanc27213a2016-08-31 14:50:49 +02004373/*
4374 * Future replacement of exec() that passes CLI buffers directly in
4375 * the API messages instead of an additional shared memory area.
4376 */
4377static int
4378exec_inband (vat_main_t * vam)
4379{
4380 vl_api_cli_inband_t *mp;
4381 f64 timeout;
4382 unformat_input_t *i = vam->input;
4383
4384 if (vec_len (i->buffer) == 0)
4385 return -1;
4386
4387 if (vam->exec_mode == 0 && unformat (i, "mode"))
4388 {
4389 vam->exec_mode = 1;
4390 return 0;
4391 }
4392 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4393 {
4394 vam->exec_mode = 0;
4395 return 0;
4396 }
4397
4398 /*
4399 * In order for the CLI command to work, it
4400 * must be a vector ending in \n, not a C-string ending
4401 * in \n\0.
4402 */
4403 u32 len = vec_len (vam->input->buffer);
4404 M2 (CLI_INBAND, cli_inband, len);
4405 clib_memcpy (mp->cmd, vam->input->buffer, len);
4406 mp->length = htonl (len);
4407
4408 S;
4409 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4410}
4411
Dave Barach72d72232016-08-04 10:15:08 -04004412static int
4413api_create_loopback (vat_main_t * vam)
4414{
4415 unformat_input_t *i = vam->input;
4416 vl_api_create_loopback_t *mp;
4417 f64 timeout;
4418 u8 mac_address[6];
4419 u8 mac_set = 0;
4420
4421 memset (mac_address, 0, sizeof (mac_address));
4422
4423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4424 {
4425 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4426 mac_set = 1;
4427 else
4428 break;
4429 }
4430
4431 /* Construct the API message */
4432 M (CREATE_LOOPBACK, create_loopback);
4433 if (mac_set)
4434 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4435
4436 S;
4437 W;
4438}
4439
4440static int
4441api_delete_loopback (vat_main_t * vam)
4442{
4443 unformat_input_t *i = vam->input;
4444 vl_api_delete_loopback_t *mp;
4445 f64 timeout;
4446 u32 sw_if_index = ~0;
4447
4448 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4449 {
4450 if (unformat (i, "sw_if_index %d", &sw_if_index))
4451 ;
4452 else
4453 break;
4454 }
4455
4456 if (sw_if_index == ~0)
4457 {
4458 errmsg ("missing sw_if_index\n");
4459 return -99;
4460 }
4461
4462 /* Construct the API message */
4463 M (DELETE_LOOPBACK, delete_loopback);
4464 mp->sw_if_index = ntohl (sw_if_index);
4465
4466 S;
4467 W;
4468}
4469
4470static int
4471api_want_stats (vat_main_t * vam)
4472{
4473 unformat_input_t *i = vam->input;
4474 vl_api_want_stats_t *mp;
4475 f64 timeout;
4476 int enable = -1;
4477
4478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4479 {
4480 if (unformat (i, "enable"))
4481 enable = 1;
4482 else if (unformat (i, "disable"))
4483 enable = 0;
4484 else
4485 break;
4486 }
4487
4488 if (enable == -1)
4489 {
4490 errmsg ("missing enable|disable\n");
4491 return -99;
4492 }
4493
4494 M (WANT_STATS, want_stats);
4495 mp->enable_disable = enable;
4496
4497 S;
4498 W;
4499}
4500
4501static int
4502api_want_interface_events (vat_main_t * vam)
4503{
4504 unformat_input_t *i = vam->input;
4505 vl_api_want_interface_events_t *mp;
4506 f64 timeout;
4507 int enable = -1;
4508
4509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4510 {
4511 if (unformat (i, "enable"))
4512 enable = 1;
4513 else if (unformat (i, "disable"))
4514 enable = 0;
4515 else
4516 break;
4517 }
4518
4519 if (enable == -1)
4520 {
4521 errmsg ("missing enable|disable\n");
4522 return -99;
4523 }
4524
4525 M (WANT_INTERFACE_EVENTS, want_interface_events);
4526 mp->enable_disable = enable;
4527
4528 vam->interface_event_display = enable;
4529
4530 S;
4531 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004532}
4533
4534
4535/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004536int
4537api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004538{
Dave Barach72d72232016-08-04 10:15:08 -04004539 vl_api_sw_interface_dump_t *mp;
4540 f64 timeout;
4541 hash_pair_t *p;
4542 name_sort_t *nses = 0, *ns;
4543 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004544
Dave Barach72d72232016-08-04 10:15:08 -04004545 /* Toss the old name table */
4546 /* *INDENT-OFF* */
4547 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4548 ({
4549 vec_add2 (nses, ns, 1);
4550 ns->name = (u8 *)(p->key);
4551 ns->value = (u32) p->value[0];
4552 }));
4553 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004554
Dave Barach72d72232016-08-04 10:15:08 -04004555 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004556
Dave Barach72d72232016-08-04 10:15:08 -04004557 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004558
Dave Barach72d72232016-08-04 10:15:08 -04004559 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004560
Dave Barach72d72232016-08-04 10:15:08 -04004561 vec_foreach (sub, vam->sw_if_subif_table)
4562 {
4563 vec_free (sub->interface_name);
4564 }
4565 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004566
Dave Barach72d72232016-08-04 10:15:08 -04004567 /* recreate the interface name hash table */
4568 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004569
Dave Barach72d72232016-08-04 10:15:08 -04004570 /* Get list of ethernets */
4571 M (SW_INTERFACE_DUMP, sw_interface_dump);
4572 mp->name_filter_valid = 1;
4573 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4574 S;
4575
4576 /* and local / loopback interfaces */
4577 M (SW_INTERFACE_DUMP, sw_interface_dump);
4578 mp->name_filter_valid = 1;
4579 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4580 S;
4581
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004582 /* and packet-generator interfaces */
4583 M (SW_INTERFACE_DUMP, sw_interface_dump);
4584 mp->name_filter_valid = 1;
4585 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4586 S;
Dave Barach72d72232016-08-04 10:15:08 -04004587
4588 /* and vxlan-gpe tunnel interfaces */
4589 M (SW_INTERFACE_DUMP, sw_interface_dump);
4590 mp->name_filter_valid = 1;
4591 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4592 sizeof (mp->name_filter) - 1);
4593 S;
4594
4595 /* and vxlan tunnel interfaces */
4596 M (SW_INTERFACE_DUMP, sw_interface_dump);
4597 mp->name_filter_valid = 1;
4598 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4599 S;
4600
4601 /* and host (af_packet) interfaces */
4602 M (SW_INTERFACE_DUMP, sw_interface_dump);
4603 mp->name_filter_valid = 1;
4604 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4605 S;
4606
4607 /* and l2tpv3 tunnel interfaces */
4608 M (SW_INTERFACE_DUMP, sw_interface_dump);
4609 mp->name_filter_valid = 1;
4610 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4611 sizeof (mp->name_filter) - 1);
4612 S;
4613
4614 /* and GRE tunnel interfaces */
4615 M (SW_INTERFACE_DUMP, sw_interface_dump);
4616 mp->name_filter_valid = 1;
4617 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4618 S;
4619
Florin Corasce982752016-09-06 13:36:11 +02004620 /* and LISP-GPE interfaces */
4621 M (SW_INTERFACE_DUMP, sw_interface_dump);
4622 mp->name_filter_valid = 1;
4623 strncpy ((char *) mp->name_filter, "lisp_gpe",
4624 sizeof (mp->name_filter) - 1);
4625 S;
4626
Matus Fabian8fce3e32016-09-06 23:19:43 -07004627 /* and IPSEC tunnel interfaces */
4628 M (SW_INTERFACE_DUMP, sw_interface_dump);
4629 mp->name_filter_valid = 1;
4630 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4631 S;
4632
Dave Barach72d72232016-08-04 10:15:08 -04004633 /* Use a control ping for synchronization */
4634 {
4635 vl_api_control_ping_t *mp;
4636 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004637 S;
Dave Barach72d72232016-08-04 10:15:08 -04004638 }
4639 W;
4640}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004641
Dave Barach72d72232016-08-04 10:15:08 -04004642static int
4643api_sw_interface_set_flags (vat_main_t * vam)
4644{
4645 unformat_input_t *i = vam->input;
4646 vl_api_sw_interface_set_flags_t *mp;
4647 f64 timeout;
4648 u32 sw_if_index;
4649 u8 sw_if_index_set = 0;
4650 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004651
Dave Barach72d72232016-08-04 10:15:08 -04004652 /* Parse args required to build the message */
4653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004654 {
Dave Barach72d72232016-08-04 10:15:08 -04004655 if (unformat (i, "admin-up"))
4656 admin_up = 1;
4657 else if (unformat (i, "admin-down"))
4658 admin_up = 0;
4659 else if (unformat (i, "link-up"))
4660 link_up = 1;
4661 else if (unformat (i, "link-down"))
4662 link_up = 0;
4663 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4664 sw_if_index_set = 1;
4665 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4666 sw_if_index_set = 1;
4667 else
4668 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004669 }
4670
Dave Barach72d72232016-08-04 10:15:08 -04004671 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004672 {
Dave Barach72d72232016-08-04 10:15:08 -04004673 errmsg ("missing interface name or sw_if_index\n");
4674 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004675 }
4676
Dave Barach72d72232016-08-04 10:15:08 -04004677 /* Construct the API message */
4678 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4679 mp->sw_if_index = ntohl (sw_if_index);
4680 mp->admin_up_down = admin_up;
4681 mp->link_up_down = link_up;
4682
4683 /* send it... */
4684 S;
4685
4686 /* Wait for a reply, return the good/bad news... */
4687 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004688}
4689
Dave Barach72d72232016-08-04 10:15:08 -04004690static int
4691api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004692{
Dave Barach72d72232016-08-04 10:15:08 -04004693 unformat_input_t *i = vam->input;
4694 vl_api_sw_interface_clear_stats_t *mp;
4695 f64 timeout;
4696 u32 sw_if_index;
4697 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004698
Dave Barach72d72232016-08-04 10:15:08 -04004699 /* Parse args required to build the message */
4700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4701 {
4702 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4703 sw_if_index_set = 1;
4704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4705 sw_if_index_set = 1;
4706 else
4707 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004708 }
4709
Dave Barach72d72232016-08-04 10:15:08 -04004710 /* Construct the API message */
4711 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004712
Dave Barach72d72232016-08-04 10:15:08 -04004713 if (sw_if_index_set == 1)
4714 mp->sw_if_index = ntohl (sw_if_index);
4715 else
4716 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004717
Dave Barach72d72232016-08-04 10:15:08 -04004718 /* send it... */
4719 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004720
Dave Barach72d72232016-08-04 10:15:08 -04004721 /* Wait for a reply, return the good/bad news... */
4722 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004723}
4724
Dave Barach72d72232016-08-04 10:15:08 -04004725static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004726api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4727{
4728 unformat_input_t *i = vam->input;
4729 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4730 f64 timeout;
4731 u32 sw_if_index;
4732 u8 sw_if_index_set = 0;
4733 u32 subport;
4734 u8 subport_set = 0;
4735 u32 pipe;
4736 u8 pipe_set = 0;
4737 u32 profile;
4738 u8 profile_set = 0;
4739
4740 /* Parse args required to build the message */
4741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4742 {
4743 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4744 sw_if_index_set = 1;
4745 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4746 sw_if_index_set = 1;
4747 else if (unformat (i, "subport %u", &subport))
4748 subport_set = 1;
4749 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4750 sw_if_index_set = 1;
4751 else if (unformat (i, "pipe %u", &pipe))
4752 pipe_set = 1;
4753 else if (unformat (i, "profile %u", &profile))
4754 profile_set = 1;
4755 else
4756 break;
4757 }
4758
4759 if (sw_if_index_set == 0)
4760 {
4761 errmsg ("missing interface name or sw_if_index\n");
4762 return -99;
4763 }
4764
4765 if (subport_set == 0)
4766 {
4767 errmsg ("missing subport \n");
4768 return -99;
4769 }
4770
4771 if (pipe_set == 0)
4772 {
4773 errmsg ("missing pipe\n");
4774 return -99;
4775 }
4776
4777 if (profile_set == 0)
4778 {
4779 errmsg ("missing profile\n");
4780 return -99;
4781 }
4782
4783 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4784
4785 mp->sw_if_index = ntohl (sw_if_index);
4786 mp->subport = ntohl (subport);
4787 mp->pipe = ntohl (pipe);
4788 mp->profile = ntohl (profile);
4789
4790
4791 S;
4792 W;
4793 /* NOTREACHED */
4794 return 0;
4795}
4796
4797static int
4798api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4799{
4800 unformat_input_t *i = vam->input;
4801 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4802 f64 timeout;
4803 u32 sw_if_index;
4804 u8 sw_if_index_set = 0;
4805 u32 subport;
4806 u8 subport_set = 0;
4807 u32 tb_rate = 1250000000; /* 10GbE */
4808 u32 tb_size = 1000000;
4809 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4810 u32 tc_period = 10;
4811
4812 /* Parse args required to build the message */
4813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4814 {
4815 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4816 sw_if_index_set = 1;
4817 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4818 sw_if_index_set = 1;
4819 else if (unformat (i, "subport %u", &subport))
4820 subport_set = 1;
4821 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4822 sw_if_index_set = 1;
4823 else if (unformat (i, "rate %u", &tb_rate))
4824 {
4825 u32 tc_id;
4826
4827 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4828 tc_id++)
4829 tc_rate[tc_id] = tb_rate;
4830 }
4831 else if (unformat (i, "bktsize %u", &tb_size))
4832 ;
4833 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4834 ;
4835 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4836 ;
4837 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4838 ;
4839 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4840 ;
4841 else if (unformat (i, "period %u", &tc_period))
4842 ;
4843 else
4844 break;
4845 }
4846
4847 if (sw_if_index_set == 0)
4848 {
4849 errmsg ("missing interface name or sw_if_index\n");
4850 return -99;
4851 }
4852
4853 if (subport_set == 0)
4854 {
4855 errmsg ("missing subport \n");
4856 return -99;
4857 }
4858
4859 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4860
4861 mp->sw_if_index = ntohl (sw_if_index);
4862 mp->subport = ntohl (subport);
4863 mp->tb_rate = ntohl (tb_rate);
4864 mp->tb_size = ntohl (tb_size);
4865 mp->tc_rate[0] = ntohl (tc_rate[0]);
4866 mp->tc_rate[1] = ntohl (tc_rate[1]);
4867 mp->tc_rate[2] = ntohl (tc_rate[2]);
4868 mp->tc_rate[3] = ntohl (tc_rate[3]);
4869 mp->tc_period = ntohl (tc_period);
4870
4871 S;
4872 W;
4873 /* NOTREACHED */
4874 return 0;
4875}
4876
4877static int
4878api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4879{
4880 unformat_input_t *i = vam->input;
4881 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4882 f64 timeout;
4883 u32 sw_if_index;
4884 u8 sw_if_index_set = 0;
4885 u8 entry_set = 0;
4886 u8 tc_set = 0;
4887 u8 queue_set = 0;
4888 u32 entry, tc, queue;
4889
4890 /* Parse args required to build the message */
4891 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4892 {
4893 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4894 sw_if_index_set = 1;
4895 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4896 sw_if_index_set = 1;
4897 else if (unformat (i, "entry %d", &entry))
4898 entry_set = 1;
4899 else if (unformat (i, "tc %d", &tc))
4900 tc_set = 1;
4901 else if (unformat (i, "queue %d", &queue))
4902 queue_set = 1;
4903 else
4904 break;
4905 }
4906
4907 if (sw_if_index_set == 0)
4908 {
4909 errmsg ("missing interface name or sw_if_index\n");
4910 return -99;
4911 }
4912
4913 if (entry_set == 0)
4914 {
4915 errmsg ("missing entry \n");
4916 return -99;
4917 }
4918
4919 if (tc_set == 0)
4920 {
4921 errmsg ("missing traffic class \n");
4922 return -99;
4923 }
4924
4925 if (queue_set == 0)
4926 {
4927 errmsg ("missing queue \n");
4928 return -99;
4929 }
4930
4931 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4932
4933 mp->sw_if_index = ntohl (sw_if_index);
4934 mp->entry = ntohl (entry);
4935 mp->tc = ntohl (tc);
4936 mp->queue = ntohl (queue);
4937
4938 S;
4939 W;
4940 /* NOTREACHED */
4941 return 0;
4942}
4943
4944static int
Dave Barach72d72232016-08-04 10:15:08 -04004945api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004946{
Dave Barach72d72232016-08-04 10:15:08 -04004947 unformat_input_t *i = vam->input;
4948 vl_api_sw_interface_add_del_address_t *mp;
4949 f64 timeout;
4950 u32 sw_if_index;
4951 u8 sw_if_index_set = 0;
4952 u8 is_add = 1, del_all = 0;
4953 u32 address_length = 0;
4954 u8 v4_address_set = 0;
4955 u8 v6_address_set = 0;
4956 ip4_address_t v4address;
4957 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004958
Dave Barach72d72232016-08-04 10:15:08 -04004959 /* Parse args required to build the message */
4960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4961 {
4962 if (unformat (i, "del-all"))
4963 del_all = 1;
4964 else if (unformat (i, "del"))
4965 is_add = 0;
4966 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4967 sw_if_index_set = 1;
4968 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4969 sw_if_index_set = 1;
4970 else if (unformat (i, "%U/%d",
4971 unformat_ip4_address, &v4address, &address_length))
4972 v4_address_set = 1;
4973 else if (unformat (i, "%U/%d",
4974 unformat_ip6_address, &v6address, &address_length))
4975 v6_address_set = 1;
4976 else
4977 break;
4978 }
4979
4980 if (sw_if_index_set == 0)
4981 {
4982 errmsg ("missing interface name or sw_if_index\n");
4983 return -99;
4984 }
4985 if (v4_address_set && v6_address_set)
4986 {
4987 errmsg ("both v4 and v6 addresses set\n");
4988 return -99;
4989 }
4990 if (!v4_address_set && !v6_address_set && !del_all)
4991 {
4992 errmsg ("no addresses set\n");
4993 return -99;
4994 }
4995
4996 /* Construct the API message */
4997 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4998
4999 mp->sw_if_index = ntohl (sw_if_index);
5000 mp->is_add = is_add;
5001 mp->del_all = del_all;
5002 if (v6_address_set)
5003 {
5004 mp->is_ipv6 = 1;
5005 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5006 }
5007 else
5008 {
5009 clib_memcpy (mp->address, &v4address, sizeof (v4address));
5010 }
5011 mp->address_length = address_length;
5012
5013 /* send it... */
5014 S;
5015
5016 /* Wait for a reply, return good/bad news */
5017 W;
5018}
5019
5020static int
John Lo06b14b92016-10-24 20:20:11 -04005021api_sw_interface_set_mpls_enable (vat_main_t * vam)
5022{
5023 unformat_input_t *i = vam->input;
5024 vl_api_sw_interface_set_mpls_enable_t *mp;
5025 f64 timeout;
5026 u32 sw_if_index;
5027 u8 sw_if_index_set = 0;
5028 u8 enable = 1;
5029
5030 /* Parse args required to build the message */
5031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5032 {
5033 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5034 sw_if_index_set = 1;
5035 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5036 sw_if_index_set = 1;
5037 else if (unformat (i, "disable"))
5038 enable = 0;
5039 else if (unformat (i, "dis"))
5040 enable = 0;
5041 else
5042 break;
5043 }
5044
5045 if (sw_if_index_set == 0)
5046 {
5047 errmsg ("missing interface name or sw_if_index\n");
5048 return -99;
5049 }
5050
5051 /* Construct the API message */
5052 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
5053
5054 mp->sw_if_index = ntohl (sw_if_index);
5055 mp->enable = enable;
5056
5057 /* send it... */
5058 S;
5059
5060 /* Wait for a reply... */
5061 W;
5062}
5063
5064static int
Dave Barach72d72232016-08-04 10:15:08 -04005065api_sw_interface_set_table (vat_main_t * vam)
5066{
5067 unformat_input_t *i = vam->input;
5068 vl_api_sw_interface_set_table_t *mp;
5069 f64 timeout;
5070 u32 sw_if_index, vrf_id = 0;
5071 u8 sw_if_index_set = 0;
5072 u8 is_ipv6 = 0;
5073
5074 /* Parse args required to build the message */
5075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5076 {
5077 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5078 sw_if_index_set = 1;
5079 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5080 sw_if_index_set = 1;
5081 else if (unformat (i, "vrf %d", &vrf_id))
5082 ;
5083 else if (unformat (i, "ipv6"))
5084 is_ipv6 = 1;
5085 else
5086 break;
5087 }
5088
5089 if (sw_if_index_set == 0)
5090 {
5091 errmsg ("missing interface name or sw_if_index\n");
5092 return -99;
5093 }
5094
5095 /* Construct the API message */
5096 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
5097
5098 mp->sw_if_index = ntohl (sw_if_index);
5099 mp->is_ipv6 = is_ipv6;
5100 mp->vrf_id = ntohl (vrf_id);
5101
5102 /* send it... */
5103 S;
5104
5105 /* Wait for a reply... */
5106 W;
5107}
5108
Juraj Slobodadfc19232016-12-05 13:20:37 +01005109static void vl_api_sw_interface_get_table_reply_t_handler
5110 (vl_api_sw_interface_get_table_reply_t * mp)
5111{
5112 vat_main_t *vam = &vat_main;
5113
5114 fformat (vam->ofp, "%d\n", ntohl (mp->vrf_id));
5115
5116 vam->retval = ntohl (mp->retval);
5117 vam->result_ready = 1;
5118
5119}
5120
5121static void vl_api_sw_interface_get_table_reply_t_handler_json
5122 (vl_api_sw_interface_get_table_reply_t * mp)
5123{
5124 vat_main_t *vam = &vat_main;
5125 vat_json_node_t node;
5126
5127 vat_json_init_object (&node);
5128 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
5129 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
5130
5131 vat_json_print (vam->ofp, &node);
5132 vat_json_free (&node);
5133
5134 vam->retval = ntohl (mp->retval);
5135 vam->result_ready = 1;
5136}
5137
5138static int
5139api_sw_interface_get_table (vat_main_t * vam)
5140{
5141 unformat_input_t *i = vam->input;
5142 vl_api_sw_interface_get_table_t *mp;
5143 u32 sw_if_index;
5144 u8 sw_if_index_set = 0;
5145 u8 is_ipv6 = 0;
5146 f64 timeout;
5147
5148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5149 {
5150 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5151 sw_if_index_set = 1;
5152 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5153 sw_if_index_set = 1;
5154 else if (unformat (i, "ipv6"))
5155 is_ipv6 = 1;
5156 else
5157 break;
5158 }
5159
5160 if (sw_if_index_set == 0)
5161 {
5162 errmsg ("missing interface name or sw_if_index\n");
5163 return -99;
5164 }
5165
5166 M (SW_INTERFACE_GET_TABLE, sw_interface_get_table);
5167 mp->sw_if_index = htonl (sw_if_index);
5168 mp->is_ipv6 = is_ipv6;
5169
5170 S;
5171 W;
5172}
5173
Dave Barach72d72232016-08-04 10:15:08 -04005174static int
5175api_sw_interface_set_vpath (vat_main_t * vam)
5176{
5177 unformat_input_t *i = vam->input;
5178 vl_api_sw_interface_set_vpath_t *mp;
5179 f64 timeout;
5180 u32 sw_if_index = 0;
5181 u8 sw_if_index_set = 0;
5182 u8 is_enable = 0;
5183
5184 /* Parse args required to build the message */
5185 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5186 {
5187 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5188 sw_if_index_set = 1;
5189 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5190 sw_if_index_set = 1;
5191 else if (unformat (i, "enable"))
5192 is_enable = 1;
5193 else if (unformat (i, "disable"))
5194 is_enable = 0;
5195 else
5196 break;
5197 }
5198
5199 if (sw_if_index_set == 0)
5200 {
5201 errmsg ("missing interface name or sw_if_index\n");
5202 return -99;
5203 }
5204
5205 /* Construct the API message */
5206 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5207
5208 mp->sw_if_index = ntohl (sw_if_index);
5209 mp->enable = is_enable;
5210
5211 /* send it... */
5212 S;
5213
5214 /* Wait for a reply... */
5215 W;
5216}
5217
5218static int
John Lo37682e12016-11-30 12:51:39 -05005219api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
5220{
5221 unformat_input_t *i = vam->input;
5222 vl_api_sw_interface_set_vxlan_bypass_t *mp;
5223 f64 timeout;
5224 u32 sw_if_index = 0;
5225 u8 sw_if_index_set = 0;
5226 u8 is_enable = 0;
5227 u8 is_ipv6 = 0;
5228
5229 /* Parse args required to build the message */
5230 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5231 {
5232 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5233 sw_if_index_set = 1;
5234 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5235 sw_if_index_set = 1;
5236 else if (unformat (i, "enable"))
5237 is_enable = 1;
5238 else if (unformat (i, "disable"))
5239 is_enable = 0;
5240 else if (unformat (i, "ip4"))
5241 is_ipv6 = 0;
5242 else if (unformat (i, "ip6"))
5243 is_ipv6 = 1;
5244 else
5245 break;
5246 }
5247
5248 if (sw_if_index_set == 0)
5249 {
5250 errmsg ("missing interface name or sw_if_index\n");
5251 return -99;
5252 }
5253
5254 /* Construct the API message */
5255 M (SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass);
5256
5257 mp->sw_if_index = ntohl (sw_if_index);
5258 mp->enable = is_enable;
5259 mp->is_ipv6 = is_ipv6;
5260
5261 /* send it... */
5262 S;
5263
5264 /* Wait for a reply... */
5265 W;
5266}
5267
5268static int
Dave Barach72d72232016-08-04 10:15:08 -04005269api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5270{
5271 unformat_input_t *i = vam->input;
5272 vl_api_sw_interface_set_l2_xconnect_t *mp;
5273 f64 timeout;
5274 u32 rx_sw_if_index;
5275 u8 rx_sw_if_index_set = 0;
5276 u32 tx_sw_if_index;
5277 u8 tx_sw_if_index_set = 0;
5278 u8 enable = 1;
5279
5280 /* Parse args required to build the message */
5281 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5282 {
5283 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5284 rx_sw_if_index_set = 1;
5285 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5286 tx_sw_if_index_set = 1;
5287 else if (unformat (i, "rx"))
5288 {
5289 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5290 {
5291 if (unformat (i, "%U", unformat_sw_if_index, vam,
5292 &rx_sw_if_index))
5293 rx_sw_if_index_set = 1;
5294 }
5295 else
Dave Barach41da02d2016-07-11 16:48:42 -07005296 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005297 }
Dave Barach72d72232016-08-04 10:15:08 -04005298 else if (unformat (i, "tx"))
5299 {
5300 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5301 {
5302 if (unformat (i, "%U", unformat_sw_if_index, vam,
5303 &tx_sw_if_index))
5304 tx_sw_if_index_set = 1;
5305 }
5306 else
5307 break;
5308 }
5309 else if (unformat (i, "enable"))
5310 enable = 1;
5311 else if (unformat (i, "disable"))
5312 enable = 0;
5313 else
5314 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005315 }
5316
Dave Barach72d72232016-08-04 10:15:08 -04005317 if (rx_sw_if_index_set == 0)
5318 {
5319 errmsg ("missing rx interface name or rx_sw_if_index\n");
5320 return -99;
5321 }
Dave Barach41da02d2016-07-11 16:48:42 -07005322
Dave Barach72d72232016-08-04 10:15:08 -04005323 if (enable && (tx_sw_if_index_set == 0))
5324 {
5325 errmsg ("missing tx interface name or tx_sw_if_index\n");
5326 return -99;
5327 }
Dave Barach41da02d2016-07-11 16:48:42 -07005328
Dave Barach72d72232016-08-04 10:15:08 -04005329 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005330
Dave Barach72d72232016-08-04 10:15:08 -04005331 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5332 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5333 mp->enable = enable;
5334
5335 S;
5336 W;
5337 /* NOTREACHED */
5338 return 0;
5339}
5340
5341static int
5342api_sw_interface_set_l2_bridge (vat_main_t * vam)
5343{
5344 unformat_input_t *i = vam->input;
5345 vl_api_sw_interface_set_l2_bridge_t *mp;
5346 f64 timeout;
5347 u32 rx_sw_if_index;
5348 u8 rx_sw_if_index_set = 0;
5349 u32 bd_id;
5350 u8 bd_id_set = 0;
5351 u8 bvi = 0;
5352 u32 shg = 0;
5353 u8 enable = 1;
5354
5355 /* Parse args required to build the message */
5356 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5357 {
5358 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5359 rx_sw_if_index_set = 1;
5360 else if (unformat (i, "bd_id %d", &bd_id))
5361 bd_id_set = 1;
5362 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5363 rx_sw_if_index_set = 1;
5364 else if (unformat (i, "shg %d", &shg))
5365 ;
5366 else if (unformat (i, "bvi"))
5367 bvi = 1;
5368 else if (unformat (i, "enable"))
5369 enable = 1;
5370 else if (unformat (i, "disable"))
5371 enable = 0;
5372 else
5373 break;
5374 }
5375
5376 if (rx_sw_if_index_set == 0)
5377 {
5378 errmsg ("missing rx interface name or sw_if_index\n");
5379 return -99;
5380 }
5381
5382 if (enable && (bd_id_set == 0))
5383 {
5384 errmsg ("missing bridge domain\n");
5385 return -99;
5386 }
5387
5388 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5389
5390 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5391 mp->bd_id = ntohl (bd_id);
5392 mp->shg = (u8) shg;
5393 mp->bvi = bvi;
5394 mp->enable = enable;
5395
5396 S;
5397 W;
5398 /* NOTREACHED */
5399 return 0;
5400}
5401
5402static int
5403api_bridge_domain_dump (vat_main_t * vam)
5404{
5405 unformat_input_t *i = vam->input;
5406 vl_api_bridge_domain_dump_t *mp;
5407 f64 timeout;
5408 u32 bd_id = ~0;
5409
5410 /* Parse args required to build the message */
5411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5412 {
5413 if (unformat (i, "bd_id %d", &bd_id))
5414 ;
5415 else
5416 break;
5417 }
5418
5419 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5420 mp->bd_id = ntohl (bd_id);
5421 S;
5422
5423 /* Use a control ping for synchronization */
5424 {
5425 vl_api_control_ping_t *mp;
5426 M (CONTROL_PING, control_ping);
5427 S;
5428 }
5429
5430 W;
5431 /* NOTREACHED */
5432 return 0;
5433}
5434
5435static int
5436api_bridge_domain_add_del (vat_main_t * vam)
5437{
5438 unformat_input_t *i = vam->input;
5439 vl_api_bridge_domain_add_del_t *mp;
5440 f64 timeout;
5441 u32 bd_id = ~0;
5442 u8 is_add = 1;
5443 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5444
5445 /* Parse args required to build the message */
5446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5447 {
5448 if (unformat (i, "bd_id %d", &bd_id))
5449 ;
5450 else if (unformat (i, "flood %d", &flood))
5451 ;
5452 else if (unformat (i, "uu-flood %d", &uu_flood))
5453 ;
5454 else if (unformat (i, "forward %d", &forward))
5455 ;
5456 else if (unformat (i, "learn %d", &learn))
5457 ;
5458 else if (unformat (i, "arp-term %d", &arp_term))
5459 ;
5460 else if (unformat (i, "del"))
5461 {
5462 is_add = 0;
5463 flood = uu_flood = forward = learn = 0;
5464 }
5465 else
5466 break;
5467 }
5468
5469 if (bd_id == ~0)
5470 {
5471 errmsg ("missing bridge domain\n");
5472 return -99;
5473 }
5474
5475 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5476
5477 mp->bd_id = ntohl (bd_id);
5478 mp->flood = flood;
5479 mp->uu_flood = uu_flood;
5480 mp->forward = forward;
5481 mp->learn = learn;
5482 mp->arp_term = arp_term;
5483 mp->is_add = is_add;
5484
5485 S;
5486 W;
5487 /* NOTREACHED */
5488 return 0;
5489}
5490
5491static int
5492api_l2fib_add_del (vat_main_t * vam)
5493{
5494 unformat_input_t *i = vam->input;
5495 vl_api_l2fib_add_del_t *mp;
5496 f64 timeout;
5497 u64 mac = 0;
5498 u8 mac_set = 0;
5499 u32 bd_id;
5500 u8 bd_id_set = 0;
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005501 u32 sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04005502 u8 sw_if_index_set = 0;
5503 u8 is_add = 1;
5504 u8 static_mac = 0;
5505 u8 filter_mac = 0;
5506 u8 bvi_mac = 0;
5507 int count = 1;
5508 f64 before = 0;
5509 int j;
5510
5511 /* Parse args required to build the message */
5512 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5513 {
5514 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5515 mac_set = 1;
5516 else if (unformat (i, "bd_id %d", &bd_id))
5517 bd_id_set = 1;
5518 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5519 sw_if_index_set = 1;
5520 else if (unformat (i, "sw_if"))
5521 {
5522 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5523 {
5524 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5525 sw_if_index_set = 1;
5526 }
5527 else
5528 break;
5529 }
5530 else if (unformat (i, "static"))
5531 static_mac = 1;
5532 else if (unformat (i, "filter"))
5533 {
5534 filter_mac = 1;
5535 static_mac = 1;
5536 }
5537 else if (unformat (i, "bvi"))
5538 {
5539 bvi_mac = 1;
5540 static_mac = 1;
5541 }
5542 else if (unformat (i, "del"))
5543 is_add = 0;
5544 else if (unformat (i, "count %d", &count))
5545 ;
5546 else
5547 break;
5548 }
5549
5550 if (mac_set == 0)
5551 {
5552 errmsg ("missing mac address\n");
5553 return -99;
5554 }
5555
5556 if (bd_id_set == 0)
5557 {
5558 errmsg ("missing bridge domain\n");
5559 return -99;
5560 }
5561
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005562 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
Dave Barach72d72232016-08-04 10:15:08 -04005563 {
5564 errmsg ("missing interface name or sw_if_index\n");
5565 return -99;
5566 }
5567
5568 if (count > 1)
5569 {
5570 /* Turn on async mode */
5571 vam->async_mode = 1;
5572 vam->async_errors = 0;
5573 before = vat_time_now (vam);
5574 }
5575
5576 for (j = 0; j < count; j++)
5577 {
5578 M (L2FIB_ADD_DEL, l2fib_add_del);
5579
5580 mp->mac = mac;
5581 mp->bd_id = ntohl (bd_id);
5582 mp->is_add = is_add;
5583
5584 if (is_add)
5585 {
5586 mp->sw_if_index = ntohl (sw_if_index);
5587 mp->static_mac = static_mac;
5588 mp->filter_mac = filter_mac;
5589 mp->bvi_mac = bvi_mac;
5590 }
5591 increment_mac_address (&mac);
5592 /* send it... */
5593 S;
5594 }
5595
5596 if (count > 1)
5597 {
5598 vl_api_control_ping_t *mp;
5599 f64 after;
5600
5601 /* Shut off async mode */
5602 vam->async_mode = 0;
5603
5604 M (CONTROL_PING, control_ping);
5605 S;
5606
5607 timeout = vat_time_now (vam) + 1.0;
5608 while (vat_time_now (vam) < timeout)
5609 if (vam->result_ready == 1)
5610 goto out;
5611 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005612
5613 out:
Dave Barach72d72232016-08-04 10:15:08 -04005614 if (vam->retval == -99)
5615 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005616
Dave Barach72d72232016-08-04 10:15:08 -04005617 if (vam->async_errors > 0)
5618 {
5619 errmsg ("%d asynchronous errors\n", vam->async_errors);
5620 vam->retval = -98;
5621 }
5622 vam->async_errors = 0;
5623 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005624
Dave Barach72d72232016-08-04 10:15:08 -04005625 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5626 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005627 }
Dave Barach72d72232016-08-04 10:15:08 -04005628 else
5629 {
5630 /* Wait for a reply... */
5631 W;
5632 }
5633 /* Return the good/bad news */
5634 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005635}
5636
Dave Barach72d72232016-08-04 10:15:08 -04005637static int
5638api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005639{
Dave Barach72d72232016-08-04 10:15:08 -04005640 unformat_input_t *i = vam->input;
5641 vl_api_l2_flags_t *mp;
5642 f64 timeout;
5643 u32 sw_if_index;
5644 u32 feature_bitmap = 0;
5645 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005646
Dave Barach72d72232016-08-04 10:15:08 -04005647 /* Parse args required to build the message */
5648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5649 {
5650 if (unformat (i, "sw_if_index %d", &sw_if_index))
5651 sw_if_index_set = 1;
5652 else if (unformat (i, "sw_if"))
5653 {
5654 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5655 {
5656 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5657 sw_if_index_set = 1;
5658 }
5659 else
5660 break;
5661 }
5662 else if (unformat (i, "learn"))
5663 feature_bitmap |= L2INPUT_FEAT_LEARN;
5664 else if (unformat (i, "forward"))
5665 feature_bitmap |= L2INPUT_FEAT_FWD;
5666 else if (unformat (i, "flood"))
5667 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5668 else if (unformat (i, "uu-flood"))
5669 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5670 else
5671 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005672 }
5673
Dave Barach72d72232016-08-04 10:15:08 -04005674 if (sw_if_index_set == 0)
5675 {
5676 errmsg ("missing interface name or sw_if_index\n");
5677 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005678 }
5679
Dave Barach72d72232016-08-04 10:15:08 -04005680 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005681
Dave Barach72d72232016-08-04 10:15:08 -04005682 mp->sw_if_index = ntohl (sw_if_index);
5683 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005684
Dave Barach72d72232016-08-04 10:15:08 -04005685 S;
5686 W;
5687 /* NOTREACHED */
5688 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005689}
5690
Dave Barach72d72232016-08-04 10:15:08 -04005691static int
5692api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005693{
Dave Barach72d72232016-08-04 10:15:08 -04005694 unformat_input_t *i = vam->input;
5695 vl_api_bridge_flags_t *mp;
5696 f64 timeout;
5697 u32 bd_id;
5698 u8 bd_id_set = 0;
5699 u8 is_set = 1;
5700 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005701
Dave Barach72d72232016-08-04 10:15:08 -04005702 /* Parse args required to build the message */
5703 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5704 {
5705 if (unformat (i, "bd_id %d", &bd_id))
5706 bd_id_set = 1;
5707 else if (unformat (i, "learn"))
5708 flags |= L2_LEARN;
5709 else if (unformat (i, "forward"))
5710 flags |= L2_FWD;
5711 else if (unformat (i, "flood"))
5712 flags |= L2_FLOOD;
5713 else if (unformat (i, "uu-flood"))
5714 flags |= L2_UU_FLOOD;
5715 else if (unformat (i, "arp-term"))
5716 flags |= L2_ARP_TERM;
5717 else if (unformat (i, "off"))
5718 is_set = 0;
5719 else if (unformat (i, "disable"))
5720 is_set = 0;
5721 else
5722 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005723 }
5724
Dave Barach72d72232016-08-04 10:15:08 -04005725 if (bd_id_set == 0)
5726 {
5727 errmsg ("missing bridge domain\n");
5728 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005729 }
5730
Dave Barach72d72232016-08-04 10:15:08 -04005731 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005732
Dave Barach72d72232016-08-04 10:15:08 -04005733 mp->bd_id = ntohl (bd_id);
5734 mp->feature_bitmap = ntohl (flags);
5735 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005736
Dave Barach72d72232016-08-04 10:15:08 -04005737 S;
5738 W;
5739 /* NOTREACHED */
5740 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005741}
5742
Dave Barach72d72232016-08-04 10:15:08 -04005743static int
5744api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005745{
Dave Barach72d72232016-08-04 10:15:08 -04005746 unformat_input_t *i = vam->input;
5747 vl_api_bd_ip_mac_add_del_t *mp;
5748 f64 timeout;
5749 u32 bd_id;
5750 u8 is_ipv6 = 0;
5751 u8 is_add = 1;
5752 u8 bd_id_set = 0;
5753 u8 ip_set = 0;
5754 u8 mac_set = 0;
5755 ip4_address_t v4addr;
5756 ip6_address_t v6addr;
5757 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005758
Ed Warnickecb9cada2015-12-08 15:45:58 -07005759
Dave Barach72d72232016-08-04 10:15:08 -04005760 /* Parse args required to build the message */
5761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5762 {
5763 if (unformat (i, "bd_id %d", &bd_id))
5764 {
5765 bd_id_set++;
5766 }
5767 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5768 {
5769 ip_set++;
5770 }
5771 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5772 {
5773 ip_set++;
5774 is_ipv6++;
5775 }
5776 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5777 {
5778 mac_set++;
5779 }
5780 else if (unformat (i, "del"))
5781 is_add = 0;
5782 else
5783 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005784 }
5785
Dave Barach72d72232016-08-04 10:15:08 -04005786 if (bd_id_set == 0)
5787 {
5788 errmsg ("missing bridge domain\n");
5789 return -99;
5790 }
5791 else if (ip_set == 0)
5792 {
5793 errmsg ("missing IP address\n");
5794 return -99;
5795 }
5796 else if (mac_set == 0)
5797 {
5798 errmsg ("missing MAC address\n");
5799 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005800 }
5801
Dave Barach72d72232016-08-04 10:15:08 -04005802 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005803
Dave Barach72d72232016-08-04 10:15:08 -04005804 mp->bd_id = ntohl (bd_id);
5805 mp->is_ipv6 = is_ipv6;
5806 mp->is_add = is_add;
5807 if (is_ipv6)
5808 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5809 else
5810 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5811 clib_memcpy (mp->mac_address, macaddr, 6);
5812 S;
5813 W;
5814 /* NOTREACHED */
5815 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005816}
5817
Dave Barach72d72232016-08-04 10:15:08 -04005818static int
5819api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005820{
Dave Barach72d72232016-08-04 10:15:08 -04005821 unformat_input_t *i = vam->input;
5822 vl_api_tap_connect_t *mp;
5823 f64 timeout;
5824 u8 mac_address[6];
5825 u8 random_mac = 1;
5826 u8 name_set = 0;
5827 u8 *tap_name;
Dave Barach7be864a2016-11-28 11:41:35 -05005828 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005829
Dave Barach72d72232016-08-04 10:15:08 -04005830 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005831
Dave Barach72d72232016-08-04 10:15:08 -04005832 /* Parse args required to build the message */
5833 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5834 {
5835 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5836 {
5837 random_mac = 0;
5838 }
5839 else if (unformat (i, "random-mac"))
5840 random_mac = 1;
5841 else if (unformat (i, "tapname %s", &tap_name))
5842 name_set = 1;
Dave Barach143faaa2016-12-02 08:43:40 -05005843 else if (unformat (i, "tag %s", &tag))
5844 ;
Dave Barach72d72232016-08-04 10:15:08 -04005845 else
5846 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005847 }
5848
Dave Barach72d72232016-08-04 10:15:08 -04005849 if (name_set == 0)
5850 {
5851 errmsg ("missing tap name\n");
5852 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005853 }
Dave Barach72d72232016-08-04 10:15:08 -04005854 if (vec_len (tap_name) > 63)
5855 {
5856 errmsg ("tap name too long\n");
Dave Barach7be864a2016-11-28 11:41:35 -05005857 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005858 }
Dave Barach72d72232016-08-04 10:15:08 -04005859 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005860
Dave Barach7be864a2016-11-28 11:41:35 -05005861 if (vec_len (tag) > 63)
5862 {
5863 errmsg ("tag too long\n");
5864 return -99;
5865 }
Dave Barach7be864a2016-11-28 11:41:35 -05005866
Dave Barach72d72232016-08-04 10:15:08 -04005867 /* Construct the API message */
5868 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005869
Dave Barach72d72232016-08-04 10:15:08 -04005870 mp->use_random_mac = random_mac;
5871 clib_memcpy (mp->mac_address, mac_address, 6);
5872 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
Dave Barach7be864a2016-11-28 11:41:35 -05005873 if (tag)
5874 clib_memcpy (mp->tag, tag, vec_len (tag));
5875
Dave Barach72d72232016-08-04 10:15:08 -04005876 vec_free (tap_name);
Dave Barach7be864a2016-11-28 11:41:35 -05005877 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005878
Dave Barach72d72232016-08-04 10:15:08 -04005879 /* send it... */
5880 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005881
Dave Barach72d72232016-08-04 10:15:08 -04005882 /* Wait for a reply... */
5883 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005884}
5885
Dave Barach72d72232016-08-04 10:15:08 -04005886static int
5887api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005888{
Dave Barach72d72232016-08-04 10:15:08 -04005889 unformat_input_t *i = vam->input;
5890 vl_api_tap_modify_t *mp;
5891 f64 timeout;
5892 u8 mac_address[6];
5893 u8 random_mac = 1;
5894 u8 name_set = 0;
5895 u8 *tap_name;
5896 u32 sw_if_index = ~0;
5897 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005898
Dave Barach72d72232016-08-04 10:15:08 -04005899 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005900
Dave Barach72d72232016-08-04 10:15:08 -04005901 /* Parse args required to build the message */
5902 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5903 {
5904 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5905 sw_if_index_set = 1;
5906 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5907 sw_if_index_set = 1;
5908 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5909 {
5910 random_mac = 0;
5911 }
5912 else if (unformat (i, "random-mac"))
5913 random_mac = 1;
5914 else if (unformat (i, "tapname %s", &tap_name))
5915 name_set = 1;
5916 else
5917 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005918 }
5919
Dave Barach72d72232016-08-04 10:15:08 -04005920 if (sw_if_index_set == 0)
5921 {
5922 errmsg ("missing vpp interface name");
5923 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005924 }
Dave Barach72d72232016-08-04 10:15:08 -04005925 if (name_set == 0)
5926 {
5927 errmsg ("missing tap name\n");
5928 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005929 }
Dave Barach72d72232016-08-04 10:15:08 -04005930 if (vec_len (tap_name) > 63)
5931 {
5932 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005933 }
Dave Barach72d72232016-08-04 10:15:08 -04005934 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005935
Dave Barach72d72232016-08-04 10:15:08 -04005936 /* Construct the API message */
5937 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005938
Dave Barach72d72232016-08-04 10:15:08 -04005939 mp->use_random_mac = random_mac;
5940 mp->sw_if_index = ntohl (sw_if_index);
5941 clib_memcpy (mp->mac_address, mac_address, 6);
5942 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5943 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005944
Dave Barach72d72232016-08-04 10:15:08 -04005945 /* send it... */
5946 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005947
Dave Barach72d72232016-08-04 10:15:08 -04005948 /* Wait for a reply... */
5949 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005950}
5951
Dave Barach72d72232016-08-04 10:15:08 -04005952static int
5953api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005954{
Dave Barach72d72232016-08-04 10:15:08 -04005955 unformat_input_t *i = vam->input;
5956 vl_api_tap_delete_t *mp;
5957 f64 timeout;
5958 u32 sw_if_index = ~0;
5959 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005960
Dave Barach72d72232016-08-04 10:15:08 -04005961 /* Parse args required to build the message */
5962 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5963 {
5964 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5965 sw_if_index_set = 1;
5966 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5967 sw_if_index_set = 1;
5968 else
5969 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005970 }
5971
Dave Barach72d72232016-08-04 10:15:08 -04005972 if (sw_if_index_set == 0)
5973 {
5974 errmsg ("missing vpp interface name");
5975 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005976 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005977
Dave Barach72d72232016-08-04 10:15:08 -04005978 /* Construct the API message */
5979 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005980
Dave Barach72d72232016-08-04 10:15:08 -04005981 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005982
Dave Barach72d72232016-08-04 10:15:08 -04005983 /* send it... */
5984 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005985
Dave Barach72d72232016-08-04 10:15:08 -04005986 /* Wait for a reply... */
5987 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005988}
5989
Dave Barach72d72232016-08-04 10:15:08 -04005990static int
5991api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005992{
Dave Barach72d72232016-08-04 10:15:08 -04005993 unformat_input_t *i = vam->input;
5994 vl_api_ip_add_del_route_t *mp;
5995 f64 timeout;
5996 u32 sw_if_index = ~0, vrf_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005997 u8 is_ipv6 = 0;
5998 u8 is_local = 0, is_drop = 0;
Neale Ranns948e00f2016-10-20 13:39:34 +01005999 u8 is_unreach = 0, is_prohibit = 0;
Dave Barach72d72232016-08-04 10:15:08 -04006000 u8 create_vrf_if_needed = 0;
6001 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006002 u32 next_hop_weight = 1;
Dave Barach72d72232016-08-04 10:15:08 -04006003 u8 not_last = 0;
6004 u8 is_multipath = 0;
6005 u8 address_set = 0;
6006 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006007 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04006008 u32 resolve_attempts = 0;
6009 u32 dst_address_length = 0;
6010 u8 next_hop_set = 0;
6011 ip4_address_t v4_dst_address, v4_next_hop_address;
6012 ip6_address_t v6_dst_address, v6_next_hop_address;
6013 int count = 1;
6014 int j;
6015 f64 before = 0;
6016 u32 random_add_del = 0;
6017 u32 *random_vector = 0;
6018 uword *random_hash;
6019 u32 random_seed = 0xdeaddabe;
6020 u32 classify_table_index = ~0;
6021 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01006022 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006023 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006024 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006025 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006026
Dave Barach72d72232016-08-04 10:15:08 -04006027 /* Parse args required to build the message */
6028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6029 {
6030 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00006031 ;
Dave Barach72d72232016-08-04 10:15:08 -04006032 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00006033 ;
Dave Barach72d72232016-08-04 10:15:08 -04006034 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
6035 {
6036 address_set = 1;
6037 is_ipv6 = 0;
6038 }
6039 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
6040 {
6041 address_set = 1;
6042 is_ipv6 = 1;
6043 }
6044 else if (unformat (i, "/%d", &dst_address_length))
6045 {
6046 address_length_set = 1;
6047 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006048
Dave Barach72d72232016-08-04 10:15:08 -04006049 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
6050 &v4_next_hop_address))
6051 {
6052 next_hop_set = 1;
6053 }
6054 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
6055 &v6_next_hop_address))
6056 {
6057 next_hop_set = 1;
6058 }
6059 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6060 ;
6061 else if (unformat (i, "weight %d", &next_hop_weight))
6062 ;
6063 else if (unformat (i, "drop"))
6064 {
6065 is_drop = 1;
6066 }
Neale Ranns948e00f2016-10-20 13:39:34 +01006067 else if (unformat (i, "null-send-unreach"))
6068 {
6069 is_unreach = 1;
6070 }
6071 else if (unformat (i, "null-send-prohibit"))
6072 {
6073 is_prohibit = 1;
6074 }
Dave Barach72d72232016-08-04 10:15:08 -04006075 else if (unformat (i, "local"))
6076 {
6077 is_local = 1;
6078 }
6079 else if (unformat (i, "classify %d", &classify_table_index))
6080 {
6081 is_classify = 1;
6082 }
6083 else if (unformat (i, "del"))
6084 is_add = 0;
6085 else if (unformat (i, "add"))
6086 is_add = 1;
6087 else if (unformat (i, "not-last"))
6088 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006089 else if (unformat (i, "resolve-via-host"))
6090 resolve_host = 1;
6091 else if (unformat (i, "resolve-via-attached"))
6092 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04006093 else if (unformat (i, "multipath"))
6094 is_multipath = 1;
6095 else if (unformat (i, "vrf %d", &vrf_id))
6096 ;
6097 else if (unformat (i, "create-vrf"))
6098 create_vrf_if_needed = 1;
6099 else if (unformat (i, "count %d", &count))
6100 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006101 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
6102 ;
6103 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6104 ;
6105 else if (unformat (i, "out-label %d", &next_hop_out_label))
Neale Rannsad422ed2016-11-02 14:20:04 +00006106 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
6107 else if (unformat (i, "via-label %d", &next_hop_via_label))
Dave Barach72d72232016-08-04 10:15:08 -04006108 ;
6109 else if (unformat (i, "random"))
6110 random_add_del = 1;
6111 else if (unformat (i, "seed %d", &random_seed))
6112 ;
6113 else
6114 {
6115 clib_warning ("parse error '%U'", format_unformat_error, i);
6116 return -99;
6117 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006118 }
6119
Neale Ranns948e00f2016-10-20 13:39:34 +01006120 if (!next_hop_set && !is_drop && !is_local &&
Neale Rannsad422ed2016-11-02 14:20:04 +00006121 !is_classify && !is_unreach && !is_prohibit &&
6122 MPLS_LABEL_INVALID == next_hop_via_label)
Dave Barach72d72232016-08-04 10:15:08 -04006123 {
Neale Ranns948e00f2016-10-20 13:39:34 +01006124 errmsg
6125 ("next hop / local / drop / unreach / prohibit / classify not set\n");
Dave Barach72d72232016-08-04 10:15:08 -04006126 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006127 }
6128
Neale Rannsad422ed2016-11-02 14:20:04 +00006129 if (next_hop_set && MPLS_LABEL_INVALID != next_hop_via_label)
6130 {
6131 errmsg ("next hop and next-hop via label set\n");
6132 return -99;
6133 }
Dave Barach72d72232016-08-04 10:15:08 -04006134 if (address_set == 0)
6135 {
6136 errmsg ("missing addresses\n");
6137 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006138 }
6139
Dave Barach72d72232016-08-04 10:15:08 -04006140 if (address_length_set == 0)
6141 {
6142 errmsg ("missing address length\n");
6143 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006144 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006145
Dave Barach72d72232016-08-04 10:15:08 -04006146 /* Generate a pile of unique, random routes */
6147 if (random_add_del)
6148 {
6149 u32 this_random_address;
6150 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006151
Dave Barach72d72232016-08-04 10:15:08 -04006152 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
6153 for (j = 0; j <= count; j++)
6154 {
6155 do
6156 {
6157 this_random_address = random_u32 (&random_seed);
6158 this_random_address =
6159 clib_host_to_net_u32 (this_random_address);
6160 }
6161 while (hash_get (random_hash, this_random_address));
6162 vec_add1 (random_vector, this_random_address);
6163 hash_set (random_hash, this_random_address, 1);
6164 }
6165 hash_free (random_hash);
6166 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07006167 }
6168
Dave Barach72d72232016-08-04 10:15:08 -04006169 if (count > 1)
6170 {
6171 /* Turn on async mode */
6172 vam->async_mode = 1;
6173 vam->async_errors = 0;
6174 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006175 }
6176
Dave Barach72d72232016-08-04 10:15:08 -04006177 for (j = 0; j < count; j++)
6178 {
6179 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006180 M2 (IP_ADD_DEL_ROUTE, ip_add_del_route,
6181 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006182
Dave Barach72d72232016-08-04 10:15:08 -04006183 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006184 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04006185 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006186
Dave Barach72d72232016-08-04 10:15:08 -04006187 mp->is_add = is_add;
6188 mp->is_drop = is_drop;
Neale Ranns948e00f2016-10-20 13:39:34 +01006189 mp->is_unreach = is_unreach;
6190 mp->is_prohibit = is_prohibit;
Dave Barach72d72232016-08-04 10:15:08 -04006191 mp->is_ipv6 = is_ipv6;
6192 mp->is_local = is_local;
6193 mp->is_classify = is_classify;
6194 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006195 mp->is_resolve_host = resolve_host;
6196 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04006197 mp->not_last = not_last;
6198 mp->next_hop_weight = next_hop_weight;
6199 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006200 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04006201 mp->classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006202 mp->next_hop_via_label = ntohl (next_hop_via_label);
6203 mp->next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6204 if (0 != mp->next_hop_n_out_labels)
6205 {
6206 memcpy (mp->next_hop_out_label_stack,
6207 next_hop_out_label_stack,
6208 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6209 vec_free (next_hop_out_label_stack);
6210 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006211
Dave Barach72d72232016-08-04 10:15:08 -04006212 if (is_ipv6)
6213 {
6214 clib_memcpy (mp->dst_address, &v6_dst_address,
6215 sizeof (v6_dst_address));
6216 if (next_hop_set)
6217 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
6218 sizeof (v6_next_hop_address));
6219 increment_v6_address (&v6_dst_address);
6220 }
6221 else
6222 {
6223 clib_memcpy (mp->dst_address, &v4_dst_address,
6224 sizeof (v4_dst_address));
6225 if (next_hop_set)
6226 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
6227 sizeof (v4_next_hop_address));
6228 if (random_add_del)
6229 v4_dst_address.as_u32 = random_vector[j + 1];
6230 else
6231 increment_v4_address (&v4_dst_address);
6232 }
6233 /* send it... */
6234 S;
Dave Barach477570e2016-10-09 17:43:22 -04006235 /* If we receive SIGTERM, stop now... */
6236 if (vam->do_exit)
6237 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006238 }
6239
Dave Barach72d72232016-08-04 10:15:08 -04006240 /* When testing multiple add/del ops, use a control-ping to sync */
6241 if (count > 1)
6242 {
6243 vl_api_control_ping_t *mp;
6244 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006245
Dave Barach72d72232016-08-04 10:15:08 -04006246 /* Shut off async mode */
6247 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006248
Dave Barach72d72232016-08-04 10:15:08 -04006249 M (CONTROL_PING, control_ping);
6250 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006251
Dave Barach72d72232016-08-04 10:15:08 -04006252 timeout = vat_time_now (vam) + 1.0;
6253 while (vat_time_now (vam) < timeout)
6254 if (vam->result_ready == 1)
6255 goto out;
6256 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006257
6258 out:
Dave Barach72d72232016-08-04 10:15:08 -04006259 if (vam->retval == -99)
6260 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006261
Dave Barach72d72232016-08-04 10:15:08 -04006262 if (vam->async_errors > 0)
6263 {
6264 errmsg ("%d asynchronous errors\n", vam->async_errors);
6265 vam->retval = -98;
6266 }
6267 vam->async_errors = 0;
6268 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006269
Dave Barach477570e2016-10-09 17:43:22 -04006270 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6271 if (j > 0)
6272 count = j;
6273
Dave Barach72d72232016-08-04 10:15:08 -04006274 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6275 count, after - before, count / (after - before));
6276 }
6277 else
6278 {
6279 /* Wait for a reply... */
6280 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006281 }
6282
Dave Barach72d72232016-08-04 10:15:08 -04006283 /* Return the good/bad news */
6284 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006285}
6286
Dave Barach72d72232016-08-04 10:15:08 -04006287static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006288api_mpls_route_add_del (vat_main_t * vam)
6289{
6290 unformat_input_t *i = vam->input;
6291 vl_api_mpls_route_add_del_t *mp;
6292 f64 timeout;
6293 u32 sw_if_index = ~0, table_id = 0;
6294 u8 create_table_if_needed = 0;
6295 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006296 u32 next_hop_weight = 1;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006297 u8 is_multipath = 0;
6298 u32 next_hop_table_id = 0;
6299 u8 next_hop_set = 0;
6300 ip4_address_t v4_next_hop_address = {
6301 .as_u32 = 0,
6302 };
6303 ip6_address_t v6_next_hop_address = { {0} };
6304 int count = 1;
6305 int j;
6306 f64 before = 0;
6307 u32 classify_table_index = ~0;
6308 u8 is_classify = 0;
6309 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006310 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006311 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006312 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006313 mpls_label_t local_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006314 u8 is_eos = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006315 u8 next_hop_proto_is_ip4 = 1;
6316
6317 /* Parse args required to build the message */
6318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6319 {
6320 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6321 ;
6322 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6323 ;
6324 else if (unformat (i, "%d", &local_label))
6325 ;
6326 else if (unformat (i, "eos"))
6327 is_eos = 1;
6328 else if (unformat (i, "non-eos"))
6329 is_eos = 0;
6330 else if (unformat (i, "via %U", unformat_ip4_address,
6331 &v4_next_hop_address))
6332 {
6333 next_hop_set = 1;
6334 next_hop_proto_is_ip4 = 1;
6335 }
6336 else if (unformat (i, "via %U", unformat_ip6_address,
6337 &v6_next_hop_address))
6338 {
6339 next_hop_set = 1;
6340 next_hop_proto_is_ip4 = 0;
6341 }
6342 else if (unformat (i, "weight %d", &next_hop_weight))
6343 ;
6344 else if (unformat (i, "create-table"))
6345 create_table_if_needed = 1;
6346 else if (unformat (i, "classify %d", &classify_table_index))
6347 {
6348 is_classify = 1;
6349 }
6350 else if (unformat (i, "del"))
6351 is_add = 0;
6352 else if (unformat (i, "add"))
6353 is_add = 1;
6354 else if (unformat (i, "resolve-via-host"))
6355 resolve_host = 1;
6356 else if (unformat (i, "resolve-via-attached"))
6357 resolve_attached = 1;
6358 else if (unformat (i, "multipath"))
6359 is_multipath = 1;
6360 else if (unformat (i, "count %d", &count))
6361 ;
6362 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6363 {
6364 next_hop_set = 1;
6365 next_hop_proto_is_ip4 = 1;
6366 }
6367 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6368 {
6369 next_hop_set = 1;
6370 next_hop_proto_is_ip4 = 0;
6371 }
6372 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6373 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006374 else if (unformat (i, "via-label %d", &next_hop_via_label))
Neale Ranns1357f3b2016-10-16 12:01:42 -07006375 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006376 else if (unformat (i, "out-label %d", &next_hop_out_label))
6377 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006378 else
6379 {
6380 clib_warning ("parse error '%U'", format_unformat_error, i);
6381 return -99;
6382 }
6383 }
6384
6385 if (!next_hop_set && !is_classify)
6386 {
6387 errmsg ("next hop / classify not set\n");
6388 return -99;
6389 }
6390
6391 if (MPLS_LABEL_INVALID == local_label)
6392 {
6393 errmsg ("missing label\n");
6394 return -99;
6395 }
6396
6397 if (count > 1)
6398 {
6399 /* Turn on async mode */
6400 vam->async_mode = 1;
6401 vam->async_errors = 0;
6402 before = vat_time_now (vam);
6403 }
6404
6405 for (j = 0; j < count; j++)
6406 {
6407 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006408 M2 (MPLS_ROUTE_ADD_DEL, mpls_route_add_del,
6409 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006410
6411 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6412 mp->mr_table_id = ntohl (table_id);
6413 mp->mr_create_table_if_needed = create_table_if_needed;
6414
6415 mp->mr_is_add = is_add;
6416 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6417 mp->mr_is_classify = is_classify;
6418 mp->mr_is_multipath = is_multipath;
6419 mp->mr_is_resolve_host = resolve_host;
6420 mp->mr_is_resolve_attached = resolve_attached;
6421 mp->mr_next_hop_weight = next_hop_weight;
6422 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6423 mp->mr_classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006424 mp->mr_next_hop_via_label = ntohl (next_hop_via_label);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006425 mp->mr_label = ntohl (local_label);
6426 mp->mr_eos = is_eos;
6427
Neale Rannsad422ed2016-11-02 14:20:04 +00006428 mp->mr_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6429 if (0 != mp->mr_next_hop_n_out_labels)
6430 {
6431 memcpy (mp->mr_next_hop_out_label_stack,
6432 next_hop_out_label_stack,
6433 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6434 vec_free (next_hop_out_label_stack);
6435 }
6436
Neale Ranns1357f3b2016-10-16 12:01:42 -07006437 if (next_hop_set)
6438 {
6439 if (next_hop_proto_is_ip4)
6440 {
6441 clib_memcpy (mp->mr_next_hop,
6442 &v4_next_hop_address,
6443 sizeof (v4_next_hop_address));
6444 }
6445 else
6446 {
6447 clib_memcpy (mp->mr_next_hop,
6448 &v6_next_hop_address,
6449 sizeof (v6_next_hop_address));
6450 }
6451 }
6452 local_label++;
6453
6454 /* send it... */
6455 S;
6456 /* If we receive SIGTERM, stop now... */
6457 if (vam->do_exit)
6458 break;
6459 }
6460
6461 /* When testing multiple add/del ops, use a control-ping to sync */
6462 if (count > 1)
6463 {
6464 vl_api_control_ping_t *mp;
6465 f64 after;
6466
6467 /* Shut off async mode */
6468 vam->async_mode = 0;
6469
6470 M (CONTROL_PING, control_ping);
6471 S;
6472
6473 timeout = vat_time_now (vam) + 1.0;
6474 while (vat_time_now (vam) < timeout)
6475 if (vam->result_ready == 1)
6476 goto out;
6477 vam->retval = -99;
6478
6479 out:
6480 if (vam->retval == -99)
6481 errmsg ("timeout\n");
6482
6483 if (vam->async_errors > 0)
6484 {
6485 errmsg ("%d asynchronous errors\n", vam->async_errors);
6486 vam->retval = -98;
6487 }
6488 vam->async_errors = 0;
6489 after = vat_time_now (vam);
6490
6491 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6492 if (j > 0)
6493 count = j;
6494
6495 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6496 count, after - before, count / (after - before));
6497 }
6498 else
6499 {
6500 /* Wait for a reply... */
6501 W;
6502 }
6503
6504 /* Return the good/bad news */
6505 return (vam->retval);
6506}
6507
6508static int
6509api_mpls_ip_bind_unbind (vat_main_t * vam)
6510{
6511 unformat_input_t *i = vam->input;
6512 vl_api_mpls_ip_bind_unbind_t *mp;
6513 f64 timeout;
6514 u32 ip_table_id = 0;
6515 u8 create_table_if_needed = 0;
6516 u8 is_bind = 1;
6517 u8 is_ip4 = 1;
6518 ip4_address_t v4_address;
6519 ip6_address_t v6_address;
6520 u32 address_length;
6521 u8 address_set = 0;
6522 mpls_label_t local_label = MPLS_LABEL_INVALID;
6523
6524 /* Parse args required to build the message */
6525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6526 {
6527 if (unformat (i, "%U/%d", unformat_ip4_address,
6528 &v4_address, &address_length))
6529 {
6530 is_ip4 = 1;
6531 address_set = 1;
6532 }
6533 else if (unformat (i, "%U/%d", unformat_ip6_address,
6534 &v6_address, &address_length))
6535 {
6536 is_ip4 = 0;
6537 address_set = 1;
6538 }
6539 else if (unformat (i, "%d", &local_label))
6540 ;
6541 else if (unformat (i, "create-table"))
6542 create_table_if_needed = 1;
6543 else if (unformat (i, "table-id %d", &ip_table_id))
6544 ;
6545 else if (unformat (i, "unbind"))
6546 is_bind = 0;
6547 else if (unformat (i, "bind"))
6548 is_bind = 1;
6549 else
6550 {
6551 clib_warning ("parse error '%U'", format_unformat_error, i);
6552 return -99;
6553 }
6554 }
6555
6556 if (!address_set)
6557 {
6558 errmsg ("IP addres not set\n");
6559 return -99;
6560 }
6561
6562 if (MPLS_LABEL_INVALID == local_label)
6563 {
6564 errmsg ("missing label\n");
6565 return -99;
6566 }
6567
6568 /* Construct the API message */
6569 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6570
6571 mp->mb_create_table_if_needed = create_table_if_needed;
6572 mp->mb_is_bind = is_bind;
6573 mp->mb_is_ip4 = is_ip4;
6574 mp->mb_ip_table_id = ntohl (ip_table_id);
6575 mp->mb_mpls_table_id = 0;
6576 mp->mb_label = ntohl (local_label);
6577 mp->mb_address_length = address_length;
6578
6579 if (is_ip4)
6580 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6581 else
6582 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6583
6584 /* send it... */
6585 S;
6586
6587 /* Wait for a reply... */
6588 W;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006589}
6590
6591static int
Dave Barach72d72232016-08-04 10:15:08 -04006592api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006593{
Dave Barach72d72232016-08-04 10:15:08 -04006594 unformat_input_t *i = vam->input;
6595 vl_api_proxy_arp_add_del_t *mp;
6596 f64 timeout;
6597 u32 vrf_id = 0;
6598 u8 is_add = 1;
6599 ip4_address_t lo, hi;
6600 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006601
Dave Barach72d72232016-08-04 10:15:08 -04006602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6603 {
6604 if (unformat (i, "vrf %d", &vrf_id))
6605 ;
6606 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6607 unformat_ip4_address, &hi))
6608 range_set = 1;
6609 else if (unformat (i, "del"))
6610 is_add = 0;
6611 else
6612 {
6613 clib_warning ("parse error '%U'", format_unformat_error, i);
6614 return -99;
6615 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006616 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006617
Dave Barach72d72232016-08-04 10:15:08 -04006618 if (range_set == 0)
6619 {
6620 errmsg ("address range not set\n");
6621 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006622 }
6623
Dave Barach72d72232016-08-04 10:15:08 -04006624 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006625
Dave Barach72d72232016-08-04 10:15:08 -04006626 mp->vrf_id = ntohl (vrf_id);
6627 mp->is_add = is_add;
6628 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6629 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006630
Dave Barach72d72232016-08-04 10:15:08 -04006631 S;
6632 W;
6633 /* NOTREACHED */
6634 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006635}
6636
Dave Barach72d72232016-08-04 10:15:08 -04006637static int
6638api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006639{
Dave Barach72d72232016-08-04 10:15:08 -04006640 unformat_input_t *i = vam->input;
6641 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6642 f64 timeout;
6643 u32 sw_if_index;
6644 u8 enable = 1;
6645 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006646
Dave Barach72d72232016-08-04 10:15:08 -04006647 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6648 {
6649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6650 sw_if_index_set = 1;
6651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6652 sw_if_index_set = 1;
6653 else if (unformat (i, "enable"))
6654 enable = 1;
6655 else if (unformat (i, "disable"))
6656 enable = 0;
6657 else
6658 {
6659 clib_warning ("parse error '%U'", format_unformat_error, i);
6660 return -99;
6661 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006662 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006663
Dave Barach72d72232016-08-04 10:15:08 -04006664 if (sw_if_index_set == 0)
6665 {
6666 errmsg ("missing interface name or sw_if_index\n");
6667 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006668 }
6669
Dave Barach72d72232016-08-04 10:15:08 -04006670 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006671
Dave Barach72d72232016-08-04 10:15:08 -04006672 mp->sw_if_index = ntohl (sw_if_index);
6673 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006674
Dave Barach72d72232016-08-04 10:15:08 -04006675 S;
6676 W;
6677 /* NOTREACHED */
6678 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006679}
6680
Dave Barach72d72232016-08-04 10:15:08 -04006681static int
Neale Rannsad422ed2016-11-02 14:20:04 +00006682api_mpls_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006683{
Dave Barach72d72232016-08-04 10:15:08 -04006684 unformat_input_t *i = vam->input;
Neale Rannsad422ed2016-11-02 14:20:04 +00006685 vl_api_mpls_tunnel_add_del_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04006686 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006687
Dave Barach72d72232016-08-04 10:15:08 -04006688 u8 is_add = 1;
6689 u8 l2_only = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006690 u32 sw_if_index = ~0;
6691 u32 next_hop_sw_if_index = ~0;
6692 u32 next_hop_proto_is_ip4 = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006693
Neale Rannsad422ed2016-11-02 14:20:04 +00006694 u32 next_hop_table_id = 0;
6695 ip4_address_t v4_next_hop_address = {
6696 .as_u32 = 0,
6697 };
6698 ip6_address_t v6_next_hop_address = { {0} };
6699 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID, *labels = NULL;
Dave Barach75665d32016-11-17 11:36:59 -05006700
Dave Barach72d72232016-08-04 10:15:08 -04006701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6702 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006703 if (unformat (i, "add"))
6704 is_add = 1;
6705 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6706 is_add = 0;
6707 else if (unformat (i, "sw_if_index %d", &next_hop_sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -04006708 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006709 else if (unformat (i, "via %U",
6710 unformat_ip4_address, &v4_next_hop_address))
6711 {
6712 next_hop_proto_is_ip4 = 1;
6713 }
6714 else if (unformat (i, "via %U",
6715 unformat_ip6_address, &v6_next_hop_address))
6716 {
6717 next_hop_proto_is_ip4 = 0;
6718 }
Dave Barach72d72232016-08-04 10:15:08 -04006719 else if (unformat (i, "l2-only"))
6720 l2_only = 1;
Neale Rannsad422ed2016-11-02 14:20:04 +00006721 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6722 ;
6723 else if (unformat (i, "out-label %d", &next_hop_out_label))
6724 vec_add1 (labels, ntohl (next_hop_out_label));
Dave Barach72d72232016-08-04 10:15:08 -04006725 else
6726 {
6727 clib_warning ("parse error '%U'", format_unformat_error, i);
6728 return -99;
6729 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006730 }
6731
Neale Rannsad422ed2016-11-02 14:20:04 +00006732 M2 (MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del,
6733 sizeof (mpls_label_t) * vec_len (labels));
6734
6735 mp->mt_next_hop_sw_if_index = ntohl (next_hop_sw_if_index);
6736 mp->mt_sw_if_index = ntohl (sw_if_index);
6737 mp->mt_is_add = is_add;
6738 mp->mt_l2_only = l2_only;
6739 mp->mt_next_hop_table_id = ntohl (next_hop_table_id);
6740 mp->mt_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6741
6742 mp->mt_next_hop_n_out_labels = vec_len (labels);
6743
6744 if (0 != mp->mt_next_hop_n_out_labels)
Dave Barach72d72232016-08-04 10:15:08 -04006745 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006746 clib_memcpy (mp->mt_next_hop_out_label_stack, labels,
6747 sizeof (mpls_label_t) * mp->mt_next_hop_n_out_labels);
6748 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006749 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006750
Neale Rannsad422ed2016-11-02 14:20:04 +00006751 if (next_hop_proto_is_ip4)
Dave Barach72d72232016-08-04 10:15:08 -04006752 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006753 clib_memcpy (mp->mt_next_hop,
6754 &v4_next_hop_address, sizeof (v4_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006755 }
Neale Rannsad422ed2016-11-02 14:20:04 +00006756 else
Dave Barach72d72232016-08-04 10:15:08 -04006757 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006758 clib_memcpy (mp->mt_next_hop,
6759 &v6_next_hop_address, sizeof (v6_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006760 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006761
Dave Barach72d72232016-08-04 10:15:08 -04006762 S;
6763 W;
6764 /* NOTREACHED */
6765 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006766}
6767
Dave Barach72d72232016-08-04 10:15:08 -04006768static int
6769api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006770{
Dave Barach72d72232016-08-04 10:15:08 -04006771 unformat_input_t *i = vam->input;
6772 vl_api_sw_interface_set_unnumbered_t *mp;
6773 f64 timeout;
6774 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006775 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006776 u8 is_add = 1;
6777 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006778
Dave Barach72d72232016-08-04 10:15:08 -04006779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6780 {
6781 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6782 sw_if_index_set = 1;
6783 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6784 sw_if_index_set = 1;
6785 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6786 ;
6787 else if (unformat (i, "del"))
6788 is_add = 0;
6789 else
6790 {
6791 clib_warning ("parse error '%U'", format_unformat_error, i);
6792 return -99;
6793 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006794 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006795
Dave Barach72d72232016-08-04 10:15:08 -04006796 if (sw_if_index_set == 0)
6797 {
6798 errmsg ("missing interface name or sw_if_index\n");
6799 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006800 }
6801
Dave Barach72d72232016-08-04 10:15:08 -04006802 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006803
Dave Barach72d72232016-08-04 10:15:08 -04006804 mp->sw_if_index = ntohl (sw_if_index);
6805 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6806 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006807
Dave Barach72d72232016-08-04 10:15:08 -04006808 S;
6809 W;
6810 /* NOTREACHED */
6811 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006812}
6813
Dave Barach72d72232016-08-04 10:15:08 -04006814static int
6815api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006816{
Dave Barach72d72232016-08-04 10:15:08 -04006817 unformat_input_t *i = vam->input;
6818 vl_api_ip_neighbor_add_del_t *mp;
6819 f64 timeout;
6820 u32 sw_if_index;
6821 u8 sw_if_index_set = 0;
6822 u32 vrf_id = 0;
6823 u8 is_add = 1;
6824 u8 is_static = 0;
6825 u8 mac_address[6];
6826 u8 mac_set = 0;
6827 u8 v4_address_set = 0;
6828 u8 v6_address_set = 0;
6829 ip4_address_t v4address;
6830 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006831
Dave Barach72d72232016-08-04 10:15:08 -04006832 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006833
Dave Barach72d72232016-08-04 10:15:08 -04006834 /* Parse args required to build the message */
6835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6836 {
6837 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6838 {
6839 mac_set = 1;
6840 }
6841 else if (unformat (i, "del"))
6842 is_add = 0;
6843 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6844 sw_if_index_set = 1;
6845 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6846 sw_if_index_set = 1;
6847 else if (unformat (i, "is_static"))
6848 is_static = 1;
6849 else if (unformat (i, "vrf %d", &vrf_id))
6850 ;
6851 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6852 v4_address_set = 1;
6853 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6854 v6_address_set = 1;
6855 else
6856 {
6857 clib_warning ("parse error '%U'", format_unformat_error, i);
6858 return -99;
6859 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006860 }
6861
Dave Barach72d72232016-08-04 10:15:08 -04006862 if (sw_if_index_set == 0)
6863 {
6864 errmsg ("missing interface name or sw_if_index\n");
6865 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006866 }
Dave Barach72d72232016-08-04 10:15:08 -04006867 if (v4_address_set && v6_address_set)
6868 {
6869 errmsg ("both v4 and v6 addresses set\n");
6870 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006871 }
Dave Barach72d72232016-08-04 10:15:08 -04006872 if (!v4_address_set && !v6_address_set)
6873 {
6874 errmsg ("no address set\n");
6875 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006876 }
6877
Dave Barach72d72232016-08-04 10:15:08 -04006878 /* Construct the API message */
6879 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006880
Dave Barach72d72232016-08-04 10:15:08 -04006881 mp->sw_if_index = ntohl (sw_if_index);
6882 mp->is_add = is_add;
6883 mp->vrf_id = ntohl (vrf_id);
6884 mp->is_static = is_static;
6885 if (mac_set)
6886 clib_memcpy (mp->mac_address, mac_address, 6);
6887 if (v6_address_set)
6888 {
6889 mp->is_ipv6 = 1;
6890 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6891 }
6892 else
6893 {
6894 /* mp->is_ipv6 = 0; via memset in M macro above */
6895 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006896 }
6897
Dave Barach72d72232016-08-04 10:15:08 -04006898 /* send it... */
6899 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006900
Dave Barach72d72232016-08-04 10:15:08 -04006901 /* Wait for a reply, return good/bad news */
6902 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006903
Dave Barach72d72232016-08-04 10:15:08 -04006904 /* NOTREACHED */
6905 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906}
6907
Dave Barach72d72232016-08-04 10:15:08 -04006908static int
6909api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006910{
Dave Barach72d72232016-08-04 10:15:08 -04006911 unformat_input_t *i = vam->input;
6912 vl_api_reset_vrf_t *mp;
6913 f64 timeout;
6914 u32 vrf_id = 0;
6915 u8 is_ipv6 = 0;
6916 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006917
Dave Barach72d72232016-08-04 10:15:08 -04006918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6919 {
6920 if (unformat (i, "vrf %d", &vrf_id))
6921 vrf_id_set = 1;
6922 else if (unformat (i, "ipv6"))
6923 is_ipv6 = 1;
6924 else
6925 {
6926 clib_warning ("parse error '%U'", format_unformat_error, i);
6927 return -99;
6928 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006929 }
6930
Dave Barach72d72232016-08-04 10:15:08 -04006931 if (vrf_id_set == 0)
6932 {
6933 errmsg ("missing vrf id\n");
6934 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006935 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006936
Dave Barach72d72232016-08-04 10:15:08 -04006937 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006938
Dave Barach72d72232016-08-04 10:15:08 -04006939 mp->vrf_id = ntohl (vrf_id);
6940 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006941
Dave Barach72d72232016-08-04 10:15:08 -04006942 S;
6943 W;
6944 /* NOTREACHED */
6945 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006946}
6947
Dave Barach72d72232016-08-04 10:15:08 -04006948static int
6949api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006950{
Dave Barach72d72232016-08-04 10:15:08 -04006951 unformat_input_t *i = vam->input;
6952 vl_api_create_vlan_subif_t *mp;
6953 f64 timeout;
6954 u32 sw_if_index;
6955 u8 sw_if_index_set = 0;
6956 u32 vlan_id;
6957 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006958
Dave Barach72d72232016-08-04 10:15:08 -04006959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6960 {
6961 if (unformat (i, "sw_if_index %d", &sw_if_index))
6962 sw_if_index_set = 1;
6963 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6964 sw_if_index_set = 1;
6965 else if (unformat (i, "vlan %d", &vlan_id))
6966 vlan_id_set = 1;
6967 else
6968 {
6969 clib_warning ("parse error '%U'", format_unformat_error, i);
6970 return -99;
6971 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006972 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006973
Dave Barach72d72232016-08-04 10:15:08 -04006974 if (sw_if_index_set == 0)
6975 {
6976 errmsg ("missing interface name or sw_if_index\n");
6977 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006978 }
6979
Dave Barach72d72232016-08-04 10:15:08 -04006980 if (vlan_id_set == 0)
6981 {
6982 errmsg ("missing vlan_id\n");
6983 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006984 }
Dave Barach72d72232016-08-04 10:15:08 -04006985 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006986
Dave Barach72d72232016-08-04 10:15:08 -04006987 mp->sw_if_index = ntohl (sw_if_index);
6988 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006989
Dave Barach72d72232016-08-04 10:15:08 -04006990 S;
6991 W;
6992 /* NOTREACHED */
6993 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006994}
6995
6996#define foreach_create_subif_bit \
6997_(no_tags) \
6998_(one_tag) \
6999_(two_tags) \
7000_(dot1ad) \
7001_(exact_match) \
7002_(default_sub) \
7003_(outer_vlan_id_any) \
7004_(inner_vlan_id_any)
7005
Dave Barach72d72232016-08-04 10:15:08 -04007006static int
7007api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007008{
Dave Barach72d72232016-08-04 10:15:08 -04007009 unformat_input_t *i = vam->input;
7010 vl_api_create_subif_t *mp;
7011 f64 timeout;
7012 u32 sw_if_index;
7013 u8 sw_if_index_set = 0;
7014 u32 sub_id;
7015 u8 sub_id_set = 0;
7016 u32 no_tags = 0;
7017 u32 one_tag = 0;
7018 u32 two_tags = 0;
7019 u32 dot1ad = 0;
7020 u32 exact_match = 0;
7021 u32 default_sub = 0;
7022 u32 outer_vlan_id_any = 0;
7023 u32 inner_vlan_id_any = 0;
7024 u32 tmp;
7025 u16 outer_vlan_id = 0;
7026 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007027
Dave Barach72d72232016-08-04 10:15:08 -04007028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7029 {
7030 if (unformat (i, "sw_if_index %d", &sw_if_index))
7031 sw_if_index_set = 1;
7032 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7033 sw_if_index_set = 1;
7034 else if (unformat (i, "sub_id %d", &sub_id))
7035 sub_id_set = 1;
7036 else if (unformat (i, "outer_vlan_id %d", &tmp))
7037 outer_vlan_id = tmp;
7038 else if (unformat (i, "inner_vlan_id %d", &tmp))
7039 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007040
7041#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04007042 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07007043#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007044 else
7045 {
7046 clib_warning ("parse error '%U'", format_unformat_error, i);
7047 return -99;
7048 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007049 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007050
Dave Barach72d72232016-08-04 10:15:08 -04007051 if (sw_if_index_set == 0)
7052 {
7053 errmsg ("missing interface name or sw_if_index\n");
7054 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007055 }
7056
Dave Barach72d72232016-08-04 10:15:08 -04007057 if (sub_id_set == 0)
7058 {
7059 errmsg ("missing sub_id\n");
7060 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007061 }
Dave Barach72d72232016-08-04 10:15:08 -04007062 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007063
Dave Barach72d72232016-08-04 10:15:08 -04007064 mp->sw_if_index = ntohl (sw_if_index);
7065 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007066
Ed Warnickecb9cada2015-12-08 15:45:58 -07007067#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04007068 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007069#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007070
Dave Barach72d72232016-08-04 10:15:08 -04007071 mp->outer_vlan_id = ntohs (outer_vlan_id);
7072 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007073
Dave Barach72d72232016-08-04 10:15:08 -04007074 S;
7075 W;
7076 /* NOTREACHED */
7077 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007078}
7079
Dave Barach72d72232016-08-04 10:15:08 -04007080static int
7081api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007082{
Dave Barach72d72232016-08-04 10:15:08 -04007083 unformat_input_t *i = vam->input;
7084 vl_api_oam_add_del_t *mp;
7085 f64 timeout;
7086 u32 vrf_id = 0;
7087 u8 is_add = 1;
7088 ip4_address_t src, dst;
7089 u8 src_set = 0;
7090 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007091
Dave Barach72d72232016-08-04 10:15:08 -04007092 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7093 {
7094 if (unformat (i, "vrf %d", &vrf_id))
7095 ;
7096 else if (unformat (i, "src %U", unformat_ip4_address, &src))
7097 src_set = 1;
7098 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
7099 dst_set = 1;
7100 else if (unformat (i, "del"))
7101 is_add = 0;
7102 else
7103 {
7104 clib_warning ("parse error '%U'", format_unformat_error, i);
7105 return -99;
7106 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007107 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007108
Dave Barach72d72232016-08-04 10:15:08 -04007109 if (src_set == 0)
7110 {
7111 errmsg ("missing src addr\n");
7112 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007113 }
7114
Dave Barach72d72232016-08-04 10:15:08 -04007115 if (dst_set == 0)
7116 {
7117 errmsg ("missing dst addr\n");
7118 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007119 }
7120
Dave Barach72d72232016-08-04 10:15:08 -04007121 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007122
Dave Barach72d72232016-08-04 10:15:08 -04007123 mp->vrf_id = ntohl (vrf_id);
7124 mp->is_add = is_add;
7125 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
7126 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007127
Dave Barach72d72232016-08-04 10:15:08 -04007128 S;
7129 W;
7130 /* NOTREACHED */
7131 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007132}
7133
Dave Barach72d72232016-08-04 10:15:08 -04007134static int
7135api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007136{
Dave Barach72d72232016-08-04 10:15:08 -04007137 unformat_input_t *i = vam->input;
7138 vl_api_reset_fib_t *mp;
7139 f64 timeout;
7140 u32 vrf_id = 0;
7141 u8 is_ipv6 = 0;
7142 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007143
Dave Barach72d72232016-08-04 10:15:08 -04007144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7145 {
7146 if (unformat (i, "vrf %d", &vrf_id))
7147 vrf_id_set = 1;
7148 else if (unformat (i, "ipv6"))
7149 is_ipv6 = 1;
7150 else
7151 {
7152 clib_warning ("parse error '%U'", format_unformat_error, i);
7153 return -99;
7154 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007155 }
7156
Dave Barach72d72232016-08-04 10:15:08 -04007157 if (vrf_id_set == 0)
7158 {
7159 errmsg ("missing vrf id\n");
7160 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007161 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007162
Dave Barach72d72232016-08-04 10:15:08 -04007163 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007164
Dave Barach72d72232016-08-04 10:15:08 -04007165 mp->vrf_id = ntohl (vrf_id);
7166 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007167
Dave Barach72d72232016-08-04 10:15:08 -04007168 S;
7169 W;
7170 /* NOTREACHED */
7171 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007172}
7173
Dave Barach72d72232016-08-04 10:15:08 -04007174static int
7175api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007176{
Dave Barach72d72232016-08-04 10:15:08 -04007177 unformat_input_t *i = vam->input;
7178 vl_api_dhcp_proxy_config_t *mp;
7179 f64 timeout;
7180 u32 vrf_id = 0;
7181 u8 is_add = 1;
7182 u8 insert_cid = 1;
7183 u8 v4_address_set = 0;
7184 u8 v6_address_set = 0;
7185 ip4_address_t v4address;
7186 ip6_address_t v6address;
7187 u8 v4_src_address_set = 0;
7188 u8 v6_src_address_set = 0;
7189 ip4_address_t v4srcaddress;
7190 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007191
Dave Barach72d72232016-08-04 10:15:08 -04007192 /* Parse args required to build the message */
7193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7194 {
7195 if (unformat (i, "del"))
7196 is_add = 0;
7197 else if (unformat (i, "vrf %d", &vrf_id))
7198 ;
7199 else if (unformat (i, "insert-cid %d", &insert_cid))
7200 ;
7201 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7202 v4_address_set = 1;
7203 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7204 v6_address_set = 1;
7205 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7206 v4_src_address_set = 1;
7207 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7208 v6_src_address_set = 1;
7209 else
7210 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007211 }
7212
Dave Barach72d72232016-08-04 10:15:08 -04007213 if (v4_address_set && v6_address_set)
7214 {
7215 errmsg ("both v4 and v6 server addresses set\n");
7216 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007217 }
Dave Barach72d72232016-08-04 10:15:08 -04007218 if (!v4_address_set && !v6_address_set)
7219 {
7220 errmsg ("no server addresses set\n");
7221 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007222 }
7223
Dave Barach72d72232016-08-04 10:15:08 -04007224 if (v4_src_address_set && v6_src_address_set)
7225 {
7226 errmsg ("both v4 and v6 src addresses set\n");
7227 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007228 }
Dave Barach72d72232016-08-04 10:15:08 -04007229 if (!v4_src_address_set && !v6_src_address_set)
7230 {
7231 errmsg ("no src addresses set\n");
7232 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007233 }
7234
Dave Barach72d72232016-08-04 10:15:08 -04007235 if (!(v4_src_address_set && v4_address_set) &&
7236 !(v6_src_address_set && v6_address_set))
7237 {
7238 errmsg ("no matching server and src addresses set\n");
7239 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007240 }
7241
Dave Barach72d72232016-08-04 10:15:08 -04007242 /* Construct the API message */
7243 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007244
Dave Barach72d72232016-08-04 10:15:08 -04007245 mp->insert_circuit_id = insert_cid;
7246 mp->is_add = is_add;
7247 mp->vrf_id = ntohl (vrf_id);
7248 if (v6_address_set)
7249 {
7250 mp->is_ipv6 = 1;
7251 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7252 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7253 }
7254 else
7255 {
7256 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7257 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007258 }
7259
Dave Barach72d72232016-08-04 10:15:08 -04007260 /* send it... */
7261 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007262
Dave Barach72d72232016-08-04 10:15:08 -04007263 /* Wait for a reply, return good/bad news */
7264 W;
7265 /* NOTREACHED */
7266 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007267}
7268
Dave Barach72d72232016-08-04 10:15:08 -04007269static int
7270api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007271{
Dave Barach72d72232016-08-04 10:15:08 -04007272 unformat_input_t *i = vam->input;
7273 vl_api_dhcp_proxy_config_2_t *mp;
7274 f64 timeout;
7275 u32 rx_vrf_id = 0;
7276 u32 server_vrf_id = 0;
7277 u8 is_add = 1;
7278 u8 insert_cid = 1;
7279 u8 v4_address_set = 0;
7280 u8 v6_address_set = 0;
7281 ip4_address_t v4address;
7282 ip6_address_t v6address;
7283 u8 v4_src_address_set = 0;
7284 u8 v6_src_address_set = 0;
7285 ip4_address_t v4srcaddress;
7286 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007287
Dave Barach72d72232016-08-04 10:15:08 -04007288 /* Parse args required to build the message */
7289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7290 {
7291 if (unformat (i, "del"))
7292 is_add = 0;
7293 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7294 ;
7295 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7296 ;
7297 else if (unformat (i, "insert-cid %d", &insert_cid))
7298 ;
7299 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7300 v4_address_set = 1;
7301 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7302 v6_address_set = 1;
7303 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7304 v4_src_address_set = 1;
7305 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7306 v6_src_address_set = 1;
7307 else
7308 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007309 }
7310
Dave Barach72d72232016-08-04 10:15:08 -04007311 if (v4_address_set && v6_address_set)
7312 {
7313 errmsg ("both v4 and v6 server addresses set\n");
7314 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007315 }
Dave Barach72d72232016-08-04 10:15:08 -04007316 if (!v4_address_set && !v6_address_set)
7317 {
7318 errmsg ("no server addresses set\n");
7319 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007320 }
7321
Dave Barach72d72232016-08-04 10:15:08 -04007322 if (v4_src_address_set && v6_src_address_set)
7323 {
7324 errmsg ("both v4 and v6 src addresses set\n");
7325 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007326 }
Dave Barach72d72232016-08-04 10:15:08 -04007327 if (!v4_src_address_set && !v6_src_address_set)
7328 {
7329 errmsg ("no src addresses set\n");
7330 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007331 }
7332
Dave Barach72d72232016-08-04 10:15:08 -04007333 if (!(v4_src_address_set && v4_address_set) &&
7334 !(v6_src_address_set && v6_address_set))
7335 {
7336 errmsg ("no matching server and src addresses set\n");
7337 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007338 }
7339
Dave Barach72d72232016-08-04 10:15:08 -04007340 /* Construct the API message */
7341 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007342
Dave Barach72d72232016-08-04 10:15:08 -04007343 mp->insert_circuit_id = insert_cid;
7344 mp->is_add = is_add;
7345 mp->rx_vrf_id = ntohl (rx_vrf_id);
7346 mp->server_vrf_id = ntohl (server_vrf_id);
7347 if (v6_address_set)
7348 {
7349 mp->is_ipv6 = 1;
7350 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7351 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7352 }
7353 else
7354 {
7355 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7356 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007357 }
7358
Dave Barach72d72232016-08-04 10:15:08 -04007359 /* send it... */
7360 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007361
Dave Barach72d72232016-08-04 10:15:08 -04007362 /* Wait for a reply, return good/bad news */
7363 W;
7364 /* NOTREACHED */
7365 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007366}
7367
Dave Barach72d72232016-08-04 10:15:08 -04007368static int
7369api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007370{
Dave Barach72d72232016-08-04 10:15:08 -04007371 unformat_input_t *i = vam->input;
7372 vl_api_dhcp_proxy_set_vss_t *mp;
7373 f64 timeout;
7374 u8 is_ipv6 = 0;
7375 u8 is_add = 1;
7376 u32 tbl_id;
7377 u8 tbl_id_set = 0;
7378 u32 oui;
7379 u8 oui_set = 0;
7380 u32 fib_id;
7381 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007382
Dave Barach72d72232016-08-04 10:15:08 -04007383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7384 {
7385 if (unformat (i, "tbl_id %d", &tbl_id))
7386 tbl_id_set = 1;
7387 if (unformat (i, "fib_id %d", &fib_id))
7388 fib_id_set = 1;
7389 if (unformat (i, "oui %d", &oui))
7390 oui_set = 1;
7391 else if (unformat (i, "ipv6"))
7392 is_ipv6 = 1;
7393 else if (unformat (i, "del"))
7394 is_add = 0;
7395 else
7396 {
7397 clib_warning ("parse error '%U'", format_unformat_error, i);
7398 return -99;
7399 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007400 }
7401
Dave Barach72d72232016-08-04 10:15:08 -04007402 if (tbl_id_set == 0)
7403 {
7404 errmsg ("missing tbl id\n");
7405 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007406 }
7407
Dave Barach72d72232016-08-04 10:15:08 -04007408 if (fib_id_set == 0)
7409 {
7410 errmsg ("missing fib id\n");
7411 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007412 }
Dave Barach72d72232016-08-04 10:15:08 -04007413 if (oui_set == 0)
7414 {
7415 errmsg ("missing oui\n");
7416 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007417 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007418
Dave Barach72d72232016-08-04 10:15:08 -04007419 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7420 mp->tbl_id = ntohl (tbl_id);
7421 mp->fib_id = ntohl (fib_id);
7422 mp->oui = ntohl (oui);
7423 mp->is_ipv6 = is_ipv6;
7424 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007425
Dave Barach72d72232016-08-04 10:15:08 -04007426 S;
7427 W;
7428 /* NOTREACHED */
7429 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007430}
7431
Dave Barach72d72232016-08-04 10:15:08 -04007432static int
7433api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007434{
Dave Barach72d72232016-08-04 10:15:08 -04007435 unformat_input_t *i = vam->input;
7436 vl_api_dhcp_client_config_t *mp;
7437 f64 timeout;
7438 u32 sw_if_index;
7439 u8 sw_if_index_set = 0;
7440 u8 is_add = 1;
7441 u8 *hostname = 0;
7442 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007443
Dave Barach72d72232016-08-04 10:15:08 -04007444 /* Parse args required to build the message */
7445 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7446 {
7447 if (unformat (i, "del"))
7448 is_add = 0;
7449 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7450 sw_if_index_set = 1;
7451 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7452 sw_if_index_set = 1;
7453 else if (unformat (i, "hostname %s", &hostname))
7454 ;
7455 else if (unformat (i, "disable_event"))
7456 disable_event = 1;
7457 else
7458 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007459 }
7460
Dave Barach72d72232016-08-04 10:15:08 -04007461 if (sw_if_index_set == 0)
7462 {
7463 errmsg ("missing interface name or sw_if_index\n");
7464 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007465 }
7466
Dave Barach72d72232016-08-04 10:15:08 -04007467 if (vec_len (hostname) > 63)
7468 {
7469 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007470 }
Dave Barach72d72232016-08-04 10:15:08 -04007471 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007472
Dave Barach72d72232016-08-04 10:15:08 -04007473 /* Construct the API message */
7474 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007475
Dave Barach72d72232016-08-04 10:15:08 -04007476 mp->sw_if_index = ntohl (sw_if_index);
7477 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7478 vec_free (hostname);
7479 mp->is_add = is_add;
7480 mp->want_dhcp_event = disable_event ? 0 : 1;
7481 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007482
Dave Barach72d72232016-08-04 10:15:08 -04007483 /* send it... */
7484 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007485
Dave Barach72d72232016-08-04 10:15:08 -04007486 /* Wait for a reply, return good/bad news */
7487 W;
7488 /* NOTREACHED */
7489 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007490}
7491
Dave Barach72d72232016-08-04 10:15:08 -04007492static int
7493api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007494{
Dave Barach72d72232016-08-04 10:15:08 -04007495 unformat_input_t *i = vam->input;
7496 vl_api_set_ip_flow_hash_t *mp;
7497 f64 timeout;
7498 u32 vrf_id = 0;
7499 u8 is_ipv6 = 0;
7500 u8 vrf_id_set = 0;
7501 u8 src = 0;
7502 u8 dst = 0;
7503 u8 sport = 0;
7504 u8 dport = 0;
7505 u8 proto = 0;
7506 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007507
Dave Barach72d72232016-08-04 10:15:08 -04007508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7509 {
7510 if (unformat (i, "vrf %d", &vrf_id))
7511 vrf_id_set = 1;
7512 else if (unformat (i, "ipv6"))
7513 is_ipv6 = 1;
7514 else if (unformat (i, "src"))
7515 src = 1;
7516 else if (unformat (i, "dst"))
7517 dst = 1;
7518 else if (unformat (i, "sport"))
7519 sport = 1;
7520 else if (unformat (i, "dport"))
7521 dport = 1;
7522 else if (unformat (i, "proto"))
7523 proto = 1;
7524 else if (unformat (i, "reverse"))
7525 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007526
Dave Barach72d72232016-08-04 10:15:08 -04007527 else
7528 {
7529 clib_warning ("parse error '%U'", format_unformat_error, i);
7530 return -99;
7531 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007532 }
7533
Dave Barach72d72232016-08-04 10:15:08 -04007534 if (vrf_id_set == 0)
7535 {
7536 errmsg ("missing vrf id\n");
7537 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007538 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007539
Dave Barach72d72232016-08-04 10:15:08 -04007540 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7541 mp->src = src;
7542 mp->dst = dst;
7543 mp->sport = sport;
7544 mp->dport = dport;
7545 mp->proto = proto;
7546 mp->reverse = reverse;
7547 mp->vrf_id = ntohl (vrf_id);
7548 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007549
Dave Barach72d72232016-08-04 10:15:08 -04007550 S;
7551 W;
7552 /* NOTREACHED */
7553 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007554}
7555
Dave Barach72d72232016-08-04 10:15:08 -04007556static int
7557api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007558{
Dave Barach72d72232016-08-04 10:15:08 -04007559 unformat_input_t *i = vam->input;
7560 vl_api_sw_interface_ip6_enable_disable_t *mp;
7561 f64 timeout;
7562 u32 sw_if_index;
7563 u8 sw_if_index_set = 0;
7564 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565
Dave Barach72d72232016-08-04 10:15:08 -04007566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7567 {
7568 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7569 sw_if_index_set = 1;
7570 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7571 sw_if_index_set = 1;
7572 else if (unformat (i, "enable"))
7573 enable = 1;
7574 else if (unformat (i, "disable"))
7575 enable = 0;
7576 else
7577 {
7578 clib_warning ("parse error '%U'", format_unformat_error, i);
7579 return -99;
7580 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007581 }
7582
Dave Barach72d72232016-08-04 10:15:08 -04007583 if (sw_if_index_set == 0)
7584 {
7585 errmsg ("missing interface name or sw_if_index\n");
7586 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007587 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007588
Dave Barach72d72232016-08-04 10:15:08 -04007589 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007590
Dave Barach72d72232016-08-04 10:15:08 -04007591 mp->sw_if_index = ntohl (sw_if_index);
7592 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007593
Dave Barach72d72232016-08-04 10:15:08 -04007594 S;
7595 W;
7596 /* NOTREACHED */
7597 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007598}
7599
Dave Barach72d72232016-08-04 10:15:08 -04007600static int
7601api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007602{
Dave Barach72d72232016-08-04 10:15:08 -04007603 unformat_input_t *i = vam->input;
7604 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7605 f64 timeout;
7606 u32 sw_if_index;
7607 u8 sw_if_index_set = 0;
7608 u32 address_length = 0;
7609 u8 v6_address_set = 0;
7610 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007611
Dave Barach72d72232016-08-04 10:15:08 -04007612 /* Parse args required to build the message */
7613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7614 {
7615 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7616 sw_if_index_set = 1;
7617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7618 sw_if_index_set = 1;
7619 else if (unformat (i, "%U/%d",
7620 unformat_ip6_address, &v6address, &address_length))
7621 v6_address_set = 1;
7622 else
7623 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007624 }
7625
Dave Barach72d72232016-08-04 10:15:08 -04007626 if (sw_if_index_set == 0)
7627 {
7628 errmsg ("missing interface name or sw_if_index\n");
7629 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007630 }
Dave Barach72d72232016-08-04 10:15:08 -04007631 if (!v6_address_set)
7632 {
7633 errmsg ("no address set\n");
7634 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007635 }
7636
Dave Barach72d72232016-08-04 10:15:08 -04007637 /* Construct the API message */
7638 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7639 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007640
Dave Barach72d72232016-08-04 10:15:08 -04007641 mp->sw_if_index = ntohl (sw_if_index);
7642 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7643 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007644
Dave Barach72d72232016-08-04 10:15:08 -04007645 /* send it... */
7646 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007647
Dave Barach72d72232016-08-04 10:15:08 -04007648 /* Wait for a reply, return good/bad news */
7649 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007650
Dave Barach72d72232016-08-04 10:15:08 -04007651 /* NOTREACHED */
7652 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007653}
7654
7655
Dave Barach72d72232016-08-04 10:15:08 -04007656static int
7657api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007658{
Dave Barach72d72232016-08-04 10:15:08 -04007659 unformat_input_t *i = vam->input;
7660 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7661 f64 timeout;
7662 u32 sw_if_index;
7663 u8 sw_if_index_set = 0;
7664 u32 address_length = 0;
7665 u8 v6_address_set = 0;
7666 ip6_address_t v6address;
7667 u8 use_default = 0;
7668 u8 no_advertise = 0;
7669 u8 off_link = 0;
7670 u8 no_autoconfig = 0;
7671 u8 no_onlink = 0;
7672 u8 is_no = 0;
7673 u32 val_lifetime = 0;
7674 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007675
Dave Barach72d72232016-08-04 10:15:08 -04007676 /* Parse args required to build the message */
7677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7678 {
7679 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7680 sw_if_index_set = 1;
7681 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7682 sw_if_index_set = 1;
7683 else if (unformat (i, "%U/%d",
7684 unformat_ip6_address, &v6address, &address_length))
7685 v6_address_set = 1;
7686 else if (unformat (i, "val_life %d", &val_lifetime))
7687 ;
7688 else if (unformat (i, "pref_life %d", &pref_lifetime))
7689 ;
7690 else if (unformat (i, "def"))
7691 use_default = 1;
7692 else if (unformat (i, "noadv"))
7693 no_advertise = 1;
7694 else if (unformat (i, "offl"))
7695 off_link = 1;
7696 else if (unformat (i, "noauto"))
7697 no_autoconfig = 1;
7698 else if (unformat (i, "nolink"))
7699 no_onlink = 1;
7700 else if (unformat (i, "isno"))
7701 is_no = 1;
7702 else
7703 {
7704 clib_warning ("parse error '%U'", format_unformat_error, i);
7705 return -99;
7706 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007707 }
7708
Dave Barach72d72232016-08-04 10:15:08 -04007709 if (sw_if_index_set == 0)
7710 {
7711 errmsg ("missing interface name or sw_if_index\n");
7712 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007713 }
Dave Barach72d72232016-08-04 10:15:08 -04007714 if (!v6_address_set)
7715 {
7716 errmsg ("no address set\n");
7717 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007718 }
7719
Dave Barach72d72232016-08-04 10:15:08 -04007720 /* Construct the API message */
7721 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007722
Dave Barach72d72232016-08-04 10:15:08 -04007723 mp->sw_if_index = ntohl (sw_if_index);
7724 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7725 mp->address_length = address_length;
7726 mp->use_default = use_default;
7727 mp->no_advertise = no_advertise;
7728 mp->off_link = off_link;
7729 mp->no_autoconfig = no_autoconfig;
7730 mp->no_onlink = no_onlink;
7731 mp->is_no = is_no;
7732 mp->val_lifetime = ntohl (val_lifetime);
7733 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007734
Dave Barach72d72232016-08-04 10:15:08 -04007735 /* send it... */
7736 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007737
Dave Barach72d72232016-08-04 10:15:08 -04007738 /* Wait for a reply, return good/bad news */
7739 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007740
Dave Barach72d72232016-08-04 10:15:08 -04007741 /* NOTREACHED */
7742 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007743}
7744
Dave Barach72d72232016-08-04 10:15:08 -04007745static int
7746api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007747{
Dave Barach72d72232016-08-04 10:15:08 -04007748 unformat_input_t *i = vam->input;
7749 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7750 f64 timeout;
7751 u32 sw_if_index;
7752 u8 sw_if_index_set = 0;
7753 u8 suppress = 0;
7754 u8 managed = 0;
7755 u8 other = 0;
7756 u8 ll_option = 0;
7757 u8 send_unicast = 0;
7758 u8 cease = 0;
7759 u8 is_no = 0;
7760 u8 default_router = 0;
7761 u32 max_interval = 0;
7762 u32 min_interval = 0;
7763 u32 lifetime = 0;
7764 u32 initial_count = 0;
7765 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007766
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007767
Dave Barach72d72232016-08-04 10:15:08 -04007768 /* Parse args required to build the message */
7769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7770 {
7771 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7772 sw_if_index_set = 1;
7773 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7774 sw_if_index_set = 1;
7775 else if (unformat (i, "maxint %d", &max_interval))
7776 ;
7777 else if (unformat (i, "minint %d", &min_interval))
7778 ;
7779 else if (unformat (i, "life %d", &lifetime))
7780 ;
7781 else if (unformat (i, "count %d", &initial_count))
7782 ;
7783 else if (unformat (i, "interval %d", &initial_interval))
7784 ;
7785 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7786 suppress = 1;
7787 else if (unformat (i, "managed"))
7788 managed = 1;
7789 else if (unformat (i, "other"))
7790 other = 1;
7791 else if (unformat (i, "ll"))
7792 ll_option = 1;
7793 else if (unformat (i, "send"))
7794 send_unicast = 1;
7795 else if (unformat (i, "cease"))
7796 cease = 1;
7797 else if (unformat (i, "isno"))
7798 is_no = 1;
7799 else if (unformat (i, "def"))
7800 default_router = 1;
7801 else
7802 {
7803 clib_warning ("parse error '%U'", format_unformat_error, i);
7804 return -99;
7805 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806 }
7807
Dave Barach72d72232016-08-04 10:15:08 -04007808 if (sw_if_index_set == 0)
7809 {
7810 errmsg ("missing interface name or sw_if_index\n");
7811 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007812 }
7813
Dave Barach72d72232016-08-04 10:15:08 -04007814 /* Construct the API message */
7815 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007816
Dave Barach72d72232016-08-04 10:15:08 -04007817 mp->sw_if_index = ntohl (sw_if_index);
7818 mp->max_interval = ntohl (max_interval);
7819 mp->min_interval = ntohl (min_interval);
7820 mp->lifetime = ntohl (lifetime);
7821 mp->initial_count = ntohl (initial_count);
7822 mp->initial_interval = ntohl (initial_interval);
7823 mp->suppress = suppress;
7824 mp->managed = managed;
7825 mp->other = other;
7826 mp->ll_option = ll_option;
7827 mp->send_unicast = send_unicast;
7828 mp->cease = cease;
7829 mp->is_no = is_no;
7830 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007831
Dave Barach72d72232016-08-04 10:15:08 -04007832 /* send it... */
7833 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007834
Dave Barach72d72232016-08-04 10:15:08 -04007835 /* Wait for a reply, return good/bad news */
7836 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007837
Dave Barach72d72232016-08-04 10:15:08 -04007838 /* NOTREACHED */
7839 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007840}
7841
Dave Barach72d72232016-08-04 10:15:08 -04007842static int
7843api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007844{
Dave Barach72d72232016-08-04 10:15:08 -04007845 unformat_input_t *i = vam->input;
7846 vl_api_set_arp_neighbor_limit_t *mp;
7847 f64 timeout;
7848 u32 arp_nbr_limit;
7849 u8 limit_set = 0;
7850 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007851
Dave Barach72d72232016-08-04 10:15:08 -04007852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7853 {
7854 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7855 limit_set = 1;
7856 else if (unformat (i, "ipv6"))
7857 is_ipv6 = 1;
7858 else
7859 {
7860 clib_warning ("parse error '%U'", format_unformat_error, i);
7861 return -99;
7862 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007863 }
7864
Dave Barach72d72232016-08-04 10:15:08 -04007865 if (limit_set == 0)
7866 {
7867 errmsg ("missing limit value\n");
7868 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007869 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007870
Dave Barach72d72232016-08-04 10:15:08 -04007871 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007872
Dave Barach72d72232016-08-04 10:15:08 -04007873 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7874 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007875
Dave Barach72d72232016-08-04 10:15:08 -04007876 S;
7877 W;
7878 /* NOTREACHED */
7879 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007880}
7881
Dave Barach72d72232016-08-04 10:15:08 -04007882static int
7883api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007884{
Dave Barach72d72232016-08-04 10:15:08 -04007885 unformat_input_t *i = vam->input;
7886 vl_api_l2_patch_add_del_t *mp;
7887 f64 timeout;
7888 u32 rx_sw_if_index;
7889 u8 rx_sw_if_index_set = 0;
7890 u32 tx_sw_if_index;
7891 u8 tx_sw_if_index_set = 0;
7892 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007893
Dave Barach72d72232016-08-04 10:15:08 -04007894 /* Parse args required to build the message */
7895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7896 {
7897 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7898 rx_sw_if_index_set = 1;
7899 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7900 tx_sw_if_index_set = 1;
7901 else if (unformat (i, "rx"))
7902 {
7903 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7904 {
7905 if (unformat (i, "%U", unformat_sw_if_index, vam,
7906 &rx_sw_if_index))
7907 rx_sw_if_index_set = 1;
7908 }
7909 else
7910 break;
7911 }
7912 else if (unformat (i, "tx"))
7913 {
7914 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7915 {
7916 if (unformat (i, "%U", unformat_sw_if_index, vam,
7917 &tx_sw_if_index))
7918 tx_sw_if_index_set = 1;
7919 }
7920 else
7921 break;
7922 }
7923 else if (unformat (i, "del"))
7924 is_add = 0;
7925 else
7926 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007927 }
7928
Dave Barach72d72232016-08-04 10:15:08 -04007929 if (rx_sw_if_index_set == 0)
7930 {
7931 errmsg ("missing rx interface name or rx_sw_if_index\n");
7932 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007933 }
7934
Dave Barach72d72232016-08-04 10:15:08 -04007935 if (tx_sw_if_index_set == 0)
7936 {
7937 errmsg ("missing tx interface name or tx_sw_if_index\n");
7938 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007939 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007940
Dave Barach72d72232016-08-04 10:15:08 -04007941 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007942
Dave Barach72d72232016-08-04 10:15:08 -04007943 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7944 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7945 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007946
Dave Barach72d72232016-08-04 10:15:08 -04007947 S;
7948 W;
7949 /* NOTREACHED */
7950 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007951}
Dave Barach72d72232016-08-04 10:15:08 -04007952
7953static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007954api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007955{
Dave Barach72d72232016-08-04 10:15:08 -04007956 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007957 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007958 f64 timeout;
7959 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007960 int has_trace_option = 0;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307961 int has_pot_option = 0;
7962 int has_seqno_option = 0;
7963 int has_analyse_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007964
Shwetha20a64f52016-03-25 10:55:01 +00007965 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7966 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007967 if (unformat (input, "trace"))
7968 has_trace_option = 1;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307969 else if (unformat (input, "pot"))
7970 has_pot_option = 1;
7971 else if (unformat (input, "seqno"))
7972 has_seqno_option = 1;
7973 else if (unformat (input, "analyse"))
7974 has_analyse_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007975 else
Dave Barach72d72232016-08-04 10:15:08 -04007976 break;
Shwetha20a64f52016-03-25 10:55:01 +00007977 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007978 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007979 mp->id = htons (id);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307980 mp->seqno = has_seqno_option;
7981 mp->analyse = has_analyse_option;
7982 mp->pot_enable = has_pot_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007983 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007984
Dave Barach72d72232016-08-04 10:15:08 -04007985 S;
7986 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007987
Dave Barach72d72232016-08-04 10:15:08 -04007988 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007989
Shwetha20a64f52016-03-25 10:55:01 +00007990}
Dave Barach72d72232016-08-04 10:15:08 -04007991
Shwetha20a64f52016-03-25 10:55:01 +00007992
Dave Barach72d72232016-08-04 10:15:08 -04007993static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007994api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007995{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007996 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007997 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007998
Vengada Govindan07d2f842016-08-25 10:34:34 -07007999 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04008000 S;
8001 W;
8002 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00008003}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008004
Dave Barach72d72232016-08-04 10:15:08 -04008005static int
8006api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008007{
Dave Barach72d72232016-08-04 10:15:08 -04008008 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008009 vl_api_sr_tunnel_add_del_t *mp;
8010 f64 timeout;
8011 int is_del = 0;
8012 int pl_index;
8013 ip6_address_t src_address;
8014 int src_address_set = 0;
8015 ip6_address_t dst_address;
8016 u32 dst_mask_width;
8017 int dst_address_set = 0;
8018 u16 flags = 0;
8019 u32 rx_table_id = 0;
8020 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008021 ip6_address_t *segments = 0;
8022 ip6_address_t *this_seg;
8023 ip6_address_t *tags = 0;
8024 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008025 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04008026 u8 *name = 0;
8027 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008028
8029 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8030 {
8031 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008032 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008033 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04008034 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008035 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008036 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008037 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04008038 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008039 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04008040 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008041 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04008042 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008043 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04008044 unformat_ip6_address, &dst_address, &dst_mask_width))
8045 dst_address_set = 1;
8046 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
8047 {
8048 vec_add2 (segments, this_seg, 1);
8049 clib_memcpy (this_seg->as_u8, next_address.as_u8,
8050 sizeof (*this_seg));
8051 }
8052 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
8053 {
8054 vec_add2 (tags, this_tag, 1);
8055 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
8056 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008057 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04008058 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008059 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04008060 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008061 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008062 {
8063 if (pl_index <= 0 || pl_index > 4)
8064 {
8065 pl_index_range_error:
8066 errmsg ("pl index %d out of range\n", pl_index);
8067 return -99;
8068 }
8069 flags |=
8070 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
8071 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008072 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008073 {
8074 if (pl_index <= 0 || pl_index > 4)
8075 goto pl_index_range_error;
8076 flags |=
8077 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
8078 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008079 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008080 {
8081 if (pl_index <= 0 || pl_index > 4)
8082 goto pl_index_range_error;
8083 flags |=
8084 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
8085 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008086 else
Dave Barach72d72232016-08-04 10:15:08 -04008087 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008088 }
8089
8090 if (!src_address_set)
8091 {
8092 errmsg ("src address required\n");
8093 return -99;
8094 }
8095
8096 if (!dst_address_set)
8097 {
8098 errmsg ("dst address required\n");
8099 return -99;
8100 }
8101
8102 if (!segments)
8103 {
8104 errmsg ("at least one sr segment required\n");
8105 return -99;
8106 }
8107
Dave Barach72d72232016-08-04 10:15:08 -04008108 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
8109 vec_len (segments) * sizeof (ip6_address_t)
8110 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008111
Damjan Marionf1213b82016-03-13 02:22:06 +01008112 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
8113 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008114 mp->dst_mask_width = dst_mask_width;
8115 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
8116 mp->n_segments = vec_len (segments);
8117 mp->n_tags = vec_len (tags);
8118 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008119 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04008120 vec_len (segments) * sizeof (ip6_address_t));
8121 clib_memcpy (mp->segs_and_tags +
8122 vec_len (segments) * sizeof (ip6_address_t), tags,
8123 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008124
8125 mp->outer_vrf_id = ntohl (rx_table_id);
8126 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04008127 memcpy (mp->name, name, vec_len (name));
8128 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008129
8130 vec_free (segments);
8131 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008132
Dave Barach72d72232016-08-04 10:15:08 -04008133 S;
8134 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008135 /* NOTREACHED */
8136}
8137
Dave Barach72d72232016-08-04 10:15:08 -04008138static int
8139api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008140{
Dave Barach72d72232016-08-04 10:15:08 -04008141 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008142 vl_api_sr_policy_add_del_t *mp;
8143 f64 timeout;
8144 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008145 u8 *name = 0;
8146 u8 *tunnel_name = 0;
8147 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008148
Dave Barach72d72232016-08-04 10:15:08 -04008149 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008150 int tunnel_set = 0;
8151 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008152 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
8153 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 -07008154
8155 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8156 {
8157 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008158 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008159 else if (unformat (input, "name %s", &name))
8160 name_set = 1;
8161 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04008162 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008163 if (tunnel_name)
8164 {
8165 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008166 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04008167 - length = #bytes to store in serial vector
8168 - +1 = byte to store that length
8169 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008170 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008171 tunnel_set = 1;
8172 tunnel_name = 0;
8173 }
Dave Barach72d72232016-08-04 10:15:08 -04008174 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008175 else
Dave Barach72d72232016-08-04 10:15:08 -04008176 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008177 }
8178
8179 if (!name_set)
8180 {
8181 errmsg ("policy name required\n");
8182 return -99;
8183 }
8184
8185 if ((!tunnel_set) && (!is_del))
8186 {
8187 errmsg ("tunnel name required\n");
8188 return -99;
8189 }
8190
Dave Barach72d72232016-08-04 10:15:08 -04008191 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008192
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008193
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008194
8195 mp->is_add = !is_del;
8196
Dave Barach72d72232016-08-04 10:15:08 -04008197 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008198 // 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 -04008199 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008200 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008201 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8202 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008203
Dave Barach72d72232016-08-04 10:15:08 -04008204 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008205 {
8206 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008207 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8208 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008209 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008210 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008211 }
Dave Barach72d72232016-08-04 10:15:08 -04008212 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 -07008213
8214 vec_free (tunnel_names);
8215 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008216
Dave Barach72d72232016-08-04 10:15:08 -04008217 S;
8218 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008219 /* NOTREACHED */
8220}
8221
Dave Barach72d72232016-08-04 10:15:08 -04008222static int
8223api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008224{
Dave Barach72d72232016-08-04 10:15:08 -04008225 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008226 vl_api_sr_multicast_map_add_del_t *mp;
8227 f64 timeout;
8228 int is_del = 0;
8229 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008230 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008231 int multicast_address_set = 0;
8232
8233 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8234 {
8235 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008236 is_del = 1;
8237 else
8238 if (unformat
8239 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008240 multicast_address_set = 1;
8241 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008242 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008243 else
Dave Barach72d72232016-08-04 10:15:08 -04008244 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008245 }
8246
8247 if (!is_del && !policy_name)
8248 {
8249 errmsg ("sr-policy name required\n");
8250 return -99;
8251 }
8252
8253
8254 if (!multicast_address_set)
8255 {
8256 errmsg ("address required\n");
8257 return -99;
8258 }
8259
Dave Barach72d72232016-08-04 10:15:08 -04008260 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008261
8262 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008263 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8264 clib_memcpy (mp->multicast_address, &multicast_address,
8265 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008266
8267
8268 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008269
Dave Barach72d72232016-08-04 10:15:08 -04008270 S;
8271 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008272 /* NOTREACHED */
8273}
8274
Ed Warnickecb9cada2015-12-08 15:45:58 -07008275
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008276#define foreach_tcp_proto_field \
8277_(src_port) \
8278_(dst_port)
8279
8280#define foreach_udp_proto_field \
8281_(src_port) \
8282_(dst_port)
8283
Ed Warnickecb9cada2015-12-08 15:45:58 -07008284#define foreach_ip4_proto_field \
8285_(src_address) \
8286_(dst_address) \
8287_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008288_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008289_(fragment_id) \
8290_(ttl) \
8291_(protocol) \
8292_(checksum)
8293
Dave Barach72d72232016-08-04 10:15:08 -04008294uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008295unformat_tcp_mask (unformat_input_t * input, va_list * args)
8296{
8297 u8 **maskp = va_arg (*args, u8 **);
8298 u8 *mask = 0;
8299 u8 found_something = 0;
8300 tcp_header_t *tcp;
8301
8302#define _(a) u8 a=0;
8303 foreach_tcp_proto_field;
8304#undef _
8305
8306 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8307 {
8308 if (0);
8309#define _(a) else if (unformat (input, #a)) a=1;
8310 foreach_tcp_proto_field
8311#undef _
8312 else
8313 break;
8314 }
8315
8316#define _(a) found_something += a;
8317 foreach_tcp_proto_field;
8318#undef _
8319
8320 if (found_something == 0)
8321 return 0;
8322
8323 vec_validate (mask, sizeof (*tcp) - 1);
8324
8325 tcp = (tcp_header_t *) mask;
8326
8327#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8328 foreach_tcp_proto_field;
8329#undef _
8330
8331 *maskp = mask;
8332 return 1;
8333}
8334
8335uword
8336unformat_udp_mask (unformat_input_t * input, va_list * args)
8337{
8338 u8 **maskp = va_arg (*args, u8 **);
8339 u8 *mask = 0;
8340 u8 found_something = 0;
8341 udp_header_t *udp;
8342
8343#define _(a) u8 a=0;
8344 foreach_udp_proto_field;
8345#undef _
8346
8347 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8348 {
8349 if (0);
8350#define _(a) else if (unformat (input, #a)) a=1;
8351 foreach_udp_proto_field
8352#undef _
8353 else
8354 break;
8355 }
8356
8357#define _(a) found_something += a;
8358 foreach_udp_proto_field;
8359#undef _
8360
8361 if (found_something == 0)
8362 return 0;
8363
8364 vec_validate (mask, sizeof (*udp) - 1);
8365
8366 udp = (udp_header_t *) mask;
8367
8368#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8369 foreach_udp_proto_field;
8370#undef _
8371
8372 *maskp = mask;
8373 return 1;
8374}
8375
8376typedef struct
8377{
8378 u16 src_port, dst_port;
8379} tcpudp_header_t;
8380
8381uword
8382unformat_l4_mask (unformat_input_t * input, va_list * args)
8383{
8384 u8 **maskp = va_arg (*args, u8 **);
8385 u16 src_port = 0, dst_port = 0;
8386 tcpudp_header_t *tcpudp;
8387
8388 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8389 {
8390 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8391 return 1;
8392 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8393 return 1;
8394 else if (unformat (input, "src_port"))
8395 src_port = 0xFFFF;
8396 else if (unformat (input, "dst_port"))
8397 dst_port = 0xFFFF;
8398 else
8399 return 0;
8400 }
8401
8402 if (!src_port && !dst_port)
8403 return 0;
8404
8405 u8 *mask = 0;
8406 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8407
8408 tcpudp = (tcpudp_header_t *) mask;
8409 tcpudp->src_port = src_port;
8410 tcpudp->dst_port = dst_port;
8411
8412 *maskp = mask;
8413
8414 return 1;
8415}
8416
8417uword
Dave Barach72d72232016-08-04 10:15:08 -04008418unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008419{
Dave Barach72d72232016-08-04 10:15:08 -04008420 u8 **maskp = va_arg (*args, u8 **);
8421 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008422 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008423 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008424
Ed Warnickecb9cada2015-12-08 15:45:58 -07008425#define _(a) u8 a=0;
8426 foreach_ip4_proto_field;
8427#undef _
8428 u8 version = 0;
8429 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008430
8431
8432 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008433 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008434 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008435 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008436 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008437 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008438 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008439 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008440 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008441 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008442 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008443 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008444
Ed Warnickecb9cada2015-12-08 15:45:58 -07008445#define _(a) else if (unformat (input, #a)) a=1;
8446 foreach_ip4_proto_field
8447#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008448 else
8449 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008450 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008451
Ed Warnickecb9cada2015-12-08 15:45:58 -07008452#define _(a) found_something += a;
8453 foreach_ip4_proto_field;
8454#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008455
Ed Warnickecb9cada2015-12-08 15:45:58 -07008456 if (found_something == 0)
8457 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008458
Ed Warnickecb9cada2015-12-08 15:45:58 -07008459 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008460
Ed Warnickecb9cada2015-12-08 15:45:58 -07008461 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008462
Ed Warnickecb9cada2015-12-08 15:45:58 -07008463#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8464 foreach_ip4_proto_field;
8465#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008466
Ed Warnickecb9cada2015-12-08 15:45:58 -07008467 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008468
Ed Warnickecb9cada2015-12-08 15:45:58 -07008469 if (version)
8470 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008471
Ed Warnickecb9cada2015-12-08 15:45:58 -07008472 if (hdr_length)
8473 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008474
Ed Warnickecb9cada2015-12-08 15:45:58 -07008475 *maskp = mask;
8476 return 1;
8477}
8478
8479#define foreach_ip6_proto_field \
8480_(src_address) \
8481_(dst_address) \
8482_(payload_length) \
8483_(hop_limit) \
8484_(protocol)
8485
Dave Barach72d72232016-08-04 10:15:08 -04008486uword
8487unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008488{
Dave Barach72d72232016-08-04 10:15:08 -04008489 u8 **maskp = va_arg (*args, u8 **);
8490 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008491 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008492 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008493 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008494
Ed Warnickecb9cada2015-12-08 15:45:58 -07008495#define _(a) u8 a=0;
8496 foreach_ip6_proto_field;
8497#undef _
8498 u8 version = 0;
8499 u8 traffic_class = 0;
8500 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008501
8502 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008503 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008504 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008505 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008506 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008507 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008508 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008509 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008510 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008511 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008512 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008513 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008514 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008515 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008516
Ed Warnickecb9cada2015-12-08 15:45:58 -07008517#define _(a) else if (unformat (input, #a)) a=1;
8518 foreach_ip6_proto_field
8519#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008520 else
8521 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008522 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008523
Ed Warnickecb9cada2015-12-08 15:45:58 -07008524#define _(a) found_something += a;
8525 foreach_ip6_proto_field;
8526#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008527
Ed Warnickecb9cada2015-12-08 15:45:58 -07008528 if (found_something == 0)
8529 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008530
Ed Warnickecb9cada2015-12-08 15:45:58 -07008531 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008532
Ed Warnickecb9cada2015-12-08 15:45:58 -07008533 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008534
Ed Warnickecb9cada2015-12-08 15:45:58 -07008535#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8536 foreach_ip6_proto_field;
8537#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008538
Ed Warnickecb9cada2015-12-08 15:45:58 -07008539 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008540
Ed Warnickecb9cada2015-12-08 15:45:58 -07008541 if (version)
8542 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8543
8544 if (traffic_class)
8545 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8546
8547 if (flow_label)
8548 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8549
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008550 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008551 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008552
Ed Warnickecb9cada2015-12-08 15:45:58 -07008553 *maskp = mask;
8554 return 1;
8555}
8556
Dave Barach72d72232016-08-04 10:15:08 -04008557uword
8558unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008559{
Dave Barach72d72232016-08-04 10:15:08 -04008560 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008561
Dave Barach72d72232016-08-04 10:15:08 -04008562 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8563 {
8564 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8565 return 1;
8566 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8567 return 1;
8568 else
8569 break;
8570 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008571 return 0;
8572}
8573
Dave Barach72d72232016-08-04 10:15:08 -04008574uword
8575unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008576{
Dave Barach72d72232016-08-04 10:15:08 -04008577 u8 **maskp = va_arg (*args, u8 **);
8578 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008579 u8 src = 0;
8580 u8 dst = 0;
8581 u8 proto = 0;
8582 u8 tag1 = 0;
8583 u8 tag2 = 0;
8584 u8 ignore_tag1 = 0;
8585 u8 ignore_tag2 = 0;
8586 u8 cos1 = 0;
8587 u8 cos2 = 0;
8588 u8 dot1q = 0;
8589 u8 dot1ad = 0;
8590 int len = 14;
8591
Dave Barach72d72232016-08-04 10:15:08 -04008592 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8593 {
8594 if (unformat (input, "src"))
8595 src = 1;
8596 else if (unformat (input, "dst"))
8597 dst = 1;
8598 else if (unformat (input, "proto"))
8599 proto = 1;
8600 else if (unformat (input, "tag1"))
8601 tag1 = 1;
8602 else if (unformat (input, "tag2"))
8603 tag2 = 1;
8604 else if (unformat (input, "ignore-tag1"))
8605 ignore_tag1 = 1;
8606 else if (unformat (input, "ignore-tag2"))
8607 ignore_tag2 = 1;
8608 else if (unformat (input, "cos1"))
8609 cos1 = 1;
8610 else if (unformat (input, "cos2"))
8611 cos2 = 1;
8612 else if (unformat (input, "dot1q"))
8613 dot1q = 1;
8614 else if (unformat (input, "dot1ad"))
8615 dot1ad = 1;
8616 else
8617 break;
8618 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008619 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008620 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008621 return 0;
8622
8623 if (tag1 || ignore_tag1 || cos1 || dot1q)
8624 len = 18;
8625 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8626 len = 22;
8627
Dave Barach72d72232016-08-04 10:15:08 -04008628 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008629
8630 if (dst)
8631 memset (mask, 0xff, 6);
8632
8633 if (src)
8634 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008635
Ed Warnickecb9cada2015-12-08 15:45:58 -07008636 if (tag2 || dot1ad)
8637 {
8638 /* inner vlan tag */
8639 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008640 {
8641 mask[19] = 0xff;
8642 mask[18] = 0x0f;
8643 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008644 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008645 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008646 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008647 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008648 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008649 {
8650 mask[15] = 0xff;
8651 mask[14] = 0x0f;
8652 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008653 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008654 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008655 *maskp = mask;
8656 return 1;
8657 }
8658 if (tag1 | dot1q)
8659 {
8660 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008661 {
8662 mask[15] = 0xff;
8663 mask[14] = 0x0f;
8664 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008665 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008666 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008667 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008668 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008669
8670 *maskp = mask;
8671 return 1;
8672 }
8673 if (cos2)
8674 mask[18] |= 0xe0;
8675 if (cos1)
8676 mask[14] |= 0xe0;
8677 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008678 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008679
Ed Warnickecb9cada2015-12-08 15:45:58 -07008680 *maskp = mask;
8681 return 1;
8682}
8683
Dave Barach72d72232016-08-04 10:15:08 -04008684uword
8685unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008686{
Dave Barach72d72232016-08-04 10:15:08 -04008687 u8 **maskp = va_arg (*args, u8 **);
8688 u32 *skipp = va_arg (*args, u32 *);
8689 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008690 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008691 u8 *mask = 0;
8692 u8 *l2 = 0;
8693 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008694 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008695 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008696
Dave Barach72d72232016-08-04 10:15:08 -04008697 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8698 {
8699 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8700 ;
8701 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8702 ;
8703 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8704 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008705 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8706 ;
Dave Barach72d72232016-08-04 10:15:08 -04008707 else
8708 break;
8709 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008710
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008711 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008712 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008713 vec_free (mask);
8714 vec_free (l2);
8715 vec_free (l4);
8716 return 0;
8717 }
8718
8719 if (mask || l2 || l3 || l4)
8720 {
8721 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008722 {
8723 /* "With a free Ethernet header in every package" */
8724 if (l2 == 0)
8725 vec_validate (l2, 13);
8726 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008727 if (vec_len (l3))
8728 {
8729 vec_append (mask, l3);
8730 vec_free (l3);
8731 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008732 if (vec_len (l4))
8733 {
8734 vec_append (mask, l4);
8735 vec_free (l4);
8736 }
Dave Barach72d72232016-08-04 10:15:08 -04008737 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008738
8739 /* Scan forward looking for the first significant mask octet */
8740 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008741 if (mask[i])
8742 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008743
8744 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008745 *skipp = i / sizeof (u32x4);
8746 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008747
8748 /* Pad mask to an even multiple of the vector size */
8749 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008750 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008751
8752 match = vec_len (mask) / sizeof (u32x4);
8753
Dave Barach72d72232016-08-04 10:15:08 -04008754 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8755 {
8756 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8757 if (*tmp || *(tmp + 1))
8758 break;
8759 match--;
8760 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008761 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008762 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008763
Dave Barach72d72232016-08-04 10:15:08 -04008764 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008765
8766 *matchp = match;
8767 *maskp = mask;
8768
8769 return 1;
8770 }
8771
8772 return 0;
8773}
8774
8775#define foreach_l2_next \
8776_(drop, DROP) \
8777_(ethernet, ETHERNET_INPUT) \
8778_(ip4, IP4_INPUT) \
8779_(ip6, IP6_INPUT)
8780
Dave Barach72d72232016-08-04 10:15:08 -04008781uword
8782unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008783{
Dave Barach72d72232016-08-04 10:15:08 -04008784 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008785 u32 next_index = 0;
8786 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008787
Ed Warnickecb9cada2015-12-08 15:45:58 -07008788#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008789 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008790 foreach_l2_next;
8791#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008792
Ed Warnickecb9cada2015-12-08 15:45:58 -07008793 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008794 {
8795 next_index = tmp;
8796 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008797 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008798
Ed Warnickecb9cada2015-12-08 15:45:58 -07008799 return 0;
8800
Dave Barach72d72232016-08-04 10:15:08 -04008801out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008802 *miss_next_indexp = next_index;
8803 return 1;
8804}
8805
8806#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008807_(drop, DROP) \
8808_(local, LOCAL) \
8809_(rewrite, REWRITE)
8810
Dave Barach72d72232016-08-04 10:15:08 -04008811uword
8812unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008813{
Dave Barach72d72232016-08-04 10:15:08 -04008814 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008815 u32 next_index = 0;
8816 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008817
Ed Warnickecb9cada2015-12-08 15:45:58 -07008818#define _(n,N) \
8819 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8820 foreach_ip_next;
8821#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008822
Ed Warnickecb9cada2015-12-08 15:45:58 -07008823 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008824 {
8825 next_index = tmp;
8826 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008827 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008828
Ed Warnickecb9cada2015-12-08 15:45:58 -07008829 return 0;
8830
Dave Barach72d72232016-08-04 10:15:08 -04008831out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008832 *miss_next_indexp = next_index;
8833 return 1;
8834}
8835
8836#define foreach_acl_next \
8837_(deny, DENY)
8838
Dave Barach72d72232016-08-04 10:15:08 -04008839uword
8840unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008841{
Dave Barach72d72232016-08-04 10:15:08 -04008842 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008843 u32 next_index = 0;
8844 u32 tmp;
8845
8846#define _(n,N) \
8847 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8848 foreach_acl_next;
8849#undef _
8850
8851 if (unformat (input, "permit"))
8852 {
8853 next_index = ~0;
8854 goto out;
8855 }
8856 else if (unformat (input, "%d", &tmp))
8857 {
8858 next_index = tmp;
8859 goto out;
8860 }
8861
8862 return 0;
8863
Dave Barach72d72232016-08-04 10:15:08 -04008864out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008865 *miss_next_indexp = next_index;
8866 return 1;
8867}
8868
Dave Barach72d72232016-08-04 10:15:08 -04008869uword
8870unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008871{
Dave Barach72d72232016-08-04 10:15:08 -04008872 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008873
8874 if (unformat (input, "conform-color"))
8875 *r = POLICE_CONFORM;
8876 else if (unformat (input, "exceed-color"))
8877 *r = POLICE_EXCEED;
8878 else
8879 return 0;
8880
8881 return 1;
8882}
8883
Dave Barach72d72232016-08-04 10:15:08 -04008884static int
8885api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008886{
Dave Barach72d72232016-08-04 10:15:08 -04008887 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008888 vl_api_classify_add_del_table_t *mp;
8889
8890 u32 nbuckets = 2;
8891 u32 skip = ~0;
8892 u32 match = ~0;
8893 int is_add = 1;
8894 u32 table_index = ~0;
8895 u32 next_table_index = ~0;
8896 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008897 u32 memory_size = 32 << 20;
8898 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008899 f64 timeout;
Steve Shin25e26dc2016-11-08 10:47:10 -08008900 u32 current_data_flag = 0;
8901 int current_data_offset = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008902
Dave Barach72d72232016-08-04 10:15:08 -04008903 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8904 {
8905 if (unformat (i, "del"))
8906 is_add = 0;
8907 else if (unformat (i, "buckets %d", &nbuckets))
8908 ;
8909 else if (unformat (i, "memory_size %d", &memory_size))
8910 ;
8911 else if (unformat (i, "skip %d", &skip))
8912 ;
8913 else if (unformat (i, "match %d", &match))
8914 ;
8915 else if (unformat (i, "table %d", &table_index))
8916 ;
8917 else if (unformat (i, "mask %U", unformat_classify_mask,
8918 &mask, &skip, &match))
8919 ;
8920 else if (unformat (i, "next-table %d", &next_table_index))
8921 ;
8922 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8923 &miss_next_index))
8924 ;
8925 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8926 &miss_next_index))
8927 ;
8928 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8929 &miss_next_index))
8930 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08008931 else if (unformat (i, "current-data-flag %d", &current_data_flag))
8932 ;
8933 else if (unformat (i, "current-data-offset %d", &current_data_offset))
8934 ;
Dave Barach72d72232016-08-04 10:15:08 -04008935 else
8936 break;
8937 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008938
Dave Barach72d72232016-08-04 10:15:08 -04008939 if (is_add && mask == 0)
8940 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008941 errmsg ("Mask required\n");
8942 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008943 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008944
Dave Barach72d72232016-08-04 10:15:08 -04008945 if (is_add && skip == ~0)
8946 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008947 errmsg ("skip count required\n");
8948 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008949 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008950
Dave Barach72d72232016-08-04 10:15:08 -04008951 if (is_add && match == ~0)
8952 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008953 errmsg ("match count required\n");
8954 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008955 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008956
Dave Barach72d72232016-08-04 10:15:08 -04008957 if (!is_add && table_index == ~0)
8958 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008959 errmsg ("table index required for delete\n");
8960 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008961 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008962
Dave Barach72d72232016-08-04 10:15:08 -04008963 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008964
8965 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008966 mp->table_index = ntohl (table_index);
8967 mp->nbuckets = ntohl (nbuckets);
8968 mp->memory_size = ntohl (memory_size);
8969 mp->skip_n_vectors = ntohl (skip);
8970 mp->match_n_vectors = ntohl (match);
8971 mp->next_table_index = ntohl (next_table_index);
8972 mp->miss_next_index = ntohl (miss_next_index);
Steve Shin25e26dc2016-11-08 10:47:10 -08008973 mp->current_data_flag = ntohl (current_data_flag);
8974 mp->current_data_offset = ntohl (current_data_offset);
Dave Barach72d72232016-08-04 10:15:08 -04008975 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008976
Dave Barach72d72232016-08-04 10:15:08 -04008977 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008978
Dave Barach72d72232016-08-04 10:15:08 -04008979 S;
8980 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008981 /* NOTREACHED */
8982}
8983
Dave Barach72d72232016-08-04 10:15:08 -04008984uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008985unformat_l4_match (unformat_input_t * input, va_list * args)
8986{
8987 u8 **matchp = va_arg (*args, u8 **);
8988
8989 u8 *proto_header = 0;
8990 int src_port = 0;
8991 int dst_port = 0;
8992
8993 tcpudp_header_t h;
8994
8995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8996 {
8997 if (unformat (input, "src_port %d", &src_port))
8998 ;
8999 else if (unformat (input, "dst_port %d", &dst_port))
9000 ;
9001 else
9002 return 0;
9003 }
9004
9005 h.src_port = clib_host_to_net_u16 (src_port);
9006 h.dst_port = clib_host_to_net_u16 (dst_port);
9007 vec_validate (proto_header, sizeof (h) - 1);
9008 memcpy (proto_header, &h, sizeof (h));
9009
9010 *matchp = proto_header;
9011
9012 return 1;
9013}
9014
9015uword
Dave Barach72d72232016-08-04 10:15:08 -04009016unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009017{
Dave Barach72d72232016-08-04 10:15:08 -04009018 u8 **matchp = va_arg (*args, u8 **);
9019 u8 *match = 0;
9020 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009021 int version = 0;
9022 u32 version_val;
9023 int hdr_length = 0;
9024 u32 hdr_length_val;
9025 int src = 0, dst = 0;
9026 ip4_address_t src_val, dst_val;
9027 int proto = 0;
9028 u32 proto_val;
9029 int tos = 0;
9030 u32 tos_val;
9031 int length = 0;
9032 u32 length_val;
9033 int fragment_id = 0;
9034 u32 fragment_id_val;
9035 int ttl = 0;
9036 int ttl_val;
9037 int checksum = 0;
9038 u32 checksum_val;
9039
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009040 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009041 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009042 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04009043 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009044 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009045 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009046 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04009047 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009048 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04009049 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009050 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04009051 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009052 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04009053 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009054 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009055 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009056 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04009057 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009058 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04009059 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009060 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04009061 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009062 else
Dave Barach72d72232016-08-04 10:15:08 -04009063 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009064 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009065
Ed Warnickecb9cada2015-12-08 15:45:58 -07009066 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
9067 + ttl + checksum == 0)
9068 return 0;
9069
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009070 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009071 * Aligned because we use the real comparison functions
9072 */
Dave Barach72d72232016-08-04 10:15:08 -04009073 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009074
Ed Warnickecb9cada2015-12-08 15:45:58 -07009075 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009076
Ed Warnickecb9cada2015-12-08 15:45:58 -07009077 /* These are realistically matched in practice */
9078 if (src)
9079 ip->src_address.as_u32 = src_val.as_u32;
9080
9081 if (dst)
9082 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009083
Ed Warnickecb9cada2015-12-08 15:45:58 -07009084 if (proto)
9085 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009086
Ed Warnickecb9cada2015-12-08 15:45:58 -07009087
9088 /* These are not, but they're included for completeness */
9089 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04009090 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009091
9092 if (hdr_length)
9093 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009094
Ed Warnickecb9cada2015-12-08 15:45:58 -07009095 if (tos)
9096 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009097
Ed Warnickecb9cada2015-12-08 15:45:58 -07009098 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009099 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009100
Ed Warnickecb9cada2015-12-08 15:45:58 -07009101 if (ttl)
9102 ip->ttl = ttl_val;
9103
9104 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009105 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009106
9107 *matchp = match;
9108 return 1;
9109}
9110
Dave Barach72d72232016-08-04 10:15:08 -04009111uword
9112unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009113{
Dave Barach72d72232016-08-04 10:15:08 -04009114 u8 **matchp = va_arg (*args, u8 **);
9115 u8 *match = 0;
9116 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009117 int version = 0;
9118 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04009119 u8 traffic_class = 0;
9120 u32 traffic_class_val = 0;
9121 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009122 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009123 int src = 0, dst = 0;
9124 ip6_address_t src_val, dst_val;
9125 int proto = 0;
9126 u32 proto_val;
9127 int payload_length = 0;
9128 u32 payload_length_val;
9129 int hop_limit = 0;
9130 int hop_limit_val;
9131 u32 ip_version_traffic_class_and_flow_label;
9132
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009133 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009134 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009135 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04009136 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009137 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04009138 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009139 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04009140 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009141 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04009142 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009143 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04009144 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009145 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04009146 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009147 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009148 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009149 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04009150 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009151 else
Dave Barach72d72232016-08-04 10:15:08 -04009152 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009153 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009154
Ed Warnickecb9cada2015-12-08 15:45:58 -07009155 if (version + traffic_class + flow_label + src + dst + proto +
9156 payload_length + hop_limit == 0)
9157 return 0;
9158
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009159 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160 * Aligned because we use the real comparison functions
9161 */
Dave Barach72d72232016-08-04 10:15:08 -04009162 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009163
Ed Warnickecb9cada2015-12-08 15:45:58 -07009164 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009165
Ed Warnickecb9cada2015-12-08 15:45:58 -07009166 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009167 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009168
9169 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009170 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009171
Ed Warnickecb9cada2015-12-08 15:45:58 -07009172 if (proto)
9173 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009174
Ed Warnickecb9cada2015-12-08 15:45:58 -07009175 ip_version_traffic_class_and_flow_label = 0;
9176
9177 if (version)
9178 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
9179
9180 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04009181 ip_version_traffic_class_and_flow_label |=
9182 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009183
9184 if (flow_label)
9185 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009186
9187 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07009188 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9189
9190 if (payload_length)
9191 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009192
Ed Warnickecb9cada2015-12-08 15:45:58 -07009193 if (hop_limit)
9194 ip->hop_limit = hop_limit_val;
9195
9196 *matchp = match;
9197 return 1;
9198}
9199
Dave Barach72d72232016-08-04 10:15:08 -04009200uword
9201unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009202{
Dave Barach72d72232016-08-04 10:15:08 -04009203 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009204
Dave Barach72d72232016-08-04 10:15:08 -04009205 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9206 {
9207 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9208 return 1;
9209 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9210 return 1;
9211 else
9212 break;
9213 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009214 return 0;
9215}
9216
Dave Barach72d72232016-08-04 10:15:08 -04009217uword
9218unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009219{
Dave Barach72d72232016-08-04 10:15:08 -04009220 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009221 u32 tag;
9222
Dave Barach72d72232016-08-04 10:15:08 -04009223 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009224 {
Dave Barach72d72232016-08-04 10:15:08 -04009225 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009226 tagp[1] = tag & 0xFF;
9227 return 1;
9228 }
9229
9230 return 0;
9231}
9232
Dave Barach72d72232016-08-04 10:15:08 -04009233uword
9234unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009235{
Dave Barach72d72232016-08-04 10:15:08 -04009236 u8 **matchp = va_arg (*args, u8 **);
9237 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009238 u8 src = 0;
9239 u8 src_val[6];
9240 u8 dst = 0;
9241 u8 dst_val[6];
9242 u8 proto = 0;
9243 u16 proto_val;
9244 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009245 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009246 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009247 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009248 int len = 14;
9249 u8 ignore_tag1 = 0;
9250 u8 ignore_tag2 = 0;
9251 u8 cos1 = 0;
9252 u8 cos2 = 0;
9253 u32 cos1_val = 0;
9254 u32 cos2_val = 0;
9255
Dave Barach72d72232016-08-04 10:15:08 -04009256 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9257 {
9258 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9259 src = 1;
9260 else
9261 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9262 dst = 1;
9263 else if (unformat (input, "proto %U",
9264 unformat_ethernet_type_host_byte_order, &proto_val))
9265 proto = 1;
9266 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9267 tag1 = 1;
9268 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9269 tag2 = 1;
9270 else if (unformat (input, "ignore-tag1"))
9271 ignore_tag1 = 1;
9272 else if (unformat (input, "ignore-tag2"))
9273 ignore_tag2 = 1;
9274 else if (unformat (input, "cos1 %d", &cos1_val))
9275 cos1 = 1;
9276 else if (unformat (input, "cos2 %d", &cos2_val))
9277 cos2 = 1;
9278 else
9279 break;
9280 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009281 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009282 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009283 return 0;
9284
9285 if (tag1 || ignore_tag1 || cos1)
9286 len = 18;
9287 if (tag2 || ignore_tag2 || cos2)
9288 len = 22;
9289
Dave Barach72d72232016-08-04 10:15:08 -04009290 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009291
9292 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009293 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009294
9295 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009296 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009297
Ed Warnickecb9cada2015-12-08 15:45:58 -07009298 if (tag2)
9299 {
9300 /* inner vlan tag */
9301 match[19] = tag2_val[1];
9302 match[18] = tag2_val[0];
9303 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009304 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009305 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009306 {
9307 match[21] = proto_val & 0xff;
9308 match[20] = proto_val >> 8;
9309 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009310 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009311 {
9312 match[15] = tag1_val[1];
9313 match[14] = tag1_val[0];
9314 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009315 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009316 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009317 *matchp = match;
9318 return 1;
9319 }
9320 if (tag1)
9321 {
Dave Barach72d72232016-08-04 10:15:08 -04009322 match[15] = tag1_val[1];
9323 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009324 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009325 {
9326 match[17] = proto_val & 0xff;
9327 match[16] = proto_val >> 8;
9328 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009329 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009330 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009331
9332 *matchp = match;
9333 return 1;
9334 }
9335 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009336 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009337 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009338 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009339 if (proto)
9340 {
9341 match[13] = proto_val & 0xff;
9342 match[12] = proto_val >> 8;
9343 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009344
Ed Warnickecb9cada2015-12-08 15:45:58 -07009345 *matchp = match;
9346 return 1;
9347}
9348
9349
Dave Barach72d72232016-08-04 10:15:08 -04009350uword
9351unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009352{
Dave Barach72d72232016-08-04 10:15:08 -04009353 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009354 u32 skip_n_vectors = va_arg (*args, u32);
9355 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009356
Dave Barach72d72232016-08-04 10:15:08 -04009357 u8 *match = 0;
9358 u8 *l2 = 0;
9359 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009360 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009361
Dave Barach72d72232016-08-04 10:15:08 -04009362 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9363 {
9364 if (unformat (input, "hex %U", unformat_hex_string, &match))
9365 ;
9366 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9367 ;
9368 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9369 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009370 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9371 ;
Dave Barach72d72232016-08-04 10:15:08 -04009372 else
9373 break;
9374 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009375
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009376 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009377 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009378 vec_free (match);
9379 vec_free (l2);
9380 vec_free (l4);
9381 return 0;
9382 }
9383
9384 if (match || l2 || l3 || l4)
9385 {
9386 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009387 {
9388 /* "Win a free Ethernet header in every packet" */
9389 if (l2 == 0)
9390 vec_validate_aligned (l2, 13, sizeof (u32x4));
9391 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009392 if (vec_len (l3))
9393 {
9394 vec_append_aligned (match, l3, sizeof (u32x4));
9395 vec_free (l3);
9396 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009397 if (vec_len (l4))
9398 {
9399 vec_append_aligned (match, l4, sizeof (u32x4));
9400 vec_free (l4);
9401 }
Dave Barach72d72232016-08-04 10:15:08 -04009402 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009403
9404 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009405 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009406 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9407 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009408
Dave Barach72d72232016-08-04 10:15:08 -04009409 /* Set size, include skipped vectors */
9410 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009411
9412 *matchp = match;
9413
9414 return 1;
9415 }
9416
9417 return 0;
9418}
9419
Dave Barach72d72232016-08-04 10:15:08 -04009420static int
9421api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009422{
Dave Barach72d72232016-08-04 10:15:08 -04009423 unformat_input_t *i = vam->input;
9424 vl_api_classify_add_del_session_t *mp;
9425 int is_add = 1;
9426 u32 table_index = ~0;
9427 u32 hit_next_index = ~0;
9428 u32 opaque_index = ~0;
9429 u8 *match = 0;
9430 i32 advance = 0;
9431 f64 timeout;
9432 u32 skip_n_vectors = 0;
9433 u32 match_n_vectors = 0;
Steve Shin25e26dc2016-11-08 10:47:10 -08009434 u32 action = 0;
9435 u32 metadata = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009436
Dave Barach72d72232016-08-04 10:15:08 -04009437 /*
9438 * Warning: you have to supply skip_n and match_n
9439 * because the API client cant simply look at the classify
9440 * table object.
9441 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009442
Dave Barach72d72232016-08-04 10:15:08 -04009443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9444 {
9445 if (unformat (i, "del"))
9446 is_add = 0;
9447 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9448 &hit_next_index))
9449 ;
9450 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9451 &hit_next_index))
9452 ;
9453 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9454 &hit_next_index))
9455 ;
9456 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9457 ;
9458 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9459 ;
9460 else if (unformat (i, "opaque-index %d", &opaque_index))
9461 ;
9462 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9463 ;
9464 else if (unformat (i, "match_n %d", &match_n_vectors))
9465 ;
9466 else if (unformat (i, "match %U", unformat_classify_match,
9467 &match, skip_n_vectors, match_n_vectors))
9468 ;
9469 else if (unformat (i, "advance %d", &advance))
9470 ;
9471 else if (unformat (i, "table-index %d", &table_index))
9472 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08009473 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
9474 action = 1;
9475 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
9476 action = 2;
9477 else if (unformat (i, "action %d", &action))
9478 ;
9479 else if (unformat (i, "metadata %d", &metadata))
9480 ;
Dave Barach72d72232016-08-04 10:15:08 -04009481 else
9482 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009483 }
9484
Dave Barach72d72232016-08-04 10:15:08 -04009485 if (table_index == ~0)
9486 {
9487 errmsg ("Table index required\n");
9488 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009489 }
9490
Dave Barach72d72232016-08-04 10:15:08 -04009491 if (is_add && match == 0)
9492 {
9493 errmsg ("Match value required\n");
9494 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009495 }
9496
Dave Barach72d72232016-08-04 10:15:08 -04009497 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009498
Dave Barach72d72232016-08-04 10:15:08 -04009499 mp->is_add = is_add;
9500 mp->table_index = ntohl (table_index);
9501 mp->hit_next_index = ntohl (hit_next_index);
9502 mp->opaque_index = ntohl (opaque_index);
9503 mp->advance = ntohl (advance);
Steve Shin25e26dc2016-11-08 10:47:10 -08009504 mp->action = action;
9505 mp->metadata = ntohl (metadata);
Dave Barach72d72232016-08-04 10:15:08 -04009506 clib_memcpy (mp->match, match, vec_len (match));
9507 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009508
Dave Barach72d72232016-08-04 10:15:08 -04009509 S;
9510 W;
9511 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009512}
9513
Dave Barach72d72232016-08-04 10:15:08 -04009514static int
9515api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009516{
Dave Barach72d72232016-08-04 10:15:08 -04009517 unformat_input_t *i = vam->input;
9518 vl_api_classify_set_interface_ip_table_t *mp;
9519 f64 timeout;
9520 u32 sw_if_index;
9521 int sw_if_index_set;
9522 u32 table_index = ~0;
9523 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009524
Dave Barach72d72232016-08-04 10:15:08 -04009525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9526 {
9527 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9528 sw_if_index_set = 1;
9529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9530 sw_if_index_set = 1;
9531 else if (unformat (i, "table %d", &table_index))
9532 ;
9533 else
9534 {
9535 clib_warning ("parse error '%U'", format_unformat_error, i);
9536 return -99;
9537 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009538 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009539
Dave Barach72d72232016-08-04 10:15:08 -04009540 if (sw_if_index_set == 0)
9541 {
9542 errmsg ("missing interface name or sw_if_index\n");
9543 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009544 }
9545
9546
Dave Barach72d72232016-08-04 10:15:08 -04009547 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009548
Dave Barach72d72232016-08-04 10:15:08 -04009549 mp->sw_if_index = ntohl (sw_if_index);
9550 mp->table_index = ntohl (table_index);
9551 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009552
Dave Barach72d72232016-08-04 10:15:08 -04009553 S;
9554 W;
9555 /* NOTREACHED */
9556 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009557}
9558
Dave Barach72d72232016-08-04 10:15:08 -04009559static int
9560api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009561{
Dave Barach72d72232016-08-04 10:15:08 -04009562 unformat_input_t *i = vam->input;
9563 vl_api_classify_set_interface_l2_tables_t *mp;
9564 f64 timeout;
9565 u32 sw_if_index;
9566 int sw_if_index_set;
9567 u32 ip4_table_index = ~0;
9568 u32 ip6_table_index = ~0;
9569 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009570 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009571
Dave Barach72d72232016-08-04 10:15:08 -04009572 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9573 {
9574 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9575 sw_if_index_set = 1;
9576 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9577 sw_if_index_set = 1;
9578 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9579 ;
9580 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9581 ;
9582 else if (unformat (i, "other-table %d", &other_table_index))
9583 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009584 else if (unformat (i, "is-input %d", &is_input))
9585 ;
Dave Barach72d72232016-08-04 10:15:08 -04009586 else
9587 {
9588 clib_warning ("parse error '%U'", format_unformat_error, i);
9589 return -99;
9590 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009591 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009592
Dave Barach72d72232016-08-04 10:15:08 -04009593 if (sw_if_index_set == 0)
9594 {
9595 errmsg ("missing interface name or sw_if_index\n");
9596 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009597 }
9598
9599
Dave Barach72d72232016-08-04 10:15:08 -04009600 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009601
Dave Barach72d72232016-08-04 10:15:08 -04009602 mp->sw_if_index = ntohl (sw_if_index);
9603 mp->ip4_table_index = ntohl (ip4_table_index);
9604 mp->ip6_table_index = ntohl (ip6_table_index);
9605 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009606 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009607
Dave Barach72d72232016-08-04 10:15:08 -04009608 S;
9609 W;
9610 /* NOTREACHED */
9611 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009612}
9613
Dave Barach72d72232016-08-04 10:15:08 -04009614static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009615api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009616{
Dave Barach72d72232016-08-04 10:15:08 -04009617 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009618 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009619 ip4_address_t collector_address;
9620 u8 collector_address_set = 0;
9621 u32 collector_port = ~0;
9622 ip4_address_t src_address;
9623 u8 src_address_set = 0;
9624 u32 vrf_id = ~0;
9625 u32 path_mtu = ~0;
9626 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009627 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009628 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009629
Dave Barach72d72232016-08-04 10:15:08 -04009630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9631 {
9632 if (unformat (i, "collector_address %U", unformat_ip4_address,
9633 &collector_address))
9634 collector_address_set = 1;
9635 else if (unformat (i, "collector_port %d", &collector_port))
9636 ;
9637 else if (unformat (i, "src_address %U", unformat_ip4_address,
9638 &src_address))
9639 src_address_set = 1;
9640 else if (unformat (i, "vrf_id %d", &vrf_id))
9641 ;
9642 else if (unformat (i, "path_mtu %d", &path_mtu))
9643 ;
9644 else if (unformat (i, "template_interval %d", &template_interval))
9645 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009646 else if (unformat (i, "udp_checksum"))
9647 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009648 else
9649 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009650 }
9651
Dave Barach72d72232016-08-04 10:15:08 -04009652 if (collector_address_set == 0)
9653 {
9654 errmsg ("collector_address required\n");
9655 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009656 }
9657
Dave Barach72d72232016-08-04 10:15:08 -04009658 if (src_address_set == 0)
9659 {
9660 errmsg ("src_address required\n");
9661 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009662 }
9663
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009664 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009665
Dave Barach72d72232016-08-04 10:15:08 -04009666 memcpy (mp->collector_address, collector_address.data,
9667 sizeof (collector_address.data));
9668 mp->collector_port = htons ((u16) collector_port);
9669 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9670 mp->vrf_id = htonl (vrf_id);
9671 mp->path_mtu = htonl (path_mtu);
9672 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009673 mp->udp_checksum = udp_checksum;
9674
9675 S;
9676 W;
9677 /* NOTREACHED */
9678}
9679
9680static int
9681api_set_ipfix_classify_stream (vat_main_t * vam)
9682{
9683 unformat_input_t *i = vam->input;
9684 vl_api_set_ipfix_classify_stream_t *mp;
9685 u32 domain_id = 0;
9686 u32 src_port = UDP_DST_PORT_ipfix;
9687 f64 timeout;
9688
9689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9690 {
9691 if (unformat (i, "domain %d", &domain_id))
9692 ;
9693 else if (unformat (i, "src_port %d", &src_port))
9694 ;
9695 else
9696 {
9697 errmsg ("unknown input `%U'", format_unformat_error, i);
9698 return -99;
9699 }
9700 }
9701
9702 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9703
9704 mp->domain_id = htonl (domain_id);
9705 mp->src_port = htons ((u16) src_port);
9706
9707 S;
9708 W;
9709 /* NOTREACHED */
9710}
9711
9712static int
9713api_ipfix_classify_table_add_del (vat_main_t * vam)
9714{
9715 unformat_input_t *i = vam->input;
9716 vl_api_ipfix_classify_table_add_del_t *mp;
9717 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009718 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009719 u8 ip_version = 0;
9720 u8 transport_protocol = 255;
9721 f64 timeout;
9722
9723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9724 {
9725 if (unformat (i, "add"))
9726 is_add = 1;
9727 else if (unformat (i, "del"))
9728 is_add = 0;
9729 else if (unformat (i, "table %d", &classify_table_index))
9730 ;
9731 else if (unformat (i, "ip4"))
9732 ip_version = 4;
9733 else if (unformat (i, "ip6"))
9734 ip_version = 6;
9735 else if (unformat (i, "tcp"))
9736 transport_protocol = 6;
9737 else if (unformat (i, "udp"))
9738 transport_protocol = 17;
9739 else
9740 {
9741 errmsg ("unknown input `%U'", format_unformat_error, i);
9742 return -99;
9743 }
9744 }
9745
9746 if (is_add == -1)
9747 {
9748 errmsg ("expecting: add|del");
9749 return -99;
9750 }
9751 if (classify_table_index == ~0)
9752 {
9753 errmsg ("classifier table not specified");
9754 return -99;
9755 }
9756 if (ip_version == 0)
9757 {
9758 errmsg ("IP version not specified");
9759 return -99;
9760 }
9761
9762 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9763
9764 mp->is_add = is_add;
9765 mp->table_id = htonl (classify_table_index);
9766 mp->ip_version = ip_version;
9767 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009768
Dave Barach72d72232016-08-04 10:15:08 -04009769 S;
9770 W;
9771 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009772}
9773
Dave Barach72d72232016-08-04 10:15:08 -04009774static int
9775api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009776{
Dave Barach72d72232016-08-04 10:15:08 -04009777 unformat_input_t *i = vam->input;
9778 vl_api_get_node_index_t *mp;
9779 f64 timeout;
9780 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009781
Dave Barach72d72232016-08-04 10:15:08 -04009782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9783 {
9784 if (unformat (i, "node %s", &name))
9785 ;
9786 else
9787 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009788 }
Dave Barach72d72232016-08-04 10:15:08 -04009789 if (name == 0)
9790 {
9791 errmsg ("node name required\n");
9792 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009793 }
Dave Barach72d72232016-08-04 10:15:08 -04009794 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9795 {
9796 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9797 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009798 }
9799
Dave Barach72d72232016-08-04 10:15:08 -04009800 M (GET_NODE_INDEX, get_node_index);
9801 clib_memcpy (mp->node_name, name, vec_len (name));
9802 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009803
Dave Barach72d72232016-08-04 10:15:08 -04009804 S;
9805 W;
9806 /* NOTREACHED */
9807 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009808}
9809
Dave Barach72d72232016-08-04 10:15:08 -04009810static int
9811api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009812{
Dave Barach72d72232016-08-04 10:15:08 -04009813 unformat_input_t *i = vam->input;
9814 vl_api_get_next_index_t *mp;
9815 f64 timeout;
9816 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009817
Dave Barach72d72232016-08-04 10:15:08 -04009818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9819 {
9820 if (unformat (i, "node-name %s", &node_name))
9821 ;
9822 else if (unformat (i, "next-node-name %s", &next_node_name))
9823 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009824 }
9825
Dave Barach72d72232016-08-04 10:15:08 -04009826 if (node_name == 0)
9827 {
9828 errmsg ("node name required\n");
9829 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009830 }
Dave Barach72d72232016-08-04 10:15:08 -04009831 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9832 {
9833 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9834 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009835 }
9836
Dave Barach72d72232016-08-04 10:15:08 -04009837 if (next_node_name == 0)
9838 {
9839 errmsg ("next node name required\n");
9840 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009841 }
Dave Barach72d72232016-08-04 10:15:08 -04009842 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9843 {
9844 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9845 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009846 }
9847
Dave Barach72d72232016-08-04 10:15:08 -04009848 M (GET_NEXT_INDEX, get_next_index);
9849 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9850 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9851 vec_free (node_name);
9852 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009853
Dave Barach72d72232016-08-04 10:15:08 -04009854 S;
9855 W;
9856 /* NOTREACHED */
9857 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009858}
9859
Dave Barach72d72232016-08-04 10:15:08 -04009860static int
9861api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009862{
Dave Barach72d72232016-08-04 10:15:08 -04009863 unformat_input_t *i = vam->input;
9864 vl_api_add_node_next_t *mp;
9865 f64 timeout;
9866 u8 *name = 0;
9867 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009868
Dave Barach72d72232016-08-04 10:15:08 -04009869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9870 {
9871 if (unformat (i, "node %s", &name))
9872 ;
9873 else if (unformat (i, "next %s", &next))
9874 ;
9875 else
9876 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009877 }
Dave Barach72d72232016-08-04 10:15:08 -04009878 if (name == 0)
9879 {
9880 errmsg ("node name required\n");
9881 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009882 }
Dave Barach72d72232016-08-04 10:15:08 -04009883 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9884 {
9885 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9886 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009887 }
Dave Barach72d72232016-08-04 10:15:08 -04009888 if (next == 0)
9889 {
9890 errmsg ("next node required\n");
9891 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009892 }
Dave Barach72d72232016-08-04 10:15:08 -04009893 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9894 {
9895 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9896 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009897 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009898
Dave Barach72d72232016-08-04 10:15:08 -04009899 M (ADD_NODE_NEXT, add_node_next);
9900 clib_memcpy (mp->node_name, name, vec_len (name));
9901 clib_memcpy (mp->next_name, next, vec_len (next));
9902 vec_free (name);
9903 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009904
Dave Barach72d72232016-08-04 10:15:08 -04009905 S;
9906 W;
9907 /* NOTREACHED */
9908 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009909}
9910
Dave Barach72d72232016-08-04 10:15:08 -04009911static int
9912api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009913{
Dave Barach72d72232016-08-04 10:15:08 -04009914 unformat_input_t *i = vam->input;
9915 ip6_address_t client_address, our_address;
9916 int client_address_set = 0;
9917 int our_address_set = 0;
9918 u32 local_session_id = 0;
9919 u32 remote_session_id = 0;
9920 u64 local_cookie = 0;
9921 u64 remote_cookie = 0;
9922 u8 l2_sublayer_present = 0;
9923 vl_api_l2tpv3_create_tunnel_t *mp;
9924 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009925
Dave Barach72d72232016-08-04 10:15:08 -04009926 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9927 {
9928 if (unformat (i, "client_address %U", unformat_ip6_address,
9929 &client_address))
9930 client_address_set = 1;
9931 else if (unformat (i, "our_address %U", unformat_ip6_address,
9932 &our_address))
9933 our_address_set = 1;
9934 else if (unformat (i, "local_session_id %d", &local_session_id))
9935 ;
9936 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9937 ;
9938 else if (unformat (i, "local_cookie %lld", &local_cookie))
9939 ;
9940 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9941 ;
9942 else if (unformat (i, "l2-sublayer-present"))
9943 l2_sublayer_present = 1;
9944 else
9945 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009946 }
9947
Dave Barach72d72232016-08-04 10:15:08 -04009948 if (client_address_set == 0)
9949 {
9950 errmsg ("client_address required\n");
9951 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009952 }
9953
Dave Barach72d72232016-08-04 10:15:08 -04009954 if (our_address_set == 0)
9955 {
9956 errmsg ("our_address required\n");
9957 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009958 }
9959
Dave Barach72d72232016-08-04 10:15:08 -04009960 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009961
Dave Barach72d72232016-08-04 10:15:08 -04009962 clib_memcpy (mp->client_address, client_address.as_u8,
9963 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009964
Dave Barach72d72232016-08-04 10:15:08 -04009965 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009966
Dave Barach72d72232016-08-04 10:15:08 -04009967 mp->local_session_id = ntohl (local_session_id);
9968 mp->remote_session_id = ntohl (remote_session_id);
9969 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9970 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9971 mp->l2_sublayer_present = l2_sublayer_present;
9972 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009973
Dave Barach72d72232016-08-04 10:15:08 -04009974 S;
9975 W;
9976 /* NOTREACHED */
9977 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009978}
9979
Dave Barach72d72232016-08-04 10:15:08 -04009980static int
9981api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009982{
Dave Barach72d72232016-08-04 10:15:08 -04009983 unformat_input_t *i = vam->input;
9984 u32 sw_if_index;
9985 u8 sw_if_index_set = 0;
9986 u64 new_local_cookie = 0;
9987 u64 new_remote_cookie = 0;
9988 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9989 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009990
Dave Barach72d72232016-08-04 10:15:08 -04009991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9992 {
9993 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9994 sw_if_index_set = 1;
9995 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9996 sw_if_index_set = 1;
9997 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9998 ;
9999 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
10000 ;
10001 else
10002 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010003 }
10004
Dave Barach72d72232016-08-04 10:15:08 -040010005 if (sw_if_index_set == 0)
10006 {
10007 errmsg ("missing interface name or sw_if_index\n");
10008 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010009 }
10010
Dave Barach72d72232016-08-04 10:15:08 -040010011 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010012
Dave Barach72d72232016-08-04 10:15:08 -040010013 mp->sw_if_index = ntohl (sw_if_index);
10014 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
10015 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010016
Dave Barach72d72232016-08-04 10:15:08 -040010017 S;
10018 W;
10019 /* NOTREACHED */
10020 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010021}
10022
Dave Barach72d72232016-08-04 10:15:08 -040010023static int
10024api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010025{
Dave Barach72d72232016-08-04 10:15:08 -040010026 unformat_input_t *i = vam->input;
10027 vl_api_l2tpv3_interface_enable_disable_t *mp;
10028 f64 timeout;
10029 u32 sw_if_index;
10030 u8 sw_if_index_set = 0;
10031 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010032
Dave Barach72d72232016-08-04 10:15:08 -040010033 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10034 {
10035 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10036 sw_if_index_set = 1;
10037 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10038 sw_if_index_set = 1;
10039 else if (unformat (i, "enable"))
10040 enable_disable = 1;
10041 else if (unformat (i, "disable"))
10042 enable_disable = 0;
10043 else
10044 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010045 }
10046
Dave Barach72d72232016-08-04 10:15:08 -040010047 if (sw_if_index_set == 0)
10048 {
10049 errmsg ("missing interface name or sw_if_index\n");
10050 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010051 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010052
Dave Barach72d72232016-08-04 10:15:08 -040010053 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010054
Dave Barach72d72232016-08-04 10:15:08 -040010055 mp->sw_if_index = ntohl (sw_if_index);
10056 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010057
Dave Barach72d72232016-08-04 10:15:08 -040010058 S;
10059 W;
10060 /* NOTREACHED */
10061 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010062}
10063
Dave Barach72d72232016-08-04 10:15:08 -040010064static int
10065api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010066{
Dave Barach72d72232016-08-04 10:15:08 -040010067 unformat_input_t *i = vam->input;
10068 vl_api_l2tpv3_set_lookup_key_t *mp;
10069 f64 timeout;
10070 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010071
Dave Barach72d72232016-08-04 10:15:08 -040010072 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10073 {
10074 if (unformat (i, "lookup_v6_src"))
10075 key = L2T_LOOKUP_SRC_ADDRESS;
10076 else if (unformat (i, "lookup_v6_dst"))
10077 key = L2T_LOOKUP_DST_ADDRESS;
10078 else if (unformat (i, "lookup_session_id"))
10079 key = L2T_LOOKUP_SESSION_ID;
10080 else
10081 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010082 }
10083
Dave Barach72d72232016-08-04 10:15:08 -040010084 if (key == (u8) ~ 0)
10085 {
10086 errmsg ("l2tp session lookup key unset\n");
10087 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010088 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010089
Dave Barach72d72232016-08-04 10:15:08 -040010090 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010091
Dave Barach72d72232016-08-04 10:15:08 -040010092 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010093
Dave Barach72d72232016-08-04 10:15:08 -040010094 S;
10095 W;
10096 /* NOTREACHED */
10097 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010098}
10099
10100static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010101 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010102{
Dave Barach72d72232016-08-04 10:15:08 -040010103 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010104
Dave Barach72d72232016-08-04 10:15:08 -040010105 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
10106 format_ip6_address, mp->our_address,
10107 format_ip6_address, mp->client_address,
10108 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010109
Dave Barach72d72232016-08-04 10:15:08 -040010110 fformat (vam->ofp,
10111 " local cookies %016llx %016llx remote cookie %016llx\n",
10112 clib_net_to_host_u64 (mp->local_cookie[0]),
10113 clib_net_to_host_u64 (mp->local_cookie[1]),
10114 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010115
Dave Barach72d72232016-08-04 10:15:08 -040010116 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
10117 clib_net_to_host_u32 (mp->local_session_id),
10118 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010119
Dave Barach72d72232016-08-04 10:15:08 -040010120 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
10121 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010122
10123}
10124
10125static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010126 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010127{
Dave Barach72d72232016-08-04 10:15:08 -040010128 vat_main_t *vam = &vat_main;
10129 vat_json_node_t *node = NULL;
10130 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010131
Dave Barach72d72232016-08-04 10:15:08 -040010132 if (VAT_JSON_ARRAY != vam->json_tree.type)
10133 {
10134 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10135 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010136 }
Dave Barach72d72232016-08-04 10:15:08 -040010137 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010138
Dave Barach72d72232016-08-04 10:15:08 -040010139 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010140
Dave Barach72d72232016-08-04 10:15:08 -040010141 clib_memcpy (&addr, mp->our_address, sizeof (addr));
10142 vat_json_object_add_ip6 (node, "our_address", addr);
10143 clib_memcpy (&addr, mp->client_address, sizeof (addr));
10144 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010145
Dave Barach72d72232016-08-04 10:15:08 -040010146 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
10147 vat_json_init_array (lc);
10148 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
10149 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
10150 vat_json_object_add_uint (node, "remote_cookie",
10151 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010152
Dave Barach72d72232016-08-04 10:15:08 -040010153 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
10154 vat_json_object_add_uint (node, "local_session_id",
10155 clib_net_to_host_u32 (mp->local_session_id));
10156 vat_json_object_add_uint (node, "remote_session_id",
10157 clib_net_to_host_u32 (mp->remote_session_id));
10158 vat_json_object_add_string_copy (node, "l2_sublayer",
10159 mp->l2_sublayer_present ? (u8 *) "present"
10160 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010161}
10162
Dave Barach72d72232016-08-04 10:15:08 -040010163static int
10164api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010165{
Dave Barach72d72232016-08-04 10:15:08 -040010166 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
10167 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168
Dave Barach72d72232016-08-04 10:15:08 -040010169 /* Get list of l2tpv3-tunnel interfaces */
10170 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
10171 S;
10172
10173 /* Use a control ping for synchronization */
10174 {
10175 vl_api_control_ping_t *mp;
10176 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010177 S;
Dave Barach72d72232016-08-04 10:15:08 -040010178 }
10179 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010180}
10181
10182
10183static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010184 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010185{
Dave Barach72d72232016-08-04 10:15:08 -040010186 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010187
Dave Barach72d72232016-08-04 10:15:08 -040010188 fformat (vam->ofp, "%-16s %d\n",
10189 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010190}
10191
10192static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010193 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010194{
Dave Barach72d72232016-08-04 10:15:08 -040010195 vat_main_t *vam = &vat_main;
10196 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010197
Dave Barach72d72232016-08-04 10:15:08 -040010198 if (VAT_JSON_ARRAY != vam->json_tree.type)
10199 {
10200 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10201 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010202 }
Dave Barach72d72232016-08-04 10:15:08 -040010203 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010204
Dave Barach72d72232016-08-04 10:15:08 -040010205 vat_json_init_object (node);
10206 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10207 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010208}
10209
Dave Barach72d72232016-08-04 10:15:08 -040010210static int
10211api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010212{
Dave Barach72d72232016-08-04 10:15:08 -040010213 vl_api_sw_interface_tap_dump_t *mp;
10214 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010215
Dave Barach72d72232016-08-04 10:15:08 -040010216 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10217 /* Get list of tap interfaces */
10218 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10219 S;
10220
10221 /* Use a control ping for synchronization */
10222 {
10223 vl_api_control_ping_t *mp;
10224 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010225 S;
Dave Barach72d72232016-08-04 10:15:08 -040010226 }
10227 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010228}
10229
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010230static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010231 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010232{
Dave Barach72d72232016-08-04 10:15:08 -040010233 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010234 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010235
John Loc42912d2016-11-07 18:30:47 -050010236 if (unformat (input, "l2"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070010237 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10238 else if (unformat (input, "%d", &tmp))
10239 *result = tmp;
10240 else
10241 return 0;
10242 return 1;
10243}
10244
Dave Barach72d72232016-08-04 10:15:08 -040010245static int
10246api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010247{
Dave Barach72d72232016-08-04 10:15:08 -040010248 unformat_input_t *line_input = vam->input;
10249 vl_api_vxlan_add_del_tunnel_t *mp;
10250 f64 timeout;
Eyal Baric5b13602016-11-24 19:42:43 +020010251 ip46_address_t src, dst;
Dave Barach72d72232016-08-04 10:15:08 -040010252 u8 is_add = 1;
10253 u8 ipv4_set = 0, ipv6_set = 0;
10254 u8 src_set = 0;
10255 u8 dst_set = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010256 u8 grp_set = 0;
10257 u32 mcast_sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040010258 u32 encap_vrf_id = 0;
10259 u32 decap_next_index = ~0;
10260 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010261
Eyal Baric5b13602016-11-24 19:42:43 +020010262 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
10263 memset (&src, 0, sizeof src);
10264 memset (&dst, 0, sizeof dst);
10265
Dave Barach72d72232016-08-04 10:15:08 -040010266 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10267 {
10268 if (unformat (line_input, "del"))
10269 is_add = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010270 else
10271 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010272 {
10273 ipv4_set = 1;
10274 src_set = 1;
10275 }
Eyal Baric5b13602016-11-24 19:42:43 +020010276 else
10277 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010278 {
10279 ipv4_set = 1;
10280 dst_set = 1;
10281 }
Eyal Baric5b13602016-11-24 19:42:43 +020010282 else
10283 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010284 {
10285 ipv6_set = 1;
10286 src_set = 1;
10287 }
Eyal Baric5b13602016-11-24 19:42:43 +020010288 else
10289 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010290 {
10291 ipv6_set = 1;
10292 dst_set = 1;
10293 }
Eyal Baric5b13602016-11-24 19:42:43 +020010294 else if (unformat (line_input, "group %U %U",
10295 unformat_ip4_address, &dst.ip4,
10296 unformat_sw_if_index, vam, &mcast_sw_if_index))
10297 {
10298 grp_set = dst_set = 1;
10299 ipv4_set = 1;
10300 }
10301 else if (unformat (line_input, "group %U",
10302 unformat_ip4_address, &dst.ip4))
10303 {
10304 grp_set = dst_set = 1;
10305 ipv4_set = 1;
10306 }
10307 else if (unformat (line_input, "group %U %U",
10308 unformat_ip6_address, &dst.ip6,
10309 unformat_sw_if_index, vam, &mcast_sw_if_index))
10310 {
10311 grp_set = dst_set = 1;
10312 ipv6_set = 1;
10313 }
10314 else if (unformat (line_input, "group %U",
10315 unformat_ip6_address, &dst.ip6))
10316 {
10317 grp_set = dst_set = 1;
10318 ipv6_set = 1;
10319 }
10320 else
10321 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10322 ;
Dave Barach72d72232016-08-04 10:15:08 -040010323 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10324 ;
10325 else if (unformat (line_input, "decap-next %U",
10326 unformat_vxlan_decap_next, &decap_next_index))
10327 ;
10328 else if (unformat (line_input, "vni %d", &vni))
10329 ;
10330 else
10331 {
10332 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10333 return -99;
10334 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010335 }
10336
Dave Barach72d72232016-08-04 10:15:08 -040010337 if (src_set == 0)
10338 {
10339 errmsg ("tunnel src address not specified\n");
10340 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010341 }
Dave Barach72d72232016-08-04 10:15:08 -040010342 if (dst_set == 0)
10343 {
10344 errmsg ("tunnel dst address not specified\n");
10345 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010346 }
10347
Eyal Baric5b13602016-11-24 19:42:43 +020010348 if (grp_set && !ip46_address_is_multicast (&dst))
10349 {
10350 errmsg ("tunnel group address not multicast\n");
10351 return -99;
10352 }
10353 if (grp_set && mcast_sw_if_index == ~0)
10354 {
10355 errmsg ("tunnel nonexistent multicast device\n");
10356 return -99;
10357 }
10358
10359
Dave Barach72d72232016-08-04 10:15:08 -040010360 if (ipv4_set && ipv6_set)
10361 {
10362 errmsg ("both IPv4 and IPv6 addresses specified");
10363 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010364 }
10365
Dave Barach72d72232016-08-04 10:15:08 -040010366 if ((vni == 0) || (vni >> 24))
10367 {
10368 errmsg ("vni not specified or out of range\n");
10369 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010370 }
10371
Dave Barach72d72232016-08-04 10:15:08 -040010372 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010373
Dave Barach72d72232016-08-04 10:15:08 -040010374 if (ipv6_set)
10375 {
Eyal Baric5b13602016-11-24 19:42:43 +020010376 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
10377 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
Chris Luke99cb3352016-04-26 10:49:53 -040010378 }
Dave Barach72d72232016-08-04 10:15:08 -040010379 else
10380 {
Eyal Baric5b13602016-11-24 19:42:43 +020010381 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
10382 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010383 }
10384 mp->encap_vrf_id = ntohl (encap_vrf_id);
10385 mp->decap_next_index = ntohl (decap_next_index);
Eyal Baric5b13602016-11-24 19:42:43 +020010386 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Dave Barach72d72232016-08-04 10:15:08 -040010387 mp->vni = ntohl (vni);
10388 mp->is_add = is_add;
10389 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010390
Dave Barach72d72232016-08-04 10:15:08 -040010391 S;
10392 W;
10393 /* NOTREACHED */
10394 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010395}
10396
Dave Wallace60231f32015-12-17 21:04:30 -050010397static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010398 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010399{
Dave Barach72d72232016-08-04 10:15:08 -040010400 vat_main_t *vam = &vat_main;
Eyal Baric5b13602016-11-24 19:42:43 +020010401 ip46_address_t src, dst;
Dave Wallace60231f32015-12-17 21:04:30 -050010402
Eyal Baric5b13602016-11-24 19:42:43 +020010403 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src);
10404 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst);
10405
10406 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010407 ntohl (mp->sw_if_index),
Eyal Baric5b13602016-11-24 19:42:43 +020010408 format_ip46_address, &src, IP46_TYPE_ANY,
10409 format_ip46_address, &dst, IP46_TYPE_ANY,
Dave Barach72d72232016-08-04 10:15:08 -040010410 ntohl (mp->encap_vrf_id),
Eyal Baric5b13602016-11-24 19:42:43 +020010411 ntohl (mp->decap_next_index), ntohl (mp->vni),
10412 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010413}
10414
10415static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010416 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010417{
Dave Barach72d72232016-08-04 10:15:08 -040010418 vat_main_t *vam = &vat_main;
10419 vat_json_node_t *node = NULL;
Dave Wallace60231f32015-12-17 21:04:30 -050010420
Dave Barach72d72232016-08-04 10:15:08 -040010421 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010422 {
Dave Barach72d72232016-08-04 10:15:08 -040010423 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10424 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010425 }
Dave Barach72d72232016-08-04 10:15:08 -040010426 node = vat_json_array_add (&vam->json_tree);
10427
10428 vat_json_init_object (node);
10429 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10430 if (mp->is_ipv6)
10431 {
Eyal Baric5b13602016-11-24 19:42:43 +020010432 struct in6_addr ip6;
10433
10434 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010435 vat_json_object_add_ip6 (node, "src_address", ip6);
Eyal Baric5b13602016-11-24 19:42:43 +020010436 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010437 vat_json_object_add_ip6 (node, "dst_address", ip6);
10438 }
10439 else
10440 {
Eyal Baric5b13602016-11-24 19:42:43 +020010441 struct in_addr ip4;
10442
10443 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010444 vat_json_object_add_ip4 (node, "src_address", ip4);
Eyal Baric5b13602016-11-24 19:42:43 +020010445 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010446 vat_json_object_add_ip4 (node, "dst_address", ip4);
10447 }
10448 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10449 vat_json_object_add_uint (node, "decap_next_index",
10450 ntohl (mp->decap_next_index));
10451 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10452 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Eyal Baric5b13602016-11-24 19:42:43 +020010453 vat_json_object_add_uint (node, "mcast_sw_if_index",
10454 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010455}
10456
Dave Barach72d72232016-08-04 10:15:08 -040010457static int
10458api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010459{
Dave Barach72d72232016-08-04 10:15:08 -040010460 unformat_input_t *i = vam->input;
10461 vl_api_vxlan_tunnel_dump_t *mp;
10462 f64 timeout;
10463 u32 sw_if_index;
10464 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010465
Dave Barach72d72232016-08-04 10:15:08 -040010466 /* Parse args required to build the message */
10467 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10468 {
10469 if (unformat (i, "sw_if_index %d", &sw_if_index))
10470 sw_if_index_set = 1;
10471 else
10472 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010473 }
10474
Dave Barach72d72232016-08-04 10:15:08 -040010475 if (sw_if_index_set == 0)
10476 {
10477 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010478 }
Dave Barach72d72232016-08-04 10:15:08 -040010479
10480 if (!vam->json_output)
10481 {
Eyal Baric5b13602016-11-24 19:42:43 +020010482 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s\n",
Dave Barach72d72232016-08-04 10:15:08 -040010483 "sw_if_index", "src_address", "dst_address",
Eyal Baric5b13602016-11-24 19:42:43 +020010484 "encap_vrf_id", "decap_next_index", "vni",
10485 "mcast_sw_if_index");
Dave Barach72d72232016-08-04 10:15:08 -040010486 }
10487
10488 /* Get list of vxlan-tunnel interfaces */
10489 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10490
10491 mp->sw_if_index = htonl (sw_if_index);
10492
10493 S;
10494
10495 /* Use a control ping for synchronization */
10496 {
10497 vl_api_control_ping_t *mp;
10498 M (CONTROL_PING, control_ping);
10499 S;
10500 }
10501 W;
10502}
10503
10504static int
10505api_gre_add_del_tunnel (vat_main_t * vam)
10506{
10507 unformat_input_t *line_input = vam->input;
10508 vl_api_gre_add_del_tunnel_t *mp;
10509 f64 timeout;
10510 ip4_address_t src4, dst4;
10511 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010512 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010513 u8 src_set = 0;
10514 u8 dst_set = 0;
10515 u32 outer_fib_id = 0;
10516
10517 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10518 {
10519 if (unformat (line_input, "del"))
10520 is_add = 0;
10521 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10522 src_set = 1;
10523 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10524 dst_set = 1;
10525 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10526 ;
David Hothama8cd3092016-09-19 09:55:07 -070010527 else if (unformat (line_input, "teb"))
10528 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010529 else
10530 {
10531 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10532 return -99;
10533 }
10534 }
10535
10536 if (src_set == 0)
10537 {
10538 errmsg ("tunnel src address not specified\n");
10539 return -99;
10540 }
10541 if (dst_set == 0)
10542 {
10543 errmsg ("tunnel dst address not specified\n");
10544 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010545 }
10546
10547
Dave Barach72d72232016-08-04 10:15:08 -040010548 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010549
Dave Barach72d72232016-08-04 10:15:08 -040010550 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10551 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10552 mp->outer_fib_id = ntohl (outer_fib_id);
10553 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010554 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010555
Dave Barach72d72232016-08-04 10:15:08 -040010556 S;
10557 W;
10558 /* NOTREACHED */
10559 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010560}
10561
10562static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010563 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010564{
Dave Barach72d72232016-08-04 10:15:08 -040010565 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010566
David Hothama8cd3092016-09-19 09:55:07 -070010567 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010568 ntohl (mp->sw_if_index),
10569 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010570 format_ip4_address, &mp->dst_address,
10571 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010572}
10573
10574static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010575 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010576{
Dave Barach72d72232016-08-04 10:15:08 -040010577 vat_main_t *vam = &vat_main;
10578 vat_json_node_t *node = NULL;
10579 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010580
Dave Barach72d72232016-08-04 10:15:08 -040010581 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010582 {
Dave Barach72d72232016-08-04 10:15:08 -040010583 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10584 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010585 }
Dave Barach72d72232016-08-04 10:15:08 -040010586 node = vat_json_array_add (&vam->json_tree);
10587
10588 vat_json_init_object (node);
10589 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10590 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10591 vat_json_object_add_ip4 (node, "src_address", ip4);
10592 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10593 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010594 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010595 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010596}
10597
Dave Barach72d72232016-08-04 10:15:08 -040010598static int
10599api_gre_tunnel_dump (vat_main_t * vam)
10600{
10601 unformat_input_t *i = vam->input;
10602 vl_api_gre_tunnel_dump_t *mp;
10603 f64 timeout;
10604 u32 sw_if_index;
10605 u8 sw_if_index_set = 0;
10606
10607 /* Parse args required to build the message */
10608 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10609 {
10610 if (unformat (i, "sw_if_index %d", &sw_if_index))
10611 sw_if_index_set = 1;
10612 else
10613 break;
10614 }
10615
10616 if (sw_if_index_set == 0)
10617 {
10618 sw_if_index = ~0;
10619 }
10620
10621 if (!vam->json_output)
10622 {
David Hothama8cd3092016-09-19 09:55:07 -070010623 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10624 "sw_if_index", "src_address", "dst_address", "teb",
10625 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010626 }
10627
10628 /* Get list of gre-tunnel interfaces */
10629 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10630
10631 mp->sw_if_index = htonl (sw_if_index);
10632
10633 S;
10634
10635 /* Use a control ping for synchronization */
10636 {
10637 vl_api_control_ping_t *mp;
10638 M (CONTROL_PING, control_ping);
10639 S;
10640 }
10641 W;
10642}
10643
10644static int
10645api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010646{
10647// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010648 vl_api_l2_fib_clear_table_t *mp;
10649 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010650
Dave Barach72d72232016-08-04 10:15:08 -040010651 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010652
Dave Barach72d72232016-08-04 10:15:08 -040010653 S;
10654 W;
10655 /* NOTREACHED */
10656 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010657}
10658
Dave Barach72d72232016-08-04 10:15:08 -040010659static int
10660api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010661{
Dave Barach72d72232016-08-04 10:15:08 -040010662 unformat_input_t *i = vam->input;
10663 vl_api_l2_interface_efp_filter_t *mp;
10664 f64 timeout;
10665 u32 sw_if_index;
10666 u8 enable = 1;
10667 u8 sw_if_index_set = 0;
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, "enable"))
10676 enable = 1;
10677 else if (unformat (i, "disable"))
10678 enable = 0;
10679 else
10680 {
10681 clib_warning ("parse error '%U'", format_unformat_error, i);
10682 return -99;
10683 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010684 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010685
Dave Barach72d72232016-08-04 10:15:08 -040010686 if (sw_if_index_set == 0)
10687 {
10688 errmsg ("missing sw_if_index\n");
10689 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010690 }
10691
Dave Barach72d72232016-08-04 10:15:08 -040010692 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010693
Dave Barach72d72232016-08-04 10:15:08 -040010694 mp->sw_if_index = ntohl (sw_if_index);
10695 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010696
Dave Barach72d72232016-08-04 10:15:08 -040010697 S;
10698 W;
10699 /* NOTREACHED */
10700 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010701}
10702
10703#define foreach_vtr_op \
10704_("disable", L2_VTR_DISABLED) \
10705_("push-1", L2_VTR_PUSH_1) \
10706_("push-2", L2_VTR_PUSH_2) \
10707_("pop-1", L2_VTR_POP_1) \
10708_("pop-2", L2_VTR_POP_2) \
10709_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10710_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10711_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10712_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10713
Dave Barach72d72232016-08-04 10:15:08 -040010714static int
10715api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010716{
Dave Barach72d72232016-08-04 10:15:08 -040010717 unformat_input_t *i = vam->input;
10718 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10719 f64 timeout;
10720 u32 sw_if_index;
10721 u8 sw_if_index_set = 0;
10722 u8 vtr_op_set = 0;
10723 u32 vtr_op = 0;
10724 u32 push_dot1q = 1;
10725 u32 tag1 = ~0;
10726 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010727
Dave Barach72d72232016-08-04 10:15:08 -040010728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10729 {
10730 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10731 sw_if_index_set = 1;
10732 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10733 sw_if_index_set = 1;
10734 else if (unformat (i, "vtr_op %d", &vtr_op))
10735 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010736#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010737 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010738#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010739 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10740 ;
10741 else if (unformat (i, "tag1 %d", &tag1))
10742 ;
10743 else if (unformat (i, "tag2 %d", &tag2))
10744 ;
10745 else
10746 {
10747 clib_warning ("parse error '%U'", format_unformat_error, i);
10748 return -99;
10749 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010750 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010751
Dave Barach72d72232016-08-04 10:15:08 -040010752 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
10753 {
10754 errmsg ("missing vtr operation or sw_if_index\n");
10755 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010756 }
10757
Dave Barach72d72232016-08-04 10:15:08 -040010758 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10759 mp->sw_if_index = ntohl (sw_if_index);
10760 mp->vtr_op = ntohl (vtr_op);
10761 mp->push_dot1q = ntohl (push_dot1q);
10762 mp->tag1 = ntohl (tag1);
10763 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010764
Dave Barach72d72232016-08-04 10:15:08 -040010765 S;
10766 W;
10767 /* NOTREACHED */
10768 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010769}
10770
Dave Barach72d72232016-08-04 10:15:08 -040010771static int
10772api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010773{
Dave Barach72d72232016-08-04 10:15:08 -040010774 unformat_input_t *i = vam->input;
10775 vl_api_create_vhost_user_if_t *mp;
10776 f64 timeout;
10777 u8 *file_name;
10778 u8 is_server = 0;
10779 u8 file_name_set = 0;
10780 u32 custom_dev_instance = ~0;
10781 u8 hwaddr[6];
10782 u8 use_custom_mac = 0;
Dave Barach7be864a2016-11-28 11:41:35 -050010783 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010784
Dave Barach75665d32016-11-17 11:36:59 -050010785 /* Shut up coverity */
10786 memset (hwaddr, 0, sizeof (hwaddr));
10787
Dave Barach72d72232016-08-04 10:15:08 -040010788 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10789 {
10790 if (unformat (i, "socket %s", &file_name))
10791 {
10792 file_name_set = 1;
10793 }
10794 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10795 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010796 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010797 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010798 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010799 is_server = 1;
Dave Barach7be864a2016-11-28 11:41:35 -050010800 else if (unformat (i, "tag %s", &tag))
10801 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010802 else
Dave Barach72d72232016-08-04 10:15:08 -040010803 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010804 }
10805
Dave Barach72d72232016-08-04 10:15:08 -040010806 if (file_name_set == 0)
10807 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010808 errmsg ("missing socket file name\n");
10809 return -99;
10810 }
10811
Dave Barach72d72232016-08-04 10:15:08 -040010812 if (vec_len (file_name) > 255)
10813 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010814 errmsg ("socket file name too long\n");
10815 return -99;
10816 }
Dave Barach72d72232016-08-04 10:15:08 -040010817 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010818
Dave Barach72d72232016-08-04 10:15:08 -040010819 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010820
Dave Barach72d72232016-08-04 10:15:08 -040010821 mp->is_server = is_server;
10822 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10823 vec_free (file_name);
10824 if (custom_dev_instance != ~0)
10825 {
10826 mp->renumber = 1;
10827 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010828 }
Dave Barach72d72232016-08-04 10:15:08 -040010829 mp->use_custom_mac = use_custom_mac;
10830 clib_memcpy (mp->mac_address, hwaddr, 6);
Dave Barach7be864a2016-11-28 11:41:35 -050010831 if (tag)
10832 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10833 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010834
Dave Barach72d72232016-08-04 10:15:08 -040010835 S;
10836 W;
10837 /* NOTREACHED */
10838 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010839}
10840
Dave Barach72d72232016-08-04 10:15:08 -040010841static int
10842api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010843{
Dave Barach72d72232016-08-04 10:15:08 -040010844 unformat_input_t *i = vam->input;
10845 vl_api_modify_vhost_user_if_t *mp;
10846 f64 timeout;
10847 u8 *file_name;
10848 u8 is_server = 0;
10849 u8 file_name_set = 0;
10850 u32 custom_dev_instance = ~0;
10851 u8 sw_if_index_set = 0;
10852 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010853
Dave Barach72d72232016-08-04 10:15:08 -040010854 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10855 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010856 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010857 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010858 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010859 sw_if_index_set = 1;
10860 else if (unformat (i, "socket %s", &file_name))
10861 {
10862 file_name_set = 1;
10863 }
10864 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10865 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010866 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010867 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010868 else
Dave Barach72d72232016-08-04 10:15:08 -040010869 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010870 }
10871
Dave Barach72d72232016-08-04 10:15:08 -040010872 if (sw_if_index_set == 0)
10873 {
10874 errmsg ("missing sw_if_index or interface name\n");
10875 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010876 }
10877
Dave Barach72d72232016-08-04 10:15:08 -040010878 if (file_name_set == 0)
10879 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010880 errmsg ("missing socket file name\n");
10881 return -99;
10882 }
10883
Dave Barach72d72232016-08-04 10:15:08 -040010884 if (vec_len (file_name) > 255)
10885 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010886 errmsg ("socket file name too long\n");
10887 return -99;
10888 }
Dave Barach72d72232016-08-04 10:15:08 -040010889 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010890
Dave Barach72d72232016-08-04 10:15:08 -040010891 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010892
Dave Barach72d72232016-08-04 10:15:08 -040010893 mp->sw_if_index = ntohl (sw_if_index);
10894 mp->is_server = is_server;
10895 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10896 vec_free (file_name);
10897 if (custom_dev_instance != ~0)
10898 {
10899 mp->renumber = 1;
10900 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010901 }
10902
Dave Barach72d72232016-08-04 10:15:08 -040010903 S;
10904 W;
10905 /* NOTREACHED */
10906 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010907}
10908
Dave Barach72d72232016-08-04 10:15:08 -040010909static int
10910api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010911{
Dave Barach72d72232016-08-04 10:15:08 -040010912 unformat_input_t *i = vam->input;
10913 vl_api_delete_vhost_user_if_t *mp;
10914 f64 timeout;
10915 u32 sw_if_index = ~0;
10916 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010917
Dave Barach72d72232016-08-04 10:15:08 -040010918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10919 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010920 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010921 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010922 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010923 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010924 else
Dave Barach72d72232016-08-04 10:15:08 -040010925 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010926 }
10927
Dave Barach72d72232016-08-04 10:15:08 -040010928 if (sw_if_index_set == 0)
10929 {
10930 errmsg ("missing sw_if_index or interface name\n");
10931 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010932 }
10933
10934
Dave Barach72d72232016-08-04 10:15:08 -040010935 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010936
Dave Barach72d72232016-08-04 10:15:08 -040010937 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010938
Dave Barach72d72232016-08-04 10:15:08 -040010939 S;
10940 W;
10941 /* NOTREACHED */
10942 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010943}
10944
10945static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010946 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010947{
Dave Barach72d72232016-08-04 10:15:08 -040010948 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010949
Dave Barach72d72232016-08-04 10:15:08 -040010950 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10951 (char *) mp->interface_name,
10952 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10953 clib_net_to_host_u64 (mp->features), mp->is_server,
10954 ntohl (mp->num_regions), (char *) mp->sock_filename);
10955 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010956}
10957
10958static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010959 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010960{
Dave Barach72d72232016-08-04 10:15:08 -040010961 vat_main_t *vam = &vat_main;
10962 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010963
Dave Barach72d72232016-08-04 10:15:08 -040010964 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010965 {
Dave Barach72d72232016-08-04 10:15:08 -040010966 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10967 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010968 }
Dave Barach72d72232016-08-04 10:15:08 -040010969 node = vat_json_array_add (&vam->json_tree);
10970
10971 vat_json_init_object (node);
10972 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10973 vat_json_object_add_string_copy (node, "interface_name",
10974 mp->interface_name);
10975 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10976 ntohl (mp->virtio_net_hdr_sz));
10977 vat_json_object_add_uint (node, "features",
10978 clib_net_to_host_u64 (mp->features));
10979 vat_json_object_add_uint (node, "is_server", mp->is_server);
10980 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10981 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10982 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010983}
10984
Dave Barach72d72232016-08-04 10:15:08 -040010985static int
10986api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010987{
Dave Barach72d72232016-08-04 10:15:08 -040010988 vl_api_sw_interface_vhost_user_dump_t *mp;
10989 f64 timeout;
10990 fformat (vam->ofp,
10991 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010992
Dave Barach72d72232016-08-04 10:15:08 -040010993 /* Get list of vhost-user interfaces */
10994 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10995 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010996
Dave Barach72d72232016-08-04 10:15:08 -040010997 /* Use a control ping for synchronization */
10998 {
10999 vl_api_control_ping_t *mp;
11000 M (CONTROL_PING, control_ping);
11001 S;
11002 }
11003 W;
11004}
11005
11006static int
11007api_show_version (vat_main_t * vam)
11008{
11009 vl_api_show_version_t *mp;
11010 f64 timeout;
11011
11012 M (SHOW_VERSION, show_version);
11013
11014 S;
11015 W;
11016 /* NOTREACHED */
11017 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011018}
11019
Ed Warnickecb9cada2015-12-08 15:45:58 -070011020
Dave Barach72d72232016-08-04 10:15:08 -040011021static int
11022api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011023{
Dave Barach72d72232016-08-04 10:15:08 -040011024 unformat_input_t *line_input = vam->input;
11025 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
11026 f64 timeout;
11027 ip4_address_t local4, remote4;
11028 ip6_address_t local6, remote6;
11029 u8 is_add = 1;
11030 u8 ipv4_set = 0, ipv6_set = 0;
11031 u8 local_set = 0;
11032 u8 remote_set = 0;
11033 u32 encap_vrf_id = 0;
11034 u32 decap_vrf_id = 0;
11035 u8 protocol = ~0;
11036 u32 vni;
11037 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011038
Dave Barach72d72232016-08-04 10:15:08 -040011039 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11040 {
11041 if (unformat (line_input, "del"))
11042 is_add = 0;
11043 else if (unformat (line_input, "local %U",
11044 unformat_ip4_address, &local4))
11045 {
11046 local_set = 1;
11047 ipv4_set = 1;
11048 }
11049 else if (unformat (line_input, "remote %U",
11050 unformat_ip4_address, &remote4))
11051 {
11052 remote_set = 1;
11053 ipv4_set = 1;
11054 }
11055 else if (unformat (line_input, "local %U",
11056 unformat_ip6_address, &local6))
11057 {
11058 local_set = 1;
11059 ipv6_set = 1;
11060 }
11061 else if (unformat (line_input, "remote %U",
11062 unformat_ip6_address, &remote6))
11063 {
11064 remote_set = 1;
11065 ipv6_set = 1;
11066 }
11067 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11068 ;
11069 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
11070 ;
11071 else if (unformat (line_input, "vni %d", &vni))
11072 vni_set = 1;
11073 else if (unformat (line_input, "next-ip4"))
11074 protocol = 1;
11075 else if (unformat (line_input, "next-ip6"))
11076 protocol = 2;
11077 else if (unformat (line_input, "next-ethernet"))
11078 protocol = 3;
11079 else if (unformat (line_input, "next-nsh"))
11080 protocol = 4;
11081 else
11082 {
11083 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
11084 return -99;
11085 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011086 }
11087
Dave Barach72d72232016-08-04 10:15:08 -040011088 if (local_set == 0)
11089 {
11090 errmsg ("tunnel local address not specified\n");
11091 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011092 }
Dave Barach72d72232016-08-04 10:15:08 -040011093 if (remote_set == 0)
11094 {
11095 errmsg ("tunnel remote address not specified\n");
11096 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011097 }
Dave Barach72d72232016-08-04 10:15:08 -040011098 if (ipv4_set && ipv6_set)
11099 {
11100 errmsg ("both IPv4 and IPv6 addresses specified");
11101 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080011102 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011103
Dave Barach72d72232016-08-04 10:15:08 -040011104 if (vni_set == 0)
11105 {
11106 errmsg ("vni not specified\n");
11107 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011108 }
11109
Dave Barach72d72232016-08-04 10:15:08 -040011110 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011111
Hongjun Nidf921cc2016-05-25 01:16:19 +080011112
Dave Barach72d72232016-08-04 10:15:08 -040011113 if (ipv6_set)
11114 {
11115 clib_memcpy (&mp->local, &local6, sizeof (local6));
11116 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
11117 }
11118 else
11119 {
11120 clib_memcpy (&mp->local, &local4, sizeof (local4));
11121 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080011122 }
11123
Dave Barach72d72232016-08-04 10:15:08 -040011124 mp->encap_vrf_id = ntohl (encap_vrf_id);
11125 mp->decap_vrf_id = ntohl (decap_vrf_id);
11126 mp->protocol = ntohl (protocol);
11127 mp->vni = ntohl (vni);
11128 mp->is_add = is_add;
11129 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011130
Dave Barach72d72232016-08-04 10:15:08 -040011131 S;
11132 W;
11133 /* NOTREACHED */
11134 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011135}
11136
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011137static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011138 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011139{
Dave Barach72d72232016-08-04 10:15:08 -040011140 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011141
Dave Barach72d72232016-08-04 10:15:08 -040011142 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
11143 ntohl (mp->sw_if_index),
11144 format_ip46_address, &(mp->local[0]),
11145 format_ip46_address, &(mp->remote[0]),
11146 ntohl (mp->vni),
11147 ntohl (mp->protocol),
11148 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011149}
11150
11151static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011152 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011153{
Dave Barach72d72232016-08-04 10:15:08 -040011154 vat_main_t *vam = &vat_main;
11155 vat_json_node_t *node = NULL;
11156 struct in_addr ip4;
11157 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011158
Dave Barach72d72232016-08-04 10:15:08 -040011159 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011160 {
Dave Barach72d72232016-08-04 10:15:08 -040011161 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11162 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011163 }
Dave Barach72d72232016-08-04 10:15:08 -040011164 node = vat_json_array_add (&vam->json_tree);
11165
11166 vat_json_init_object (node);
11167 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11168 if (mp->is_ipv6)
11169 {
11170 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
11171 vat_json_object_add_ip6 (node, "local", ip6);
11172 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
11173 vat_json_object_add_ip6 (node, "remote", ip6);
11174 }
11175 else
11176 {
11177 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
11178 vat_json_object_add_ip4 (node, "local", ip4);
11179 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
11180 vat_json_object_add_ip4 (node, "remote", ip4);
11181 }
11182 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
11183 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
11184 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
11185 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
11186 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011187}
11188
Dave Barach72d72232016-08-04 10:15:08 -040011189static int
11190api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011191{
Dave Barach72d72232016-08-04 10:15:08 -040011192 unformat_input_t *i = vam->input;
11193 vl_api_vxlan_gpe_tunnel_dump_t *mp;
11194 f64 timeout;
11195 u32 sw_if_index;
11196 u8 sw_if_index_set = 0;
11197
11198 /* Parse args required to build the message */
11199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11200 {
11201 if (unformat (i, "sw_if_index %d", &sw_if_index))
11202 sw_if_index_set = 1;
11203 else
11204 break;
11205 }
11206
11207 if (sw_if_index_set == 0)
11208 {
11209 sw_if_index = ~0;
11210 }
11211
11212 if (!vam->json_output)
11213 {
11214 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
11215 "sw_if_index", "local", "remote", "vni",
11216 "protocol", "encap_vrf_id", "decap_vrf_id");
11217 }
11218
11219 /* Get list of vxlan-tunnel interfaces */
11220 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
11221
11222 mp->sw_if_index = htonl (sw_if_index);
11223
11224 S;
11225
11226 /* Use a control ping for synchronization */
11227 {
11228 vl_api_control_ping_t *mp;
11229 M (CONTROL_PING, control_ping);
11230 S;
11231 }
11232 W;
11233}
11234
11235u8 *
11236format_l2_fib_mac_address (u8 * s, va_list * args)
11237{
11238 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011239
11240 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011241 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011242}
11243
11244static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011245 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011246{
Dave Barach72d72232016-08-04 10:15:08 -040011247 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011248
Dave Barach72d72232016-08-04 10:15:08 -040011249 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11250 " %d %d %d\n",
11251 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11252 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11253 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011254}
11255
11256static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011257 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011258{
Dave Barach72d72232016-08-04 10:15:08 -040011259 vat_main_t *vam = &vat_main;
11260 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011261
Dave Barach72d72232016-08-04 10:15:08 -040011262 if (VAT_JSON_ARRAY != vam->json_tree.type)
11263 {
11264 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11265 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011266 }
Dave Barach72d72232016-08-04 10:15:08 -040011267 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011268
Dave Barach72d72232016-08-04 10:15:08 -040011269 vat_json_init_object (node);
11270 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11271 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11272 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11273 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11274 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11275 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011276}
11277
Dave Barach72d72232016-08-04 10:15:08 -040011278static int
11279api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011280{
Dave Barach72d72232016-08-04 10:15:08 -040011281 unformat_input_t *i = vam->input;
11282 vl_api_l2_fib_table_dump_t *mp;
11283 f64 timeout;
11284 u32 bd_id;
11285 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011286
Dave Barach72d72232016-08-04 10:15:08 -040011287 /* Parse args required to build the message */
11288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011289 {
Dave Barach72d72232016-08-04 10:15:08 -040011290 if (unformat (i, "bd_id %d", &bd_id))
11291 bd_id_set = 1;
11292 else
11293 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011294 }
Dave Barach72d72232016-08-04 10:15:08 -040011295
11296 if (bd_id_set == 0)
11297 {
11298 errmsg ("missing bridge domain\n");
11299 return -99;
11300 }
11301
11302 fformat (vam->ofp,
11303 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11304
11305 /* Get list of l2 fib entries */
11306 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11307
11308 mp->bd_id = ntohl (bd_id);
11309 S;
11310
11311 /* Use a control ping for synchronization */
11312 {
11313 vl_api_control_ping_t *mp;
11314 M (CONTROL_PING, control_ping);
11315 S;
11316 }
11317 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011318}
11319
11320
11321static int
11322api_interface_name_renumber (vat_main_t * vam)
11323{
Dave Barach72d72232016-08-04 10:15:08 -040011324 unformat_input_t *line_input = vam->input;
11325 vl_api_interface_name_renumber_t *mp;
11326 u32 sw_if_index = ~0;
11327 f64 timeout;
11328 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011329
Dave Barach72d72232016-08-04 10:15:08 -040011330 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11331 {
11332 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11333 &sw_if_index))
11334 ;
11335 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11336 ;
11337 else if (unformat (line_input, "new_show_dev_instance %d",
11338 &new_show_dev_instance))
11339 ;
11340 else
11341 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011342 }
11343
Dave Barach72d72232016-08-04 10:15:08 -040011344 if (sw_if_index == ~0)
11345 {
11346 errmsg ("missing interface name or sw_if_index\n");
11347 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011348 }
11349
Dave Barach72d72232016-08-04 10:15:08 -040011350 if (new_show_dev_instance == ~0)
11351 {
11352 errmsg ("missing new_show_dev_instance\n");
11353 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011354 }
11355
Dave Barach72d72232016-08-04 10:15:08 -040011356 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011357
Dave Barach72d72232016-08-04 10:15:08 -040011358 mp->sw_if_index = ntohl (sw_if_index);
11359 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011360
Dave Barach72d72232016-08-04 10:15:08 -040011361 S;
11362 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011363}
11364
11365static int
11366api_want_ip4_arp_events (vat_main_t * vam)
11367{
Dave Barach72d72232016-08-04 10:15:08 -040011368 unformat_input_t *line_input = vam->input;
11369 vl_api_want_ip4_arp_events_t *mp;
11370 f64 timeout;
11371 ip4_address_t address;
11372 int address_set = 0;
11373 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011374
Dave Barach72d72232016-08-04 10:15:08 -040011375 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11376 {
11377 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11378 address_set = 1;
11379 else if (unformat (line_input, "del"))
11380 enable_disable = 0;
11381 else
11382 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011383 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011384
Dave Barach72d72232016-08-04 10:15:08 -040011385 if (address_set == 0)
11386 {
11387 errmsg ("missing addresses\n");
11388 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011389 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011390
Dave Barach72d72232016-08-04 10:15:08 -040011391 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11392 mp->enable_disable = enable_disable;
11393 mp->pid = getpid ();
11394 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011395
Dave Barach72d72232016-08-04 10:15:08 -040011396 S;
11397 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011398}
11399
Dave Barach72d72232016-08-04 10:15:08 -040011400static int
John Lo1edfba92016-08-27 01:11:57 -040011401api_want_ip6_nd_events (vat_main_t * vam)
11402{
11403 unformat_input_t *line_input = vam->input;
11404 vl_api_want_ip6_nd_events_t *mp;
11405 f64 timeout;
11406 ip6_address_t address;
11407 int address_set = 0;
11408 u32 enable_disable = 1;
11409
11410 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11411 {
11412 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11413 address_set = 1;
11414 else if (unformat (line_input, "del"))
11415 enable_disable = 0;
11416 else
11417 break;
11418 }
11419
11420 if (address_set == 0)
11421 {
11422 errmsg ("missing addresses\n");
11423 return -99;
11424 }
11425
11426 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11427 mp->enable_disable = enable_disable;
11428 mp->pid = getpid ();
11429 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11430
11431 S;
11432 W;
11433}
11434
11435static int
Dave Barach72d72232016-08-04 10:15:08 -040011436api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011437{
Dave Barach72d72232016-08-04 10:15:08 -040011438 unformat_input_t *i = vam->input;
11439 vl_api_input_acl_set_interface_t *mp;
11440 f64 timeout;
11441 u32 sw_if_index;
11442 int sw_if_index_set;
11443 u32 ip4_table_index = ~0;
11444 u32 ip6_table_index = ~0;
11445 u32 l2_table_index = ~0;
11446 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011447
Dave Barach72d72232016-08-04 10:15:08 -040011448 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11449 {
11450 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11451 sw_if_index_set = 1;
11452 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11453 sw_if_index_set = 1;
11454 else if (unformat (i, "del"))
11455 is_add = 0;
11456 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11457 ;
11458 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11459 ;
11460 else if (unformat (i, "l2-table %d", &l2_table_index))
11461 ;
11462 else
11463 {
11464 clib_warning ("parse error '%U'", format_unformat_error, i);
11465 return -99;
11466 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011467 }
11468
Dave Barach72d72232016-08-04 10:15:08 -040011469 if (sw_if_index_set == 0)
11470 {
11471 errmsg ("missing interface name or sw_if_index\n");
11472 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011473 }
11474
Dave Barach72d72232016-08-04 10:15:08 -040011475 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011476
Dave Barach72d72232016-08-04 10:15:08 -040011477 mp->sw_if_index = ntohl (sw_if_index);
11478 mp->ip4_table_index = ntohl (ip4_table_index);
11479 mp->ip6_table_index = ntohl (ip6_table_index);
11480 mp->l2_table_index = ntohl (l2_table_index);
11481 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011482
Dave Barach72d72232016-08-04 10:15:08 -040011483 S;
11484 W;
11485 /* NOTREACHED */
11486 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011487}
11488
11489static int
11490api_ip_address_dump (vat_main_t * vam)
11491{
Dave Barach72d72232016-08-04 10:15:08 -040011492 unformat_input_t *i = vam->input;
11493 vl_api_ip_address_dump_t *mp;
11494 u32 sw_if_index = ~0;
11495 u8 sw_if_index_set = 0;
11496 u8 ipv4_set = 0;
11497 u8 ipv6_set = 0;
11498 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011499
Dave Barach72d72232016-08-04 10:15:08 -040011500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011501 {
Dave Barach72d72232016-08-04 10:15:08 -040011502 if (unformat (i, "sw_if_index %d", &sw_if_index))
11503 sw_if_index_set = 1;
11504 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11505 sw_if_index_set = 1;
11506 else if (unformat (i, "ipv4"))
11507 ipv4_set = 1;
11508 else if (unformat (i, "ipv6"))
11509 ipv6_set = 1;
11510 else
11511 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011512 }
Dave Barach72d72232016-08-04 10:15:08 -040011513
11514 if (ipv4_set && ipv6_set)
11515 {
11516 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11517 return -99;
11518 }
11519
11520 if ((!ipv4_set) && (!ipv6_set))
11521 {
11522 errmsg ("no ipv4 nor ipv6 flag set\n");
11523 return -99;
11524 }
11525
11526 if (sw_if_index_set == 0)
11527 {
11528 errmsg ("missing interface name or sw_if_index\n");
11529 return -99;
11530 }
11531
11532 vam->current_sw_if_index = sw_if_index;
11533 vam->is_ipv6 = ipv6_set;
11534
11535 M (IP_ADDRESS_DUMP, ip_address_dump);
11536 mp->sw_if_index = ntohl (sw_if_index);
11537 mp->is_ipv6 = ipv6_set;
11538 S;
11539
11540 /* Use a control ping for synchronization */
11541 {
11542 vl_api_control_ping_t *mp;
11543 M (CONTROL_PING, control_ping);
11544 S;
11545 }
11546 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011547}
11548
11549static int
11550api_ip_dump (vat_main_t * vam)
11551{
Dave Barach72d72232016-08-04 10:15:08 -040011552 vl_api_ip_dump_t *mp;
11553 unformat_input_t *in = vam->input;
11554 int ipv4_set = 0;
11555 int ipv6_set = 0;
11556 int is_ipv6;
11557 f64 timeout;
11558 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011559
Dave Barach72d72232016-08-04 10:15:08 -040011560 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011561 {
Dave Barach72d72232016-08-04 10:15:08 -040011562 if (unformat (in, "ipv4"))
11563 ipv4_set = 1;
11564 else if (unformat (in, "ipv6"))
11565 ipv6_set = 1;
11566 else
11567 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011568 }
Dave Barach72d72232016-08-04 10:15:08 -040011569
11570 if (ipv4_set && ipv6_set)
11571 {
11572 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11573 return -99;
11574 }
11575
11576 if ((!ipv4_set) && (!ipv6_set))
11577 {
11578 errmsg ("no ipv4 nor ipv6 flag set\n");
11579 return -99;
11580 }
11581
11582 is_ipv6 = ipv6_set;
11583 vam->is_ipv6 = is_ipv6;
11584
11585 /* free old data */
11586 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11587 {
11588 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11589 }
11590 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11591
11592 M (IP_DUMP, ip_dump);
11593 mp->is_ipv6 = ipv6_set;
11594 S;
11595
11596 /* Use a control ping for synchronization */
11597 {
11598 vl_api_control_ping_t *mp;
11599 M (CONTROL_PING, control_ping);
11600 S;
11601 }
11602 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011603}
11604
11605static int
11606api_ipsec_spd_add_del (vat_main_t * vam)
11607{
Dave Barach72d72232016-08-04 10:15:08 -040011608 unformat_input_t *i = vam->input;
11609 vl_api_ipsec_spd_add_del_t *mp;
11610 f64 timeout;
11611 u32 spd_id = ~0;
11612 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011613
Dave Barach72d72232016-08-04 10:15:08 -040011614 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11615 {
11616 if (unformat (i, "spd_id %d", &spd_id))
11617 ;
11618 else if (unformat (i, "del"))
11619 is_add = 0;
11620 else
11621 {
11622 clib_warning ("parse error '%U'", format_unformat_error, i);
11623 return -99;
11624 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011625 }
Dave Barach72d72232016-08-04 10:15:08 -040011626 if (spd_id == ~0)
11627 {
11628 errmsg ("spd_id must be set\n");
11629 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011630 }
11631
Dave Barach72d72232016-08-04 10:15:08 -040011632 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011633
Dave Barach72d72232016-08-04 10:15:08 -040011634 mp->spd_id = ntohl (spd_id);
11635 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011636
Dave Barach72d72232016-08-04 10:15:08 -040011637 S;
11638 W;
11639 /* NOTREACHED */
11640 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011641}
11642
11643static int
11644api_ipsec_interface_add_del_spd (vat_main_t * vam)
11645{
Dave Barach72d72232016-08-04 10:15:08 -040011646 unformat_input_t *i = vam->input;
11647 vl_api_ipsec_interface_add_del_spd_t *mp;
11648 f64 timeout;
11649 u32 sw_if_index;
11650 u8 sw_if_index_set = 0;
11651 u32 spd_id = (u32) ~ 0;
11652 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011653
Dave Barach72d72232016-08-04 10:15:08 -040011654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11655 {
11656 if (unformat (i, "del"))
11657 is_add = 0;
11658 else if (unformat (i, "spd_id %d", &spd_id))
11659 ;
11660 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11661 sw_if_index_set = 1;
11662 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11663 sw_if_index_set = 1;
11664 else
11665 {
11666 clib_warning ("parse error '%U'", format_unformat_error, i);
11667 return -99;
11668 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011669
11670 }
11671
Dave Barach72d72232016-08-04 10:15:08 -040011672 if (spd_id == (u32) ~ 0)
11673 {
11674 errmsg ("spd_id must be set\n");
11675 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011676 }
11677
Dave Barach72d72232016-08-04 10:15:08 -040011678 if (sw_if_index_set == 0)
11679 {
11680 errmsg ("missing interface name or sw_if_index\n");
11681 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011682 }
11683
Dave Barach72d72232016-08-04 10:15:08 -040011684 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011685
Dave Barach72d72232016-08-04 10:15:08 -040011686 mp->spd_id = ntohl (spd_id);
11687 mp->sw_if_index = ntohl (sw_if_index);
11688 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011689
Dave Barach72d72232016-08-04 10:15:08 -040011690 S;
11691 W;
11692 /* NOTREACHED */
11693 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011694}
11695
11696static int
11697api_ipsec_spd_add_del_entry (vat_main_t * vam)
11698{
Dave Barach72d72232016-08-04 10:15:08 -040011699 unformat_input_t *i = vam->input;
11700 vl_api_ipsec_spd_add_del_entry_t *mp;
11701 f64 timeout;
11702 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011703 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011704 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011705 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11706 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11707 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11708 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011709
Dave Barach72d72232016-08-04 10:15:08 -040011710 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11711 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11712 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11713 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11714 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11715 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011716
Dave Barach72d72232016-08-04 10:15:08 -040011717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11718 {
11719 if (unformat (i, "del"))
11720 is_add = 0;
11721 if (unformat (i, "outbound"))
11722 is_outbound = 1;
11723 if (unformat (i, "inbound"))
11724 is_outbound = 0;
11725 else if (unformat (i, "spd_id %d", &spd_id))
11726 ;
11727 else if (unformat (i, "sa_id %d", &sa_id))
11728 ;
11729 else if (unformat (i, "priority %d", &priority))
11730 ;
11731 else if (unformat (i, "protocol %d", &protocol))
11732 ;
11733 else if (unformat (i, "lport_start %d", &lport_start))
11734 ;
11735 else if (unformat (i, "lport_stop %d", &lport_stop))
11736 ;
11737 else if (unformat (i, "rport_start %d", &rport_start))
11738 ;
11739 else if (unformat (i, "rport_stop %d", &rport_stop))
11740 ;
11741 else
11742 if (unformat
11743 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11744 {
11745 is_ipv6 = 0;
11746 is_ip_any = 0;
11747 }
11748 else
11749 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11750 {
11751 is_ipv6 = 0;
11752 is_ip_any = 0;
11753 }
11754 else
11755 if (unformat
11756 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11757 {
11758 is_ipv6 = 0;
11759 is_ip_any = 0;
11760 }
11761 else
11762 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11763 {
11764 is_ipv6 = 0;
11765 is_ip_any = 0;
11766 }
11767 else
11768 if (unformat
11769 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11770 {
11771 is_ipv6 = 1;
11772 is_ip_any = 0;
11773 }
11774 else
11775 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11776 {
11777 is_ipv6 = 1;
11778 is_ip_any = 0;
11779 }
11780 else
11781 if (unformat
11782 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11783 {
11784 is_ipv6 = 1;
11785 is_ip_any = 0;
11786 }
11787 else
11788 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11789 {
11790 is_ipv6 = 1;
11791 is_ip_any = 0;
11792 }
11793 else
11794 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11795 {
11796 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11797 {
11798 clib_warning ("unsupported action: 'resolve'");
11799 return -99;
11800 }
11801 }
11802 else
11803 {
11804 clib_warning ("parse error '%U'", format_unformat_error, i);
11805 return -99;
11806 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011807
11808 }
11809
Dave Barach72d72232016-08-04 10:15:08 -040011810 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011811
Dave Barach72d72232016-08-04 10:15:08 -040011812 mp->spd_id = ntohl (spd_id);
11813 mp->priority = ntohl (priority);
11814 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011815
Dave Barach72d72232016-08-04 10:15:08 -040011816 mp->is_ipv6 = is_ipv6;
11817 if (is_ipv6 || is_ip_any)
11818 {
11819 clib_memcpy (mp->remote_address_start, &raddr6_start,
11820 sizeof (ip6_address_t));
11821 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11822 sizeof (ip6_address_t));
11823 clib_memcpy (mp->local_address_start, &laddr6_start,
11824 sizeof (ip6_address_t));
11825 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11826 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011827 }
Dave Barach72d72232016-08-04 10:15:08 -040011828 else
11829 {
11830 clib_memcpy (mp->remote_address_start, &raddr4_start,
11831 sizeof (ip4_address_t));
11832 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11833 sizeof (ip4_address_t));
11834 clib_memcpy (mp->local_address_start, &laddr4_start,
11835 sizeof (ip4_address_t));
11836 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11837 sizeof (ip4_address_t));
11838 }
11839 mp->protocol = (u8) protocol;
11840 mp->local_port_start = ntohs ((u16) lport_start);
11841 mp->local_port_stop = ntohs ((u16) lport_stop);
11842 mp->remote_port_start = ntohs ((u16) rport_start);
11843 mp->remote_port_stop = ntohs ((u16) rport_stop);
11844 mp->policy = (u8) policy;
11845 mp->sa_id = ntohl (sa_id);
11846 mp->is_add = is_add;
11847 mp->is_ip_any = is_ip_any;
11848 S;
11849 W;
11850 /* NOTREACHED */
11851 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011852}
11853
11854static int
11855api_ipsec_sad_add_del_entry (vat_main_t * vam)
11856{
Dave Barach72d72232016-08-04 10:15:08 -040011857 unformat_input_t *i = vam->input;
11858 vl_api_ipsec_sad_add_del_entry_t *mp;
11859 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011860 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011861 u8 *ck = 0, *ik = 0;
11862 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011863
Dave Barach72d72232016-08-04 10:15:08 -040011864 u8 protocol = IPSEC_PROTOCOL_AH;
11865 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11866 u32 crypto_alg = 0, integ_alg = 0;
11867 ip4_address_t tun_src4;
11868 ip4_address_t tun_dst4;
11869 ip6_address_t tun_src6;
11870 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011871
Dave Barach72d72232016-08-04 10:15:08 -040011872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11873 {
11874 if (unformat (i, "del"))
11875 is_add = 0;
11876 else if (unformat (i, "sad_id %d", &sad_id))
11877 ;
11878 else if (unformat (i, "spi %d", &spi))
11879 ;
11880 else if (unformat (i, "esp"))
11881 protocol = IPSEC_PROTOCOL_ESP;
11882 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11883 {
11884 is_tunnel = 1;
11885 is_tunnel_ipv6 = 0;
11886 }
11887 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11888 {
11889 is_tunnel = 1;
11890 is_tunnel_ipv6 = 0;
11891 }
11892 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11893 {
11894 is_tunnel = 1;
11895 is_tunnel_ipv6 = 1;
11896 }
11897 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11898 {
11899 is_tunnel = 1;
11900 is_tunnel_ipv6 = 1;
11901 }
11902 else
11903 if (unformat
11904 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11905 {
11906 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011907 crypto_alg >= IPSEC_CRYPTO_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011908 {
11909 clib_warning ("unsupported crypto-alg: '%U'",
11910 format_ipsec_crypto_alg, crypto_alg);
11911 return -99;
11912 }
11913 }
11914 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11915 ;
11916 else
11917 if (unformat
11918 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11919 {
Radu Nicolau6929ea92016-11-29 11:00:30 +000011920#if DPDK_CRYPTO==1
11921 if (integ_alg < IPSEC_INTEG_ALG_NONE ||
11922#else
Dave Barach72d72232016-08-04 10:15:08 -040011923 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011924#endif
11925 integ_alg >= IPSEC_INTEG_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011926 {
11927 clib_warning ("unsupported integ-alg: '%U'",
11928 format_ipsec_integ_alg, integ_alg);
11929 return -99;
11930 }
11931 }
11932 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11933 ;
11934 else
11935 {
11936 clib_warning ("parse error '%U'", format_unformat_error, i);
11937 return -99;
11938 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011939
11940 }
11941
Radu Nicolau6929ea92016-11-29 11:00:30 +000011942#if DPDK_CRYPTO==1
11943 /*Special cases, aes-gcm-128 encryption */
11944 if (crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
11945 {
11946 if (integ_alg != IPSEC_INTEG_ALG_NONE
11947 && integ_alg != IPSEC_INTEG_ALG_AES_GCM_128)
11948 {
11949 clib_warning
11950 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
11951 return -99;
11952 }
11953 else /*set integ-alg internally to aes-gcm-128 */
11954 integ_alg = IPSEC_INTEG_ALG_AES_GCM_128;
11955 }
11956 else if (integ_alg == IPSEC_INTEG_ALG_AES_GCM_128)
11957 {
11958 clib_warning ("unsupported integ-alg: aes-gcm-128");
11959 return -99;
11960 }
11961 else if (integ_alg == IPSEC_INTEG_ALG_NONE)
11962 {
11963 clib_warning ("unsupported integ-alg: none");
11964 return -99;
11965 }
11966#endif
11967
11968
Dave Barach72d72232016-08-04 10:15:08 -040011969 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011970
Dave Barach72d72232016-08-04 10:15:08 -040011971 mp->sad_id = ntohl (sad_id);
11972 mp->is_add = is_add;
11973 mp->protocol = protocol;
11974 mp->spi = ntohl (spi);
11975 mp->is_tunnel = is_tunnel;
11976 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11977 mp->crypto_algorithm = crypto_alg;
11978 mp->integrity_algorithm = integ_alg;
11979 mp->crypto_key_length = vec_len (ck);
11980 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011981
Dave Barach72d72232016-08-04 10:15:08 -040011982 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11983 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011984
Dave Barach72d72232016-08-04 10:15:08 -040011985 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11986 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011987
Dave Barach839fe3e2016-08-10 11:35:54 -040011988 if (ck)
11989 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11990 if (ik)
11991 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011992
Dave Barach72d72232016-08-04 10:15:08 -040011993 if (is_tunnel)
11994 {
11995 if (is_tunnel_ipv6)
11996 {
11997 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11998 sizeof (ip6_address_t));
11999 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
12000 sizeof (ip6_address_t));
12001 }
12002 else
12003 {
12004 clib_memcpy (mp->tunnel_src_address, &tun_src4,
12005 sizeof (ip4_address_t));
12006 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
12007 sizeof (ip4_address_t));
12008 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012009 }
12010
Dave Barach72d72232016-08-04 10:15:08 -040012011 S;
12012 W;
12013 /* NOTREACHED */
12014 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012015}
12016
12017static int
12018api_ipsec_sa_set_key (vat_main_t * vam)
12019{
Dave Barach72d72232016-08-04 10:15:08 -040012020 unformat_input_t *i = vam->input;
12021 vl_api_ipsec_sa_set_key_t *mp;
12022 f64 timeout;
12023 u32 sa_id;
12024 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012025
Dave Barach72d72232016-08-04 10:15:08 -040012026 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12027 {
12028 if (unformat (i, "sa_id %d", &sa_id))
12029 ;
12030 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
12031 ;
12032 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
12033 ;
12034 else
12035 {
12036 clib_warning ("parse error '%U'", format_unformat_error, i);
12037 return -99;
12038 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012039 }
12040
Dave Barach72d72232016-08-04 10:15:08 -040012041 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012042
Dave Barach72d72232016-08-04 10:15:08 -040012043 mp->sa_id = ntohl (sa_id);
12044 mp->crypto_key_length = vec_len (ck);
12045 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012046
Dave Barach72d72232016-08-04 10:15:08 -040012047 if (mp->crypto_key_length > sizeof (mp->crypto_key))
12048 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012049
Dave Barach72d72232016-08-04 10:15:08 -040012050 if (mp->integrity_key_length > sizeof (mp->integrity_key))
12051 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012052
Dave Barach839fe3e2016-08-10 11:35:54 -040012053 if (ck)
12054 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
12055 if (ik)
12056 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012057
Dave Barach72d72232016-08-04 10:15:08 -040012058 S;
12059 W;
12060 /* NOTREACHED */
12061 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012062}
12063
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012064static int
12065api_ikev2_profile_add_del (vat_main_t * vam)
12066{
Dave Barach72d72232016-08-04 10:15:08 -040012067 unformat_input_t *i = vam->input;
12068 vl_api_ikev2_profile_add_del_t *mp;
12069 f64 timeout;
12070 u8 is_add = 1;
12071 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012072
Dave Barach72d72232016-08-04 10:15:08 -040012073 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012074
Dave Barach72d72232016-08-04 10:15:08 -040012075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12076 {
12077 if (unformat (i, "del"))
12078 is_add = 0;
12079 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12080 vec_add1 (name, 0);
12081 else
12082 {
12083 errmsg ("parse error '%U'", format_unformat_error, i);
12084 return -99;
12085 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012086 }
12087
Dave Barach72d72232016-08-04 10:15:08 -040012088 if (!vec_len (name))
12089 {
12090 errmsg ("profile name must be specified");
12091 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012092 }
12093
Dave Barach72d72232016-08-04 10:15:08 -040012094 if (vec_len (name) > 64)
12095 {
12096 errmsg ("profile name too long");
12097 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012098 }
12099
Dave Barach72d72232016-08-04 10:15:08 -040012100 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012101
Dave Barach72d72232016-08-04 10:15:08 -040012102 clib_memcpy (mp->name, name, vec_len (name));
12103 mp->is_add = is_add;
12104 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012105
Dave Barach72d72232016-08-04 10:15:08 -040012106 S;
12107 W;
12108 /* NOTREACHED */
12109 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012110}
12111
12112static int
12113api_ikev2_profile_set_auth (vat_main_t * vam)
12114{
Dave Barach72d72232016-08-04 10:15:08 -040012115 unformat_input_t *i = vam->input;
12116 vl_api_ikev2_profile_set_auth_t *mp;
12117 f64 timeout;
12118 u8 *name = 0;
12119 u8 *data = 0;
12120 u32 auth_method = 0;
12121 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012122
Dave Barach72d72232016-08-04 10:15:08 -040012123 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012124
Dave Barach72d72232016-08-04 10:15:08 -040012125 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12126 {
12127 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12128 vec_add1 (name, 0);
12129 else if (unformat (i, "auth_method %U",
12130 unformat_ikev2_auth_method, &auth_method))
12131 ;
12132 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
12133 is_hex = 1;
12134 else if (unformat (i, "auth_data %v", &data))
12135 ;
12136 else
12137 {
12138 errmsg ("parse error '%U'", format_unformat_error, i);
12139 return -99;
12140 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012141 }
12142
Dave Barach72d72232016-08-04 10:15:08 -040012143 if (!vec_len (name))
12144 {
12145 errmsg ("profile name must be specified");
12146 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012147 }
12148
Dave Barach72d72232016-08-04 10:15:08 -040012149 if (vec_len (name) > 64)
12150 {
12151 errmsg ("profile name too long");
12152 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012153 }
12154
Dave Barach72d72232016-08-04 10:15:08 -040012155 if (!vec_len (data))
12156 {
12157 errmsg ("auth_data must be specified");
12158 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012159 }
12160
Dave Barach72d72232016-08-04 10:15:08 -040012161 if (!auth_method)
12162 {
12163 errmsg ("auth_method must be specified");
12164 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012165 }
12166
Dave Barach72d72232016-08-04 10:15:08 -040012167 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012168
Dave Barach72d72232016-08-04 10:15:08 -040012169 mp->is_hex = is_hex;
12170 mp->auth_method = (u8) auth_method;
12171 mp->data_len = vec_len (data);
12172 clib_memcpy (mp->name, name, vec_len (name));
12173 clib_memcpy (mp->data, data, vec_len (data));
12174 vec_free (name);
12175 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012176
Dave Barach72d72232016-08-04 10:15:08 -040012177 S;
12178 W;
12179 /* NOTREACHED */
12180 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012181}
12182
12183static int
12184api_ikev2_profile_set_id (vat_main_t * vam)
12185{
Dave Barach72d72232016-08-04 10:15:08 -040012186 unformat_input_t *i = vam->input;
12187 vl_api_ikev2_profile_set_id_t *mp;
12188 f64 timeout;
12189 u8 *name = 0;
12190 u8 *data = 0;
12191 u8 is_local = 0;
12192 u32 id_type = 0;
12193 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012194
Dave Barach72d72232016-08-04 10:15:08 -040012195 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012196
Dave Barach72d72232016-08-04 10:15:08 -040012197 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12198 {
12199 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12200 vec_add1 (name, 0);
12201 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
12202 ;
12203 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
12204 {
12205 data = vec_new (u8, 4);
12206 clib_memcpy (data, ip4.as_u8, 4);
12207 }
12208 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
12209 ;
12210 else if (unformat (i, "id_data %v", &data))
12211 ;
12212 else if (unformat (i, "local"))
12213 is_local = 1;
12214 else if (unformat (i, "remote"))
12215 is_local = 0;
12216 else
12217 {
12218 errmsg ("parse error '%U'", format_unformat_error, i);
12219 return -99;
12220 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012221 }
12222
Dave Barach72d72232016-08-04 10:15:08 -040012223 if (!vec_len (name))
12224 {
12225 errmsg ("profile name must be specified");
12226 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012227 }
12228
Dave Barach72d72232016-08-04 10:15:08 -040012229 if (vec_len (name) > 64)
12230 {
12231 errmsg ("profile name too long");
12232 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012233 }
12234
Dave Barach72d72232016-08-04 10:15:08 -040012235 if (!vec_len (data))
12236 {
12237 errmsg ("id_data must be specified");
12238 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012239 }
12240
Dave Barach72d72232016-08-04 10:15:08 -040012241 if (!id_type)
12242 {
12243 errmsg ("id_type must be specified");
12244 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012245 }
12246
Dave Barach72d72232016-08-04 10:15:08 -040012247 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012248
Dave Barach72d72232016-08-04 10:15:08 -040012249 mp->is_local = is_local;
12250 mp->id_type = (u8) id_type;
12251 mp->data_len = vec_len (data);
12252 clib_memcpy (mp->name, name, vec_len (name));
12253 clib_memcpy (mp->data, data, vec_len (data));
12254 vec_free (name);
12255 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012256
Dave Barach72d72232016-08-04 10:15:08 -040012257 S;
12258 W;
12259 /* NOTREACHED */
12260 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012261}
12262
12263static int
12264api_ikev2_profile_set_ts (vat_main_t * vam)
12265{
Dave Barach72d72232016-08-04 10:15:08 -040012266 unformat_input_t *i = vam->input;
12267 vl_api_ikev2_profile_set_ts_t *mp;
12268 f64 timeout;
12269 u8 *name = 0;
12270 u8 is_local = 0;
12271 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12272 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012273
Dave Barach72d72232016-08-04 10:15:08 -040012274 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012275
Dave Barach72d72232016-08-04 10:15:08 -040012276 start_addr.as_u32 = 0;
12277 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012278
Dave Barach72d72232016-08-04 10:15:08 -040012279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12280 {
12281 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12282 vec_add1 (name, 0);
12283 else if (unformat (i, "protocol %d", &proto))
12284 ;
12285 else if (unformat (i, "start_port %d", &start_port))
12286 ;
12287 else if (unformat (i, "end_port %d", &end_port))
12288 ;
12289 else
12290 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12291 ;
12292 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12293 ;
12294 else if (unformat (i, "local"))
12295 is_local = 1;
12296 else if (unformat (i, "remote"))
12297 is_local = 0;
12298 else
12299 {
12300 errmsg ("parse error '%U'", format_unformat_error, i);
12301 return -99;
12302 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012303 }
12304
Dave Barach72d72232016-08-04 10:15:08 -040012305 if (!vec_len (name))
12306 {
12307 errmsg ("profile name must be specified");
12308 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012309 }
12310
Dave Barach72d72232016-08-04 10:15:08 -040012311 if (vec_len (name) > 64)
12312 {
12313 errmsg ("profile name too long");
12314 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012315 }
12316
Dave Barach72d72232016-08-04 10:15:08 -040012317 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012318
Dave Barach72d72232016-08-04 10:15:08 -040012319 mp->is_local = is_local;
12320 mp->proto = (u8) proto;
12321 mp->start_port = (u16) start_port;
12322 mp->end_port = (u16) end_port;
12323 mp->start_addr = start_addr.as_u32;
12324 mp->end_addr = end_addr.as_u32;
12325 clib_memcpy (mp->name, name, vec_len (name));
12326 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012327
Dave Barach72d72232016-08-04 10:15:08 -040012328 S;
12329 W;
12330 /* NOTREACHED */
12331 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012332}
12333
12334static int
12335api_ikev2_set_local_key (vat_main_t * vam)
12336{
Dave Barach72d72232016-08-04 10:15:08 -040012337 unformat_input_t *i = vam->input;
12338 vl_api_ikev2_set_local_key_t *mp;
12339 f64 timeout;
12340 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012341
Dave Barach72d72232016-08-04 10:15:08 -040012342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12343 {
12344 if (unformat (i, "file %v", &file))
12345 vec_add1 (file, 0);
12346 else
12347 {
12348 errmsg ("parse error '%U'", format_unformat_error, i);
12349 return -99;
12350 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012351 }
12352
Dave Barach72d72232016-08-04 10:15:08 -040012353 if (!vec_len (file))
12354 {
12355 errmsg ("RSA key file must be specified");
12356 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012357 }
12358
Dave Barach72d72232016-08-04 10:15:08 -040012359 if (vec_len (file) > 256)
12360 {
12361 errmsg ("file name too long");
12362 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012363 }
12364
Dave Barach72d72232016-08-04 10:15:08 -040012365 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012366
Dave Barach72d72232016-08-04 10:15:08 -040012367 clib_memcpy (mp->key_file, file, vec_len (file));
12368 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012369
Dave Barach72d72232016-08-04 10:15:08 -040012370 S;
12371 W;
12372 /* NOTREACHED */
12373 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012374}
12375
Ed Warnickecb9cada2015-12-08 15:45:58 -070012376/*
12377 * MAP
12378 */
Dave Barach72d72232016-08-04 10:15:08 -040012379static int
12380api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012381{
12382 unformat_input_t *i = vam->input;
12383 vl_api_map_add_domain_t *mp;
12384 f64 timeout;
12385
12386 ip4_address_t ip4_prefix;
12387 ip6_address_t ip6_prefix;
12388 ip6_address_t ip6_src;
12389 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012390 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12391 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012392 u8 is_translation = 0;
12393 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012394 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012395
Dave Barach72d72232016-08-04 10:15:08 -040012396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12397 {
12398 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12399 &ip4_prefix, &ip4_prefix_len))
12400 num_m_args++;
12401 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12402 &ip6_prefix, &ip6_prefix_len))
12403 num_m_args++;
12404 else
12405 if (unformat
12406 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12407 &ip6_src_len))
12408 num_m_args++;
12409 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12410 num_m_args++;
12411 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12412 num_m_args++;
12413 else if (unformat (i, "psid-offset %d", &psid_offset))
12414 num_m_args++;
12415 else if (unformat (i, "psid-len %d", &psid_length))
12416 num_m_args++;
12417 else if (unformat (i, "mtu %d", &mtu))
12418 num_m_args++;
12419 else if (unformat (i, "map-t"))
12420 is_translation = 1;
12421 else
12422 {
12423 clib_warning ("parse error '%U'", format_unformat_error, i);
12424 return -99;
12425 }
12426 }
12427
Ole Troan07e7eab2016-08-25 00:24:08 +020012428 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012429 {
12430 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012431 return -99;
12432 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012433
12434 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012435 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012436
Dave Barach72d72232016-08-04 10:15:08 -040012437 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012438 mp->ip4_prefix_len = ip4_prefix_len;
12439
Dave Barach72d72232016-08-04 10:15:08 -040012440 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012441 mp->ip6_prefix_len = ip6_prefix_len;
12442
Dave Barach72d72232016-08-04 10:15:08 -040012443 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012444 mp->ip6_src_prefix_len = ip6_src_len;
12445
12446 mp->ea_bits_len = ea_bits_len;
12447 mp->psid_offset = psid_offset;
12448 mp->psid_length = psid_length;
12449 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012450 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012451
12452 /* send it... */
12453 S;
12454
12455 /* Wait for a reply, return good/bad news */
12456 W;
12457}
12458
Dave Barach72d72232016-08-04 10:15:08 -040012459static int
12460api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012461{
12462 unformat_input_t *i = vam->input;
12463 vl_api_map_del_domain_t *mp;
12464 f64 timeout;
12465
12466 u32 num_m_args = 0;
12467 u32 index;
12468
Dave Barach72d72232016-08-04 10:15:08 -040012469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12470 {
12471 if (unformat (i, "index %d", &index))
12472 num_m_args++;
12473 else
12474 {
12475 clib_warning ("parse error '%U'", format_unformat_error, i);
12476 return -99;
12477 }
12478 }
12479
12480 if (num_m_args != 1)
12481 {
12482 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012483 return -99;
12484 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012485
12486 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012487 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012488
Dave Barach72d72232016-08-04 10:15:08 -040012489 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012490
12491 /* send it... */
12492 S;
12493
12494 /* Wait for a reply, return good/bad news */
12495 W;
12496}
12497
Dave Barach72d72232016-08-04 10:15:08 -040012498static int
12499api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012500{
12501 unformat_input_t *i = vam->input;
12502 vl_api_map_add_del_rule_t *mp;
12503 f64 timeout;
12504 u8 is_add = 1;
12505 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012506 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012507
Dave Barach72d72232016-08-04 10:15:08 -040012508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12509 {
12510 if (unformat (i, "index %d", &index))
12511 num_m_args++;
12512 else if (unformat (i, "psid %d", &psid))
12513 num_m_args++;
12514 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12515 num_m_args++;
12516 else if (unformat (i, "del"))
12517 {
12518 is_add = 0;
12519 }
12520 else
12521 {
12522 clib_warning ("parse error '%U'", format_unformat_error, i);
12523 return -99;
12524 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012525 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012526
12527 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012528 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012529
Dave Barach72d72232016-08-04 10:15:08 -040012530 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012531 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012532 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12533 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012534
12535 /* send it... */
12536 S;
12537
12538 /* Wait for a reply, return good/bad news */
12539 W;
12540}
12541
Dave Barach72d72232016-08-04 10:15:08 -040012542static int
12543api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012544{
Dave Barach72d72232016-08-04 10:15:08 -040012545 vl_api_map_domain_dump_t *mp;
12546 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012547
Dave Barach72d72232016-08-04 10:15:08 -040012548 /* Construct the API message */
12549 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012550
Dave Barach72d72232016-08-04 10:15:08 -040012551 /* send it... */
12552 S;
12553
12554 /* Use a control ping for synchronization */
12555 {
12556 vl_api_control_ping_t *mp;
12557 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012558 S;
Dave Barach72d72232016-08-04 10:15:08 -040012559 }
12560 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012561}
12562
Dave Barach72d72232016-08-04 10:15:08 -040012563static int
12564api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012565{
Dave Barach72d72232016-08-04 10:15:08 -040012566 unformat_input_t *i = vam->input;
12567 vl_api_map_rule_dump_t *mp;
12568 f64 timeout;
12569 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012570
Dave Barach72d72232016-08-04 10:15:08 -040012571 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012572 {
Dave Barach72d72232016-08-04 10:15:08 -040012573 if (unformat (i, "index %u", &domain_index))
12574 ;
12575 else
12576 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012577 }
Dave Barach72d72232016-08-04 10:15:08 -040012578
12579 if (domain_index == ~0)
12580 {
12581 clib_warning ("parse error: domain index expected");
12582 return -99;
12583 }
12584
12585 /* Construct the API message */
12586 M (MAP_RULE_DUMP, map_rule_dump);
12587
12588 mp->domain_index = htonl (domain_index);
12589
12590 /* send it... */
12591 S;
12592
12593 /* Use a control ping for synchronization */
12594 {
12595 vl_api_control_ping_t *mp;
12596 M (CONTROL_PING, control_ping);
12597 S;
12598 }
12599 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012600}
12601
12602static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012603 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012604{
Dave Barach72d72232016-08-04 10:15:08 -040012605 vat_main_t *vam = &vat_main;
12606 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012607
Dave Barach72d72232016-08-04 10:15:08 -040012608 if (vam->async_mode)
12609 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012610 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012611 }
12612 else
12613 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012614 vam->retval = retval;
12615 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012616 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012617}
12618
12619static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012620 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012621{
Dave Barach72d72232016-08-04 10:15:08 -040012622 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012623 vat_json_node_t node;
12624
Dave Barach72d72232016-08-04 10:15:08 -040012625 vat_json_init_object (&node);
12626 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12627 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012628
Dave Barach72d72232016-08-04 10:15:08 -040012629 vat_json_print (vam->ofp, &node);
12630 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012631
Dave Barach72d72232016-08-04 10:15:08 -040012632 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012633 vam->result_ready = 1;
12634}
12635
12636static int
12637api_get_first_msg_id (vat_main_t * vam)
12638{
Dave Barach72d72232016-08-04 10:15:08 -040012639 vl_api_get_first_msg_id_t *mp;
12640 f64 timeout;
12641 unformat_input_t *i = vam->input;
12642 u8 *name;
12643 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012644
Dave Barach72d72232016-08-04 10:15:08 -040012645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12646 {
12647 if (unformat (i, "client %s", &name))
12648 name_set = 1;
12649 else
12650 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012651 }
12652
Dave Barach72d72232016-08-04 10:15:08 -040012653 if (name_set == 0)
12654 {
12655 errmsg ("missing client name\n");
12656 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012657 }
Dave Barach72d72232016-08-04 10:15:08 -040012658 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012659
Dave Barach72d72232016-08-04 10:15:08 -040012660 if (vec_len (name) > 63)
12661 {
12662 errmsg ("client name too long\n");
12663 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012664 }
12665
Dave Barach72d72232016-08-04 10:15:08 -040012666 M (GET_FIRST_MSG_ID, get_first_msg_id);
12667 clib_memcpy (mp->name, name, vec_len (name));
12668 S;
12669 W;
12670 /* NOTREACHED */
12671 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012672}
12673
Dave Barach72d72232016-08-04 10:15:08 -040012674static int
12675api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012676{
Dave Barach72d72232016-08-04 10:15:08 -040012677 unformat_input_t *line_input = vam->input;
12678 vl_api_cop_interface_enable_disable_t *mp;
12679 f64 timeout;
12680 u32 sw_if_index = ~0;
12681 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012682
Dave Barach72d72232016-08-04 10:15:08 -040012683 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12684 {
12685 if (unformat (line_input, "disable"))
12686 enable_disable = 0;
12687 if (unformat (line_input, "enable"))
12688 enable_disable = 1;
12689 else if (unformat (line_input, "%U", unformat_sw_if_index,
12690 vam, &sw_if_index))
12691 ;
12692 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12693 ;
12694 else
12695 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012696 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012697
Dave Barach72d72232016-08-04 10:15:08 -040012698 if (sw_if_index == ~0)
12699 {
12700 errmsg ("missing interface name or sw_if_index\n");
12701 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012702 }
12703
Dave Barach72d72232016-08-04 10:15:08 -040012704 /* Construct the API message */
12705 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12706 mp->sw_if_index = ntohl (sw_if_index);
12707 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012708
Dave Barach72d72232016-08-04 10:15:08 -040012709 /* send it... */
12710 S;
12711 /* Wait for the reply */
12712 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012713}
12714
Dave Barach72d72232016-08-04 10:15:08 -040012715static int
12716api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012717{
Dave Barach72d72232016-08-04 10:15:08 -040012718 unformat_input_t *line_input = vam->input;
12719 vl_api_cop_whitelist_enable_disable_t *mp;
12720 f64 timeout;
12721 u32 sw_if_index = ~0;
12722 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012723 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012724
Dave Barach72d72232016-08-04 10:15:08 -040012725 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12726 {
12727 if (unformat (line_input, "ip4"))
12728 ip4 = 1;
12729 else if (unformat (line_input, "ip6"))
12730 ip6 = 1;
12731 else if (unformat (line_input, "default"))
12732 default_cop = 1;
12733 else if (unformat (line_input, "%U", unformat_sw_if_index,
12734 vam, &sw_if_index))
12735 ;
12736 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12737 ;
12738 else if (unformat (line_input, "fib-id %d", &fib_id))
12739 ;
12740 else
12741 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012742 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012743
Dave Barach72d72232016-08-04 10:15:08 -040012744 if (sw_if_index == ~0)
12745 {
12746 errmsg ("missing interface name or sw_if_index\n");
12747 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012748 }
12749
Dave Barach72d72232016-08-04 10:15:08 -040012750 /* Construct the API message */
12751 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12752 mp->sw_if_index = ntohl (sw_if_index);
12753 mp->fib_id = ntohl (fib_id);
12754 mp->ip4 = ip4;
12755 mp->ip6 = ip6;
12756 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012757
Dave Barach72d72232016-08-04 10:15:08 -040012758 /* send it... */
12759 S;
12760 /* Wait for the reply */
12761 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012762}
12763
Dave Barach72d72232016-08-04 10:15:08 -040012764static int
12765api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012766{
Dave Barach72d72232016-08-04 10:15:08 -040012767 vl_api_get_node_graph_t *mp;
12768 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012769
Dave Barach72d72232016-08-04 10:15:08 -040012770 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012771
Dave Barach72d72232016-08-04 10:15:08 -040012772 /* send it... */
12773 S;
12774 /* Wait for the reply */
12775 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012776}
12777
Dave Barach72d72232016-08-04 10:15:08 -040012778/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012779/** Used for parsing LISP eids */
12780typedef CLIB_PACKED(struct{
12781 u8 addr[16]; /**< eid address */
12782 u32 len; /**< prefix length if IP */
12783 u8 type; /**< type of eid */
12784}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012785/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012786
12787static uword
12788unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12789{
Dave Barach72d72232016-08-04 10:15:08 -040012790 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012791
Dave Barach72d72232016-08-04 10:15:08 -040012792 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012793
Dave Barach72d72232016-08-04 10:15:08 -040012794 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12795 {
12796 a->type = 0; /* ipv4 type */
12797 }
12798 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12799 {
12800 a->type = 1; /* ipv6 type */
12801 }
12802 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12803 {
12804 a->type = 2; /* mac type */
12805 }
12806 else
12807 {
Florin Coras429e7952016-08-02 02:31:03 +020012808 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012809 }
Florin Coras429e7952016-08-02 02:31:03 +020012810
Dave Barach72d72232016-08-04 10:15:08 -040012811 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12812 {
Florin Coras429e7952016-08-02 02:31:03 +020012813 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012814 }
Florin Coras429e7952016-08-02 02:31:03 +020012815
12816 return 1;
12817}
12818
12819static int
12820lisp_eid_size_vat (u8 type)
12821{
Dave Barach72d72232016-08-04 10:15:08 -040012822 switch (type)
12823 {
Florin Coras429e7952016-08-02 02:31:03 +020012824 case 0:
12825 return 4;
12826 case 1:
12827 return 16;
12828 case 2:
12829 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012830 }
Florin Coras429e7952016-08-02 02:31:03 +020012831 return 0;
12832}
12833
12834static void
12835lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12836{
Dave Barach72d72232016-08-04 10:15:08 -040012837 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012838}
12839
Dave Barach72d72232016-08-04 10:15:08 -040012840/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012841/** Used for transferring locators via VPP API */
12842typedef CLIB_PACKED(struct
12843{
Dave Barach72d72232016-08-04 10:15:08 -040012844 u32 sw_if_index; /**< locator sw_if_index */
12845 u8 priority; /**< locator priority */
12846 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012847}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012848/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012849
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012850static int
Dave Barach72d72232016-08-04 10:15:08 -040012851api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012852{
Dave Barach72d72232016-08-04 10:15:08 -040012853 unformat_input_t *input = vam->input;
12854 vl_api_lisp_add_del_locator_set_t *mp;
12855 f64 timeout = ~0;
12856 u8 is_add = 1;
12857 u8 *locator_set_name = NULL;
12858 u8 locator_set_name_set = 0;
12859 ls_locator_t locator, *locators = 0;
12860 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012861 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012862
Dave Barach72d72232016-08-04 10:15:08 -040012863 /* Parse args required to build the message */
12864 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12865 {
12866 if (unformat (input, "del"))
12867 {
12868 is_add = 0;
12869 }
12870 else if (unformat (input, "locator-set %s", &locator_set_name))
12871 {
12872 locator_set_name_set = 1;
12873 }
12874 else if (unformat (input, "sw_if_index %u p %u w %u",
12875 &sw_if_index, &priority, &weight))
12876 {
12877 locator.sw_if_index = htonl (sw_if_index);
12878 locator.priority = priority;
12879 locator.weight = weight;
12880 vec_add1 (locators, locator);
12881 }
12882 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12883 vam, &sw_if_index, &priority, &weight))
12884 {
12885 locator.sw_if_index = htonl (sw_if_index);
12886 locator.priority = priority;
12887 locator.weight = weight;
12888 vec_add1 (locators, locator);
12889 }
12890 else
12891 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012892 }
12893
Dave Barach72d72232016-08-04 10:15:08 -040012894 if (locator_set_name_set == 0)
12895 {
12896 errmsg ("missing locator-set name");
12897 vec_free (locators);
12898 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012899 }
12900
Dave Barach72d72232016-08-04 10:15:08 -040012901 if (vec_len (locator_set_name) > 64)
12902 {
12903 errmsg ("locator-set name too long\n");
12904 vec_free (locator_set_name);
12905 vec_free (locators);
12906 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012907 }
Dave Barach72d72232016-08-04 10:15:08 -040012908 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012909
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012910 data_len = sizeof (ls_locator_t) * vec_len (locators);
12911
Dave Barach72d72232016-08-04 10:15:08 -040012912 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012913 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012914
Dave Barach72d72232016-08-04 10:15:08 -040012915 mp->is_add = is_add;
12916 clib_memcpy (mp->locator_set_name, locator_set_name,
12917 vec_len (locator_set_name));
12918 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012919
Filip Tehlare3552c42016-08-26 12:44:38 +020012920 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012921 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012922 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012923 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012924
Dave Barach72d72232016-08-04 10:15:08 -040012925 /* send it... */
12926 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012927
Dave Barach72d72232016-08-04 10:15:08 -040012928 /* Wait for a reply... */
12929 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012930
Dave Barach72d72232016-08-04 10:15:08 -040012931 /* NOTREACHED */
12932 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012933}
12934
12935static int
Dave Barach72d72232016-08-04 10:15:08 -040012936api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012937{
Dave Barach72d72232016-08-04 10:15:08 -040012938 unformat_input_t *input = vam->input;
12939 vl_api_lisp_add_del_locator_t *mp;
12940 f64 timeout = ~0;
12941 u32 tmp_if_index = ~0;
12942 u32 sw_if_index = ~0;
12943 u8 sw_if_index_set = 0;
12944 u8 sw_if_index_if_name_set = 0;
12945 u32 priority = ~0;
12946 u8 priority_set = 0;
12947 u32 weight = ~0;
12948 u8 weight_set = 0;
12949 u8 is_add = 1;
12950 u8 *locator_set_name = NULL;
12951 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012952
Dave Barach72d72232016-08-04 10:15:08 -040012953 /* Parse args required to build the message */
12954 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12955 {
12956 if (unformat (input, "del"))
12957 {
12958 is_add = 0;
12959 }
12960 else if (unformat (input, "locator-set %s", &locator_set_name))
12961 {
12962 locator_set_name_set = 1;
12963 }
12964 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12965 &tmp_if_index))
12966 {
12967 sw_if_index_if_name_set = 1;
12968 sw_if_index = tmp_if_index;
12969 }
12970 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12971 {
12972 sw_if_index_set = 1;
12973 sw_if_index = tmp_if_index;
12974 }
12975 else if (unformat (input, "p %d", &priority))
12976 {
12977 priority_set = 1;
12978 }
12979 else if (unformat (input, "w %d", &weight))
12980 {
12981 weight_set = 1;
12982 }
12983 else
12984 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012985 }
12986
Dave Barach72d72232016-08-04 10:15:08 -040012987 if (locator_set_name_set == 0)
12988 {
12989 errmsg ("missing locator-set name");
12990 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012991 }
12992
Dave Barach72d72232016-08-04 10:15:08 -040012993 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12994 {
12995 errmsg ("missing sw_if_index");
12996 vec_free (locator_set_name);
12997 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012998 }
12999
Dave Barach72d72232016-08-04 10:15:08 -040013000 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
13001 {
13002 errmsg ("cannot use both params interface name and sw_if_index");
13003 vec_free (locator_set_name);
13004 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013005 }
13006
Dave Barach72d72232016-08-04 10:15:08 -040013007 if (priority_set == 0)
13008 {
13009 errmsg ("missing locator-set priority\n");
13010 vec_free (locator_set_name);
13011 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013012 }
13013
Dave Barach72d72232016-08-04 10:15:08 -040013014 if (weight_set == 0)
13015 {
13016 errmsg ("missing locator-set weight\n");
13017 vec_free (locator_set_name);
13018 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013019 }
13020
Dave Barach72d72232016-08-04 10:15:08 -040013021 if (vec_len (locator_set_name) > 64)
13022 {
13023 errmsg ("locator-set name too long\n");
13024 vec_free (locator_set_name);
13025 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013026 }
Dave Barach72d72232016-08-04 10:15:08 -040013027 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013028
Dave Barach72d72232016-08-04 10:15:08 -040013029 /* Construct the API message */
13030 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013031
Dave Barach72d72232016-08-04 10:15:08 -040013032 mp->is_add = is_add;
13033 mp->sw_if_index = ntohl (sw_if_index);
13034 mp->priority = priority;
13035 mp->weight = weight;
13036 clib_memcpy (mp->locator_set_name, locator_set_name,
13037 vec_len (locator_set_name));
13038 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013039
Dave Barach72d72232016-08-04 10:15:08 -040013040 /* send it... */
13041 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013042
Dave Barach72d72232016-08-04 10:15:08 -040013043 /* Wait for a reply... */
13044 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013045
Dave Barach72d72232016-08-04 10:15:08 -040013046 /* NOTREACHED */
13047 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013048}
13049
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013050uword
13051unformat_hmac_key_id (unformat_input_t * input, va_list * args)
13052{
13053 u32 *key_id = va_arg (*args, u32 *);
13054 u8 *s = 0;
13055
13056 if (unformat (input, "%s", &s))
13057 {
13058 if (!strcmp ((char *) s, "sha1"))
13059 key_id[0] = HMAC_SHA_1_96;
13060 else if (!strcmp ((char *) s, "sha256"))
13061 key_id[0] = HMAC_SHA_256_128;
13062 else
13063 {
13064 clib_warning ("invalid key_id: '%s'", s);
13065 key_id[0] = HMAC_NO_KEY;
13066 }
13067 }
13068 else
13069 return 0;
13070
13071 vec_free (s);
13072 return 1;
13073}
13074
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013075static int
Dave Barach72d72232016-08-04 10:15:08 -040013076api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013077{
Dave Barach72d72232016-08-04 10:15:08 -040013078 unformat_input_t *input = vam->input;
13079 vl_api_lisp_add_del_local_eid_t *mp;
13080 f64 timeout = ~0;
13081 u8 is_add = 1;
13082 u8 eid_set = 0;
13083 lisp_eid_vat_t _eid, *eid = &_eid;
13084 u8 *locator_set_name = 0;
13085 u8 locator_set_name_set = 0;
13086 u32 vni = 0;
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013087 u16 key_id = 0;
13088 u8 *key = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013089
Dave Barach72d72232016-08-04 10:15:08 -040013090 /* Parse args required to build the message */
13091 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13092 {
13093 if (unformat (input, "del"))
13094 {
13095 is_add = 0;
13096 }
13097 else if (unformat (input, "vni %d", &vni))
13098 {
13099 ;
13100 }
13101 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
13102 {
13103 eid_set = 1;
13104 }
13105 else if (unformat (input, "locator-set %s", &locator_set_name))
13106 {
13107 locator_set_name_set = 1;
13108 }
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013109 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
13110 ;
13111 else if (unformat (input, "secret-key %_%v%_", &key))
13112 ;
Dave Barach72d72232016-08-04 10:15:08 -040013113 else
13114 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013115 }
13116
Dave Barach72d72232016-08-04 10:15:08 -040013117 if (locator_set_name_set == 0)
13118 {
13119 errmsg ("missing locator-set name\n");
13120 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013121 }
13122
Dave Barach72d72232016-08-04 10:15:08 -040013123 if (0 == eid_set)
13124 {
13125 errmsg ("EID address not set!");
13126 vec_free (locator_set_name);
13127 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020013128 }
13129
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013130 if (key && (0 == key_id))
13131 {
13132 errmsg ("invalid key_id!");
13133 return -99;
13134 }
13135
13136 if (vec_len (key) > 64)
13137 {
13138 errmsg ("key too long");
13139 vec_free (key);
13140 return -99;
13141 }
13142
Dave Barach72d72232016-08-04 10:15:08 -040013143 if (vec_len (locator_set_name) > 64)
13144 {
13145 errmsg ("locator-set name too long\n");
13146 vec_free (locator_set_name);
13147 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013148 }
Dave Barach72d72232016-08-04 10:15:08 -040013149 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013150
Dave Barach72d72232016-08-04 10:15:08 -040013151 /* Construct the API message */
13152 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013153
Dave Barach72d72232016-08-04 10:15:08 -040013154 mp->is_add = is_add;
13155 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
13156 mp->eid_type = eid->type;
13157 mp->prefix_len = eid->len;
13158 mp->vni = clib_host_to_net_u32 (vni);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013159 mp->key_id = clib_host_to_net_u16 (key_id);
Dave Barach72d72232016-08-04 10:15:08 -040013160 clib_memcpy (mp->locator_set_name, locator_set_name,
13161 vec_len (locator_set_name));
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013162 clib_memcpy (mp->key, key, vec_len (key));
Florin Coras429e7952016-08-02 02:31:03 +020013163
Dave Barach72d72232016-08-04 10:15:08 -040013164 vec_free (locator_set_name);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013165 vec_free (key);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013166
Dave Barach72d72232016-08-04 10:15:08 -040013167 /* send it... */
13168 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013169
Dave Barach72d72232016-08-04 10:15:08 -040013170 /* Wait for a reply... */
13171 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013172
Dave Barach72d72232016-08-04 10:15:08 -040013173 /* NOTREACHED */
13174 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013175}
13176
Dave Barach72d72232016-08-04 10:15:08 -040013177/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020013178/** Used for transferring locators via VPP API */
13179typedef CLIB_PACKED(struct
13180{
Dave Barach72d72232016-08-04 10:15:08 -040013181 u8 is_ip4; /**< is locator an IPv4 address? */
13182 u8 priority; /**< locator priority */
13183 u8 weight; /**< locator weight */
13184 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020013185}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040013186/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020013187
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013188static int
Dave Barach72d72232016-08-04 10:15:08 -040013189api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013190{
Dave Barach72d72232016-08-04 10:15:08 -040013191 unformat_input_t *input = vam->input;
13192 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
13193 f64 timeout = ~0;
13194 u8 is_add = 1;
13195 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
13196 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
13197 u8 rmt_eid_set = 0, lcl_eid_set = 0;
13198 u32 action = ~0, p, w;
13199 ip4_address_t rmt_rloc4, lcl_rloc4;
13200 ip6_address_t rmt_rloc6, lcl_rloc6;
13201 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013202
Dave Barach839fe3e2016-08-10 11:35:54 -040013203 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020013204
Dave Barach72d72232016-08-04 10:15:08 -040013205 /* Parse args required to build the message */
13206 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13207 {
13208 if (unformat (input, "del"))
13209 {
13210 is_add = 0;
13211 }
13212 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
13213 {
13214 rmt_eid_set = 1;
13215 }
13216 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
13217 {
13218 lcl_eid_set = 1;
13219 }
13220 else if (unformat (input, "p %d w %d", &p, &w))
13221 {
13222 if (!curr_rloc)
13223 {
13224 errmsg ("No RLOC configured for setting priority/weight!");
13225 return -99;
13226 }
13227 curr_rloc->priority = p;
13228 curr_rloc->weight = w;
13229 }
13230 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
13231 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
13232 {
13233 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020013234
Dave Barach72d72232016-08-04 10:15:08 -040013235 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020013236 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013237 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013238
Dave Barach72d72232016-08-04 10:15:08 -040013239 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
13240 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013241 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013242 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13243 }
Florin Coras7fbfad32016-08-05 16:57:33 +020013244 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040013245 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
13246 {
13247 rloc.is_ip4 = 0;
13248 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020013249 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013250 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013251
Dave Barach72d72232016-08-04 10:15:08 -040013252 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
13253 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013254 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013255 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13256 }
13257 else if (unformat (input, "action %d", &action))
13258 {
13259 ;
13260 }
13261 else
13262 {
13263 clib_warning ("parse error '%U'", format_unformat_error, input);
13264 return -99;
13265 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013266 }
13267
Dave Barach72d72232016-08-04 10:15:08 -040013268 if (!rmt_eid_set)
13269 {
13270 errmsg ("remote eid addresses not set\n");
13271 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013272 }
13273
Dave Barach72d72232016-08-04 10:15:08 -040013274 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
13275 {
13276 errmsg ("eid types don't match\n");
13277 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013278 }
13279
Dave Barach839fe3e2016-08-10 11:35:54 -040013280 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020013281 {
13282 errmsg ("action not set for negative mapping\n");
13283 return -99;
13284 }
13285
Dave Barach72d72232016-08-04 10:15:08 -040013286 /* Construct the API message */
13287 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013288
Dave Barach72d72232016-08-04 10:15:08 -040013289 mp->is_add = is_add;
13290 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
13291 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
13292 mp->eid_type = rmt_eid->type;
13293 mp->rmt_len = rmt_eid->len;
13294 mp->lcl_len = lcl_eid->len;
13295 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020013296
Florin Coras7fbfad32016-08-05 16:57:33 +020013297 if (0 != rmt_locs && 0 != lcl_locs)
13298 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013299 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020013300 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013301 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013302 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013303 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013304 }
Dave Barach72d72232016-08-04 10:15:08 -040013305 vec_free (lcl_locs);
13306 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013307
Dave Barach72d72232016-08-04 10:15:08 -040013308 /* send it... */
13309 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013310
Dave Barach72d72232016-08-04 10:15:08 -040013311 /* Wait for a reply... */
13312 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013313
Dave Barach72d72232016-08-04 10:15:08 -040013314 /* NOTREACHED */
13315 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013316}
13317
13318static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013319api_lisp_add_del_map_server (vat_main_t * vam)
13320{
13321 unformat_input_t *input = vam->input;
13322 vl_api_lisp_add_del_map_server_t *mp;
13323 f64 timeout = ~0;
13324 u8 is_add = 1;
13325 u8 ipv4_set = 0;
13326 u8 ipv6_set = 0;
13327 ip4_address_t ipv4;
13328 ip6_address_t ipv6;
13329
13330 /* Parse args required to build the message */
13331 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13332 {
13333 if (unformat (input, "del"))
13334 {
13335 is_add = 0;
13336 }
13337 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13338 {
13339 ipv4_set = 1;
13340 }
13341 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13342 {
13343 ipv6_set = 1;
13344 }
13345 else
13346 break;
13347 }
13348
13349 if (ipv4_set && ipv6_set)
13350 {
13351 errmsg ("both eid v4 and v6 addresses set\n");
13352 return -99;
13353 }
13354
13355 if (!ipv4_set && !ipv6_set)
13356 {
13357 errmsg ("eid addresses not set\n");
13358 return -99;
13359 }
13360
13361 /* Construct the API message */
13362 M (LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server);
13363
13364 mp->is_add = is_add;
13365 if (ipv6_set)
13366 {
13367 mp->is_ipv6 = 1;
13368 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13369 }
13370 else
13371 {
13372 mp->is_ipv6 = 0;
13373 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
13374 }
13375
13376 /* send it... */
13377 S;
13378
13379 /* Wait for a reply... */
13380 W;
13381
13382 /* NOTREACHED */
13383 return 0;
13384}
13385
13386static int
Dave Barach72d72232016-08-04 10:15:08 -040013387api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013388{
Dave Barach72d72232016-08-04 10:15:08 -040013389 unformat_input_t *input = vam->input;
13390 vl_api_lisp_add_del_map_resolver_t *mp;
13391 f64 timeout = ~0;
13392 u8 is_add = 1;
13393 u8 ipv4_set = 0;
13394 u8 ipv6_set = 0;
13395 ip4_address_t ipv4;
13396 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013397
Dave Barach72d72232016-08-04 10:15:08 -040013398 /* Parse args required to build the message */
13399 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13400 {
13401 if (unformat (input, "del"))
13402 {
13403 is_add = 0;
13404 }
13405 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13406 {
13407 ipv4_set = 1;
13408 }
13409 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13410 {
13411 ipv6_set = 1;
13412 }
13413 else
13414 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013415 }
13416
Dave Barach72d72232016-08-04 10:15:08 -040013417 if (ipv4_set && ipv6_set)
13418 {
13419 errmsg ("both eid v4 and v6 addresses set\n");
13420 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013421 }
13422
Dave Barach72d72232016-08-04 10:15:08 -040013423 if (!ipv4_set && !ipv6_set)
13424 {
13425 errmsg ("eid addresses not set\n");
13426 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013427 }
13428
Dave Barach72d72232016-08-04 10:15:08 -040013429 /* Construct the API message */
13430 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013431
Dave Barach72d72232016-08-04 10:15:08 -040013432 mp->is_add = is_add;
13433 if (ipv6_set)
13434 {
13435 mp->is_ipv6 = 1;
13436 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13437 }
13438 else
13439 {
13440 mp->is_ipv6 = 0;
13441 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013442 }
13443
Dave Barach72d72232016-08-04 10:15:08 -040013444 /* send it... */
13445 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013446
Dave Barach72d72232016-08-04 10:15:08 -040013447 /* Wait for a reply... */
13448 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013449
Dave Barach72d72232016-08-04 10:15:08 -040013450 /* NOTREACHED */
13451 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013452}
13453
13454static int
Florin Coras577c3552016-04-21 00:45:40 +020013455api_lisp_gpe_enable_disable (vat_main_t * vam)
13456{
Dave Barach72d72232016-08-04 10:15:08 -040013457 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013458 vl_api_lisp_gpe_enable_disable_t *mp;
13459 f64 timeout = ~0;
13460 u8 is_set = 0;
13461 u8 is_en = 1;
13462
13463 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013464 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13465 {
13466 if (unformat (input, "enable"))
13467 {
13468 is_set = 1;
13469 is_en = 1;
13470 }
13471 else if (unformat (input, "disable"))
13472 {
13473 is_set = 1;
13474 is_en = 0;
13475 }
13476 else
13477 break;
13478 }
Florin Coras577c3552016-04-21 00:45:40 +020013479
Dave Barach72d72232016-08-04 10:15:08 -040013480 if (is_set == 0)
13481 {
13482 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013483 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013484 }
Florin Coras577c3552016-04-21 00:45:40 +020013485
13486 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013487 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013488
13489 mp->is_en = is_en;
13490
13491 /* send it... */
13492 S;
13493
13494 /* Wait for a reply... */
13495 W;
13496
13497 /* NOTREACHED */
13498 return 0;
13499}
13500
13501static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013502api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
13503{
13504 unformat_input_t *input = vam->input;
13505 vl_api_lisp_rloc_probe_enable_disable_t *mp;
13506 f64 timeout = ~0;
13507 u8 is_set = 0;
13508 u8 is_en = 0;
13509
13510 /* Parse args required to build the message */
13511 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13512 {
13513 if (unformat (input, "enable"))
13514 {
13515 is_set = 1;
13516 is_en = 1;
13517 }
13518 else if (unformat (input, "disable"))
13519 is_set = 1;
13520 else
13521 break;
13522 }
13523
13524 if (!is_set)
13525 {
13526 errmsg ("Value not set\n");
13527 return -99;
13528 }
13529
13530 /* Construct the API message */
13531 M (LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable);
13532
13533 mp->is_enabled = is_en;
13534
13535 /* send it... */
13536 S;
13537
13538 /* Wait for a reply... */
13539 W;
13540
13541 /* NOTREACHED */
13542 return 0;
13543}
13544
13545static int
13546api_lisp_map_register_enable_disable (vat_main_t * vam)
13547{
13548 unformat_input_t *input = vam->input;
13549 vl_api_lisp_map_register_enable_disable_t *mp;
13550 f64 timeout = ~0;
13551 u8 is_set = 0;
13552 u8 is_en = 0;
13553
13554 /* Parse args required to build the message */
13555 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13556 {
13557 if (unformat (input, "enable"))
13558 {
13559 is_set = 1;
13560 is_en = 1;
13561 }
13562 else if (unformat (input, "disable"))
13563 is_set = 1;
13564 else
13565 break;
13566 }
13567
13568 if (!is_set)
13569 {
13570 errmsg ("Value not set\n");
13571 return -99;
13572 }
13573
13574 /* Construct the API message */
13575 M (LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable);
13576
13577 mp->is_enabled = is_en;
13578
13579 /* send it... */
13580 S;
13581
13582 /* Wait for a reply... */
13583 W;
13584
13585 /* NOTREACHED */
13586 return 0;
13587}
13588
13589static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013590api_lisp_enable_disable (vat_main_t * vam)
13591{
Dave Barach72d72232016-08-04 10:15:08 -040013592 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013593 vl_api_lisp_enable_disable_t *mp;
13594 f64 timeout = ~0;
13595 u8 is_set = 0;
13596 u8 is_en = 0;
13597
13598 /* Parse args required to build the message */
13599 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13600 {
13601 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013602 {
13603 is_set = 1;
13604 is_en = 1;
13605 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013606 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013607 {
13608 is_set = 1;
13609 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013610 else
Dave Barach72d72232016-08-04 10:15:08 -040013611 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013612 }
13613
13614 if (!is_set)
13615 {
13616 errmsg ("Value not set\n");
13617 return -99;
13618 }
13619
13620 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013621 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013622
13623 mp->is_en = is_en;
13624
13625 /* send it... */
13626 S;
13627
13628 /* Wait for a reply... */
13629 W;
13630
13631 /* NOTREACHED */
13632 return 0;
13633}
13634
Florin Corasdca88042016-09-14 16:01:38 +020013635static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013636api_show_lisp_map_register_state (vat_main_t * vam)
13637{
13638 f64 timeout = ~0;
13639 vl_api_show_lisp_map_register_state_t *mp;
13640
13641 M (SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state);
13642
13643 /* send */
13644 S;
13645
13646 /* wait for reply */
13647 W;
13648
13649 return 0;
13650}
13651
13652static int
13653api_show_lisp_rloc_probe_state (vat_main_t * vam)
13654{
13655 f64 timeout = ~0;
13656 vl_api_show_lisp_rloc_probe_state_t *mp;
13657
13658 M (SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state);
13659
13660 /* send */
13661 S;
13662
13663 /* wait for reply */
13664 W;
13665
13666 return 0;
13667}
13668
13669static int
Florin Corasdca88042016-09-14 16:01:38 +020013670api_show_lisp_map_request_mode (vat_main_t * vam)
13671{
13672 f64 timeout = ~0;
13673 vl_api_show_lisp_map_request_mode_t *mp;
13674
13675 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13676
13677 /* send */
13678 S;
13679
13680 /* wait for reply */
13681 W;
13682
13683 return 0;
13684}
13685
13686static int
13687api_lisp_map_request_mode (vat_main_t * vam)
13688{
13689 f64 timeout = ~0;
13690 unformat_input_t *input = vam->input;
13691 vl_api_lisp_map_request_mode_t *mp;
13692 u8 mode = 0;
13693
13694 /* Parse args required to build the message */
13695 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13696 {
13697 if (unformat (input, "dst-only"))
13698 mode = 0;
13699 else if (unformat (input, "src-dst"))
13700 mode = 1;
13701 else
13702 {
13703 errmsg ("parse error '%U'", format_unformat_error, input);
13704 return -99;
13705 }
13706 }
13707
13708 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13709
13710 mp->mode = mode;
13711
13712 /* send */
13713 S;
13714
13715 /* wait for reply */
13716 W;
13717
13718 /* notreached */
13719 return 0;
13720}
13721
Filip Tehlar195bcee2016-05-13 17:37:35 +020013722/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013723 * Enable/disable LISP proxy ITR.
13724 *
13725 * @param vam vpp API test context
13726 * @return return code
13727 */
13728static int
13729api_lisp_pitr_set_locator_set (vat_main_t * vam)
13730{
13731 f64 timeout = ~0;
13732 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013733 unformat_input_t *input = vam->input;
13734 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013735 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013736 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013737
13738 /* Parse args required to build the message */
13739 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13740 {
13741 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013742 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013743 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013744 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013745 else
Dave Barach72d72232016-08-04 10:15:08 -040013746 {
13747 errmsg ("parse error '%U'", format_unformat_error, input);
13748 return -99;
13749 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013750 }
13751
13752 if (!ls_name_set)
13753 {
13754 errmsg ("locator-set name not set!");
13755 return -99;
13756 }
13757
Dave Barach72d72232016-08-04 10:15:08 -040013758 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013759
13760 mp->is_add = is_add;
13761 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13762 vec_free (ls_name);
13763
13764 /* send */
13765 S;
13766
13767 /* wait for reply */
13768 W;
13769
Dave Barach72d72232016-08-04 10:15:08 -040013770 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013771 return 0;
13772}
13773
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013774static int
13775api_show_lisp_pitr (vat_main_t * vam)
13776{
Dave Barach72d72232016-08-04 10:15:08 -040013777 vl_api_show_lisp_pitr_t *mp;
13778 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013779
Dave Barach72d72232016-08-04 10:15:08 -040013780 if (!vam->json_output)
13781 {
13782 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013783 }
13784
Dave Barach72d72232016-08-04 10:15:08 -040013785 M (SHOW_LISP_PITR, show_lisp_pitr);
13786 /* send it... */
13787 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013788
Dave Barach72d72232016-08-04 10:15:08 -040013789 /* Wait for a reply... */
13790 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013791
Dave Barach72d72232016-08-04 10:15:08 -040013792 /* NOTREACHED */
13793 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013794}
13795
Filip Tehlar53f09e32016-05-19 14:25:44 +020013796/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013797 * Add/delete mapping between vni and vrf
13798 */
13799static int
13800api_lisp_eid_table_add_del_map (vat_main_t * vam)
13801{
13802 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013803 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013804 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013805 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13806 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013807
13808 /* Parse args required to build the message */
13809 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13810 {
13811 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013812 is_add = 0;
13813 else if (unformat (input, "vrf %d", &vrf))
13814 vrf_set = 1;
13815 else if (unformat (input, "bd_index %d", &bd_index))
13816 bd_index_set = 1;
13817 else if (unformat (input, "vni %d", &vni))
13818 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013819 else
Dave Barach72d72232016-08-04 10:15:08 -040013820 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013821 }
13822
Florin Coras1a1adc72016-07-22 01:45:30 +020013823 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013824 {
13825 errmsg ("missing arguments!");
13826 return -99;
13827 }
13828
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013829 if (vrf_set && bd_index_set)
13830 {
13831 errmsg ("error: both vrf and bd entered!");
13832 return -99;
13833 }
13834
Dave Barach72d72232016-08-04 10:15:08 -040013835 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013836
13837 mp->is_add = is_add;
13838 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013839 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013840 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013841
13842 /* send */
13843 S;
13844
13845 /* wait for reply */
13846 W;
13847
Dave Barach72d72232016-08-04 10:15:08 -040013848 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013849 return 0;
13850}
13851
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013852uword
13853unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13854{
13855 u32 *action = va_arg (*args, u32 *);
13856 u8 *s = 0;
13857
13858 if (unformat (input, "%s", &s))
13859 {
13860 if (!strcmp ((char *) s, "no-action"))
13861 action[0] = 0;
13862 else if (!strcmp ((char *) s, "natively-forward"))
13863 action[0] = 1;
13864 else if (!strcmp ((char *) s, "send-map-request"))
13865 action[0] = 2;
13866 else if (!strcmp ((char *) s, "drop"))
13867 action[0] = 3;
13868 else
13869 {
13870 clib_warning ("invalid action: '%s'", s);
13871 action[0] = 3;
13872 }
13873 }
13874 else
13875 return 0;
13876
13877 vec_free (s);
13878 return 1;
13879}
13880
Filip Tehlar324112f2016-06-02 16:07:38 +020013881/**
Florin Corasf727db92016-06-23 15:01:58 +020013882 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013883 *
13884 * @param vam vpp API test context
13885 * @return return code
13886 */
13887static int
13888api_lisp_add_del_remote_mapping (vat_main_t * vam)
13889{
Dave Barach72d72232016-08-04 10:15:08 -040013890 unformat_input_t *input = vam->input;
13891 vl_api_lisp_add_del_remote_mapping_t *mp;
13892 f64 timeout = ~0;
13893 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013894 lisp_eid_vat_t _eid, *eid = &_eid;
13895 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013896 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013897 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013898 ip4_address_t rloc4;
13899 ip6_address_t rloc6;
13900 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013901
Dave Barach839fe3e2016-08-10 11:35:54 -040013902 memset (&rloc, 0, sizeof (rloc));
13903
Dave Barach72d72232016-08-04 10:15:08 -040013904 /* Parse args required to build the message */
13905 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13906 {
13907 if (unformat (input, "del-all"))
13908 {
13909 del_all = 1;
13910 }
13911 else if (unformat (input, "del"))
13912 {
13913 is_add = 0;
13914 }
13915 else if (unformat (input, "add"))
13916 {
13917 is_add = 1;
13918 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013919 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013920 {
13921 eid_set = 1;
13922 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013923 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013924 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013925 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013926 }
13927 else if (unformat (input, "vni %d", &vni))
13928 {
13929 ;
13930 }
13931 else if (unformat (input, "p %d w %d", &p, &w))
13932 {
13933 if (!curr_rloc)
13934 {
13935 errmsg ("No RLOC configured for setting priority/weight!");
13936 return -99;
13937 }
13938 curr_rloc->priority = p;
13939 curr_rloc->weight = w;
13940 }
13941 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13942 {
13943 rloc.is_ip4 = 1;
13944 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13945 vec_add1 (rlocs, rloc);
13946 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13947 }
13948 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13949 {
13950 rloc.is_ip4 = 0;
13951 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13952 vec_add1 (rlocs, rloc);
13953 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13954 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013955 else if (unformat (input, "action %U",
13956 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013957 {
13958 ;
13959 }
13960 else
13961 {
13962 clib_warning ("parse error '%U'", format_unformat_error, input);
13963 return -99;
13964 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013965 }
13966
Dave Barach72d72232016-08-04 10:15:08 -040013967 if (0 == eid_set)
13968 {
13969 errmsg ("missing params!");
13970 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013971 }
13972
Dave Barach72d72232016-08-04 10:15:08 -040013973 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13974 {
13975 errmsg ("no action set for negative map-reply!");
13976 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013977 }
13978
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013979 data_len = vec_len (rlocs) * sizeof (rloc_t);
13980
13981 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013982 mp->is_add = is_add;
13983 mp->vni = htonl (vni);
13984 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013985 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013986 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013987 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013988 mp->del_all = del_all;
13989 mp->eid_type = eid->type;
13990 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013991 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013992
Filip Tehlare3552c42016-08-26 12:44:38 +020013993 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013994 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013995 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013996
Dave Barach72d72232016-08-04 10:15:08 -040013997 /* send it... */
13998 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013999
Dave Barach72d72232016-08-04 10:15:08 -040014000 /* Wait for a reply... */
14001 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020014002
Dave Barach72d72232016-08-04 10:15:08 -040014003 /* NOTREACHED */
14004 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020014005}
14006
Florin Corasf727db92016-06-23 15:01:58 +020014007/**
14008 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
14009 * forwarding entries in data-plane accordingly.
14010 *
14011 * @param vam vpp API test context
14012 * @return return code
14013 */
14014static int
14015api_lisp_add_del_adjacency (vat_main_t * vam)
14016{
Dave Barach72d72232016-08-04 10:15:08 -040014017 unformat_input_t *input = vam->input;
14018 vl_api_lisp_add_del_adjacency_t *mp;
14019 f64 timeout = ~0;
14020 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014021 ip4_address_t leid4, reid4;
14022 ip6_address_t leid6, reid6;
14023 u8 reid_mac[6] = { 0 };
14024 u8 leid_mac[6] = { 0 };
14025 u8 reid_type, leid_type;
14026 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040014027 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020014028
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014029 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020014030
Dave Barach72d72232016-08-04 10:15:08 -040014031 /* Parse args required to build the message */
14032 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14033 {
14034 if (unformat (input, "del"))
14035 {
14036 is_add = 0;
14037 }
14038 else if (unformat (input, "add"))
14039 {
14040 is_add = 1;
14041 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014042 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
14043 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014044 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014045 reid_type = 0; /* ipv4 */
14046 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014047 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014048 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
14049 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014050 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014051 reid_type = 1; /* ipv6 */
14052 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014053 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014054 else if (unformat (input, "reid %U", unformat_ethernet_address,
14055 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040014056 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014057 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040014058 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014059 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
14060 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014061 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014062 leid_type = 0; /* ipv4 */
14063 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014064 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014065 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
14066 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014067 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014068 leid_type = 1; /* ipv6 */
14069 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014070 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014071 else if (unformat (input, "leid %U", unformat_ethernet_address,
14072 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040014073 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014074 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040014075 }
14076 else if (unformat (input, "vni %d", &vni))
14077 {
14078 ;
14079 }
14080 else
14081 {
14082 errmsg ("parse error '%U'", format_unformat_error, input);
14083 return -99;
14084 }
Florin Corasf727db92016-06-23 15:01:58 +020014085 }
14086
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014087 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014088 {
14089 errmsg ("missing params!");
14090 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014091 }
14092
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014093 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014094 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014095 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040014096 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014097 }
14098
Dave Barach72d72232016-08-04 10:15:08 -040014099 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
14100 mp->is_add = is_add;
14101 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014102 mp->leid_len = leid_len;
14103 mp->reid_len = reid_len;
14104 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020014105
Dave Barach72d72232016-08-04 10:15:08 -040014106 switch (mp->eid_type)
14107 {
Florin Corasf727db92016-06-23 15:01:58 +020014108 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014109 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
14110 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040014111 break;
Florin Corasf727db92016-06-23 15:01:58 +020014112 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014113 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
14114 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040014115 break;
Florin Corasf727db92016-06-23 15:01:58 +020014116 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014117 clib_memcpy (mp->leid, leid_mac, 6);
14118 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040014119 break;
Florin Corasf727db92016-06-23 15:01:58 +020014120 default:
Dave Barach72d72232016-08-04 10:15:08 -040014121 errmsg ("unknown EID type %d!", mp->eid_type);
14122 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014123 }
14124
Dave Barach72d72232016-08-04 10:15:08 -040014125 /* send it... */
14126 S;
Florin Corasf727db92016-06-23 15:01:58 +020014127
Dave Barach72d72232016-08-04 10:15:08 -040014128 /* Wait for a reply... */
14129 W;
Florin Corasf727db92016-06-23 15:01:58 +020014130
Dave Barach72d72232016-08-04 10:15:08 -040014131 /* NOTREACHED */
14132 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014133}
14134
Filip Tehlar46d4e362016-05-09 09:39:26 +020014135static int
Dave Barach72d72232016-08-04 10:15:08 -040014136api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014137{
Dave Barach72d72232016-08-04 10:15:08 -040014138 unformat_input_t *input = vam->input;
14139 vl_api_lisp_gpe_add_del_iface_t *mp;
14140 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020014141 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040014142 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014143
Dave Barach72d72232016-08-04 10:15:08 -040014144 /* Parse args required to build the message */
14145 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14146 {
14147 if (unformat (input, "up"))
14148 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014149 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014150 is_add = 1;
14151 }
14152 else if (unformat (input, "down"))
14153 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014154 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014155 is_add = 0;
14156 }
14157 else if (unformat (input, "table_id %d", &dp_table))
14158 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014159 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014160 }
14161 else if (unformat (input, "bd_id %d", &dp_table))
14162 {
Dave Barach839fe3e2016-08-10 11:35:54 -040014163 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014164 is_l2 = 1;
14165 }
14166 else if (unformat (input, "vni %d", &vni))
14167 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014168 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014169 }
14170 else
14171 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014172 }
14173
Florin Coras7fbfad32016-08-05 16:57:33 +020014174 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040014175 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014176 errmsg ("Action not set\n");
14177 return -99;
14178 }
14179 if (dp_table_set == 0 || vni_set == 0)
14180 {
14181 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040014182 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014183 }
14184
Dave Barach72d72232016-08-04 10:15:08 -040014185 /* Construct the API message */
14186 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014187
Dave Barach72d72232016-08-04 10:15:08 -040014188 mp->is_add = is_add;
14189 mp->dp_table = dp_table;
14190 mp->is_l2 = is_l2;
14191 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014192
Dave Barach72d72232016-08-04 10:15:08 -040014193 /* send it... */
14194 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014195
Dave Barach72d72232016-08-04 10:15:08 -040014196 /* Wait for a reply... */
14197 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014198
Dave Barach72d72232016-08-04 10:15:08 -040014199 /* NOTREACHED */
14200 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014201}
14202
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014203/**
14204 * Add/del map request itr rlocs from LISP control plane and updates
14205 *
14206 * @param vam vpp API test context
14207 * @return return code
14208 */
14209static int
Dave Barach72d72232016-08-04 10:15:08 -040014210api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014211{
Dave Barach72d72232016-08-04 10:15:08 -040014212 unformat_input_t *input = vam->input;
14213 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
14214 f64 timeout = ~0;
14215 u8 *locator_set_name = 0;
14216 u8 locator_set_name_set = 0;
14217 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014218
Dave Barach72d72232016-08-04 10:15:08 -040014219 /* Parse args required to build the message */
14220 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014221 {
Dave Barach72d72232016-08-04 10:15:08 -040014222 if (unformat (input, "del"))
14223 {
14224 is_add = 0;
14225 }
14226 else if (unformat (input, "%_%v%_", &locator_set_name))
14227 {
14228 locator_set_name_set = 1;
14229 }
14230 else
14231 {
14232 clib_warning ("parse error '%U'", format_unformat_error, input);
14233 return -99;
14234 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014235 }
14236
Dave Barach72d72232016-08-04 10:15:08 -040014237 if (is_add && !locator_set_name_set)
14238 {
14239 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020014240 return -99;
14241 }
14242
Dave Barach72d72232016-08-04 10:15:08 -040014243 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020014244 {
Dave Barach72d72232016-08-04 10:15:08 -040014245 errmsg ("itr-rloc locator-set name too long\n");
14246 vec_free (locator_set_name);
14247 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014248 }
14249
Dave Barach72d72232016-08-04 10:15:08 -040014250 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
14251 mp->is_add = is_add;
14252 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014253 {
Dave Barach72d72232016-08-04 10:15:08 -040014254 clib_memcpy (mp->locator_set_name, locator_set_name,
14255 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014256 }
Dave Barach72d72232016-08-04 10:15:08 -040014257 else
14258 {
14259 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014260 }
Dave Barach72d72232016-08-04 10:15:08 -040014261 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014262
Dave Barach72d72232016-08-04 10:15:08 -040014263 /* send it... */
14264 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014265
Dave Barach72d72232016-08-04 10:15:08 -040014266 /* Wait for a reply... */
14267 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014268
Dave Barach72d72232016-08-04 10:15:08 -040014269 /* NOTREACHED */
14270 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014271}
14272
14273static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014274api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014275{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014276 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014277 vl_api_lisp_locator_dump_t *mp;
14278 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014279 u8 is_index_set = 0, is_name_set = 0;
14280 u8 *ls_name = 0;
14281 u32 ls_index = ~0;
14282
14283 /* Parse args required to build the message */
14284 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14285 {
14286 if (unformat (input, "ls_name %_%v%_", &ls_name))
14287 {
14288 is_name_set = 1;
14289 }
14290 else if (unformat (input, "ls_index %d", &ls_index))
14291 {
14292 is_index_set = 1;
14293 }
14294 else
14295 {
14296 errmsg ("parse error '%U'", format_unformat_error, input);
14297 return -99;
14298 }
14299 }
14300
14301 if (!is_index_set && !is_name_set)
14302 {
14303 errmsg ("error: expected one of index or name!\n");
14304 return -99;
14305 }
14306
14307 if (is_index_set && is_name_set)
14308 {
14309 errmsg ("error: only one param expected!\n");
14310 return -99;
14311 }
14312
Florin Coras042d2122016-09-21 16:38:19 +020014313 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020014314 {
14315 errmsg ("error: locator set name too long!");
14316 return -99;
14317 }
14318
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014319 if (!vam->json_output)
14320 {
14321 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
14322 "weight");
14323 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014324
Dave Barach72d72232016-08-04 10:15:08 -040014325 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014326 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014327
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014328 if (is_index_set)
14329 mp->ls_index = clib_host_to_net_u32 (ls_index);
14330 else
14331 {
14332 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020014333 strncpy ((char *) mp->ls_name, (char *) ls_name,
14334 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014335 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014336
Dave Barach72d72232016-08-04 10:15:08 -040014337 /* send it... */
14338 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014339
Dave Barach72d72232016-08-04 10:15:08 -040014340 /* Use a control ping for synchronization */
14341 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014342 vl_api_control_ping_t *mp;
14343 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014344 S;
14345 }
14346 /* Wait for a reply... */
14347 W;
Dave Barach72d72232016-08-04 10:15:08 -040014348
14349 /* NOTREACHED */
14350 return 0;
14351}
14352
14353static int
14354api_lisp_locator_set_dump (vat_main_t * vam)
14355{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014356 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014357 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014358 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040014359 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040014360
14361 /* Parse args required to build the message */
14362 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14363 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014364 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040014365 {
14366 filter = 1;
14367 }
14368 else if (unformat (input, "remote"))
14369 {
14370 filter = 2;
14371 }
14372 else
14373 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014374 errmsg ("parse error '%U'", format_unformat_error, input);
14375 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040014376 }
14377 }
14378
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014379 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040014380 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014381 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040014382 }
14383
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014384 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014385
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014386 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040014387
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014388 /* send it... */
14389 S;
14390
14391 /* Use a control ping for synchronization */
14392 {
14393 vl_api_control_ping_t *mp;
14394 M (CONTROL_PING, control_ping);
14395 S;
14396 }
14397 /* Wait for a reply... */
14398 W;
14399
14400 /* NOTREACHED */
14401 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040014402}
14403
14404static int
14405api_lisp_eid_table_map_dump (vat_main_t * vam)
14406{
Filip Tehlarc0681792016-08-24 14:11:07 +020014407 u8 is_l2 = 0;
14408 u8 mode_set = 0;
14409 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014410 vl_api_lisp_eid_table_map_dump_t *mp;
14411 f64 timeout = ~0;
14412
Filip Tehlarc0681792016-08-24 14:11:07 +020014413 /* Parse args required to build the message */
14414 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14415 {
14416 if (unformat (input, "l2"))
14417 {
14418 is_l2 = 1;
14419 mode_set = 1;
14420 }
14421 else if (unformat (input, "l3"))
14422 {
14423 is_l2 = 0;
14424 mode_set = 1;
14425 }
14426 else
14427 {
14428 errmsg ("parse error '%U'", format_unformat_error, input);
14429 return -99;
14430 }
14431 }
14432
14433 if (!mode_set)
14434 {
14435 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
14436 return -99;
14437 }
14438
Dave Barach72d72232016-08-04 10:15:08 -040014439 if (!vam->json_output)
14440 {
Filip Tehlarc0681792016-08-24 14:11:07 +020014441 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040014442 }
14443
14444 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020014445 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040014446
14447 /* send it... */
14448 S;
14449
14450 /* Use a control ping for synchronization */
14451 {
14452 vl_api_control_ping_t *mp;
14453 M (CONTROL_PING, control_ping);
14454 S;
14455 }
14456 /* Wait for a reply... */
14457 W;
14458
14459 /* NOTREACHED */
14460 return 0;
14461}
14462
14463static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020014464api_lisp_eid_table_vni_dump (vat_main_t * vam)
14465{
14466 vl_api_lisp_eid_table_vni_dump_t *mp;
14467 f64 timeout = ~0;
14468
14469 if (!vam->json_output)
14470 {
14471 fformat (vam->ofp, "VNI\n");
14472 }
14473
14474 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
14475
14476 /* send it... */
14477 S;
14478
14479 /* Use a control ping for synchronization */
14480 {
14481 vl_api_control_ping_t *mp;
14482 M (CONTROL_PING, control_ping);
14483 S;
14484 }
14485 /* Wait for a reply... */
14486 W;
14487
14488 /* NOTREACHED */
14489 return 0;
14490}
14491
14492static int
Dave Barach72d72232016-08-04 10:15:08 -040014493api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014494{
Dave Barach72d72232016-08-04 10:15:08 -040014495 unformat_input_t *i = vam->input;
14496 vl_api_lisp_eid_table_dump_t *mp;
14497 f64 timeout = ~0;
14498 struct in_addr ip4;
14499 struct in6_addr ip6;
14500 u8 mac[6];
14501 u8 eid_type = ~0, eid_set = 0;
14502 u32 prefix_length = ~0, t, vni = 0;
14503 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014504
Dave Barach72d72232016-08-04 10:15:08 -040014505 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014506 {
Dave Barach72d72232016-08-04 10:15:08 -040014507 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14508 {
14509 eid_set = 1;
14510 eid_type = 0;
14511 prefix_length = t;
14512 }
14513 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14514 {
14515 eid_set = 1;
14516 eid_type = 1;
14517 prefix_length = t;
14518 }
14519 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14520 {
14521 eid_set = 1;
14522 eid_type = 2;
14523 }
14524 else if (unformat (i, "vni %d", &t))
14525 {
14526 vni = t;
14527 }
14528 else if (unformat (i, "local"))
14529 {
14530 filter = 1;
14531 }
14532 else if (unformat (i, "remote"))
14533 {
14534 filter = 2;
14535 }
14536 else
14537 {
14538 errmsg ("parse error '%U'", format_unformat_error, i);
14539 return -99;
14540 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014541 }
14542
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014543 if (!vam->json_output)
14544 {
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014545 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s\n", "EID",
14546 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014547 }
14548
Dave Barach72d72232016-08-04 10:15:08 -040014549 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014550
Dave Barach72d72232016-08-04 10:15:08 -040014551 mp->filter = filter;
14552 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014553 {
Dave Barach72d72232016-08-04 10:15:08 -040014554 mp->eid_set = 1;
14555 mp->vni = htonl (vni);
14556 mp->eid_type = eid_type;
14557 switch (eid_type)
14558 {
14559 case 0:
14560 mp->prefix_length = prefix_length;
14561 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14562 break;
14563 case 1:
14564 mp->prefix_length = prefix_length;
14565 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14566 break;
14567 case 2:
14568 clib_memcpy (mp->eid, mac, sizeof (mac));
14569 break;
14570 default:
14571 errmsg ("unknown EID type %d!", eid_type);
14572 return -99;
14573 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014574 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014575
Dave Barach72d72232016-08-04 10:15:08 -040014576 /* send it... */
14577 S;
14578
14579 /* Use a control ping for synchronization */
14580 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014581 vl_api_control_ping_t *mp;
14582 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014583 S;
14584 }
14585
14586 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014587 W;
Dave Barach72d72232016-08-04 10:15:08 -040014588
14589 /* NOTREACHED */
14590 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014591}
14592
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014593static int
Dave Barach72d72232016-08-04 10:15:08 -040014594api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014595{
Dave Barach72d72232016-08-04 10:15:08 -040014596 vl_api_lisp_gpe_tunnel_dump_t *mp;
14597 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014598
Dave Barach72d72232016-08-04 10:15:08 -040014599 if (!vam->json_output)
14600 {
14601 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14602 "%=16s%=16s%=16s%=16s%=16s\n",
14603 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14604 "Decap next", "Lisp version", "Flags", "Next protocol",
14605 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014606 }
14607
Dave Barach72d72232016-08-04 10:15:08 -040014608 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14609 /* send it... */
14610 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014611
Dave Barach72d72232016-08-04 10:15:08 -040014612 /* Use a control ping for synchronization */
14613 {
14614 vl_api_control_ping_t *mp;
14615 M (CONTROL_PING, control_ping);
14616 S;
14617 }
14618 /* Wait for a reply... */
14619 W;
14620
14621 /* NOTREACHED */
14622 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014623}
14624
Matus Fabian8a95a482016-05-06 15:14:13 +020014625static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014626api_lisp_adjacencies_get (vat_main_t * vam)
14627{
14628 unformat_input_t *i = vam->input;
14629 vl_api_lisp_adjacencies_get_t *mp;
14630 f64 timeout = ~0;
14631 u8 vni_set = 0;
14632 u32 vni = ~0;
14633
14634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14635 {
14636 if (unformat (i, "vni %d", &vni))
14637 {
14638 vni_set = 1;
14639 }
14640 else
14641 {
14642 errmsg ("parse error '%U'\n", format_unformat_error, i);
14643 return -99;
14644 }
14645 }
14646
14647 if (!vni_set)
14648 {
14649 errmsg ("vni not set!\n");
14650 return -99;
14651 }
14652
14653 if (!vam->json_output)
14654 {
14655 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14656 }
14657
14658 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14659 mp->vni = clib_host_to_net_u32 (vni);
14660
14661 /* send it... */
14662 S;
14663
14664 /* Wait for a reply... */
14665 W;
14666
14667 /* NOTREACHED */
14668 return 0;
14669}
14670
14671static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014672api_lisp_map_server_dump (vat_main_t * vam)
14673{
14674 vl_api_lisp_map_server_dump_t *mp;
14675 f64 timeout = ~0;
14676
14677 if (!vam->json_output)
14678 {
14679 fformat (vam->ofp, "%=20s\n", "Map server");
14680 }
14681
14682 M (LISP_MAP_SERVER_DUMP, lisp_map_server_dump);
14683 /* send it... */
14684 S;
14685
14686 /* Use a control ping for synchronization */
14687 {
14688 vl_api_control_ping_t *mp;
14689 M (CONTROL_PING, control_ping);
14690 S;
14691 }
14692 /* Wait for a reply... */
14693 W;
14694
14695 /* NOTREACHED */
14696 return 0;
14697}
14698
14699static int
Dave Barach72d72232016-08-04 10:15:08 -040014700api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014701{
Dave Barach72d72232016-08-04 10:15:08 -040014702 vl_api_lisp_map_resolver_dump_t *mp;
14703 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014704
Dave Barach72d72232016-08-04 10:15:08 -040014705 if (!vam->json_output)
14706 {
14707 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014708 }
14709
Dave Barach72d72232016-08-04 10:15:08 -040014710 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14711 /* send it... */
14712 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014713
Dave Barach72d72232016-08-04 10:15:08 -040014714 /* Use a control ping for synchronization */
14715 {
14716 vl_api_control_ping_t *mp;
14717 M (CONTROL_PING, control_ping);
14718 S;
14719 }
14720 /* Wait for a reply... */
14721 W;
14722
14723 /* NOTREACHED */
14724 return 0;
14725}
14726
14727static int
14728api_show_lisp_status (vat_main_t * vam)
14729{
14730 vl_api_show_lisp_status_t *mp;
14731 f64 timeout = ~0;
14732
14733 if (!vam->json_output)
14734 {
14735 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14736 }
14737
14738 M (SHOW_LISP_STATUS, show_lisp_status);
14739 /* send it... */
14740 S;
14741 /* Wait for a reply... */
14742 W;
14743
14744 /* NOTREACHED */
14745 return 0;
14746}
14747
14748static int
14749api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14750{
14751 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14752 f64 timeout = ~0;
14753
14754 if (!vam->json_output)
14755 {
14756 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14757 }
14758
14759 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14760 /* send it... */
14761 S;
14762 /* Wait for a reply... */
14763 W;
14764
14765 /* NOTREACHED */
14766 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014767}
14768
14769static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014770api_af_packet_create (vat_main_t * vam)
14771{
Dave Barach72d72232016-08-04 10:15:08 -040014772 unformat_input_t *i = vam->input;
14773 vl_api_af_packet_create_t *mp;
14774 f64 timeout;
14775 u8 *host_if_name = 0;
14776 u8 hw_addr[6];
14777 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014778
Dave Barach72d72232016-08-04 10:15:08 -040014779 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014780
Dave Barach72d72232016-08-04 10:15:08 -040014781 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14782 {
14783 if (unformat (i, "name %s", &host_if_name))
14784 vec_add1 (host_if_name, 0);
14785 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14786 random_hw_addr = 0;
14787 else
14788 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014789 }
14790
Dave Barach72d72232016-08-04 10:15:08 -040014791 if (!vec_len (host_if_name))
14792 {
14793 errmsg ("host-interface name must be specified");
14794 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014795 }
14796
Dave Barach72d72232016-08-04 10:15:08 -040014797 if (vec_len (host_if_name) > 64)
14798 {
14799 errmsg ("host-interface name too long");
14800 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014801 }
14802
Dave Barach72d72232016-08-04 10:15:08 -040014803 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014804
Dave Barach72d72232016-08-04 10:15:08 -040014805 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14806 clib_memcpy (mp->hw_addr, hw_addr, 6);
14807 mp->use_random_hw_addr = random_hw_addr;
14808 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014809
Dave Barach72d72232016-08-04 10:15:08 -040014810 S;
14811 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14812 /* NOTREACHED */
14813 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014814}
14815
14816static int
14817api_af_packet_delete (vat_main_t * vam)
14818{
Dave Barach72d72232016-08-04 10:15:08 -040014819 unformat_input_t *i = vam->input;
14820 vl_api_af_packet_delete_t *mp;
14821 f64 timeout;
14822 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014823
Dave Barach72d72232016-08-04 10:15:08 -040014824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14825 {
14826 if (unformat (i, "name %s", &host_if_name))
14827 vec_add1 (host_if_name, 0);
14828 else
14829 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014830 }
14831
Dave Barach72d72232016-08-04 10:15:08 -040014832 if (!vec_len (host_if_name))
14833 {
14834 errmsg ("host-interface name must be specified");
14835 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014836 }
14837
Dave Barach72d72232016-08-04 10:15:08 -040014838 if (vec_len (host_if_name) > 64)
14839 {
14840 errmsg ("host-interface name too long");
14841 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014842 }
14843
Dave Barach72d72232016-08-04 10:15:08 -040014844 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014845
Dave Barach72d72232016-08-04 10:15:08 -040014846 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14847 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014848
Dave Barach72d72232016-08-04 10:15:08 -040014849 S;
14850 W;
14851 /* NOTREACHED */
14852 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014853}
14854
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014855static int
14856api_policer_add_del (vat_main_t * vam)
14857{
Dave Barach72d72232016-08-04 10:15:08 -040014858 unformat_input_t *i = vam->input;
14859 vl_api_policer_add_del_t *mp;
14860 f64 timeout;
14861 u8 is_add = 1;
14862 u8 *name = 0;
14863 u32 cir = 0;
14864 u32 eir = 0;
14865 u64 cb = 0;
14866 u64 eb = 0;
14867 u8 rate_type = 0;
14868 u8 round_type = 0;
14869 u8 type = 0;
14870 u8 color_aware = 0;
14871 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014872
Dave Barach839fe3e2016-08-10 11:35:54 -040014873 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14874 conform_action.dscp = 0;
14875 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14876 exceed_action.dscp = 0;
14877 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14878 violate_action.dscp = 0;
14879
Dave Barach72d72232016-08-04 10:15:08 -040014880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14881 {
14882 if (unformat (i, "del"))
14883 is_add = 0;
14884 else if (unformat (i, "name %s", &name))
14885 vec_add1 (name, 0);
14886 else if (unformat (i, "cir %u", &cir))
14887 ;
14888 else if (unformat (i, "eir %u", &eir))
14889 ;
14890 else if (unformat (i, "cb %u", &cb))
14891 ;
14892 else if (unformat (i, "eb %u", &eb))
14893 ;
14894 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14895 &rate_type))
14896 ;
14897 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14898 &round_type))
14899 ;
14900 else if (unformat (i, "type %U", unformat_policer_type, &type))
14901 ;
14902 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14903 &conform_action))
14904 ;
14905 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14906 &exceed_action))
14907 ;
14908 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14909 &violate_action))
14910 ;
14911 else if (unformat (i, "color-aware"))
14912 color_aware = 1;
14913 else
14914 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014915 }
14916
Dave Barach72d72232016-08-04 10:15:08 -040014917 if (!vec_len (name))
14918 {
14919 errmsg ("policer name must be specified");
14920 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014921 }
14922
Dave Barach72d72232016-08-04 10:15:08 -040014923 if (vec_len (name) > 64)
14924 {
14925 errmsg ("policer name too long");
14926 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014927 }
14928
Dave Barach72d72232016-08-04 10:15:08 -040014929 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014930
Dave Barach72d72232016-08-04 10:15:08 -040014931 clib_memcpy (mp->name, name, vec_len (name));
14932 vec_free (name);
14933 mp->is_add = is_add;
14934 mp->cir = cir;
14935 mp->eir = eir;
14936 mp->cb = cb;
14937 mp->eb = eb;
14938 mp->rate_type = rate_type;
14939 mp->round_type = round_type;
14940 mp->type = type;
14941 mp->conform_action_type = conform_action.action_type;
14942 mp->conform_dscp = conform_action.dscp;
14943 mp->exceed_action_type = exceed_action.action_type;
14944 mp->exceed_dscp = exceed_action.dscp;
14945 mp->violate_action_type = violate_action.action_type;
14946 mp->violate_dscp = violate_action.dscp;
14947 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014948
Dave Barach72d72232016-08-04 10:15:08 -040014949 S;
14950 W;
14951 /* NOTREACHED */
14952 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014953}
14954
Matus Fabian82e29c42016-05-11 04:49:46 -070014955static int
Dave Barach72d72232016-08-04 10:15:08 -040014956api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014957{
Dave Barach72d72232016-08-04 10:15:08 -040014958 unformat_input_t *i = vam->input;
14959 vl_api_policer_dump_t *mp;
14960 f64 timeout = ~0;
14961 u8 *match_name = 0;
14962 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014963
Dave Barach72d72232016-08-04 10:15:08 -040014964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014965 {
Dave Barach72d72232016-08-04 10:15:08 -040014966 if (unformat (i, "name %s", &match_name))
14967 {
14968 vec_add1 (match_name, 0);
14969 match_name_valid = 1;
14970 }
14971 else
14972 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014973 }
Matus Fabiane8554802016-05-18 23:40:37 -070014974
Dave Barach72d72232016-08-04 10:15:08 -040014975 M (POLICER_DUMP, policer_dump);
14976 mp->match_name_valid = match_name_valid;
14977 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14978 vec_free (match_name);
14979 /* send it... */
14980 S;
14981
14982 /* Use a control ping for synchronization */
14983 {
14984 vl_api_control_ping_t *mp;
14985 M (CONTROL_PING, control_ping);
14986 S;
14987 }
14988 /* Wait for a reply... */
14989 W;
14990
14991 /* NOTREACHED */
14992 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014993}
14994
14995static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014996api_policer_classify_set_interface (vat_main_t * vam)
14997{
Dave Barach72d72232016-08-04 10:15:08 -040014998 unformat_input_t *i = vam->input;
14999 vl_api_policer_classify_set_interface_t *mp;
15000 f64 timeout;
15001 u32 sw_if_index;
15002 int sw_if_index_set;
15003 u32 ip4_table_index = ~0;
15004 u32 ip6_table_index = ~0;
15005 u32 l2_table_index = ~0;
15006 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015007
Dave Barach72d72232016-08-04 10:15:08 -040015008 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15009 {
15010 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15011 sw_if_index_set = 1;
15012 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15013 sw_if_index_set = 1;
15014 else if (unformat (i, "del"))
15015 is_add = 0;
15016 else if (unformat (i, "ip4-table %d", &ip4_table_index))
15017 ;
15018 else if (unformat (i, "ip6-table %d", &ip6_table_index))
15019 ;
15020 else if (unformat (i, "l2-table %d", &l2_table_index))
15021 ;
15022 else
15023 {
15024 clib_warning ("parse error '%U'", format_unformat_error, i);
15025 return -99;
15026 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015027 }
15028
Dave Barach72d72232016-08-04 10:15:08 -040015029 if (sw_if_index_set == 0)
15030 {
15031 errmsg ("missing interface name or sw_if_index\n");
15032 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015033 }
15034
Dave Barach72d72232016-08-04 10:15:08 -040015035 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015036
Dave Barach72d72232016-08-04 10:15:08 -040015037 mp->sw_if_index = ntohl (sw_if_index);
15038 mp->ip4_table_index = ntohl (ip4_table_index);
15039 mp->ip6_table_index = ntohl (ip6_table_index);
15040 mp->l2_table_index = ntohl (l2_table_index);
15041 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015042
Dave Barach72d72232016-08-04 10:15:08 -040015043 S;
15044 W;
15045 /* NOTREACHED */
15046 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015047}
15048
15049static int
Dave Barach72d72232016-08-04 10:15:08 -040015050api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015051{
Dave Barach72d72232016-08-04 10:15:08 -040015052 unformat_input_t *i = vam->input;
15053 vl_api_policer_classify_dump_t *mp;
15054 f64 timeout = ~0;
15055 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015056
Juraj Sloboda506b2452016-08-07 23:45:24 -070015057 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040015058 ;
15059 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015060 {
Dave Barach72d72232016-08-04 10:15:08 -040015061 errmsg ("classify table type must be specified\n");
15062 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015063 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015064
Dave Barach72d72232016-08-04 10:15:08 -040015065 if (!vam->json_output)
15066 {
15067 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
15068 }
15069
15070 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
15071 mp->type = type;
15072 /* send it... */
15073 S;
15074
15075 /* Use a control ping for synchronization */
15076 {
15077 vl_api_control_ping_t *mp;
15078 M (CONTROL_PING, control_ping);
15079 S;
15080 }
15081 /* Wait for a reply... */
15082 W;
15083
15084 /* NOTREACHED */
15085 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015086}
15087
15088static int
Matus Fabian82e29c42016-05-11 04:49:46 -070015089api_netmap_create (vat_main_t * vam)
15090{
Dave Barach72d72232016-08-04 10:15:08 -040015091 unformat_input_t *i = vam->input;
15092 vl_api_netmap_create_t *mp;
15093 f64 timeout;
15094 u8 *if_name = 0;
15095 u8 hw_addr[6];
15096 u8 random_hw_addr = 1;
15097 u8 is_pipe = 0;
15098 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015099
Dave Barach72d72232016-08-04 10:15:08 -040015100 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070015101
Dave Barach72d72232016-08-04 10:15:08 -040015102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15103 {
15104 if (unformat (i, "name %s", &if_name))
15105 vec_add1 (if_name, 0);
15106 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
15107 random_hw_addr = 0;
15108 else if (unformat (i, "pipe"))
15109 is_pipe = 1;
15110 else if (unformat (i, "master"))
15111 is_master = 1;
15112 else if (unformat (i, "slave"))
15113 is_master = 0;
15114 else
15115 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015116 }
15117
Dave Barach72d72232016-08-04 10:15:08 -040015118 if (!vec_len (if_name))
15119 {
15120 errmsg ("interface name must be specified");
15121 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015122 }
15123
Dave Barach72d72232016-08-04 10:15:08 -040015124 if (vec_len (if_name) > 64)
15125 {
15126 errmsg ("interface name too long");
15127 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015128 }
15129
Dave Barach72d72232016-08-04 10:15:08 -040015130 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070015131
Dave Barach72d72232016-08-04 10:15:08 -040015132 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15133 clib_memcpy (mp->hw_addr, hw_addr, 6);
15134 mp->use_random_hw_addr = random_hw_addr;
15135 mp->is_pipe = is_pipe;
15136 mp->is_master = is_master;
15137 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015138
Dave Barach72d72232016-08-04 10:15:08 -040015139 S;
15140 W;
15141 /* NOTREACHED */
15142 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015143}
15144
15145static int
15146api_netmap_delete (vat_main_t * vam)
15147{
Dave Barach72d72232016-08-04 10:15:08 -040015148 unformat_input_t *i = vam->input;
15149 vl_api_netmap_delete_t *mp;
15150 f64 timeout;
15151 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015152
Dave Barach72d72232016-08-04 10:15:08 -040015153 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15154 {
15155 if (unformat (i, "name %s", &if_name))
15156 vec_add1 (if_name, 0);
15157 else
15158 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015159 }
15160
Dave Barach72d72232016-08-04 10:15:08 -040015161 if (!vec_len (if_name))
15162 {
15163 errmsg ("interface name must be specified");
15164 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015165 }
15166
Dave Barach72d72232016-08-04 10:15:08 -040015167 if (vec_len (if_name) > 64)
15168 {
15169 errmsg ("interface name too long");
15170 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015171 }
15172
Dave Barach72d72232016-08-04 10:15:08 -040015173 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070015174
Dave Barach72d72232016-08-04 10:15:08 -040015175 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15176 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015177
Dave Barach72d72232016-08-04 10:15:08 -040015178 S;
15179 W;
15180 /* NOTREACHED */
15181 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015182}
15183
Neale Rannsad422ed2016-11-02 14:20:04 +000015184static void vl_api_mpls_tunnel_details_t_handler
15185 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015186{
Dave Barach72d72232016-08-04 10:15:08 -040015187 vat_main_t *vam = &vat_main;
Neale Rannsad422ed2016-11-02 14:20:04 +000015188 i32 len = mp->mt_next_hop_n_labels;
Dave Barach72d72232016-08-04 10:15:08 -040015189 i32 i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015190
Neale Rannsad422ed2016-11-02 14:20:04 +000015191 fformat (vam->ofp, "[%d]: via %U %d labels ",
15192 mp->tunnel_index,
15193 format_ip4_address, mp->mt_next_hop,
15194 ntohl (mp->mt_next_hop_sw_if_index));
Dave Barach72d72232016-08-04 10:15:08 -040015195 for (i = 0; i < len; i++)
15196 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015197 fformat (vam->ofp, "%u ", ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015198 }
Dave Barach72d72232016-08-04 10:15:08 -040015199 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015200}
15201
Neale Rannsad422ed2016-11-02 14:20:04 +000015202static void vl_api_mpls_tunnel_details_t_handler_json
15203 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015204{
Dave Barach72d72232016-08-04 10:15:08 -040015205 vat_main_t *vam = &vat_main;
15206 vat_json_node_t *node = NULL;
15207 struct in_addr ip4;
15208 i32 i;
Neale Rannsad422ed2016-11-02 14:20:04 +000015209 i32 len = mp->mt_next_hop_n_labels;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015210
Dave Barach72d72232016-08-04 10:15:08 -040015211 if (VAT_JSON_ARRAY != vam->json_tree.type)
15212 {
15213 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15214 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015215 }
Dave Barach72d72232016-08-04 10:15:08 -040015216 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015217
Dave Barach72d72232016-08-04 10:15:08 -040015218 vat_json_init_object (node);
15219 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
Neale Rannsad422ed2016-11-02 14:20:04 +000015220 clib_memcpy (&ip4, &(mp->mt_next_hop), sizeof (ip4));
15221 vat_json_object_add_ip4 (node, "next_hop", ip4);
15222 vat_json_object_add_uint (node, "next_hop_sw_if_index",
15223 ntohl (mp->mt_next_hop_sw_if_index));
15224 vat_json_object_add_uint (node, "l2_only", ntohl (mp->mt_l2_only));
Dave Barach72d72232016-08-04 10:15:08 -040015225 vat_json_object_add_uint (node, "label_count", len);
15226 for (i = 0; i < len; i++)
15227 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015228 vat_json_object_add_uint (node, "label",
15229 ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015230 }
15231}
15232
Dave Barach72d72232016-08-04 10:15:08 -040015233static int
Neale Rannsad422ed2016-11-02 14:20:04 +000015234api_mpls_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015235{
Neale Rannsad422ed2016-11-02 14:20:04 +000015236 vl_api_mpls_tunnel_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015237 f64 timeout;
15238 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015239
Dave Barach72d72232016-08-04 10:15:08 -040015240 /* Parse args required to build the message */
15241 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015242 {
Dave Barach72d72232016-08-04 10:15:08 -040015243 if (!unformat (vam->input, "tunnel_index %d", &index))
15244 {
15245 index = -1;
15246 break;
15247 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015248 }
Dave Barach72d72232016-08-04 10:15:08 -040015249
15250 fformat (vam->ofp, " tunnel_index %d\n", index);
15251
Neale Rannsad422ed2016-11-02 14:20:04 +000015252 M (MPLS_TUNNEL_DUMP, mpls_tunnel_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015253 mp->tunnel_index = htonl (index);
15254 S;
15255
15256 /* Use a control ping for synchronization */
15257 {
15258 vl_api_control_ping_t *mp;
15259 M (CONTROL_PING, control_ping);
15260 S;
15261 }
15262 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015263}
15264
Steven01b07122016-11-02 10:40:09 -070015265#define vl_api_mpls_fib_details_t_endian vl_noop_handler
15266#define vl_api_mpls_fib_details_t_print vl_noop_handler
15267
Neale Ranns1357f3b2016-10-16 12:01:42 -070015268static void
15269vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015270{
Dave Barach72d72232016-08-04 10:15:08 -040015271 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070015272 int count = ntohl (mp->count);
15273 vl_api_fib_path_t *fp;
15274 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015275
Dave Barach72d72232016-08-04 10:15:08 -040015276 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070015277 "table-id %d, label %u, ess_bit %u\n",
15278 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
Steven01b07122016-11-02 10:40:09 -070015279 fp = mp->path;
15280 for (i = 0; i < count; i++)
15281 {
Steven5858a822016-11-16 13:26:27 -080015282 if (fp->afi == IP46_TYPE_IP6)
15283 fformat (vam->ofp,
15284 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15285 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15286 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15287 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15288 format_ip6_address, fp->next_hop);
15289 else if (fp->afi == IP46_TYPE_IP4)
15290 fformat (vam->ofp,
15291 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15292 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15293 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15294 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15295 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015296 fp++;
15297 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015298}
15299
Neale Ranns1357f3b2016-10-16 12:01:42 -070015300static void vl_api_mpls_fib_details_t_handler_json
15301 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015302{
Dave Barach72d72232016-08-04 10:15:08 -040015303 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070015304 int count = ntohl (mp->count);
Dave Barach72d72232016-08-04 10:15:08 -040015305 vat_json_node_t *node = NULL;
Steven01b07122016-11-02 10:40:09 -070015306 struct in_addr ip4;
15307 struct in6_addr ip6;
15308 vl_api_fib_path_t *fp;
15309 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015310
Dave Barach72d72232016-08-04 10:15:08 -040015311 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015312 {
Dave Barach72d72232016-08-04 10:15:08 -040015313 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15314 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015315 }
Dave Barach72d72232016-08-04 10:15:08 -040015316 node = vat_json_array_add (&vam->json_tree);
15317
15318 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070015319 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15320 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040015321 vat_json_object_add_uint (node, "label", ntohl (mp->label));
Steven01b07122016-11-02 10:40:09 -070015322 vat_json_object_add_uint (node, "path_count", count);
15323 fp = mp->path;
15324 for (i = 0; i < count; i++)
15325 {
15326 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15327 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15328 vat_json_object_add_uint (node, "is_local", fp->is_local);
15329 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15330 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15331 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15332 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15333 if (fp->afi == IP46_TYPE_IP4)
15334 {
15335 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15336 vat_json_object_add_ip4 (node, "next_hop", ip4);
15337 }
15338 else if (fp->afi == IP46_TYPE_IP6)
15339 {
15340 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15341 vat_json_object_add_ip6 (node, "next_hop", ip6);
15342 }
15343 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015344}
15345
Dave Barach72d72232016-08-04 10:15:08 -040015346static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070015347api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015348{
Neale Ranns1357f3b2016-10-16 12:01:42 -070015349 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015350 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015351
Neale Ranns1357f3b2016-10-16 12:01:42 -070015352 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015353 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015354
Dave Barach72d72232016-08-04 10:15:08 -040015355 /* Use a control ping for synchronization */
15356 {
15357 vl_api_control_ping_t *mp;
15358 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015359 S;
Dave Barach72d72232016-08-04 10:15:08 -040015360 }
15361 W;
15362}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015363
Steven01b07122016-11-02 10:40:09 -070015364#define vl_api_ip_fib_details_t_endian vl_noop_handler
15365#define vl_api_ip_fib_details_t_print vl_noop_handler
15366
15367static void
15368vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
15369{
15370 vat_main_t *vam = &vat_main;
15371 int count = ntohl (mp->count);
15372 vl_api_fib_path_t *fp;
15373 int i;
15374
15375 fformat (vam->ofp,
15376 "table-id %d, prefix %U/%d\n",
15377 ntohl (mp->table_id), format_ip4_address, mp->address,
15378 mp->address_length);
15379 fp = mp->path;
15380 for (i = 0; i < count; i++)
15381 {
Steven5858a822016-11-16 13:26:27 -080015382 if (fp->afi == IP46_TYPE_IP6)
15383 fformat (vam->ofp,
15384 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15385 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15386 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15387 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15388 format_ip6_address, fp->next_hop);
15389 else if (fp->afi == IP46_TYPE_IP4)
15390 fformat (vam->ofp,
15391 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15392 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15393 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15394 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15395 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015396 fp++;
15397 }
15398}
15399
15400static void vl_api_ip_fib_details_t_handler_json
15401 (vl_api_ip_fib_details_t * mp)
15402{
15403 vat_main_t *vam = &vat_main;
15404 int count = ntohl (mp->count);
15405 vat_json_node_t *node = NULL;
15406 struct in_addr ip4;
15407 struct in6_addr ip6;
15408 vl_api_fib_path_t *fp;
15409 int i;
15410
15411 if (VAT_JSON_ARRAY != vam->json_tree.type)
15412 {
15413 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15414 vat_json_init_array (&vam->json_tree);
15415 }
15416 node = vat_json_array_add (&vam->json_tree);
15417
15418 vat_json_init_object (node);
15419 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15420 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
15421 vat_json_object_add_ip4 (node, "prefix", ip4);
15422 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15423 vat_json_object_add_uint (node, "path_count", count);
15424 fp = mp->path;
15425 for (i = 0; i < count; i++)
15426 {
15427 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15428 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15429 vat_json_object_add_uint (node, "is_local", fp->is_local);
15430 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15431 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15432 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15433 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15434 if (fp->afi == IP46_TYPE_IP4)
15435 {
15436 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15437 vat_json_object_add_ip4 (node, "next_hop", ip4);
15438 }
15439 else if (fp->afi == IP46_TYPE_IP6)
15440 {
15441 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15442 vat_json_object_add_ip6 (node, "next_hop", ip6);
15443 }
15444 }
15445}
15446
15447static int
15448api_ip_fib_dump (vat_main_t * vam)
15449{
15450 vl_api_ip_fib_dump_t *mp;
15451 f64 timeout;
15452
15453 M (IP_FIB_DUMP, ip_fib_dump);
15454 S;
15455
15456 /* Use a control ping for synchronization */
15457 {
15458 vl_api_control_ping_t *mp;
15459 M (CONTROL_PING, control_ping);
15460 S;
15461 }
15462 W;
15463}
15464
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010015465static void vl_api_ip_neighbor_details_t_handler
15466 (vl_api_ip_neighbor_details_t * mp)
15467{
15468 vat_main_t *vam = &vat_main;
15469
15470 fformat (vam->ofp, "%c %U %U\n",
15471 (mp->is_static) ? 'S' : 'D',
15472 format_ethernet_address, &mp->mac_address,
15473 (mp->is_ipv6) ? format_ip6_address : format_ip4_address,
15474 &mp->ip_address);
15475}
15476
15477static void vl_api_ip_neighbor_details_t_handler_json
15478 (vl_api_ip_neighbor_details_t * mp)
15479{
15480
15481 vat_main_t *vam = &vat_main;
15482 vat_json_node_t *node;
15483 struct in_addr ip4;
15484 struct in6_addr ip6;
15485
15486 if (VAT_JSON_ARRAY != vam->json_tree.type)
15487 {
15488 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15489 vat_json_init_array (&vam->json_tree);
15490 }
15491 node = vat_json_array_add (&vam->json_tree);
15492
15493 vat_json_init_object (node);
15494 vat_json_object_add_string_copy (node, "flag",
15495 (mp->is_static) ? (u8 *) "static" : (u8 *)
15496 "dynamic");
15497
15498 vat_json_object_add_string_copy (node, "link_layer",
15499 format (0, "%U", format_ethernet_address,
15500 &mp->mac_address));
15501
15502 if (mp->is_ipv6)
15503 {
15504 clib_memcpy (&ip6, &mp->ip_address, sizeof (ip6));
15505 vat_json_object_add_ip6 (node, "ip_address", ip6);
15506 }
15507 else
15508 {
15509 clib_memcpy (&ip4, &mp->ip_address, sizeof (ip4));
15510 vat_json_object_add_ip4 (node, "ip_address", ip4);
15511 }
15512}
15513
15514static int
15515api_ip_neighbor_dump (vat_main_t * vam)
15516{
15517 unformat_input_t *i = vam->input;
15518 vl_api_ip_neighbor_dump_t *mp;
15519 f64 timeout;
15520 u8 is_ipv6 = 0;
15521 u32 sw_if_index = ~0;
15522
15523 /* Parse args required to build the message */
15524 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15525 {
15526 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15527 ;
15528 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15529 ;
15530 else if (unformat (i, "ip6"))
15531 is_ipv6 = 1;
15532 else
15533 break;
15534 }
15535
15536 if (sw_if_index == ~0)
15537 {
15538 errmsg ("missing interface name or sw_if_index\n");
15539 return -99;
15540 }
15541
15542 M (IP_NEIGHBOR_DUMP, ip_neighbor_dump);
15543 mp->is_ipv6 = (u8) is_ipv6;
15544 mp->sw_if_index = ntohl (sw_if_index);
15545 S;
15546
15547 /* Use a control ping for synchronization */
15548 {
15549 vl_api_control_ping_t *mp;
15550 M (CONTROL_PING, control_ping);
15551 S;
15552 }
15553 W;
15554}
15555
Steven01b07122016-11-02 10:40:09 -070015556#define vl_api_ip6_fib_details_t_endian vl_noop_handler
15557#define vl_api_ip6_fib_details_t_print vl_noop_handler
15558
15559static void
15560vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
15561{
15562 vat_main_t *vam = &vat_main;
15563 int count = ntohl (mp->count);
15564 vl_api_fib_path_t *fp;
15565 int i;
15566
15567 fformat (vam->ofp,
15568 "table-id %d, prefix %U/%d\n",
15569 ntohl (mp->table_id), format_ip6_address, mp->address,
15570 mp->address_length);
15571 fp = mp->path;
15572 for (i = 0; i < count; i++)
15573 {
Steven5858a822016-11-16 13:26:27 -080015574 if (fp->afi == IP46_TYPE_IP6)
15575 fformat (vam->ofp,
15576 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15577 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15578 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15579 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15580 format_ip6_address, fp->next_hop);
15581 else if (fp->afi == IP46_TYPE_IP4)
15582 fformat (vam->ofp,
15583 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15584 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15585 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15586 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15587 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015588 fp++;
15589 }
15590}
15591
15592static void vl_api_ip6_fib_details_t_handler_json
15593 (vl_api_ip6_fib_details_t * mp)
15594{
15595 vat_main_t *vam = &vat_main;
15596 int count = ntohl (mp->count);
15597 vat_json_node_t *node = NULL;
15598 struct in_addr ip4;
15599 struct in6_addr ip6;
15600 vl_api_fib_path_t *fp;
15601 int i;
15602
15603 if (VAT_JSON_ARRAY != vam->json_tree.type)
15604 {
15605 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15606 vat_json_init_array (&vam->json_tree);
15607 }
15608 node = vat_json_array_add (&vam->json_tree);
15609
15610 vat_json_init_object (node);
15611 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15612 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
15613 vat_json_object_add_ip6 (node, "prefix", ip6);
15614 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15615 vat_json_object_add_uint (node, "path_count", count);
15616 fp = mp->path;
15617 for (i = 0; i < count; i++)
15618 {
15619 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15620 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15621 vat_json_object_add_uint (node, "is_local", fp->is_local);
15622 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15623 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15624 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15625 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15626 if (fp->afi == IP46_TYPE_IP4)
15627 {
15628 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15629 vat_json_object_add_ip4 (node, "next_hop", ip4);
15630 }
15631 else if (fp->afi == IP46_TYPE_IP6)
15632 {
15633 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15634 vat_json_object_add_ip6 (node, "next_hop", ip6);
15635 }
15636 }
15637}
15638
15639static int
15640api_ip6_fib_dump (vat_main_t * vam)
15641{
15642 vl_api_ip6_fib_dump_t *mp;
15643 f64 timeout;
15644
15645 M (IP6_FIB_DUMP, ip6_fib_dump);
15646 S;
15647
15648 /* Use a control ping for synchronization */
15649 {
15650 vl_api_control_ping_t *mp;
15651 M (CONTROL_PING, control_ping);
15652 S;
15653 }
15654 W;
15655}
15656
Dave Barach72d72232016-08-04 10:15:08 -040015657int
15658api_classify_table_ids (vat_main_t * vam)
15659{
15660 vl_api_classify_table_ids_t *mp;
15661 f64 timeout;
15662
15663 /* Construct the API message */
15664 M (CLASSIFY_TABLE_IDS, classify_table_ids);
15665 mp->context = 0;
15666
15667 S;
15668 W;
15669 /* NOTREACHED */
15670 return 0;
15671}
15672
15673int
15674api_classify_table_by_interface (vat_main_t * vam)
15675{
15676 unformat_input_t *input = vam->input;
15677 vl_api_classify_table_by_interface_t *mp;
15678 f64 timeout;
15679
15680 u32 sw_if_index = ~0;
15681 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015682 {
Dave Barach72d72232016-08-04 10:15:08 -040015683 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15684 ;
15685 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15686 ;
15687 else
15688 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015689 }
Dave Barach72d72232016-08-04 10:15:08 -040015690 if (sw_if_index == ~0)
15691 {
15692 errmsg ("missing interface name or sw_if_index\n");
15693 return -99;
15694 }
15695
15696 /* Construct the API message */
15697 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
15698 mp->context = 0;
15699 mp->sw_if_index = ntohl (sw_if_index);
15700
15701 S;
15702 W;
15703 /* NOTREACHED */
15704 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015705}
15706
Dave Barach72d72232016-08-04 10:15:08 -040015707int
15708api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015709{
Dave Barach72d72232016-08-04 10:15:08 -040015710 unformat_input_t *input = vam->input;
15711 vl_api_classify_table_info_t *mp;
15712 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015713
Dave Barach72d72232016-08-04 10:15:08 -040015714 u32 table_id = ~0;
15715 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15716 {
15717 if (unformat (input, "table_id %d", &table_id))
15718 ;
15719 else
15720 break;
15721 }
15722 if (table_id == ~0)
15723 {
15724 errmsg ("missing table id\n");
15725 return -99;
15726 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015727
Dave Barach72d72232016-08-04 10:15:08 -040015728 /* Construct the API message */
15729 M (CLASSIFY_TABLE_INFO, classify_table_info);
15730 mp->context = 0;
15731 mp->table_id = ntohl (table_id);
15732
15733 S;
15734 W;
15735 /* NOTREACHED */
15736 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015737}
15738
Dave Barach72d72232016-08-04 10:15:08 -040015739int
15740api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015741{
Dave Barach72d72232016-08-04 10:15:08 -040015742 unformat_input_t *input = vam->input;
15743 vl_api_classify_session_dump_t *mp;
15744 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015745
Dave Barach72d72232016-08-04 10:15:08 -040015746 u32 table_id = ~0;
15747 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15748 {
15749 if (unformat (input, "table_id %d", &table_id))
15750 ;
15751 else
15752 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015753 }
Dave Barach72d72232016-08-04 10:15:08 -040015754 if (table_id == ~0)
15755 {
15756 errmsg ("missing table id\n");
15757 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015758 }
15759
Dave Barach72d72232016-08-04 10:15:08 -040015760 /* Construct the API message */
15761 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15762 mp->context = 0;
15763 mp->table_id = ntohl (table_id);
15764 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015765
Dave Barach72d72232016-08-04 10:15:08 -040015766 /* Use a control ping for synchronization */
15767 {
15768 vl_api_control_ping_t *mp;
15769 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015770 S;
Dave Barach72d72232016-08-04 10:15:08 -040015771 }
15772 W;
15773 /* NOTREACHED */
15774 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015775}
15776
Dave Barach72d72232016-08-04 10:15:08 -040015777static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015778vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015779{
Dave Barach72d72232016-08-04 10:15:08 -040015780 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015781
Dave Barach72d72232016-08-04 10:15:08 -040015782 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015783 "src_address %U, vrf_id %d, path_mtu %u, "
15784 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015785 format_ip4_address, mp->collector_address,
15786 ntohs (mp->collector_port),
15787 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015788 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15789 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015790
15791 vam->retval = 0;
15792 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015793}
15794
Dave Barach72d72232016-08-04 10:15:08 -040015795static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015796 vl_api_ipfix_exporter_details_t_handler_json
15797 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015798{
Dave Barach72d72232016-08-04 10:15:08 -040015799 vat_main_t *vam = &vat_main;
15800 vat_json_node_t node;
15801 struct in_addr collector_address;
15802 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015803
Dave Barach72d72232016-08-04 10:15:08 -040015804 vat_json_init_object (&node);
15805 clib_memcpy (&collector_address, &mp->collector_address,
15806 sizeof (collector_address));
15807 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15808 vat_json_object_add_uint (&node, "collector_port",
15809 ntohs (mp->collector_port));
15810 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15811 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015812 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015813 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15814 vat_json_object_add_uint (&node, "template_interval",
15815 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015816 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015817
15818 vat_json_print (vam->ofp, &node);
15819 vat_json_free (&node);
15820 vam->retval = 0;
15821 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015822}
15823
Dave Barach72d72232016-08-04 10:15:08 -040015824int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015825api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015826{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015827 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015828 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015829
Dave Barach72d72232016-08-04 10:15:08 -040015830 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015831 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015832 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015833
Dave Barach72d72232016-08-04 10:15:08 -040015834 S;
15835 W;
15836 /* NOTREACHED */
15837 return 0;
15838}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015839
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015840static int
15841api_ipfix_classify_stream_dump (vat_main_t * vam)
15842{
15843 vl_api_ipfix_classify_stream_dump_t *mp;
15844 f64 timeout;
15845
15846 /* Construct the API message */
15847 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15848 mp->context = 0;
15849
15850 S;
15851 W;
15852 /* NOTREACHED */
15853 return 0;
15854}
15855
15856static void
15857 vl_api_ipfix_classify_stream_details_t_handler
15858 (vl_api_ipfix_classify_stream_details_t * mp)
15859{
15860 vat_main_t *vam = &vat_main;
15861 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15862 ntohl (mp->domain_id), ntohs (mp->src_port));
15863 vam->retval = 0;
15864 vam->result_ready = 1;
15865}
15866
15867static void
15868 vl_api_ipfix_classify_stream_details_t_handler_json
15869 (vl_api_ipfix_classify_stream_details_t * mp)
15870{
15871 vat_main_t *vam = &vat_main;
15872 vat_json_node_t node;
15873
15874 vat_json_init_object (&node);
15875 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15876 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15877
15878 vat_json_print (vam->ofp, &node);
15879 vat_json_free (&node);
15880 vam->retval = 0;
15881 vam->result_ready = 1;
15882}
15883
15884static int
15885api_ipfix_classify_table_dump (vat_main_t * vam)
15886{
15887 vl_api_ipfix_classify_table_dump_t *mp;
15888 f64 timeout;
15889
15890 if (!vam->json_output)
15891 {
15892 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15893 "transport_protocol");
15894 }
15895
15896 /* Construct the API message */
15897 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15898
15899 /* send it... */
15900 S;
15901
15902 /* Use a control ping for synchronization */
15903 {
15904 vl_api_control_ping_t *mp;
15905 M (CONTROL_PING, control_ping);
15906 S;
15907 }
15908 W;
15909}
15910
15911static void
15912 vl_api_ipfix_classify_table_details_t_handler
15913 (vl_api_ipfix_classify_table_details_t * mp)
15914{
15915 vat_main_t *vam = &vat_main;
15916 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15917 mp->transport_protocol);
15918}
15919
15920static void
15921 vl_api_ipfix_classify_table_details_t_handler_json
15922 (vl_api_ipfix_classify_table_details_t * mp)
15923{
15924 vat_json_node_t *node = NULL;
15925 vat_main_t *vam = &vat_main;
15926
15927 if (VAT_JSON_ARRAY != vam->json_tree.type)
15928 {
15929 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15930 vat_json_init_array (&vam->json_tree);
15931 }
15932
15933 node = vat_json_array_add (&vam->json_tree);
15934 vat_json_init_object (node);
15935
15936 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15937 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15938 vat_json_object_add_uint (node, "transport_protocol",
15939 mp->transport_protocol);
15940}
15941
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015942static int
15943api_sw_interface_span_enable_disable (vat_main_t * vam)
15944{
15945 unformat_input_t *i = vam->input;
15946 vl_api_sw_interface_span_enable_disable_t *mp;
15947 f64 timeout;
15948 u32 src_sw_if_index = ~0;
15949 u32 dst_sw_if_index = ~0;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015950 u8 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015951
15952 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15953 {
15954 if (unformat (i, "src %U", unformat_sw_if_index, vam, &src_sw_if_index))
15955 ;
15956 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
15957 ;
15958 else
15959 if (unformat
15960 (i, "dst %U", unformat_sw_if_index, vam, &dst_sw_if_index))
15961 ;
15962 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
15963 ;
15964 else if (unformat (i, "disable"))
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015965 state = 0;
15966 else if (unformat (i, "rx"))
15967 state = 1;
15968 else if (unformat (i, "tx"))
15969 state = 2;
15970 else if (unformat (i, "both"))
15971 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015972 else
15973 break;
15974 }
15975
15976 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable);
15977
15978 mp->sw_if_index_from = htonl (src_sw_if_index);
15979 mp->sw_if_index_to = htonl (dst_sw_if_index);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015980 mp->state = state;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015981
15982 S;
15983 W;
15984 /* NOTREACHED */
15985 return 0;
15986}
15987
15988static void
15989vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
15990 * mp)
15991{
15992 vat_main_t *vam = &vat_main;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015993 u8 *sw_if_from_name = 0;
15994 u8 *sw_if_to_name = 0;
15995 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
15996 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
15997 char *states[] = { "none", "rx", "tx", "both" };
15998 hash_pair_t *p;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015999
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016000 /* *INDENT-OFF* */
16001 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
16002 ({
16003 if ((u32) p->value[0] == sw_if_index_from)
16004 {
16005 sw_if_from_name = (u8 *)(p->key);
16006 if (sw_if_to_name)
16007 break;
16008 }
16009 if ((u32) p->value[0] == sw_if_index_to)
16010 {
16011 sw_if_to_name = (u8 *)(p->key);
16012 if (sw_if_from_name)
16013 break;
16014 }
16015 }));
16016 /* *INDENT-ON* */
16017 fformat (vam->ofp, "%20s => %20s (%s)\n",
16018 sw_if_from_name, sw_if_to_name, states[mp->state]);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016019}
16020
16021static void
16022 vl_api_sw_interface_span_details_t_handler_json
16023 (vl_api_sw_interface_span_details_t * mp)
16024{
16025 vat_main_t *vam = &vat_main;
16026 vat_json_node_t *node = NULL;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016027 u8 *sw_if_from_name = 0;
16028 u8 *sw_if_to_name = 0;
16029 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
16030 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
16031 hash_pair_t *p;
16032
16033 /* *INDENT-OFF* */
16034 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
16035 ({
16036 if ((u32) p->value[0] == sw_if_index_from)
16037 {
16038 sw_if_from_name = (u8 *)(p->key);
16039 if (sw_if_to_name)
16040 break;
16041 }
16042 if ((u32) p->value[0] == sw_if_index_to)
16043 {
16044 sw_if_to_name = (u8 *)(p->key);
16045 if (sw_if_from_name)
16046 break;
16047 }
16048 }));
16049 /* *INDENT-ON* */
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016050
16051 if (VAT_JSON_ARRAY != vam->json_tree.type)
16052 {
16053 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16054 vat_json_init_array (&vam->json_tree);
16055 }
16056 node = vat_json_array_add (&vam->json_tree);
16057
16058 vat_json_init_object (node);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016059 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
16060 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
16061 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
16062 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
16063 vat_json_object_add_uint (node, "state", mp->state);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016064}
16065
16066static int
16067api_sw_interface_span_dump (vat_main_t * vam)
16068{
16069 vl_api_sw_interface_span_dump_t *mp;
16070 f64 timeout;
16071
16072 M (SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump);
16073 S;
16074
16075 /* Use a control ping for synchronization */
16076 {
16077 vl_api_control_ping_t *mp;
16078 M (CONTROL_PING, control_ping);
16079 S;
16080 }
16081 W;
16082}
16083
Dave Barach72d72232016-08-04 10:15:08 -040016084int
16085api_pg_create_interface (vat_main_t * vam)
16086{
16087 unformat_input_t *input = vam->input;
16088 vl_api_pg_create_interface_t *mp;
16089 f64 timeout;
16090
16091 u32 if_id = ~0;
16092 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16093 {
16094 if (unformat (input, "if_id %d", &if_id))
16095 ;
16096 else
16097 break;
16098 }
16099 if (if_id == ~0)
16100 {
16101 errmsg ("missing pg interface index\n");
16102 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016103 }
16104
Dave Barach72d72232016-08-04 10:15:08 -040016105 /* Construct the API message */
16106 M (PG_CREATE_INTERFACE, pg_create_interface);
16107 mp->context = 0;
16108 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016109
Dave Barach72d72232016-08-04 10:15:08 -040016110 S;
16111 W;
16112 /* NOTREACHED */
16113 return 0;
16114}
16115
16116int
16117api_pg_capture (vat_main_t * vam)
16118{
16119 unformat_input_t *input = vam->input;
16120 vl_api_pg_capture_t *mp;
16121 f64 timeout;
16122
16123 u32 if_id = ~0;
16124 u8 enable = 1;
16125 u32 count = 1;
16126 u8 pcap_file_set = 0;
16127 u8 *pcap_file = 0;
16128 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16129 {
16130 if (unformat (input, "if_id %d", &if_id))
16131 ;
16132 else if (unformat (input, "pcap %s", &pcap_file))
16133 pcap_file_set = 1;
16134 else if (unformat (input, "count %d", &count))
16135 ;
16136 else if (unformat (input, "disable"))
16137 enable = 0;
16138 else
16139 break;
16140 }
16141 if (if_id == ~0)
16142 {
16143 errmsg ("missing pg interface index\n");
16144 return -99;
16145 }
16146 if (pcap_file_set > 0)
16147 {
16148 if (vec_len (pcap_file) > 255)
16149 {
16150 errmsg ("pcap file name is too long\n");
16151 return -99;
16152 }
16153 }
16154
16155 u32 name_len = vec_len (pcap_file);
16156 /* Construct the API message */
16157 M (PG_CAPTURE, pg_capture);
16158 mp->context = 0;
16159 mp->interface_id = ntohl (if_id);
16160 mp->is_enabled = enable;
16161 mp->count = ntohl (count);
16162 mp->pcap_name_length = ntohl (name_len);
16163 if (pcap_file_set != 0)
16164 {
16165 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
16166 }
16167 vec_free (pcap_file);
16168
16169 S;
16170 W;
16171 /* NOTREACHED */
16172 return 0;
16173}
16174
16175int
16176api_pg_enable_disable (vat_main_t * vam)
16177{
16178 unformat_input_t *input = vam->input;
16179 vl_api_pg_enable_disable_t *mp;
16180 f64 timeout;
16181
16182 u8 enable = 1;
16183 u8 stream_name_set = 0;
16184 u8 *stream_name = 0;
16185 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16186 {
16187 if (unformat (input, "stream %s", &stream_name))
16188 stream_name_set = 1;
16189 else if (unformat (input, "disable"))
16190 enable = 0;
16191 else
16192 break;
16193 }
16194
16195 if (stream_name_set > 0)
16196 {
16197 if (vec_len (stream_name) > 255)
16198 {
16199 errmsg ("stream name too long\n");
16200 return -99;
16201 }
16202 }
16203
16204 u32 name_len = vec_len (stream_name);
16205 /* Construct the API message */
16206 M (PG_ENABLE_DISABLE, pg_enable_disable);
16207 mp->context = 0;
16208 mp->is_enabled = enable;
16209 if (stream_name_set != 0)
16210 {
16211 mp->stream_name_length = ntohl (name_len);
16212 clib_memcpy (mp->stream_name, stream_name, name_len);
16213 }
16214 vec_free (stream_name);
16215
16216 S;
16217 W;
16218 /* NOTREACHED */
16219 return 0;
16220}
16221
16222int
16223api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
16224{
16225 unformat_input_t *input = vam->input;
16226 vl_api_ip_source_and_port_range_check_add_del_t *mp;
16227 f64 timeout;
16228
16229 u16 *low_ports = 0;
16230 u16 *high_ports = 0;
16231 u16 this_low;
16232 u16 this_hi;
16233 ip4_address_t ip4_addr;
16234 ip6_address_t ip6_addr;
16235 u32 length;
16236 u32 tmp, tmp2;
16237 u8 prefix_set = 0;
16238 u32 vrf_id = ~0;
16239 u8 is_add = 1;
16240 u8 is_ipv6 = 0;
16241
16242 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16243 {
16244 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
16245 {
16246 prefix_set = 1;
16247 }
16248 else
16249 if (unformat
16250 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
16251 {
16252 prefix_set = 1;
16253 is_ipv6 = 1;
16254 }
16255 else if (unformat (input, "vrf %d", &vrf_id))
16256 ;
16257 else if (unformat (input, "del"))
16258 is_add = 0;
16259 else if (unformat (input, "port %d", &tmp))
16260 {
16261 if (tmp == 0 || tmp > 65535)
16262 {
16263 errmsg ("port %d out of range", tmp);
16264 return -99;
16265 }
16266 this_low = tmp;
16267 this_hi = this_low + 1;
16268 vec_add1 (low_ports, this_low);
16269 vec_add1 (high_ports, this_hi);
16270 }
16271 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
16272 {
16273 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
16274 {
16275 errmsg ("incorrect range parameters\n");
16276 return -99;
16277 }
16278 this_low = tmp;
16279 /* Note: in debug CLI +1 is added to high before
16280 passing to real fn that does "the work"
16281 (ip_source_and_port_range_check_add_del).
16282 This fn is a wrapper around the binary API fn a
16283 control plane will call, which expects this increment
16284 to have occurred. Hence letting the binary API control
16285 plane fn do the increment for consistency between VAT
16286 and other control planes.
16287 */
16288 this_hi = tmp2;
16289 vec_add1 (low_ports, this_low);
16290 vec_add1 (high_ports, this_hi);
16291 }
16292 else
16293 break;
16294 }
16295
16296 if (prefix_set == 0)
16297 {
16298 errmsg ("<address>/<mask> not specified\n");
16299 return -99;
16300 }
16301
16302 if (vrf_id == ~0)
16303 {
16304 errmsg ("VRF ID required, not specified\n");
16305 return -99;
16306 }
16307
16308 if (vrf_id == 0)
16309 {
16310 errmsg
16311 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16312 return -99;
16313 }
16314
16315 if (vec_len (low_ports) == 0)
16316 {
16317 errmsg ("At least one port or port range required\n");
16318 return -99;
16319 }
16320
16321 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
16322 ip_source_and_port_range_check_add_del);
16323
16324 mp->is_add = is_add;
16325
16326 if (is_ipv6)
16327 {
16328 mp->is_ipv6 = 1;
16329 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
16330 }
16331 else
16332 {
16333 mp->is_ipv6 = 0;
16334 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
16335 }
16336
16337 mp->mask_length = length;
16338 mp->number_of_ranges = vec_len (low_ports);
16339
16340 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
16341 vec_free (low_ports);
16342
16343 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
16344 vec_free (high_ports);
16345
16346 mp->vrf_id = ntohl (vrf_id);
16347
16348 S;
16349 W;
16350 /* NOTREACHED */
16351 return 0;
16352}
16353
16354int
16355api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
16356{
16357 unformat_input_t *input = vam->input;
16358 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
16359 f64 timeout;
16360 u32 sw_if_index = ~0;
16361 int vrf_set = 0;
16362 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
16363 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
16364 u8 is_add = 1;
16365
16366 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16367 {
16368 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
16369 ;
16370 else if (unformat (input, "sw_if_index %d", &sw_if_index))
16371 ;
16372 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
16373 vrf_set = 1;
16374 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
16375 vrf_set = 1;
16376 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
16377 vrf_set = 1;
16378 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
16379 vrf_set = 1;
16380 else if (unformat (input, "del"))
16381 is_add = 0;
16382 else
16383 break;
16384 }
16385
16386 if (sw_if_index == ~0)
16387 {
16388 errmsg ("Interface required but not specified\n");
16389 return -99;
16390 }
16391
16392 if (vrf_set == 0)
16393 {
16394 errmsg ("VRF ID required but not specified\n");
16395 return -99;
16396 }
16397
16398 if (tcp_out_vrf_id == 0
16399 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
16400 {
16401 errmsg
16402 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16403 return -99;
16404 }
16405
16406 /* Construct the API message */
16407 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
16408 ip_source_and_port_range_check_interface_add_del);
16409
16410 mp->sw_if_index = ntohl (sw_if_index);
16411 mp->is_add = is_add;
16412 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
16413 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
16414 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
16415 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
16416
16417 /* send it... */
16418 S;
16419
16420 /* Wait for a reply... */
16421 W;
16422}
16423
16424static int
Matus Fabian694265d2016-08-10 01:55:36 -070016425api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
16426{
16427 unformat_input_t *i = vam->input;
16428 vl_api_ipsec_gre_add_del_tunnel_t *mp;
16429 f64 timeout;
16430 u32 local_sa_id = 0;
16431 u32 remote_sa_id = 0;
16432 ip4_address_t src_address;
16433 ip4_address_t dst_address;
16434 u8 is_add = 1;
16435
16436 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16437 {
16438 if (unformat (i, "local_sa %d", &local_sa_id))
16439 ;
16440 else if (unformat (i, "remote_sa %d", &remote_sa_id))
16441 ;
16442 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
16443 ;
16444 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
16445 ;
16446 else if (unformat (i, "del"))
16447 is_add = 0;
16448 else
16449 {
16450 clib_warning ("parse error '%U'", format_unformat_error, i);
16451 return -99;
16452 }
16453 }
16454
16455 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
16456
16457 mp->local_sa_id = ntohl (local_sa_id);
16458 mp->remote_sa_id = ntohl (remote_sa_id);
16459 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
16460 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
16461 mp->is_add = is_add;
16462
16463 S;
16464 W;
16465 /* NOTREACHED */
16466 return 0;
16467}
16468
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016469static int
16470api_punt (vat_main_t * vam)
16471{
16472 unformat_input_t *i = vam->input;
16473 vl_api_punt_t *mp;
16474 f64 timeout;
16475 u32 ipv = ~0;
16476 u32 protocol = ~0;
16477 u32 port = ~0;
16478 int is_add = 1;
16479
16480 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16481 {
16482 if (unformat (i, "ip %d", &ipv))
16483 ;
16484 else if (unformat (i, "protocol %d", &protocol))
16485 ;
16486 else if (unformat (i, "port %d", &port))
16487 ;
16488 else if (unformat (i, "del"))
16489 is_add = 0;
16490 else
16491 {
16492 clib_warning ("parse error '%U'", format_unformat_error, i);
16493 return -99;
16494 }
16495 }
16496
16497 M (PUNT, punt);
16498
16499 mp->is_add = (u8) is_add;
16500 mp->ipv = (u8) ipv;
16501 mp->l4_protocol = (u8) protocol;
16502 mp->l4_port = htons ((u16) port);
16503
16504 S;
16505 W;
16506 /* NOTREACHED */
16507 return 0;
16508}
16509
Matus Fabian694265d2016-08-10 01:55:36 -070016510static void vl_api_ipsec_gre_tunnel_details_t_handler
16511 (vl_api_ipsec_gre_tunnel_details_t * mp)
16512{
16513 vat_main_t *vam = &vat_main;
16514
16515 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
16516 ntohl (mp->sw_if_index),
16517 format_ip4_address, &mp->src_address,
16518 format_ip4_address, &mp->dst_address,
16519 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
16520}
16521
16522static void vl_api_ipsec_gre_tunnel_details_t_handler_json
16523 (vl_api_ipsec_gre_tunnel_details_t * mp)
16524{
16525 vat_main_t *vam = &vat_main;
16526 vat_json_node_t *node = NULL;
16527 struct in_addr ip4;
16528
16529 if (VAT_JSON_ARRAY != vam->json_tree.type)
16530 {
16531 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16532 vat_json_init_array (&vam->json_tree);
16533 }
16534 node = vat_json_array_add (&vam->json_tree);
16535
16536 vat_json_init_object (node);
16537 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
16538 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
16539 vat_json_object_add_ip4 (node, "src_address", ip4);
16540 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
16541 vat_json_object_add_ip4 (node, "dst_address", ip4);
16542 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
16543 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
16544}
16545
16546static int
16547api_ipsec_gre_tunnel_dump (vat_main_t * vam)
16548{
16549 unformat_input_t *i = vam->input;
16550 vl_api_ipsec_gre_tunnel_dump_t *mp;
16551 f64 timeout;
16552 u32 sw_if_index;
16553 u8 sw_if_index_set = 0;
16554
16555 /* Parse args required to build the message */
16556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16557 {
16558 if (unformat (i, "sw_if_index %d", &sw_if_index))
16559 sw_if_index_set = 1;
16560 else
16561 break;
16562 }
16563
16564 if (sw_if_index_set == 0)
16565 {
16566 sw_if_index = ~0;
16567 }
16568
16569 if (!vam->json_output)
16570 {
16571 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
16572 "sw_if_index", "src_address", "dst_address",
16573 "local_sa_id", "remote_sa_id");
16574 }
16575
16576 /* Get list of gre-tunnel interfaces */
16577 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
16578
16579 mp->sw_if_index = htonl (sw_if_index);
16580
16581 S;
16582
16583 /* Use a control ping for synchronization */
16584 {
16585 vl_api_control_ping_t *mp;
16586 M (CONTROL_PING, control_ping);
16587 S;
16588 }
16589 W;
16590}
16591
16592static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016593api_delete_subif (vat_main_t * vam)
16594{
16595 unformat_input_t *i = vam->input;
16596 vl_api_delete_subif_t *mp;
16597 f64 timeout;
16598 u32 sw_if_index = ~0;
16599
16600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16601 {
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016602 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16603 ;
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016604 if (unformat (i, "sw_if_index %d", &sw_if_index))
16605 ;
16606 else
16607 break;
16608 }
16609
16610 if (sw_if_index == ~0)
16611 {
16612 errmsg ("missing sw_if_index\n");
16613 return -99;
16614 }
16615
16616 /* Construct the API message */
16617 M (DELETE_SUBIF, delete_subif);
16618 mp->sw_if_index = ntohl (sw_if_index);
16619
16620 S;
16621 W;
16622}
16623
Pavel Kotucek95300d12016-08-26 16:11:36 +020016624#define foreach_pbb_vtr_op \
16625_("disable", L2_VTR_DISABLED) \
16626_("pop", L2_VTR_POP_2) \
16627_("push", L2_VTR_PUSH_2)
16628
16629static int
16630api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
16631{
16632 unformat_input_t *i = vam->input;
16633 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
16634 f64 timeout;
16635 u32 sw_if_index = ~0, vtr_op = ~0;
16636 u16 outer_tag = ~0;
16637 u8 dmac[6], smac[6];
16638 u8 dmac_set = 0, smac_set = 0;
16639 u16 vlanid = 0;
16640 u32 sid = ~0;
16641 u32 tmp;
16642
Dave Barach75665d32016-11-17 11:36:59 -050016643 /* Shut up coverity */
16644 memset (dmac, 0, sizeof (dmac));
16645 memset (smac, 0, sizeof (smac));
16646
Pavel Kotucek95300d12016-08-26 16:11:36 +020016647 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16648 {
16649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16650 ;
16651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16652 ;
16653 else if (unformat (i, "vtr_op %d", &vtr_op))
16654 ;
16655#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
16656 foreach_pbb_vtr_op
16657#undef _
16658 else if (unformat (i, "translate_pbb_stag"))
16659 {
16660 if (unformat (i, "%d", &tmp))
16661 {
16662 vtr_op = L2_VTR_TRANSLATE_2_1;
16663 outer_tag = tmp;
16664 }
16665 else
16666 {
16667 errmsg
16668 ("translate_pbb_stag operation requires outer tag definition\n");
16669 return -99;
16670 }
16671 }
16672 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
16673 dmac_set++;
16674 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
16675 smac_set++;
16676 else if (unformat (i, "sid %d", &sid))
16677 ;
16678 else if (unformat (i, "vlanid %d", &tmp))
16679 vlanid = tmp;
16680 else
16681 {
16682 clib_warning ("parse error '%U'", format_unformat_error, i);
16683 return -99;
16684 }
16685 }
16686
16687 if ((sw_if_index == ~0) || (vtr_op == ~0))
16688 {
16689 errmsg ("missing sw_if_index or vtr operation\n");
16690 return -99;
16691 }
16692 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
16693 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
16694 {
16695 errmsg
16696 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
16697 return -99;
16698 }
16699
16700 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
16701 mp->sw_if_index = ntohl (sw_if_index);
16702 mp->vtr_op = ntohl (vtr_op);
16703 mp->outer_tag = ntohs (outer_tag);
16704 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
16705 clib_memcpy (mp->b_smac, smac, sizeof (smac));
16706 mp->b_vlanid = ntohs (vlanid);
16707 mp->i_sid = ntohl (sid);
16708
16709 S;
16710 W;
16711 /* NOTREACHED */
16712 return 0;
16713}
16714
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016715static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070016716api_flow_classify_set_interface (vat_main_t * vam)
16717{
16718 unformat_input_t *i = vam->input;
16719 vl_api_flow_classify_set_interface_t *mp;
16720 f64 timeout;
16721 u32 sw_if_index;
16722 int sw_if_index_set;
16723 u32 ip4_table_index = ~0;
16724 u32 ip6_table_index = ~0;
16725 u8 is_add = 1;
16726
16727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16728 {
16729 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16730 sw_if_index_set = 1;
16731 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16732 sw_if_index_set = 1;
16733 else if (unformat (i, "del"))
16734 is_add = 0;
16735 else if (unformat (i, "ip4-table %d", &ip4_table_index))
16736 ;
16737 else if (unformat (i, "ip6-table %d", &ip6_table_index))
16738 ;
16739 else
16740 {
16741 clib_warning ("parse error '%U'", format_unformat_error, i);
16742 return -99;
16743 }
16744 }
16745
16746 if (sw_if_index_set == 0)
16747 {
16748 errmsg ("missing interface name or sw_if_index\n");
16749 return -99;
16750 }
16751
16752 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
16753
16754 mp->sw_if_index = ntohl (sw_if_index);
16755 mp->ip4_table_index = ntohl (ip4_table_index);
16756 mp->ip6_table_index = ntohl (ip6_table_index);
16757 mp->is_add = is_add;
16758
16759 S;
16760 W;
16761 /* NOTREACHED */
16762 return 0;
16763}
16764
16765static int
16766api_flow_classify_dump (vat_main_t * vam)
16767{
16768 unformat_input_t *i = vam->input;
16769 vl_api_flow_classify_dump_t *mp;
16770 f64 timeout = ~0;
16771 u8 type = FLOW_CLASSIFY_N_TABLES;
16772
16773 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
16774 ;
16775 else
16776 {
16777 errmsg ("classify table type must be specified\n");
16778 return -99;
16779 }
16780
16781 if (!vam->json_output)
16782 {
16783 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
16784 }
16785
16786 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
16787 mp->type = type;
16788 /* send it... */
16789 S;
16790
16791 /* Use a control ping for synchronization */
16792 {
16793 vl_api_control_ping_t *mp;
16794 M (CONTROL_PING, control_ping);
16795 S;
16796 }
16797 /* Wait for a reply... */
16798 W;
16799
16800 /* NOTREACHED */
16801 return 0;
16802}
16803
16804static int
Pavel Kotucek7490a752016-11-15 09:19:11 +010016805api_feature_enable_disable (vat_main_t * vam)
16806{
16807 unformat_input_t *i = vam->input;
16808 vl_api_feature_enable_disable_t *mp;
16809 f64 timeout;
16810 u8 *arc_name = 0;
16811 u8 *feature_name = 0;
16812 u32 sw_if_index = ~0;
16813 u8 enable = 1;
16814
16815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16816 {
16817 if (unformat (i, "arc_name %s", &arc_name))
16818 ;
16819 else if (unformat (i, "feature_name %s", &feature_name))
16820 ;
16821 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16822 ;
16823 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16824 ;
16825 else if (unformat (i, "disable"))
16826 enable = 0;
16827 else
16828 break;
16829 }
16830
16831 if (arc_name == 0)
16832 {
16833 errmsg ("missing arc name\n");
16834 return -99;
16835 }
16836 if (vec_len (arc_name) > 63)
16837 {
16838 errmsg ("arc name too long\n");
16839 }
16840
16841 if (feature_name == 0)
16842 {
16843 errmsg ("missing feature name\n");
16844 return -99;
16845 }
16846 if (vec_len (feature_name) > 63)
16847 {
16848 errmsg ("feature name too long\n");
16849 }
16850
16851 if (sw_if_index == ~0)
16852 {
16853 errmsg ("missing interface name or sw_if_index\n");
16854 return -99;
16855 }
16856
16857 /* Construct the API message */
16858 M (FEATURE_ENABLE_DISABLE, feature_enable_disable);
16859 mp->sw_if_index = ntohl (sw_if_index);
16860 mp->enable = enable;
16861 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
16862 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
16863 vec_free (arc_name);
16864 vec_free (feature_name);
16865
16866 S;
16867 W;
16868}
16869
16870static int
Dave Barach7be864a2016-11-28 11:41:35 -050016871api_sw_interface_tag_add_del (vat_main_t * vam)
16872{
16873 unformat_input_t *i = vam->input;
16874 vl_api_sw_interface_tag_add_del_t *mp;
16875 f64 timeout;
16876 u32 sw_if_index = ~0;
16877 u8 *tag = 0;
16878 u8 enable = 1;
16879
16880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16881 {
16882 if (unformat (i, "tag %s", &tag))
16883 ;
16884 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16885 ;
16886 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16887 ;
16888 else if (unformat (i, "del"))
16889 enable = 0;
16890 else
16891 break;
16892 }
16893
16894 if (sw_if_index == ~0)
16895 {
16896 errmsg ("missing interface name or sw_if_index\n");
16897 return -99;
16898 }
16899
16900 if (enable && (tag == 0))
16901 {
16902 errmsg ("no tag specified\n");
16903 return -99;
16904 }
16905
16906 /* Construct the API message */
16907 M (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del);
16908 mp->sw_if_index = ntohl (sw_if_index);
16909 mp->is_add = enable;
16910 if (enable)
16911 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
16912 vec_free (tag);
16913
16914 S;
16915 W;
16916}
16917
Matus Fabianf468e232016-12-02 06:00:53 -080016918static void vl_api_l2_xconnect_details_t_handler
16919 (vl_api_l2_xconnect_details_t * mp)
16920{
16921 vat_main_t *vam = &vat_main;
16922
16923 fformat (vam->ofp, "%15d%15d\n",
16924 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
16925}
16926
16927static void vl_api_l2_xconnect_details_t_handler_json
16928 (vl_api_l2_xconnect_details_t * mp)
16929{
16930 vat_main_t *vam = &vat_main;
16931 vat_json_node_t *node = NULL;
16932
16933 if (VAT_JSON_ARRAY != vam->json_tree.type)
16934 {
16935 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16936 vat_json_init_array (&vam->json_tree);
16937 }
16938 node = vat_json_array_add (&vam->json_tree);
16939
16940 vat_json_init_object (node);
16941 vat_json_object_add_uint (node, "rx_sw_if_index",
16942 ntohl (mp->rx_sw_if_index));
16943 vat_json_object_add_uint (node, "tx_sw_if_index",
16944 ntohl (mp->tx_sw_if_index));
16945}
16946
16947static int
16948api_l2_xconnect_dump (vat_main_t * vam)
16949{
16950 vl_api_l2_xconnect_dump_t *mp;
16951 f64 timeout;
16952
16953 if (!vam->json_output)
16954 {
16955 fformat (vam->ofp, "%15s%15s\n", "rx_sw_if_index", "tx_sw_if_index");
16956 }
16957
16958 M (L2_XCONNECT_DUMP, l2_xconnect_dump);
16959
16960 S;
16961
16962 /* Use a control ping for synchronization */
16963 {
16964 vl_api_control_ping_t *mp;
16965 M (CONTROL_PING, control_ping);
16966 S;
16967 }
16968 W;
16969}
16970
Dave Barach7be864a2016-11-28 11:41:35 -050016971static int
Matus Fabiand162f3d2016-12-05 01:05:35 -080016972api_sw_interface_set_mtu (vat_main_t * vam)
16973{
16974 unformat_input_t *i = vam->input;
16975 vl_api_sw_interface_set_mtu_t *mp;
16976 f64 timeout;
16977 u32 sw_if_index = ~0;
16978 u32 mtu = 0;
16979
16980 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16981 {
16982 if (unformat (i, "mtu %d", &mtu))
16983 ;
16984 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16985 ;
16986 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16987 ;
16988 else
16989 break;
16990 }
16991
16992 if (sw_if_index == ~0)
16993 {
16994 errmsg ("missing interface name or sw_if_index\n");
16995 return -99;
16996 }
16997
16998 if (mtu == 0)
16999 {
17000 errmsg ("no mtu specified\n");
17001 return -99;
17002 }
17003
17004 /* Construct the API message */
17005 M (SW_INTERFACE_SET_MTU, sw_interface_set_mtu);
17006 mp->sw_if_index = ntohl (sw_if_index);
17007 mp->mtu = ntohs ((u16) mtu);
17008
17009 S;
17010 W;
17011}
17012
17013
17014static int
Dave Barach72d72232016-08-04 10:15:08 -040017015q_or_quit (vat_main_t * vam)
17016{
17017 longjmp (vam->jump_buf, 1);
17018 return 0; /* not so much */
17019}
17020
17021static int
17022q (vat_main_t * vam)
17023{
17024 return q_or_quit (vam);
17025}
17026
17027static int
17028quit (vat_main_t * vam)
17029{
17030 return q_or_quit (vam);
17031}
17032
17033static int
17034comment (vat_main_t * vam)
17035{
17036 return 0;
17037}
17038
17039static int
17040cmd_cmp (void *a1, void *a2)
17041{
17042 u8 **c1 = a1;
17043 u8 **c2 = a2;
17044
17045 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
17046}
17047
17048static int
17049help (vat_main_t * vam)
17050{
17051 u8 **cmds = 0;
17052 u8 *name = 0;
17053 hash_pair_t *p;
17054 unformat_input_t *i = vam->input;
17055 int j;
17056
17057 if (unformat (i, "%s", &name))
17058 {
17059 uword *hs;
17060
17061 vec_add1 (name, 0);
17062
17063 hs = hash_get_mem (vam->help_by_name, name);
17064 if (hs)
17065 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
17066 else
17067 fformat (vam->ofp, "No such msg / command '%s'\n", name);
17068 vec_free (name);
17069 return 0;
17070 }
17071
17072 fformat (vam->ofp, "Help is available for the following:\n");
17073
17074 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017075 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017076 ({
Dave Barach72d72232016-08-04 10:15:08 -040017077 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017078 }));
Dave Barach72d72232016-08-04 10:15:08 -040017079 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017080
Dave Barach72d72232016-08-04 10:15:08 -040017081 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017082
Dave Barach72d72232016-08-04 10:15:08 -040017083 for (j = 0; j < vec_len (cmds); j++)
17084 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017085
Dave Barach72d72232016-08-04 10:15:08 -040017086 vec_free (cmds);
17087 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017088}
17089
Dave Barach72d72232016-08-04 10:15:08 -040017090static int
17091set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017092{
Dave Barach72d72232016-08-04 10:15:08 -040017093 u8 *name = 0, *value = 0;
17094 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017095
Dave Barach72d72232016-08-04 10:15:08 -040017096 if (unformat (i, "%s", &name))
17097 {
17098 /* The input buffer is a vector, not a string. */
17099 value = vec_dup (i->buffer);
17100 vec_delete (value, i->index, 0);
17101 /* Almost certainly has a trailing newline */
17102 if (value[vec_len (value) - 1] == '\n')
17103 value[vec_len (value) - 1] = 0;
17104 /* Make sure it's a proper string, one way or the other */
17105 vec_add1 (value, 0);
17106 (void) clib_macro_set_value (&vam->macro_main,
17107 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017108 }
Dave Barach72d72232016-08-04 10:15:08 -040017109 else
17110 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017111
Dave Barach72d72232016-08-04 10:15:08 -040017112 vec_free (name);
17113 vec_free (value);
17114 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017115}
17116
Dave Barach72d72232016-08-04 10:15:08 -040017117static int
17118unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017119{
Dave Barach72d72232016-08-04 10:15:08 -040017120 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017121
Dave Barach72d72232016-08-04 10:15:08 -040017122 if (unformat (vam->input, "%s", &name))
17123 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
17124 errmsg ("unset: %s wasn't set\n", name);
17125 vec_free (name);
17126 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017127}
17128
Dave Barach72d72232016-08-04 10:15:08 -040017129typedef struct
17130{
17131 u8 *name;
17132 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017133} macro_sort_t;
17134
17135
Dave Barach72d72232016-08-04 10:15:08 -040017136static int
17137macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017138{
Dave Barach72d72232016-08-04 10:15:08 -040017139 macro_sort_t *s1 = a1;
17140 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017141
Dave Barach72d72232016-08-04 10:15:08 -040017142 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017143}
17144
Dave Barach72d72232016-08-04 10:15:08 -040017145static int
17146dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017147{
Dave Barach72d72232016-08-04 10:15:08 -040017148 macro_sort_t *sort_me = 0, *sm;
17149 int i;
17150 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017151
Dave Barach72d72232016-08-04 10:15:08 -040017152 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017153 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017154 ({
Dave Barach72d72232016-08-04 10:15:08 -040017155 vec_add2 (sort_me, sm, 1);
17156 sm->name = (u8 *)(p->key);
17157 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017158 }));
Dave Barach72d72232016-08-04 10:15:08 -040017159 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017160
Dave Barach72d72232016-08-04 10:15:08 -040017161 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017162
Dave Barach72d72232016-08-04 10:15:08 -040017163 if (vec_len (sort_me))
17164 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
17165 else
17166 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017167
Dave Barach72d72232016-08-04 10:15:08 -040017168 for (i = 0; i < vec_len (sort_me); i++)
17169 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
17170 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017171}
17172
Dave Barach72d72232016-08-04 10:15:08 -040017173static int
17174dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017175{
Dave Barach72d72232016-08-04 10:15:08 -040017176 int i, j;
17177 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017178
Dave Barach72d72232016-08-04 10:15:08 -040017179 if (vec_len (vam->graph_nodes) == 0)
17180 {
17181 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17182 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017183 }
17184
Dave Barach72d72232016-08-04 10:15:08 -040017185 for (i = 0; i < vec_len (vam->graph_nodes); i++)
17186 {
17187 node = vam->graph_nodes[i];
17188 fformat (vam->ofp, "[%d] %s\n", i, node->name);
17189 for (j = 0; j < vec_len (node->next_nodes); j++)
17190 {
17191 if (node->next_nodes[j] != ~0)
17192 {
17193 next_node = vam->graph_nodes[node->next_nodes[j]];
17194 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17195 }
17196 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017197 }
Dave Barach72d72232016-08-04 10:15:08 -040017198 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017199}
17200
Dave Barach72d72232016-08-04 10:15:08 -040017201static int
Dave Barach557d1282016-11-10 14:22:49 -050017202value_sort_cmp (void *a1, void *a2)
17203{
17204 name_sort_t *n1 = a1;
17205 name_sort_t *n2 = a2;
17206
17207 if (n1->value < n2->value)
17208 return -1;
17209 if (n1->value > n2->value)
17210 return 1;
17211 return 0;
17212}
17213
17214
17215static int
17216dump_msg_api_table (vat_main_t * vam)
17217{
17218 api_main_t *am = &api_main;
17219 name_sort_t *nses = 0, *ns;
17220 hash_pair_t *hp;
17221 int i;
17222
17223 /* *INDENT-OFF* */
17224 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
17225 ({
17226 vec_add2 (nses, ns, 1);
17227 ns->name = (u8 *)(hp->key);
17228 ns->value = (u32) hp->value[0];
17229 }));
17230 /* *INDENT-ON* */
17231
17232 vec_sort_with_function (nses, value_sort_cmp);
17233
17234 for (i = 0; i < vec_len (nses); i++)
17235 fformat (vam->ofp, " [%d]: %s\n", nses[i].value, nses[i].name);
17236 vec_free (nses);
17237 return 0;
17238}
17239
17240static int
17241get_msg_id (vat_main_t * vam)
17242{
17243 u8 *name_and_crc;
17244 u32 message_index;
17245
17246 if (unformat (vam->input, "%s", &name_and_crc))
17247 {
17248 message_index = vl_api_get_msg_index (name_and_crc);
17249 if (message_index == ~0)
17250 {
17251 fformat (vam->ofp, " '%s' not found\n", name_and_crc);
17252 return 0;
17253 }
17254 fformat (vam->ofp, " '%s' has message index %d\n",
17255 name_and_crc, message_index);
17256 return 0;
17257 }
17258 errmsg ("name_and_crc required...\n");
17259 return 0;
17260}
17261
17262static int
Dave Barach72d72232016-08-04 10:15:08 -040017263search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017264{
Dave Barach72d72232016-08-04 10:15:08 -040017265 unformat_input_t *line_input = vam->input;
17266 u8 *node_to_find;
17267 int j;
17268 vlib_node_t *node, *next_node;
17269 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017270
Dave Barach72d72232016-08-04 10:15:08 -040017271 if (vam->graph_node_index_by_name == 0)
17272 {
17273 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17274 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017275 }
17276
Dave Barach72d72232016-08-04 10:15:08 -040017277 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
17278 {
17279 if (unformat (line_input, "%s", &node_to_find))
17280 {
17281 vec_add1 (node_to_find, 0);
17282 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
17283 if (p == 0)
17284 {
17285 fformat (vam->ofp, "%s not found...\n", node_to_find);
17286 goto out;
17287 }
17288 node = vam->graph_nodes[p[0]];
17289 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
17290 for (j = 0; j < vec_len (node->next_nodes); j++)
17291 {
17292 if (node->next_nodes[j] != ~0)
17293 {
17294 next_node = vam->graph_nodes[node->next_nodes[j]];
17295 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17296 }
17297 }
17298 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017299
Dave Barach72d72232016-08-04 10:15:08 -040017300 else
17301 {
17302 clib_warning ("parse error '%U'", format_unformat_error,
17303 line_input);
17304 return -99;
17305 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017306
17307 out:
Dave Barach72d72232016-08-04 10:15:08 -040017308 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017309
Dave Barachb44e9bc2016-02-19 09:06:23 -050017310 }
17311
Dave Barach72d72232016-08-04 10:15:08 -040017312 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017313}
17314
17315
Dave Barach72d72232016-08-04 10:15:08 -040017316static int
17317script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017318{
Dave Barach72d72232016-08-04 10:15:08 -040017319 u8 *s = 0;
17320 char *save_current_file;
17321 unformat_input_t save_input;
17322 jmp_buf save_jump_buf;
17323 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017324
Dave Barach72d72232016-08-04 10:15:08 -040017325 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017326
Dave Barach72d72232016-08-04 10:15:08 -040017327 if (unformat (vam->input, "%s", &s))
17328 {
17329 new_fp = fopen ((char *) s, "r");
17330 if (new_fp == 0)
17331 {
17332 errmsg ("Couldn't open script file %s\n", s);
17333 vec_free (s);
17334 return -99;
17335 }
17336 }
17337 else
17338 {
17339 errmsg ("Missing script name\n");
17340 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017341 }
17342
Dave Barach72d72232016-08-04 10:15:08 -040017343 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
17344 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
17345 save_ifp = vam->ifp;
17346 save_line_number = vam->input_line_number;
17347 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017348
Dave Barach72d72232016-08-04 10:15:08 -040017349 vam->input_line_number = 0;
17350 vam->ifp = new_fp;
17351 vam->current_file = s;
17352 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017353
Dave Barach72d72232016-08-04 10:15:08 -040017354 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
17355 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
17356 vam->ifp = save_ifp;
17357 vam->input_line_number = save_line_number;
17358 vam->current_file = (u8 *) save_current_file;
17359 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017360
Dave Barach72d72232016-08-04 10:15:08 -040017361 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017362}
17363
Dave Barach72d72232016-08-04 10:15:08 -040017364static int
17365echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017366{
Dave Barach72d72232016-08-04 10:15:08 -040017367 fformat (vam->ofp, "%v", vam->input->buffer);
17368 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017369}
17370
17371/* List of API message constructors, CLI names map to api_xxx */
17372#define foreach_vpe_api_msg \
17373_(create_loopback,"[mac <mac-addr>]") \
17374_(sw_interface_dump,"") \
17375_(sw_interface_set_flags, \
17376 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
17377_(sw_interface_add_del_address, \
17378 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
17379_(sw_interface_set_table, \
17380 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040017381_(sw_interface_set_mpls_enable, \
17382 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017383_(sw_interface_set_vpath, \
17384 "<intfc> | sw_if_index <id> enable | disable") \
John Lo37682e12016-11-30 12:51:39 -050017385_(sw_interface_set_vxlan_bypass, \
17386 "<intfc> | sw_if_index <id> [ip4 | ip6] enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017387_(sw_interface_set_l2_xconnect, \
17388 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17389 "enable | disable") \
17390_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040017391 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017392 "[shg <split-horizon-group>] [bvi]\n" \
17393 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010017394_(sw_interface_set_dpdk_hqos_pipe, \
17395 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
17396 "profile <profile-id>\n") \
17397_(sw_interface_set_dpdk_hqos_subport, \
17398 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
17399 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
17400_(sw_interface_set_dpdk_hqos_tctbl, \
17401 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017402_(bridge_domain_add_del, \
17403 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
17404_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
17405_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070017406 "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 -070017407_(l2_flags, \
17408 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
17409_(bridge_flags, \
17410 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
17411_(tap_connect, \
Dave Barach7be864a2016-11-28 11:41:35 -050017412 "tapname <name> mac <mac-addr> | random-mac [tag <string>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017413_(tap_modify, \
17414 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
17415_(tap_delete, \
17416 "<vpp-if-name> | sw_if_index <id>") \
17417_(sw_interface_tap_dump, "") \
17418_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017419 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017420 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17421 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17422 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017423_(mpls_route_add_del, \
17424 "<label> <eos> via <addr> [table-id <n>]\n" \
17425 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17426 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17427 "[multipath] [count <n>]") \
17428_(mpls_ip_bind_unbind, \
17429 "<label> <addr/len>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017430_(mpls_tunnel_add_del, \
17431 " via <addr> [table-id <n>]\n" \
17432 "sw_if_index <id>] [l2] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017433_(proxy_arp_add_del, \
17434 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
17435_(proxy_arp_intfc_enable_disable, \
17436 "<intfc> | sw_if_index <id> enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017437_(sw_interface_set_unnumbered, \
17438 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
17439_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040017440 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
17441 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017442_(reset_vrf, "vrf <id> [ipv6]") \
17443_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
17444_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
17445 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
17446 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
17447 "[outer_vlan_id_any][inner_vlan_id_any]") \
17448_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
17449_(reset_fib, "vrf <n> [ipv6]") \
17450_(dhcp_proxy_config, \
17451 "svr <v46-address> src <v46-address>\n" \
17452 "insert-cid <n> [del]") \
17453_(dhcp_proxy_config_2, \
17454 "svr <v46-address> src <v46-address>\n" \
17455 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
17456_(dhcp_proxy_set_vss, \
17457 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
17458_(dhcp_client_config, \
17459 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
17460_(set_ip_flow_hash, \
17461 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
17462_(sw_interface_ip6_enable_disable, \
17463 "<intfc> | sw_if_index <id> enable | disable") \
17464_(sw_interface_ip6_set_link_local_address, \
17465 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
17466_(sw_interface_ip6nd_ra_prefix, \
17467 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
17468 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
17469 "[nolink] [isno]") \
17470_(sw_interface_ip6nd_ra_config, \
17471 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040017472 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017473 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
17474_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
17475_(l2_patch_add_del, \
17476 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17477 "enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017478_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070017479 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
17480 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
17481 "[policy <policy_name>]") \
17482_(sr_policy_add_del, \
17483 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
17484_(sr_multicast_map_add_del, \
17485 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017486_(classify_add_del_table, \
17487 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017488 " [del] mask <mask-value>\n" \
17489 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
17490 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017491_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017492 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
17493 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017494 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
17495 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017496_(classify_set_interface_ip_table, \
17497 "<intfc> | sw_if_index <nn> table <nn>") \
17498_(classify_set_interface_l2_tables, \
17499 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17500 " [other-table <nn>]") \
17501_(get_node_index, "node <node-name") \
17502_(add_node_next, "node <node-name> next <next-node-name>") \
17503_(l2tpv3_create_tunnel, \
17504 "client_address <ip6-addr> our_address <ip6-addr>\n" \
17505 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
17506 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
17507_(l2tpv3_set_tunnel_cookies, \
17508 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
17509 "[new_remote_cookie <nn>]\n") \
17510_(l2tpv3_interface_enable_disable, \
17511 "<intfc> | sw_if_index <nn> enable | disable") \
17512_(l2tpv3_set_lookup_key, \
17513 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
17514_(sw_if_l2tpv3_tunnel_dump, "") \
17515_(vxlan_add_del_tunnel, \
Eyal Baric5b13602016-11-24 19:42:43 +020017516 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
17517 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
Hongjun Nibeb4bf72016-11-25 00:03:46 +080017518 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050017519_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017520_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070017521 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017522_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017523_(l2_fib_clear_table, "") \
17524_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
17525_(l2_interface_vlan_tag_rewrite, \
17526 "<intfc> | sw_if_index <nn> \n" \
17527 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
17528 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
17529_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000017530 "socket <filename> [server] [renumber <dev_instance>] " \
17531 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017532_(modify_vhost_user_if, \
17533 "<intfc> | sw_if_index <nn> socket <filename>\n" \
17534 "[server] [renumber <dev_instance>]") \
17535_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
17536_(sw_interface_vhost_user_dump, "") \
17537_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080017538_(vxlan_gpe_add_del_tunnel, \
17539 "local <addr> remote <addr> vni <nn>\n" \
17540 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
17541 "[next-ethernet] [next-nsh]\n") \
17542_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017543_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017544_(interface_name_renumber, \
17545 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
17546_(input_acl_set_interface, \
17547 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17548 " [l2-table <nn>] [del]") \
17549_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040017550_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017551_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
17552_(ip_dump, "ipv4 | ipv6") \
17553_(ipsec_spd_add_del, "spd_id <n> [del]") \
17554_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
17555 " spid_id <n> ") \
17556_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
17557 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
17558 " integ_alg <alg> integ_key <hex>") \
17559_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
17560 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
17561 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
17562 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
17563_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020017564_(ikev2_profile_add_del, "name <profile_name> [del]") \
17565_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
17566 "(auth_data 0x<data> | auth_data <data>)") \
17567_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
17568 "(id_data 0x<data> | id_data <data>) (local|remote)") \
17569_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
17570 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
17571 "(local|remote)") \
17572_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017573_(delete_loopback,"sw_if_index <nn>") \
17574_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
17575_(map_add_domain, \
17576 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
17577 "ip6-src <ip6addr> " \
17578 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
17579_(map_del_domain, "index <n>") \
17580_(map_add_del_rule, \
17581 "index <n> psid <n> dst <ip6addr> [del]") \
17582_(map_domain_dump, "") \
17583_(map_rule_dump, "index <map-domain>") \
17584_(want_interface_events, "enable|disable") \
17585_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050017586_(get_first_msg_id, "client <name>") \
17587_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
17588_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017589 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010017590_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000017591_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070017592_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
17593_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020017594_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
17595 " sw_if_index <sw_if_index> p <priority> " \
17596 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017597_(lisp_add_del_locator, "locator-set <locator_name> " \
17598 "iface <intf> | sw_if_index <sw_if_index> " \
17599 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017600_(lisp_add_del_local_eid,"vni <vni> eid " \
17601 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017602 "locator-set <locator_name> [del]" \
17603 "[key-id sha1|sha256 secret-key <secret-key>]")\
Florin Coras429e7952016-08-02 02:31:03 +020017604_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
17605 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017606_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017607_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020017608_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020017609_(lisp_enable_disable, "enable|disable") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017610_(lisp_map_register_enable_disable, "enable|disable") \
17611_(lisp_rloc_probe_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017612_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017613_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
17614 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017615 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020017616 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017617 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020017618_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
17619 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020017620_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020017621_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017622_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020017623_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017624_(lisp_locator_set_dump, "[local | remote]") \
17625_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020017626_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
17627 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020017628_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020017629_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017630_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020017631_(lisp_map_resolver_dump, "") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017632_(lisp_map_server_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020017633_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017634_(show_lisp_rloc_probe_state, "") \
17635_(show_lisp_map_register_state, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017636_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017637_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020017638_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020017639_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020017640_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070017641_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017642_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070017643_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017644_(policer_classify_set_interface, \
17645 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17646 " [l2-table <nn>] [del]") \
17647_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017648_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
17649 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020017650_(netmap_delete, "name <interface name>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017651_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017652_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020017653_(classify_table_ids, "") \
17654_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
17655_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070017656_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070017657_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
17658 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
17659 "[template_interval <nn>] [udp_checksum]") \
17660_(ipfix_exporter_dump, "") \
17661_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
17662_(ipfix_classify_stream_dump, "") \
17663_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
17664_(ipfix_classify_table_dump, "") \
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010017665_(sw_interface_span_enable_disable, "[src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010017666_(sw_interface_span_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020017667_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
17668_(pg_create_interface, "if_id <nn>") \
17669_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040017670_(pg_enable_disable, "[stream <id>] disable") \
17671_(ip_source_and_port_range_check_add_del, \
17672 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
17673_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070017674 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070017675 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
17676_(ipsec_gre_add_del_tunnel, \
17677 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020017678_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020017679_(delete_subif,"<intfc> | sw_if_index <nn>") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020017680_(l2_interface_pbb_tag_rewrite, \
17681 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070017682 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
17683 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070017684_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
17685_(flow_classify_set_interface, \
17686 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
Steven01b07122016-11-02 10:40:09 -070017687_(flow_classify_dump, "type [ip4|ip6]") \
17688_(ip_fib_dump, "") \
Pavel Kotucek7490a752016-11-15 09:19:11 +010017689_(ip6_fib_dump, "") \
17690_(feature_enable_disable, "arc_name <arc_name> " \
Dave Barach7be864a2016-11-28 11:41:35 -050017691 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
17692_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
Matus Fabianf468e232016-12-02 06:00:53 -080017693"[disable]") \
Matus Fabiand162f3d2016-12-05 01:05:35 -080017694_(l2_xconnect_dump, "") \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010017695_(sw_interface_set_mtu, "<intfc> | sw_if_index <nn> mtu <nn>") \
Juraj Slobodadfc19232016-12-05 13:20:37 +010017696_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>") \
17697_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070017698
17699/* List of command functions, CLI names map directly to functions */
17700#define foreach_cli_function \
17701_(comment, "usage: comment <ignore-rest-of-line>") \
17702_(dump_interface_table, "usage: dump_interface_table") \
17703_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
17704_(dump_ipv4_table, "usage: dump_ipv4_table") \
17705_(dump_ipv6_table, "usage: dump_ipv6_table") \
17706_(dump_stats_table, "usage: dump_stats_table") \
17707_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017708_(dump_node_table, "usage: dump_node_table") \
Dave Barach557d1282016-11-10 14:22:49 -050017709_(dump_msg_api_table, "usage: dump_msg_api_table") \
17710_(get_msg_id, "usage: get_msg_id name_and_crc") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017711_(echo, "usage: echo <message>") \
17712_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020017713_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017714_(help, "usage: help") \
17715_(q, "usage: quit") \
17716_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017717_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017718_(set, "usage: set <variable-name> <value>") \
17719_(script, "usage: script <file-name>") \
17720_(unset, "usage: unset <variable-name>")
17721
17722#define _(N,n) \
17723 static void vl_api_##n##_t_handler_uni \
17724 (vl_api_##n##_t * mp) \
17725 { \
17726 vat_main_t * vam = &vat_main; \
17727 if (vam->json_output) { \
17728 vl_api_##n##_t_handler_json(mp); \
17729 } else { \
17730 vl_api_##n##_t_handler(mp); \
17731 } \
17732 }
17733foreach_vpe_api_reply_msg;
17734#undef _
17735
Dave Barach72d72232016-08-04 10:15:08 -040017736void
17737vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017738{
17739#define _(N,n) \
17740 vl_msg_api_set_handlers(VL_API_##N, #n, \
17741 vl_api_##n##_t_handler_uni, \
17742 vl_noop_handler, \
17743 vl_api_##n##_t_endian, \
17744 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017745 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040017746 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017747#undef _
17748
Dave Barach72d72232016-08-04 10:15:08 -040017749 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017750
Dave Barach72d72232016-08-04 10:15:08 -040017751 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017752
Dave Barach72d72232016-08-04 10:15:08 -040017753 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017754
Dave Barach72d72232016-08-04 10:15:08 -040017755 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017756
Dave Barach72d72232016-08-04 10:15:08 -040017757 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017758#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040017759 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017760#undef _
17761
Dave Barach72d72232016-08-04 10:15:08 -040017762 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017763#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017764 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017765#undef _
17766
Dave Barach72d72232016-08-04 10:15:08 -040017767 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017768#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040017769 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017770#undef _
17771
Dave Barach72d72232016-08-04 10:15:08 -040017772 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017773#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017774 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017775#undef _
17776}
17777
17778#undef vl_api_version
Dave Barachaff70772016-10-31 11:59:07 -040017779#define vl_api_version(n,v) static u32 memory_api_version = v;
17780#include <vlibmemory/vl_memory_api_h.h>
17781#undef vl_api_version
17782
17783#undef vl_api_version
17784#define vl_api_version(n,v) static u32 vnet_interface_api_version = v;
17785#include <vnet/interface.api.h>
17786#undef vl_api_version
17787
17788#undef vl_api_version
17789#define vl_api_version(n,v) static u32 vpp_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040017790#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070017791#undef vl_api_version
17792
Dave Barachaff70772016-10-31 11:59:07 -040017793static u32 *api_versions[] = {
17794 &memory_api_version,
17795 &vnet_interface_api_version,
17796 &vpp_api_version,
17797};
17798
Dave Barach72d72232016-08-04 10:15:08 -040017799void
17800vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017801{
Dave Barachaff70772016-10-31 11:59:07 -040017802 int i;
17803
17804 ASSERT (ARRAY_LEN (mp->api_versions) >= ARRAY_LEN (api_versions));
17805
Dave Barach72d72232016-08-04 10:15:08 -040017806 /*
Dave Barachaff70772016-10-31 11:59:07 -040017807 * Send the API signatures. This bit of code must
Dave Barach72d72232016-08-04 10:15:08 -040017808 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
17809 */
Dave Barachaff70772016-10-31 11:59:07 -040017810
17811 for (i = 0; i < ARRAY_LEN (api_versions); i++)
17812 mp->api_versions[i] = clib_host_to_net_u32 (*api_versions[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017813}
Dave Barach72d72232016-08-04 10:15:08 -040017814
17815/*
17816 * fd.io coding-style-patch-verification: ON
17817 *
17818 * Local Variables:
17819 * eval: (c-set-style "gnu")
17820 * End:
17821 */