blob: 83fe57e121125aa0d7417a7666d15e17064a3163 [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) \
3924_(IP_NEIGHBOR_DETAILS, ip_neighbor_details)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003925
3926/* M: construct, but don't yet send a message */
3927
3928#define M(T,t) \
3929do { \
3930 vam->result_ready = 0; \
3931 mp = vl_msg_api_alloc(sizeof(*mp)); \
3932 memset (mp, 0, sizeof (*mp)); \
3933 mp->_vl_msg_id = ntohs (VL_API_##T); \
3934 mp->client_index = vam->my_client_index; \
3935} while(0);
3936
3937#define M2(T,t,n) \
3938do { \
3939 vam->result_ready = 0; \
3940 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3941 memset (mp, 0, sizeof (*mp)); \
3942 mp->_vl_msg_id = ntohs (VL_API_##T); \
3943 mp->client_index = vam->my_client_index; \
3944} while(0);
3945
3946
3947/* S: send a message */
3948#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3949
3950/* W: wait for results, with timeout */
3951#define W \
3952do { \
3953 timeout = vat_time_now (vam) + 1.0; \
3954 \
3955 while (vat_time_now (vam) < timeout) { \
3956 if (vam->result_ready == 1) { \
3957 return (vam->retval); \
3958 } \
3959 } \
3960 return -99; \
3961} while(0);
3962
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003963/* W2: wait for results, with timeout */
3964#define W2(body) \
3965do { \
3966 timeout = vat_time_now (vam) + 1.0; \
3967 \
3968 while (vat_time_now (vam) < timeout) { \
3969 if (vam->result_ready == 1) { \
3970 (body); \
3971 return (vam->retval); \
3972 } \
3973 } \
3974 return -99; \
3975} while(0);
3976
Dave Barach72d72232016-08-04 10:15:08 -04003977typedef struct
3978{
3979 u8 *name;
3980 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003981} name_sort_t;
3982
3983
3984#define STR_VTR_OP_CASE(op) \
3985 case L2_VTR_ ## op: \
3986 return "" # op;
3987
Dave Barach72d72232016-08-04 10:15:08 -04003988static const char *
3989str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003990{
Dave Barach72d72232016-08-04 10:15:08 -04003991 switch (vtr_op)
3992 {
3993 STR_VTR_OP_CASE (DISABLED);
3994 STR_VTR_OP_CASE (PUSH_1);
3995 STR_VTR_OP_CASE (PUSH_2);
3996 STR_VTR_OP_CASE (POP_1);
3997 STR_VTR_OP_CASE (POP_2);
3998 STR_VTR_OP_CASE (TRANSLATE_1_1);
3999 STR_VTR_OP_CASE (TRANSLATE_1_2);
4000 STR_VTR_OP_CASE (TRANSLATE_2_1);
4001 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004002 }
4003
Dave Barach72d72232016-08-04 10:15:08 -04004004 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07004005}
4006
Dave Barach72d72232016-08-04 10:15:08 -04004007static int
4008dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004009{
Dave Barach72d72232016-08-04 10:15:08 -04004010 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004011
Dave Barach72d72232016-08-04 10:15:08 -04004012 if (vam->json_output)
4013 {
4014 clib_warning
4015 ("JSON output supported only for VPE API calls and dump_stats_table");
4016 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004017 }
4018
Dave Barach72d72232016-08-04 10:15:08 -04004019 fformat (vam->ofp,
4020 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
4021 "Interface", "sw_if_index",
4022 "sub id", "dot1ad", "tags", "outer id",
4023 "inner id", "exact", "default", "outer any", "inner any");
4024
4025 vec_foreach (sub, vam->sw_if_subif_table)
4026 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07004027 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004028 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
4029 sub->interface_name,
4030 sub->sw_if_index,
4031 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
4032 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
4033 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
4034 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
4035 if (sub->vtr_op != L2_VTR_DISABLED)
4036 {
4037 fformat (vam->ofp,
4038 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
4039 "tag1: %d tag2: %d ]\n",
4040 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
4041 sub->vtr_tag1, sub->vtr_tag2);
4042 }
4043 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004044
Dave Barach72d72232016-08-04 10:15:08 -04004045 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004046}
4047
Dave Barach72d72232016-08-04 10:15:08 -04004048static int
4049name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004050{
Dave Barach72d72232016-08-04 10:15:08 -04004051 name_sort_t *n1 = a1;
4052 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004053
Dave Barach72d72232016-08-04 10:15:08 -04004054 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004055}
4056
Dave Barach72d72232016-08-04 10:15:08 -04004057static int
4058dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004059{
Dave Barach72d72232016-08-04 10:15:08 -04004060 hash_pair_t *p;
4061 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004062
Dave Barach72d72232016-08-04 10:15:08 -04004063 if (vam->json_output)
4064 {
4065 clib_warning
4066 ("JSON output supported only for VPE API calls and dump_stats_table");
4067 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004068 }
4069
Dave Barach72d72232016-08-04 10:15:08 -04004070 /* *INDENT-OFF* */
4071 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4072 ({
4073 vec_add2 (nses, ns, 1);
4074 ns->name = (u8 *)(p->key);
4075 ns->value = (u32) p->value[0];
4076 }));
4077 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004078
Dave Barach72d72232016-08-04 10:15:08 -04004079 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004080
Dave Barach72d72232016-08-04 10:15:08 -04004081 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
4082 vec_foreach (ns, nses)
4083 {
4084 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
4085 }
4086 vec_free (nses);
4087 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004088}
4089
Dave Barach72d72232016-08-04 10:15:08 -04004090static int
4091dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004092{
Dave Barach72d72232016-08-04 10:15:08 -04004093 const ip_details_t *det = NULL;
4094 const ip_address_details_t *address = NULL;
4095 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004096
Dave Barach72d72232016-08-04 10:15:08 -04004097 fformat (vam->ofp, "%-12s\n", "sw_if_index");
4098
Dave Barach72d72232016-08-04 10:15:08 -04004099 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
4100 {
4101 i++;
4102 if (!det->present)
4103 {
4104 continue;
4105 }
4106 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004107 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004108 " %-30s%-13s\n", "Address", "Prefix length");
4109 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004110 {
Dave Barach72d72232016-08-04 10:15:08 -04004111 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004112 }
Dave Barach72d72232016-08-04 10:15:08 -04004113 vec_foreach (address, det->addr)
4114 {
4115 fformat (vam->ofp,
4116 " %-30U%-13d\n",
4117 is_ipv6 ? format_ip6_address : format_ip4_address,
4118 address->ip, address->prefix_length);
4119 }
4120 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004121
Dave Barach72d72232016-08-04 10:15:08 -04004122 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004123}
4124
Dave Barach72d72232016-08-04 10:15:08 -04004125static int
4126dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004127{
Dave Barach72d72232016-08-04 10:15:08 -04004128 if (vam->json_output)
4129 {
4130 clib_warning
4131 ("JSON output supported only for VPE API calls and dump_stats_table");
4132 return -99;
4133 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004134
Dave Barach72d72232016-08-04 10:15:08 -04004135 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004136}
4137
Dave Barach72d72232016-08-04 10:15:08 -04004138static int
4139dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004140{
Dave Barach72d72232016-08-04 10:15:08 -04004141 if (vam->json_output)
4142 {
4143 clib_warning
4144 ("JSON output supported only for VPE API calls and dump_stats_table");
4145 return -99;
4146 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004147
Dave Barach72d72232016-08-04 10:15:08 -04004148 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004149}
4150
Dave Barach72d72232016-08-04 10:15:08 -04004151static char *
4152counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004153{
Dave Barach72d72232016-08-04 10:15:08 -04004154 if (!is_combined)
4155 {
4156 switch (counter_type)
4157 {
4158 case VNET_INTERFACE_COUNTER_DROP:
4159 return "drop";
4160 case VNET_INTERFACE_COUNTER_PUNT:
4161 return "punt";
4162 case VNET_INTERFACE_COUNTER_IP4:
4163 return "ip4";
4164 case VNET_INTERFACE_COUNTER_IP6:
4165 return "ip6";
4166 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4167 return "rx-no-buf";
4168 case VNET_INTERFACE_COUNTER_RX_MISS:
4169 return "rx-miss";
4170 case VNET_INTERFACE_COUNTER_RX_ERROR:
4171 return "rx-error";
4172 case VNET_INTERFACE_COUNTER_TX_ERROR:
4173 return "tx-error";
4174 default:
4175 return "INVALID-COUNTER-TYPE";
4176 }
4177 }
4178 else
4179 {
4180 switch (counter_type)
4181 {
4182 case VNET_INTERFACE_COUNTER_RX:
4183 return "rx";
4184 case VNET_INTERFACE_COUNTER_TX:
4185 return "tx";
4186 default:
4187 return "INVALID-COUNTER-TYPE";
4188 }
4189 }
4190}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004191
Dave Barach72d72232016-08-04 10:15:08 -04004192static int
4193dump_stats_table (vat_main_t * vam)
4194{
4195 vat_json_node_t node;
4196 vat_json_node_t *msg_array;
4197 vat_json_node_t *msg;
4198 vat_json_node_t *counter_array;
4199 vat_json_node_t *counter;
4200 interface_counter_t c;
4201 u64 packets;
4202 ip4_fib_counter_t *c4;
4203 ip6_fib_counter_t *c6;
4204 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004205
Dave Barach72d72232016-08-04 10:15:08 -04004206 if (!vam->json_output)
4207 {
4208 clib_warning ("dump_stats_table supported only in JSON format");
4209 return -99;
4210 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004211
Dave Barach72d72232016-08-04 10:15:08 -04004212 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004213
Dave Barach72d72232016-08-04 10:15:08 -04004214 /* interface counters */
4215 msg_array = vat_json_object_add (&node, "interface_counters");
4216 vat_json_init_array (msg_array);
4217 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4218 {
4219 msg = vat_json_array_add (msg_array);
4220 vat_json_init_object (msg);
4221 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4222 (u8 *) counter_type_to_str (i, 0));
4223 vat_json_object_add_int (msg, "is_combined", 0);
4224 counter_array = vat_json_object_add (msg, "data");
4225 vat_json_init_array (counter_array);
4226 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4227 {
4228 packets = vam->simple_interface_counters[i][j];
4229 vat_json_array_add_uint (counter_array, packets);
4230 }
4231 }
4232 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4233 {
4234 msg = vat_json_array_add (msg_array);
4235 vat_json_init_object (msg);
4236 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4237 (u8 *) counter_type_to_str (i, 1));
4238 vat_json_object_add_int (msg, "is_combined", 1);
4239 counter_array = vat_json_object_add (msg, "data");
4240 vat_json_init_array (counter_array);
4241 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4242 {
4243 c = vam->combined_interface_counters[i][j];
4244 counter = vat_json_array_add (counter_array);
4245 vat_json_init_object (counter);
4246 vat_json_object_add_uint (counter, "packets", c.packets);
4247 vat_json_object_add_uint (counter, "bytes", c.bytes);
4248 }
4249 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004250
Dave Barach72d72232016-08-04 10:15:08 -04004251 /* ip4 fib counters */
4252 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4253 vat_json_init_array (msg_array);
4254 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4255 {
4256 msg = vat_json_array_add (msg_array);
4257 vat_json_init_object (msg);
4258 vat_json_object_add_uint (msg, "vrf_id",
4259 vam->ip4_fib_counters_vrf_id_by_index[i]);
4260 counter_array = vat_json_object_add (msg, "c");
4261 vat_json_init_array (counter_array);
4262 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4263 {
4264 counter = vat_json_array_add (counter_array);
4265 vat_json_init_object (counter);
4266 c4 = &vam->ip4_fib_counters[i][j];
4267 vat_json_object_add_ip4 (counter, "address", c4->address);
4268 vat_json_object_add_uint (counter, "address_length",
4269 c4->address_length);
4270 vat_json_object_add_uint (counter, "packets", c4->packets);
4271 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4272 }
4273 }
4274
4275 /* ip6 fib counters */
4276 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4277 vat_json_init_array (msg_array);
4278 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4279 {
4280 msg = vat_json_array_add (msg_array);
4281 vat_json_init_object (msg);
4282 vat_json_object_add_uint (msg, "vrf_id",
4283 vam->ip6_fib_counters_vrf_id_by_index[i]);
4284 counter_array = vat_json_object_add (msg, "c");
4285 vat_json_init_array (counter_array);
4286 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4287 {
4288 counter = vat_json_array_add (counter_array);
4289 vat_json_init_object (counter);
4290 c6 = &vam->ip6_fib_counters[i][j];
4291 vat_json_object_add_ip6 (counter, "address", c6->address);
4292 vat_json_object_add_uint (counter, "address_length",
4293 c6->address_length);
4294 vat_json_object_add_uint (counter, "packets", c6->packets);
4295 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4296 }
4297 }
4298
4299 vat_json_print (vam->ofp, &node);
4300 vat_json_free (&node);
4301
4302 return 0;
4303}
4304
4305int
4306exec (vat_main_t * vam)
4307{
4308 api_main_t *am = &api_main;
4309 vl_api_cli_request_t *mp;
4310 f64 timeout;
4311 void *oldheap;
4312 u8 *cmd = 0;
4313 unformat_input_t *i = vam->input;
4314
4315 if (vec_len (i->buffer) == 0)
4316 return -1;
4317
4318 if (vam->exec_mode == 0 && unformat (i, "mode"))
4319 {
4320 vam->exec_mode = 1;
4321 return 0;
4322 }
4323 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4324 {
4325 vam->exec_mode = 0;
4326 return 0;
4327 }
4328
4329
4330 M (CLI_REQUEST, cli_request);
4331
4332 /*
4333 * Copy cmd into shared memory.
4334 * In order for the CLI command to work, it
4335 * must be a vector ending in \n, not a C-string ending
4336 * in \n\0.
4337 */
4338 pthread_mutex_lock (&am->vlib_rp->mutex);
4339 oldheap = svm_push_data_heap (am->vlib_rp);
4340
4341 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4342 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4343
4344 svm_pop_heap (oldheap);
4345 pthread_mutex_unlock (&am->vlib_rp->mutex);
4346
4347 mp->cmd_in_shmem = (u64) cmd;
4348 S;
4349 timeout = vat_time_now (vam) + 10.0;
4350
4351 while (vat_time_now (vam) < timeout)
4352 {
4353 if (vam->result_ready == 1)
4354 {
4355 u8 *free_me;
4356 if (vam->shmem_result != NULL)
4357 fformat (vam->ofp, "%s", vam->shmem_result);
4358 pthread_mutex_lock (&am->vlib_rp->mutex);
4359 oldheap = svm_push_data_heap (am->vlib_rp);
4360
4361 free_me = (u8 *) vam->shmem_result;
4362 vec_free (free_me);
4363
4364 svm_pop_heap (oldheap);
4365 pthread_mutex_unlock (&am->vlib_rp->mutex);
4366 return 0;
4367 }
4368 }
4369 return -99;
4370}
4371
Ole Troanc27213a2016-08-31 14:50:49 +02004372/*
4373 * Future replacement of exec() that passes CLI buffers directly in
4374 * the API messages instead of an additional shared memory area.
4375 */
4376static int
4377exec_inband (vat_main_t * vam)
4378{
4379 vl_api_cli_inband_t *mp;
4380 f64 timeout;
4381 unformat_input_t *i = vam->input;
4382
4383 if (vec_len (i->buffer) == 0)
4384 return -1;
4385
4386 if (vam->exec_mode == 0 && unformat (i, "mode"))
4387 {
4388 vam->exec_mode = 1;
4389 return 0;
4390 }
4391 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4392 {
4393 vam->exec_mode = 0;
4394 return 0;
4395 }
4396
4397 /*
4398 * In order for the CLI command to work, it
4399 * must be a vector ending in \n, not a C-string ending
4400 * in \n\0.
4401 */
4402 u32 len = vec_len (vam->input->buffer);
4403 M2 (CLI_INBAND, cli_inband, len);
4404 clib_memcpy (mp->cmd, vam->input->buffer, len);
4405 mp->length = htonl (len);
4406
4407 S;
4408 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4409}
4410
Dave Barach72d72232016-08-04 10:15:08 -04004411static int
4412api_create_loopback (vat_main_t * vam)
4413{
4414 unformat_input_t *i = vam->input;
4415 vl_api_create_loopback_t *mp;
4416 f64 timeout;
4417 u8 mac_address[6];
4418 u8 mac_set = 0;
4419
4420 memset (mac_address, 0, sizeof (mac_address));
4421
4422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4423 {
4424 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4425 mac_set = 1;
4426 else
4427 break;
4428 }
4429
4430 /* Construct the API message */
4431 M (CREATE_LOOPBACK, create_loopback);
4432 if (mac_set)
4433 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4434
4435 S;
4436 W;
4437}
4438
4439static int
4440api_delete_loopback (vat_main_t * vam)
4441{
4442 unformat_input_t *i = vam->input;
4443 vl_api_delete_loopback_t *mp;
4444 f64 timeout;
4445 u32 sw_if_index = ~0;
4446
4447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4448 {
4449 if (unformat (i, "sw_if_index %d", &sw_if_index))
4450 ;
4451 else
4452 break;
4453 }
4454
4455 if (sw_if_index == ~0)
4456 {
4457 errmsg ("missing sw_if_index\n");
4458 return -99;
4459 }
4460
4461 /* Construct the API message */
4462 M (DELETE_LOOPBACK, delete_loopback);
4463 mp->sw_if_index = ntohl (sw_if_index);
4464
4465 S;
4466 W;
4467}
4468
4469static int
4470api_want_stats (vat_main_t * vam)
4471{
4472 unformat_input_t *i = vam->input;
4473 vl_api_want_stats_t *mp;
4474 f64 timeout;
4475 int enable = -1;
4476
4477 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4478 {
4479 if (unformat (i, "enable"))
4480 enable = 1;
4481 else if (unformat (i, "disable"))
4482 enable = 0;
4483 else
4484 break;
4485 }
4486
4487 if (enable == -1)
4488 {
4489 errmsg ("missing enable|disable\n");
4490 return -99;
4491 }
4492
4493 M (WANT_STATS, want_stats);
4494 mp->enable_disable = enable;
4495
4496 S;
4497 W;
4498}
4499
4500static int
4501api_want_interface_events (vat_main_t * vam)
4502{
4503 unformat_input_t *i = vam->input;
4504 vl_api_want_interface_events_t *mp;
4505 f64 timeout;
4506 int enable = -1;
4507
4508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4509 {
4510 if (unformat (i, "enable"))
4511 enable = 1;
4512 else if (unformat (i, "disable"))
4513 enable = 0;
4514 else
4515 break;
4516 }
4517
4518 if (enable == -1)
4519 {
4520 errmsg ("missing enable|disable\n");
4521 return -99;
4522 }
4523
4524 M (WANT_INTERFACE_EVENTS, want_interface_events);
4525 mp->enable_disable = enable;
4526
4527 vam->interface_event_display = enable;
4528
4529 S;
4530 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004531}
4532
4533
4534/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004535int
4536api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004537{
Dave Barach72d72232016-08-04 10:15:08 -04004538 vl_api_sw_interface_dump_t *mp;
4539 f64 timeout;
4540 hash_pair_t *p;
4541 name_sort_t *nses = 0, *ns;
4542 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004543
Dave Barach72d72232016-08-04 10:15:08 -04004544 /* Toss the old name table */
4545 /* *INDENT-OFF* */
4546 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4547 ({
4548 vec_add2 (nses, ns, 1);
4549 ns->name = (u8 *)(p->key);
4550 ns->value = (u32) p->value[0];
4551 }));
4552 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004553
Dave Barach72d72232016-08-04 10:15:08 -04004554 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004555
Dave Barach72d72232016-08-04 10:15:08 -04004556 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004557
Dave Barach72d72232016-08-04 10:15:08 -04004558 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004559
Dave Barach72d72232016-08-04 10:15:08 -04004560 vec_foreach (sub, vam->sw_if_subif_table)
4561 {
4562 vec_free (sub->interface_name);
4563 }
4564 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004565
Dave Barach72d72232016-08-04 10:15:08 -04004566 /* recreate the interface name hash table */
4567 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004568
Dave Barach72d72232016-08-04 10:15:08 -04004569 /* Get list of ethernets */
4570 M (SW_INTERFACE_DUMP, sw_interface_dump);
4571 mp->name_filter_valid = 1;
4572 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4573 S;
4574
4575 /* and local / loopback interfaces */
4576 M (SW_INTERFACE_DUMP, sw_interface_dump);
4577 mp->name_filter_valid = 1;
4578 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4579 S;
4580
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004581 /* and packet-generator interfaces */
4582 M (SW_INTERFACE_DUMP, sw_interface_dump);
4583 mp->name_filter_valid = 1;
4584 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4585 S;
Dave Barach72d72232016-08-04 10:15:08 -04004586
4587 /* and vxlan-gpe tunnel interfaces */
4588 M (SW_INTERFACE_DUMP, sw_interface_dump);
4589 mp->name_filter_valid = 1;
4590 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4591 sizeof (mp->name_filter) - 1);
4592 S;
4593
4594 /* and vxlan tunnel interfaces */
4595 M (SW_INTERFACE_DUMP, sw_interface_dump);
4596 mp->name_filter_valid = 1;
4597 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4598 S;
4599
4600 /* and host (af_packet) interfaces */
4601 M (SW_INTERFACE_DUMP, sw_interface_dump);
4602 mp->name_filter_valid = 1;
4603 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4604 S;
4605
4606 /* and l2tpv3 tunnel interfaces */
4607 M (SW_INTERFACE_DUMP, sw_interface_dump);
4608 mp->name_filter_valid = 1;
4609 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4610 sizeof (mp->name_filter) - 1);
4611 S;
4612
4613 /* and GRE tunnel interfaces */
4614 M (SW_INTERFACE_DUMP, sw_interface_dump);
4615 mp->name_filter_valid = 1;
4616 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4617 S;
4618
Florin Corasce982752016-09-06 13:36:11 +02004619 /* and LISP-GPE interfaces */
4620 M (SW_INTERFACE_DUMP, sw_interface_dump);
4621 mp->name_filter_valid = 1;
4622 strncpy ((char *) mp->name_filter, "lisp_gpe",
4623 sizeof (mp->name_filter) - 1);
4624 S;
4625
Matus Fabian8fce3e32016-09-06 23:19:43 -07004626 /* and IPSEC tunnel interfaces */
4627 M (SW_INTERFACE_DUMP, sw_interface_dump);
4628 mp->name_filter_valid = 1;
4629 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4630 S;
4631
Dave Barach72d72232016-08-04 10:15:08 -04004632 /* Use a control ping for synchronization */
4633 {
4634 vl_api_control_ping_t *mp;
4635 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004636 S;
Dave Barach72d72232016-08-04 10:15:08 -04004637 }
4638 W;
4639}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004640
Dave Barach72d72232016-08-04 10:15:08 -04004641static int
4642api_sw_interface_set_flags (vat_main_t * vam)
4643{
4644 unformat_input_t *i = vam->input;
4645 vl_api_sw_interface_set_flags_t *mp;
4646 f64 timeout;
4647 u32 sw_if_index;
4648 u8 sw_if_index_set = 0;
4649 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004650
Dave Barach72d72232016-08-04 10:15:08 -04004651 /* Parse args required to build the message */
4652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004653 {
Dave Barach72d72232016-08-04 10:15:08 -04004654 if (unformat (i, "admin-up"))
4655 admin_up = 1;
4656 else if (unformat (i, "admin-down"))
4657 admin_up = 0;
4658 else if (unformat (i, "link-up"))
4659 link_up = 1;
4660 else if (unformat (i, "link-down"))
4661 link_up = 0;
4662 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4663 sw_if_index_set = 1;
4664 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4665 sw_if_index_set = 1;
4666 else
4667 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004668 }
4669
Dave Barach72d72232016-08-04 10:15:08 -04004670 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004671 {
Dave Barach72d72232016-08-04 10:15:08 -04004672 errmsg ("missing interface name or sw_if_index\n");
4673 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004674 }
4675
Dave Barach72d72232016-08-04 10:15:08 -04004676 /* Construct the API message */
4677 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4678 mp->sw_if_index = ntohl (sw_if_index);
4679 mp->admin_up_down = admin_up;
4680 mp->link_up_down = link_up;
4681
4682 /* send it... */
4683 S;
4684
4685 /* Wait for a reply, return the good/bad news... */
4686 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004687}
4688
Dave Barach72d72232016-08-04 10:15:08 -04004689static int
4690api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004691{
Dave Barach72d72232016-08-04 10:15:08 -04004692 unformat_input_t *i = vam->input;
4693 vl_api_sw_interface_clear_stats_t *mp;
4694 f64 timeout;
4695 u32 sw_if_index;
4696 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004697
Dave Barach72d72232016-08-04 10:15:08 -04004698 /* Parse args required to build the message */
4699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4700 {
4701 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4702 sw_if_index_set = 1;
4703 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4704 sw_if_index_set = 1;
4705 else
4706 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004707 }
4708
Dave Barach72d72232016-08-04 10:15:08 -04004709 /* Construct the API message */
4710 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004711
Dave Barach72d72232016-08-04 10:15:08 -04004712 if (sw_if_index_set == 1)
4713 mp->sw_if_index = ntohl (sw_if_index);
4714 else
4715 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004716
Dave Barach72d72232016-08-04 10:15:08 -04004717 /* send it... */
4718 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004719
Dave Barach72d72232016-08-04 10:15:08 -04004720 /* Wait for a reply, return the good/bad news... */
4721 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004722}
4723
Dave Barach72d72232016-08-04 10:15:08 -04004724static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004725api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4726{
4727 unformat_input_t *i = vam->input;
4728 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4729 f64 timeout;
4730 u32 sw_if_index;
4731 u8 sw_if_index_set = 0;
4732 u32 subport;
4733 u8 subport_set = 0;
4734 u32 pipe;
4735 u8 pipe_set = 0;
4736 u32 profile;
4737 u8 profile_set = 0;
4738
4739 /* Parse args required to build the message */
4740 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4741 {
4742 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4743 sw_if_index_set = 1;
4744 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4745 sw_if_index_set = 1;
4746 else if (unformat (i, "subport %u", &subport))
4747 subport_set = 1;
4748 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4749 sw_if_index_set = 1;
4750 else if (unformat (i, "pipe %u", &pipe))
4751 pipe_set = 1;
4752 else if (unformat (i, "profile %u", &profile))
4753 profile_set = 1;
4754 else
4755 break;
4756 }
4757
4758 if (sw_if_index_set == 0)
4759 {
4760 errmsg ("missing interface name or sw_if_index\n");
4761 return -99;
4762 }
4763
4764 if (subport_set == 0)
4765 {
4766 errmsg ("missing subport \n");
4767 return -99;
4768 }
4769
4770 if (pipe_set == 0)
4771 {
4772 errmsg ("missing pipe\n");
4773 return -99;
4774 }
4775
4776 if (profile_set == 0)
4777 {
4778 errmsg ("missing profile\n");
4779 return -99;
4780 }
4781
4782 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4783
4784 mp->sw_if_index = ntohl (sw_if_index);
4785 mp->subport = ntohl (subport);
4786 mp->pipe = ntohl (pipe);
4787 mp->profile = ntohl (profile);
4788
4789
4790 S;
4791 W;
4792 /* NOTREACHED */
4793 return 0;
4794}
4795
4796static int
4797api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4798{
4799 unformat_input_t *i = vam->input;
4800 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4801 f64 timeout;
4802 u32 sw_if_index;
4803 u8 sw_if_index_set = 0;
4804 u32 subport;
4805 u8 subport_set = 0;
4806 u32 tb_rate = 1250000000; /* 10GbE */
4807 u32 tb_size = 1000000;
4808 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4809 u32 tc_period = 10;
4810
4811 /* Parse args required to build the message */
4812 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4813 {
4814 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4815 sw_if_index_set = 1;
4816 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4817 sw_if_index_set = 1;
4818 else if (unformat (i, "subport %u", &subport))
4819 subport_set = 1;
4820 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4821 sw_if_index_set = 1;
4822 else if (unformat (i, "rate %u", &tb_rate))
4823 {
4824 u32 tc_id;
4825
4826 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4827 tc_id++)
4828 tc_rate[tc_id] = tb_rate;
4829 }
4830 else if (unformat (i, "bktsize %u", &tb_size))
4831 ;
4832 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4833 ;
4834 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4835 ;
4836 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4837 ;
4838 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4839 ;
4840 else if (unformat (i, "period %u", &tc_period))
4841 ;
4842 else
4843 break;
4844 }
4845
4846 if (sw_if_index_set == 0)
4847 {
4848 errmsg ("missing interface name or sw_if_index\n");
4849 return -99;
4850 }
4851
4852 if (subport_set == 0)
4853 {
4854 errmsg ("missing subport \n");
4855 return -99;
4856 }
4857
4858 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4859
4860 mp->sw_if_index = ntohl (sw_if_index);
4861 mp->subport = ntohl (subport);
4862 mp->tb_rate = ntohl (tb_rate);
4863 mp->tb_size = ntohl (tb_size);
4864 mp->tc_rate[0] = ntohl (tc_rate[0]);
4865 mp->tc_rate[1] = ntohl (tc_rate[1]);
4866 mp->tc_rate[2] = ntohl (tc_rate[2]);
4867 mp->tc_rate[3] = ntohl (tc_rate[3]);
4868 mp->tc_period = ntohl (tc_period);
4869
4870 S;
4871 W;
4872 /* NOTREACHED */
4873 return 0;
4874}
4875
4876static int
4877api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4878{
4879 unformat_input_t *i = vam->input;
4880 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4881 f64 timeout;
4882 u32 sw_if_index;
4883 u8 sw_if_index_set = 0;
4884 u8 entry_set = 0;
4885 u8 tc_set = 0;
4886 u8 queue_set = 0;
4887 u32 entry, tc, queue;
4888
4889 /* Parse args required to build the message */
4890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4891 {
4892 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4893 sw_if_index_set = 1;
4894 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4895 sw_if_index_set = 1;
4896 else if (unformat (i, "entry %d", &entry))
4897 entry_set = 1;
4898 else if (unformat (i, "tc %d", &tc))
4899 tc_set = 1;
4900 else if (unformat (i, "queue %d", &queue))
4901 queue_set = 1;
4902 else
4903 break;
4904 }
4905
4906 if (sw_if_index_set == 0)
4907 {
4908 errmsg ("missing interface name or sw_if_index\n");
4909 return -99;
4910 }
4911
4912 if (entry_set == 0)
4913 {
4914 errmsg ("missing entry \n");
4915 return -99;
4916 }
4917
4918 if (tc_set == 0)
4919 {
4920 errmsg ("missing traffic class \n");
4921 return -99;
4922 }
4923
4924 if (queue_set == 0)
4925 {
4926 errmsg ("missing queue \n");
4927 return -99;
4928 }
4929
4930 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4931
4932 mp->sw_if_index = ntohl (sw_if_index);
4933 mp->entry = ntohl (entry);
4934 mp->tc = ntohl (tc);
4935 mp->queue = ntohl (queue);
4936
4937 S;
4938 W;
4939 /* NOTREACHED */
4940 return 0;
4941}
4942
4943static int
Dave Barach72d72232016-08-04 10:15:08 -04004944api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004945{
Dave Barach72d72232016-08-04 10:15:08 -04004946 unformat_input_t *i = vam->input;
4947 vl_api_sw_interface_add_del_address_t *mp;
4948 f64 timeout;
4949 u32 sw_if_index;
4950 u8 sw_if_index_set = 0;
4951 u8 is_add = 1, del_all = 0;
4952 u32 address_length = 0;
4953 u8 v4_address_set = 0;
4954 u8 v6_address_set = 0;
4955 ip4_address_t v4address;
4956 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004957
Dave Barach72d72232016-08-04 10:15:08 -04004958 /* Parse args required to build the message */
4959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4960 {
4961 if (unformat (i, "del-all"))
4962 del_all = 1;
4963 else if (unformat (i, "del"))
4964 is_add = 0;
4965 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4966 sw_if_index_set = 1;
4967 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4968 sw_if_index_set = 1;
4969 else if (unformat (i, "%U/%d",
4970 unformat_ip4_address, &v4address, &address_length))
4971 v4_address_set = 1;
4972 else if (unformat (i, "%U/%d",
4973 unformat_ip6_address, &v6address, &address_length))
4974 v6_address_set = 1;
4975 else
4976 break;
4977 }
4978
4979 if (sw_if_index_set == 0)
4980 {
4981 errmsg ("missing interface name or sw_if_index\n");
4982 return -99;
4983 }
4984 if (v4_address_set && v6_address_set)
4985 {
4986 errmsg ("both v4 and v6 addresses set\n");
4987 return -99;
4988 }
4989 if (!v4_address_set && !v6_address_set && !del_all)
4990 {
4991 errmsg ("no addresses set\n");
4992 return -99;
4993 }
4994
4995 /* Construct the API message */
4996 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4997
4998 mp->sw_if_index = ntohl (sw_if_index);
4999 mp->is_add = is_add;
5000 mp->del_all = del_all;
5001 if (v6_address_set)
5002 {
5003 mp->is_ipv6 = 1;
5004 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5005 }
5006 else
5007 {
5008 clib_memcpy (mp->address, &v4address, sizeof (v4address));
5009 }
5010 mp->address_length = address_length;
5011
5012 /* send it... */
5013 S;
5014
5015 /* Wait for a reply, return good/bad news */
5016 W;
5017}
5018
5019static int
John Lo06b14b92016-10-24 20:20:11 -04005020api_sw_interface_set_mpls_enable (vat_main_t * vam)
5021{
5022 unformat_input_t *i = vam->input;
5023 vl_api_sw_interface_set_mpls_enable_t *mp;
5024 f64 timeout;
5025 u32 sw_if_index;
5026 u8 sw_if_index_set = 0;
5027 u8 enable = 1;
5028
5029 /* Parse args required to build the message */
5030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5031 {
5032 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5033 sw_if_index_set = 1;
5034 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5035 sw_if_index_set = 1;
5036 else if (unformat (i, "disable"))
5037 enable = 0;
5038 else if (unformat (i, "dis"))
5039 enable = 0;
5040 else
5041 break;
5042 }
5043
5044 if (sw_if_index_set == 0)
5045 {
5046 errmsg ("missing interface name or sw_if_index\n");
5047 return -99;
5048 }
5049
5050 /* Construct the API message */
5051 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
5052
5053 mp->sw_if_index = ntohl (sw_if_index);
5054 mp->enable = enable;
5055
5056 /* send it... */
5057 S;
5058
5059 /* Wait for a reply... */
5060 W;
5061}
5062
5063static int
Dave Barach72d72232016-08-04 10:15:08 -04005064api_sw_interface_set_table (vat_main_t * vam)
5065{
5066 unformat_input_t *i = vam->input;
5067 vl_api_sw_interface_set_table_t *mp;
5068 f64 timeout;
5069 u32 sw_if_index, vrf_id = 0;
5070 u8 sw_if_index_set = 0;
5071 u8 is_ipv6 = 0;
5072
5073 /* Parse args required to build the message */
5074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5075 {
5076 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5077 sw_if_index_set = 1;
5078 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5079 sw_if_index_set = 1;
5080 else if (unformat (i, "vrf %d", &vrf_id))
5081 ;
5082 else if (unformat (i, "ipv6"))
5083 is_ipv6 = 1;
5084 else
5085 break;
5086 }
5087
5088 if (sw_if_index_set == 0)
5089 {
5090 errmsg ("missing interface name or sw_if_index\n");
5091 return -99;
5092 }
5093
5094 /* Construct the API message */
5095 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
5096
5097 mp->sw_if_index = ntohl (sw_if_index);
5098 mp->is_ipv6 = is_ipv6;
5099 mp->vrf_id = ntohl (vrf_id);
5100
5101 /* send it... */
5102 S;
5103
5104 /* Wait for a reply... */
5105 W;
5106}
5107
5108static int
5109api_sw_interface_set_vpath (vat_main_t * vam)
5110{
5111 unformat_input_t *i = vam->input;
5112 vl_api_sw_interface_set_vpath_t *mp;
5113 f64 timeout;
5114 u32 sw_if_index = 0;
5115 u8 sw_if_index_set = 0;
5116 u8 is_enable = 0;
5117
5118 /* Parse args required to build the message */
5119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5120 {
5121 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5122 sw_if_index_set = 1;
5123 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5124 sw_if_index_set = 1;
5125 else if (unformat (i, "enable"))
5126 is_enable = 1;
5127 else if (unformat (i, "disable"))
5128 is_enable = 0;
5129 else
5130 break;
5131 }
5132
5133 if (sw_if_index_set == 0)
5134 {
5135 errmsg ("missing interface name or sw_if_index\n");
5136 return -99;
5137 }
5138
5139 /* Construct the API message */
5140 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5141
5142 mp->sw_if_index = ntohl (sw_if_index);
5143 mp->enable = is_enable;
5144
5145 /* send it... */
5146 S;
5147
5148 /* Wait for a reply... */
5149 W;
5150}
5151
5152static int
John Lo37682e12016-11-30 12:51:39 -05005153api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
5154{
5155 unformat_input_t *i = vam->input;
5156 vl_api_sw_interface_set_vxlan_bypass_t *mp;
5157 f64 timeout;
5158 u32 sw_if_index = 0;
5159 u8 sw_if_index_set = 0;
5160 u8 is_enable = 0;
5161 u8 is_ipv6 = 0;
5162
5163 /* Parse args required to build the message */
5164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5165 {
5166 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5167 sw_if_index_set = 1;
5168 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5169 sw_if_index_set = 1;
5170 else if (unformat (i, "enable"))
5171 is_enable = 1;
5172 else if (unformat (i, "disable"))
5173 is_enable = 0;
5174 else if (unformat (i, "ip4"))
5175 is_ipv6 = 0;
5176 else if (unformat (i, "ip6"))
5177 is_ipv6 = 1;
5178 else
5179 break;
5180 }
5181
5182 if (sw_if_index_set == 0)
5183 {
5184 errmsg ("missing interface name or sw_if_index\n");
5185 return -99;
5186 }
5187
5188 /* Construct the API message */
5189 M (SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass);
5190
5191 mp->sw_if_index = ntohl (sw_if_index);
5192 mp->enable = is_enable;
5193 mp->is_ipv6 = is_ipv6;
5194
5195 /* send it... */
5196 S;
5197
5198 /* Wait for a reply... */
5199 W;
5200}
5201
5202static int
Dave Barach72d72232016-08-04 10:15:08 -04005203api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5204{
5205 unformat_input_t *i = vam->input;
5206 vl_api_sw_interface_set_l2_xconnect_t *mp;
5207 f64 timeout;
5208 u32 rx_sw_if_index;
5209 u8 rx_sw_if_index_set = 0;
5210 u32 tx_sw_if_index;
5211 u8 tx_sw_if_index_set = 0;
5212 u8 enable = 1;
5213
5214 /* Parse args required to build the message */
5215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5216 {
5217 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5218 rx_sw_if_index_set = 1;
5219 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5220 tx_sw_if_index_set = 1;
5221 else if (unformat (i, "rx"))
5222 {
5223 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5224 {
5225 if (unformat (i, "%U", unformat_sw_if_index, vam,
5226 &rx_sw_if_index))
5227 rx_sw_if_index_set = 1;
5228 }
5229 else
Dave Barach41da02d2016-07-11 16:48:42 -07005230 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005231 }
Dave Barach72d72232016-08-04 10:15:08 -04005232 else if (unformat (i, "tx"))
5233 {
5234 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5235 {
5236 if (unformat (i, "%U", unformat_sw_if_index, vam,
5237 &tx_sw_if_index))
5238 tx_sw_if_index_set = 1;
5239 }
5240 else
5241 break;
5242 }
5243 else if (unformat (i, "enable"))
5244 enable = 1;
5245 else if (unformat (i, "disable"))
5246 enable = 0;
5247 else
5248 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005249 }
5250
Dave Barach72d72232016-08-04 10:15:08 -04005251 if (rx_sw_if_index_set == 0)
5252 {
5253 errmsg ("missing rx interface name or rx_sw_if_index\n");
5254 return -99;
5255 }
Dave Barach41da02d2016-07-11 16:48:42 -07005256
Dave Barach72d72232016-08-04 10:15:08 -04005257 if (enable && (tx_sw_if_index_set == 0))
5258 {
5259 errmsg ("missing tx interface name or tx_sw_if_index\n");
5260 return -99;
5261 }
Dave Barach41da02d2016-07-11 16:48:42 -07005262
Dave Barach72d72232016-08-04 10:15:08 -04005263 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005264
Dave Barach72d72232016-08-04 10:15:08 -04005265 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5266 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5267 mp->enable = enable;
5268
5269 S;
5270 W;
5271 /* NOTREACHED */
5272 return 0;
5273}
5274
5275static int
5276api_sw_interface_set_l2_bridge (vat_main_t * vam)
5277{
5278 unformat_input_t *i = vam->input;
5279 vl_api_sw_interface_set_l2_bridge_t *mp;
5280 f64 timeout;
5281 u32 rx_sw_if_index;
5282 u8 rx_sw_if_index_set = 0;
5283 u32 bd_id;
5284 u8 bd_id_set = 0;
5285 u8 bvi = 0;
5286 u32 shg = 0;
5287 u8 enable = 1;
5288
5289 /* Parse args required to build the message */
5290 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5291 {
5292 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5293 rx_sw_if_index_set = 1;
5294 else if (unformat (i, "bd_id %d", &bd_id))
5295 bd_id_set = 1;
5296 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5297 rx_sw_if_index_set = 1;
5298 else if (unformat (i, "shg %d", &shg))
5299 ;
5300 else if (unformat (i, "bvi"))
5301 bvi = 1;
5302 else if (unformat (i, "enable"))
5303 enable = 1;
5304 else if (unformat (i, "disable"))
5305 enable = 0;
5306 else
5307 break;
5308 }
5309
5310 if (rx_sw_if_index_set == 0)
5311 {
5312 errmsg ("missing rx interface name or sw_if_index\n");
5313 return -99;
5314 }
5315
5316 if (enable && (bd_id_set == 0))
5317 {
5318 errmsg ("missing bridge domain\n");
5319 return -99;
5320 }
5321
5322 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5323
5324 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5325 mp->bd_id = ntohl (bd_id);
5326 mp->shg = (u8) shg;
5327 mp->bvi = bvi;
5328 mp->enable = enable;
5329
5330 S;
5331 W;
5332 /* NOTREACHED */
5333 return 0;
5334}
5335
5336static int
5337api_bridge_domain_dump (vat_main_t * vam)
5338{
5339 unformat_input_t *i = vam->input;
5340 vl_api_bridge_domain_dump_t *mp;
5341 f64 timeout;
5342 u32 bd_id = ~0;
5343
5344 /* Parse args required to build the message */
5345 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5346 {
5347 if (unformat (i, "bd_id %d", &bd_id))
5348 ;
5349 else
5350 break;
5351 }
5352
5353 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5354 mp->bd_id = ntohl (bd_id);
5355 S;
5356
5357 /* Use a control ping for synchronization */
5358 {
5359 vl_api_control_ping_t *mp;
5360 M (CONTROL_PING, control_ping);
5361 S;
5362 }
5363
5364 W;
5365 /* NOTREACHED */
5366 return 0;
5367}
5368
5369static int
5370api_bridge_domain_add_del (vat_main_t * vam)
5371{
5372 unformat_input_t *i = vam->input;
5373 vl_api_bridge_domain_add_del_t *mp;
5374 f64 timeout;
5375 u32 bd_id = ~0;
5376 u8 is_add = 1;
5377 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5378
5379 /* Parse args required to build the message */
5380 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5381 {
5382 if (unformat (i, "bd_id %d", &bd_id))
5383 ;
5384 else if (unformat (i, "flood %d", &flood))
5385 ;
5386 else if (unformat (i, "uu-flood %d", &uu_flood))
5387 ;
5388 else if (unformat (i, "forward %d", &forward))
5389 ;
5390 else if (unformat (i, "learn %d", &learn))
5391 ;
5392 else if (unformat (i, "arp-term %d", &arp_term))
5393 ;
5394 else if (unformat (i, "del"))
5395 {
5396 is_add = 0;
5397 flood = uu_flood = forward = learn = 0;
5398 }
5399 else
5400 break;
5401 }
5402
5403 if (bd_id == ~0)
5404 {
5405 errmsg ("missing bridge domain\n");
5406 return -99;
5407 }
5408
5409 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5410
5411 mp->bd_id = ntohl (bd_id);
5412 mp->flood = flood;
5413 mp->uu_flood = uu_flood;
5414 mp->forward = forward;
5415 mp->learn = learn;
5416 mp->arp_term = arp_term;
5417 mp->is_add = is_add;
5418
5419 S;
5420 W;
5421 /* NOTREACHED */
5422 return 0;
5423}
5424
5425static int
5426api_l2fib_add_del (vat_main_t * vam)
5427{
5428 unformat_input_t *i = vam->input;
5429 vl_api_l2fib_add_del_t *mp;
5430 f64 timeout;
5431 u64 mac = 0;
5432 u8 mac_set = 0;
5433 u32 bd_id;
5434 u8 bd_id_set = 0;
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005435 u32 sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04005436 u8 sw_if_index_set = 0;
5437 u8 is_add = 1;
5438 u8 static_mac = 0;
5439 u8 filter_mac = 0;
5440 u8 bvi_mac = 0;
5441 int count = 1;
5442 f64 before = 0;
5443 int j;
5444
5445 /* Parse args required to build the message */
5446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5447 {
5448 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5449 mac_set = 1;
5450 else if (unformat (i, "bd_id %d", &bd_id))
5451 bd_id_set = 1;
5452 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5453 sw_if_index_set = 1;
5454 else if (unformat (i, "sw_if"))
5455 {
5456 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5457 {
5458 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5459 sw_if_index_set = 1;
5460 }
5461 else
5462 break;
5463 }
5464 else if (unformat (i, "static"))
5465 static_mac = 1;
5466 else if (unformat (i, "filter"))
5467 {
5468 filter_mac = 1;
5469 static_mac = 1;
5470 }
5471 else if (unformat (i, "bvi"))
5472 {
5473 bvi_mac = 1;
5474 static_mac = 1;
5475 }
5476 else if (unformat (i, "del"))
5477 is_add = 0;
5478 else if (unformat (i, "count %d", &count))
5479 ;
5480 else
5481 break;
5482 }
5483
5484 if (mac_set == 0)
5485 {
5486 errmsg ("missing mac address\n");
5487 return -99;
5488 }
5489
5490 if (bd_id_set == 0)
5491 {
5492 errmsg ("missing bridge domain\n");
5493 return -99;
5494 }
5495
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005496 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
Dave Barach72d72232016-08-04 10:15:08 -04005497 {
5498 errmsg ("missing interface name or sw_if_index\n");
5499 return -99;
5500 }
5501
5502 if (count > 1)
5503 {
5504 /* Turn on async mode */
5505 vam->async_mode = 1;
5506 vam->async_errors = 0;
5507 before = vat_time_now (vam);
5508 }
5509
5510 for (j = 0; j < count; j++)
5511 {
5512 M (L2FIB_ADD_DEL, l2fib_add_del);
5513
5514 mp->mac = mac;
5515 mp->bd_id = ntohl (bd_id);
5516 mp->is_add = is_add;
5517
5518 if (is_add)
5519 {
5520 mp->sw_if_index = ntohl (sw_if_index);
5521 mp->static_mac = static_mac;
5522 mp->filter_mac = filter_mac;
5523 mp->bvi_mac = bvi_mac;
5524 }
5525 increment_mac_address (&mac);
5526 /* send it... */
5527 S;
5528 }
5529
5530 if (count > 1)
5531 {
5532 vl_api_control_ping_t *mp;
5533 f64 after;
5534
5535 /* Shut off async mode */
5536 vam->async_mode = 0;
5537
5538 M (CONTROL_PING, control_ping);
5539 S;
5540
5541 timeout = vat_time_now (vam) + 1.0;
5542 while (vat_time_now (vam) < timeout)
5543 if (vam->result_ready == 1)
5544 goto out;
5545 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005546
5547 out:
Dave Barach72d72232016-08-04 10:15:08 -04005548 if (vam->retval == -99)
5549 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005550
Dave Barach72d72232016-08-04 10:15:08 -04005551 if (vam->async_errors > 0)
5552 {
5553 errmsg ("%d asynchronous errors\n", vam->async_errors);
5554 vam->retval = -98;
5555 }
5556 vam->async_errors = 0;
5557 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005558
Dave Barach72d72232016-08-04 10:15:08 -04005559 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5560 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005561 }
Dave Barach72d72232016-08-04 10:15:08 -04005562 else
5563 {
5564 /* Wait for a reply... */
5565 W;
5566 }
5567 /* Return the good/bad news */
5568 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005569}
5570
Dave Barach72d72232016-08-04 10:15:08 -04005571static int
5572api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005573{
Dave Barach72d72232016-08-04 10:15:08 -04005574 unformat_input_t *i = vam->input;
5575 vl_api_l2_flags_t *mp;
5576 f64 timeout;
5577 u32 sw_if_index;
5578 u32 feature_bitmap = 0;
5579 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005580
Dave Barach72d72232016-08-04 10:15:08 -04005581 /* Parse args required to build the message */
5582 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5583 {
5584 if (unformat (i, "sw_if_index %d", &sw_if_index))
5585 sw_if_index_set = 1;
5586 else if (unformat (i, "sw_if"))
5587 {
5588 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5589 {
5590 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5591 sw_if_index_set = 1;
5592 }
5593 else
5594 break;
5595 }
5596 else if (unformat (i, "learn"))
5597 feature_bitmap |= L2INPUT_FEAT_LEARN;
5598 else if (unformat (i, "forward"))
5599 feature_bitmap |= L2INPUT_FEAT_FWD;
5600 else if (unformat (i, "flood"))
5601 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5602 else if (unformat (i, "uu-flood"))
5603 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5604 else
5605 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005606 }
5607
Dave Barach72d72232016-08-04 10:15:08 -04005608 if (sw_if_index_set == 0)
5609 {
5610 errmsg ("missing interface name or sw_if_index\n");
5611 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005612 }
5613
Dave Barach72d72232016-08-04 10:15:08 -04005614 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005615
Dave Barach72d72232016-08-04 10:15:08 -04005616 mp->sw_if_index = ntohl (sw_if_index);
5617 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005618
Dave Barach72d72232016-08-04 10:15:08 -04005619 S;
5620 W;
5621 /* NOTREACHED */
5622 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005623}
5624
Dave Barach72d72232016-08-04 10:15:08 -04005625static int
5626api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005627{
Dave Barach72d72232016-08-04 10:15:08 -04005628 unformat_input_t *i = vam->input;
5629 vl_api_bridge_flags_t *mp;
5630 f64 timeout;
5631 u32 bd_id;
5632 u8 bd_id_set = 0;
5633 u8 is_set = 1;
5634 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005635
Dave Barach72d72232016-08-04 10:15:08 -04005636 /* Parse args required to build the message */
5637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5638 {
5639 if (unformat (i, "bd_id %d", &bd_id))
5640 bd_id_set = 1;
5641 else if (unformat (i, "learn"))
5642 flags |= L2_LEARN;
5643 else if (unformat (i, "forward"))
5644 flags |= L2_FWD;
5645 else if (unformat (i, "flood"))
5646 flags |= L2_FLOOD;
5647 else if (unformat (i, "uu-flood"))
5648 flags |= L2_UU_FLOOD;
5649 else if (unformat (i, "arp-term"))
5650 flags |= L2_ARP_TERM;
5651 else if (unformat (i, "off"))
5652 is_set = 0;
5653 else if (unformat (i, "disable"))
5654 is_set = 0;
5655 else
5656 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005657 }
5658
Dave Barach72d72232016-08-04 10:15:08 -04005659 if (bd_id_set == 0)
5660 {
5661 errmsg ("missing bridge domain\n");
5662 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005663 }
5664
Dave Barach72d72232016-08-04 10:15:08 -04005665 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005666
Dave Barach72d72232016-08-04 10:15:08 -04005667 mp->bd_id = ntohl (bd_id);
5668 mp->feature_bitmap = ntohl (flags);
5669 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005670
Dave Barach72d72232016-08-04 10:15:08 -04005671 S;
5672 W;
5673 /* NOTREACHED */
5674 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005675}
5676
Dave Barach72d72232016-08-04 10:15:08 -04005677static int
5678api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005679{
Dave Barach72d72232016-08-04 10:15:08 -04005680 unformat_input_t *i = vam->input;
5681 vl_api_bd_ip_mac_add_del_t *mp;
5682 f64 timeout;
5683 u32 bd_id;
5684 u8 is_ipv6 = 0;
5685 u8 is_add = 1;
5686 u8 bd_id_set = 0;
5687 u8 ip_set = 0;
5688 u8 mac_set = 0;
5689 ip4_address_t v4addr;
5690 ip6_address_t v6addr;
5691 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005692
Ed Warnickecb9cada2015-12-08 15:45:58 -07005693
Dave Barach72d72232016-08-04 10:15:08 -04005694 /* Parse args required to build the message */
5695 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5696 {
5697 if (unformat (i, "bd_id %d", &bd_id))
5698 {
5699 bd_id_set++;
5700 }
5701 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5702 {
5703 ip_set++;
5704 }
5705 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5706 {
5707 ip_set++;
5708 is_ipv6++;
5709 }
5710 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5711 {
5712 mac_set++;
5713 }
5714 else if (unformat (i, "del"))
5715 is_add = 0;
5716 else
5717 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005718 }
5719
Dave Barach72d72232016-08-04 10:15:08 -04005720 if (bd_id_set == 0)
5721 {
5722 errmsg ("missing bridge domain\n");
5723 return -99;
5724 }
5725 else if (ip_set == 0)
5726 {
5727 errmsg ("missing IP address\n");
5728 return -99;
5729 }
5730 else if (mac_set == 0)
5731 {
5732 errmsg ("missing MAC address\n");
5733 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005734 }
5735
Dave Barach72d72232016-08-04 10:15:08 -04005736 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005737
Dave Barach72d72232016-08-04 10:15:08 -04005738 mp->bd_id = ntohl (bd_id);
5739 mp->is_ipv6 = is_ipv6;
5740 mp->is_add = is_add;
5741 if (is_ipv6)
5742 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5743 else
5744 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5745 clib_memcpy (mp->mac_address, macaddr, 6);
5746 S;
5747 W;
5748 /* NOTREACHED */
5749 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005750}
5751
Dave Barach72d72232016-08-04 10:15:08 -04005752static int
5753api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005754{
Dave Barach72d72232016-08-04 10:15:08 -04005755 unformat_input_t *i = vam->input;
5756 vl_api_tap_connect_t *mp;
5757 f64 timeout;
5758 u8 mac_address[6];
5759 u8 random_mac = 1;
5760 u8 name_set = 0;
5761 u8 *tap_name;
Dave Barach7be864a2016-11-28 11:41:35 -05005762 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005763
Dave Barach72d72232016-08-04 10:15:08 -04005764 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005765
Dave Barach72d72232016-08-04 10:15:08 -04005766 /* Parse args required to build the message */
5767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5768 {
5769 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5770 {
5771 random_mac = 0;
5772 }
5773 else if (unformat (i, "random-mac"))
5774 random_mac = 1;
5775 else if (unformat (i, "tapname %s", &tap_name))
5776 name_set = 1;
Dave Barach143faaa2016-12-02 08:43:40 -05005777 else if (unformat (i, "tag %s", &tag))
5778 ;
Dave Barach72d72232016-08-04 10:15:08 -04005779 else
5780 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005781 }
5782
Dave Barach72d72232016-08-04 10:15:08 -04005783 if (name_set == 0)
5784 {
5785 errmsg ("missing tap name\n");
5786 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005787 }
Dave Barach72d72232016-08-04 10:15:08 -04005788 if (vec_len (tap_name) > 63)
5789 {
5790 errmsg ("tap name too long\n");
Dave Barach7be864a2016-11-28 11:41:35 -05005791 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005792 }
Dave Barach72d72232016-08-04 10:15:08 -04005793 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005794
Dave Barach7be864a2016-11-28 11:41:35 -05005795 if (vec_len (tag) > 63)
5796 {
5797 errmsg ("tag too long\n");
5798 return -99;
5799 }
Dave Barach7be864a2016-11-28 11:41:35 -05005800
Dave Barach72d72232016-08-04 10:15:08 -04005801 /* Construct the API message */
5802 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005803
Dave Barach72d72232016-08-04 10:15:08 -04005804 mp->use_random_mac = random_mac;
5805 clib_memcpy (mp->mac_address, mac_address, 6);
5806 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
Dave Barach7be864a2016-11-28 11:41:35 -05005807 if (tag)
5808 clib_memcpy (mp->tag, tag, vec_len (tag));
5809
Dave Barach72d72232016-08-04 10:15:08 -04005810 vec_free (tap_name);
Dave Barach7be864a2016-11-28 11:41:35 -05005811 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005812
Dave Barach72d72232016-08-04 10:15:08 -04005813 /* send it... */
5814 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005815
Dave Barach72d72232016-08-04 10:15:08 -04005816 /* Wait for a reply... */
5817 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005818}
5819
Dave Barach72d72232016-08-04 10:15:08 -04005820static int
5821api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005822{
Dave Barach72d72232016-08-04 10:15:08 -04005823 unformat_input_t *i = vam->input;
5824 vl_api_tap_modify_t *mp;
5825 f64 timeout;
5826 u8 mac_address[6];
5827 u8 random_mac = 1;
5828 u8 name_set = 0;
5829 u8 *tap_name;
5830 u32 sw_if_index = ~0;
5831 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005832
Dave Barach72d72232016-08-04 10:15:08 -04005833 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005834
Dave Barach72d72232016-08-04 10:15:08 -04005835 /* Parse args required to build the message */
5836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5837 {
5838 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5839 sw_if_index_set = 1;
5840 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5841 sw_if_index_set = 1;
5842 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5843 {
5844 random_mac = 0;
5845 }
5846 else if (unformat (i, "random-mac"))
5847 random_mac = 1;
5848 else if (unformat (i, "tapname %s", &tap_name))
5849 name_set = 1;
5850 else
5851 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005852 }
5853
Dave Barach72d72232016-08-04 10:15:08 -04005854 if (sw_if_index_set == 0)
5855 {
5856 errmsg ("missing vpp interface name");
5857 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005858 }
Dave Barach72d72232016-08-04 10:15:08 -04005859 if (name_set == 0)
5860 {
5861 errmsg ("missing tap name\n");
5862 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005863 }
Dave Barach72d72232016-08-04 10:15:08 -04005864 if (vec_len (tap_name) > 63)
5865 {
5866 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005867 }
Dave Barach72d72232016-08-04 10:15:08 -04005868 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005869
Dave Barach72d72232016-08-04 10:15:08 -04005870 /* Construct the API message */
5871 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005872
Dave Barach72d72232016-08-04 10:15:08 -04005873 mp->use_random_mac = random_mac;
5874 mp->sw_if_index = ntohl (sw_if_index);
5875 clib_memcpy (mp->mac_address, mac_address, 6);
5876 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5877 vec_free (tap_name);
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_delete (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_delete_t *mp;
5891 f64 timeout;
5892 u32 sw_if_index = ~0;
5893 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005894
Dave Barach72d72232016-08-04 10:15:08 -04005895 /* Parse args required to build the message */
5896 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5897 {
5898 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5899 sw_if_index_set = 1;
5900 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5901 sw_if_index_set = 1;
5902 else
5903 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005904 }
5905
Dave Barach72d72232016-08-04 10:15:08 -04005906 if (sw_if_index_set == 0)
5907 {
5908 errmsg ("missing vpp interface name");
5909 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005910 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005911
Dave Barach72d72232016-08-04 10:15:08 -04005912 /* Construct the API message */
5913 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005914
Dave Barach72d72232016-08-04 10:15:08 -04005915 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005916
Dave Barach72d72232016-08-04 10:15:08 -04005917 /* send it... */
5918 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005919
Dave Barach72d72232016-08-04 10:15:08 -04005920 /* Wait for a reply... */
5921 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005922}
5923
Dave Barach72d72232016-08-04 10:15:08 -04005924static int
5925api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005926{
Dave Barach72d72232016-08-04 10:15:08 -04005927 unformat_input_t *i = vam->input;
5928 vl_api_ip_add_del_route_t *mp;
5929 f64 timeout;
5930 u32 sw_if_index = ~0, vrf_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005931 u8 is_ipv6 = 0;
5932 u8 is_local = 0, is_drop = 0;
Neale Ranns948e00f2016-10-20 13:39:34 +01005933 u8 is_unreach = 0, is_prohibit = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005934 u8 create_vrf_if_needed = 0;
5935 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00005936 u32 next_hop_weight = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005937 u8 not_last = 0;
5938 u8 is_multipath = 0;
5939 u8 address_set = 0;
5940 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005941 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005942 u32 resolve_attempts = 0;
5943 u32 dst_address_length = 0;
5944 u8 next_hop_set = 0;
5945 ip4_address_t v4_dst_address, v4_next_hop_address;
5946 ip6_address_t v6_dst_address, v6_next_hop_address;
5947 int count = 1;
5948 int j;
5949 f64 before = 0;
5950 u32 random_add_del = 0;
5951 u32 *random_vector = 0;
5952 uword *random_hash;
5953 u32 random_seed = 0xdeaddabe;
5954 u32 classify_table_index = ~0;
5955 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01005956 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00005957 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005958 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00005959 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005960
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))
Neale Rannsad422ed2016-11-02 14:20:04 +00005965 ;
Dave Barach72d72232016-08-04 10:15:08 -04005966 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00005967 ;
Dave Barach72d72232016-08-04 10:15:08 -04005968 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5969 {
5970 address_set = 1;
5971 is_ipv6 = 0;
5972 }
5973 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5974 {
5975 address_set = 1;
5976 is_ipv6 = 1;
5977 }
5978 else if (unformat (i, "/%d", &dst_address_length))
5979 {
5980 address_length_set = 1;
5981 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005982
Dave Barach72d72232016-08-04 10:15:08 -04005983 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5984 &v4_next_hop_address))
5985 {
5986 next_hop_set = 1;
5987 }
5988 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5989 &v6_next_hop_address))
5990 {
5991 next_hop_set = 1;
5992 }
5993 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5994 ;
5995 else if (unformat (i, "weight %d", &next_hop_weight))
5996 ;
5997 else if (unformat (i, "drop"))
5998 {
5999 is_drop = 1;
6000 }
Neale Ranns948e00f2016-10-20 13:39:34 +01006001 else if (unformat (i, "null-send-unreach"))
6002 {
6003 is_unreach = 1;
6004 }
6005 else if (unformat (i, "null-send-prohibit"))
6006 {
6007 is_prohibit = 1;
6008 }
Dave Barach72d72232016-08-04 10:15:08 -04006009 else if (unformat (i, "local"))
6010 {
6011 is_local = 1;
6012 }
6013 else if (unformat (i, "classify %d", &classify_table_index))
6014 {
6015 is_classify = 1;
6016 }
6017 else if (unformat (i, "del"))
6018 is_add = 0;
6019 else if (unformat (i, "add"))
6020 is_add = 1;
6021 else if (unformat (i, "not-last"))
6022 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006023 else if (unformat (i, "resolve-via-host"))
6024 resolve_host = 1;
6025 else if (unformat (i, "resolve-via-attached"))
6026 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04006027 else if (unformat (i, "multipath"))
6028 is_multipath = 1;
6029 else if (unformat (i, "vrf %d", &vrf_id))
6030 ;
6031 else if (unformat (i, "create-vrf"))
6032 create_vrf_if_needed = 1;
6033 else if (unformat (i, "count %d", &count))
6034 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006035 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
6036 ;
6037 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6038 ;
6039 else if (unformat (i, "out-label %d", &next_hop_out_label))
Neale Rannsad422ed2016-11-02 14:20:04 +00006040 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
6041 else if (unformat (i, "via-label %d", &next_hop_via_label))
Dave Barach72d72232016-08-04 10:15:08 -04006042 ;
6043 else if (unformat (i, "random"))
6044 random_add_del = 1;
6045 else if (unformat (i, "seed %d", &random_seed))
6046 ;
6047 else
6048 {
6049 clib_warning ("parse error '%U'", format_unformat_error, i);
6050 return -99;
6051 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006052 }
6053
Neale Ranns948e00f2016-10-20 13:39:34 +01006054 if (!next_hop_set && !is_drop && !is_local &&
Neale Rannsad422ed2016-11-02 14:20:04 +00006055 !is_classify && !is_unreach && !is_prohibit &&
6056 MPLS_LABEL_INVALID == next_hop_via_label)
Dave Barach72d72232016-08-04 10:15:08 -04006057 {
Neale Ranns948e00f2016-10-20 13:39:34 +01006058 errmsg
6059 ("next hop / local / drop / unreach / prohibit / classify not set\n");
Dave Barach72d72232016-08-04 10:15:08 -04006060 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006061 }
6062
Neale Rannsad422ed2016-11-02 14:20:04 +00006063 if (next_hop_set && MPLS_LABEL_INVALID != next_hop_via_label)
6064 {
6065 errmsg ("next hop and next-hop via label set\n");
6066 return -99;
6067 }
Dave Barach72d72232016-08-04 10:15:08 -04006068 if (address_set == 0)
6069 {
6070 errmsg ("missing addresses\n");
6071 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006072 }
6073
Dave Barach72d72232016-08-04 10:15:08 -04006074 if (address_length_set == 0)
6075 {
6076 errmsg ("missing address length\n");
6077 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006078 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006079
Dave Barach72d72232016-08-04 10:15:08 -04006080 /* Generate a pile of unique, random routes */
6081 if (random_add_del)
6082 {
6083 u32 this_random_address;
6084 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006085
Dave Barach72d72232016-08-04 10:15:08 -04006086 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
6087 for (j = 0; j <= count; j++)
6088 {
6089 do
6090 {
6091 this_random_address = random_u32 (&random_seed);
6092 this_random_address =
6093 clib_host_to_net_u32 (this_random_address);
6094 }
6095 while (hash_get (random_hash, this_random_address));
6096 vec_add1 (random_vector, this_random_address);
6097 hash_set (random_hash, this_random_address, 1);
6098 }
6099 hash_free (random_hash);
6100 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07006101 }
6102
Dave Barach72d72232016-08-04 10:15:08 -04006103 if (count > 1)
6104 {
6105 /* Turn on async mode */
6106 vam->async_mode = 1;
6107 vam->async_errors = 0;
6108 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006109 }
6110
Dave Barach72d72232016-08-04 10:15:08 -04006111 for (j = 0; j < count; j++)
6112 {
6113 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006114 M2 (IP_ADD_DEL_ROUTE, ip_add_del_route,
6115 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006116
Dave Barach72d72232016-08-04 10:15:08 -04006117 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006118 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04006119 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006120
Dave Barach72d72232016-08-04 10:15:08 -04006121 mp->is_add = is_add;
6122 mp->is_drop = is_drop;
Neale Ranns948e00f2016-10-20 13:39:34 +01006123 mp->is_unreach = is_unreach;
6124 mp->is_prohibit = is_prohibit;
Dave Barach72d72232016-08-04 10:15:08 -04006125 mp->is_ipv6 = is_ipv6;
6126 mp->is_local = is_local;
6127 mp->is_classify = is_classify;
6128 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006129 mp->is_resolve_host = resolve_host;
6130 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04006131 mp->not_last = not_last;
6132 mp->next_hop_weight = next_hop_weight;
6133 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006134 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04006135 mp->classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006136 mp->next_hop_via_label = ntohl (next_hop_via_label);
6137 mp->next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6138 if (0 != mp->next_hop_n_out_labels)
6139 {
6140 memcpy (mp->next_hop_out_label_stack,
6141 next_hop_out_label_stack,
6142 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6143 vec_free (next_hop_out_label_stack);
6144 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006145
Dave Barach72d72232016-08-04 10:15:08 -04006146 if (is_ipv6)
6147 {
6148 clib_memcpy (mp->dst_address, &v6_dst_address,
6149 sizeof (v6_dst_address));
6150 if (next_hop_set)
6151 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
6152 sizeof (v6_next_hop_address));
6153 increment_v6_address (&v6_dst_address);
6154 }
6155 else
6156 {
6157 clib_memcpy (mp->dst_address, &v4_dst_address,
6158 sizeof (v4_dst_address));
6159 if (next_hop_set)
6160 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
6161 sizeof (v4_next_hop_address));
6162 if (random_add_del)
6163 v4_dst_address.as_u32 = random_vector[j + 1];
6164 else
6165 increment_v4_address (&v4_dst_address);
6166 }
6167 /* send it... */
6168 S;
Dave Barach477570e2016-10-09 17:43:22 -04006169 /* If we receive SIGTERM, stop now... */
6170 if (vam->do_exit)
6171 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006172 }
6173
Dave Barach72d72232016-08-04 10:15:08 -04006174 /* When testing multiple add/del ops, use a control-ping to sync */
6175 if (count > 1)
6176 {
6177 vl_api_control_ping_t *mp;
6178 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006179
Dave Barach72d72232016-08-04 10:15:08 -04006180 /* Shut off async mode */
6181 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006182
Dave Barach72d72232016-08-04 10:15:08 -04006183 M (CONTROL_PING, control_ping);
6184 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006185
Dave Barach72d72232016-08-04 10:15:08 -04006186 timeout = vat_time_now (vam) + 1.0;
6187 while (vat_time_now (vam) < timeout)
6188 if (vam->result_ready == 1)
6189 goto out;
6190 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006191
6192 out:
Dave Barach72d72232016-08-04 10:15:08 -04006193 if (vam->retval == -99)
6194 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006195
Dave Barach72d72232016-08-04 10:15:08 -04006196 if (vam->async_errors > 0)
6197 {
6198 errmsg ("%d asynchronous errors\n", vam->async_errors);
6199 vam->retval = -98;
6200 }
6201 vam->async_errors = 0;
6202 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006203
Dave Barach477570e2016-10-09 17:43:22 -04006204 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6205 if (j > 0)
6206 count = j;
6207
Dave Barach72d72232016-08-04 10:15:08 -04006208 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6209 count, after - before, count / (after - before));
6210 }
6211 else
6212 {
6213 /* Wait for a reply... */
6214 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006215 }
6216
Dave Barach72d72232016-08-04 10:15:08 -04006217 /* Return the good/bad news */
6218 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006219}
6220
Dave Barach72d72232016-08-04 10:15:08 -04006221static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006222api_mpls_route_add_del (vat_main_t * vam)
6223{
6224 unformat_input_t *i = vam->input;
6225 vl_api_mpls_route_add_del_t *mp;
6226 f64 timeout;
6227 u32 sw_if_index = ~0, table_id = 0;
6228 u8 create_table_if_needed = 0;
6229 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006230 u32 next_hop_weight = 1;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006231 u8 is_multipath = 0;
6232 u32 next_hop_table_id = 0;
6233 u8 next_hop_set = 0;
6234 ip4_address_t v4_next_hop_address = {
6235 .as_u32 = 0,
6236 };
6237 ip6_address_t v6_next_hop_address = { {0} };
6238 int count = 1;
6239 int j;
6240 f64 before = 0;
6241 u32 classify_table_index = ~0;
6242 u8 is_classify = 0;
6243 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006244 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006245 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006246 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006247 mpls_label_t local_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006248 u8 is_eos = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006249 u8 next_hop_proto_is_ip4 = 1;
6250
6251 /* Parse args required to build the message */
6252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6253 {
6254 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6255 ;
6256 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6257 ;
6258 else if (unformat (i, "%d", &local_label))
6259 ;
6260 else if (unformat (i, "eos"))
6261 is_eos = 1;
6262 else if (unformat (i, "non-eos"))
6263 is_eos = 0;
6264 else if (unformat (i, "via %U", unformat_ip4_address,
6265 &v4_next_hop_address))
6266 {
6267 next_hop_set = 1;
6268 next_hop_proto_is_ip4 = 1;
6269 }
6270 else if (unformat (i, "via %U", unformat_ip6_address,
6271 &v6_next_hop_address))
6272 {
6273 next_hop_set = 1;
6274 next_hop_proto_is_ip4 = 0;
6275 }
6276 else if (unformat (i, "weight %d", &next_hop_weight))
6277 ;
6278 else if (unformat (i, "create-table"))
6279 create_table_if_needed = 1;
6280 else if (unformat (i, "classify %d", &classify_table_index))
6281 {
6282 is_classify = 1;
6283 }
6284 else if (unformat (i, "del"))
6285 is_add = 0;
6286 else if (unformat (i, "add"))
6287 is_add = 1;
6288 else if (unformat (i, "resolve-via-host"))
6289 resolve_host = 1;
6290 else if (unformat (i, "resolve-via-attached"))
6291 resolve_attached = 1;
6292 else if (unformat (i, "multipath"))
6293 is_multipath = 1;
6294 else if (unformat (i, "count %d", &count))
6295 ;
6296 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6297 {
6298 next_hop_set = 1;
6299 next_hop_proto_is_ip4 = 1;
6300 }
6301 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6302 {
6303 next_hop_set = 1;
6304 next_hop_proto_is_ip4 = 0;
6305 }
6306 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6307 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006308 else if (unformat (i, "via-label %d", &next_hop_via_label))
Neale Ranns1357f3b2016-10-16 12:01:42 -07006309 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006310 else if (unformat (i, "out-label %d", &next_hop_out_label))
6311 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006312 else
6313 {
6314 clib_warning ("parse error '%U'", format_unformat_error, i);
6315 return -99;
6316 }
6317 }
6318
6319 if (!next_hop_set && !is_classify)
6320 {
6321 errmsg ("next hop / classify not set\n");
6322 return -99;
6323 }
6324
6325 if (MPLS_LABEL_INVALID == local_label)
6326 {
6327 errmsg ("missing label\n");
6328 return -99;
6329 }
6330
6331 if (count > 1)
6332 {
6333 /* Turn on async mode */
6334 vam->async_mode = 1;
6335 vam->async_errors = 0;
6336 before = vat_time_now (vam);
6337 }
6338
6339 for (j = 0; j < count; j++)
6340 {
6341 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006342 M2 (MPLS_ROUTE_ADD_DEL, mpls_route_add_del,
6343 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006344
6345 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6346 mp->mr_table_id = ntohl (table_id);
6347 mp->mr_create_table_if_needed = create_table_if_needed;
6348
6349 mp->mr_is_add = is_add;
6350 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6351 mp->mr_is_classify = is_classify;
6352 mp->mr_is_multipath = is_multipath;
6353 mp->mr_is_resolve_host = resolve_host;
6354 mp->mr_is_resolve_attached = resolve_attached;
6355 mp->mr_next_hop_weight = next_hop_weight;
6356 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6357 mp->mr_classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006358 mp->mr_next_hop_via_label = ntohl (next_hop_via_label);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006359 mp->mr_label = ntohl (local_label);
6360 mp->mr_eos = is_eos;
6361
Neale Rannsad422ed2016-11-02 14:20:04 +00006362 mp->mr_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6363 if (0 != mp->mr_next_hop_n_out_labels)
6364 {
6365 memcpy (mp->mr_next_hop_out_label_stack,
6366 next_hop_out_label_stack,
6367 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6368 vec_free (next_hop_out_label_stack);
6369 }
6370
Neale Ranns1357f3b2016-10-16 12:01:42 -07006371 if (next_hop_set)
6372 {
6373 if (next_hop_proto_is_ip4)
6374 {
6375 clib_memcpy (mp->mr_next_hop,
6376 &v4_next_hop_address,
6377 sizeof (v4_next_hop_address));
6378 }
6379 else
6380 {
6381 clib_memcpy (mp->mr_next_hop,
6382 &v6_next_hop_address,
6383 sizeof (v6_next_hop_address));
6384 }
6385 }
6386 local_label++;
6387
6388 /* send it... */
6389 S;
6390 /* If we receive SIGTERM, stop now... */
6391 if (vam->do_exit)
6392 break;
6393 }
6394
6395 /* When testing multiple add/del ops, use a control-ping to sync */
6396 if (count > 1)
6397 {
6398 vl_api_control_ping_t *mp;
6399 f64 after;
6400
6401 /* Shut off async mode */
6402 vam->async_mode = 0;
6403
6404 M (CONTROL_PING, control_ping);
6405 S;
6406
6407 timeout = vat_time_now (vam) + 1.0;
6408 while (vat_time_now (vam) < timeout)
6409 if (vam->result_ready == 1)
6410 goto out;
6411 vam->retval = -99;
6412
6413 out:
6414 if (vam->retval == -99)
6415 errmsg ("timeout\n");
6416
6417 if (vam->async_errors > 0)
6418 {
6419 errmsg ("%d asynchronous errors\n", vam->async_errors);
6420 vam->retval = -98;
6421 }
6422 vam->async_errors = 0;
6423 after = vat_time_now (vam);
6424
6425 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6426 if (j > 0)
6427 count = j;
6428
6429 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6430 count, after - before, count / (after - before));
6431 }
6432 else
6433 {
6434 /* Wait for a reply... */
6435 W;
6436 }
6437
6438 /* Return the good/bad news */
6439 return (vam->retval);
6440}
6441
6442static int
6443api_mpls_ip_bind_unbind (vat_main_t * vam)
6444{
6445 unformat_input_t *i = vam->input;
6446 vl_api_mpls_ip_bind_unbind_t *mp;
6447 f64 timeout;
6448 u32 ip_table_id = 0;
6449 u8 create_table_if_needed = 0;
6450 u8 is_bind = 1;
6451 u8 is_ip4 = 1;
6452 ip4_address_t v4_address;
6453 ip6_address_t v6_address;
6454 u32 address_length;
6455 u8 address_set = 0;
6456 mpls_label_t local_label = MPLS_LABEL_INVALID;
6457
6458 /* Parse args required to build the message */
6459 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6460 {
6461 if (unformat (i, "%U/%d", unformat_ip4_address,
6462 &v4_address, &address_length))
6463 {
6464 is_ip4 = 1;
6465 address_set = 1;
6466 }
6467 else if (unformat (i, "%U/%d", unformat_ip6_address,
6468 &v6_address, &address_length))
6469 {
6470 is_ip4 = 0;
6471 address_set = 1;
6472 }
6473 else if (unformat (i, "%d", &local_label))
6474 ;
6475 else if (unformat (i, "create-table"))
6476 create_table_if_needed = 1;
6477 else if (unformat (i, "table-id %d", &ip_table_id))
6478 ;
6479 else if (unformat (i, "unbind"))
6480 is_bind = 0;
6481 else if (unformat (i, "bind"))
6482 is_bind = 1;
6483 else
6484 {
6485 clib_warning ("parse error '%U'", format_unformat_error, i);
6486 return -99;
6487 }
6488 }
6489
6490 if (!address_set)
6491 {
6492 errmsg ("IP addres not set\n");
6493 return -99;
6494 }
6495
6496 if (MPLS_LABEL_INVALID == local_label)
6497 {
6498 errmsg ("missing label\n");
6499 return -99;
6500 }
6501
6502 /* Construct the API message */
6503 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6504
6505 mp->mb_create_table_if_needed = create_table_if_needed;
6506 mp->mb_is_bind = is_bind;
6507 mp->mb_is_ip4 = is_ip4;
6508 mp->mb_ip_table_id = ntohl (ip_table_id);
6509 mp->mb_mpls_table_id = 0;
6510 mp->mb_label = ntohl (local_label);
6511 mp->mb_address_length = address_length;
6512
6513 if (is_ip4)
6514 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6515 else
6516 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6517
6518 /* send it... */
6519 S;
6520
6521 /* Wait for a reply... */
6522 W;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006523}
6524
6525static int
Dave Barach72d72232016-08-04 10:15:08 -04006526api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006527{
Dave Barach72d72232016-08-04 10:15:08 -04006528 unformat_input_t *i = vam->input;
6529 vl_api_proxy_arp_add_del_t *mp;
6530 f64 timeout;
6531 u32 vrf_id = 0;
6532 u8 is_add = 1;
6533 ip4_address_t lo, hi;
6534 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006535
Dave Barach72d72232016-08-04 10:15:08 -04006536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6537 {
6538 if (unformat (i, "vrf %d", &vrf_id))
6539 ;
6540 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6541 unformat_ip4_address, &hi))
6542 range_set = 1;
6543 else if (unformat (i, "del"))
6544 is_add = 0;
6545 else
6546 {
6547 clib_warning ("parse error '%U'", format_unformat_error, i);
6548 return -99;
6549 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006550 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006551
Dave Barach72d72232016-08-04 10:15:08 -04006552 if (range_set == 0)
6553 {
6554 errmsg ("address range not set\n");
6555 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006556 }
6557
Dave Barach72d72232016-08-04 10:15:08 -04006558 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006559
Dave Barach72d72232016-08-04 10:15:08 -04006560 mp->vrf_id = ntohl (vrf_id);
6561 mp->is_add = is_add;
6562 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6563 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006564
Dave Barach72d72232016-08-04 10:15:08 -04006565 S;
6566 W;
6567 /* NOTREACHED */
6568 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006569}
6570
Dave Barach72d72232016-08-04 10:15:08 -04006571static int
6572api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006573{
Dave Barach72d72232016-08-04 10:15:08 -04006574 unformat_input_t *i = vam->input;
6575 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6576 f64 timeout;
6577 u32 sw_if_index;
6578 u8 enable = 1;
6579 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006580
Dave Barach72d72232016-08-04 10:15:08 -04006581 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6582 {
6583 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6584 sw_if_index_set = 1;
6585 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6586 sw_if_index_set = 1;
6587 else if (unformat (i, "enable"))
6588 enable = 1;
6589 else if (unformat (i, "disable"))
6590 enable = 0;
6591 else
6592 {
6593 clib_warning ("parse error '%U'", format_unformat_error, i);
6594 return -99;
6595 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006596 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006597
Dave Barach72d72232016-08-04 10:15:08 -04006598 if (sw_if_index_set == 0)
6599 {
6600 errmsg ("missing interface name or sw_if_index\n");
6601 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006602 }
6603
Dave Barach72d72232016-08-04 10:15:08 -04006604 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006605
Dave Barach72d72232016-08-04 10:15:08 -04006606 mp->sw_if_index = ntohl (sw_if_index);
6607 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006608
Dave Barach72d72232016-08-04 10:15:08 -04006609 S;
6610 W;
6611 /* NOTREACHED */
6612 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006613}
6614
Dave Barach72d72232016-08-04 10:15:08 -04006615static int
Neale Rannsad422ed2016-11-02 14:20:04 +00006616api_mpls_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006617{
Dave Barach72d72232016-08-04 10:15:08 -04006618 unformat_input_t *i = vam->input;
Neale Rannsad422ed2016-11-02 14:20:04 +00006619 vl_api_mpls_tunnel_add_del_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04006620 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006621
Dave Barach72d72232016-08-04 10:15:08 -04006622 u8 is_add = 1;
6623 u8 l2_only = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006624 u32 sw_if_index = ~0;
6625 u32 next_hop_sw_if_index = ~0;
6626 u32 next_hop_proto_is_ip4 = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006627
Neale Rannsad422ed2016-11-02 14:20:04 +00006628 u32 next_hop_table_id = 0;
6629 ip4_address_t v4_next_hop_address = {
6630 .as_u32 = 0,
6631 };
6632 ip6_address_t v6_next_hop_address = { {0} };
6633 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID, *labels = NULL;
Dave Barach75665d32016-11-17 11:36:59 -05006634
Dave Barach72d72232016-08-04 10:15:08 -04006635 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6636 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006637 if (unformat (i, "add"))
6638 is_add = 1;
6639 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6640 is_add = 0;
6641 else if (unformat (i, "sw_if_index %d", &next_hop_sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -04006642 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006643 else if (unformat (i, "via %U",
6644 unformat_ip4_address, &v4_next_hop_address))
6645 {
6646 next_hop_proto_is_ip4 = 1;
6647 }
6648 else if (unformat (i, "via %U",
6649 unformat_ip6_address, &v6_next_hop_address))
6650 {
6651 next_hop_proto_is_ip4 = 0;
6652 }
Dave Barach72d72232016-08-04 10:15:08 -04006653 else if (unformat (i, "l2-only"))
6654 l2_only = 1;
Neale Rannsad422ed2016-11-02 14:20:04 +00006655 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6656 ;
6657 else if (unformat (i, "out-label %d", &next_hop_out_label))
6658 vec_add1 (labels, ntohl (next_hop_out_label));
Dave Barach72d72232016-08-04 10:15:08 -04006659 else
6660 {
6661 clib_warning ("parse error '%U'", format_unformat_error, i);
6662 return -99;
6663 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006664 }
6665
Neale Rannsad422ed2016-11-02 14:20:04 +00006666 M2 (MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del,
6667 sizeof (mpls_label_t) * vec_len (labels));
6668
6669 mp->mt_next_hop_sw_if_index = ntohl (next_hop_sw_if_index);
6670 mp->mt_sw_if_index = ntohl (sw_if_index);
6671 mp->mt_is_add = is_add;
6672 mp->mt_l2_only = l2_only;
6673 mp->mt_next_hop_table_id = ntohl (next_hop_table_id);
6674 mp->mt_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6675
6676 mp->mt_next_hop_n_out_labels = vec_len (labels);
6677
6678 if (0 != mp->mt_next_hop_n_out_labels)
Dave Barach72d72232016-08-04 10:15:08 -04006679 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006680 clib_memcpy (mp->mt_next_hop_out_label_stack, labels,
6681 sizeof (mpls_label_t) * mp->mt_next_hop_n_out_labels);
6682 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006683 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006684
Neale Rannsad422ed2016-11-02 14:20:04 +00006685 if (next_hop_proto_is_ip4)
Dave Barach72d72232016-08-04 10:15:08 -04006686 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006687 clib_memcpy (mp->mt_next_hop,
6688 &v4_next_hop_address, sizeof (v4_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006689 }
Neale Rannsad422ed2016-11-02 14:20:04 +00006690 else
Dave Barach72d72232016-08-04 10:15:08 -04006691 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006692 clib_memcpy (mp->mt_next_hop,
6693 &v6_next_hop_address, sizeof (v6_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006694 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006695
Dave Barach72d72232016-08-04 10:15:08 -04006696 S;
6697 W;
6698 /* NOTREACHED */
6699 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006700}
6701
Dave Barach72d72232016-08-04 10:15:08 -04006702static int
6703api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006704{
Dave Barach72d72232016-08-04 10:15:08 -04006705 unformat_input_t *i = vam->input;
6706 vl_api_sw_interface_set_unnumbered_t *mp;
6707 f64 timeout;
6708 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006709 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006710 u8 is_add = 1;
6711 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006712
Dave Barach72d72232016-08-04 10:15:08 -04006713 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6714 {
6715 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6716 sw_if_index_set = 1;
6717 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6718 sw_if_index_set = 1;
6719 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6720 ;
6721 else if (unformat (i, "del"))
6722 is_add = 0;
6723 else
6724 {
6725 clib_warning ("parse error '%U'", format_unformat_error, i);
6726 return -99;
6727 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006728 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006729
Dave Barach72d72232016-08-04 10:15:08 -04006730 if (sw_if_index_set == 0)
6731 {
6732 errmsg ("missing interface name or sw_if_index\n");
6733 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006734 }
6735
Dave Barach72d72232016-08-04 10:15:08 -04006736 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006737
Dave Barach72d72232016-08-04 10:15:08 -04006738 mp->sw_if_index = ntohl (sw_if_index);
6739 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6740 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006741
Dave Barach72d72232016-08-04 10:15:08 -04006742 S;
6743 W;
6744 /* NOTREACHED */
6745 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006746}
6747
Dave Barach72d72232016-08-04 10:15:08 -04006748static int
6749api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006750{
Dave Barach72d72232016-08-04 10:15:08 -04006751 unformat_input_t *i = vam->input;
6752 vl_api_ip_neighbor_add_del_t *mp;
6753 f64 timeout;
6754 u32 sw_if_index;
6755 u8 sw_if_index_set = 0;
6756 u32 vrf_id = 0;
6757 u8 is_add = 1;
6758 u8 is_static = 0;
6759 u8 mac_address[6];
6760 u8 mac_set = 0;
6761 u8 v4_address_set = 0;
6762 u8 v6_address_set = 0;
6763 ip4_address_t v4address;
6764 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006765
Dave Barach72d72232016-08-04 10:15:08 -04006766 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006767
Dave Barach72d72232016-08-04 10:15:08 -04006768 /* Parse args required to build the message */
6769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6770 {
6771 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6772 {
6773 mac_set = 1;
6774 }
6775 else if (unformat (i, "del"))
6776 is_add = 0;
6777 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6778 sw_if_index_set = 1;
6779 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6780 sw_if_index_set = 1;
6781 else if (unformat (i, "is_static"))
6782 is_static = 1;
6783 else if (unformat (i, "vrf %d", &vrf_id))
6784 ;
6785 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6786 v4_address_set = 1;
6787 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6788 v6_address_set = 1;
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 }
6795
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 }
Dave Barach72d72232016-08-04 10:15:08 -04006801 if (v4_address_set && v6_address_set)
6802 {
6803 errmsg ("both v4 and v6 addresses set\n");
6804 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006805 }
Dave Barach72d72232016-08-04 10:15:08 -04006806 if (!v4_address_set && !v6_address_set)
6807 {
6808 errmsg ("no address set\n");
6809 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006810 }
6811
Dave Barach72d72232016-08-04 10:15:08 -04006812 /* Construct the API message */
6813 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006814
Dave Barach72d72232016-08-04 10:15:08 -04006815 mp->sw_if_index = ntohl (sw_if_index);
6816 mp->is_add = is_add;
6817 mp->vrf_id = ntohl (vrf_id);
6818 mp->is_static = is_static;
6819 if (mac_set)
6820 clib_memcpy (mp->mac_address, mac_address, 6);
6821 if (v6_address_set)
6822 {
6823 mp->is_ipv6 = 1;
6824 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6825 }
6826 else
6827 {
6828 /* mp->is_ipv6 = 0; via memset in M macro above */
6829 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006830 }
6831
Dave Barach72d72232016-08-04 10:15:08 -04006832 /* send it... */
6833 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006834
Dave Barach72d72232016-08-04 10:15:08 -04006835 /* Wait for a reply, return good/bad news */
6836 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006837
Dave Barach72d72232016-08-04 10:15:08 -04006838 /* NOTREACHED */
6839 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006840}
6841
Dave Barach72d72232016-08-04 10:15:08 -04006842static int
6843api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006844{
Dave Barach72d72232016-08-04 10:15:08 -04006845 unformat_input_t *i = vam->input;
6846 vl_api_reset_vrf_t *mp;
6847 f64 timeout;
6848 u32 vrf_id = 0;
6849 u8 is_ipv6 = 0;
6850 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006851
Dave Barach72d72232016-08-04 10:15:08 -04006852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6853 {
6854 if (unformat (i, "vrf %d", &vrf_id))
6855 vrf_id_set = 1;
6856 else if (unformat (i, "ipv6"))
6857 is_ipv6 = 1;
6858 else
6859 {
6860 clib_warning ("parse error '%U'", format_unformat_error, i);
6861 return -99;
6862 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006863 }
6864
Dave Barach72d72232016-08-04 10:15:08 -04006865 if (vrf_id_set == 0)
6866 {
6867 errmsg ("missing vrf id\n");
6868 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006869 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006870
Dave Barach72d72232016-08-04 10:15:08 -04006871 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006872
Dave Barach72d72232016-08-04 10:15:08 -04006873 mp->vrf_id = ntohl (vrf_id);
6874 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006875
Dave Barach72d72232016-08-04 10:15:08 -04006876 S;
6877 W;
6878 /* NOTREACHED */
6879 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006880}
6881
Dave Barach72d72232016-08-04 10:15:08 -04006882static int
6883api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006884{
Dave Barach72d72232016-08-04 10:15:08 -04006885 unformat_input_t *i = vam->input;
6886 vl_api_create_vlan_subif_t *mp;
6887 f64 timeout;
6888 u32 sw_if_index;
6889 u8 sw_if_index_set = 0;
6890 u32 vlan_id;
6891 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006892
Dave Barach72d72232016-08-04 10:15:08 -04006893 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6894 {
6895 if (unformat (i, "sw_if_index %d", &sw_if_index))
6896 sw_if_index_set = 1;
6897 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6898 sw_if_index_set = 1;
6899 else if (unformat (i, "vlan %d", &vlan_id))
6900 vlan_id_set = 1;
6901 else
6902 {
6903 clib_warning ("parse error '%U'", format_unformat_error, i);
6904 return -99;
6905 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006907
Dave Barach72d72232016-08-04 10:15:08 -04006908 if (sw_if_index_set == 0)
6909 {
6910 errmsg ("missing interface name or sw_if_index\n");
6911 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006912 }
6913
Dave Barach72d72232016-08-04 10:15:08 -04006914 if (vlan_id_set == 0)
6915 {
6916 errmsg ("missing vlan_id\n");
6917 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006918 }
Dave Barach72d72232016-08-04 10:15:08 -04006919 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006920
Dave Barach72d72232016-08-04 10:15:08 -04006921 mp->sw_if_index = ntohl (sw_if_index);
6922 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006923
Dave Barach72d72232016-08-04 10:15:08 -04006924 S;
6925 W;
6926 /* NOTREACHED */
6927 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006928}
6929
6930#define foreach_create_subif_bit \
6931_(no_tags) \
6932_(one_tag) \
6933_(two_tags) \
6934_(dot1ad) \
6935_(exact_match) \
6936_(default_sub) \
6937_(outer_vlan_id_any) \
6938_(inner_vlan_id_any)
6939
Dave Barach72d72232016-08-04 10:15:08 -04006940static int
6941api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006942{
Dave Barach72d72232016-08-04 10:15:08 -04006943 unformat_input_t *i = vam->input;
6944 vl_api_create_subif_t *mp;
6945 f64 timeout;
6946 u32 sw_if_index;
6947 u8 sw_if_index_set = 0;
6948 u32 sub_id;
6949 u8 sub_id_set = 0;
6950 u32 no_tags = 0;
6951 u32 one_tag = 0;
6952 u32 two_tags = 0;
6953 u32 dot1ad = 0;
6954 u32 exact_match = 0;
6955 u32 default_sub = 0;
6956 u32 outer_vlan_id_any = 0;
6957 u32 inner_vlan_id_any = 0;
6958 u32 tmp;
6959 u16 outer_vlan_id = 0;
6960 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006961
Dave Barach72d72232016-08-04 10:15:08 -04006962 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6963 {
6964 if (unformat (i, "sw_if_index %d", &sw_if_index))
6965 sw_if_index_set = 1;
6966 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6967 sw_if_index_set = 1;
6968 else if (unformat (i, "sub_id %d", &sub_id))
6969 sub_id_set = 1;
6970 else if (unformat (i, "outer_vlan_id %d", &tmp))
6971 outer_vlan_id = tmp;
6972 else if (unformat (i, "inner_vlan_id %d", &tmp))
6973 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006974
6975#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006976 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006977#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006978 else
6979 {
6980 clib_warning ("parse error '%U'", format_unformat_error, i);
6981 return -99;
6982 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006983 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006984
Dave Barach72d72232016-08-04 10:15:08 -04006985 if (sw_if_index_set == 0)
6986 {
6987 errmsg ("missing interface name or sw_if_index\n");
6988 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006989 }
6990
Dave Barach72d72232016-08-04 10:15:08 -04006991 if (sub_id_set == 0)
6992 {
6993 errmsg ("missing sub_id\n");
6994 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006995 }
Dave Barach72d72232016-08-04 10:15:08 -04006996 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006997
Dave Barach72d72232016-08-04 10:15:08 -04006998 mp->sw_if_index = ntohl (sw_if_index);
6999 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007000
Ed Warnickecb9cada2015-12-08 15:45:58 -07007001#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04007002 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007003#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007004
Dave Barach72d72232016-08-04 10:15:08 -04007005 mp->outer_vlan_id = ntohs (outer_vlan_id);
7006 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007007
Dave Barach72d72232016-08-04 10:15:08 -04007008 S;
7009 W;
7010 /* NOTREACHED */
7011 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007012}
7013
Dave Barach72d72232016-08-04 10:15:08 -04007014static int
7015api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007016{
Dave Barach72d72232016-08-04 10:15:08 -04007017 unformat_input_t *i = vam->input;
7018 vl_api_oam_add_del_t *mp;
7019 f64 timeout;
7020 u32 vrf_id = 0;
7021 u8 is_add = 1;
7022 ip4_address_t src, dst;
7023 u8 src_set = 0;
7024 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007025
Dave Barach72d72232016-08-04 10:15:08 -04007026 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7027 {
7028 if (unformat (i, "vrf %d", &vrf_id))
7029 ;
7030 else if (unformat (i, "src %U", unformat_ip4_address, &src))
7031 src_set = 1;
7032 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
7033 dst_set = 1;
7034 else if (unformat (i, "del"))
7035 is_add = 0;
7036 else
7037 {
7038 clib_warning ("parse error '%U'", format_unformat_error, i);
7039 return -99;
7040 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007041 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007042
Dave Barach72d72232016-08-04 10:15:08 -04007043 if (src_set == 0)
7044 {
7045 errmsg ("missing src addr\n");
7046 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007047 }
7048
Dave Barach72d72232016-08-04 10:15:08 -04007049 if (dst_set == 0)
7050 {
7051 errmsg ("missing dst addr\n");
7052 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007053 }
7054
Dave Barach72d72232016-08-04 10:15:08 -04007055 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007056
Dave Barach72d72232016-08-04 10:15:08 -04007057 mp->vrf_id = ntohl (vrf_id);
7058 mp->is_add = is_add;
7059 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
7060 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007061
Dave Barach72d72232016-08-04 10:15:08 -04007062 S;
7063 W;
7064 /* NOTREACHED */
7065 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007066}
7067
Dave Barach72d72232016-08-04 10:15:08 -04007068static int
7069api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007070{
Dave Barach72d72232016-08-04 10:15:08 -04007071 unformat_input_t *i = vam->input;
7072 vl_api_reset_fib_t *mp;
7073 f64 timeout;
7074 u32 vrf_id = 0;
7075 u8 is_ipv6 = 0;
7076 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007077
Dave Barach72d72232016-08-04 10:15:08 -04007078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7079 {
7080 if (unformat (i, "vrf %d", &vrf_id))
7081 vrf_id_set = 1;
7082 else if (unformat (i, "ipv6"))
7083 is_ipv6 = 1;
7084 else
7085 {
7086 clib_warning ("parse error '%U'", format_unformat_error, i);
7087 return -99;
7088 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007089 }
7090
Dave Barach72d72232016-08-04 10:15:08 -04007091 if (vrf_id_set == 0)
7092 {
7093 errmsg ("missing vrf id\n");
7094 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007095 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007096
Dave Barach72d72232016-08-04 10:15:08 -04007097 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007098
Dave Barach72d72232016-08-04 10:15:08 -04007099 mp->vrf_id = ntohl (vrf_id);
7100 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007101
Dave Barach72d72232016-08-04 10:15:08 -04007102 S;
7103 W;
7104 /* NOTREACHED */
7105 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007106}
7107
Dave Barach72d72232016-08-04 10:15:08 -04007108static int
7109api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007110{
Dave Barach72d72232016-08-04 10:15:08 -04007111 unformat_input_t *i = vam->input;
7112 vl_api_dhcp_proxy_config_t *mp;
7113 f64 timeout;
7114 u32 vrf_id = 0;
7115 u8 is_add = 1;
7116 u8 insert_cid = 1;
7117 u8 v4_address_set = 0;
7118 u8 v6_address_set = 0;
7119 ip4_address_t v4address;
7120 ip6_address_t v6address;
7121 u8 v4_src_address_set = 0;
7122 u8 v6_src_address_set = 0;
7123 ip4_address_t v4srcaddress;
7124 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007125
Dave Barach72d72232016-08-04 10:15:08 -04007126 /* Parse args required to build the message */
7127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7128 {
7129 if (unformat (i, "del"))
7130 is_add = 0;
7131 else if (unformat (i, "vrf %d", &vrf_id))
7132 ;
7133 else if (unformat (i, "insert-cid %d", &insert_cid))
7134 ;
7135 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7136 v4_address_set = 1;
7137 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7138 v6_address_set = 1;
7139 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7140 v4_src_address_set = 1;
7141 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7142 v6_src_address_set = 1;
7143 else
7144 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007145 }
7146
Dave Barach72d72232016-08-04 10:15:08 -04007147 if (v4_address_set && v6_address_set)
7148 {
7149 errmsg ("both v4 and v6 server addresses set\n");
7150 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007151 }
Dave Barach72d72232016-08-04 10:15:08 -04007152 if (!v4_address_set && !v6_address_set)
7153 {
7154 errmsg ("no server addresses set\n");
7155 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007156 }
7157
Dave Barach72d72232016-08-04 10:15:08 -04007158 if (v4_src_address_set && v6_src_address_set)
7159 {
7160 errmsg ("both v4 and v6 src addresses set\n");
7161 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007162 }
Dave Barach72d72232016-08-04 10:15:08 -04007163 if (!v4_src_address_set && !v6_src_address_set)
7164 {
7165 errmsg ("no src addresses set\n");
7166 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007167 }
7168
Dave Barach72d72232016-08-04 10:15:08 -04007169 if (!(v4_src_address_set && v4_address_set) &&
7170 !(v6_src_address_set && v6_address_set))
7171 {
7172 errmsg ("no matching server and src addresses set\n");
7173 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007174 }
7175
Dave Barach72d72232016-08-04 10:15:08 -04007176 /* Construct the API message */
7177 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007178
Dave Barach72d72232016-08-04 10:15:08 -04007179 mp->insert_circuit_id = insert_cid;
7180 mp->is_add = is_add;
7181 mp->vrf_id = ntohl (vrf_id);
7182 if (v6_address_set)
7183 {
7184 mp->is_ipv6 = 1;
7185 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7186 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7187 }
7188 else
7189 {
7190 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7191 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007192 }
7193
Dave Barach72d72232016-08-04 10:15:08 -04007194 /* send it... */
7195 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007196
Dave Barach72d72232016-08-04 10:15:08 -04007197 /* Wait for a reply, return good/bad news */
7198 W;
7199 /* NOTREACHED */
7200 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007201}
7202
Dave Barach72d72232016-08-04 10:15:08 -04007203static int
7204api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007205{
Dave Barach72d72232016-08-04 10:15:08 -04007206 unformat_input_t *i = vam->input;
7207 vl_api_dhcp_proxy_config_2_t *mp;
7208 f64 timeout;
7209 u32 rx_vrf_id = 0;
7210 u32 server_vrf_id = 0;
7211 u8 is_add = 1;
7212 u8 insert_cid = 1;
7213 u8 v4_address_set = 0;
7214 u8 v6_address_set = 0;
7215 ip4_address_t v4address;
7216 ip6_address_t v6address;
7217 u8 v4_src_address_set = 0;
7218 u8 v6_src_address_set = 0;
7219 ip4_address_t v4srcaddress;
7220 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007221
Dave Barach72d72232016-08-04 10:15:08 -04007222 /* Parse args required to build the message */
7223 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7224 {
7225 if (unformat (i, "del"))
7226 is_add = 0;
7227 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7228 ;
7229 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7230 ;
7231 else if (unformat (i, "insert-cid %d", &insert_cid))
7232 ;
7233 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7234 v4_address_set = 1;
7235 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7236 v6_address_set = 1;
7237 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7238 v4_src_address_set = 1;
7239 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7240 v6_src_address_set = 1;
7241 else
7242 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007243 }
7244
Dave Barach72d72232016-08-04 10:15:08 -04007245 if (v4_address_set && v6_address_set)
7246 {
7247 errmsg ("both v4 and v6 server addresses set\n");
7248 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007249 }
Dave Barach72d72232016-08-04 10:15:08 -04007250 if (!v4_address_set && !v6_address_set)
7251 {
7252 errmsg ("no server addresses set\n");
7253 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007254 }
7255
Dave Barach72d72232016-08-04 10:15:08 -04007256 if (v4_src_address_set && v6_src_address_set)
7257 {
7258 errmsg ("both v4 and v6 src addresses set\n");
7259 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007260 }
Dave Barach72d72232016-08-04 10:15:08 -04007261 if (!v4_src_address_set && !v6_src_address_set)
7262 {
7263 errmsg ("no src addresses set\n");
7264 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007265 }
7266
Dave Barach72d72232016-08-04 10:15:08 -04007267 if (!(v4_src_address_set && v4_address_set) &&
7268 !(v6_src_address_set && v6_address_set))
7269 {
7270 errmsg ("no matching server and src addresses set\n");
7271 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007272 }
7273
Dave Barach72d72232016-08-04 10:15:08 -04007274 /* Construct the API message */
7275 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007276
Dave Barach72d72232016-08-04 10:15:08 -04007277 mp->insert_circuit_id = insert_cid;
7278 mp->is_add = is_add;
7279 mp->rx_vrf_id = ntohl (rx_vrf_id);
7280 mp->server_vrf_id = ntohl (server_vrf_id);
7281 if (v6_address_set)
7282 {
7283 mp->is_ipv6 = 1;
7284 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7285 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7286 }
7287 else
7288 {
7289 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7290 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007291 }
7292
Dave Barach72d72232016-08-04 10:15:08 -04007293 /* send it... */
7294 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007295
Dave Barach72d72232016-08-04 10:15:08 -04007296 /* Wait for a reply, return good/bad news */
7297 W;
7298 /* NOTREACHED */
7299 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007300}
7301
Dave Barach72d72232016-08-04 10:15:08 -04007302static int
7303api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007304{
Dave Barach72d72232016-08-04 10:15:08 -04007305 unformat_input_t *i = vam->input;
7306 vl_api_dhcp_proxy_set_vss_t *mp;
7307 f64 timeout;
7308 u8 is_ipv6 = 0;
7309 u8 is_add = 1;
7310 u32 tbl_id;
7311 u8 tbl_id_set = 0;
7312 u32 oui;
7313 u8 oui_set = 0;
7314 u32 fib_id;
7315 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007316
Dave Barach72d72232016-08-04 10:15:08 -04007317 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7318 {
7319 if (unformat (i, "tbl_id %d", &tbl_id))
7320 tbl_id_set = 1;
7321 if (unformat (i, "fib_id %d", &fib_id))
7322 fib_id_set = 1;
7323 if (unformat (i, "oui %d", &oui))
7324 oui_set = 1;
7325 else if (unformat (i, "ipv6"))
7326 is_ipv6 = 1;
7327 else if (unformat (i, "del"))
7328 is_add = 0;
7329 else
7330 {
7331 clib_warning ("parse error '%U'", format_unformat_error, i);
7332 return -99;
7333 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007334 }
7335
Dave Barach72d72232016-08-04 10:15:08 -04007336 if (tbl_id_set == 0)
7337 {
7338 errmsg ("missing tbl id\n");
7339 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007340 }
7341
Dave Barach72d72232016-08-04 10:15:08 -04007342 if (fib_id_set == 0)
7343 {
7344 errmsg ("missing fib id\n");
7345 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007346 }
Dave Barach72d72232016-08-04 10:15:08 -04007347 if (oui_set == 0)
7348 {
7349 errmsg ("missing oui\n");
7350 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007351 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007352
Dave Barach72d72232016-08-04 10:15:08 -04007353 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7354 mp->tbl_id = ntohl (tbl_id);
7355 mp->fib_id = ntohl (fib_id);
7356 mp->oui = ntohl (oui);
7357 mp->is_ipv6 = is_ipv6;
7358 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007359
Dave Barach72d72232016-08-04 10:15:08 -04007360 S;
7361 W;
7362 /* NOTREACHED */
7363 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007364}
7365
Dave Barach72d72232016-08-04 10:15:08 -04007366static int
7367api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007368{
Dave Barach72d72232016-08-04 10:15:08 -04007369 unformat_input_t *i = vam->input;
7370 vl_api_dhcp_client_config_t *mp;
7371 f64 timeout;
7372 u32 sw_if_index;
7373 u8 sw_if_index_set = 0;
7374 u8 is_add = 1;
7375 u8 *hostname = 0;
7376 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007377
Dave Barach72d72232016-08-04 10:15:08 -04007378 /* Parse args required to build the message */
7379 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7380 {
7381 if (unformat (i, "del"))
7382 is_add = 0;
7383 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7384 sw_if_index_set = 1;
7385 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7386 sw_if_index_set = 1;
7387 else if (unformat (i, "hostname %s", &hostname))
7388 ;
7389 else if (unformat (i, "disable_event"))
7390 disable_event = 1;
7391 else
7392 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007393 }
7394
Dave Barach72d72232016-08-04 10:15:08 -04007395 if (sw_if_index_set == 0)
7396 {
7397 errmsg ("missing interface name or sw_if_index\n");
7398 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007399 }
7400
Dave Barach72d72232016-08-04 10:15:08 -04007401 if (vec_len (hostname) > 63)
7402 {
7403 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007404 }
Dave Barach72d72232016-08-04 10:15:08 -04007405 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007406
Dave Barach72d72232016-08-04 10:15:08 -04007407 /* Construct the API message */
7408 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007409
Dave Barach72d72232016-08-04 10:15:08 -04007410 mp->sw_if_index = ntohl (sw_if_index);
7411 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7412 vec_free (hostname);
7413 mp->is_add = is_add;
7414 mp->want_dhcp_event = disable_event ? 0 : 1;
7415 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007416
Dave Barach72d72232016-08-04 10:15:08 -04007417 /* send it... */
7418 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007419
Dave Barach72d72232016-08-04 10:15:08 -04007420 /* Wait for a reply, return good/bad news */
7421 W;
7422 /* NOTREACHED */
7423 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007424}
7425
Dave Barach72d72232016-08-04 10:15:08 -04007426static int
7427api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007428{
Dave Barach72d72232016-08-04 10:15:08 -04007429 unformat_input_t *i = vam->input;
7430 vl_api_set_ip_flow_hash_t *mp;
7431 f64 timeout;
7432 u32 vrf_id = 0;
7433 u8 is_ipv6 = 0;
7434 u8 vrf_id_set = 0;
7435 u8 src = 0;
7436 u8 dst = 0;
7437 u8 sport = 0;
7438 u8 dport = 0;
7439 u8 proto = 0;
7440 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007441
Dave Barach72d72232016-08-04 10:15:08 -04007442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7443 {
7444 if (unformat (i, "vrf %d", &vrf_id))
7445 vrf_id_set = 1;
7446 else if (unformat (i, "ipv6"))
7447 is_ipv6 = 1;
7448 else if (unformat (i, "src"))
7449 src = 1;
7450 else if (unformat (i, "dst"))
7451 dst = 1;
7452 else if (unformat (i, "sport"))
7453 sport = 1;
7454 else if (unformat (i, "dport"))
7455 dport = 1;
7456 else if (unformat (i, "proto"))
7457 proto = 1;
7458 else if (unformat (i, "reverse"))
7459 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007460
Dave Barach72d72232016-08-04 10:15:08 -04007461 else
7462 {
7463 clib_warning ("parse error '%U'", format_unformat_error, i);
7464 return -99;
7465 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007466 }
7467
Dave Barach72d72232016-08-04 10:15:08 -04007468 if (vrf_id_set == 0)
7469 {
7470 errmsg ("missing vrf id\n");
7471 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007472 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007473
Dave Barach72d72232016-08-04 10:15:08 -04007474 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7475 mp->src = src;
7476 mp->dst = dst;
7477 mp->sport = sport;
7478 mp->dport = dport;
7479 mp->proto = proto;
7480 mp->reverse = reverse;
7481 mp->vrf_id = ntohl (vrf_id);
7482 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007483
Dave Barach72d72232016-08-04 10:15:08 -04007484 S;
7485 W;
7486 /* NOTREACHED */
7487 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007488}
7489
Dave Barach72d72232016-08-04 10:15:08 -04007490static int
7491api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007492{
Dave Barach72d72232016-08-04 10:15:08 -04007493 unformat_input_t *i = vam->input;
7494 vl_api_sw_interface_ip6_enable_disable_t *mp;
7495 f64 timeout;
7496 u32 sw_if_index;
7497 u8 sw_if_index_set = 0;
7498 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007499
Dave Barach72d72232016-08-04 10:15:08 -04007500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7501 {
7502 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7503 sw_if_index_set = 1;
7504 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7505 sw_if_index_set = 1;
7506 else if (unformat (i, "enable"))
7507 enable = 1;
7508 else if (unformat (i, "disable"))
7509 enable = 0;
7510 else
7511 {
7512 clib_warning ("parse error '%U'", format_unformat_error, i);
7513 return -99;
7514 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007515 }
7516
Dave Barach72d72232016-08-04 10:15:08 -04007517 if (sw_if_index_set == 0)
7518 {
7519 errmsg ("missing interface name or sw_if_index\n");
7520 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007521 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007522
Dave Barach72d72232016-08-04 10:15:08 -04007523 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007524
Dave Barach72d72232016-08-04 10:15:08 -04007525 mp->sw_if_index = ntohl (sw_if_index);
7526 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007527
Dave Barach72d72232016-08-04 10:15:08 -04007528 S;
7529 W;
7530 /* NOTREACHED */
7531 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007532}
7533
Dave Barach72d72232016-08-04 10:15:08 -04007534static int
7535api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007536{
Dave Barach72d72232016-08-04 10:15:08 -04007537 unformat_input_t *i = vam->input;
7538 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7539 f64 timeout;
7540 u32 sw_if_index;
7541 u8 sw_if_index_set = 0;
7542 u32 address_length = 0;
7543 u8 v6_address_set = 0;
7544 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007545
Dave Barach72d72232016-08-04 10:15:08 -04007546 /* Parse args required to build the message */
7547 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7548 {
7549 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7550 sw_if_index_set = 1;
7551 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7552 sw_if_index_set = 1;
7553 else if (unformat (i, "%U/%d",
7554 unformat_ip6_address, &v6address, &address_length))
7555 v6_address_set = 1;
7556 else
7557 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007558 }
7559
Dave Barach72d72232016-08-04 10:15:08 -04007560 if (sw_if_index_set == 0)
7561 {
7562 errmsg ("missing interface name or sw_if_index\n");
7563 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007564 }
Dave Barach72d72232016-08-04 10:15:08 -04007565 if (!v6_address_set)
7566 {
7567 errmsg ("no address set\n");
7568 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007569 }
7570
Dave Barach72d72232016-08-04 10:15:08 -04007571 /* Construct the API message */
7572 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7573 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007574
Dave Barach72d72232016-08-04 10:15:08 -04007575 mp->sw_if_index = ntohl (sw_if_index);
7576 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7577 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007578
Dave Barach72d72232016-08-04 10:15:08 -04007579 /* send it... */
7580 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007581
Dave Barach72d72232016-08-04 10:15:08 -04007582 /* Wait for a reply, return good/bad news */
7583 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007584
Dave Barach72d72232016-08-04 10:15:08 -04007585 /* NOTREACHED */
7586 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007587}
7588
7589
Dave Barach72d72232016-08-04 10:15:08 -04007590static int
7591api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007592{
Dave Barach72d72232016-08-04 10:15:08 -04007593 unformat_input_t *i = vam->input;
7594 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7595 f64 timeout;
7596 u32 sw_if_index;
7597 u8 sw_if_index_set = 0;
7598 u32 address_length = 0;
7599 u8 v6_address_set = 0;
7600 ip6_address_t v6address;
7601 u8 use_default = 0;
7602 u8 no_advertise = 0;
7603 u8 off_link = 0;
7604 u8 no_autoconfig = 0;
7605 u8 no_onlink = 0;
7606 u8 is_no = 0;
7607 u32 val_lifetime = 0;
7608 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007609
Dave Barach72d72232016-08-04 10:15:08 -04007610 /* Parse args required to build the message */
7611 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7612 {
7613 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7614 sw_if_index_set = 1;
7615 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7616 sw_if_index_set = 1;
7617 else if (unformat (i, "%U/%d",
7618 unformat_ip6_address, &v6address, &address_length))
7619 v6_address_set = 1;
7620 else if (unformat (i, "val_life %d", &val_lifetime))
7621 ;
7622 else if (unformat (i, "pref_life %d", &pref_lifetime))
7623 ;
7624 else if (unformat (i, "def"))
7625 use_default = 1;
7626 else if (unformat (i, "noadv"))
7627 no_advertise = 1;
7628 else if (unformat (i, "offl"))
7629 off_link = 1;
7630 else if (unformat (i, "noauto"))
7631 no_autoconfig = 1;
7632 else if (unformat (i, "nolink"))
7633 no_onlink = 1;
7634 else if (unformat (i, "isno"))
7635 is_no = 1;
7636 else
7637 {
7638 clib_warning ("parse error '%U'", format_unformat_error, i);
7639 return -99;
7640 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007641 }
7642
Dave Barach72d72232016-08-04 10:15:08 -04007643 if (sw_if_index_set == 0)
7644 {
7645 errmsg ("missing interface name or sw_if_index\n");
7646 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007647 }
Dave Barach72d72232016-08-04 10:15:08 -04007648 if (!v6_address_set)
7649 {
7650 errmsg ("no address set\n");
7651 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007652 }
7653
Dave Barach72d72232016-08-04 10:15:08 -04007654 /* Construct the API message */
7655 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007656
Dave Barach72d72232016-08-04 10:15:08 -04007657 mp->sw_if_index = ntohl (sw_if_index);
7658 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7659 mp->address_length = address_length;
7660 mp->use_default = use_default;
7661 mp->no_advertise = no_advertise;
7662 mp->off_link = off_link;
7663 mp->no_autoconfig = no_autoconfig;
7664 mp->no_onlink = no_onlink;
7665 mp->is_no = is_no;
7666 mp->val_lifetime = ntohl (val_lifetime);
7667 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007668
Dave Barach72d72232016-08-04 10:15:08 -04007669 /* send it... */
7670 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007671
Dave Barach72d72232016-08-04 10:15:08 -04007672 /* Wait for a reply, return good/bad news */
7673 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007674
Dave Barach72d72232016-08-04 10:15:08 -04007675 /* NOTREACHED */
7676 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007677}
7678
Dave Barach72d72232016-08-04 10:15:08 -04007679static int
7680api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007681{
Dave Barach72d72232016-08-04 10:15:08 -04007682 unformat_input_t *i = vam->input;
7683 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7684 f64 timeout;
7685 u32 sw_if_index;
7686 u8 sw_if_index_set = 0;
7687 u8 suppress = 0;
7688 u8 managed = 0;
7689 u8 other = 0;
7690 u8 ll_option = 0;
7691 u8 send_unicast = 0;
7692 u8 cease = 0;
7693 u8 is_no = 0;
7694 u8 default_router = 0;
7695 u32 max_interval = 0;
7696 u32 min_interval = 0;
7697 u32 lifetime = 0;
7698 u32 initial_count = 0;
7699 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007700
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007701
Dave Barach72d72232016-08-04 10:15:08 -04007702 /* Parse args required to build the message */
7703 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7704 {
7705 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7706 sw_if_index_set = 1;
7707 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7708 sw_if_index_set = 1;
7709 else if (unformat (i, "maxint %d", &max_interval))
7710 ;
7711 else if (unformat (i, "minint %d", &min_interval))
7712 ;
7713 else if (unformat (i, "life %d", &lifetime))
7714 ;
7715 else if (unformat (i, "count %d", &initial_count))
7716 ;
7717 else if (unformat (i, "interval %d", &initial_interval))
7718 ;
7719 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7720 suppress = 1;
7721 else if (unformat (i, "managed"))
7722 managed = 1;
7723 else if (unformat (i, "other"))
7724 other = 1;
7725 else if (unformat (i, "ll"))
7726 ll_option = 1;
7727 else if (unformat (i, "send"))
7728 send_unicast = 1;
7729 else if (unformat (i, "cease"))
7730 cease = 1;
7731 else if (unformat (i, "isno"))
7732 is_no = 1;
7733 else if (unformat (i, "def"))
7734 default_router = 1;
7735 else
7736 {
7737 clib_warning ("parse error '%U'", format_unformat_error, i);
7738 return -99;
7739 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007740 }
7741
Dave Barach72d72232016-08-04 10:15:08 -04007742 if (sw_if_index_set == 0)
7743 {
7744 errmsg ("missing interface name or sw_if_index\n");
7745 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007746 }
7747
Dave Barach72d72232016-08-04 10:15:08 -04007748 /* Construct the API message */
7749 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007750
Dave Barach72d72232016-08-04 10:15:08 -04007751 mp->sw_if_index = ntohl (sw_if_index);
7752 mp->max_interval = ntohl (max_interval);
7753 mp->min_interval = ntohl (min_interval);
7754 mp->lifetime = ntohl (lifetime);
7755 mp->initial_count = ntohl (initial_count);
7756 mp->initial_interval = ntohl (initial_interval);
7757 mp->suppress = suppress;
7758 mp->managed = managed;
7759 mp->other = other;
7760 mp->ll_option = ll_option;
7761 mp->send_unicast = send_unicast;
7762 mp->cease = cease;
7763 mp->is_no = is_no;
7764 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007765
Dave Barach72d72232016-08-04 10:15:08 -04007766 /* send it... */
7767 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007768
Dave Barach72d72232016-08-04 10:15:08 -04007769 /* Wait for a reply, return good/bad news */
7770 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007771
Dave Barach72d72232016-08-04 10:15:08 -04007772 /* NOTREACHED */
7773 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007774}
7775
Dave Barach72d72232016-08-04 10:15:08 -04007776static int
7777api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007778{
Dave Barach72d72232016-08-04 10:15:08 -04007779 unformat_input_t *i = vam->input;
7780 vl_api_set_arp_neighbor_limit_t *mp;
7781 f64 timeout;
7782 u32 arp_nbr_limit;
7783 u8 limit_set = 0;
7784 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007785
Dave Barach72d72232016-08-04 10:15:08 -04007786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7787 {
7788 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7789 limit_set = 1;
7790 else if (unformat (i, "ipv6"))
7791 is_ipv6 = 1;
7792 else
7793 {
7794 clib_warning ("parse error '%U'", format_unformat_error, i);
7795 return -99;
7796 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007797 }
7798
Dave Barach72d72232016-08-04 10:15:08 -04007799 if (limit_set == 0)
7800 {
7801 errmsg ("missing limit value\n");
7802 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007803 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007804
Dave Barach72d72232016-08-04 10:15:08 -04007805 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806
Dave Barach72d72232016-08-04 10:15:08 -04007807 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7808 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007809
Dave Barach72d72232016-08-04 10:15:08 -04007810 S;
7811 W;
7812 /* NOTREACHED */
7813 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007814}
7815
Dave Barach72d72232016-08-04 10:15:08 -04007816static int
7817api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007818{
Dave Barach72d72232016-08-04 10:15:08 -04007819 unformat_input_t *i = vam->input;
7820 vl_api_l2_patch_add_del_t *mp;
7821 f64 timeout;
7822 u32 rx_sw_if_index;
7823 u8 rx_sw_if_index_set = 0;
7824 u32 tx_sw_if_index;
7825 u8 tx_sw_if_index_set = 0;
7826 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007827
Dave Barach72d72232016-08-04 10:15:08 -04007828 /* Parse args required to build the message */
7829 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7830 {
7831 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7832 rx_sw_if_index_set = 1;
7833 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7834 tx_sw_if_index_set = 1;
7835 else if (unformat (i, "rx"))
7836 {
7837 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7838 {
7839 if (unformat (i, "%U", unformat_sw_if_index, vam,
7840 &rx_sw_if_index))
7841 rx_sw_if_index_set = 1;
7842 }
7843 else
7844 break;
7845 }
7846 else if (unformat (i, "tx"))
7847 {
7848 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7849 {
7850 if (unformat (i, "%U", unformat_sw_if_index, vam,
7851 &tx_sw_if_index))
7852 tx_sw_if_index_set = 1;
7853 }
7854 else
7855 break;
7856 }
7857 else if (unformat (i, "del"))
7858 is_add = 0;
7859 else
7860 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007861 }
7862
Dave Barach72d72232016-08-04 10:15:08 -04007863 if (rx_sw_if_index_set == 0)
7864 {
7865 errmsg ("missing rx interface name or rx_sw_if_index\n");
7866 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007867 }
7868
Dave Barach72d72232016-08-04 10:15:08 -04007869 if (tx_sw_if_index_set == 0)
7870 {
7871 errmsg ("missing tx interface name or tx_sw_if_index\n");
7872 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007873 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007874
Dave Barach72d72232016-08-04 10:15:08 -04007875 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007876
Dave Barach72d72232016-08-04 10:15:08 -04007877 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7878 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7879 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007880
Dave Barach72d72232016-08-04 10:15:08 -04007881 S;
7882 W;
7883 /* NOTREACHED */
7884 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007885}
Dave Barach72d72232016-08-04 10:15:08 -04007886
7887static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007888api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007889{
Dave Barach72d72232016-08-04 10:15:08 -04007890 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007891 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007892 f64 timeout;
7893 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007894 int has_trace_option = 0;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307895 int has_pot_option = 0;
7896 int has_seqno_option = 0;
7897 int has_analyse_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007898
Shwetha20a64f52016-03-25 10:55:01 +00007899 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7900 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007901 if (unformat (input, "trace"))
7902 has_trace_option = 1;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307903 else if (unformat (input, "pot"))
7904 has_pot_option = 1;
7905 else if (unformat (input, "seqno"))
7906 has_seqno_option = 1;
7907 else if (unformat (input, "analyse"))
7908 has_analyse_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007909 else
Dave Barach72d72232016-08-04 10:15:08 -04007910 break;
Shwetha20a64f52016-03-25 10:55:01 +00007911 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007912 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007913 mp->id = htons (id);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307914 mp->seqno = has_seqno_option;
7915 mp->analyse = has_analyse_option;
7916 mp->pot_enable = has_pot_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007917 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007918
Dave Barach72d72232016-08-04 10:15:08 -04007919 S;
7920 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007921
Dave Barach72d72232016-08-04 10:15:08 -04007922 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007923
Shwetha20a64f52016-03-25 10:55:01 +00007924}
Dave Barach72d72232016-08-04 10:15:08 -04007925
Shwetha20a64f52016-03-25 10:55:01 +00007926
Dave Barach72d72232016-08-04 10:15:08 -04007927static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007928api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007929{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007930 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007931 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007932
Vengada Govindan07d2f842016-08-25 10:34:34 -07007933 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007934 S;
7935 W;
7936 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007937}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007938
Dave Barach72d72232016-08-04 10:15:08 -04007939static int
7940api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007941{
Dave Barach72d72232016-08-04 10:15:08 -04007942 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007943 vl_api_sr_tunnel_add_del_t *mp;
7944 f64 timeout;
7945 int is_del = 0;
7946 int pl_index;
7947 ip6_address_t src_address;
7948 int src_address_set = 0;
7949 ip6_address_t dst_address;
7950 u32 dst_mask_width;
7951 int dst_address_set = 0;
7952 u16 flags = 0;
7953 u32 rx_table_id = 0;
7954 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007955 ip6_address_t *segments = 0;
7956 ip6_address_t *this_seg;
7957 ip6_address_t *tags = 0;
7958 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007959 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007960 u8 *name = 0;
7961 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007962
7963 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7964 {
7965 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007966 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007967 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007968 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007969 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007970 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007971 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007972 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007973 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007974 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007975 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007976 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007977 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007978 unformat_ip6_address, &dst_address, &dst_mask_width))
7979 dst_address_set = 1;
7980 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7981 {
7982 vec_add2 (segments, this_seg, 1);
7983 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7984 sizeof (*this_seg));
7985 }
7986 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7987 {
7988 vec_add2 (tags, this_tag, 1);
7989 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7990 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007991 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007992 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007993 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007994 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007995 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007996 {
7997 if (pl_index <= 0 || pl_index > 4)
7998 {
7999 pl_index_range_error:
8000 errmsg ("pl index %d out of range\n", pl_index);
8001 return -99;
8002 }
8003 flags |=
8004 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
8005 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008006 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008007 {
8008 if (pl_index <= 0 || pl_index > 4)
8009 goto pl_index_range_error;
8010 flags |=
8011 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
8012 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008013 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008014 {
8015 if (pl_index <= 0 || pl_index > 4)
8016 goto pl_index_range_error;
8017 flags |=
8018 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
8019 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008020 else
Dave Barach72d72232016-08-04 10:15:08 -04008021 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008022 }
8023
8024 if (!src_address_set)
8025 {
8026 errmsg ("src address required\n");
8027 return -99;
8028 }
8029
8030 if (!dst_address_set)
8031 {
8032 errmsg ("dst address required\n");
8033 return -99;
8034 }
8035
8036 if (!segments)
8037 {
8038 errmsg ("at least one sr segment required\n");
8039 return -99;
8040 }
8041
Dave Barach72d72232016-08-04 10:15:08 -04008042 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
8043 vec_len (segments) * sizeof (ip6_address_t)
8044 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008045
Damjan Marionf1213b82016-03-13 02:22:06 +01008046 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
8047 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008048 mp->dst_mask_width = dst_mask_width;
8049 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
8050 mp->n_segments = vec_len (segments);
8051 mp->n_tags = vec_len (tags);
8052 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008053 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04008054 vec_len (segments) * sizeof (ip6_address_t));
8055 clib_memcpy (mp->segs_and_tags +
8056 vec_len (segments) * sizeof (ip6_address_t), tags,
8057 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008058
8059 mp->outer_vrf_id = ntohl (rx_table_id);
8060 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04008061 memcpy (mp->name, name, vec_len (name));
8062 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008063
8064 vec_free (segments);
8065 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008066
Dave Barach72d72232016-08-04 10:15:08 -04008067 S;
8068 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008069 /* NOTREACHED */
8070}
8071
Dave Barach72d72232016-08-04 10:15:08 -04008072static int
8073api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008074{
Dave Barach72d72232016-08-04 10:15:08 -04008075 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008076 vl_api_sr_policy_add_del_t *mp;
8077 f64 timeout;
8078 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008079 u8 *name = 0;
8080 u8 *tunnel_name = 0;
8081 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008082
Dave Barach72d72232016-08-04 10:15:08 -04008083 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008084 int tunnel_set = 0;
8085 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008086 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
8087 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 -07008088
8089 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8090 {
8091 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008092 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008093 else if (unformat (input, "name %s", &name))
8094 name_set = 1;
8095 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04008096 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008097 if (tunnel_name)
8098 {
8099 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008100 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04008101 - length = #bytes to store in serial vector
8102 - +1 = byte to store that length
8103 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008104 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008105 tunnel_set = 1;
8106 tunnel_name = 0;
8107 }
Dave Barach72d72232016-08-04 10:15:08 -04008108 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008109 else
Dave Barach72d72232016-08-04 10:15:08 -04008110 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008111 }
8112
8113 if (!name_set)
8114 {
8115 errmsg ("policy name required\n");
8116 return -99;
8117 }
8118
8119 if ((!tunnel_set) && (!is_del))
8120 {
8121 errmsg ("tunnel name required\n");
8122 return -99;
8123 }
8124
Dave Barach72d72232016-08-04 10:15:08 -04008125 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008126
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008127
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008128
8129 mp->is_add = !is_del;
8130
Dave Barach72d72232016-08-04 10:15:08 -04008131 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008132 // 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 -04008133 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008134 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008135 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8136 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008137
Dave Barach72d72232016-08-04 10:15:08 -04008138 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008139 {
8140 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008141 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8142 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008143 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008144 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008145 }
Dave Barach72d72232016-08-04 10:15:08 -04008146 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 -07008147
8148 vec_free (tunnel_names);
8149 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008150
Dave Barach72d72232016-08-04 10:15:08 -04008151 S;
8152 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008153 /* NOTREACHED */
8154}
8155
Dave Barach72d72232016-08-04 10:15:08 -04008156static int
8157api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008158{
Dave Barach72d72232016-08-04 10:15:08 -04008159 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008160 vl_api_sr_multicast_map_add_del_t *mp;
8161 f64 timeout;
8162 int is_del = 0;
8163 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008164 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008165 int multicast_address_set = 0;
8166
8167 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8168 {
8169 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008170 is_del = 1;
8171 else
8172 if (unformat
8173 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008174 multicast_address_set = 1;
8175 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008176 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008177 else
Dave Barach72d72232016-08-04 10:15:08 -04008178 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008179 }
8180
8181 if (!is_del && !policy_name)
8182 {
8183 errmsg ("sr-policy name required\n");
8184 return -99;
8185 }
8186
8187
8188 if (!multicast_address_set)
8189 {
8190 errmsg ("address required\n");
8191 return -99;
8192 }
8193
Dave Barach72d72232016-08-04 10:15:08 -04008194 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008195
8196 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008197 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8198 clib_memcpy (mp->multicast_address, &multicast_address,
8199 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008200
8201
8202 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008203
Dave Barach72d72232016-08-04 10:15:08 -04008204 S;
8205 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008206 /* NOTREACHED */
8207}
8208
Ed Warnickecb9cada2015-12-08 15:45:58 -07008209
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008210#define foreach_tcp_proto_field \
8211_(src_port) \
8212_(dst_port)
8213
8214#define foreach_udp_proto_field \
8215_(src_port) \
8216_(dst_port)
8217
Ed Warnickecb9cada2015-12-08 15:45:58 -07008218#define foreach_ip4_proto_field \
8219_(src_address) \
8220_(dst_address) \
8221_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008222_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008223_(fragment_id) \
8224_(ttl) \
8225_(protocol) \
8226_(checksum)
8227
Dave Barach72d72232016-08-04 10:15:08 -04008228uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008229unformat_tcp_mask (unformat_input_t * input, va_list * args)
8230{
8231 u8 **maskp = va_arg (*args, u8 **);
8232 u8 *mask = 0;
8233 u8 found_something = 0;
8234 tcp_header_t *tcp;
8235
8236#define _(a) u8 a=0;
8237 foreach_tcp_proto_field;
8238#undef _
8239
8240 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8241 {
8242 if (0);
8243#define _(a) else if (unformat (input, #a)) a=1;
8244 foreach_tcp_proto_field
8245#undef _
8246 else
8247 break;
8248 }
8249
8250#define _(a) found_something += a;
8251 foreach_tcp_proto_field;
8252#undef _
8253
8254 if (found_something == 0)
8255 return 0;
8256
8257 vec_validate (mask, sizeof (*tcp) - 1);
8258
8259 tcp = (tcp_header_t *) mask;
8260
8261#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8262 foreach_tcp_proto_field;
8263#undef _
8264
8265 *maskp = mask;
8266 return 1;
8267}
8268
8269uword
8270unformat_udp_mask (unformat_input_t * input, va_list * args)
8271{
8272 u8 **maskp = va_arg (*args, u8 **);
8273 u8 *mask = 0;
8274 u8 found_something = 0;
8275 udp_header_t *udp;
8276
8277#define _(a) u8 a=0;
8278 foreach_udp_proto_field;
8279#undef _
8280
8281 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8282 {
8283 if (0);
8284#define _(a) else if (unformat (input, #a)) a=1;
8285 foreach_udp_proto_field
8286#undef _
8287 else
8288 break;
8289 }
8290
8291#define _(a) found_something += a;
8292 foreach_udp_proto_field;
8293#undef _
8294
8295 if (found_something == 0)
8296 return 0;
8297
8298 vec_validate (mask, sizeof (*udp) - 1);
8299
8300 udp = (udp_header_t *) mask;
8301
8302#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8303 foreach_udp_proto_field;
8304#undef _
8305
8306 *maskp = mask;
8307 return 1;
8308}
8309
8310typedef struct
8311{
8312 u16 src_port, dst_port;
8313} tcpudp_header_t;
8314
8315uword
8316unformat_l4_mask (unformat_input_t * input, va_list * args)
8317{
8318 u8 **maskp = va_arg (*args, u8 **);
8319 u16 src_port = 0, dst_port = 0;
8320 tcpudp_header_t *tcpudp;
8321
8322 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8323 {
8324 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8325 return 1;
8326 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8327 return 1;
8328 else if (unformat (input, "src_port"))
8329 src_port = 0xFFFF;
8330 else if (unformat (input, "dst_port"))
8331 dst_port = 0xFFFF;
8332 else
8333 return 0;
8334 }
8335
8336 if (!src_port && !dst_port)
8337 return 0;
8338
8339 u8 *mask = 0;
8340 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8341
8342 tcpudp = (tcpudp_header_t *) mask;
8343 tcpudp->src_port = src_port;
8344 tcpudp->dst_port = dst_port;
8345
8346 *maskp = mask;
8347
8348 return 1;
8349}
8350
8351uword
Dave Barach72d72232016-08-04 10:15:08 -04008352unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008353{
Dave Barach72d72232016-08-04 10:15:08 -04008354 u8 **maskp = va_arg (*args, u8 **);
8355 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008356 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008357 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008358
Ed Warnickecb9cada2015-12-08 15:45:58 -07008359#define _(a) u8 a=0;
8360 foreach_ip4_proto_field;
8361#undef _
8362 u8 version = 0;
8363 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008364
8365
8366 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008367 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008368 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008369 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008370 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008371 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008372 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008373 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008374 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008375 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008376 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008377 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008378
Ed Warnickecb9cada2015-12-08 15:45:58 -07008379#define _(a) else if (unformat (input, #a)) a=1;
8380 foreach_ip4_proto_field
8381#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008382 else
8383 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008384 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008385
Ed Warnickecb9cada2015-12-08 15:45:58 -07008386#define _(a) found_something += a;
8387 foreach_ip4_proto_field;
8388#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008389
Ed Warnickecb9cada2015-12-08 15:45:58 -07008390 if (found_something == 0)
8391 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008392
Ed Warnickecb9cada2015-12-08 15:45:58 -07008393 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008394
Ed Warnickecb9cada2015-12-08 15:45:58 -07008395 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008396
Ed Warnickecb9cada2015-12-08 15:45:58 -07008397#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8398 foreach_ip4_proto_field;
8399#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008400
Ed Warnickecb9cada2015-12-08 15:45:58 -07008401 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008402
Ed Warnickecb9cada2015-12-08 15:45:58 -07008403 if (version)
8404 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008405
Ed Warnickecb9cada2015-12-08 15:45:58 -07008406 if (hdr_length)
8407 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008408
Ed Warnickecb9cada2015-12-08 15:45:58 -07008409 *maskp = mask;
8410 return 1;
8411}
8412
8413#define foreach_ip6_proto_field \
8414_(src_address) \
8415_(dst_address) \
8416_(payload_length) \
8417_(hop_limit) \
8418_(protocol)
8419
Dave Barach72d72232016-08-04 10:15:08 -04008420uword
8421unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008422{
Dave Barach72d72232016-08-04 10:15:08 -04008423 u8 **maskp = va_arg (*args, u8 **);
8424 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008425 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008426 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008427 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008428
Ed Warnickecb9cada2015-12-08 15:45:58 -07008429#define _(a) u8 a=0;
8430 foreach_ip6_proto_field;
8431#undef _
8432 u8 version = 0;
8433 u8 traffic_class = 0;
8434 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008435
8436 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008437 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008438 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008439 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008440 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008441 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008442 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008443 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008444 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008445 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008446 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008447 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008448 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008449 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008450
Ed Warnickecb9cada2015-12-08 15:45:58 -07008451#define _(a) else if (unformat (input, #a)) a=1;
8452 foreach_ip6_proto_field
8453#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008454 else
8455 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008456 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008457
Ed Warnickecb9cada2015-12-08 15:45:58 -07008458#define _(a) found_something += a;
8459 foreach_ip6_proto_field;
8460#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008461
Ed Warnickecb9cada2015-12-08 15:45:58 -07008462 if (found_something == 0)
8463 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008464
Ed Warnickecb9cada2015-12-08 15:45:58 -07008465 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008466
Ed Warnickecb9cada2015-12-08 15:45:58 -07008467 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008468
Ed Warnickecb9cada2015-12-08 15:45:58 -07008469#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8470 foreach_ip6_proto_field;
8471#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008472
Ed Warnickecb9cada2015-12-08 15:45:58 -07008473 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008474
Ed Warnickecb9cada2015-12-08 15:45:58 -07008475 if (version)
8476 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8477
8478 if (traffic_class)
8479 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8480
8481 if (flow_label)
8482 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8483
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008484 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008485 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008486
Ed Warnickecb9cada2015-12-08 15:45:58 -07008487 *maskp = mask;
8488 return 1;
8489}
8490
Dave Barach72d72232016-08-04 10:15:08 -04008491uword
8492unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008493{
Dave Barach72d72232016-08-04 10:15:08 -04008494 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008495
Dave Barach72d72232016-08-04 10:15:08 -04008496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8497 {
8498 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8499 return 1;
8500 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8501 return 1;
8502 else
8503 break;
8504 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008505 return 0;
8506}
8507
Dave Barach72d72232016-08-04 10:15:08 -04008508uword
8509unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008510{
Dave Barach72d72232016-08-04 10:15:08 -04008511 u8 **maskp = va_arg (*args, u8 **);
8512 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008513 u8 src = 0;
8514 u8 dst = 0;
8515 u8 proto = 0;
8516 u8 tag1 = 0;
8517 u8 tag2 = 0;
8518 u8 ignore_tag1 = 0;
8519 u8 ignore_tag2 = 0;
8520 u8 cos1 = 0;
8521 u8 cos2 = 0;
8522 u8 dot1q = 0;
8523 u8 dot1ad = 0;
8524 int len = 14;
8525
Dave Barach72d72232016-08-04 10:15:08 -04008526 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8527 {
8528 if (unformat (input, "src"))
8529 src = 1;
8530 else if (unformat (input, "dst"))
8531 dst = 1;
8532 else if (unformat (input, "proto"))
8533 proto = 1;
8534 else if (unformat (input, "tag1"))
8535 tag1 = 1;
8536 else if (unformat (input, "tag2"))
8537 tag2 = 1;
8538 else if (unformat (input, "ignore-tag1"))
8539 ignore_tag1 = 1;
8540 else if (unformat (input, "ignore-tag2"))
8541 ignore_tag2 = 1;
8542 else if (unformat (input, "cos1"))
8543 cos1 = 1;
8544 else if (unformat (input, "cos2"))
8545 cos2 = 1;
8546 else if (unformat (input, "dot1q"))
8547 dot1q = 1;
8548 else if (unformat (input, "dot1ad"))
8549 dot1ad = 1;
8550 else
8551 break;
8552 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008553 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008554 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008555 return 0;
8556
8557 if (tag1 || ignore_tag1 || cos1 || dot1q)
8558 len = 18;
8559 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8560 len = 22;
8561
Dave Barach72d72232016-08-04 10:15:08 -04008562 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008563
8564 if (dst)
8565 memset (mask, 0xff, 6);
8566
8567 if (src)
8568 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008569
Ed Warnickecb9cada2015-12-08 15:45:58 -07008570 if (tag2 || dot1ad)
8571 {
8572 /* inner vlan tag */
8573 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008574 {
8575 mask[19] = 0xff;
8576 mask[18] = 0x0f;
8577 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008578 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008579 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008580 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008581 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008582 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008583 {
8584 mask[15] = 0xff;
8585 mask[14] = 0x0f;
8586 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008587 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008588 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008589 *maskp = mask;
8590 return 1;
8591 }
8592 if (tag1 | dot1q)
8593 {
8594 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008595 {
8596 mask[15] = 0xff;
8597 mask[14] = 0x0f;
8598 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008599 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008600 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008601 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008602 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008603
8604 *maskp = mask;
8605 return 1;
8606 }
8607 if (cos2)
8608 mask[18] |= 0xe0;
8609 if (cos1)
8610 mask[14] |= 0xe0;
8611 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008612 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008613
Ed Warnickecb9cada2015-12-08 15:45:58 -07008614 *maskp = mask;
8615 return 1;
8616}
8617
Dave Barach72d72232016-08-04 10:15:08 -04008618uword
8619unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008620{
Dave Barach72d72232016-08-04 10:15:08 -04008621 u8 **maskp = va_arg (*args, u8 **);
8622 u32 *skipp = va_arg (*args, u32 *);
8623 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008624 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008625 u8 *mask = 0;
8626 u8 *l2 = 0;
8627 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008628 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008629 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008630
Dave Barach72d72232016-08-04 10:15:08 -04008631 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8632 {
8633 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8634 ;
8635 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8636 ;
8637 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8638 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008639 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8640 ;
Dave Barach72d72232016-08-04 10:15:08 -04008641 else
8642 break;
8643 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008644
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008645 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008646 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008647 vec_free (mask);
8648 vec_free (l2);
8649 vec_free (l4);
8650 return 0;
8651 }
8652
8653 if (mask || l2 || l3 || l4)
8654 {
8655 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008656 {
8657 /* "With a free Ethernet header in every package" */
8658 if (l2 == 0)
8659 vec_validate (l2, 13);
8660 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008661 if (vec_len (l3))
8662 {
8663 vec_append (mask, l3);
8664 vec_free (l3);
8665 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008666 if (vec_len (l4))
8667 {
8668 vec_append (mask, l4);
8669 vec_free (l4);
8670 }
Dave Barach72d72232016-08-04 10:15:08 -04008671 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008672
8673 /* Scan forward looking for the first significant mask octet */
8674 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008675 if (mask[i])
8676 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008677
8678 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008679 *skipp = i / sizeof (u32x4);
8680 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008681
8682 /* Pad mask to an even multiple of the vector size */
8683 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008684 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008685
8686 match = vec_len (mask) / sizeof (u32x4);
8687
Dave Barach72d72232016-08-04 10:15:08 -04008688 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8689 {
8690 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8691 if (*tmp || *(tmp + 1))
8692 break;
8693 match--;
8694 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008695 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008696 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008697
Dave Barach72d72232016-08-04 10:15:08 -04008698 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008699
8700 *matchp = match;
8701 *maskp = mask;
8702
8703 return 1;
8704 }
8705
8706 return 0;
8707}
8708
8709#define foreach_l2_next \
8710_(drop, DROP) \
8711_(ethernet, ETHERNET_INPUT) \
8712_(ip4, IP4_INPUT) \
8713_(ip6, IP6_INPUT)
8714
Dave Barach72d72232016-08-04 10:15:08 -04008715uword
8716unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008717{
Dave Barach72d72232016-08-04 10:15:08 -04008718 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008719 u32 next_index = 0;
8720 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008721
Ed Warnickecb9cada2015-12-08 15:45:58 -07008722#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008723 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008724 foreach_l2_next;
8725#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008726
Ed Warnickecb9cada2015-12-08 15:45:58 -07008727 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008728 {
8729 next_index = tmp;
8730 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008731 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008732
Ed Warnickecb9cada2015-12-08 15:45:58 -07008733 return 0;
8734
Dave Barach72d72232016-08-04 10:15:08 -04008735out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008736 *miss_next_indexp = next_index;
8737 return 1;
8738}
8739
8740#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008741_(drop, DROP) \
8742_(local, LOCAL) \
8743_(rewrite, REWRITE)
8744
Dave Barach72d72232016-08-04 10:15:08 -04008745uword
8746unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008747{
Dave Barach72d72232016-08-04 10:15:08 -04008748 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008749 u32 next_index = 0;
8750 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008751
Ed Warnickecb9cada2015-12-08 15:45:58 -07008752#define _(n,N) \
8753 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8754 foreach_ip_next;
8755#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008756
Ed Warnickecb9cada2015-12-08 15:45:58 -07008757 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008758 {
8759 next_index = tmp;
8760 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008761 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008762
Ed Warnickecb9cada2015-12-08 15:45:58 -07008763 return 0;
8764
Dave Barach72d72232016-08-04 10:15:08 -04008765out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008766 *miss_next_indexp = next_index;
8767 return 1;
8768}
8769
8770#define foreach_acl_next \
8771_(deny, DENY)
8772
Dave Barach72d72232016-08-04 10:15:08 -04008773uword
8774unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008775{
Dave Barach72d72232016-08-04 10:15:08 -04008776 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008777 u32 next_index = 0;
8778 u32 tmp;
8779
8780#define _(n,N) \
8781 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8782 foreach_acl_next;
8783#undef _
8784
8785 if (unformat (input, "permit"))
8786 {
8787 next_index = ~0;
8788 goto out;
8789 }
8790 else if (unformat (input, "%d", &tmp))
8791 {
8792 next_index = tmp;
8793 goto out;
8794 }
8795
8796 return 0;
8797
Dave Barach72d72232016-08-04 10:15:08 -04008798out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008799 *miss_next_indexp = next_index;
8800 return 1;
8801}
8802
Dave Barach72d72232016-08-04 10:15:08 -04008803uword
8804unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008805{
Dave Barach72d72232016-08-04 10:15:08 -04008806 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008807
8808 if (unformat (input, "conform-color"))
8809 *r = POLICE_CONFORM;
8810 else if (unformat (input, "exceed-color"))
8811 *r = POLICE_EXCEED;
8812 else
8813 return 0;
8814
8815 return 1;
8816}
8817
Dave Barach72d72232016-08-04 10:15:08 -04008818static int
8819api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008820{
Dave Barach72d72232016-08-04 10:15:08 -04008821 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008822 vl_api_classify_add_del_table_t *mp;
8823
8824 u32 nbuckets = 2;
8825 u32 skip = ~0;
8826 u32 match = ~0;
8827 int is_add = 1;
8828 u32 table_index = ~0;
8829 u32 next_table_index = ~0;
8830 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008831 u32 memory_size = 32 << 20;
8832 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008833 f64 timeout;
Steve Shin25e26dc2016-11-08 10:47:10 -08008834 u32 current_data_flag = 0;
8835 int current_data_offset = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008836
Dave Barach72d72232016-08-04 10:15:08 -04008837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8838 {
8839 if (unformat (i, "del"))
8840 is_add = 0;
8841 else if (unformat (i, "buckets %d", &nbuckets))
8842 ;
8843 else if (unformat (i, "memory_size %d", &memory_size))
8844 ;
8845 else if (unformat (i, "skip %d", &skip))
8846 ;
8847 else if (unformat (i, "match %d", &match))
8848 ;
8849 else if (unformat (i, "table %d", &table_index))
8850 ;
8851 else if (unformat (i, "mask %U", unformat_classify_mask,
8852 &mask, &skip, &match))
8853 ;
8854 else if (unformat (i, "next-table %d", &next_table_index))
8855 ;
8856 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8857 &miss_next_index))
8858 ;
8859 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8860 &miss_next_index))
8861 ;
8862 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8863 &miss_next_index))
8864 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08008865 else if (unformat (i, "current-data-flag %d", &current_data_flag))
8866 ;
8867 else if (unformat (i, "current-data-offset %d", &current_data_offset))
8868 ;
Dave Barach72d72232016-08-04 10:15:08 -04008869 else
8870 break;
8871 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008872
Dave Barach72d72232016-08-04 10:15:08 -04008873 if (is_add && mask == 0)
8874 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008875 errmsg ("Mask required\n");
8876 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008877 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008878
Dave Barach72d72232016-08-04 10:15:08 -04008879 if (is_add && skip == ~0)
8880 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008881 errmsg ("skip count required\n");
8882 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008883 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008884
Dave Barach72d72232016-08-04 10:15:08 -04008885 if (is_add && match == ~0)
8886 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008887 errmsg ("match count required\n");
8888 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008889 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008890
Dave Barach72d72232016-08-04 10:15:08 -04008891 if (!is_add && table_index == ~0)
8892 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008893 errmsg ("table index required for delete\n");
8894 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008895 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008896
Dave Barach72d72232016-08-04 10:15:08 -04008897 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008898
8899 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008900 mp->table_index = ntohl (table_index);
8901 mp->nbuckets = ntohl (nbuckets);
8902 mp->memory_size = ntohl (memory_size);
8903 mp->skip_n_vectors = ntohl (skip);
8904 mp->match_n_vectors = ntohl (match);
8905 mp->next_table_index = ntohl (next_table_index);
8906 mp->miss_next_index = ntohl (miss_next_index);
Steve Shin25e26dc2016-11-08 10:47:10 -08008907 mp->current_data_flag = ntohl (current_data_flag);
8908 mp->current_data_offset = ntohl (current_data_offset);
Dave Barach72d72232016-08-04 10:15:08 -04008909 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008910
Dave Barach72d72232016-08-04 10:15:08 -04008911 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008912
Dave Barach72d72232016-08-04 10:15:08 -04008913 S;
8914 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008915 /* NOTREACHED */
8916}
8917
Dave Barach72d72232016-08-04 10:15:08 -04008918uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008919unformat_l4_match (unformat_input_t * input, va_list * args)
8920{
8921 u8 **matchp = va_arg (*args, u8 **);
8922
8923 u8 *proto_header = 0;
8924 int src_port = 0;
8925 int dst_port = 0;
8926
8927 tcpudp_header_t h;
8928
8929 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8930 {
8931 if (unformat (input, "src_port %d", &src_port))
8932 ;
8933 else if (unformat (input, "dst_port %d", &dst_port))
8934 ;
8935 else
8936 return 0;
8937 }
8938
8939 h.src_port = clib_host_to_net_u16 (src_port);
8940 h.dst_port = clib_host_to_net_u16 (dst_port);
8941 vec_validate (proto_header, sizeof (h) - 1);
8942 memcpy (proto_header, &h, sizeof (h));
8943
8944 *matchp = proto_header;
8945
8946 return 1;
8947}
8948
8949uword
Dave Barach72d72232016-08-04 10:15:08 -04008950unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008951{
Dave Barach72d72232016-08-04 10:15:08 -04008952 u8 **matchp = va_arg (*args, u8 **);
8953 u8 *match = 0;
8954 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008955 int version = 0;
8956 u32 version_val;
8957 int hdr_length = 0;
8958 u32 hdr_length_val;
8959 int src = 0, dst = 0;
8960 ip4_address_t src_val, dst_val;
8961 int proto = 0;
8962 u32 proto_val;
8963 int tos = 0;
8964 u32 tos_val;
8965 int length = 0;
8966 u32 length_val;
8967 int fragment_id = 0;
8968 u32 fragment_id_val;
8969 int ttl = 0;
8970 int ttl_val;
8971 int checksum = 0;
8972 u32 checksum_val;
8973
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008974 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008975 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008976 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008977 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008978 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008979 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008980 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008981 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008982 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008983 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008984 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008985 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008986 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008987 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008988 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008989 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008990 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008991 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008992 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008993 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008994 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008995 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008996 else
Dave Barach72d72232016-08-04 10:15:08 -04008997 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008998 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008999
Ed Warnickecb9cada2015-12-08 15:45:58 -07009000 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
9001 + ttl + checksum == 0)
9002 return 0;
9003
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009004 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009005 * Aligned because we use the real comparison functions
9006 */
Dave Barach72d72232016-08-04 10:15:08 -04009007 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009008
Ed Warnickecb9cada2015-12-08 15:45:58 -07009009 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009010
Ed Warnickecb9cada2015-12-08 15:45:58 -07009011 /* These are realistically matched in practice */
9012 if (src)
9013 ip->src_address.as_u32 = src_val.as_u32;
9014
9015 if (dst)
9016 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009017
Ed Warnickecb9cada2015-12-08 15:45:58 -07009018 if (proto)
9019 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009020
Ed Warnickecb9cada2015-12-08 15:45:58 -07009021
9022 /* These are not, but they're included for completeness */
9023 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04009024 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009025
9026 if (hdr_length)
9027 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009028
Ed Warnickecb9cada2015-12-08 15:45:58 -07009029 if (tos)
9030 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009031
Ed Warnickecb9cada2015-12-08 15:45:58 -07009032 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009033 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009034
Ed Warnickecb9cada2015-12-08 15:45:58 -07009035 if (ttl)
9036 ip->ttl = ttl_val;
9037
9038 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009039 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009040
9041 *matchp = match;
9042 return 1;
9043}
9044
Dave Barach72d72232016-08-04 10:15:08 -04009045uword
9046unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009047{
Dave Barach72d72232016-08-04 10:15:08 -04009048 u8 **matchp = va_arg (*args, u8 **);
9049 u8 *match = 0;
9050 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009051 int version = 0;
9052 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04009053 u8 traffic_class = 0;
9054 u32 traffic_class_val = 0;
9055 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009056 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009057 int src = 0, dst = 0;
9058 ip6_address_t src_val, dst_val;
9059 int proto = 0;
9060 u32 proto_val;
9061 int payload_length = 0;
9062 u32 payload_length_val;
9063 int hop_limit = 0;
9064 int hop_limit_val;
9065 u32 ip_version_traffic_class_and_flow_label;
9066
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009067 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009068 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009069 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04009070 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009071 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04009072 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009073 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04009074 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009075 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04009076 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009077 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04009078 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009079 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04009080 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009081 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009082 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009083 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04009084 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009085 else
Dave Barach72d72232016-08-04 10:15:08 -04009086 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009087 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009088
Ed Warnickecb9cada2015-12-08 15:45:58 -07009089 if (version + traffic_class + flow_label + src + dst + proto +
9090 payload_length + hop_limit == 0)
9091 return 0;
9092
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009093 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009094 * Aligned because we use the real comparison functions
9095 */
Dave Barach72d72232016-08-04 10:15:08 -04009096 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009097
Ed Warnickecb9cada2015-12-08 15:45:58 -07009098 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009099
Ed Warnickecb9cada2015-12-08 15:45:58 -07009100 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009101 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009102
9103 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009104 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009105
Ed Warnickecb9cada2015-12-08 15:45:58 -07009106 if (proto)
9107 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009108
Ed Warnickecb9cada2015-12-08 15:45:58 -07009109 ip_version_traffic_class_and_flow_label = 0;
9110
9111 if (version)
9112 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
9113
9114 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04009115 ip_version_traffic_class_and_flow_label |=
9116 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009117
9118 if (flow_label)
9119 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009120
9121 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07009122 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9123
9124 if (payload_length)
9125 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009126
Ed Warnickecb9cada2015-12-08 15:45:58 -07009127 if (hop_limit)
9128 ip->hop_limit = hop_limit_val;
9129
9130 *matchp = match;
9131 return 1;
9132}
9133
Dave Barach72d72232016-08-04 10:15:08 -04009134uword
9135unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009136{
Dave Barach72d72232016-08-04 10:15:08 -04009137 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009138
Dave Barach72d72232016-08-04 10:15:08 -04009139 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9140 {
9141 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9142 return 1;
9143 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9144 return 1;
9145 else
9146 break;
9147 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009148 return 0;
9149}
9150
Dave Barach72d72232016-08-04 10:15:08 -04009151uword
9152unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009153{
Dave Barach72d72232016-08-04 10:15:08 -04009154 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009155 u32 tag;
9156
Dave Barach72d72232016-08-04 10:15:08 -04009157 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009158 {
Dave Barach72d72232016-08-04 10:15:08 -04009159 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160 tagp[1] = tag & 0xFF;
9161 return 1;
9162 }
9163
9164 return 0;
9165}
9166
Dave Barach72d72232016-08-04 10:15:08 -04009167uword
9168unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009169{
Dave Barach72d72232016-08-04 10:15:08 -04009170 u8 **matchp = va_arg (*args, u8 **);
9171 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009172 u8 src = 0;
9173 u8 src_val[6];
9174 u8 dst = 0;
9175 u8 dst_val[6];
9176 u8 proto = 0;
9177 u16 proto_val;
9178 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009179 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009180 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009181 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009182 int len = 14;
9183 u8 ignore_tag1 = 0;
9184 u8 ignore_tag2 = 0;
9185 u8 cos1 = 0;
9186 u8 cos2 = 0;
9187 u32 cos1_val = 0;
9188 u32 cos2_val = 0;
9189
Dave Barach72d72232016-08-04 10:15:08 -04009190 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9191 {
9192 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9193 src = 1;
9194 else
9195 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9196 dst = 1;
9197 else if (unformat (input, "proto %U",
9198 unformat_ethernet_type_host_byte_order, &proto_val))
9199 proto = 1;
9200 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9201 tag1 = 1;
9202 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9203 tag2 = 1;
9204 else if (unformat (input, "ignore-tag1"))
9205 ignore_tag1 = 1;
9206 else if (unformat (input, "ignore-tag2"))
9207 ignore_tag2 = 1;
9208 else if (unformat (input, "cos1 %d", &cos1_val))
9209 cos1 = 1;
9210 else if (unformat (input, "cos2 %d", &cos2_val))
9211 cos2 = 1;
9212 else
9213 break;
9214 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009215 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009216 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009217 return 0;
9218
9219 if (tag1 || ignore_tag1 || cos1)
9220 len = 18;
9221 if (tag2 || ignore_tag2 || cos2)
9222 len = 22;
9223
Dave Barach72d72232016-08-04 10:15:08 -04009224 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009225
9226 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009227 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009228
9229 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009230 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009231
Ed Warnickecb9cada2015-12-08 15:45:58 -07009232 if (tag2)
9233 {
9234 /* inner vlan tag */
9235 match[19] = tag2_val[1];
9236 match[18] = tag2_val[0];
9237 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009238 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009239 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009240 {
9241 match[21] = proto_val & 0xff;
9242 match[20] = proto_val >> 8;
9243 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009244 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009245 {
9246 match[15] = tag1_val[1];
9247 match[14] = tag1_val[0];
9248 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009249 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009250 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009251 *matchp = match;
9252 return 1;
9253 }
9254 if (tag1)
9255 {
Dave Barach72d72232016-08-04 10:15:08 -04009256 match[15] = tag1_val[1];
9257 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009258 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009259 {
9260 match[17] = proto_val & 0xff;
9261 match[16] = proto_val >> 8;
9262 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009263 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009264 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009265
9266 *matchp = match;
9267 return 1;
9268 }
9269 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009270 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009271 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009272 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009273 if (proto)
9274 {
9275 match[13] = proto_val & 0xff;
9276 match[12] = proto_val >> 8;
9277 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009278
Ed Warnickecb9cada2015-12-08 15:45:58 -07009279 *matchp = match;
9280 return 1;
9281}
9282
9283
Dave Barach72d72232016-08-04 10:15:08 -04009284uword
9285unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009286{
Dave Barach72d72232016-08-04 10:15:08 -04009287 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009288 u32 skip_n_vectors = va_arg (*args, u32);
9289 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009290
Dave Barach72d72232016-08-04 10:15:08 -04009291 u8 *match = 0;
9292 u8 *l2 = 0;
9293 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009294 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009295
Dave Barach72d72232016-08-04 10:15:08 -04009296 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9297 {
9298 if (unformat (input, "hex %U", unformat_hex_string, &match))
9299 ;
9300 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9301 ;
9302 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9303 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009304 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9305 ;
Dave Barach72d72232016-08-04 10:15:08 -04009306 else
9307 break;
9308 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009309
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009310 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009311 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009312 vec_free (match);
9313 vec_free (l2);
9314 vec_free (l4);
9315 return 0;
9316 }
9317
9318 if (match || l2 || l3 || l4)
9319 {
9320 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009321 {
9322 /* "Win a free Ethernet header in every packet" */
9323 if (l2 == 0)
9324 vec_validate_aligned (l2, 13, sizeof (u32x4));
9325 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009326 if (vec_len (l3))
9327 {
9328 vec_append_aligned (match, l3, sizeof (u32x4));
9329 vec_free (l3);
9330 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009331 if (vec_len (l4))
9332 {
9333 vec_append_aligned (match, l4, sizeof (u32x4));
9334 vec_free (l4);
9335 }
Dave Barach72d72232016-08-04 10:15:08 -04009336 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009337
9338 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009339 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009340 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9341 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009342
Dave Barach72d72232016-08-04 10:15:08 -04009343 /* Set size, include skipped vectors */
9344 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009345
9346 *matchp = match;
9347
9348 return 1;
9349 }
9350
9351 return 0;
9352}
9353
Dave Barach72d72232016-08-04 10:15:08 -04009354static int
9355api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009356{
Dave Barach72d72232016-08-04 10:15:08 -04009357 unformat_input_t *i = vam->input;
9358 vl_api_classify_add_del_session_t *mp;
9359 int is_add = 1;
9360 u32 table_index = ~0;
9361 u32 hit_next_index = ~0;
9362 u32 opaque_index = ~0;
9363 u8 *match = 0;
9364 i32 advance = 0;
9365 f64 timeout;
9366 u32 skip_n_vectors = 0;
9367 u32 match_n_vectors = 0;
Steve Shin25e26dc2016-11-08 10:47:10 -08009368 u32 action = 0;
9369 u32 metadata = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009370
Dave Barach72d72232016-08-04 10:15:08 -04009371 /*
9372 * Warning: you have to supply skip_n and match_n
9373 * because the API client cant simply look at the classify
9374 * table object.
9375 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009376
Dave Barach72d72232016-08-04 10:15:08 -04009377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9378 {
9379 if (unformat (i, "del"))
9380 is_add = 0;
9381 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9382 &hit_next_index))
9383 ;
9384 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9385 &hit_next_index))
9386 ;
9387 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9388 &hit_next_index))
9389 ;
9390 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9391 ;
9392 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9393 ;
9394 else if (unformat (i, "opaque-index %d", &opaque_index))
9395 ;
9396 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9397 ;
9398 else if (unformat (i, "match_n %d", &match_n_vectors))
9399 ;
9400 else if (unformat (i, "match %U", unformat_classify_match,
9401 &match, skip_n_vectors, match_n_vectors))
9402 ;
9403 else if (unformat (i, "advance %d", &advance))
9404 ;
9405 else if (unformat (i, "table-index %d", &table_index))
9406 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08009407 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
9408 action = 1;
9409 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
9410 action = 2;
9411 else if (unformat (i, "action %d", &action))
9412 ;
9413 else if (unformat (i, "metadata %d", &metadata))
9414 ;
Dave Barach72d72232016-08-04 10:15:08 -04009415 else
9416 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009417 }
9418
Dave Barach72d72232016-08-04 10:15:08 -04009419 if (table_index == ~0)
9420 {
9421 errmsg ("Table index required\n");
9422 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009423 }
9424
Dave Barach72d72232016-08-04 10:15:08 -04009425 if (is_add && match == 0)
9426 {
9427 errmsg ("Match value required\n");
9428 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009429 }
9430
Dave Barach72d72232016-08-04 10:15:08 -04009431 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009432
Dave Barach72d72232016-08-04 10:15:08 -04009433 mp->is_add = is_add;
9434 mp->table_index = ntohl (table_index);
9435 mp->hit_next_index = ntohl (hit_next_index);
9436 mp->opaque_index = ntohl (opaque_index);
9437 mp->advance = ntohl (advance);
Steve Shin25e26dc2016-11-08 10:47:10 -08009438 mp->action = action;
9439 mp->metadata = ntohl (metadata);
Dave Barach72d72232016-08-04 10:15:08 -04009440 clib_memcpy (mp->match, match, vec_len (match));
9441 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009442
Dave Barach72d72232016-08-04 10:15:08 -04009443 S;
9444 W;
9445 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009446}
9447
Dave Barach72d72232016-08-04 10:15:08 -04009448static int
9449api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009450{
Dave Barach72d72232016-08-04 10:15:08 -04009451 unformat_input_t *i = vam->input;
9452 vl_api_classify_set_interface_ip_table_t *mp;
9453 f64 timeout;
9454 u32 sw_if_index;
9455 int sw_if_index_set;
9456 u32 table_index = ~0;
9457 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009458
Dave Barach72d72232016-08-04 10:15:08 -04009459 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9460 {
9461 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9462 sw_if_index_set = 1;
9463 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9464 sw_if_index_set = 1;
9465 else if (unformat (i, "table %d", &table_index))
9466 ;
9467 else
9468 {
9469 clib_warning ("parse error '%U'", format_unformat_error, i);
9470 return -99;
9471 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009472 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009473
Dave Barach72d72232016-08-04 10:15:08 -04009474 if (sw_if_index_set == 0)
9475 {
9476 errmsg ("missing interface name or sw_if_index\n");
9477 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009478 }
9479
9480
Dave Barach72d72232016-08-04 10:15:08 -04009481 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009482
Dave Barach72d72232016-08-04 10:15:08 -04009483 mp->sw_if_index = ntohl (sw_if_index);
9484 mp->table_index = ntohl (table_index);
9485 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009486
Dave Barach72d72232016-08-04 10:15:08 -04009487 S;
9488 W;
9489 /* NOTREACHED */
9490 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009491}
9492
Dave Barach72d72232016-08-04 10:15:08 -04009493static int
9494api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009495{
Dave Barach72d72232016-08-04 10:15:08 -04009496 unformat_input_t *i = vam->input;
9497 vl_api_classify_set_interface_l2_tables_t *mp;
9498 f64 timeout;
9499 u32 sw_if_index;
9500 int sw_if_index_set;
9501 u32 ip4_table_index = ~0;
9502 u32 ip6_table_index = ~0;
9503 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009504 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009505
Dave Barach72d72232016-08-04 10:15:08 -04009506 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9507 {
9508 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9509 sw_if_index_set = 1;
9510 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9511 sw_if_index_set = 1;
9512 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9513 ;
9514 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9515 ;
9516 else if (unformat (i, "other-table %d", &other_table_index))
9517 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009518 else if (unformat (i, "is-input %d", &is_input))
9519 ;
Dave Barach72d72232016-08-04 10:15:08 -04009520 else
9521 {
9522 clib_warning ("parse error '%U'", format_unformat_error, i);
9523 return -99;
9524 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009525 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009526
Dave Barach72d72232016-08-04 10:15:08 -04009527 if (sw_if_index_set == 0)
9528 {
9529 errmsg ("missing interface name or sw_if_index\n");
9530 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009531 }
9532
9533
Dave Barach72d72232016-08-04 10:15:08 -04009534 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009535
Dave Barach72d72232016-08-04 10:15:08 -04009536 mp->sw_if_index = ntohl (sw_if_index);
9537 mp->ip4_table_index = ntohl (ip4_table_index);
9538 mp->ip6_table_index = ntohl (ip6_table_index);
9539 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009540 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009541
Dave Barach72d72232016-08-04 10:15:08 -04009542 S;
9543 W;
9544 /* NOTREACHED */
9545 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009546}
9547
Dave Barach72d72232016-08-04 10:15:08 -04009548static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009549api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009550{
Dave Barach72d72232016-08-04 10:15:08 -04009551 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009552 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009553 ip4_address_t collector_address;
9554 u8 collector_address_set = 0;
9555 u32 collector_port = ~0;
9556 ip4_address_t src_address;
9557 u8 src_address_set = 0;
9558 u32 vrf_id = ~0;
9559 u32 path_mtu = ~0;
9560 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009561 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009562 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009563
Dave Barach72d72232016-08-04 10:15:08 -04009564 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9565 {
9566 if (unformat (i, "collector_address %U", unformat_ip4_address,
9567 &collector_address))
9568 collector_address_set = 1;
9569 else if (unformat (i, "collector_port %d", &collector_port))
9570 ;
9571 else if (unformat (i, "src_address %U", unformat_ip4_address,
9572 &src_address))
9573 src_address_set = 1;
9574 else if (unformat (i, "vrf_id %d", &vrf_id))
9575 ;
9576 else if (unformat (i, "path_mtu %d", &path_mtu))
9577 ;
9578 else if (unformat (i, "template_interval %d", &template_interval))
9579 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009580 else if (unformat (i, "udp_checksum"))
9581 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009582 else
9583 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009584 }
9585
Dave Barach72d72232016-08-04 10:15:08 -04009586 if (collector_address_set == 0)
9587 {
9588 errmsg ("collector_address required\n");
9589 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009590 }
9591
Dave Barach72d72232016-08-04 10:15:08 -04009592 if (src_address_set == 0)
9593 {
9594 errmsg ("src_address required\n");
9595 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009596 }
9597
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009598 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009599
Dave Barach72d72232016-08-04 10:15:08 -04009600 memcpy (mp->collector_address, collector_address.data,
9601 sizeof (collector_address.data));
9602 mp->collector_port = htons ((u16) collector_port);
9603 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9604 mp->vrf_id = htonl (vrf_id);
9605 mp->path_mtu = htonl (path_mtu);
9606 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009607 mp->udp_checksum = udp_checksum;
9608
9609 S;
9610 W;
9611 /* NOTREACHED */
9612}
9613
9614static int
9615api_set_ipfix_classify_stream (vat_main_t * vam)
9616{
9617 unformat_input_t *i = vam->input;
9618 vl_api_set_ipfix_classify_stream_t *mp;
9619 u32 domain_id = 0;
9620 u32 src_port = UDP_DST_PORT_ipfix;
9621 f64 timeout;
9622
9623 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9624 {
9625 if (unformat (i, "domain %d", &domain_id))
9626 ;
9627 else if (unformat (i, "src_port %d", &src_port))
9628 ;
9629 else
9630 {
9631 errmsg ("unknown input `%U'", format_unformat_error, i);
9632 return -99;
9633 }
9634 }
9635
9636 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9637
9638 mp->domain_id = htonl (domain_id);
9639 mp->src_port = htons ((u16) src_port);
9640
9641 S;
9642 W;
9643 /* NOTREACHED */
9644}
9645
9646static int
9647api_ipfix_classify_table_add_del (vat_main_t * vam)
9648{
9649 unformat_input_t *i = vam->input;
9650 vl_api_ipfix_classify_table_add_del_t *mp;
9651 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009652 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009653 u8 ip_version = 0;
9654 u8 transport_protocol = 255;
9655 f64 timeout;
9656
9657 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9658 {
9659 if (unformat (i, "add"))
9660 is_add = 1;
9661 else if (unformat (i, "del"))
9662 is_add = 0;
9663 else if (unformat (i, "table %d", &classify_table_index))
9664 ;
9665 else if (unformat (i, "ip4"))
9666 ip_version = 4;
9667 else if (unformat (i, "ip6"))
9668 ip_version = 6;
9669 else if (unformat (i, "tcp"))
9670 transport_protocol = 6;
9671 else if (unformat (i, "udp"))
9672 transport_protocol = 17;
9673 else
9674 {
9675 errmsg ("unknown input `%U'", format_unformat_error, i);
9676 return -99;
9677 }
9678 }
9679
9680 if (is_add == -1)
9681 {
9682 errmsg ("expecting: add|del");
9683 return -99;
9684 }
9685 if (classify_table_index == ~0)
9686 {
9687 errmsg ("classifier table not specified");
9688 return -99;
9689 }
9690 if (ip_version == 0)
9691 {
9692 errmsg ("IP version not specified");
9693 return -99;
9694 }
9695
9696 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9697
9698 mp->is_add = is_add;
9699 mp->table_id = htonl (classify_table_index);
9700 mp->ip_version = ip_version;
9701 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009702
Dave Barach72d72232016-08-04 10:15:08 -04009703 S;
9704 W;
9705 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009706}
9707
Dave Barach72d72232016-08-04 10:15:08 -04009708static int
9709api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009710{
Dave Barach72d72232016-08-04 10:15:08 -04009711 unformat_input_t *i = vam->input;
9712 vl_api_get_node_index_t *mp;
9713 f64 timeout;
9714 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009715
Dave Barach72d72232016-08-04 10:15:08 -04009716 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9717 {
9718 if (unformat (i, "node %s", &name))
9719 ;
9720 else
9721 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009722 }
Dave Barach72d72232016-08-04 10:15:08 -04009723 if (name == 0)
9724 {
9725 errmsg ("node name required\n");
9726 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009727 }
Dave Barach72d72232016-08-04 10:15:08 -04009728 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9729 {
9730 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9731 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009732 }
9733
Dave Barach72d72232016-08-04 10:15:08 -04009734 M (GET_NODE_INDEX, get_node_index);
9735 clib_memcpy (mp->node_name, name, vec_len (name));
9736 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009737
Dave Barach72d72232016-08-04 10:15:08 -04009738 S;
9739 W;
9740 /* NOTREACHED */
9741 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009742}
9743
Dave Barach72d72232016-08-04 10:15:08 -04009744static int
9745api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009746{
Dave Barach72d72232016-08-04 10:15:08 -04009747 unformat_input_t *i = vam->input;
9748 vl_api_get_next_index_t *mp;
9749 f64 timeout;
9750 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009751
Dave Barach72d72232016-08-04 10:15:08 -04009752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9753 {
9754 if (unformat (i, "node-name %s", &node_name))
9755 ;
9756 else if (unformat (i, "next-node-name %s", &next_node_name))
9757 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009758 }
9759
Dave Barach72d72232016-08-04 10:15:08 -04009760 if (node_name == 0)
9761 {
9762 errmsg ("node name required\n");
9763 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009764 }
Dave Barach72d72232016-08-04 10:15:08 -04009765 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9766 {
9767 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9768 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009769 }
9770
Dave Barach72d72232016-08-04 10:15:08 -04009771 if (next_node_name == 0)
9772 {
9773 errmsg ("next node name required\n");
9774 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009775 }
Dave Barach72d72232016-08-04 10:15:08 -04009776 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9777 {
9778 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9779 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009780 }
9781
Dave Barach72d72232016-08-04 10:15:08 -04009782 M (GET_NEXT_INDEX, get_next_index);
9783 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9784 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9785 vec_free (node_name);
9786 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009787
Dave Barach72d72232016-08-04 10:15:08 -04009788 S;
9789 W;
9790 /* NOTREACHED */
9791 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009792}
9793
Dave Barach72d72232016-08-04 10:15:08 -04009794static int
9795api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009796{
Dave Barach72d72232016-08-04 10:15:08 -04009797 unformat_input_t *i = vam->input;
9798 vl_api_add_node_next_t *mp;
9799 f64 timeout;
9800 u8 *name = 0;
9801 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009802
Dave Barach72d72232016-08-04 10:15:08 -04009803 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9804 {
9805 if (unformat (i, "node %s", &name))
9806 ;
9807 else if (unformat (i, "next %s", &next))
9808 ;
9809 else
9810 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009811 }
Dave Barach72d72232016-08-04 10:15:08 -04009812 if (name == 0)
9813 {
9814 errmsg ("node name required\n");
9815 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009816 }
Dave Barach72d72232016-08-04 10:15:08 -04009817 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9818 {
9819 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9820 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009821 }
Dave Barach72d72232016-08-04 10:15:08 -04009822 if (next == 0)
9823 {
9824 errmsg ("next node required\n");
9825 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009826 }
Dave Barach72d72232016-08-04 10:15:08 -04009827 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9828 {
9829 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9830 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009831 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009832
Dave Barach72d72232016-08-04 10:15:08 -04009833 M (ADD_NODE_NEXT, add_node_next);
9834 clib_memcpy (mp->node_name, name, vec_len (name));
9835 clib_memcpy (mp->next_name, next, vec_len (next));
9836 vec_free (name);
9837 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009838
Dave Barach72d72232016-08-04 10:15:08 -04009839 S;
9840 W;
9841 /* NOTREACHED */
9842 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009843}
9844
Dave Barach72d72232016-08-04 10:15:08 -04009845static int
9846api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009847{
Dave Barach72d72232016-08-04 10:15:08 -04009848 unformat_input_t *i = vam->input;
9849 ip6_address_t client_address, our_address;
9850 int client_address_set = 0;
9851 int our_address_set = 0;
9852 u32 local_session_id = 0;
9853 u32 remote_session_id = 0;
9854 u64 local_cookie = 0;
9855 u64 remote_cookie = 0;
9856 u8 l2_sublayer_present = 0;
9857 vl_api_l2tpv3_create_tunnel_t *mp;
9858 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009859
Dave Barach72d72232016-08-04 10:15:08 -04009860 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9861 {
9862 if (unformat (i, "client_address %U", unformat_ip6_address,
9863 &client_address))
9864 client_address_set = 1;
9865 else if (unformat (i, "our_address %U", unformat_ip6_address,
9866 &our_address))
9867 our_address_set = 1;
9868 else if (unformat (i, "local_session_id %d", &local_session_id))
9869 ;
9870 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9871 ;
9872 else if (unformat (i, "local_cookie %lld", &local_cookie))
9873 ;
9874 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9875 ;
9876 else if (unformat (i, "l2-sublayer-present"))
9877 l2_sublayer_present = 1;
9878 else
9879 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009880 }
9881
Dave Barach72d72232016-08-04 10:15:08 -04009882 if (client_address_set == 0)
9883 {
9884 errmsg ("client_address required\n");
9885 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009886 }
9887
Dave Barach72d72232016-08-04 10:15:08 -04009888 if (our_address_set == 0)
9889 {
9890 errmsg ("our_address required\n");
9891 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009892 }
9893
Dave Barach72d72232016-08-04 10:15:08 -04009894 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009895
Dave Barach72d72232016-08-04 10:15:08 -04009896 clib_memcpy (mp->client_address, client_address.as_u8,
9897 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009898
Dave Barach72d72232016-08-04 10:15:08 -04009899 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009900
Dave Barach72d72232016-08-04 10:15:08 -04009901 mp->local_session_id = ntohl (local_session_id);
9902 mp->remote_session_id = ntohl (remote_session_id);
9903 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9904 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9905 mp->l2_sublayer_present = l2_sublayer_present;
9906 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009907
Dave Barach72d72232016-08-04 10:15:08 -04009908 S;
9909 W;
9910 /* NOTREACHED */
9911 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009912}
9913
Dave Barach72d72232016-08-04 10:15:08 -04009914static int
9915api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009916{
Dave Barach72d72232016-08-04 10:15:08 -04009917 unformat_input_t *i = vam->input;
9918 u32 sw_if_index;
9919 u8 sw_if_index_set = 0;
9920 u64 new_local_cookie = 0;
9921 u64 new_remote_cookie = 0;
9922 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9923 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009924
Dave Barach72d72232016-08-04 10:15:08 -04009925 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9926 {
9927 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9928 sw_if_index_set = 1;
9929 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9930 sw_if_index_set = 1;
9931 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9932 ;
9933 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9934 ;
9935 else
9936 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009937 }
9938
Dave Barach72d72232016-08-04 10:15:08 -04009939 if (sw_if_index_set == 0)
9940 {
9941 errmsg ("missing interface name or sw_if_index\n");
9942 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009943 }
9944
Dave Barach72d72232016-08-04 10:15:08 -04009945 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009946
Dave Barach72d72232016-08-04 10:15:08 -04009947 mp->sw_if_index = ntohl (sw_if_index);
9948 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9949 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009950
Dave Barach72d72232016-08-04 10:15:08 -04009951 S;
9952 W;
9953 /* NOTREACHED */
9954 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009955}
9956
Dave Barach72d72232016-08-04 10:15:08 -04009957static int
9958api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009959{
Dave Barach72d72232016-08-04 10:15:08 -04009960 unformat_input_t *i = vam->input;
9961 vl_api_l2tpv3_interface_enable_disable_t *mp;
9962 f64 timeout;
9963 u32 sw_if_index;
9964 u8 sw_if_index_set = 0;
9965 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009966
Dave Barach72d72232016-08-04 10:15:08 -04009967 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9968 {
9969 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9970 sw_if_index_set = 1;
9971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9972 sw_if_index_set = 1;
9973 else if (unformat (i, "enable"))
9974 enable_disable = 1;
9975 else if (unformat (i, "disable"))
9976 enable_disable = 0;
9977 else
9978 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009979 }
9980
Dave Barach72d72232016-08-04 10:15:08 -04009981 if (sw_if_index_set == 0)
9982 {
9983 errmsg ("missing interface name or sw_if_index\n");
9984 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009985 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009986
Dave Barach72d72232016-08-04 10:15:08 -04009987 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009988
Dave Barach72d72232016-08-04 10:15:08 -04009989 mp->sw_if_index = ntohl (sw_if_index);
9990 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009991
Dave Barach72d72232016-08-04 10:15:08 -04009992 S;
9993 W;
9994 /* NOTREACHED */
9995 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009996}
9997
Dave Barach72d72232016-08-04 10:15:08 -04009998static int
9999api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010000{
Dave Barach72d72232016-08-04 10:15:08 -040010001 unformat_input_t *i = vam->input;
10002 vl_api_l2tpv3_set_lookup_key_t *mp;
10003 f64 timeout;
10004 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010005
Dave Barach72d72232016-08-04 10:15:08 -040010006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10007 {
10008 if (unformat (i, "lookup_v6_src"))
10009 key = L2T_LOOKUP_SRC_ADDRESS;
10010 else if (unformat (i, "lookup_v6_dst"))
10011 key = L2T_LOOKUP_DST_ADDRESS;
10012 else if (unformat (i, "lookup_session_id"))
10013 key = L2T_LOOKUP_SESSION_ID;
10014 else
10015 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010016 }
10017
Dave Barach72d72232016-08-04 10:15:08 -040010018 if (key == (u8) ~ 0)
10019 {
10020 errmsg ("l2tp session lookup key unset\n");
10021 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010022 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010023
Dave Barach72d72232016-08-04 10:15:08 -040010024 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010025
Dave Barach72d72232016-08-04 10:15:08 -040010026 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010027
Dave Barach72d72232016-08-04 10:15:08 -040010028 S;
10029 W;
10030 /* NOTREACHED */
10031 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010032}
10033
10034static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010035 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010036{
Dave Barach72d72232016-08-04 10:15:08 -040010037 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010038
Dave Barach72d72232016-08-04 10:15:08 -040010039 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
10040 format_ip6_address, mp->our_address,
10041 format_ip6_address, mp->client_address,
10042 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010043
Dave Barach72d72232016-08-04 10:15:08 -040010044 fformat (vam->ofp,
10045 " local cookies %016llx %016llx remote cookie %016llx\n",
10046 clib_net_to_host_u64 (mp->local_cookie[0]),
10047 clib_net_to_host_u64 (mp->local_cookie[1]),
10048 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010049
Dave Barach72d72232016-08-04 10:15:08 -040010050 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
10051 clib_net_to_host_u32 (mp->local_session_id),
10052 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010053
Dave Barach72d72232016-08-04 10:15:08 -040010054 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
10055 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010056
10057}
10058
10059static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010060 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010061{
Dave Barach72d72232016-08-04 10:15:08 -040010062 vat_main_t *vam = &vat_main;
10063 vat_json_node_t *node = NULL;
10064 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010065
Dave Barach72d72232016-08-04 10:15:08 -040010066 if (VAT_JSON_ARRAY != vam->json_tree.type)
10067 {
10068 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10069 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010070 }
Dave Barach72d72232016-08-04 10:15:08 -040010071 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010072
Dave Barach72d72232016-08-04 10:15:08 -040010073 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010074
Dave Barach72d72232016-08-04 10:15:08 -040010075 clib_memcpy (&addr, mp->our_address, sizeof (addr));
10076 vat_json_object_add_ip6 (node, "our_address", addr);
10077 clib_memcpy (&addr, mp->client_address, sizeof (addr));
10078 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010079
Dave Barach72d72232016-08-04 10:15:08 -040010080 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
10081 vat_json_init_array (lc);
10082 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
10083 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
10084 vat_json_object_add_uint (node, "remote_cookie",
10085 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010086
Dave Barach72d72232016-08-04 10:15:08 -040010087 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
10088 vat_json_object_add_uint (node, "local_session_id",
10089 clib_net_to_host_u32 (mp->local_session_id));
10090 vat_json_object_add_uint (node, "remote_session_id",
10091 clib_net_to_host_u32 (mp->remote_session_id));
10092 vat_json_object_add_string_copy (node, "l2_sublayer",
10093 mp->l2_sublayer_present ? (u8 *) "present"
10094 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010095}
10096
Dave Barach72d72232016-08-04 10:15:08 -040010097static int
10098api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010099{
Dave Barach72d72232016-08-04 10:15:08 -040010100 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
10101 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010102
Dave Barach72d72232016-08-04 10:15:08 -040010103 /* Get list of l2tpv3-tunnel interfaces */
10104 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
10105 S;
10106
10107 /* Use a control ping for synchronization */
10108 {
10109 vl_api_control_ping_t *mp;
10110 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010111 S;
Dave Barach72d72232016-08-04 10:15:08 -040010112 }
10113 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010114}
10115
10116
10117static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010118 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010119{
Dave Barach72d72232016-08-04 10:15:08 -040010120 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010121
Dave Barach72d72232016-08-04 10:15:08 -040010122 fformat (vam->ofp, "%-16s %d\n",
10123 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010124}
10125
10126static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010127 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010128{
Dave Barach72d72232016-08-04 10:15:08 -040010129 vat_main_t *vam = &vat_main;
10130 vat_json_node_t *node = NULL;
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);
10140 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10141 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010142}
10143
Dave Barach72d72232016-08-04 10:15:08 -040010144static int
10145api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010146{
Dave Barach72d72232016-08-04 10:15:08 -040010147 vl_api_sw_interface_tap_dump_t *mp;
10148 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010149
Dave Barach72d72232016-08-04 10:15:08 -040010150 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10151 /* Get list of tap interfaces */
10152 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10153 S;
10154
10155 /* Use a control ping for synchronization */
10156 {
10157 vl_api_control_ping_t *mp;
10158 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010159 S;
Dave Barach72d72232016-08-04 10:15:08 -040010160 }
10161 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010162}
10163
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010164static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010165 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010166{
Dave Barach72d72232016-08-04 10:15:08 -040010167 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010169
John Loc42912d2016-11-07 18:30:47 -050010170 if (unformat (input, "l2"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070010171 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10172 else if (unformat (input, "%d", &tmp))
10173 *result = tmp;
10174 else
10175 return 0;
10176 return 1;
10177}
10178
Dave Barach72d72232016-08-04 10:15:08 -040010179static int
10180api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010181{
Dave Barach72d72232016-08-04 10:15:08 -040010182 unformat_input_t *line_input = vam->input;
10183 vl_api_vxlan_add_del_tunnel_t *mp;
10184 f64 timeout;
Eyal Baric5b13602016-11-24 19:42:43 +020010185 ip46_address_t src, dst;
Dave Barach72d72232016-08-04 10:15:08 -040010186 u8 is_add = 1;
10187 u8 ipv4_set = 0, ipv6_set = 0;
10188 u8 src_set = 0;
10189 u8 dst_set = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010190 u8 grp_set = 0;
10191 u32 mcast_sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040010192 u32 encap_vrf_id = 0;
10193 u32 decap_next_index = ~0;
10194 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010195
Eyal Baric5b13602016-11-24 19:42:43 +020010196 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
10197 memset (&src, 0, sizeof src);
10198 memset (&dst, 0, sizeof dst);
10199
Dave Barach72d72232016-08-04 10:15:08 -040010200 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10201 {
10202 if (unformat (line_input, "del"))
10203 is_add = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010204 else
10205 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010206 {
10207 ipv4_set = 1;
10208 src_set = 1;
10209 }
Eyal Baric5b13602016-11-24 19:42:43 +020010210 else
10211 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010212 {
10213 ipv4_set = 1;
10214 dst_set = 1;
10215 }
Eyal Baric5b13602016-11-24 19:42:43 +020010216 else
10217 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010218 {
10219 ipv6_set = 1;
10220 src_set = 1;
10221 }
Eyal Baric5b13602016-11-24 19:42:43 +020010222 else
10223 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010224 {
10225 ipv6_set = 1;
10226 dst_set = 1;
10227 }
Eyal Baric5b13602016-11-24 19:42:43 +020010228 else if (unformat (line_input, "group %U %U",
10229 unformat_ip4_address, &dst.ip4,
10230 unformat_sw_if_index, vam, &mcast_sw_if_index))
10231 {
10232 grp_set = dst_set = 1;
10233 ipv4_set = 1;
10234 }
10235 else if (unformat (line_input, "group %U",
10236 unformat_ip4_address, &dst.ip4))
10237 {
10238 grp_set = dst_set = 1;
10239 ipv4_set = 1;
10240 }
10241 else if (unformat (line_input, "group %U %U",
10242 unformat_ip6_address, &dst.ip6,
10243 unformat_sw_if_index, vam, &mcast_sw_if_index))
10244 {
10245 grp_set = dst_set = 1;
10246 ipv6_set = 1;
10247 }
10248 else if (unformat (line_input, "group %U",
10249 unformat_ip6_address, &dst.ip6))
10250 {
10251 grp_set = dst_set = 1;
10252 ipv6_set = 1;
10253 }
10254 else
10255 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10256 ;
Dave Barach72d72232016-08-04 10:15:08 -040010257 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10258 ;
10259 else if (unformat (line_input, "decap-next %U",
10260 unformat_vxlan_decap_next, &decap_next_index))
10261 ;
10262 else if (unformat (line_input, "vni %d", &vni))
10263 ;
10264 else
10265 {
10266 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10267 return -99;
10268 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010269 }
10270
Dave Barach72d72232016-08-04 10:15:08 -040010271 if (src_set == 0)
10272 {
10273 errmsg ("tunnel src address not specified\n");
10274 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010275 }
Dave Barach72d72232016-08-04 10:15:08 -040010276 if (dst_set == 0)
10277 {
10278 errmsg ("tunnel dst address not specified\n");
10279 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010280 }
10281
Eyal Baric5b13602016-11-24 19:42:43 +020010282 if (grp_set && !ip46_address_is_multicast (&dst))
10283 {
10284 errmsg ("tunnel group address not multicast\n");
10285 return -99;
10286 }
10287 if (grp_set && mcast_sw_if_index == ~0)
10288 {
10289 errmsg ("tunnel nonexistent multicast device\n");
10290 return -99;
10291 }
10292
10293
Dave Barach72d72232016-08-04 10:15:08 -040010294 if (ipv4_set && ipv6_set)
10295 {
10296 errmsg ("both IPv4 and IPv6 addresses specified");
10297 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010298 }
10299
Dave Barach72d72232016-08-04 10:15:08 -040010300 if ((vni == 0) || (vni >> 24))
10301 {
10302 errmsg ("vni not specified or out of range\n");
10303 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010304 }
10305
Dave Barach72d72232016-08-04 10:15:08 -040010306 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010307
Dave Barach72d72232016-08-04 10:15:08 -040010308 if (ipv6_set)
10309 {
Eyal Baric5b13602016-11-24 19:42:43 +020010310 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
10311 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
Chris Luke99cb3352016-04-26 10:49:53 -040010312 }
Dave Barach72d72232016-08-04 10:15:08 -040010313 else
10314 {
Eyal Baric5b13602016-11-24 19:42:43 +020010315 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
10316 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010317 }
10318 mp->encap_vrf_id = ntohl (encap_vrf_id);
10319 mp->decap_next_index = ntohl (decap_next_index);
Eyal Baric5b13602016-11-24 19:42:43 +020010320 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Dave Barach72d72232016-08-04 10:15:08 -040010321 mp->vni = ntohl (vni);
10322 mp->is_add = is_add;
10323 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010324
Dave Barach72d72232016-08-04 10:15:08 -040010325 S;
10326 W;
10327 /* NOTREACHED */
10328 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010329}
10330
Dave Wallace60231f32015-12-17 21:04:30 -050010331static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010332 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010333{
Dave Barach72d72232016-08-04 10:15:08 -040010334 vat_main_t *vam = &vat_main;
Eyal Baric5b13602016-11-24 19:42:43 +020010335 ip46_address_t src, dst;
Dave Wallace60231f32015-12-17 21:04:30 -050010336
Eyal Baric5b13602016-11-24 19:42:43 +020010337 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src);
10338 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst);
10339
10340 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010341 ntohl (mp->sw_if_index),
Eyal Baric5b13602016-11-24 19:42:43 +020010342 format_ip46_address, &src, IP46_TYPE_ANY,
10343 format_ip46_address, &dst, IP46_TYPE_ANY,
Dave Barach72d72232016-08-04 10:15:08 -040010344 ntohl (mp->encap_vrf_id),
Eyal Baric5b13602016-11-24 19:42:43 +020010345 ntohl (mp->decap_next_index), ntohl (mp->vni),
10346 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010347}
10348
10349static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010350 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010351{
Dave Barach72d72232016-08-04 10:15:08 -040010352 vat_main_t *vam = &vat_main;
10353 vat_json_node_t *node = NULL;
Dave Wallace60231f32015-12-17 21:04:30 -050010354
Dave Barach72d72232016-08-04 10:15:08 -040010355 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010356 {
Dave Barach72d72232016-08-04 10:15:08 -040010357 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10358 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010359 }
Dave Barach72d72232016-08-04 10:15:08 -040010360 node = vat_json_array_add (&vam->json_tree);
10361
10362 vat_json_init_object (node);
10363 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10364 if (mp->is_ipv6)
10365 {
Eyal Baric5b13602016-11-24 19:42:43 +020010366 struct in6_addr ip6;
10367
10368 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010369 vat_json_object_add_ip6 (node, "src_address", ip6);
Eyal Baric5b13602016-11-24 19:42:43 +020010370 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010371 vat_json_object_add_ip6 (node, "dst_address", ip6);
10372 }
10373 else
10374 {
Eyal Baric5b13602016-11-24 19:42:43 +020010375 struct in_addr ip4;
10376
10377 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010378 vat_json_object_add_ip4 (node, "src_address", ip4);
Eyal Baric5b13602016-11-24 19:42:43 +020010379 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010380 vat_json_object_add_ip4 (node, "dst_address", ip4);
10381 }
10382 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10383 vat_json_object_add_uint (node, "decap_next_index",
10384 ntohl (mp->decap_next_index));
10385 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10386 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Eyal Baric5b13602016-11-24 19:42:43 +020010387 vat_json_object_add_uint (node, "mcast_sw_if_index",
10388 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010389}
10390
Dave Barach72d72232016-08-04 10:15:08 -040010391static int
10392api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010393{
Dave Barach72d72232016-08-04 10:15:08 -040010394 unformat_input_t *i = vam->input;
10395 vl_api_vxlan_tunnel_dump_t *mp;
10396 f64 timeout;
10397 u32 sw_if_index;
10398 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010399
Dave Barach72d72232016-08-04 10:15:08 -040010400 /* Parse args required to build the message */
10401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10402 {
10403 if (unformat (i, "sw_if_index %d", &sw_if_index))
10404 sw_if_index_set = 1;
10405 else
10406 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010407 }
10408
Dave Barach72d72232016-08-04 10:15:08 -040010409 if (sw_if_index_set == 0)
10410 {
10411 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010412 }
Dave Barach72d72232016-08-04 10:15:08 -040010413
10414 if (!vam->json_output)
10415 {
Eyal Baric5b13602016-11-24 19:42:43 +020010416 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s\n",
Dave Barach72d72232016-08-04 10:15:08 -040010417 "sw_if_index", "src_address", "dst_address",
Eyal Baric5b13602016-11-24 19:42:43 +020010418 "encap_vrf_id", "decap_next_index", "vni",
10419 "mcast_sw_if_index");
Dave Barach72d72232016-08-04 10:15:08 -040010420 }
10421
10422 /* Get list of vxlan-tunnel interfaces */
10423 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10424
10425 mp->sw_if_index = htonl (sw_if_index);
10426
10427 S;
10428
10429 /* Use a control ping for synchronization */
10430 {
10431 vl_api_control_ping_t *mp;
10432 M (CONTROL_PING, control_ping);
10433 S;
10434 }
10435 W;
10436}
10437
10438static int
10439api_gre_add_del_tunnel (vat_main_t * vam)
10440{
10441 unformat_input_t *line_input = vam->input;
10442 vl_api_gre_add_del_tunnel_t *mp;
10443 f64 timeout;
10444 ip4_address_t src4, dst4;
10445 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010446 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010447 u8 src_set = 0;
10448 u8 dst_set = 0;
10449 u32 outer_fib_id = 0;
10450
10451 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10452 {
10453 if (unformat (line_input, "del"))
10454 is_add = 0;
10455 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10456 src_set = 1;
10457 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10458 dst_set = 1;
10459 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10460 ;
David Hothama8cd3092016-09-19 09:55:07 -070010461 else if (unformat (line_input, "teb"))
10462 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010463 else
10464 {
10465 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10466 return -99;
10467 }
10468 }
10469
10470 if (src_set == 0)
10471 {
10472 errmsg ("tunnel src address not specified\n");
10473 return -99;
10474 }
10475 if (dst_set == 0)
10476 {
10477 errmsg ("tunnel dst address not specified\n");
10478 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010479 }
10480
10481
Dave Barach72d72232016-08-04 10:15:08 -040010482 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010483
Dave Barach72d72232016-08-04 10:15:08 -040010484 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10485 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10486 mp->outer_fib_id = ntohl (outer_fib_id);
10487 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010488 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010489
Dave Barach72d72232016-08-04 10:15:08 -040010490 S;
10491 W;
10492 /* NOTREACHED */
10493 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010494}
10495
10496static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010497 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010498{
Dave Barach72d72232016-08-04 10:15:08 -040010499 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010500
David Hothama8cd3092016-09-19 09:55:07 -070010501 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010502 ntohl (mp->sw_if_index),
10503 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010504 format_ip4_address, &mp->dst_address,
10505 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010506}
10507
10508static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010509 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010510{
Dave Barach72d72232016-08-04 10:15:08 -040010511 vat_main_t *vam = &vat_main;
10512 vat_json_node_t *node = NULL;
10513 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010514
Dave Barach72d72232016-08-04 10:15:08 -040010515 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010516 {
Dave Barach72d72232016-08-04 10:15:08 -040010517 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10518 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010519 }
Dave Barach72d72232016-08-04 10:15:08 -040010520 node = vat_json_array_add (&vam->json_tree);
10521
10522 vat_json_init_object (node);
10523 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10524 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10525 vat_json_object_add_ip4 (node, "src_address", ip4);
10526 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10527 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010528 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010529 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010530}
10531
Dave Barach72d72232016-08-04 10:15:08 -040010532static int
10533api_gre_tunnel_dump (vat_main_t * vam)
10534{
10535 unformat_input_t *i = vam->input;
10536 vl_api_gre_tunnel_dump_t *mp;
10537 f64 timeout;
10538 u32 sw_if_index;
10539 u8 sw_if_index_set = 0;
10540
10541 /* Parse args required to build the message */
10542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10543 {
10544 if (unformat (i, "sw_if_index %d", &sw_if_index))
10545 sw_if_index_set = 1;
10546 else
10547 break;
10548 }
10549
10550 if (sw_if_index_set == 0)
10551 {
10552 sw_if_index = ~0;
10553 }
10554
10555 if (!vam->json_output)
10556 {
David Hothama8cd3092016-09-19 09:55:07 -070010557 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10558 "sw_if_index", "src_address", "dst_address", "teb",
10559 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010560 }
10561
10562 /* Get list of gre-tunnel interfaces */
10563 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10564
10565 mp->sw_if_index = htonl (sw_if_index);
10566
10567 S;
10568
10569 /* Use a control ping for synchronization */
10570 {
10571 vl_api_control_ping_t *mp;
10572 M (CONTROL_PING, control_ping);
10573 S;
10574 }
10575 W;
10576}
10577
10578static int
10579api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010580{
10581// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010582 vl_api_l2_fib_clear_table_t *mp;
10583 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010584
Dave Barach72d72232016-08-04 10:15:08 -040010585 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010586
Dave Barach72d72232016-08-04 10:15:08 -040010587 S;
10588 W;
10589 /* NOTREACHED */
10590 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010591}
10592
Dave Barach72d72232016-08-04 10:15:08 -040010593static int
10594api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010595{
Dave Barach72d72232016-08-04 10:15:08 -040010596 unformat_input_t *i = vam->input;
10597 vl_api_l2_interface_efp_filter_t *mp;
10598 f64 timeout;
10599 u32 sw_if_index;
10600 u8 enable = 1;
10601 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010602
Dave Barach72d72232016-08-04 10:15:08 -040010603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10604 {
10605 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10606 sw_if_index_set = 1;
10607 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10608 sw_if_index_set = 1;
10609 else if (unformat (i, "enable"))
10610 enable = 1;
10611 else if (unformat (i, "disable"))
10612 enable = 0;
10613 else
10614 {
10615 clib_warning ("parse error '%U'", format_unformat_error, i);
10616 return -99;
10617 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010618 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010619
Dave Barach72d72232016-08-04 10:15:08 -040010620 if (sw_if_index_set == 0)
10621 {
10622 errmsg ("missing sw_if_index\n");
10623 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010624 }
10625
Dave Barach72d72232016-08-04 10:15:08 -040010626 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010627
Dave Barach72d72232016-08-04 10:15:08 -040010628 mp->sw_if_index = ntohl (sw_if_index);
10629 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010630
Dave Barach72d72232016-08-04 10:15:08 -040010631 S;
10632 W;
10633 /* NOTREACHED */
10634 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010635}
10636
10637#define foreach_vtr_op \
10638_("disable", L2_VTR_DISABLED) \
10639_("push-1", L2_VTR_PUSH_1) \
10640_("push-2", L2_VTR_PUSH_2) \
10641_("pop-1", L2_VTR_POP_1) \
10642_("pop-2", L2_VTR_POP_2) \
10643_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10644_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10645_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10646_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10647
Dave Barach72d72232016-08-04 10:15:08 -040010648static int
10649api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010650{
Dave Barach72d72232016-08-04 10:15:08 -040010651 unformat_input_t *i = vam->input;
10652 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10653 f64 timeout;
10654 u32 sw_if_index;
10655 u8 sw_if_index_set = 0;
10656 u8 vtr_op_set = 0;
10657 u32 vtr_op = 0;
10658 u32 push_dot1q = 1;
10659 u32 tag1 = ~0;
10660 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010661
Dave Barach72d72232016-08-04 10:15:08 -040010662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10663 {
10664 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10665 sw_if_index_set = 1;
10666 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10667 sw_if_index_set = 1;
10668 else if (unformat (i, "vtr_op %d", &vtr_op))
10669 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010670#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010671 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010672#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010673 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10674 ;
10675 else if (unformat (i, "tag1 %d", &tag1))
10676 ;
10677 else if (unformat (i, "tag2 %d", &tag2))
10678 ;
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) || (vtr_op_set == 0))
10687 {
10688 errmsg ("missing vtr operation or 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_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10693 mp->sw_if_index = ntohl (sw_if_index);
10694 mp->vtr_op = ntohl (vtr_op);
10695 mp->push_dot1q = ntohl (push_dot1q);
10696 mp->tag1 = ntohl (tag1);
10697 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010698
Dave Barach72d72232016-08-04 10:15:08 -040010699 S;
10700 W;
10701 /* NOTREACHED */
10702 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010703}
10704
Dave Barach72d72232016-08-04 10:15:08 -040010705static int
10706api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010707{
Dave Barach72d72232016-08-04 10:15:08 -040010708 unformat_input_t *i = vam->input;
10709 vl_api_create_vhost_user_if_t *mp;
10710 f64 timeout;
10711 u8 *file_name;
10712 u8 is_server = 0;
10713 u8 file_name_set = 0;
10714 u32 custom_dev_instance = ~0;
10715 u8 hwaddr[6];
10716 u8 use_custom_mac = 0;
Dave Barach7be864a2016-11-28 11:41:35 -050010717 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010718
Dave Barach75665d32016-11-17 11:36:59 -050010719 /* Shut up coverity */
10720 memset (hwaddr, 0, sizeof (hwaddr));
10721
Dave Barach72d72232016-08-04 10:15:08 -040010722 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10723 {
10724 if (unformat (i, "socket %s", &file_name))
10725 {
10726 file_name_set = 1;
10727 }
10728 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10729 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010730 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010731 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010732 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010733 is_server = 1;
Dave Barach7be864a2016-11-28 11:41:35 -050010734 else if (unformat (i, "tag %s", &tag))
10735 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010736 else
Dave Barach72d72232016-08-04 10:15:08 -040010737 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010738 }
10739
Dave Barach72d72232016-08-04 10:15:08 -040010740 if (file_name_set == 0)
10741 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010742 errmsg ("missing socket file name\n");
10743 return -99;
10744 }
10745
Dave Barach72d72232016-08-04 10:15:08 -040010746 if (vec_len (file_name) > 255)
10747 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010748 errmsg ("socket file name too long\n");
10749 return -99;
10750 }
Dave Barach72d72232016-08-04 10:15:08 -040010751 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010752
Dave Barach72d72232016-08-04 10:15:08 -040010753 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010754
Dave Barach72d72232016-08-04 10:15:08 -040010755 mp->is_server = is_server;
10756 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10757 vec_free (file_name);
10758 if (custom_dev_instance != ~0)
10759 {
10760 mp->renumber = 1;
10761 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010762 }
Dave Barach72d72232016-08-04 10:15:08 -040010763 mp->use_custom_mac = use_custom_mac;
10764 clib_memcpy (mp->mac_address, hwaddr, 6);
Dave Barach7be864a2016-11-28 11:41:35 -050010765 if (tag)
10766 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10767 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010768
Dave Barach72d72232016-08-04 10:15:08 -040010769 S;
10770 W;
10771 /* NOTREACHED */
10772 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010773}
10774
Dave Barach72d72232016-08-04 10:15:08 -040010775static int
10776api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010777{
Dave Barach72d72232016-08-04 10:15:08 -040010778 unformat_input_t *i = vam->input;
10779 vl_api_modify_vhost_user_if_t *mp;
10780 f64 timeout;
10781 u8 *file_name;
10782 u8 is_server = 0;
10783 u8 file_name_set = 0;
10784 u32 custom_dev_instance = ~0;
10785 u8 sw_if_index_set = 0;
10786 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010787
Dave Barach72d72232016-08-04 10:15:08 -040010788 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10789 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010790 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010791 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010792 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010793 sw_if_index_set = 1;
10794 else if (unformat (i, "socket %s", &file_name))
10795 {
10796 file_name_set = 1;
10797 }
10798 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10799 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010800 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010801 is_server = 1;
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 (sw_if_index_set == 0)
10807 {
10808 errmsg ("missing sw_if_index or interface name\n");
10809 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010810 }
10811
Dave Barach72d72232016-08-04 10:15:08 -040010812 if (file_name_set == 0)
10813 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010814 errmsg ("missing socket file name\n");
10815 return -99;
10816 }
10817
Dave Barach72d72232016-08-04 10:15:08 -040010818 if (vec_len (file_name) > 255)
10819 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010820 errmsg ("socket file name too long\n");
10821 return -99;
10822 }
Dave Barach72d72232016-08-04 10:15:08 -040010823 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010824
Dave Barach72d72232016-08-04 10:15:08 -040010825 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010826
Dave Barach72d72232016-08-04 10:15:08 -040010827 mp->sw_if_index = ntohl (sw_if_index);
10828 mp->is_server = is_server;
10829 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10830 vec_free (file_name);
10831 if (custom_dev_instance != ~0)
10832 {
10833 mp->renumber = 1;
10834 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010835 }
10836
Dave Barach72d72232016-08-04 10:15:08 -040010837 S;
10838 W;
10839 /* NOTREACHED */
10840 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010841}
10842
Dave Barach72d72232016-08-04 10:15:08 -040010843static int
10844api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010845{
Dave Barach72d72232016-08-04 10:15:08 -040010846 unformat_input_t *i = vam->input;
10847 vl_api_delete_vhost_user_if_t *mp;
10848 f64 timeout;
10849 u32 sw_if_index = ~0;
10850 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010851
Dave Barach72d72232016-08-04 10:15:08 -040010852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10853 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010854 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010855 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010856 else if (unformat (i, "sw_if_index %d", &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
Dave Barach72d72232016-08-04 10:15:08 -040010859 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010860 }
10861
Dave Barach72d72232016-08-04 10:15:08 -040010862 if (sw_if_index_set == 0)
10863 {
10864 errmsg ("missing sw_if_index or interface name\n");
10865 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010866 }
10867
10868
Dave Barach72d72232016-08-04 10:15:08 -040010869 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010870
Dave Barach72d72232016-08-04 10:15:08 -040010871 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010872
Dave Barach72d72232016-08-04 10:15:08 -040010873 S;
10874 W;
10875 /* NOTREACHED */
10876 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010877}
10878
10879static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010880 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010881{
Dave Barach72d72232016-08-04 10:15:08 -040010882 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010883
Dave Barach72d72232016-08-04 10:15:08 -040010884 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10885 (char *) mp->interface_name,
10886 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10887 clib_net_to_host_u64 (mp->features), mp->is_server,
10888 ntohl (mp->num_regions), (char *) mp->sock_filename);
10889 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010890}
10891
10892static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010893 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010894{
Dave Barach72d72232016-08-04 10:15:08 -040010895 vat_main_t *vam = &vat_main;
10896 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010897
Dave Barach72d72232016-08-04 10:15:08 -040010898 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010899 {
Dave Barach72d72232016-08-04 10:15:08 -040010900 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10901 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010902 }
Dave Barach72d72232016-08-04 10:15:08 -040010903 node = vat_json_array_add (&vam->json_tree);
10904
10905 vat_json_init_object (node);
10906 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10907 vat_json_object_add_string_copy (node, "interface_name",
10908 mp->interface_name);
10909 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10910 ntohl (mp->virtio_net_hdr_sz));
10911 vat_json_object_add_uint (node, "features",
10912 clib_net_to_host_u64 (mp->features));
10913 vat_json_object_add_uint (node, "is_server", mp->is_server);
10914 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10915 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10916 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010917}
10918
Dave Barach72d72232016-08-04 10:15:08 -040010919static int
10920api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010921{
Dave Barach72d72232016-08-04 10:15:08 -040010922 vl_api_sw_interface_vhost_user_dump_t *mp;
10923 f64 timeout;
10924 fformat (vam->ofp,
10925 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010926
Dave Barach72d72232016-08-04 10:15:08 -040010927 /* Get list of vhost-user interfaces */
10928 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10929 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010930
Dave Barach72d72232016-08-04 10:15:08 -040010931 /* Use a control ping for synchronization */
10932 {
10933 vl_api_control_ping_t *mp;
10934 M (CONTROL_PING, control_ping);
10935 S;
10936 }
10937 W;
10938}
10939
10940static int
10941api_show_version (vat_main_t * vam)
10942{
10943 vl_api_show_version_t *mp;
10944 f64 timeout;
10945
10946 M (SHOW_VERSION, show_version);
10947
10948 S;
10949 W;
10950 /* NOTREACHED */
10951 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010952}
10953
Ed Warnickecb9cada2015-12-08 15:45:58 -070010954
Dave Barach72d72232016-08-04 10:15:08 -040010955static int
10956api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010957{
Dave Barach72d72232016-08-04 10:15:08 -040010958 unformat_input_t *line_input = vam->input;
10959 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10960 f64 timeout;
10961 ip4_address_t local4, remote4;
10962 ip6_address_t local6, remote6;
10963 u8 is_add = 1;
10964 u8 ipv4_set = 0, ipv6_set = 0;
10965 u8 local_set = 0;
10966 u8 remote_set = 0;
10967 u32 encap_vrf_id = 0;
10968 u32 decap_vrf_id = 0;
10969 u8 protocol = ~0;
10970 u32 vni;
10971 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010972
Dave Barach72d72232016-08-04 10:15:08 -040010973 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10974 {
10975 if (unformat (line_input, "del"))
10976 is_add = 0;
10977 else if (unformat (line_input, "local %U",
10978 unformat_ip4_address, &local4))
10979 {
10980 local_set = 1;
10981 ipv4_set = 1;
10982 }
10983 else if (unformat (line_input, "remote %U",
10984 unformat_ip4_address, &remote4))
10985 {
10986 remote_set = 1;
10987 ipv4_set = 1;
10988 }
10989 else if (unformat (line_input, "local %U",
10990 unformat_ip6_address, &local6))
10991 {
10992 local_set = 1;
10993 ipv6_set = 1;
10994 }
10995 else if (unformat (line_input, "remote %U",
10996 unformat_ip6_address, &remote6))
10997 {
10998 remote_set = 1;
10999 ipv6_set = 1;
11000 }
11001 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11002 ;
11003 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
11004 ;
11005 else if (unformat (line_input, "vni %d", &vni))
11006 vni_set = 1;
11007 else if (unformat (line_input, "next-ip4"))
11008 protocol = 1;
11009 else if (unformat (line_input, "next-ip6"))
11010 protocol = 2;
11011 else if (unformat (line_input, "next-ethernet"))
11012 protocol = 3;
11013 else if (unformat (line_input, "next-nsh"))
11014 protocol = 4;
11015 else
11016 {
11017 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
11018 return -99;
11019 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011020 }
11021
Dave Barach72d72232016-08-04 10:15:08 -040011022 if (local_set == 0)
11023 {
11024 errmsg ("tunnel local address not specified\n");
11025 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011026 }
Dave Barach72d72232016-08-04 10:15:08 -040011027 if (remote_set == 0)
11028 {
11029 errmsg ("tunnel remote address not specified\n");
11030 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011031 }
Dave Barach72d72232016-08-04 10:15:08 -040011032 if (ipv4_set && ipv6_set)
11033 {
11034 errmsg ("both IPv4 and IPv6 addresses specified");
11035 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080011036 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011037
Dave Barach72d72232016-08-04 10:15:08 -040011038 if (vni_set == 0)
11039 {
11040 errmsg ("vni not specified\n");
11041 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011042 }
11043
Dave Barach72d72232016-08-04 10:15:08 -040011044 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011045
Hongjun Nidf921cc2016-05-25 01:16:19 +080011046
Dave Barach72d72232016-08-04 10:15:08 -040011047 if (ipv6_set)
11048 {
11049 clib_memcpy (&mp->local, &local6, sizeof (local6));
11050 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
11051 }
11052 else
11053 {
11054 clib_memcpy (&mp->local, &local4, sizeof (local4));
11055 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080011056 }
11057
Dave Barach72d72232016-08-04 10:15:08 -040011058 mp->encap_vrf_id = ntohl (encap_vrf_id);
11059 mp->decap_vrf_id = ntohl (decap_vrf_id);
11060 mp->protocol = ntohl (protocol);
11061 mp->vni = ntohl (vni);
11062 mp->is_add = is_add;
11063 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011064
Dave Barach72d72232016-08-04 10:15:08 -040011065 S;
11066 W;
11067 /* NOTREACHED */
11068 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011069}
11070
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011071static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011072 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011073{
Dave Barach72d72232016-08-04 10:15:08 -040011074 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011075
Dave Barach72d72232016-08-04 10:15:08 -040011076 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
11077 ntohl (mp->sw_if_index),
11078 format_ip46_address, &(mp->local[0]),
11079 format_ip46_address, &(mp->remote[0]),
11080 ntohl (mp->vni),
11081 ntohl (mp->protocol),
11082 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011083}
11084
11085static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011086 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011087{
Dave Barach72d72232016-08-04 10:15:08 -040011088 vat_main_t *vam = &vat_main;
11089 vat_json_node_t *node = NULL;
11090 struct in_addr ip4;
11091 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011092
Dave Barach72d72232016-08-04 10:15:08 -040011093 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011094 {
Dave Barach72d72232016-08-04 10:15:08 -040011095 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11096 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011097 }
Dave Barach72d72232016-08-04 10:15:08 -040011098 node = vat_json_array_add (&vam->json_tree);
11099
11100 vat_json_init_object (node);
11101 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11102 if (mp->is_ipv6)
11103 {
11104 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
11105 vat_json_object_add_ip6 (node, "local", ip6);
11106 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
11107 vat_json_object_add_ip6 (node, "remote", ip6);
11108 }
11109 else
11110 {
11111 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
11112 vat_json_object_add_ip4 (node, "local", ip4);
11113 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
11114 vat_json_object_add_ip4 (node, "remote", ip4);
11115 }
11116 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
11117 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
11118 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
11119 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
11120 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011121}
11122
Dave Barach72d72232016-08-04 10:15:08 -040011123static int
11124api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011125{
Dave Barach72d72232016-08-04 10:15:08 -040011126 unformat_input_t *i = vam->input;
11127 vl_api_vxlan_gpe_tunnel_dump_t *mp;
11128 f64 timeout;
11129 u32 sw_if_index;
11130 u8 sw_if_index_set = 0;
11131
11132 /* Parse args required to build the message */
11133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11134 {
11135 if (unformat (i, "sw_if_index %d", &sw_if_index))
11136 sw_if_index_set = 1;
11137 else
11138 break;
11139 }
11140
11141 if (sw_if_index_set == 0)
11142 {
11143 sw_if_index = ~0;
11144 }
11145
11146 if (!vam->json_output)
11147 {
11148 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
11149 "sw_if_index", "local", "remote", "vni",
11150 "protocol", "encap_vrf_id", "decap_vrf_id");
11151 }
11152
11153 /* Get list of vxlan-tunnel interfaces */
11154 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
11155
11156 mp->sw_if_index = htonl (sw_if_index);
11157
11158 S;
11159
11160 /* Use a control ping for synchronization */
11161 {
11162 vl_api_control_ping_t *mp;
11163 M (CONTROL_PING, control_ping);
11164 S;
11165 }
11166 W;
11167}
11168
11169u8 *
11170format_l2_fib_mac_address (u8 * s, va_list * args)
11171{
11172 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011173
11174 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011175 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011176}
11177
11178static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011179 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011180{
Dave Barach72d72232016-08-04 10:15:08 -040011181 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011182
Dave Barach72d72232016-08-04 10:15:08 -040011183 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11184 " %d %d %d\n",
11185 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11186 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11187 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011188}
11189
11190static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011191 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011192{
Dave Barach72d72232016-08-04 10:15:08 -040011193 vat_main_t *vam = &vat_main;
11194 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011195
Dave Barach72d72232016-08-04 10:15:08 -040011196 if (VAT_JSON_ARRAY != vam->json_tree.type)
11197 {
11198 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11199 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011200 }
Dave Barach72d72232016-08-04 10:15:08 -040011201 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011202
Dave Barach72d72232016-08-04 10:15:08 -040011203 vat_json_init_object (node);
11204 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11205 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11206 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11207 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11208 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11209 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011210}
11211
Dave Barach72d72232016-08-04 10:15:08 -040011212static int
11213api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011214{
Dave Barach72d72232016-08-04 10:15:08 -040011215 unformat_input_t *i = vam->input;
11216 vl_api_l2_fib_table_dump_t *mp;
11217 f64 timeout;
11218 u32 bd_id;
11219 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011220
Dave Barach72d72232016-08-04 10:15:08 -040011221 /* Parse args required to build the message */
11222 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011223 {
Dave Barach72d72232016-08-04 10:15:08 -040011224 if (unformat (i, "bd_id %d", &bd_id))
11225 bd_id_set = 1;
11226 else
11227 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011228 }
Dave Barach72d72232016-08-04 10:15:08 -040011229
11230 if (bd_id_set == 0)
11231 {
11232 errmsg ("missing bridge domain\n");
11233 return -99;
11234 }
11235
11236 fformat (vam->ofp,
11237 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11238
11239 /* Get list of l2 fib entries */
11240 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11241
11242 mp->bd_id = ntohl (bd_id);
11243 S;
11244
11245 /* Use a control ping for synchronization */
11246 {
11247 vl_api_control_ping_t *mp;
11248 M (CONTROL_PING, control_ping);
11249 S;
11250 }
11251 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011252}
11253
11254
11255static int
11256api_interface_name_renumber (vat_main_t * vam)
11257{
Dave Barach72d72232016-08-04 10:15:08 -040011258 unformat_input_t *line_input = vam->input;
11259 vl_api_interface_name_renumber_t *mp;
11260 u32 sw_if_index = ~0;
11261 f64 timeout;
11262 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011263
Dave Barach72d72232016-08-04 10:15:08 -040011264 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11265 {
11266 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11267 &sw_if_index))
11268 ;
11269 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11270 ;
11271 else if (unformat (line_input, "new_show_dev_instance %d",
11272 &new_show_dev_instance))
11273 ;
11274 else
11275 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011276 }
11277
Dave Barach72d72232016-08-04 10:15:08 -040011278 if (sw_if_index == ~0)
11279 {
11280 errmsg ("missing interface name or sw_if_index\n");
11281 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011282 }
11283
Dave Barach72d72232016-08-04 10:15:08 -040011284 if (new_show_dev_instance == ~0)
11285 {
11286 errmsg ("missing new_show_dev_instance\n");
11287 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011288 }
11289
Dave Barach72d72232016-08-04 10:15:08 -040011290 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011291
Dave Barach72d72232016-08-04 10:15:08 -040011292 mp->sw_if_index = ntohl (sw_if_index);
11293 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011294
Dave Barach72d72232016-08-04 10:15:08 -040011295 S;
11296 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011297}
11298
11299static int
11300api_want_ip4_arp_events (vat_main_t * vam)
11301{
Dave Barach72d72232016-08-04 10:15:08 -040011302 unformat_input_t *line_input = vam->input;
11303 vl_api_want_ip4_arp_events_t *mp;
11304 f64 timeout;
11305 ip4_address_t address;
11306 int address_set = 0;
11307 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011308
Dave Barach72d72232016-08-04 10:15:08 -040011309 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11310 {
11311 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11312 address_set = 1;
11313 else if (unformat (line_input, "del"))
11314 enable_disable = 0;
11315 else
11316 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011317 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011318
Dave Barach72d72232016-08-04 10:15:08 -040011319 if (address_set == 0)
11320 {
11321 errmsg ("missing addresses\n");
11322 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011323 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011324
Dave Barach72d72232016-08-04 10:15:08 -040011325 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11326 mp->enable_disable = enable_disable;
11327 mp->pid = getpid ();
11328 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011329
Dave Barach72d72232016-08-04 10:15:08 -040011330 S;
11331 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011332}
11333
Dave Barach72d72232016-08-04 10:15:08 -040011334static int
John Lo1edfba92016-08-27 01:11:57 -040011335api_want_ip6_nd_events (vat_main_t * vam)
11336{
11337 unformat_input_t *line_input = vam->input;
11338 vl_api_want_ip6_nd_events_t *mp;
11339 f64 timeout;
11340 ip6_address_t address;
11341 int address_set = 0;
11342 u32 enable_disable = 1;
11343
11344 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11345 {
11346 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11347 address_set = 1;
11348 else if (unformat (line_input, "del"))
11349 enable_disable = 0;
11350 else
11351 break;
11352 }
11353
11354 if (address_set == 0)
11355 {
11356 errmsg ("missing addresses\n");
11357 return -99;
11358 }
11359
11360 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11361 mp->enable_disable = enable_disable;
11362 mp->pid = getpid ();
11363 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11364
11365 S;
11366 W;
11367}
11368
11369static int
Dave Barach72d72232016-08-04 10:15:08 -040011370api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011371{
Dave Barach72d72232016-08-04 10:15:08 -040011372 unformat_input_t *i = vam->input;
11373 vl_api_input_acl_set_interface_t *mp;
11374 f64 timeout;
11375 u32 sw_if_index;
11376 int sw_if_index_set;
11377 u32 ip4_table_index = ~0;
11378 u32 ip6_table_index = ~0;
11379 u32 l2_table_index = ~0;
11380 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011381
Dave Barach72d72232016-08-04 10:15:08 -040011382 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11383 {
11384 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11385 sw_if_index_set = 1;
11386 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11387 sw_if_index_set = 1;
11388 else if (unformat (i, "del"))
11389 is_add = 0;
11390 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11391 ;
11392 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11393 ;
11394 else if (unformat (i, "l2-table %d", &l2_table_index))
11395 ;
11396 else
11397 {
11398 clib_warning ("parse error '%U'", format_unformat_error, i);
11399 return -99;
11400 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011401 }
11402
Dave Barach72d72232016-08-04 10:15:08 -040011403 if (sw_if_index_set == 0)
11404 {
11405 errmsg ("missing interface name or sw_if_index\n");
11406 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011407 }
11408
Dave Barach72d72232016-08-04 10:15:08 -040011409 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011410
Dave Barach72d72232016-08-04 10:15:08 -040011411 mp->sw_if_index = ntohl (sw_if_index);
11412 mp->ip4_table_index = ntohl (ip4_table_index);
11413 mp->ip6_table_index = ntohl (ip6_table_index);
11414 mp->l2_table_index = ntohl (l2_table_index);
11415 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011416
Dave Barach72d72232016-08-04 10:15:08 -040011417 S;
11418 W;
11419 /* NOTREACHED */
11420 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011421}
11422
11423static int
11424api_ip_address_dump (vat_main_t * vam)
11425{
Dave Barach72d72232016-08-04 10:15:08 -040011426 unformat_input_t *i = vam->input;
11427 vl_api_ip_address_dump_t *mp;
11428 u32 sw_if_index = ~0;
11429 u8 sw_if_index_set = 0;
11430 u8 ipv4_set = 0;
11431 u8 ipv6_set = 0;
11432 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011433
Dave Barach72d72232016-08-04 10:15:08 -040011434 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011435 {
Dave Barach72d72232016-08-04 10:15:08 -040011436 if (unformat (i, "sw_if_index %d", &sw_if_index))
11437 sw_if_index_set = 1;
11438 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11439 sw_if_index_set = 1;
11440 else if (unformat (i, "ipv4"))
11441 ipv4_set = 1;
11442 else if (unformat (i, "ipv6"))
11443 ipv6_set = 1;
11444 else
11445 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011446 }
Dave Barach72d72232016-08-04 10:15:08 -040011447
11448 if (ipv4_set && ipv6_set)
11449 {
11450 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11451 return -99;
11452 }
11453
11454 if ((!ipv4_set) && (!ipv6_set))
11455 {
11456 errmsg ("no ipv4 nor ipv6 flag set\n");
11457 return -99;
11458 }
11459
11460 if (sw_if_index_set == 0)
11461 {
11462 errmsg ("missing interface name or sw_if_index\n");
11463 return -99;
11464 }
11465
11466 vam->current_sw_if_index = sw_if_index;
11467 vam->is_ipv6 = ipv6_set;
11468
11469 M (IP_ADDRESS_DUMP, ip_address_dump);
11470 mp->sw_if_index = ntohl (sw_if_index);
11471 mp->is_ipv6 = ipv6_set;
11472 S;
11473
11474 /* Use a control ping for synchronization */
11475 {
11476 vl_api_control_ping_t *mp;
11477 M (CONTROL_PING, control_ping);
11478 S;
11479 }
11480 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011481}
11482
11483static int
11484api_ip_dump (vat_main_t * vam)
11485{
Dave Barach72d72232016-08-04 10:15:08 -040011486 vl_api_ip_dump_t *mp;
11487 unformat_input_t *in = vam->input;
11488 int ipv4_set = 0;
11489 int ipv6_set = 0;
11490 int is_ipv6;
11491 f64 timeout;
11492 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011493
Dave Barach72d72232016-08-04 10:15:08 -040011494 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011495 {
Dave Barach72d72232016-08-04 10:15:08 -040011496 if (unformat (in, "ipv4"))
11497 ipv4_set = 1;
11498 else if (unformat (in, "ipv6"))
11499 ipv6_set = 1;
11500 else
11501 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011502 }
Dave Barach72d72232016-08-04 10:15:08 -040011503
11504 if (ipv4_set && ipv6_set)
11505 {
11506 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11507 return -99;
11508 }
11509
11510 if ((!ipv4_set) && (!ipv6_set))
11511 {
11512 errmsg ("no ipv4 nor ipv6 flag set\n");
11513 return -99;
11514 }
11515
11516 is_ipv6 = ipv6_set;
11517 vam->is_ipv6 = is_ipv6;
11518
11519 /* free old data */
11520 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11521 {
11522 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11523 }
11524 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11525
11526 M (IP_DUMP, ip_dump);
11527 mp->is_ipv6 = ipv6_set;
11528 S;
11529
11530 /* Use a control ping for synchronization */
11531 {
11532 vl_api_control_ping_t *mp;
11533 M (CONTROL_PING, control_ping);
11534 S;
11535 }
11536 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011537}
11538
11539static int
11540api_ipsec_spd_add_del (vat_main_t * vam)
11541{
Dave Barach72d72232016-08-04 10:15:08 -040011542 unformat_input_t *i = vam->input;
11543 vl_api_ipsec_spd_add_del_t *mp;
11544 f64 timeout;
11545 u32 spd_id = ~0;
11546 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011547
Dave Barach72d72232016-08-04 10:15:08 -040011548 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11549 {
11550 if (unformat (i, "spd_id %d", &spd_id))
11551 ;
11552 else if (unformat (i, "del"))
11553 is_add = 0;
11554 else
11555 {
11556 clib_warning ("parse error '%U'", format_unformat_error, i);
11557 return -99;
11558 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011559 }
Dave Barach72d72232016-08-04 10:15:08 -040011560 if (spd_id == ~0)
11561 {
11562 errmsg ("spd_id must be set\n");
11563 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011564 }
11565
Dave Barach72d72232016-08-04 10:15:08 -040011566 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011567
Dave Barach72d72232016-08-04 10:15:08 -040011568 mp->spd_id = ntohl (spd_id);
11569 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011570
Dave Barach72d72232016-08-04 10:15:08 -040011571 S;
11572 W;
11573 /* NOTREACHED */
11574 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011575}
11576
11577static int
11578api_ipsec_interface_add_del_spd (vat_main_t * vam)
11579{
Dave Barach72d72232016-08-04 10:15:08 -040011580 unformat_input_t *i = vam->input;
11581 vl_api_ipsec_interface_add_del_spd_t *mp;
11582 f64 timeout;
11583 u32 sw_if_index;
11584 u8 sw_if_index_set = 0;
11585 u32 spd_id = (u32) ~ 0;
11586 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011587
Dave Barach72d72232016-08-04 10:15:08 -040011588 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11589 {
11590 if (unformat (i, "del"))
11591 is_add = 0;
11592 else if (unformat (i, "spd_id %d", &spd_id))
11593 ;
11594 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11595 sw_if_index_set = 1;
11596 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11597 sw_if_index_set = 1;
11598 else
11599 {
11600 clib_warning ("parse error '%U'", format_unformat_error, i);
11601 return -99;
11602 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011603
11604 }
11605
Dave Barach72d72232016-08-04 10:15:08 -040011606 if (spd_id == (u32) ~ 0)
11607 {
11608 errmsg ("spd_id must be set\n");
11609 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011610 }
11611
Dave Barach72d72232016-08-04 10:15:08 -040011612 if (sw_if_index_set == 0)
11613 {
11614 errmsg ("missing interface name or sw_if_index\n");
11615 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011616 }
11617
Dave Barach72d72232016-08-04 10:15:08 -040011618 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011619
Dave Barach72d72232016-08-04 10:15:08 -040011620 mp->spd_id = ntohl (spd_id);
11621 mp->sw_if_index = ntohl (sw_if_index);
11622 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011623
Dave Barach72d72232016-08-04 10:15:08 -040011624 S;
11625 W;
11626 /* NOTREACHED */
11627 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011628}
11629
11630static int
11631api_ipsec_spd_add_del_entry (vat_main_t * vam)
11632{
Dave Barach72d72232016-08-04 10:15:08 -040011633 unformat_input_t *i = vam->input;
11634 vl_api_ipsec_spd_add_del_entry_t *mp;
11635 f64 timeout;
11636 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011637 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011638 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011639 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11640 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11641 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11642 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011643
Dave Barach72d72232016-08-04 10:15:08 -040011644 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11645 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11646 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11647 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11648 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11649 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011650
Dave Barach72d72232016-08-04 10:15:08 -040011651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11652 {
11653 if (unformat (i, "del"))
11654 is_add = 0;
11655 if (unformat (i, "outbound"))
11656 is_outbound = 1;
11657 if (unformat (i, "inbound"))
11658 is_outbound = 0;
11659 else if (unformat (i, "spd_id %d", &spd_id))
11660 ;
11661 else if (unformat (i, "sa_id %d", &sa_id))
11662 ;
11663 else if (unformat (i, "priority %d", &priority))
11664 ;
11665 else if (unformat (i, "protocol %d", &protocol))
11666 ;
11667 else if (unformat (i, "lport_start %d", &lport_start))
11668 ;
11669 else if (unformat (i, "lport_stop %d", &lport_stop))
11670 ;
11671 else if (unformat (i, "rport_start %d", &rport_start))
11672 ;
11673 else if (unformat (i, "rport_stop %d", &rport_stop))
11674 ;
11675 else
11676 if (unformat
11677 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11678 {
11679 is_ipv6 = 0;
11680 is_ip_any = 0;
11681 }
11682 else
11683 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11684 {
11685 is_ipv6 = 0;
11686 is_ip_any = 0;
11687 }
11688 else
11689 if (unformat
11690 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11691 {
11692 is_ipv6 = 0;
11693 is_ip_any = 0;
11694 }
11695 else
11696 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11697 {
11698 is_ipv6 = 0;
11699 is_ip_any = 0;
11700 }
11701 else
11702 if (unformat
11703 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11704 {
11705 is_ipv6 = 1;
11706 is_ip_any = 0;
11707 }
11708 else
11709 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11710 {
11711 is_ipv6 = 1;
11712 is_ip_any = 0;
11713 }
11714 else
11715 if (unformat
11716 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11717 {
11718 is_ipv6 = 1;
11719 is_ip_any = 0;
11720 }
11721 else
11722 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11723 {
11724 is_ipv6 = 1;
11725 is_ip_any = 0;
11726 }
11727 else
11728 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11729 {
11730 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11731 {
11732 clib_warning ("unsupported action: 'resolve'");
11733 return -99;
11734 }
11735 }
11736 else
11737 {
11738 clib_warning ("parse error '%U'", format_unformat_error, i);
11739 return -99;
11740 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011741
11742 }
11743
Dave Barach72d72232016-08-04 10:15:08 -040011744 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011745
Dave Barach72d72232016-08-04 10:15:08 -040011746 mp->spd_id = ntohl (spd_id);
11747 mp->priority = ntohl (priority);
11748 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011749
Dave Barach72d72232016-08-04 10:15:08 -040011750 mp->is_ipv6 = is_ipv6;
11751 if (is_ipv6 || is_ip_any)
11752 {
11753 clib_memcpy (mp->remote_address_start, &raddr6_start,
11754 sizeof (ip6_address_t));
11755 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11756 sizeof (ip6_address_t));
11757 clib_memcpy (mp->local_address_start, &laddr6_start,
11758 sizeof (ip6_address_t));
11759 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11760 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011761 }
Dave Barach72d72232016-08-04 10:15:08 -040011762 else
11763 {
11764 clib_memcpy (mp->remote_address_start, &raddr4_start,
11765 sizeof (ip4_address_t));
11766 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11767 sizeof (ip4_address_t));
11768 clib_memcpy (mp->local_address_start, &laddr4_start,
11769 sizeof (ip4_address_t));
11770 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11771 sizeof (ip4_address_t));
11772 }
11773 mp->protocol = (u8) protocol;
11774 mp->local_port_start = ntohs ((u16) lport_start);
11775 mp->local_port_stop = ntohs ((u16) lport_stop);
11776 mp->remote_port_start = ntohs ((u16) rport_start);
11777 mp->remote_port_stop = ntohs ((u16) rport_stop);
11778 mp->policy = (u8) policy;
11779 mp->sa_id = ntohl (sa_id);
11780 mp->is_add = is_add;
11781 mp->is_ip_any = is_ip_any;
11782 S;
11783 W;
11784 /* NOTREACHED */
11785 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011786}
11787
11788static int
11789api_ipsec_sad_add_del_entry (vat_main_t * vam)
11790{
Dave Barach72d72232016-08-04 10:15:08 -040011791 unformat_input_t *i = vam->input;
11792 vl_api_ipsec_sad_add_del_entry_t *mp;
11793 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011794 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011795 u8 *ck = 0, *ik = 0;
11796 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011797
Dave Barach72d72232016-08-04 10:15:08 -040011798 u8 protocol = IPSEC_PROTOCOL_AH;
11799 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11800 u32 crypto_alg = 0, integ_alg = 0;
11801 ip4_address_t tun_src4;
11802 ip4_address_t tun_dst4;
11803 ip6_address_t tun_src6;
11804 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011805
Dave Barach72d72232016-08-04 10:15:08 -040011806 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11807 {
11808 if (unformat (i, "del"))
11809 is_add = 0;
11810 else if (unformat (i, "sad_id %d", &sad_id))
11811 ;
11812 else if (unformat (i, "spi %d", &spi))
11813 ;
11814 else if (unformat (i, "esp"))
11815 protocol = IPSEC_PROTOCOL_ESP;
11816 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11817 {
11818 is_tunnel = 1;
11819 is_tunnel_ipv6 = 0;
11820 }
11821 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11822 {
11823 is_tunnel = 1;
11824 is_tunnel_ipv6 = 0;
11825 }
11826 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11827 {
11828 is_tunnel = 1;
11829 is_tunnel_ipv6 = 1;
11830 }
11831 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11832 {
11833 is_tunnel = 1;
11834 is_tunnel_ipv6 = 1;
11835 }
11836 else
11837 if (unformat
11838 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11839 {
11840 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011841 crypto_alg >= IPSEC_CRYPTO_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011842 {
11843 clib_warning ("unsupported crypto-alg: '%U'",
11844 format_ipsec_crypto_alg, crypto_alg);
11845 return -99;
11846 }
11847 }
11848 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11849 ;
11850 else
11851 if (unformat
11852 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11853 {
Radu Nicolau6929ea92016-11-29 11:00:30 +000011854#if DPDK_CRYPTO==1
11855 if (integ_alg < IPSEC_INTEG_ALG_NONE ||
11856#else
Dave Barach72d72232016-08-04 10:15:08 -040011857 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011858#endif
11859 integ_alg >= IPSEC_INTEG_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011860 {
11861 clib_warning ("unsupported integ-alg: '%U'",
11862 format_ipsec_integ_alg, integ_alg);
11863 return -99;
11864 }
11865 }
11866 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11867 ;
11868 else
11869 {
11870 clib_warning ("parse error '%U'", format_unformat_error, i);
11871 return -99;
11872 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011873
11874 }
11875
Radu Nicolau6929ea92016-11-29 11:00:30 +000011876#if DPDK_CRYPTO==1
11877 /*Special cases, aes-gcm-128 encryption */
11878 if (crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
11879 {
11880 if (integ_alg != IPSEC_INTEG_ALG_NONE
11881 && integ_alg != IPSEC_INTEG_ALG_AES_GCM_128)
11882 {
11883 clib_warning
11884 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
11885 return -99;
11886 }
11887 else /*set integ-alg internally to aes-gcm-128 */
11888 integ_alg = IPSEC_INTEG_ALG_AES_GCM_128;
11889 }
11890 else if (integ_alg == IPSEC_INTEG_ALG_AES_GCM_128)
11891 {
11892 clib_warning ("unsupported integ-alg: aes-gcm-128");
11893 return -99;
11894 }
11895 else if (integ_alg == IPSEC_INTEG_ALG_NONE)
11896 {
11897 clib_warning ("unsupported integ-alg: none");
11898 return -99;
11899 }
11900#endif
11901
11902
Dave Barach72d72232016-08-04 10:15:08 -040011903 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011904
Dave Barach72d72232016-08-04 10:15:08 -040011905 mp->sad_id = ntohl (sad_id);
11906 mp->is_add = is_add;
11907 mp->protocol = protocol;
11908 mp->spi = ntohl (spi);
11909 mp->is_tunnel = is_tunnel;
11910 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11911 mp->crypto_algorithm = crypto_alg;
11912 mp->integrity_algorithm = integ_alg;
11913 mp->crypto_key_length = vec_len (ck);
11914 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011915
Dave Barach72d72232016-08-04 10:15:08 -040011916 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11917 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011918
Dave Barach72d72232016-08-04 10:15:08 -040011919 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11920 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011921
Dave Barach839fe3e2016-08-10 11:35:54 -040011922 if (ck)
11923 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11924 if (ik)
11925 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011926
Dave Barach72d72232016-08-04 10:15:08 -040011927 if (is_tunnel)
11928 {
11929 if (is_tunnel_ipv6)
11930 {
11931 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11932 sizeof (ip6_address_t));
11933 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11934 sizeof (ip6_address_t));
11935 }
11936 else
11937 {
11938 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11939 sizeof (ip4_address_t));
11940 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11941 sizeof (ip4_address_t));
11942 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011943 }
11944
Dave Barach72d72232016-08-04 10:15:08 -040011945 S;
11946 W;
11947 /* NOTREACHED */
11948 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011949}
11950
11951static int
11952api_ipsec_sa_set_key (vat_main_t * vam)
11953{
Dave Barach72d72232016-08-04 10:15:08 -040011954 unformat_input_t *i = vam->input;
11955 vl_api_ipsec_sa_set_key_t *mp;
11956 f64 timeout;
11957 u32 sa_id;
11958 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011959
Dave Barach72d72232016-08-04 10:15:08 -040011960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11961 {
11962 if (unformat (i, "sa_id %d", &sa_id))
11963 ;
11964 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11965 ;
11966 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11967 ;
11968 else
11969 {
11970 clib_warning ("parse error '%U'", format_unformat_error, i);
11971 return -99;
11972 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011973 }
11974
Dave Barach72d72232016-08-04 10:15:08 -040011975 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011976
Dave Barach72d72232016-08-04 10:15:08 -040011977 mp->sa_id = ntohl (sa_id);
11978 mp->crypto_key_length = vec_len (ck);
11979 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011980
Dave Barach72d72232016-08-04 10:15:08 -040011981 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11982 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011983
Dave Barach72d72232016-08-04 10:15:08 -040011984 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11985 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011986
Dave Barach839fe3e2016-08-10 11:35:54 -040011987 if (ck)
11988 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11989 if (ik)
11990 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011991
Dave Barach72d72232016-08-04 10:15:08 -040011992 S;
11993 W;
11994 /* NOTREACHED */
11995 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011996}
11997
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011998static int
11999api_ikev2_profile_add_del (vat_main_t * vam)
12000{
Dave Barach72d72232016-08-04 10:15:08 -040012001 unformat_input_t *i = vam->input;
12002 vl_api_ikev2_profile_add_del_t *mp;
12003 f64 timeout;
12004 u8 is_add = 1;
12005 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012006
Dave Barach72d72232016-08-04 10:15:08 -040012007 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012008
Dave Barach72d72232016-08-04 10:15:08 -040012009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12010 {
12011 if (unformat (i, "del"))
12012 is_add = 0;
12013 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12014 vec_add1 (name, 0);
12015 else
12016 {
12017 errmsg ("parse error '%U'", format_unformat_error, i);
12018 return -99;
12019 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012020 }
12021
Dave Barach72d72232016-08-04 10:15:08 -040012022 if (!vec_len (name))
12023 {
12024 errmsg ("profile name must be specified");
12025 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012026 }
12027
Dave Barach72d72232016-08-04 10:15:08 -040012028 if (vec_len (name) > 64)
12029 {
12030 errmsg ("profile name too long");
12031 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012032 }
12033
Dave Barach72d72232016-08-04 10:15:08 -040012034 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012035
Dave Barach72d72232016-08-04 10:15:08 -040012036 clib_memcpy (mp->name, name, vec_len (name));
12037 mp->is_add = is_add;
12038 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012039
Dave Barach72d72232016-08-04 10:15:08 -040012040 S;
12041 W;
12042 /* NOTREACHED */
12043 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012044}
12045
12046static int
12047api_ikev2_profile_set_auth (vat_main_t * vam)
12048{
Dave Barach72d72232016-08-04 10:15:08 -040012049 unformat_input_t *i = vam->input;
12050 vl_api_ikev2_profile_set_auth_t *mp;
12051 f64 timeout;
12052 u8 *name = 0;
12053 u8 *data = 0;
12054 u32 auth_method = 0;
12055 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012056
Dave Barach72d72232016-08-04 10:15:08 -040012057 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012058
Dave Barach72d72232016-08-04 10:15:08 -040012059 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12060 {
12061 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12062 vec_add1 (name, 0);
12063 else if (unformat (i, "auth_method %U",
12064 unformat_ikev2_auth_method, &auth_method))
12065 ;
12066 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
12067 is_hex = 1;
12068 else if (unformat (i, "auth_data %v", &data))
12069 ;
12070 else
12071 {
12072 errmsg ("parse error '%U'", format_unformat_error, i);
12073 return -99;
12074 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012075 }
12076
Dave Barach72d72232016-08-04 10:15:08 -040012077 if (!vec_len (name))
12078 {
12079 errmsg ("profile name must be specified");
12080 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012081 }
12082
Dave Barach72d72232016-08-04 10:15:08 -040012083 if (vec_len (name) > 64)
12084 {
12085 errmsg ("profile name too long");
12086 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012087 }
12088
Dave Barach72d72232016-08-04 10:15:08 -040012089 if (!vec_len (data))
12090 {
12091 errmsg ("auth_data must be specified");
12092 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012093 }
12094
Dave Barach72d72232016-08-04 10:15:08 -040012095 if (!auth_method)
12096 {
12097 errmsg ("auth_method must be specified");
12098 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012099 }
12100
Dave Barach72d72232016-08-04 10:15:08 -040012101 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012102
Dave Barach72d72232016-08-04 10:15:08 -040012103 mp->is_hex = is_hex;
12104 mp->auth_method = (u8) auth_method;
12105 mp->data_len = vec_len (data);
12106 clib_memcpy (mp->name, name, vec_len (name));
12107 clib_memcpy (mp->data, data, vec_len (data));
12108 vec_free (name);
12109 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012110
Dave Barach72d72232016-08-04 10:15:08 -040012111 S;
12112 W;
12113 /* NOTREACHED */
12114 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012115}
12116
12117static int
12118api_ikev2_profile_set_id (vat_main_t * vam)
12119{
Dave Barach72d72232016-08-04 10:15:08 -040012120 unformat_input_t *i = vam->input;
12121 vl_api_ikev2_profile_set_id_t *mp;
12122 f64 timeout;
12123 u8 *name = 0;
12124 u8 *data = 0;
12125 u8 is_local = 0;
12126 u32 id_type = 0;
12127 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012128
Dave Barach72d72232016-08-04 10:15:08 -040012129 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012130
Dave Barach72d72232016-08-04 10:15:08 -040012131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12132 {
12133 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12134 vec_add1 (name, 0);
12135 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
12136 ;
12137 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
12138 {
12139 data = vec_new (u8, 4);
12140 clib_memcpy (data, ip4.as_u8, 4);
12141 }
12142 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
12143 ;
12144 else if (unformat (i, "id_data %v", &data))
12145 ;
12146 else if (unformat (i, "local"))
12147 is_local = 1;
12148 else if (unformat (i, "remote"))
12149 is_local = 0;
12150 else
12151 {
12152 errmsg ("parse error '%U'", format_unformat_error, i);
12153 return -99;
12154 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012155 }
12156
Dave Barach72d72232016-08-04 10:15:08 -040012157 if (!vec_len (name))
12158 {
12159 errmsg ("profile name must be specified");
12160 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012161 }
12162
Dave Barach72d72232016-08-04 10:15:08 -040012163 if (vec_len (name) > 64)
12164 {
12165 errmsg ("profile name too long");
12166 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012167 }
12168
Dave Barach72d72232016-08-04 10:15:08 -040012169 if (!vec_len (data))
12170 {
12171 errmsg ("id_data must be specified");
12172 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012173 }
12174
Dave Barach72d72232016-08-04 10:15:08 -040012175 if (!id_type)
12176 {
12177 errmsg ("id_type must be specified");
12178 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012179 }
12180
Dave Barach72d72232016-08-04 10:15:08 -040012181 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012182
Dave Barach72d72232016-08-04 10:15:08 -040012183 mp->is_local = is_local;
12184 mp->id_type = (u8) id_type;
12185 mp->data_len = vec_len (data);
12186 clib_memcpy (mp->name, name, vec_len (name));
12187 clib_memcpy (mp->data, data, vec_len (data));
12188 vec_free (name);
12189 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012190
Dave Barach72d72232016-08-04 10:15:08 -040012191 S;
12192 W;
12193 /* NOTREACHED */
12194 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012195}
12196
12197static int
12198api_ikev2_profile_set_ts (vat_main_t * vam)
12199{
Dave Barach72d72232016-08-04 10:15:08 -040012200 unformat_input_t *i = vam->input;
12201 vl_api_ikev2_profile_set_ts_t *mp;
12202 f64 timeout;
12203 u8 *name = 0;
12204 u8 is_local = 0;
12205 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12206 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012207
Dave Barach72d72232016-08-04 10:15:08 -040012208 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012209
Dave Barach72d72232016-08-04 10:15:08 -040012210 start_addr.as_u32 = 0;
12211 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012212
Dave Barach72d72232016-08-04 10:15:08 -040012213 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12214 {
12215 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12216 vec_add1 (name, 0);
12217 else if (unformat (i, "protocol %d", &proto))
12218 ;
12219 else if (unformat (i, "start_port %d", &start_port))
12220 ;
12221 else if (unformat (i, "end_port %d", &end_port))
12222 ;
12223 else
12224 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12225 ;
12226 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12227 ;
12228 else if (unformat (i, "local"))
12229 is_local = 1;
12230 else if (unformat (i, "remote"))
12231 is_local = 0;
12232 else
12233 {
12234 errmsg ("parse error '%U'", format_unformat_error, i);
12235 return -99;
12236 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012237 }
12238
Dave Barach72d72232016-08-04 10:15:08 -040012239 if (!vec_len (name))
12240 {
12241 errmsg ("profile name must be specified");
12242 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012243 }
12244
Dave Barach72d72232016-08-04 10:15:08 -040012245 if (vec_len (name) > 64)
12246 {
12247 errmsg ("profile name too long");
12248 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012249 }
12250
Dave Barach72d72232016-08-04 10:15:08 -040012251 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012252
Dave Barach72d72232016-08-04 10:15:08 -040012253 mp->is_local = is_local;
12254 mp->proto = (u8) proto;
12255 mp->start_port = (u16) start_port;
12256 mp->end_port = (u16) end_port;
12257 mp->start_addr = start_addr.as_u32;
12258 mp->end_addr = end_addr.as_u32;
12259 clib_memcpy (mp->name, name, vec_len (name));
12260 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012261
Dave Barach72d72232016-08-04 10:15:08 -040012262 S;
12263 W;
12264 /* NOTREACHED */
12265 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012266}
12267
12268static int
12269api_ikev2_set_local_key (vat_main_t * vam)
12270{
Dave Barach72d72232016-08-04 10:15:08 -040012271 unformat_input_t *i = vam->input;
12272 vl_api_ikev2_set_local_key_t *mp;
12273 f64 timeout;
12274 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012275
Dave Barach72d72232016-08-04 10:15:08 -040012276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12277 {
12278 if (unformat (i, "file %v", &file))
12279 vec_add1 (file, 0);
12280 else
12281 {
12282 errmsg ("parse error '%U'", format_unformat_error, i);
12283 return -99;
12284 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012285 }
12286
Dave Barach72d72232016-08-04 10:15:08 -040012287 if (!vec_len (file))
12288 {
12289 errmsg ("RSA key file must be specified");
12290 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012291 }
12292
Dave Barach72d72232016-08-04 10:15:08 -040012293 if (vec_len (file) > 256)
12294 {
12295 errmsg ("file name too long");
12296 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012297 }
12298
Dave Barach72d72232016-08-04 10:15:08 -040012299 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012300
Dave Barach72d72232016-08-04 10:15:08 -040012301 clib_memcpy (mp->key_file, file, vec_len (file));
12302 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012303
Dave Barach72d72232016-08-04 10:15:08 -040012304 S;
12305 W;
12306 /* NOTREACHED */
12307 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012308}
12309
Ed Warnickecb9cada2015-12-08 15:45:58 -070012310/*
12311 * MAP
12312 */
Dave Barach72d72232016-08-04 10:15:08 -040012313static int
12314api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012315{
12316 unformat_input_t *i = vam->input;
12317 vl_api_map_add_domain_t *mp;
12318 f64 timeout;
12319
12320 ip4_address_t ip4_prefix;
12321 ip6_address_t ip6_prefix;
12322 ip6_address_t ip6_src;
12323 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012324 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12325 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012326 u8 is_translation = 0;
12327 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012328 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012329
Dave Barach72d72232016-08-04 10:15:08 -040012330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12331 {
12332 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12333 &ip4_prefix, &ip4_prefix_len))
12334 num_m_args++;
12335 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12336 &ip6_prefix, &ip6_prefix_len))
12337 num_m_args++;
12338 else
12339 if (unformat
12340 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12341 &ip6_src_len))
12342 num_m_args++;
12343 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12344 num_m_args++;
12345 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12346 num_m_args++;
12347 else if (unformat (i, "psid-offset %d", &psid_offset))
12348 num_m_args++;
12349 else if (unformat (i, "psid-len %d", &psid_length))
12350 num_m_args++;
12351 else if (unformat (i, "mtu %d", &mtu))
12352 num_m_args++;
12353 else if (unformat (i, "map-t"))
12354 is_translation = 1;
12355 else
12356 {
12357 clib_warning ("parse error '%U'", format_unformat_error, i);
12358 return -99;
12359 }
12360 }
12361
Ole Troan07e7eab2016-08-25 00:24:08 +020012362 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012363 {
12364 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012365 return -99;
12366 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012367
12368 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012369 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012370
Dave Barach72d72232016-08-04 10:15:08 -040012371 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012372 mp->ip4_prefix_len = ip4_prefix_len;
12373
Dave Barach72d72232016-08-04 10:15:08 -040012374 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012375 mp->ip6_prefix_len = ip6_prefix_len;
12376
Dave Barach72d72232016-08-04 10:15:08 -040012377 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012378 mp->ip6_src_prefix_len = ip6_src_len;
12379
12380 mp->ea_bits_len = ea_bits_len;
12381 mp->psid_offset = psid_offset;
12382 mp->psid_length = psid_length;
12383 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012384 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012385
12386 /* send it... */
12387 S;
12388
12389 /* Wait for a reply, return good/bad news */
12390 W;
12391}
12392
Dave Barach72d72232016-08-04 10:15:08 -040012393static int
12394api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012395{
12396 unformat_input_t *i = vam->input;
12397 vl_api_map_del_domain_t *mp;
12398 f64 timeout;
12399
12400 u32 num_m_args = 0;
12401 u32 index;
12402
Dave Barach72d72232016-08-04 10:15:08 -040012403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12404 {
12405 if (unformat (i, "index %d", &index))
12406 num_m_args++;
12407 else
12408 {
12409 clib_warning ("parse error '%U'", format_unformat_error, i);
12410 return -99;
12411 }
12412 }
12413
12414 if (num_m_args != 1)
12415 {
12416 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012417 return -99;
12418 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012419
12420 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012421 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012422
Dave Barach72d72232016-08-04 10:15:08 -040012423 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012424
12425 /* send it... */
12426 S;
12427
12428 /* Wait for a reply, return good/bad news */
12429 W;
12430}
12431
Dave Barach72d72232016-08-04 10:15:08 -040012432static int
12433api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012434{
12435 unformat_input_t *i = vam->input;
12436 vl_api_map_add_del_rule_t *mp;
12437 f64 timeout;
12438 u8 is_add = 1;
12439 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012440 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012441
Dave Barach72d72232016-08-04 10:15:08 -040012442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12443 {
12444 if (unformat (i, "index %d", &index))
12445 num_m_args++;
12446 else if (unformat (i, "psid %d", &psid))
12447 num_m_args++;
12448 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12449 num_m_args++;
12450 else if (unformat (i, "del"))
12451 {
12452 is_add = 0;
12453 }
12454 else
12455 {
12456 clib_warning ("parse error '%U'", format_unformat_error, i);
12457 return -99;
12458 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012459 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012460
12461 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012462 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012463
Dave Barach72d72232016-08-04 10:15:08 -040012464 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012465 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012466 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12467 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012468
12469 /* send it... */
12470 S;
12471
12472 /* Wait for a reply, return good/bad news */
12473 W;
12474}
12475
Dave Barach72d72232016-08-04 10:15:08 -040012476static int
12477api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012478{
Dave Barach72d72232016-08-04 10:15:08 -040012479 vl_api_map_domain_dump_t *mp;
12480 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012481
Dave Barach72d72232016-08-04 10:15:08 -040012482 /* Construct the API message */
12483 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012484
Dave Barach72d72232016-08-04 10:15:08 -040012485 /* send it... */
12486 S;
12487
12488 /* Use a control ping for synchronization */
12489 {
12490 vl_api_control_ping_t *mp;
12491 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012492 S;
Dave Barach72d72232016-08-04 10:15:08 -040012493 }
12494 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012495}
12496
Dave Barach72d72232016-08-04 10:15:08 -040012497static int
12498api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012499{
Dave Barach72d72232016-08-04 10:15:08 -040012500 unformat_input_t *i = vam->input;
12501 vl_api_map_rule_dump_t *mp;
12502 f64 timeout;
12503 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012504
Dave Barach72d72232016-08-04 10:15:08 -040012505 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012506 {
Dave Barach72d72232016-08-04 10:15:08 -040012507 if (unformat (i, "index %u", &domain_index))
12508 ;
12509 else
12510 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012511 }
Dave Barach72d72232016-08-04 10:15:08 -040012512
12513 if (domain_index == ~0)
12514 {
12515 clib_warning ("parse error: domain index expected");
12516 return -99;
12517 }
12518
12519 /* Construct the API message */
12520 M (MAP_RULE_DUMP, map_rule_dump);
12521
12522 mp->domain_index = htonl (domain_index);
12523
12524 /* send it... */
12525 S;
12526
12527 /* Use a control ping for synchronization */
12528 {
12529 vl_api_control_ping_t *mp;
12530 M (CONTROL_PING, control_ping);
12531 S;
12532 }
12533 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012534}
12535
12536static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012537 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012538{
Dave Barach72d72232016-08-04 10:15:08 -040012539 vat_main_t *vam = &vat_main;
12540 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012541
Dave Barach72d72232016-08-04 10:15:08 -040012542 if (vam->async_mode)
12543 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012544 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012545 }
12546 else
12547 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012548 vam->retval = retval;
12549 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012550 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012551}
12552
12553static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012554 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012555{
Dave Barach72d72232016-08-04 10:15:08 -040012556 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012557 vat_json_node_t node;
12558
Dave Barach72d72232016-08-04 10:15:08 -040012559 vat_json_init_object (&node);
12560 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12561 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012562
Dave Barach72d72232016-08-04 10:15:08 -040012563 vat_json_print (vam->ofp, &node);
12564 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012565
Dave Barach72d72232016-08-04 10:15:08 -040012566 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012567 vam->result_ready = 1;
12568}
12569
12570static int
12571api_get_first_msg_id (vat_main_t * vam)
12572{
Dave Barach72d72232016-08-04 10:15:08 -040012573 vl_api_get_first_msg_id_t *mp;
12574 f64 timeout;
12575 unformat_input_t *i = vam->input;
12576 u8 *name;
12577 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012578
Dave Barach72d72232016-08-04 10:15:08 -040012579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12580 {
12581 if (unformat (i, "client %s", &name))
12582 name_set = 1;
12583 else
12584 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012585 }
12586
Dave Barach72d72232016-08-04 10:15:08 -040012587 if (name_set == 0)
12588 {
12589 errmsg ("missing client name\n");
12590 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012591 }
Dave Barach72d72232016-08-04 10:15:08 -040012592 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012593
Dave Barach72d72232016-08-04 10:15:08 -040012594 if (vec_len (name) > 63)
12595 {
12596 errmsg ("client name too long\n");
12597 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012598 }
12599
Dave Barach72d72232016-08-04 10:15:08 -040012600 M (GET_FIRST_MSG_ID, get_first_msg_id);
12601 clib_memcpy (mp->name, name, vec_len (name));
12602 S;
12603 W;
12604 /* NOTREACHED */
12605 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012606}
12607
Dave Barach72d72232016-08-04 10:15:08 -040012608static int
12609api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012610{
Dave Barach72d72232016-08-04 10:15:08 -040012611 unformat_input_t *line_input = vam->input;
12612 vl_api_cop_interface_enable_disable_t *mp;
12613 f64 timeout;
12614 u32 sw_if_index = ~0;
12615 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012616
Dave Barach72d72232016-08-04 10:15:08 -040012617 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12618 {
12619 if (unformat (line_input, "disable"))
12620 enable_disable = 0;
12621 if (unformat (line_input, "enable"))
12622 enable_disable = 1;
12623 else if (unformat (line_input, "%U", unformat_sw_if_index,
12624 vam, &sw_if_index))
12625 ;
12626 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12627 ;
12628 else
12629 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012630 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012631
Dave Barach72d72232016-08-04 10:15:08 -040012632 if (sw_if_index == ~0)
12633 {
12634 errmsg ("missing interface name or sw_if_index\n");
12635 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012636 }
12637
Dave Barach72d72232016-08-04 10:15:08 -040012638 /* Construct the API message */
12639 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12640 mp->sw_if_index = ntohl (sw_if_index);
12641 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012642
Dave Barach72d72232016-08-04 10:15:08 -040012643 /* send it... */
12644 S;
12645 /* Wait for the reply */
12646 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012647}
12648
Dave Barach72d72232016-08-04 10:15:08 -040012649static int
12650api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012651{
Dave Barach72d72232016-08-04 10:15:08 -040012652 unformat_input_t *line_input = vam->input;
12653 vl_api_cop_whitelist_enable_disable_t *mp;
12654 f64 timeout;
12655 u32 sw_if_index = ~0;
12656 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012657 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012658
Dave Barach72d72232016-08-04 10:15:08 -040012659 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12660 {
12661 if (unformat (line_input, "ip4"))
12662 ip4 = 1;
12663 else if (unformat (line_input, "ip6"))
12664 ip6 = 1;
12665 else if (unformat (line_input, "default"))
12666 default_cop = 1;
12667 else if (unformat (line_input, "%U", unformat_sw_if_index,
12668 vam, &sw_if_index))
12669 ;
12670 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12671 ;
12672 else if (unformat (line_input, "fib-id %d", &fib_id))
12673 ;
12674 else
12675 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012676 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012677
Dave Barach72d72232016-08-04 10:15:08 -040012678 if (sw_if_index == ~0)
12679 {
12680 errmsg ("missing interface name or sw_if_index\n");
12681 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012682 }
12683
Dave Barach72d72232016-08-04 10:15:08 -040012684 /* Construct the API message */
12685 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12686 mp->sw_if_index = ntohl (sw_if_index);
12687 mp->fib_id = ntohl (fib_id);
12688 mp->ip4 = ip4;
12689 mp->ip6 = ip6;
12690 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012691
Dave Barach72d72232016-08-04 10:15:08 -040012692 /* send it... */
12693 S;
12694 /* Wait for the reply */
12695 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012696}
12697
Dave Barach72d72232016-08-04 10:15:08 -040012698static int
12699api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012700{
Dave Barach72d72232016-08-04 10:15:08 -040012701 vl_api_get_node_graph_t *mp;
12702 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012703
Dave Barach72d72232016-08-04 10:15:08 -040012704 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012705
Dave Barach72d72232016-08-04 10:15:08 -040012706 /* send it... */
12707 S;
12708 /* Wait for the reply */
12709 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012710}
12711
Dave Barach72d72232016-08-04 10:15:08 -040012712/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012713/** Used for parsing LISP eids */
12714typedef CLIB_PACKED(struct{
12715 u8 addr[16]; /**< eid address */
12716 u32 len; /**< prefix length if IP */
12717 u8 type; /**< type of eid */
12718}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012719/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012720
12721static uword
12722unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12723{
Dave Barach72d72232016-08-04 10:15:08 -040012724 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012725
Dave Barach72d72232016-08-04 10:15:08 -040012726 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012727
Dave Barach72d72232016-08-04 10:15:08 -040012728 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12729 {
12730 a->type = 0; /* ipv4 type */
12731 }
12732 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12733 {
12734 a->type = 1; /* ipv6 type */
12735 }
12736 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12737 {
12738 a->type = 2; /* mac type */
12739 }
12740 else
12741 {
Florin Coras429e7952016-08-02 02:31:03 +020012742 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012743 }
Florin Coras429e7952016-08-02 02:31:03 +020012744
Dave Barach72d72232016-08-04 10:15:08 -040012745 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12746 {
Florin Coras429e7952016-08-02 02:31:03 +020012747 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012748 }
Florin Coras429e7952016-08-02 02:31:03 +020012749
12750 return 1;
12751}
12752
12753static int
12754lisp_eid_size_vat (u8 type)
12755{
Dave Barach72d72232016-08-04 10:15:08 -040012756 switch (type)
12757 {
Florin Coras429e7952016-08-02 02:31:03 +020012758 case 0:
12759 return 4;
12760 case 1:
12761 return 16;
12762 case 2:
12763 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012764 }
Florin Coras429e7952016-08-02 02:31:03 +020012765 return 0;
12766}
12767
12768static void
12769lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12770{
Dave Barach72d72232016-08-04 10:15:08 -040012771 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012772}
12773
Dave Barach72d72232016-08-04 10:15:08 -040012774/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012775/** Used for transferring locators via VPP API */
12776typedef CLIB_PACKED(struct
12777{
Dave Barach72d72232016-08-04 10:15:08 -040012778 u32 sw_if_index; /**< locator sw_if_index */
12779 u8 priority; /**< locator priority */
12780 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012781}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012782/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012783
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012784static int
Dave Barach72d72232016-08-04 10:15:08 -040012785api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012786{
Dave Barach72d72232016-08-04 10:15:08 -040012787 unformat_input_t *input = vam->input;
12788 vl_api_lisp_add_del_locator_set_t *mp;
12789 f64 timeout = ~0;
12790 u8 is_add = 1;
12791 u8 *locator_set_name = NULL;
12792 u8 locator_set_name_set = 0;
12793 ls_locator_t locator, *locators = 0;
12794 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012795 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012796
Dave Barach72d72232016-08-04 10:15:08 -040012797 /* Parse args required to build the message */
12798 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12799 {
12800 if (unformat (input, "del"))
12801 {
12802 is_add = 0;
12803 }
12804 else if (unformat (input, "locator-set %s", &locator_set_name))
12805 {
12806 locator_set_name_set = 1;
12807 }
12808 else if (unformat (input, "sw_if_index %u p %u w %u",
12809 &sw_if_index, &priority, &weight))
12810 {
12811 locator.sw_if_index = htonl (sw_if_index);
12812 locator.priority = priority;
12813 locator.weight = weight;
12814 vec_add1 (locators, locator);
12815 }
12816 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12817 vam, &sw_if_index, &priority, &weight))
12818 {
12819 locator.sw_if_index = htonl (sw_if_index);
12820 locator.priority = priority;
12821 locator.weight = weight;
12822 vec_add1 (locators, locator);
12823 }
12824 else
12825 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012826 }
12827
Dave Barach72d72232016-08-04 10:15:08 -040012828 if (locator_set_name_set == 0)
12829 {
12830 errmsg ("missing locator-set name");
12831 vec_free (locators);
12832 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012833 }
12834
Dave Barach72d72232016-08-04 10:15:08 -040012835 if (vec_len (locator_set_name) > 64)
12836 {
12837 errmsg ("locator-set name too long\n");
12838 vec_free (locator_set_name);
12839 vec_free (locators);
12840 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012841 }
Dave Barach72d72232016-08-04 10:15:08 -040012842 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012843
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012844 data_len = sizeof (ls_locator_t) * vec_len (locators);
12845
Dave Barach72d72232016-08-04 10:15:08 -040012846 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012847 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012848
Dave Barach72d72232016-08-04 10:15:08 -040012849 mp->is_add = is_add;
12850 clib_memcpy (mp->locator_set_name, locator_set_name,
12851 vec_len (locator_set_name));
12852 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012853
Filip Tehlare3552c42016-08-26 12:44:38 +020012854 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012855 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012856 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012857 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012858
Dave Barach72d72232016-08-04 10:15:08 -040012859 /* send it... */
12860 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012861
Dave Barach72d72232016-08-04 10:15:08 -040012862 /* Wait for a reply... */
12863 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012864
Dave Barach72d72232016-08-04 10:15:08 -040012865 /* NOTREACHED */
12866 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012867}
12868
12869static int
Dave Barach72d72232016-08-04 10:15:08 -040012870api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012871{
Dave Barach72d72232016-08-04 10:15:08 -040012872 unformat_input_t *input = vam->input;
12873 vl_api_lisp_add_del_locator_t *mp;
12874 f64 timeout = ~0;
12875 u32 tmp_if_index = ~0;
12876 u32 sw_if_index = ~0;
12877 u8 sw_if_index_set = 0;
12878 u8 sw_if_index_if_name_set = 0;
12879 u32 priority = ~0;
12880 u8 priority_set = 0;
12881 u32 weight = ~0;
12882 u8 weight_set = 0;
12883 u8 is_add = 1;
12884 u8 *locator_set_name = NULL;
12885 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012886
Dave Barach72d72232016-08-04 10:15:08 -040012887 /* Parse args required to build the message */
12888 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12889 {
12890 if (unformat (input, "del"))
12891 {
12892 is_add = 0;
12893 }
12894 else if (unformat (input, "locator-set %s", &locator_set_name))
12895 {
12896 locator_set_name_set = 1;
12897 }
12898 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12899 &tmp_if_index))
12900 {
12901 sw_if_index_if_name_set = 1;
12902 sw_if_index = tmp_if_index;
12903 }
12904 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12905 {
12906 sw_if_index_set = 1;
12907 sw_if_index = tmp_if_index;
12908 }
12909 else if (unformat (input, "p %d", &priority))
12910 {
12911 priority_set = 1;
12912 }
12913 else if (unformat (input, "w %d", &weight))
12914 {
12915 weight_set = 1;
12916 }
12917 else
12918 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012919 }
12920
Dave Barach72d72232016-08-04 10:15:08 -040012921 if (locator_set_name_set == 0)
12922 {
12923 errmsg ("missing locator-set name");
12924 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012925 }
12926
Dave Barach72d72232016-08-04 10:15:08 -040012927 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12928 {
12929 errmsg ("missing sw_if_index");
12930 vec_free (locator_set_name);
12931 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012932 }
12933
Dave Barach72d72232016-08-04 10:15:08 -040012934 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12935 {
12936 errmsg ("cannot use both params interface name and sw_if_index");
12937 vec_free (locator_set_name);
12938 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012939 }
12940
Dave Barach72d72232016-08-04 10:15:08 -040012941 if (priority_set == 0)
12942 {
12943 errmsg ("missing locator-set priority\n");
12944 vec_free (locator_set_name);
12945 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012946 }
12947
Dave Barach72d72232016-08-04 10:15:08 -040012948 if (weight_set == 0)
12949 {
12950 errmsg ("missing locator-set weight\n");
12951 vec_free (locator_set_name);
12952 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012953 }
12954
Dave Barach72d72232016-08-04 10:15:08 -040012955 if (vec_len (locator_set_name) > 64)
12956 {
12957 errmsg ("locator-set name too long\n");
12958 vec_free (locator_set_name);
12959 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012960 }
Dave Barach72d72232016-08-04 10:15:08 -040012961 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012962
Dave Barach72d72232016-08-04 10:15:08 -040012963 /* Construct the API message */
12964 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012965
Dave Barach72d72232016-08-04 10:15:08 -040012966 mp->is_add = is_add;
12967 mp->sw_if_index = ntohl (sw_if_index);
12968 mp->priority = priority;
12969 mp->weight = weight;
12970 clib_memcpy (mp->locator_set_name, locator_set_name,
12971 vec_len (locator_set_name));
12972 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012973
Dave Barach72d72232016-08-04 10:15:08 -040012974 /* send it... */
12975 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012976
Dave Barach72d72232016-08-04 10:15:08 -040012977 /* Wait for a reply... */
12978 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012979
Dave Barach72d72232016-08-04 10:15:08 -040012980 /* NOTREACHED */
12981 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012982}
12983
Filip Tehlar397fd7d2016-10-26 14:31:24 +020012984uword
12985unformat_hmac_key_id (unformat_input_t * input, va_list * args)
12986{
12987 u32 *key_id = va_arg (*args, u32 *);
12988 u8 *s = 0;
12989
12990 if (unformat (input, "%s", &s))
12991 {
12992 if (!strcmp ((char *) s, "sha1"))
12993 key_id[0] = HMAC_SHA_1_96;
12994 else if (!strcmp ((char *) s, "sha256"))
12995 key_id[0] = HMAC_SHA_256_128;
12996 else
12997 {
12998 clib_warning ("invalid key_id: '%s'", s);
12999 key_id[0] = HMAC_NO_KEY;
13000 }
13001 }
13002 else
13003 return 0;
13004
13005 vec_free (s);
13006 return 1;
13007}
13008
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013009static int
Dave Barach72d72232016-08-04 10:15:08 -040013010api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013011{
Dave Barach72d72232016-08-04 10:15:08 -040013012 unformat_input_t *input = vam->input;
13013 vl_api_lisp_add_del_local_eid_t *mp;
13014 f64 timeout = ~0;
13015 u8 is_add = 1;
13016 u8 eid_set = 0;
13017 lisp_eid_vat_t _eid, *eid = &_eid;
13018 u8 *locator_set_name = 0;
13019 u8 locator_set_name_set = 0;
13020 u32 vni = 0;
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013021 u16 key_id = 0;
13022 u8 *key = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013023
Dave Barach72d72232016-08-04 10:15:08 -040013024 /* Parse args required to build the message */
13025 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13026 {
13027 if (unformat (input, "del"))
13028 {
13029 is_add = 0;
13030 }
13031 else if (unformat (input, "vni %d", &vni))
13032 {
13033 ;
13034 }
13035 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
13036 {
13037 eid_set = 1;
13038 }
13039 else if (unformat (input, "locator-set %s", &locator_set_name))
13040 {
13041 locator_set_name_set = 1;
13042 }
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013043 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
13044 ;
13045 else if (unformat (input, "secret-key %_%v%_", &key))
13046 ;
Dave Barach72d72232016-08-04 10:15:08 -040013047 else
13048 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013049 }
13050
Dave Barach72d72232016-08-04 10:15:08 -040013051 if (locator_set_name_set == 0)
13052 {
13053 errmsg ("missing locator-set name\n");
13054 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013055 }
13056
Dave Barach72d72232016-08-04 10:15:08 -040013057 if (0 == eid_set)
13058 {
13059 errmsg ("EID address not set!");
13060 vec_free (locator_set_name);
13061 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020013062 }
13063
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013064 if (key && (0 == key_id))
13065 {
13066 errmsg ("invalid key_id!");
13067 return -99;
13068 }
13069
13070 if (vec_len (key) > 64)
13071 {
13072 errmsg ("key too long");
13073 vec_free (key);
13074 return -99;
13075 }
13076
Dave Barach72d72232016-08-04 10:15:08 -040013077 if (vec_len (locator_set_name) > 64)
13078 {
13079 errmsg ("locator-set name too long\n");
13080 vec_free (locator_set_name);
13081 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013082 }
Dave Barach72d72232016-08-04 10:15:08 -040013083 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013084
Dave Barach72d72232016-08-04 10:15:08 -040013085 /* Construct the API message */
13086 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013087
Dave Barach72d72232016-08-04 10:15:08 -040013088 mp->is_add = is_add;
13089 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
13090 mp->eid_type = eid->type;
13091 mp->prefix_len = eid->len;
13092 mp->vni = clib_host_to_net_u32 (vni);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013093 mp->key_id = clib_host_to_net_u16 (key_id);
Dave Barach72d72232016-08-04 10:15:08 -040013094 clib_memcpy (mp->locator_set_name, locator_set_name,
13095 vec_len (locator_set_name));
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013096 clib_memcpy (mp->key, key, vec_len (key));
Florin Coras429e7952016-08-02 02:31:03 +020013097
Dave Barach72d72232016-08-04 10:15:08 -040013098 vec_free (locator_set_name);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013099 vec_free (key);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013100
Dave Barach72d72232016-08-04 10:15:08 -040013101 /* send it... */
13102 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013103
Dave Barach72d72232016-08-04 10:15:08 -040013104 /* Wait for a reply... */
13105 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013106
Dave Barach72d72232016-08-04 10:15:08 -040013107 /* NOTREACHED */
13108 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013109}
13110
Dave Barach72d72232016-08-04 10:15:08 -040013111/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020013112/** Used for transferring locators via VPP API */
13113typedef CLIB_PACKED(struct
13114{
Dave Barach72d72232016-08-04 10:15:08 -040013115 u8 is_ip4; /**< is locator an IPv4 address? */
13116 u8 priority; /**< locator priority */
13117 u8 weight; /**< locator weight */
13118 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020013119}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040013120/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020013121
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013122static int
Dave Barach72d72232016-08-04 10:15:08 -040013123api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013124{
Dave Barach72d72232016-08-04 10:15:08 -040013125 unformat_input_t *input = vam->input;
13126 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
13127 f64 timeout = ~0;
13128 u8 is_add = 1;
13129 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
13130 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
13131 u8 rmt_eid_set = 0, lcl_eid_set = 0;
13132 u32 action = ~0, p, w;
13133 ip4_address_t rmt_rloc4, lcl_rloc4;
13134 ip6_address_t rmt_rloc6, lcl_rloc6;
13135 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013136
Dave Barach839fe3e2016-08-10 11:35:54 -040013137 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020013138
Dave Barach72d72232016-08-04 10:15:08 -040013139 /* Parse args required to build the message */
13140 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13141 {
13142 if (unformat (input, "del"))
13143 {
13144 is_add = 0;
13145 }
13146 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
13147 {
13148 rmt_eid_set = 1;
13149 }
13150 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
13151 {
13152 lcl_eid_set = 1;
13153 }
13154 else if (unformat (input, "p %d w %d", &p, &w))
13155 {
13156 if (!curr_rloc)
13157 {
13158 errmsg ("No RLOC configured for setting priority/weight!");
13159 return -99;
13160 }
13161 curr_rloc->priority = p;
13162 curr_rloc->weight = w;
13163 }
13164 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
13165 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
13166 {
13167 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020013168
Dave Barach72d72232016-08-04 10:15:08 -040013169 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020013170 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013171 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013172
Dave Barach72d72232016-08-04 10:15:08 -040013173 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
13174 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013175 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013176 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13177 }
Florin Coras7fbfad32016-08-05 16:57:33 +020013178 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040013179 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
13180 {
13181 rloc.is_ip4 = 0;
13182 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020013183 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013184 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013185
Dave Barach72d72232016-08-04 10:15:08 -040013186 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
13187 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013188 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013189 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13190 }
13191 else if (unformat (input, "action %d", &action))
13192 {
13193 ;
13194 }
13195 else
13196 {
13197 clib_warning ("parse error '%U'", format_unformat_error, input);
13198 return -99;
13199 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013200 }
13201
Dave Barach72d72232016-08-04 10:15:08 -040013202 if (!rmt_eid_set)
13203 {
13204 errmsg ("remote eid addresses not set\n");
13205 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013206 }
13207
Dave Barach72d72232016-08-04 10:15:08 -040013208 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
13209 {
13210 errmsg ("eid types don't match\n");
13211 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013212 }
13213
Dave Barach839fe3e2016-08-10 11:35:54 -040013214 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020013215 {
13216 errmsg ("action not set for negative mapping\n");
13217 return -99;
13218 }
13219
Dave Barach72d72232016-08-04 10:15:08 -040013220 /* Construct the API message */
13221 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013222
Dave Barach72d72232016-08-04 10:15:08 -040013223 mp->is_add = is_add;
13224 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
13225 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
13226 mp->eid_type = rmt_eid->type;
13227 mp->rmt_len = rmt_eid->len;
13228 mp->lcl_len = lcl_eid->len;
13229 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020013230
Florin Coras7fbfad32016-08-05 16:57:33 +020013231 if (0 != rmt_locs && 0 != lcl_locs)
13232 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013233 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020013234 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013235 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013236 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013237 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013238 }
Dave Barach72d72232016-08-04 10:15:08 -040013239 vec_free (lcl_locs);
13240 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013241
Dave Barach72d72232016-08-04 10:15:08 -040013242 /* send it... */
13243 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013244
Dave Barach72d72232016-08-04 10:15:08 -040013245 /* Wait for a reply... */
13246 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013247
Dave Barach72d72232016-08-04 10:15:08 -040013248 /* NOTREACHED */
13249 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013250}
13251
13252static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013253api_lisp_add_del_map_server (vat_main_t * vam)
13254{
13255 unformat_input_t *input = vam->input;
13256 vl_api_lisp_add_del_map_server_t *mp;
13257 f64 timeout = ~0;
13258 u8 is_add = 1;
13259 u8 ipv4_set = 0;
13260 u8 ipv6_set = 0;
13261 ip4_address_t ipv4;
13262 ip6_address_t ipv6;
13263
13264 /* Parse args required to build the message */
13265 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13266 {
13267 if (unformat (input, "del"))
13268 {
13269 is_add = 0;
13270 }
13271 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13272 {
13273 ipv4_set = 1;
13274 }
13275 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13276 {
13277 ipv6_set = 1;
13278 }
13279 else
13280 break;
13281 }
13282
13283 if (ipv4_set && ipv6_set)
13284 {
13285 errmsg ("both eid v4 and v6 addresses set\n");
13286 return -99;
13287 }
13288
13289 if (!ipv4_set && !ipv6_set)
13290 {
13291 errmsg ("eid addresses not set\n");
13292 return -99;
13293 }
13294
13295 /* Construct the API message */
13296 M (LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server);
13297
13298 mp->is_add = is_add;
13299 if (ipv6_set)
13300 {
13301 mp->is_ipv6 = 1;
13302 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13303 }
13304 else
13305 {
13306 mp->is_ipv6 = 0;
13307 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
13308 }
13309
13310 /* send it... */
13311 S;
13312
13313 /* Wait for a reply... */
13314 W;
13315
13316 /* NOTREACHED */
13317 return 0;
13318}
13319
13320static int
Dave Barach72d72232016-08-04 10:15:08 -040013321api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013322{
Dave Barach72d72232016-08-04 10:15:08 -040013323 unformat_input_t *input = vam->input;
13324 vl_api_lisp_add_del_map_resolver_t *mp;
13325 f64 timeout = ~0;
13326 u8 is_add = 1;
13327 u8 ipv4_set = 0;
13328 u8 ipv6_set = 0;
13329 ip4_address_t ipv4;
13330 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013331
Dave Barach72d72232016-08-04 10:15:08 -040013332 /* Parse args required to build the message */
13333 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13334 {
13335 if (unformat (input, "del"))
13336 {
13337 is_add = 0;
13338 }
13339 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13340 {
13341 ipv4_set = 1;
13342 }
13343 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13344 {
13345 ipv6_set = 1;
13346 }
13347 else
13348 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013349 }
13350
Dave Barach72d72232016-08-04 10:15:08 -040013351 if (ipv4_set && ipv6_set)
13352 {
13353 errmsg ("both eid v4 and v6 addresses set\n");
13354 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013355 }
13356
Dave Barach72d72232016-08-04 10:15:08 -040013357 if (!ipv4_set && !ipv6_set)
13358 {
13359 errmsg ("eid addresses not set\n");
13360 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013361 }
13362
Dave Barach72d72232016-08-04 10:15:08 -040013363 /* Construct the API message */
13364 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013365
Dave Barach72d72232016-08-04 10:15:08 -040013366 mp->is_add = is_add;
13367 if (ipv6_set)
13368 {
13369 mp->is_ipv6 = 1;
13370 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13371 }
13372 else
13373 {
13374 mp->is_ipv6 = 0;
13375 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013376 }
13377
Dave Barach72d72232016-08-04 10:15:08 -040013378 /* send it... */
13379 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013380
Dave Barach72d72232016-08-04 10:15:08 -040013381 /* Wait for a reply... */
13382 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013383
Dave Barach72d72232016-08-04 10:15:08 -040013384 /* NOTREACHED */
13385 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013386}
13387
13388static int
Florin Coras577c3552016-04-21 00:45:40 +020013389api_lisp_gpe_enable_disable (vat_main_t * vam)
13390{
Dave Barach72d72232016-08-04 10:15:08 -040013391 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013392 vl_api_lisp_gpe_enable_disable_t *mp;
13393 f64 timeout = ~0;
13394 u8 is_set = 0;
13395 u8 is_en = 1;
13396
13397 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013398 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13399 {
13400 if (unformat (input, "enable"))
13401 {
13402 is_set = 1;
13403 is_en = 1;
13404 }
13405 else if (unformat (input, "disable"))
13406 {
13407 is_set = 1;
13408 is_en = 0;
13409 }
13410 else
13411 break;
13412 }
Florin Coras577c3552016-04-21 00:45:40 +020013413
Dave Barach72d72232016-08-04 10:15:08 -040013414 if (is_set == 0)
13415 {
13416 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013417 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013418 }
Florin Coras577c3552016-04-21 00:45:40 +020013419
13420 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013421 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013422
13423 mp->is_en = is_en;
13424
13425 /* send it... */
13426 S;
13427
13428 /* Wait for a reply... */
13429 W;
13430
13431 /* NOTREACHED */
13432 return 0;
13433}
13434
13435static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013436api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
13437{
13438 unformat_input_t *input = vam->input;
13439 vl_api_lisp_rloc_probe_enable_disable_t *mp;
13440 f64 timeout = ~0;
13441 u8 is_set = 0;
13442 u8 is_en = 0;
13443
13444 /* Parse args required to build the message */
13445 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13446 {
13447 if (unformat (input, "enable"))
13448 {
13449 is_set = 1;
13450 is_en = 1;
13451 }
13452 else if (unformat (input, "disable"))
13453 is_set = 1;
13454 else
13455 break;
13456 }
13457
13458 if (!is_set)
13459 {
13460 errmsg ("Value not set\n");
13461 return -99;
13462 }
13463
13464 /* Construct the API message */
13465 M (LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable);
13466
13467 mp->is_enabled = is_en;
13468
13469 /* send it... */
13470 S;
13471
13472 /* Wait for a reply... */
13473 W;
13474
13475 /* NOTREACHED */
13476 return 0;
13477}
13478
13479static int
13480api_lisp_map_register_enable_disable (vat_main_t * vam)
13481{
13482 unformat_input_t *input = vam->input;
13483 vl_api_lisp_map_register_enable_disable_t *mp;
13484 f64 timeout = ~0;
13485 u8 is_set = 0;
13486 u8 is_en = 0;
13487
13488 /* Parse args required to build the message */
13489 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13490 {
13491 if (unformat (input, "enable"))
13492 {
13493 is_set = 1;
13494 is_en = 1;
13495 }
13496 else if (unformat (input, "disable"))
13497 is_set = 1;
13498 else
13499 break;
13500 }
13501
13502 if (!is_set)
13503 {
13504 errmsg ("Value not set\n");
13505 return -99;
13506 }
13507
13508 /* Construct the API message */
13509 M (LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable);
13510
13511 mp->is_enabled = is_en;
13512
13513 /* send it... */
13514 S;
13515
13516 /* Wait for a reply... */
13517 W;
13518
13519 /* NOTREACHED */
13520 return 0;
13521}
13522
13523static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013524api_lisp_enable_disable (vat_main_t * vam)
13525{
Dave Barach72d72232016-08-04 10:15:08 -040013526 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013527 vl_api_lisp_enable_disable_t *mp;
13528 f64 timeout = ~0;
13529 u8 is_set = 0;
13530 u8 is_en = 0;
13531
13532 /* Parse args required to build the message */
13533 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13534 {
13535 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013536 {
13537 is_set = 1;
13538 is_en = 1;
13539 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013540 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013541 {
13542 is_set = 1;
13543 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013544 else
Dave Barach72d72232016-08-04 10:15:08 -040013545 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013546 }
13547
13548 if (!is_set)
13549 {
13550 errmsg ("Value not set\n");
13551 return -99;
13552 }
13553
13554 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013555 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013556
13557 mp->is_en = is_en;
13558
13559 /* send it... */
13560 S;
13561
13562 /* Wait for a reply... */
13563 W;
13564
13565 /* NOTREACHED */
13566 return 0;
13567}
13568
Florin Corasdca88042016-09-14 16:01:38 +020013569static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013570api_show_lisp_map_register_state (vat_main_t * vam)
13571{
13572 f64 timeout = ~0;
13573 vl_api_show_lisp_map_register_state_t *mp;
13574
13575 M (SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state);
13576
13577 /* send */
13578 S;
13579
13580 /* wait for reply */
13581 W;
13582
13583 return 0;
13584}
13585
13586static int
13587api_show_lisp_rloc_probe_state (vat_main_t * vam)
13588{
13589 f64 timeout = ~0;
13590 vl_api_show_lisp_rloc_probe_state_t *mp;
13591
13592 M (SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state);
13593
13594 /* send */
13595 S;
13596
13597 /* wait for reply */
13598 W;
13599
13600 return 0;
13601}
13602
13603static int
Florin Corasdca88042016-09-14 16:01:38 +020013604api_show_lisp_map_request_mode (vat_main_t * vam)
13605{
13606 f64 timeout = ~0;
13607 vl_api_show_lisp_map_request_mode_t *mp;
13608
13609 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13610
13611 /* send */
13612 S;
13613
13614 /* wait for reply */
13615 W;
13616
13617 return 0;
13618}
13619
13620static int
13621api_lisp_map_request_mode (vat_main_t * vam)
13622{
13623 f64 timeout = ~0;
13624 unformat_input_t *input = vam->input;
13625 vl_api_lisp_map_request_mode_t *mp;
13626 u8 mode = 0;
13627
13628 /* Parse args required to build the message */
13629 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13630 {
13631 if (unformat (input, "dst-only"))
13632 mode = 0;
13633 else if (unformat (input, "src-dst"))
13634 mode = 1;
13635 else
13636 {
13637 errmsg ("parse error '%U'", format_unformat_error, input);
13638 return -99;
13639 }
13640 }
13641
13642 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13643
13644 mp->mode = mode;
13645
13646 /* send */
13647 S;
13648
13649 /* wait for reply */
13650 W;
13651
13652 /* notreached */
13653 return 0;
13654}
13655
Filip Tehlar195bcee2016-05-13 17:37:35 +020013656/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013657 * Enable/disable LISP proxy ITR.
13658 *
13659 * @param vam vpp API test context
13660 * @return return code
13661 */
13662static int
13663api_lisp_pitr_set_locator_set (vat_main_t * vam)
13664{
13665 f64 timeout = ~0;
13666 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013667 unformat_input_t *input = vam->input;
13668 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013669 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013670 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013671
13672 /* Parse args required to build the message */
13673 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13674 {
13675 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013676 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013677 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013678 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013679 else
Dave Barach72d72232016-08-04 10:15:08 -040013680 {
13681 errmsg ("parse error '%U'", format_unformat_error, input);
13682 return -99;
13683 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013684 }
13685
13686 if (!ls_name_set)
13687 {
13688 errmsg ("locator-set name not set!");
13689 return -99;
13690 }
13691
Dave Barach72d72232016-08-04 10:15:08 -040013692 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013693
13694 mp->is_add = is_add;
13695 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13696 vec_free (ls_name);
13697
13698 /* send */
13699 S;
13700
13701 /* wait for reply */
13702 W;
13703
Dave Barach72d72232016-08-04 10:15:08 -040013704 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013705 return 0;
13706}
13707
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013708static int
13709api_show_lisp_pitr (vat_main_t * vam)
13710{
Dave Barach72d72232016-08-04 10:15:08 -040013711 vl_api_show_lisp_pitr_t *mp;
13712 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013713
Dave Barach72d72232016-08-04 10:15:08 -040013714 if (!vam->json_output)
13715 {
13716 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013717 }
13718
Dave Barach72d72232016-08-04 10:15:08 -040013719 M (SHOW_LISP_PITR, show_lisp_pitr);
13720 /* send it... */
13721 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013722
Dave Barach72d72232016-08-04 10:15:08 -040013723 /* Wait for a reply... */
13724 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013725
Dave Barach72d72232016-08-04 10:15:08 -040013726 /* NOTREACHED */
13727 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013728}
13729
Filip Tehlar53f09e32016-05-19 14:25:44 +020013730/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013731 * Add/delete mapping between vni and vrf
13732 */
13733static int
13734api_lisp_eid_table_add_del_map (vat_main_t * vam)
13735{
13736 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013737 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013738 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013739 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13740 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013741
13742 /* Parse args required to build the message */
13743 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13744 {
13745 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013746 is_add = 0;
13747 else if (unformat (input, "vrf %d", &vrf))
13748 vrf_set = 1;
13749 else if (unformat (input, "bd_index %d", &bd_index))
13750 bd_index_set = 1;
13751 else if (unformat (input, "vni %d", &vni))
13752 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013753 else
Dave Barach72d72232016-08-04 10:15:08 -040013754 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013755 }
13756
Florin Coras1a1adc72016-07-22 01:45:30 +020013757 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013758 {
13759 errmsg ("missing arguments!");
13760 return -99;
13761 }
13762
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013763 if (vrf_set && bd_index_set)
13764 {
13765 errmsg ("error: both vrf and bd entered!");
13766 return -99;
13767 }
13768
Dave Barach72d72232016-08-04 10:15:08 -040013769 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013770
13771 mp->is_add = is_add;
13772 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013773 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013774 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013775
13776 /* send */
13777 S;
13778
13779 /* wait for reply */
13780 W;
13781
Dave Barach72d72232016-08-04 10:15:08 -040013782 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013783 return 0;
13784}
13785
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013786uword
13787unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13788{
13789 u32 *action = va_arg (*args, u32 *);
13790 u8 *s = 0;
13791
13792 if (unformat (input, "%s", &s))
13793 {
13794 if (!strcmp ((char *) s, "no-action"))
13795 action[0] = 0;
13796 else if (!strcmp ((char *) s, "natively-forward"))
13797 action[0] = 1;
13798 else if (!strcmp ((char *) s, "send-map-request"))
13799 action[0] = 2;
13800 else if (!strcmp ((char *) s, "drop"))
13801 action[0] = 3;
13802 else
13803 {
13804 clib_warning ("invalid action: '%s'", s);
13805 action[0] = 3;
13806 }
13807 }
13808 else
13809 return 0;
13810
13811 vec_free (s);
13812 return 1;
13813}
13814
Filip Tehlar324112f2016-06-02 16:07:38 +020013815/**
Florin Corasf727db92016-06-23 15:01:58 +020013816 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013817 *
13818 * @param vam vpp API test context
13819 * @return return code
13820 */
13821static int
13822api_lisp_add_del_remote_mapping (vat_main_t * vam)
13823{
Dave Barach72d72232016-08-04 10:15:08 -040013824 unformat_input_t *input = vam->input;
13825 vl_api_lisp_add_del_remote_mapping_t *mp;
13826 f64 timeout = ~0;
13827 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013828 lisp_eid_vat_t _eid, *eid = &_eid;
13829 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013830 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013831 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013832 ip4_address_t rloc4;
13833 ip6_address_t rloc6;
13834 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013835
Dave Barach839fe3e2016-08-10 11:35:54 -040013836 memset (&rloc, 0, sizeof (rloc));
13837
Dave Barach72d72232016-08-04 10:15:08 -040013838 /* Parse args required to build the message */
13839 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13840 {
13841 if (unformat (input, "del-all"))
13842 {
13843 del_all = 1;
13844 }
13845 else if (unformat (input, "del"))
13846 {
13847 is_add = 0;
13848 }
13849 else if (unformat (input, "add"))
13850 {
13851 is_add = 1;
13852 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013853 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013854 {
13855 eid_set = 1;
13856 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013857 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013858 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013859 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013860 }
13861 else if (unformat (input, "vni %d", &vni))
13862 {
13863 ;
13864 }
13865 else if (unformat (input, "p %d w %d", &p, &w))
13866 {
13867 if (!curr_rloc)
13868 {
13869 errmsg ("No RLOC configured for setting priority/weight!");
13870 return -99;
13871 }
13872 curr_rloc->priority = p;
13873 curr_rloc->weight = w;
13874 }
13875 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13876 {
13877 rloc.is_ip4 = 1;
13878 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13879 vec_add1 (rlocs, rloc);
13880 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13881 }
13882 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13883 {
13884 rloc.is_ip4 = 0;
13885 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13886 vec_add1 (rlocs, rloc);
13887 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13888 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013889 else if (unformat (input, "action %U",
13890 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013891 {
13892 ;
13893 }
13894 else
13895 {
13896 clib_warning ("parse error '%U'", format_unformat_error, input);
13897 return -99;
13898 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013899 }
13900
Dave Barach72d72232016-08-04 10:15:08 -040013901 if (0 == eid_set)
13902 {
13903 errmsg ("missing params!");
13904 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013905 }
13906
Dave Barach72d72232016-08-04 10:15:08 -040013907 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13908 {
13909 errmsg ("no action set for negative map-reply!");
13910 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013911 }
13912
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013913 data_len = vec_len (rlocs) * sizeof (rloc_t);
13914
13915 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013916 mp->is_add = is_add;
13917 mp->vni = htonl (vni);
13918 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013919 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013920 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013921 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013922 mp->del_all = del_all;
13923 mp->eid_type = eid->type;
13924 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013925 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013926
Filip Tehlare3552c42016-08-26 12:44:38 +020013927 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013928 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013929 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013930
Dave Barach72d72232016-08-04 10:15:08 -040013931 /* send it... */
13932 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013933
Dave Barach72d72232016-08-04 10:15:08 -040013934 /* Wait for a reply... */
13935 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013936
Dave Barach72d72232016-08-04 10:15:08 -040013937 /* NOTREACHED */
13938 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013939}
13940
Florin Corasf727db92016-06-23 15:01:58 +020013941/**
13942 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13943 * forwarding entries in data-plane accordingly.
13944 *
13945 * @param vam vpp API test context
13946 * @return return code
13947 */
13948static int
13949api_lisp_add_del_adjacency (vat_main_t * vam)
13950{
Dave Barach72d72232016-08-04 10:15:08 -040013951 unformat_input_t *input = vam->input;
13952 vl_api_lisp_add_del_adjacency_t *mp;
13953 f64 timeout = ~0;
13954 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013955 ip4_address_t leid4, reid4;
13956 ip6_address_t leid6, reid6;
13957 u8 reid_mac[6] = { 0 };
13958 u8 leid_mac[6] = { 0 };
13959 u8 reid_type, leid_type;
13960 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013961 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013962
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013963 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013964
Dave Barach72d72232016-08-04 10:15:08 -040013965 /* Parse args required to build the message */
13966 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13967 {
13968 if (unformat (input, "del"))
13969 {
13970 is_add = 0;
13971 }
13972 else if (unformat (input, "add"))
13973 {
13974 is_add = 1;
13975 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013976 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13977 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013978 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013979 reid_type = 0; /* ipv4 */
13980 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013981 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013982 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13983 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013984 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013985 reid_type = 1; /* ipv6 */
13986 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013987 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013988 else if (unformat (input, "reid %U", unformat_ethernet_address,
13989 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013990 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013991 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013992 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013993 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13994 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013995 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013996 leid_type = 0; /* ipv4 */
13997 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013998 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013999 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
14000 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014001 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014002 leid_type = 1; /* ipv6 */
14003 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014004 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014005 else if (unformat (input, "leid %U", unformat_ethernet_address,
14006 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040014007 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014008 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040014009 }
14010 else if (unformat (input, "vni %d", &vni))
14011 {
14012 ;
14013 }
14014 else
14015 {
14016 errmsg ("parse error '%U'", format_unformat_error, input);
14017 return -99;
14018 }
Florin Corasf727db92016-06-23 15:01:58 +020014019 }
14020
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014021 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014022 {
14023 errmsg ("missing params!");
14024 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014025 }
14026
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014027 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014028 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014029 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040014030 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014031 }
14032
Dave Barach72d72232016-08-04 10:15:08 -040014033 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
14034 mp->is_add = is_add;
14035 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014036 mp->leid_len = leid_len;
14037 mp->reid_len = reid_len;
14038 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020014039
Dave Barach72d72232016-08-04 10:15:08 -040014040 switch (mp->eid_type)
14041 {
Florin Corasf727db92016-06-23 15:01:58 +020014042 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014043 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
14044 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040014045 break;
Florin Corasf727db92016-06-23 15:01:58 +020014046 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014047 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
14048 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040014049 break;
Florin Corasf727db92016-06-23 15:01:58 +020014050 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014051 clib_memcpy (mp->leid, leid_mac, 6);
14052 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040014053 break;
Florin Corasf727db92016-06-23 15:01:58 +020014054 default:
Dave Barach72d72232016-08-04 10:15:08 -040014055 errmsg ("unknown EID type %d!", mp->eid_type);
14056 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014057 }
14058
Dave Barach72d72232016-08-04 10:15:08 -040014059 /* send it... */
14060 S;
Florin Corasf727db92016-06-23 15:01:58 +020014061
Dave Barach72d72232016-08-04 10:15:08 -040014062 /* Wait for a reply... */
14063 W;
Florin Corasf727db92016-06-23 15:01:58 +020014064
Dave Barach72d72232016-08-04 10:15:08 -040014065 /* NOTREACHED */
14066 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014067}
14068
Filip Tehlar46d4e362016-05-09 09:39:26 +020014069static int
Dave Barach72d72232016-08-04 10:15:08 -040014070api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014071{
Dave Barach72d72232016-08-04 10:15:08 -040014072 unformat_input_t *input = vam->input;
14073 vl_api_lisp_gpe_add_del_iface_t *mp;
14074 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020014075 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040014076 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014077
Dave Barach72d72232016-08-04 10:15:08 -040014078 /* Parse args required to build the message */
14079 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14080 {
14081 if (unformat (input, "up"))
14082 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014083 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014084 is_add = 1;
14085 }
14086 else if (unformat (input, "down"))
14087 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014088 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014089 is_add = 0;
14090 }
14091 else if (unformat (input, "table_id %d", &dp_table))
14092 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014093 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014094 }
14095 else if (unformat (input, "bd_id %d", &dp_table))
14096 {
Dave Barach839fe3e2016-08-10 11:35:54 -040014097 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014098 is_l2 = 1;
14099 }
14100 else if (unformat (input, "vni %d", &vni))
14101 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014102 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014103 }
14104 else
14105 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014106 }
14107
Florin Coras7fbfad32016-08-05 16:57:33 +020014108 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040014109 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014110 errmsg ("Action not set\n");
14111 return -99;
14112 }
14113 if (dp_table_set == 0 || vni_set == 0)
14114 {
14115 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040014116 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014117 }
14118
Dave Barach72d72232016-08-04 10:15:08 -040014119 /* Construct the API message */
14120 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014121
Dave Barach72d72232016-08-04 10:15:08 -040014122 mp->is_add = is_add;
14123 mp->dp_table = dp_table;
14124 mp->is_l2 = is_l2;
14125 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014126
Dave Barach72d72232016-08-04 10:15:08 -040014127 /* send it... */
14128 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014129
Dave Barach72d72232016-08-04 10:15:08 -040014130 /* Wait for a reply... */
14131 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014132
Dave Barach72d72232016-08-04 10:15:08 -040014133 /* NOTREACHED */
14134 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014135}
14136
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014137/**
14138 * Add/del map request itr rlocs from LISP control plane and updates
14139 *
14140 * @param vam vpp API test context
14141 * @return return code
14142 */
14143static int
Dave Barach72d72232016-08-04 10:15:08 -040014144api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014145{
Dave Barach72d72232016-08-04 10:15:08 -040014146 unformat_input_t *input = vam->input;
14147 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
14148 f64 timeout = ~0;
14149 u8 *locator_set_name = 0;
14150 u8 locator_set_name_set = 0;
14151 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014152
Dave Barach72d72232016-08-04 10:15:08 -040014153 /* Parse args required to build the message */
14154 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014155 {
Dave Barach72d72232016-08-04 10:15:08 -040014156 if (unformat (input, "del"))
14157 {
14158 is_add = 0;
14159 }
14160 else if (unformat (input, "%_%v%_", &locator_set_name))
14161 {
14162 locator_set_name_set = 1;
14163 }
14164 else
14165 {
14166 clib_warning ("parse error '%U'", format_unformat_error, input);
14167 return -99;
14168 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014169 }
14170
Dave Barach72d72232016-08-04 10:15:08 -040014171 if (is_add && !locator_set_name_set)
14172 {
14173 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020014174 return -99;
14175 }
14176
Dave Barach72d72232016-08-04 10:15:08 -040014177 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020014178 {
Dave Barach72d72232016-08-04 10:15:08 -040014179 errmsg ("itr-rloc locator-set name too long\n");
14180 vec_free (locator_set_name);
14181 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014182 }
14183
Dave Barach72d72232016-08-04 10:15:08 -040014184 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
14185 mp->is_add = is_add;
14186 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014187 {
Dave Barach72d72232016-08-04 10:15:08 -040014188 clib_memcpy (mp->locator_set_name, locator_set_name,
14189 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014190 }
Dave Barach72d72232016-08-04 10:15:08 -040014191 else
14192 {
14193 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014194 }
Dave Barach72d72232016-08-04 10:15:08 -040014195 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014196
Dave Barach72d72232016-08-04 10:15:08 -040014197 /* send it... */
14198 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014199
Dave Barach72d72232016-08-04 10:15:08 -040014200 /* Wait for a reply... */
14201 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014202
Dave Barach72d72232016-08-04 10:15:08 -040014203 /* NOTREACHED */
14204 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014205}
14206
14207static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014208api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014209{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014210 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014211 vl_api_lisp_locator_dump_t *mp;
14212 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014213 u8 is_index_set = 0, is_name_set = 0;
14214 u8 *ls_name = 0;
14215 u32 ls_index = ~0;
14216
14217 /* Parse args required to build the message */
14218 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14219 {
14220 if (unformat (input, "ls_name %_%v%_", &ls_name))
14221 {
14222 is_name_set = 1;
14223 }
14224 else if (unformat (input, "ls_index %d", &ls_index))
14225 {
14226 is_index_set = 1;
14227 }
14228 else
14229 {
14230 errmsg ("parse error '%U'", format_unformat_error, input);
14231 return -99;
14232 }
14233 }
14234
14235 if (!is_index_set && !is_name_set)
14236 {
14237 errmsg ("error: expected one of index or name!\n");
14238 return -99;
14239 }
14240
14241 if (is_index_set && is_name_set)
14242 {
14243 errmsg ("error: only one param expected!\n");
14244 return -99;
14245 }
14246
Florin Coras042d2122016-09-21 16:38:19 +020014247 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020014248 {
14249 errmsg ("error: locator set name too long!");
14250 return -99;
14251 }
14252
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014253 if (!vam->json_output)
14254 {
14255 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
14256 "weight");
14257 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014258
Dave Barach72d72232016-08-04 10:15:08 -040014259 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014260 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014261
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014262 if (is_index_set)
14263 mp->ls_index = clib_host_to_net_u32 (ls_index);
14264 else
14265 {
14266 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020014267 strncpy ((char *) mp->ls_name, (char *) ls_name,
14268 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014269 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014270
Dave Barach72d72232016-08-04 10:15:08 -040014271 /* send it... */
14272 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014273
Dave Barach72d72232016-08-04 10:15:08 -040014274 /* Use a control ping for synchronization */
14275 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014276 vl_api_control_ping_t *mp;
14277 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014278 S;
14279 }
14280 /* Wait for a reply... */
14281 W;
Dave Barach72d72232016-08-04 10:15:08 -040014282
14283 /* NOTREACHED */
14284 return 0;
14285}
14286
14287static int
14288api_lisp_locator_set_dump (vat_main_t * vam)
14289{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014290 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014291 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014292 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040014293 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040014294
14295 /* Parse args required to build the message */
14296 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14297 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014298 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040014299 {
14300 filter = 1;
14301 }
14302 else if (unformat (input, "remote"))
14303 {
14304 filter = 2;
14305 }
14306 else
14307 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014308 errmsg ("parse error '%U'", format_unformat_error, input);
14309 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040014310 }
14311 }
14312
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014313 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040014314 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014315 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040014316 }
14317
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014318 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014319
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014320 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040014321
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014322 /* send it... */
14323 S;
14324
14325 /* Use a control ping for synchronization */
14326 {
14327 vl_api_control_ping_t *mp;
14328 M (CONTROL_PING, control_ping);
14329 S;
14330 }
14331 /* Wait for a reply... */
14332 W;
14333
14334 /* NOTREACHED */
14335 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040014336}
14337
14338static int
14339api_lisp_eid_table_map_dump (vat_main_t * vam)
14340{
Filip Tehlarc0681792016-08-24 14:11:07 +020014341 u8 is_l2 = 0;
14342 u8 mode_set = 0;
14343 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014344 vl_api_lisp_eid_table_map_dump_t *mp;
14345 f64 timeout = ~0;
14346
Filip Tehlarc0681792016-08-24 14:11:07 +020014347 /* Parse args required to build the message */
14348 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14349 {
14350 if (unformat (input, "l2"))
14351 {
14352 is_l2 = 1;
14353 mode_set = 1;
14354 }
14355 else if (unformat (input, "l3"))
14356 {
14357 is_l2 = 0;
14358 mode_set = 1;
14359 }
14360 else
14361 {
14362 errmsg ("parse error '%U'", format_unformat_error, input);
14363 return -99;
14364 }
14365 }
14366
14367 if (!mode_set)
14368 {
14369 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
14370 return -99;
14371 }
14372
Dave Barach72d72232016-08-04 10:15:08 -040014373 if (!vam->json_output)
14374 {
Filip Tehlarc0681792016-08-24 14:11:07 +020014375 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040014376 }
14377
14378 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020014379 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040014380
14381 /* send it... */
14382 S;
14383
14384 /* Use a control ping for synchronization */
14385 {
14386 vl_api_control_ping_t *mp;
14387 M (CONTROL_PING, control_ping);
14388 S;
14389 }
14390 /* Wait for a reply... */
14391 W;
14392
14393 /* NOTREACHED */
14394 return 0;
14395}
14396
14397static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020014398api_lisp_eid_table_vni_dump (vat_main_t * vam)
14399{
14400 vl_api_lisp_eid_table_vni_dump_t *mp;
14401 f64 timeout = ~0;
14402
14403 if (!vam->json_output)
14404 {
14405 fformat (vam->ofp, "VNI\n");
14406 }
14407
14408 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
14409
14410 /* send it... */
14411 S;
14412
14413 /* Use a control ping for synchronization */
14414 {
14415 vl_api_control_ping_t *mp;
14416 M (CONTROL_PING, control_ping);
14417 S;
14418 }
14419 /* Wait for a reply... */
14420 W;
14421
14422 /* NOTREACHED */
14423 return 0;
14424}
14425
14426static int
Dave Barach72d72232016-08-04 10:15:08 -040014427api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014428{
Dave Barach72d72232016-08-04 10:15:08 -040014429 unformat_input_t *i = vam->input;
14430 vl_api_lisp_eid_table_dump_t *mp;
14431 f64 timeout = ~0;
14432 struct in_addr ip4;
14433 struct in6_addr ip6;
14434 u8 mac[6];
14435 u8 eid_type = ~0, eid_set = 0;
14436 u32 prefix_length = ~0, t, vni = 0;
14437 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014438
Dave Barach72d72232016-08-04 10:15:08 -040014439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014440 {
Dave Barach72d72232016-08-04 10:15:08 -040014441 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14442 {
14443 eid_set = 1;
14444 eid_type = 0;
14445 prefix_length = t;
14446 }
14447 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14448 {
14449 eid_set = 1;
14450 eid_type = 1;
14451 prefix_length = t;
14452 }
14453 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14454 {
14455 eid_set = 1;
14456 eid_type = 2;
14457 }
14458 else if (unformat (i, "vni %d", &t))
14459 {
14460 vni = t;
14461 }
14462 else if (unformat (i, "local"))
14463 {
14464 filter = 1;
14465 }
14466 else if (unformat (i, "remote"))
14467 {
14468 filter = 2;
14469 }
14470 else
14471 {
14472 errmsg ("parse error '%U'", format_unformat_error, i);
14473 return -99;
14474 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014475 }
14476
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014477 if (!vam->json_output)
14478 {
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014479 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s\n", "EID",
14480 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014481 }
14482
Dave Barach72d72232016-08-04 10:15:08 -040014483 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014484
Dave Barach72d72232016-08-04 10:15:08 -040014485 mp->filter = filter;
14486 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014487 {
Dave Barach72d72232016-08-04 10:15:08 -040014488 mp->eid_set = 1;
14489 mp->vni = htonl (vni);
14490 mp->eid_type = eid_type;
14491 switch (eid_type)
14492 {
14493 case 0:
14494 mp->prefix_length = prefix_length;
14495 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14496 break;
14497 case 1:
14498 mp->prefix_length = prefix_length;
14499 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14500 break;
14501 case 2:
14502 clib_memcpy (mp->eid, mac, sizeof (mac));
14503 break;
14504 default:
14505 errmsg ("unknown EID type %d!", eid_type);
14506 return -99;
14507 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014508 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014509
Dave Barach72d72232016-08-04 10:15:08 -040014510 /* send it... */
14511 S;
14512
14513 /* Use a control ping for synchronization */
14514 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014515 vl_api_control_ping_t *mp;
14516 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014517 S;
14518 }
14519
14520 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014521 W;
Dave Barach72d72232016-08-04 10:15:08 -040014522
14523 /* NOTREACHED */
14524 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014525}
14526
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014527static int
Dave Barach72d72232016-08-04 10:15:08 -040014528api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014529{
Dave Barach72d72232016-08-04 10:15:08 -040014530 vl_api_lisp_gpe_tunnel_dump_t *mp;
14531 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014532
Dave Barach72d72232016-08-04 10:15:08 -040014533 if (!vam->json_output)
14534 {
14535 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14536 "%=16s%=16s%=16s%=16s%=16s\n",
14537 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14538 "Decap next", "Lisp version", "Flags", "Next protocol",
14539 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014540 }
14541
Dave Barach72d72232016-08-04 10:15:08 -040014542 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14543 /* send it... */
14544 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014545
Dave Barach72d72232016-08-04 10:15:08 -040014546 /* Use a control ping for synchronization */
14547 {
14548 vl_api_control_ping_t *mp;
14549 M (CONTROL_PING, control_ping);
14550 S;
14551 }
14552 /* Wait for a reply... */
14553 W;
14554
14555 /* NOTREACHED */
14556 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014557}
14558
Matus Fabian8a95a482016-05-06 15:14:13 +020014559static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014560api_lisp_adjacencies_get (vat_main_t * vam)
14561{
14562 unformat_input_t *i = vam->input;
14563 vl_api_lisp_adjacencies_get_t *mp;
14564 f64 timeout = ~0;
14565 u8 vni_set = 0;
14566 u32 vni = ~0;
14567
14568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14569 {
14570 if (unformat (i, "vni %d", &vni))
14571 {
14572 vni_set = 1;
14573 }
14574 else
14575 {
14576 errmsg ("parse error '%U'\n", format_unformat_error, i);
14577 return -99;
14578 }
14579 }
14580
14581 if (!vni_set)
14582 {
14583 errmsg ("vni not set!\n");
14584 return -99;
14585 }
14586
14587 if (!vam->json_output)
14588 {
14589 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14590 }
14591
14592 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14593 mp->vni = clib_host_to_net_u32 (vni);
14594
14595 /* send it... */
14596 S;
14597
14598 /* Wait for a reply... */
14599 W;
14600
14601 /* NOTREACHED */
14602 return 0;
14603}
14604
14605static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014606api_lisp_map_server_dump (vat_main_t * vam)
14607{
14608 vl_api_lisp_map_server_dump_t *mp;
14609 f64 timeout = ~0;
14610
14611 if (!vam->json_output)
14612 {
14613 fformat (vam->ofp, "%=20s\n", "Map server");
14614 }
14615
14616 M (LISP_MAP_SERVER_DUMP, lisp_map_server_dump);
14617 /* send it... */
14618 S;
14619
14620 /* Use a control ping for synchronization */
14621 {
14622 vl_api_control_ping_t *mp;
14623 M (CONTROL_PING, control_ping);
14624 S;
14625 }
14626 /* Wait for a reply... */
14627 W;
14628
14629 /* NOTREACHED */
14630 return 0;
14631}
14632
14633static int
Dave Barach72d72232016-08-04 10:15:08 -040014634api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014635{
Dave Barach72d72232016-08-04 10:15:08 -040014636 vl_api_lisp_map_resolver_dump_t *mp;
14637 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014638
Dave Barach72d72232016-08-04 10:15:08 -040014639 if (!vam->json_output)
14640 {
14641 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014642 }
14643
Dave Barach72d72232016-08-04 10:15:08 -040014644 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14645 /* send it... */
14646 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014647
Dave Barach72d72232016-08-04 10:15:08 -040014648 /* Use a control ping for synchronization */
14649 {
14650 vl_api_control_ping_t *mp;
14651 M (CONTROL_PING, control_ping);
14652 S;
14653 }
14654 /* Wait for a reply... */
14655 W;
14656
14657 /* NOTREACHED */
14658 return 0;
14659}
14660
14661static int
14662api_show_lisp_status (vat_main_t * vam)
14663{
14664 vl_api_show_lisp_status_t *mp;
14665 f64 timeout = ~0;
14666
14667 if (!vam->json_output)
14668 {
14669 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14670 }
14671
14672 M (SHOW_LISP_STATUS, show_lisp_status);
14673 /* send it... */
14674 S;
14675 /* Wait for a reply... */
14676 W;
14677
14678 /* NOTREACHED */
14679 return 0;
14680}
14681
14682static int
14683api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14684{
14685 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14686 f64 timeout = ~0;
14687
14688 if (!vam->json_output)
14689 {
14690 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14691 }
14692
14693 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14694 /* send it... */
14695 S;
14696 /* Wait for a reply... */
14697 W;
14698
14699 /* NOTREACHED */
14700 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014701}
14702
14703static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014704api_af_packet_create (vat_main_t * vam)
14705{
Dave Barach72d72232016-08-04 10:15:08 -040014706 unformat_input_t *i = vam->input;
14707 vl_api_af_packet_create_t *mp;
14708 f64 timeout;
14709 u8 *host_if_name = 0;
14710 u8 hw_addr[6];
14711 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014712
Dave Barach72d72232016-08-04 10:15:08 -040014713 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014714
Dave Barach72d72232016-08-04 10:15:08 -040014715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14716 {
14717 if (unformat (i, "name %s", &host_if_name))
14718 vec_add1 (host_if_name, 0);
14719 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14720 random_hw_addr = 0;
14721 else
14722 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014723 }
14724
Dave Barach72d72232016-08-04 10:15:08 -040014725 if (!vec_len (host_if_name))
14726 {
14727 errmsg ("host-interface name must be specified");
14728 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014729 }
14730
Dave Barach72d72232016-08-04 10:15:08 -040014731 if (vec_len (host_if_name) > 64)
14732 {
14733 errmsg ("host-interface name too long");
14734 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014735 }
14736
Dave Barach72d72232016-08-04 10:15:08 -040014737 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014738
Dave Barach72d72232016-08-04 10:15:08 -040014739 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14740 clib_memcpy (mp->hw_addr, hw_addr, 6);
14741 mp->use_random_hw_addr = random_hw_addr;
14742 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014743
Dave Barach72d72232016-08-04 10:15:08 -040014744 S;
14745 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14746 /* NOTREACHED */
14747 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014748}
14749
14750static int
14751api_af_packet_delete (vat_main_t * vam)
14752{
Dave Barach72d72232016-08-04 10:15:08 -040014753 unformat_input_t *i = vam->input;
14754 vl_api_af_packet_delete_t *mp;
14755 f64 timeout;
14756 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014757
Dave Barach72d72232016-08-04 10:15:08 -040014758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14759 {
14760 if (unformat (i, "name %s", &host_if_name))
14761 vec_add1 (host_if_name, 0);
14762 else
14763 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014764 }
14765
Dave Barach72d72232016-08-04 10:15:08 -040014766 if (!vec_len (host_if_name))
14767 {
14768 errmsg ("host-interface name must be specified");
14769 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014770 }
14771
Dave Barach72d72232016-08-04 10:15:08 -040014772 if (vec_len (host_if_name) > 64)
14773 {
14774 errmsg ("host-interface name too long");
14775 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014776 }
14777
Dave Barach72d72232016-08-04 10:15:08 -040014778 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014779
Dave Barach72d72232016-08-04 10:15:08 -040014780 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14781 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014782
Dave Barach72d72232016-08-04 10:15:08 -040014783 S;
14784 W;
14785 /* NOTREACHED */
14786 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014787}
14788
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014789static int
14790api_policer_add_del (vat_main_t * vam)
14791{
Dave Barach72d72232016-08-04 10:15:08 -040014792 unformat_input_t *i = vam->input;
14793 vl_api_policer_add_del_t *mp;
14794 f64 timeout;
14795 u8 is_add = 1;
14796 u8 *name = 0;
14797 u32 cir = 0;
14798 u32 eir = 0;
14799 u64 cb = 0;
14800 u64 eb = 0;
14801 u8 rate_type = 0;
14802 u8 round_type = 0;
14803 u8 type = 0;
14804 u8 color_aware = 0;
14805 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014806
Dave Barach839fe3e2016-08-10 11:35:54 -040014807 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14808 conform_action.dscp = 0;
14809 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14810 exceed_action.dscp = 0;
14811 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14812 violate_action.dscp = 0;
14813
Dave Barach72d72232016-08-04 10:15:08 -040014814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14815 {
14816 if (unformat (i, "del"))
14817 is_add = 0;
14818 else if (unformat (i, "name %s", &name))
14819 vec_add1 (name, 0);
14820 else if (unformat (i, "cir %u", &cir))
14821 ;
14822 else if (unformat (i, "eir %u", &eir))
14823 ;
14824 else if (unformat (i, "cb %u", &cb))
14825 ;
14826 else if (unformat (i, "eb %u", &eb))
14827 ;
14828 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14829 &rate_type))
14830 ;
14831 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14832 &round_type))
14833 ;
14834 else if (unformat (i, "type %U", unformat_policer_type, &type))
14835 ;
14836 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14837 &conform_action))
14838 ;
14839 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14840 &exceed_action))
14841 ;
14842 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14843 &violate_action))
14844 ;
14845 else if (unformat (i, "color-aware"))
14846 color_aware = 1;
14847 else
14848 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014849 }
14850
Dave Barach72d72232016-08-04 10:15:08 -040014851 if (!vec_len (name))
14852 {
14853 errmsg ("policer name must be specified");
14854 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014855 }
14856
Dave Barach72d72232016-08-04 10:15:08 -040014857 if (vec_len (name) > 64)
14858 {
14859 errmsg ("policer name too long");
14860 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014861 }
14862
Dave Barach72d72232016-08-04 10:15:08 -040014863 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014864
Dave Barach72d72232016-08-04 10:15:08 -040014865 clib_memcpy (mp->name, name, vec_len (name));
14866 vec_free (name);
14867 mp->is_add = is_add;
14868 mp->cir = cir;
14869 mp->eir = eir;
14870 mp->cb = cb;
14871 mp->eb = eb;
14872 mp->rate_type = rate_type;
14873 mp->round_type = round_type;
14874 mp->type = type;
14875 mp->conform_action_type = conform_action.action_type;
14876 mp->conform_dscp = conform_action.dscp;
14877 mp->exceed_action_type = exceed_action.action_type;
14878 mp->exceed_dscp = exceed_action.dscp;
14879 mp->violate_action_type = violate_action.action_type;
14880 mp->violate_dscp = violate_action.dscp;
14881 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014882
Dave Barach72d72232016-08-04 10:15:08 -040014883 S;
14884 W;
14885 /* NOTREACHED */
14886 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014887}
14888
Matus Fabian82e29c42016-05-11 04:49:46 -070014889static int
Dave Barach72d72232016-08-04 10:15:08 -040014890api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014891{
Dave Barach72d72232016-08-04 10:15:08 -040014892 unformat_input_t *i = vam->input;
14893 vl_api_policer_dump_t *mp;
14894 f64 timeout = ~0;
14895 u8 *match_name = 0;
14896 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014897
Dave Barach72d72232016-08-04 10:15:08 -040014898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014899 {
Dave Barach72d72232016-08-04 10:15:08 -040014900 if (unformat (i, "name %s", &match_name))
14901 {
14902 vec_add1 (match_name, 0);
14903 match_name_valid = 1;
14904 }
14905 else
14906 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014907 }
Matus Fabiane8554802016-05-18 23:40:37 -070014908
Dave Barach72d72232016-08-04 10:15:08 -040014909 M (POLICER_DUMP, policer_dump);
14910 mp->match_name_valid = match_name_valid;
14911 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14912 vec_free (match_name);
14913 /* send it... */
14914 S;
14915
14916 /* Use a control ping for synchronization */
14917 {
14918 vl_api_control_ping_t *mp;
14919 M (CONTROL_PING, control_ping);
14920 S;
14921 }
14922 /* Wait for a reply... */
14923 W;
14924
14925 /* NOTREACHED */
14926 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014927}
14928
14929static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014930api_policer_classify_set_interface (vat_main_t * vam)
14931{
Dave Barach72d72232016-08-04 10:15:08 -040014932 unformat_input_t *i = vam->input;
14933 vl_api_policer_classify_set_interface_t *mp;
14934 f64 timeout;
14935 u32 sw_if_index;
14936 int sw_if_index_set;
14937 u32 ip4_table_index = ~0;
14938 u32 ip6_table_index = ~0;
14939 u32 l2_table_index = ~0;
14940 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014941
Dave Barach72d72232016-08-04 10:15:08 -040014942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14943 {
14944 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
14945 sw_if_index_set = 1;
14946 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14947 sw_if_index_set = 1;
14948 else if (unformat (i, "del"))
14949 is_add = 0;
14950 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14951 ;
14952 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14953 ;
14954 else if (unformat (i, "l2-table %d", &l2_table_index))
14955 ;
14956 else
14957 {
14958 clib_warning ("parse error '%U'", format_unformat_error, i);
14959 return -99;
14960 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014961 }
14962
Dave Barach72d72232016-08-04 10:15:08 -040014963 if (sw_if_index_set == 0)
14964 {
14965 errmsg ("missing interface name or sw_if_index\n");
14966 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014967 }
14968
Dave Barach72d72232016-08-04 10:15:08 -040014969 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014970
Dave Barach72d72232016-08-04 10:15:08 -040014971 mp->sw_if_index = ntohl (sw_if_index);
14972 mp->ip4_table_index = ntohl (ip4_table_index);
14973 mp->ip6_table_index = ntohl (ip6_table_index);
14974 mp->l2_table_index = ntohl (l2_table_index);
14975 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014976
Dave Barach72d72232016-08-04 10:15:08 -040014977 S;
14978 W;
14979 /* NOTREACHED */
14980 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014981}
14982
14983static int
Dave Barach72d72232016-08-04 10:15:08 -040014984api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014985{
Dave Barach72d72232016-08-04 10:15:08 -040014986 unformat_input_t *i = vam->input;
14987 vl_api_policer_classify_dump_t *mp;
14988 f64 timeout = ~0;
14989 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014990
Juraj Sloboda506b2452016-08-07 23:45:24 -070014991 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040014992 ;
14993 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014994 {
Dave Barach72d72232016-08-04 10:15:08 -040014995 errmsg ("classify table type must be specified\n");
14996 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014997 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014998
Dave Barach72d72232016-08-04 10:15:08 -040014999 if (!vam->json_output)
15000 {
15001 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
15002 }
15003
15004 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
15005 mp->type = type;
15006 /* send it... */
15007 S;
15008
15009 /* Use a control ping for synchronization */
15010 {
15011 vl_api_control_ping_t *mp;
15012 M (CONTROL_PING, control_ping);
15013 S;
15014 }
15015 /* Wait for a reply... */
15016 W;
15017
15018 /* NOTREACHED */
15019 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015020}
15021
15022static int
Matus Fabian82e29c42016-05-11 04:49:46 -070015023api_netmap_create (vat_main_t * vam)
15024{
Dave Barach72d72232016-08-04 10:15:08 -040015025 unformat_input_t *i = vam->input;
15026 vl_api_netmap_create_t *mp;
15027 f64 timeout;
15028 u8 *if_name = 0;
15029 u8 hw_addr[6];
15030 u8 random_hw_addr = 1;
15031 u8 is_pipe = 0;
15032 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015033
Dave Barach72d72232016-08-04 10:15:08 -040015034 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070015035
Dave Barach72d72232016-08-04 10:15:08 -040015036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15037 {
15038 if (unformat (i, "name %s", &if_name))
15039 vec_add1 (if_name, 0);
15040 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
15041 random_hw_addr = 0;
15042 else if (unformat (i, "pipe"))
15043 is_pipe = 1;
15044 else if (unformat (i, "master"))
15045 is_master = 1;
15046 else if (unformat (i, "slave"))
15047 is_master = 0;
15048 else
15049 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015050 }
15051
Dave Barach72d72232016-08-04 10:15:08 -040015052 if (!vec_len (if_name))
15053 {
15054 errmsg ("interface name must be specified");
15055 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015056 }
15057
Dave Barach72d72232016-08-04 10:15:08 -040015058 if (vec_len (if_name) > 64)
15059 {
15060 errmsg ("interface name too long");
15061 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015062 }
15063
Dave Barach72d72232016-08-04 10:15:08 -040015064 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070015065
Dave Barach72d72232016-08-04 10:15:08 -040015066 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15067 clib_memcpy (mp->hw_addr, hw_addr, 6);
15068 mp->use_random_hw_addr = random_hw_addr;
15069 mp->is_pipe = is_pipe;
15070 mp->is_master = is_master;
15071 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015072
Dave Barach72d72232016-08-04 10:15:08 -040015073 S;
15074 W;
15075 /* NOTREACHED */
15076 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015077}
15078
15079static int
15080api_netmap_delete (vat_main_t * vam)
15081{
Dave Barach72d72232016-08-04 10:15:08 -040015082 unformat_input_t *i = vam->input;
15083 vl_api_netmap_delete_t *mp;
15084 f64 timeout;
15085 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015086
Dave Barach72d72232016-08-04 10:15:08 -040015087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15088 {
15089 if (unformat (i, "name %s", &if_name))
15090 vec_add1 (if_name, 0);
15091 else
15092 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015093 }
15094
Dave Barach72d72232016-08-04 10:15:08 -040015095 if (!vec_len (if_name))
15096 {
15097 errmsg ("interface name must be specified");
15098 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015099 }
15100
Dave Barach72d72232016-08-04 10:15:08 -040015101 if (vec_len (if_name) > 64)
15102 {
15103 errmsg ("interface name too long");
15104 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015105 }
15106
Dave Barach72d72232016-08-04 10:15:08 -040015107 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070015108
Dave Barach72d72232016-08-04 10:15:08 -040015109 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15110 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015111
Dave Barach72d72232016-08-04 10:15:08 -040015112 S;
15113 W;
15114 /* NOTREACHED */
15115 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015116}
15117
Neale Rannsad422ed2016-11-02 14:20:04 +000015118static void vl_api_mpls_tunnel_details_t_handler
15119 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015120{
Dave Barach72d72232016-08-04 10:15:08 -040015121 vat_main_t *vam = &vat_main;
Neale Rannsad422ed2016-11-02 14:20:04 +000015122 i32 len = mp->mt_next_hop_n_labels;
Dave Barach72d72232016-08-04 10:15:08 -040015123 i32 i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015124
Neale Rannsad422ed2016-11-02 14:20:04 +000015125 fformat (vam->ofp, "[%d]: via %U %d labels ",
15126 mp->tunnel_index,
15127 format_ip4_address, mp->mt_next_hop,
15128 ntohl (mp->mt_next_hop_sw_if_index));
Dave Barach72d72232016-08-04 10:15:08 -040015129 for (i = 0; i < len; i++)
15130 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015131 fformat (vam->ofp, "%u ", ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015132 }
Dave Barach72d72232016-08-04 10:15:08 -040015133 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015134}
15135
Neale Rannsad422ed2016-11-02 14:20:04 +000015136static void vl_api_mpls_tunnel_details_t_handler_json
15137 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015138{
Dave Barach72d72232016-08-04 10:15:08 -040015139 vat_main_t *vam = &vat_main;
15140 vat_json_node_t *node = NULL;
15141 struct in_addr ip4;
15142 i32 i;
Neale Rannsad422ed2016-11-02 14:20:04 +000015143 i32 len = mp->mt_next_hop_n_labels;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015144
Dave Barach72d72232016-08-04 10:15:08 -040015145 if (VAT_JSON_ARRAY != vam->json_tree.type)
15146 {
15147 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15148 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015149 }
Dave Barach72d72232016-08-04 10:15:08 -040015150 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015151
Dave Barach72d72232016-08-04 10:15:08 -040015152 vat_json_init_object (node);
15153 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
Neale Rannsad422ed2016-11-02 14:20:04 +000015154 clib_memcpy (&ip4, &(mp->mt_next_hop), sizeof (ip4));
15155 vat_json_object_add_ip4 (node, "next_hop", ip4);
15156 vat_json_object_add_uint (node, "next_hop_sw_if_index",
15157 ntohl (mp->mt_next_hop_sw_if_index));
15158 vat_json_object_add_uint (node, "l2_only", ntohl (mp->mt_l2_only));
Dave Barach72d72232016-08-04 10:15:08 -040015159 vat_json_object_add_uint (node, "label_count", len);
15160 for (i = 0; i < len; i++)
15161 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015162 vat_json_object_add_uint (node, "label",
15163 ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015164 }
15165}
15166
Dave Barach72d72232016-08-04 10:15:08 -040015167static int
Neale Rannsad422ed2016-11-02 14:20:04 +000015168api_mpls_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015169{
Neale Rannsad422ed2016-11-02 14:20:04 +000015170 vl_api_mpls_tunnel_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015171 f64 timeout;
15172 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015173
Dave Barach72d72232016-08-04 10:15:08 -040015174 /* Parse args required to build the message */
15175 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015176 {
Dave Barach72d72232016-08-04 10:15:08 -040015177 if (!unformat (vam->input, "tunnel_index %d", &index))
15178 {
15179 index = -1;
15180 break;
15181 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015182 }
Dave Barach72d72232016-08-04 10:15:08 -040015183
15184 fformat (vam->ofp, " tunnel_index %d\n", index);
15185
Neale Rannsad422ed2016-11-02 14:20:04 +000015186 M (MPLS_TUNNEL_DUMP, mpls_tunnel_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015187 mp->tunnel_index = htonl (index);
15188 S;
15189
15190 /* Use a control ping for synchronization */
15191 {
15192 vl_api_control_ping_t *mp;
15193 M (CONTROL_PING, control_ping);
15194 S;
15195 }
15196 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015197}
15198
Steven01b07122016-11-02 10:40:09 -070015199#define vl_api_mpls_fib_details_t_endian vl_noop_handler
15200#define vl_api_mpls_fib_details_t_print vl_noop_handler
15201
Neale Ranns1357f3b2016-10-16 12:01:42 -070015202static void
15203vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_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;
Steven01b07122016-11-02 10:40:09 -070015206 int count = ntohl (mp->count);
15207 vl_api_fib_path_t *fp;
15208 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015209
Dave Barach72d72232016-08-04 10:15:08 -040015210 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070015211 "table-id %d, label %u, ess_bit %u\n",
15212 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
Steven01b07122016-11-02 10:40:09 -070015213 fp = mp->path;
15214 for (i = 0; i < count; i++)
15215 {
Steven5858a822016-11-16 13:26:27 -080015216 if (fp->afi == IP46_TYPE_IP6)
15217 fformat (vam->ofp,
15218 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15219 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15220 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15221 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15222 format_ip6_address, fp->next_hop);
15223 else if (fp->afi == IP46_TYPE_IP4)
15224 fformat (vam->ofp,
15225 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15226 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15227 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15228 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15229 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015230 fp++;
15231 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015232}
15233
Neale Ranns1357f3b2016-10-16 12:01:42 -070015234static void vl_api_mpls_fib_details_t_handler_json
15235 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015236{
Dave Barach72d72232016-08-04 10:15:08 -040015237 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070015238 int count = ntohl (mp->count);
Dave Barach72d72232016-08-04 10:15:08 -040015239 vat_json_node_t *node = NULL;
Steven01b07122016-11-02 10:40:09 -070015240 struct in_addr ip4;
15241 struct in6_addr ip6;
15242 vl_api_fib_path_t *fp;
15243 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015244
Dave Barach72d72232016-08-04 10:15:08 -040015245 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015246 {
Dave Barach72d72232016-08-04 10:15:08 -040015247 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15248 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015249 }
Dave Barach72d72232016-08-04 10:15:08 -040015250 node = vat_json_array_add (&vam->json_tree);
15251
15252 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070015253 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15254 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040015255 vat_json_object_add_uint (node, "label", ntohl (mp->label));
Steven01b07122016-11-02 10:40:09 -070015256 vat_json_object_add_uint (node, "path_count", count);
15257 fp = mp->path;
15258 for (i = 0; i < count; i++)
15259 {
15260 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15261 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15262 vat_json_object_add_uint (node, "is_local", fp->is_local);
15263 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15264 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15265 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15266 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15267 if (fp->afi == IP46_TYPE_IP4)
15268 {
15269 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15270 vat_json_object_add_ip4 (node, "next_hop", ip4);
15271 }
15272 else if (fp->afi == IP46_TYPE_IP6)
15273 {
15274 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15275 vat_json_object_add_ip6 (node, "next_hop", ip6);
15276 }
15277 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015278}
15279
Dave Barach72d72232016-08-04 10:15:08 -040015280static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070015281api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015282{
Neale Ranns1357f3b2016-10-16 12:01:42 -070015283 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015284 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015285
Neale Ranns1357f3b2016-10-16 12:01:42 -070015286 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015287 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015288
Dave Barach72d72232016-08-04 10:15:08 -040015289 /* Use a control ping for synchronization */
15290 {
15291 vl_api_control_ping_t *mp;
15292 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015293 S;
Dave Barach72d72232016-08-04 10:15:08 -040015294 }
15295 W;
15296}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015297
Steven01b07122016-11-02 10:40:09 -070015298#define vl_api_ip_fib_details_t_endian vl_noop_handler
15299#define vl_api_ip_fib_details_t_print vl_noop_handler
15300
15301static void
15302vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
15303{
15304 vat_main_t *vam = &vat_main;
15305 int count = ntohl (mp->count);
15306 vl_api_fib_path_t *fp;
15307 int i;
15308
15309 fformat (vam->ofp,
15310 "table-id %d, prefix %U/%d\n",
15311 ntohl (mp->table_id), format_ip4_address, mp->address,
15312 mp->address_length);
15313 fp = mp->path;
15314 for (i = 0; i < count; i++)
15315 {
Steven5858a822016-11-16 13:26:27 -080015316 if (fp->afi == IP46_TYPE_IP6)
15317 fformat (vam->ofp,
15318 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15319 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15320 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15321 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15322 format_ip6_address, fp->next_hop);
15323 else if (fp->afi == IP46_TYPE_IP4)
15324 fformat (vam->ofp,
15325 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15326 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15327 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15328 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15329 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015330 fp++;
15331 }
15332}
15333
15334static void vl_api_ip_fib_details_t_handler_json
15335 (vl_api_ip_fib_details_t * mp)
15336{
15337 vat_main_t *vam = &vat_main;
15338 int count = ntohl (mp->count);
15339 vat_json_node_t *node = NULL;
15340 struct in_addr ip4;
15341 struct in6_addr ip6;
15342 vl_api_fib_path_t *fp;
15343 int i;
15344
15345 if (VAT_JSON_ARRAY != vam->json_tree.type)
15346 {
15347 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15348 vat_json_init_array (&vam->json_tree);
15349 }
15350 node = vat_json_array_add (&vam->json_tree);
15351
15352 vat_json_init_object (node);
15353 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15354 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
15355 vat_json_object_add_ip4 (node, "prefix", ip4);
15356 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15357 vat_json_object_add_uint (node, "path_count", count);
15358 fp = mp->path;
15359 for (i = 0; i < count; i++)
15360 {
15361 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15362 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15363 vat_json_object_add_uint (node, "is_local", fp->is_local);
15364 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15365 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15366 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15367 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15368 if (fp->afi == IP46_TYPE_IP4)
15369 {
15370 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15371 vat_json_object_add_ip4 (node, "next_hop", ip4);
15372 }
15373 else if (fp->afi == IP46_TYPE_IP6)
15374 {
15375 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15376 vat_json_object_add_ip6 (node, "next_hop", ip6);
15377 }
15378 }
15379}
15380
15381static int
15382api_ip_fib_dump (vat_main_t * vam)
15383{
15384 vl_api_ip_fib_dump_t *mp;
15385 f64 timeout;
15386
15387 M (IP_FIB_DUMP, ip_fib_dump);
15388 S;
15389
15390 /* Use a control ping for synchronization */
15391 {
15392 vl_api_control_ping_t *mp;
15393 M (CONTROL_PING, control_ping);
15394 S;
15395 }
15396 W;
15397}
15398
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010015399static void vl_api_ip_neighbor_details_t_handler
15400 (vl_api_ip_neighbor_details_t * mp)
15401{
15402 vat_main_t *vam = &vat_main;
15403
15404 fformat (vam->ofp, "%c %U %U\n",
15405 (mp->is_static) ? 'S' : 'D',
15406 format_ethernet_address, &mp->mac_address,
15407 (mp->is_ipv6) ? format_ip6_address : format_ip4_address,
15408 &mp->ip_address);
15409}
15410
15411static void vl_api_ip_neighbor_details_t_handler_json
15412 (vl_api_ip_neighbor_details_t * mp)
15413{
15414
15415 vat_main_t *vam = &vat_main;
15416 vat_json_node_t *node;
15417 struct in_addr ip4;
15418 struct in6_addr ip6;
15419
15420 if (VAT_JSON_ARRAY != vam->json_tree.type)
15421 {
15422 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15423 vat_json_init_array (&vam->json_tree);
15424 }
15425 node = vat_json_array_add (&vam->json_tree);
15426
15427 vat_json_init_object (node);
15428 vat_json_object_add_string_copy (node, "flag",
15429 (mp->is_static) ? (u8 *) "static" : (u8 *)
15430 "dynamic");
15431
15432 vat_json_object_add_string_copy (node, "link_layer",
15433 format (0, "%U", format_ethernet_address,
15434 &mp->mac_address));
15435
15436 if (mp->is_ipv6)
15437 {
15438 clib_memcpy (&ip6, &mp->ip_address, sizeof (ip6));
15439 vat_json_object_add_ip6 (node, "ip_address", ip6);
15440 }
15441 else
15442 {
15443 clib_memcpy (&ip4, &mp->ip_address, sizeof (ip4));
15444 vat_json_object_add_ip4 (node, "ip_address", ip4);
15445 }
15446}
15447
15448static int
15449api_ip_neighbor_dump (vat_main_t * vam)
15450{
15451 unformat_input_t *i = vam->input;
15452 vl_api_ip_neighbor_dump_t *mp;
15453 f64 timeout;
15454 u8 is_ipv6 = 0;
15455 u32 sw_if_index = ~0;
15456
15457 /* Parse args required to build the message */
15458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15459 {
15460 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15461 ;
15462 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15463 ;
15464 else if (unformat (i, "ip6"))
15465 is_ipv6 = 1;
15466 else
15467 break;
15468 }
15469
15470 if (sw_if_index == ~0)
15471 {
15472 errmsg ("missing interface name or sw_if_index\n");
15473 return -99;
15474 }
15475
15476 M (IP_NEIGHBOR_DUMP, ip_neighbor_dump);
15477 mp->is_ipv6 = (u8) is_ipv6;
15478 mp->sw_if_index = ntohl (sw_if_index);
15479 S;
15480
15481 /* Use a control ping for synchronization */
15482 {
15483 vl_api_control_ping_t *mp;
15484 M (CONTROL_PING, control_ping);
15485 S;
15486 }
15487 W;
15488}
15489
Steven01b07122016-11-02 10:40:09 -070015490#define vl_api_ip6_fib_details_t_endian vl_noop_handler
15491#define vl_api_ip6_fib_details_t_print vl_noop_handler
15492
15493static void
15494vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
15495{
15496 vat_main_t *vam = &vat_main;
15497 int count = ntohl (mp->count);
15498 vl_api_fib_path_t *fp;
15499 int i;
15500
15501 fformat (vam->ofp,
15502 "table-id %d, prefix %U/%d\n",
15503 ntohl (mp->table_id), format_ip6_address, mp->address,
15504 mp->address_length);
15505 fp = mp->path;
15506 for (i = 0; i < count; i++)
15507 {
Steven5858a822016-11-16 13:26:27 -080015508 if (fp->afi == IP46_TYPE_IP6)
15509 fformat (vam->ofp,
15510 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15511 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15512 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15513 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15514 format_ip6_address, fp->next_hop);
15515 else if (fp->afi == IP46_TYPE_IP4)
15516 fformat (vam->ofp,
15517 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15518 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15519 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15520 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15521 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015522 fp++;
15523 }
15524}
15525
15526static void vl_api_ip6_fib_details_t_handler_json
15527 (vl_api_ip6_fib_details_t * mp)
15528{
15529 vat_main_t *vam = &vat_main;
15530 int count = ntohl (mp->count);
15531 vat_json_node_t *node = NULL;
15532 struct in_addr ip4;
15533 struct in6_addr ip6;
15534 vl_api_fib_path_t *fp;
15535 int i;
15536
15537 if (VAT_JSON_ARRAY != vam->json_tree.type)
15538 {
15539 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15540 vat_json_init_array (&vam->json_tree);
15541 }
15542 node = vat_json_array_add (&vam->json_tree);
15543
15544 vat_json_init_object (node);
15545 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15546 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
15547 vat_json_object_add_ip6 (node, "prefix", ip6);
15548 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15549 vat_json_object_add_uint (node, "path_count", count);
15550 fp = mp->path;
15551 for (i = 0; i < count; i++)
15552 {
15553 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15554 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15555 vat_json_object_add_uint (node, "is_local", fp->is_local);
15556 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15557 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15558 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15559 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15560 if (fp->afi == IP46_TYPE_IP4)
15561 {
15562 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15563 vat_json_object_add_ip4 (node, "next_hop", ip4);
15564 }
15565 else if (fp->afi == IP46_TYPE_IP6)
15566 {
15567 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15568 vat_json_object_add_ip6 (node, "next_hop", ip6);
15569 }
15570 }
15571}
15572
15573static int
15574api_ip6_fib_dump (vat_main_t * vam)
15575{
15576 vl_api_ip6_fib_dump_t *mp;
15577 f64 timeout;
15578
15579 M (IP6_FIB_DUMP, ip6_fib_dump);
15580 S;
15581
15582 /* Use a control ping for synchronization */
15583 {
15584 vl_api_control_ping_t *mp;
15585 M (CONTROL_PING, control_ping);
15586 S;
15587 }
15588 W;
15589}
15590
Dave Barach72d72232016-08-04 10:15:08 -040015591int
15592api_classify_table_ids (vat_main_t * vam)
15593{
15594 vl_api_classify_table_ids_t *mp;
15595 f64 timeout;
15596
15597 /* Construct the API message */
15598 M (CLASSIFY_TABLE_IDS, classify_table_ids);
15599 mp->context = 0;
15600
15601 S;
15602 W;
15603 /* NOTREACHED */
15604 return 0;
15605}
15606
15607int
15608api_classify_table_by_interface (vat_main_t * vam)
15609{
15610 unformat_input_t *input = vam->input;
15611 vl_api_classify_table_by_interface_t *mp;
15612 f64 timeout;
15613
15614 u32 sw_if_index = ~0;
15615 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015616 {
Dave Barach72d72232016-08-04 10:15:08 -040015617 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15618 ;
15619 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15620 ;
15621 else
15622 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015623 }
Dave Barach72d72232016-08-04 10:15:08 -040015624 if (sw_if_index == ~0)
15625 {
15626 errmsg ("missing interface name or sw_if_index\n");
15627 return -99;
15628 }
15629
15630 /* Construct the API message */
15631 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
15632 mp->context = 0;
15633 mp->sw_if_index = ntohl (sw_if_index);
15634
15635 S;
15636 W;
15637 /* NOTREACHED */
15638 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015639}
15640
Dave Barach72d72232016-08-04 10:15:08 -040015641int
15642api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015643{
Dave Barach72d72232016-08-04 10:15:08 -040015644 unformat_input_t *input = vam->input;
15645 vl_api_classify_table_info_t *mp;
15646 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015647
Dave Barach72d72232016-08-04 10:15:08 -040015648 u32 table_id = ~0;
15649 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15650 {
15651 if (unformat (input, "table_id %d", &table_id))
15652 ;
15653 else
15654 break;
15655 }
15656 if (table_id == ~0)
15657 {
15658 errmsg ("missing table id\n");
15659 return -99;
15660 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015661
Dave Barach72d72232016-08-04 10:15:08 -040015662 /* Construct the API message */
15663 M (CLASSIFY_TABLE_INFO, classify_table_info);
15664 mp->context = 0;
15665 mp->table_id = ntohl (table_id);
15666
15667 S;
15668 W;
15669 /* NOTREACHED */
15670 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015671}
15672
Dave Barach72d72232016-08-04 10:15:08 -040015673int
15674api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015675{
Dave Barach72d72232016-08-04 10:15:08 -040015676 unformat_input_t *input = vam->input;
15677 vl_api_classify_session_dump_t *mp;
15678 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015679
Dave Barach72d72232016-08-04 10:15:08 -040015680 u32 table_id = ~0;
15681 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15682 {
15683 if (unformat (input, "table_id %d", &table_id))
15684 ;
15685 else
15686 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015687 }
Dave Barach72d72232016-08-04 10:15:08 -040015688 if (table_id == ~0)
15689 {
15690 errmsg ("missing table id\n");
15691 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015692 }
15693
Dave Barach72d72232016-08-04 10:15:08 -040015694 /* Construct the API message */
15695 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15696 mp->context = 0;
15697 mp->table_id = ntohl (table_id);
15698 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015699
Dave Barach72d72232016-08-04 10:15:08 -040015700 /* Use a control ping for synchronization */
15701 {
15702 vl_api_control_ping_t *mp;
15703 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015704 S;
Dave Barach72d72232016-08-04 10:15:08 -040015705 }
15706 W;
15707 /* NOTREACHED */
15708 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015709}
15710
Dave Barach72d72232016-08-04 10:15:08 -040015711static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015712vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015713{
Dave Barach72d72232016-08-04 10:15:08 -040015714 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015715
Dave Barach72d72232016-08-04 10:15:08 -040015716 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015717 "src_address %U, vrf_id %d, path_mtu %u, "
15718 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015719 format_ip4_address, mp->collector_address,
15720 ntohs (mp->collector_port),
15721 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015722 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15723 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015724
15725 vam->retval = 0;
15726 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015727}
15728
Dave Barach72d72232016-08-04 10:15:08 -040015729static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015730 vl_api_ipfix_exporter_details_t_handler_json
15731 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015732{
Dave Barach72d72232016-08-04 10:15:08 -040015733 vat_main_t *vam = &vat_main;
15734 vat_json_node_t node;
15735 struct in_addr collector_address;
15736 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015737
Dave Barach72d72232016-08-04 10:15:08 -040015738 vat_json_init_object (&node);
15739 clib_memcpy (&collector_address, &mp->collector_address,
15740 sizeof (collector_address));
15741 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15742 vat_json_object_add_uint (&node, "collector_port",
15743 ntohs (mp->collector_port));
15744 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15745 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015746 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015747 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15748 vat_json_object_add_uint (&node, "template_interval",
15749 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015750 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015751
15752 vat_json_print (vam->ofp, &node);
15753 vat_json_free (&node);
15754 vam->retval = 0;
15755 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015756}
15757
Dave Barach72d72232016-08-04 10:15:08 -040015758int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015759api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015760{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015761 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015762 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015763
Dave Barach72d72232016-08-04 10:15:08 -040015764 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015765 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015766 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015767
Dave Barach72d72232016-08-04 10:15:08 -040015768 S;
15769 W;
15770 /* NOTREACHED */
15771 return 0;
15772}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015773
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015774static int
15775api_ipfix_classify_stream_dump (vat_main_t * vam)
15776{
15777 vl_api_ipfix_classify_stream_dump_t *mp;
15778 f64 timeout;
15779
15780 /* Construct the API message */
15781 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15782 mp->context = 0;
15783
15784 S;
15785 W;
15786 /* NOTREACHED */
15787 return 0;
15788}
15789
15790static void
15791 vl_api_ipfix_classify_stream_details_t_handler
15792 (vl_api_ipfix_classify_stream_details_t * mp)
15793{
15794 vat_main_t *vam = &vat_main;
15795 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15796 ntohl (mp->domain_id), ntohs (mp->src_port));
15797 vam->retval = 0;
15798 vam->result_ready = 1;
15799}
15800
15801static void
15802 vl_api_ipfix_classify_stream_details_t_handler_json
15803 (vl_api_ipfix_classify_stream_details_t * mp)
15804{
15805 vat_main_t *vam = &vat_main;
15806 vat_json_node_t node;
15807
15808 vat_json_init_object (&node);
15809 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15810 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15811
15812 vat_json_print (vam->ofp, &node);
15813 vat_json_free (&node);
15814 vam->retval = 0;
15815 vam->result_ready = 1;
15816}
15817
15818static int
15819api_ipfix_classify_table_dump (vat_main_t * vam)
15820{
15821 vl_api_ipfix_classify_table_dump_t *mp;
15822 f64 timeout;
15823
15824 if (!vam->json_output)
15825 {
15826 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15827 "transport_protocol");
15828 }
15829
15830 /* Construct the API message */
15831 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15832
15833 /* send it... */
15834 S;
15835
15836 /* Use a control ping for synchronization */
15837 {
15838 vl_api_control_ping_t *mp;
15839 M (CONTROL_PING, control_ping);
15840 S;
15841 }
15842 W;
15843}
15844
15845static void
15846 vl_api_ipfix_classify_table_details_t_handler
15847 (vl_api_ipfix_classify_table_details_t * mp)
15848{
15849 vat_main_t *vam = &vat_main;
15850 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15851 mp->transport_protocol);
15852}
15853
15854static void
15855 vl_api_ipfix_classify_table_details_t_handler_json
15856 (vl_api_ipfix_classify_table_details_t * mp)
15857{
15858 vat_json_node_t *node = NULL;
15859 vat_main_t *vam = &vat_main;
15860
15861 if (VAT_JSON_ARRAY != vam->json_tree.type)
15862 {
15863 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15864 vat_json_init_array (&vam->json_tree);
15865 }
15866
15867 node = vat_json_array_add (&vam->json_tree);
15868 vat_json_init_object (node);
15869
15870 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15871 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15872 vat_json_object_add_uint (node, "transport_protocol",
15873 mp->transport_protocol);
15874}
15875
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015876static int
15877api_sw_interface_span_enable_disable (vat_main_t * vam)
15878{
15879 unformat_input_t *i = vam->input;
15880 vl_api_sw_interface_span_enable_disable_t *mp;
15881 f64 timeout;
15882 u32 src_sw_if_index = ~0;
15883 u32 dst_sw_if_index = ~0;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015884 u8 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015885
15886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15887 {
15888 if (unformat (i, "src %U", unformat_sw_if_index, vam, &src_sw_if_index))
15889 ;
15890 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
15891 ;
15892 else
15893 if (unformat
15894 (i, "dst %U", unformat_sw_if_index, vam, &dst_sw_if_index))
15895 ;
15896 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
15897 ;
15898 else if (unformat (i, "disable"))
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015899 state = 0;
15900 else if (unformat (i, "rx"))
15901 state = 1;
15902 else if (unformat (i, "tx"))
15903 state = 2;
15904 else if (unformat (i, "both"))
15905 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015906 else
15907 break;
15908 }
15909
15910 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable);
15911
15912 mp->sw_if_index_from = htonl (src_sw_if_index);
15913 mp->sw_if_index_to = htonl (dst_sw_if_index);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015914 mp->state = state;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015915
15916 S;
15917 W;
15918 /* NOTREACHED */
15919 return 0;
15920}
15921
15922static void
15923vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
15924 * mp)
15925{
15926 vat_main_t *vam = &vat_main;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015927 u8 *sw_if_from_name = 0;
15928 u8 *sw_if_to_name = 0;
15929 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
15930 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
15931 char *states[] = { "none", "rx", "tx", "both" };
15932 hash_pair_t *p;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015933
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015934 /* *INDENT-OFF* */
15935 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
15936 ({
15937 if ((u32) p->value[0] == sw_if_index_from)
15938 {
15939 sw_if_from_name = (u8 *)(p->key);
15940 if (sw_if_to_name)
15941 break;
15942 }
15943 if ((u32) p->value[0] == sw_if_index_to)
15944 {
15945 sw_if_to_name = (u8 *)(p->key);
15946 if (sw_if_from_name)
15947 break;
15948 }
15949 }));
15950 /* *INDENT-ON* */
15951 fformat (vam->ofp, "%20s => %20s (%s)\n",
15952 sw_if_from_name, sw_if_to_name, states[mp->state]);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015953}
15954
15955static void
15956 vl_api_sw_interface_span_details_t_handler_json
15957 (vl_api_sw_interface_span_details_t * mp)
15958{
15959 vat_main_t *vam = &vat_main;
15960 vat_json_node_t *node = NULL;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015961 u8 *sw_if_from_name = 0;
15962 u8 *sw_if_to_name = 0;
15963 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
15964 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
15965 hash_pair_t *p;
15966
15967 /* *INDENT-OFF* */
15968 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
15969 ({
15970 if ((u32) p->value[0] == sw_if_index_from)
15971 {
15972 sw_if_from_name = (u8 *)(p->key);
15973 if (sw_if_to_name)
15974 break;
15975 }
15976 if ((u32) p->value[0] == sw_if_index_to)
15977 {
15978 sw_if_to_name = (u8 *)(p->key);
15979 if (sw_if_from_name)
15980 break;
15981 }
15982 }));
15983 /* *INDENT-ON* */
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015984
15985 if (VAT_JSON_ARRAY != vam->json_tree.type)
15986 {
15987 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15988 vat_json_init_array (&vam->json_tree);
15989 }
15990 node = vat_json_array_add (&vam->json_tree);
15991
15992 vat_json_init_object (node);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015993 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
15994 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
15995 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
15996 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
15997 vat_json_object_add_uint (node, "state", mp->state);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015998}
15999
16000static int
16001api_sw_interface_span_dump (vat_main_t * vam)
16002{
16003 vl_api_sw_interface_span_dump_t *mp;
16004 f64 timeout;
16005
16006 M (SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump);
16007 S;
16008
16009 /* Use a control ping for synchronization */
16010 {
16011 vl_api_control_ping_t *mp;
16012 M (CONTROL_PING, control_ping);
16013 S;
16014 }
16015 W;
16016}
16017
Dave Barach72d72232016-08-04 10:15:08 -040016018int
16019api_pg_create_interface (vat_main_t * vam)
16020{
16021 unformat_input_t *input = vam->input;
16022 vl_api_pg_create_interface_t *mp;
16023 f64 timeout;
16024
16025 u32 if_id = ~0;
16026 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16027 {
16028 if (unformat (input, "if_id %d", &if_id))
16029 ;
16030 else
16031 break;
16032 }
16033 if (if_id == ~0)
16034 {
16035 errmsg ("missing pg interface index\n");
16036 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016037 }
16038
Dave Barach72d72232016-08-04 10:15:08 -040016039 /* Construct the API message */
16040 M (PG_CREATE_INTERFACE, pg_create_interface);
16041 mp->context = 0;
16042 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016043
Dave Barach72d72232016-08-04 10:15:08 -040016044 S;
16045 W;
16046 /* NOTREACHED */
16047 return 0;
16048}
16049
16050int
16051api_pg_capture (vat_main_t * vam)
16052{
16053 unformat_input_t *input = vam->input;
16054 vl_api_pg_capture_t *mp;
16055 f64 timeout;
16056
16057 u32 if_id = ~0;
16058 u8 enable = 1;
16059 u32 count = 1;
16060 u8 pcap_file_set = 0;
16061 u8 *pcap_file = 0;
16062 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16063 {
16064 if (unformat (input, "if_id %d", &if_id))
16065 ;
16066 else if (unformat (input, "pcap %s", &pcap_file))
16067 pcap_file_set = 1;
16068 else if (unformat (input, "count %d", &count))
16069 ;
16070 else if (unformat (input, "disable"))
16071 enable = 0;
16072 else
16073 break;
16074 }
16075 if (if_id == ~0)
16076 {
16077 errmsg ("missing pg interface index\n");
16078 return -99;
16079 }
16080 if (pcap_file_set > 0)
16081 {
16082 if (vec_len (pcap_file) > 255)
16083 {
16084 errmsg ("pcap file name is too long\n");
16085 return -99;
16086 }
16087 }
16088
16089 u32 name_len = vec_len (pcap_file);
16090 /* Construct the API message */
16091 M (PG_CAPTURE, pg_capture);
16092 mp->context = 0;
16093 mp->interface_id = ntohl (if_id);
16094 mp->is_enabled = enable;
16095 mp->count = ntohl (count);
16096 mp->pcap_name_length = ntohl (name_len);
16097 if (pcap_file_set != 0)
16098 {
16099 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
16100 }
16101 vec_free (pcap_file);
16102
16103 S;
16104 W;
16105 /* NOTREACHED */
16106 return 0;
16107}
16108
16109int
16110api_pg_enable_disable (vat_main_t * vam)
16111{
16112 unformat_input_t *input = vam->input;
16113 vl_api_pg_enable_disable_t *mp;
16114 f64 timeout;
16115
16116 u8 enable = 1;
16117 u8 stream_name_set = 0;
16118 u8 *stream_name = 0;
16119 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16120 {
16121 if (unformat (input, "stream %s", &stream_name))
16122 stream_name_set = 1;
16123 else if (unformat (input, "disable"))
16124 enable = 0;
16125 else
16126 break;
16127 }
16128
16129 if (stream_name_set > 0)
16130 {
16131 if (vec_len (stream_name) > 255)
16132 {
16133 errmsg ("stream name too long\n");
16134 return -99;
16135 }
16136 }
16137
16138 u32 name_len = vec_len (stream_name);
16139 /* Construct the API message */
16140 M (PG_ENABLE_DISABLE, pg_enable_disable);
16141 mp->context = 0;
16142 mp->is_enabled = enable;
16143 if (stream_name_set != 0)
16144 {
16145 mp->stream_name_length = ntohl (name_len);
16146 clib_memcpy (mp->stream_name, stream_name, name_len);
16147 }
16148 vec_free (stream_name);
16149
16150 S;
16151 W;
16152 /* NOTREACHED */
16153 return 0;
16154}
16155
16156int
16157api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
16158{
16159 unformat_input_t *input = vam->input;
16160 vl_api_ip_source_and_port_range_check_add_del_t *mp;
16161 f64 timeout;
16162
16163 u16 *low_ports = 0;
16164 u16 *high_ports = 0;
16165 u16 this_low;
16166 u16 this_hi;
16167 ip4_address_t ip4_addr;
16168 ip6_address_t ip6_addr;
16169 u32 length;
16170 u32 tmp, tmp2;
16171 u8 prefix_set = 0;
16172 u32 vrf_id = ~0;
16173 u8 is_add = 1;
16174 u8 is_ipv6 = 0;
16175
16176 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16177 {
16178 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
16179 {
16180 prefix_set = 1;
16181 }
16182 else
16183 if (unformat
16184 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
16185 {
16186 prefix_set = 1;
16187 is_ipv6 = 1;
16188 }
16189 else if (unformat (input, "vrf %d", &vrf_id))
16190 ;
16191 else if (unformat (input, "del"))
16192 is_add = 0;
16193 else if (unformat (input, "port %d", &tmp))
16194 {
16195 if (tmp == 0 || tmp > 65535)
16196 {
16197 errmsg ("port %d out of range", tmp);
16198 return -99;
16199 }
16200 this_low = tmp;
16201 this_hi = this_low + 1;
16202 vec_add1 (low_ports, this_low);
16203 vec_add1 (high_ports, this_hi);
16204 }
16205 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
16206 {
16207 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
16208 {
16209 errmsg ("incorrect range parameters\n");
16210 return -99;
16211 }
16212 this_low = tmp;
16213 /* Note: in debug CLI +1 is added to high before
16214 passing to real fn that does "the work"
16215 (ip_source_and_port_range_check_add_del).
16216 This fn is a wrapper around the binary API fn a
16217 control plane will call, which expects this increment
16218 to have occurred. Hence letting the binary API control
16219 plane fn do the increment for consistency between VAT
16220 and other control planes.
16221 */
16222 this_hi = tmp2;
16223 vec_add1 (low_ports, this_low);
16224 vec_add1 (high_ports, this_hi);
16225 }
16226 else
16227 break;
16228 }
16229
16230 if (prefix_set == 0)
16231 {
16232 errmsg ("<address>/<mask> not specified\n");
16233 return -99;
16234 }
16235
16236 if (vrf_id == ~0)
16237 {
16238 errmsg ("VRF ID required, not specified\n");
16239 return -99;
16240 }
16241
16242 if (vrf_id == 0)
16243 {
16244 errmsg
16245 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16246 return -99;
16247 }
16248
16249 if (vec_len (low_ports) == 0)
16250 {
16251 errmsg ("At least one port or port range required\n");
16252 return -99;
16253 }
16254
16255 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
16256 ip_source_and_port_range_check_add_del);
16257
16258 mp->is_add = is_add;
16259
16260 if (is_ipv6)
16261 {
16262 mp->is_ipv6 = 1;
16263 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
16264 }
16265 else
16266 {
16267 mp->is_ipv6 = 0;
16268 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
16269 }
16270
16271 mp->mask_length = length;
16272 mp->number_of_ranges = vec_len (low_ports);
16273
16274 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
16275 vec_free (low_ports);
16276
16277 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
16278 vec_free (high_ports);
16279
16280 mp->vrf_id = ntohl (vrf_id);
16281
16282 S;
16283 W;
16284 /* NOTREACHED */
16285 return 0;
16286}
16287
16288int
16289api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
16290{
16291 unformat_input_t *input = vam->input;
16292 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
16293 f64 timeout;
16294 u32 sw_if_index = ~0;
16295 int vrf_set = 0;
16296 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
16297 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
16298 u8 is_add = 1;
16299
16300 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16301 {
16302 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
16303 ;
16304 else if (unformat (input, "sw_if_index %d", &sw_if_index))
16305 ;
16306 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
16307 vrf_set = 1;
16308 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
16309 vrf_set = 1;
16310 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
16311 vrf_set = 1;
16312 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
16313 vrf_set = 1;
16314 else if (unformat (input, "del"))
16315 is_add = 0;
16316 else
16317 break;
16318 }
16319
16320 if (sw_if_index == ~0)
16321 {
16322 errmsg ("Interface required but not specified\n");
16323 return -99;
16324 }
16325
16326 if (vrf_set == 0)
16327 {
16328 errmsg ("VRF ID required but not specified\n");
16329 return -99;
16330 }
16331
16332 if (tcp_out_vrf_id == 0
16333 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
16334 {
16335 errmsg
16336 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16337 return -99;
16338 }
16339
16340 /* Construct the API message */
16341 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
16342 ip_source_and_port_range_check_interface_add_del);
16343
16344 mp->sw_if_index = ntohl (sw_if_index);
16345 mp->is_add = is_add;
16346 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
16347 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
16348 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
16349 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
16350
16351 /* send it... */
16352 S;
16353
16354 /* Wait for a reply... */
16355 W;
16356}
16357
16358static int
Matus Fabian694265d2016-08-10 01:55:36 -070016359api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
16360{
16361 unformat_input_t *i = vam->input;
16362 vl_api_ipsec_gre_add_del_tunnel_t *mp;
16363 f64 timeout;
16364 u32 local_sa_id = 0;
16365 u32 remote_sa_id = 0;
16366 ip4_address_t src_address;
16367 ip4_address_t dst_address;
16368 u8 is_add = 1;
16369
16370 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16371 {
16372 if (unformat (i, "local_sa %d", &local_sa_id))
16373 ;
16374 else if (unformat (i, "remote_sa %d", &remote_sa_id))
16375 ;
16376 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
16377 ;
16378 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
16379 ;
16380 else if (unformat (i, "del"))
16381 is_add = 0;
16382 else
16383 {
16384 clib_warning ("parse error '%U'", format_unformat_error, i);
16385 return -99;
16386 }
16387 }
16388
16389 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
16390
16391 mp->local_sa_id = ntohl (local_sa_id);
16392 mp->remote_sa_id = ntohl (remote_sa_id);
16393 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
16394 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
16395 mp->is_add = is_add;
16396
16397 S;
16398 W;
16399 /* NOTREACHED */
16400 return 0;
16401}
16402
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016403static int
16404api_punt (vat_main_t * vam)
16405{
16406 unformat_input_t *i = vam->input;
16407 vl_api_punt_t *mp;
16408 f64 timeout;
16409 u32 ipv = ~0;
16410 u32 protocol = ~0;
16411 u32 port = ~0;
16412 int is_add = 1;
16413
16414 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16415 {
16416 if (unformat (i, "ip %d", &ipv))
16417 ;
16418 else if (unformat (i, "protocol %d", &protocol))
16419 ;
16420 else if (unformat (i, "port %d", &port))
16421 ;
16422 else if (unformat (i, "del"))
16423 is_add = 0;
16424 else
16425 {
16426 clib_warning ("parse error '%U'", format_unformat_error, i);
16427 return -99;
16428 }
16429 }
16430
16431 M (PUNT, punt);
16432
16433 mp->is_add = (u8) is_add;
16434 mp->ipv = (u8) ipv;
16435 mp->l4_protocol = (u8) protocol;
16436 mp->l4_port = htons ((u16) port);
16437
16438 S;
16439 W;
16440 /* NOTREACHED */
16441 return 0;
16442}
16443
Matus Fabian694265d2016-08-10 01:55:36 -070016444static void vl_api_ipsec_gre_tunnel_details_t_handler
16445 (vl_api_ipsec_gre_tunnel_details_t * mp)
16446{
16447 vat_main_t *vam = &vat_main;
16448
16449 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
16450 ntohl (mp->sw_if_index),
16451 format_ip4_address, &mp->src_address,
16452 format_ip4_address, &mp->dst_address,
16453 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
16454}
16455
16456static void vl_api_ipsec_gre_tunnel_details_t_handler_json
16457 (vl_api_ipsec_gre_tunnel_details_t * mp)
16458{
16459 vat_main_t *vam = &vat_main;
16460 vat_json_node_t *node = NULL;
16461 struct in_addr ip4;
16462
16463 if (VAT_JSON_ARRAY != vam->json_tree.type)
16464 {
16465 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16466 vat_json_init_array (&vam->json_tree);
16467 }
16468 node = vat_json_array_add (&vam->json_tree);
16469
16470 vat_json_init_object (node);
16471 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
16472 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
16473 vat_json_object_add_ip4 (node, "src_address", ip4);
16474 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
16475 vat_json_object_add_ip4 (node, "dst_address", ip4);
16476 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
16477 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
16478}
16479
16480static int
16481api_ipsec_gre_tunnel_dump (vat_main_t * vam)
16482{
16483 unformat_input_t *i = vam->input;
16484 vl_api_ipsec_gre_tunnel_dump_t *mp;
16485 f64 timeout;
16486 u32 sw_if_index;
16487 u8 sw_if_index_set = 0;
16488
16489 /* Parse args required to build the message */
16490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16491 {
16492 if (unformat (i, "sw_if_index %d", &sw_if_index))
16493 sw_if_index_set = 1;
16494 else
16495 break;
16496 }
16497
16498 if (sw_if_index_set == 0)
16499 {
16500 sw_if_index = ~0;
16501 }
16502
16503 if (!vam->json_output)
16504 {
16505 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
16506 "sw_if_index", "src_address", "dst_address",
16507 "local_sa_id", "remote_sa_id");
16508 }
16509
16510 /* Get list of gre-tunnel interfaces */
16511 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
16512
16513 mp->sw_if_index = htonl (sw_if_index);
16514
16515 S;
16516
16517 /* Use a control ping for synchronization */
16518 {
16519 vl_api_control_ping_t *mp;
16520 M (CONTROL_PING, control_ping);
16521 S;
16522 }
16523 W;
16524}
16525
16526static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016527api_delete_subif (vat_main_t * vam)
16528{
16529 unformat_input_t *i = vam->input;
16530 vl_api_delete_subif_t *mp;
16531 f64 timeout;
16532 u32 sw_if_index = ~0;
16533
16534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16535 {
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016536 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16537 ;
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016538 if (unformat (i, "sw_if_index %d", &sw_if_index))
16539 ;
16540 else
16541 break;
16542 }
16543
16544 if (sw_if_index == ~0)
16545 {
16546 errmsg ("missing sw_if_index\n");
16547 return -99;
16548 }
16549
16550 /* Construct the API message */
16551 M (DELETE_SUBIF, delete_subif);
16552 mp->sw_if_index = ntohl (sw_if_index);
16553
16554 S;
16555 W;
16556}
16557
Pavel Kotucek95300d12016-08-26 16:11:36 +020016558#define foreach_pbb_vtr_op \
16559_("disable", L2_VTR_DISABLED) \
16560_("pop", L2_VTR_POP_2) \
16561_("push", L2_VTR_PUSH_2)
16562
16563static int
16564api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
16565{
16566 unformat_input_t *i = vam->input;
16567 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
16568 f64 timeout;
16569 u32 sw_if_index = ~0, vtr_op = ~0;
16570 u16 outer_tag = ~0;
16571 u8 dmac[6], smac[6];
16572 u8 dmac_set = 0, smac_set = 0;
16573 u16 vlanid = 0;
16574 u32 sid = ~0;
16575 u32 tmp;
16576
Dave Barach75665d32016-11-17 11:36:59 -050016577 /* Shut up coverity */
16578 memset (dmac, 0, sizeof (dmac));
16579 memset (smac, 0, sizeof (smac));
16580
Pavel Kotucek95300d12016-08-26 16:11:36 +020016581 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16582 {
16583 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16584 ;
16585 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16586 ;
16587 else if (unformat (i, "vtr_op %d", &vtr_op))
16588 ;
16589#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
16590 foreach_pbb_vtr_op
16591#undef _
16592 else if (unformat (i, "translate_pbb_stag"))
16593 {
16594 if (unformat (i, "%d", &tmp))
16595 {
16596 vtr_op = L2_VTR_TRANSLATE_2_1;
16597 outer_tag = tmp;
16598 }
16599 else
16600 {
16601 errmsg
16602 ("translate_pbb_stag operation requires outer tag definition\n");
16603 return -99;
16604 }
16605 }
16606 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
16607 dmac_set++;
16608 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
16609 smac_set++;
16610 else if (unformat (i, "sid %d", &sid))
16611 ;
16612 else if (unformat (i, "vlanid %d", &tmp))
16613 vlanid = tmp;
16614 else
16615 {
16616 clib_warning ("parse error '%U'", format_unformat_error, i);
16617 return -99;
16618 }
16619 }
16620
16621 if ((sw_if_index == ~0) || (vtr_op == ~0))
16622 {
16623 errmsg ("missing sw_if_index or vtr operation\n");
16624 return -99;
16625 }
16626 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
16627 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
16628 {
16629 errmsg
16630 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
16631 return -99;
16632 }
16633
16634 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
16635 mp->sw_if_index = ntohl (sw_if_index);
16636 mp->vtr_op = ntohl (vtr_op);
16637 mp->outer_tag = ntohs (outer_tag);
16638 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
16639 clib_memcpy (mp->b_smac, smac, sizeof (smac));
16640 mp->b_vlanid = ntohs (vlanid);
16641 mp->i_sid = ntohl (sid);
16642
16643 S;
16644 W;
16645 /* NOTREACHED */
16646 return 0;
16647}
16648
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016649static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070016650api_flow_classify_set_interface (vat_main_t * vam)
16651{
16652 unformat_input_t *i = vam->input;
16653 vl_api_flow_classify_set_interface_t *mp;
16654 f64 timeout;
16655 u32 sw_if_index;
16656 int sw_if_index_set;
16657 u32 ip4_table_index = ~0;
16658 u32 ip6_table_index = ~0;
16659 u8 is_add = 1;
16660
16661 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16662 {
16663 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16664 sw_if_index_set = 1;
16665 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16666 sw_if_index_set = 1;
16667 else if (unformat (i, "del"))
16668 is_add = 0;
16669 else if (unformat (i, "ip4-table %d", &ip4_table_index))
16670 ;
16671 else if (unformat (i, "ip6-table %d", &ip6_table_index))
16672 ;
16673 else
16674 {
16675 clib_warning ("parse error '%U'", format_unformat_error, i);
16676 return -99;
16677 }
16678 }
16679
16680 if (sw_if_index_set == 0)
16681 {
16682 errmsg ("missing interface name or sw_if_index\n");
16683 return -99;
16684 }
16685
16686 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
16687
16688 mp->sw_if_index = ntohl (sw_if_index);
16689 mp->ip4_table_index = ntohl (ip4_table_index);
16690 mp->ip6_table_index = ntohl (ip6_table_index);
16691 mp->is_add = is_add;
16692
16693 S;
16694 W;
16695 /* NOTREACHED */
16696 return 0;
16697}
16698
16699static int
16700api_flow_classify_dump (vat_main_t * vam)
16701{
16702 unformat_input_t *i = vam->input;
16703 vl_api_flow_classify_dump_t *mp;
16704 f64 timeout = ~0;
16705 u8 type = FLOW_CLASSIFY_N_TABLES;
16706
16707 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
16708 ;
16709 else
16710 {
16711 errmsg ("classify table type must be specified\n");
16712 return -99;
16713 }
16714
16715 if (!vam->json_output)
16716 {
16717 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
16718 }
16719
16720 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
16721 mp->type = type;
16722 /* send it... */
16723 S;
16724
16725 /* Use a control ping for synchronization */
16726 {
16727 vl_api_control_ping_t *mp;
16728 M (CONTROL_PING, control_ping);
16729 S;
16730 }
16731 /* Wait for a reply... */
16732 W;
16733
16734 /* NOTREACHED */
16735 return 0;
16736}
16737
16738static int
Pavel Kotucek7490a752016-11-15 09:19:11 +010016739api_feature_enable_disable (vat_main_t * vam)
16740{
16741 unformat_input_t *i = vam->input;
16742 vl_api_feature_enable_disable_t *mp;
16743 f64 timeout;
16744 u8 *arc_name = 0;
16745 u8 *feature_name = 0;
16746 u32 sw_if_index = ~0;
16747 u8 enable = 1;
16748
16749 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16750 {
16751 if (unformat (i, "arc_name %s", &arc_name))
16752 ;
16753 else if (unformat (i, "feature_name %s", &feature_name))
16754 ;
16755 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16756 ;
16757 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16758 ;
16759 else if (unformat (i, "disable"))
16760 enable = 0;
16761 else
16762 break;
16763 }
16764
16765 if (arc_name == 0)
16766 {
16767 errmsg ("missing arc name\n");
16768 return -99;
16769 }
16770 if (vec_len (arc_name) > 63)
16771 {
16772 errmsg ("arc name too long\n");
16773 }
16774
16775 if (feature_name == 0)
16776 {
16777 errmsg ("missing feature name\n");
16778 return -99;
16779 }
16780 if (vec_len (feature_name) > 63)
16781 {
16782 errmsg ("feature name too long\n");
16783 }
16784
16785 if (sw_if_index == ~0)
16786 {
16787 errmsg ("missing interface name or sw_if_index\n");
16788 return -99;
16789 }
16790
16791 /* Construct the API message */
16792 M (FEATURE_ENABLE_DISABLE, feature_enable_disable);
16793 mp->sw_if_index = ntohl (sw_if_index);
16794 mp->enable = enable;
16795 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
16796 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
16797 vec_free (arc_name);
16798 vec_free (feature_name);
16799
16800 S;
16801 W;
16802}
16803
16804static int
Dave Barach7be864a2016-11-28 11:41:35 -050016805api_sw_interface_tag_add_del (vat_main_t * vam)
16806{
16807 unformat_input_t *i = vam->input;
16808 vl_api_sw_interface_tag_add_del_t *mp;
16809 f64 timeout;
16810 u32 sw_if_index = ~0;
16811 u8 *tag = 0;
16812 u8 enable = 1;
16813
16814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16815 {
16816 if (unformat (i, "tag %s", &tag))
16817 ;
16818 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16819 ;
16820 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16821 ;
16822 else if (unformat (i, "del"))
16823 enable = 0;
16824 else
16825 break;
16826 }
16827
16828 if (sw_if_index == ~0)
16829 {
16830 errmsg ("missing interface name or sw_if_index\n");
16831 return -99;
16832 }
16833
16834 if (enable && (tag == 0))
16835 {
16836 errmsg ("no tag specified\n");
16837 return -99;
16838 }
16839
16840 /* Construct the API message */
16841 M (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del);
16842 mp->sw_if_index = ntohl (sw_if_index);
16843 mp->is_add = enable;
16844 if (enable)
16845 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
16846 vec_free (tag);
16847
16848 S;
16849 W;
16850}
16851
Matus Fabianf468e232016-12-02 06:00:53 -080016852static void vl_api_l2_xconnect_details_t_handler
16853 (vl_api_l2_xconnect_details_t * mp)
16854{
16855 vat_main_t *vam = &vat_main;
16856
16857 fformat (vam->ofp, "%15d%15d\n",
16858 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
16859}
16860
16861static void vl_api_l2_xconnect_details_t_handler_json
16862 (vl_api_l2_xconnect_details_t * mp)
16863{
16864 vat_main_t *vam = &vat_main;
16865 vat_json_node_t *node = NULL;
16866
16867 if (VAT_JSON_ARRAY != vam->json_tree.type)
16868 {
16869 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16870 vat_json_init_array (&vam->json_tree);
16871 }
16872 node = vat_json_array_add (&vam->json_tree);
16873
16874 vat_json_init_object (node);
16875 vat_json_object_add_uint (node, "rx_sw_if_index",
16876 ntohl (mp->rx_sw_if_index));
16877 vat_json_object_add_uint (node, "tx_sw_if_index",
16878 ntohl (mp->tx_sw_if_index));
16879}
16880
16881static int
16882api_l2_xconnect_dump (vat_main_t * vam)
16883{
16884 vl_api_l2_xconnect_dump_t *mp;
16885 f64 timeout;
16886
16887 if (!vam->json_output)
16888 {
16889 fformat (vam->ofp, "%15s%15s\n", "rx_sw_if_index", "tx_sw_if_index");
16890 }
16891
16892 M (L2_XCONNECT_DUMP, l2_xconnect_dump);
16893
16894 S;
16895
16896 /* Use a control ping for synchronization */
16897 {
16898 vl_api_control_ping_t *mp;
16899 M (CONTROL_PING, control_ping);
16900 S;
16901 }
16902 W;
16903}
16904
Dave Barach7be864a2016-11-28 11:41:35 -050016905static int
Matus Fabiand162f3d2016-12-05 01:05:35 -080016906api_sw_interface_set_mtu (vat_main_t * vam)
16907{
16908 unformat_input_t *i = vam->input;
16909 vl_api_sw_interface_set_mtu_t *mp;
16910 f64 timeout;
16911 u32 sw_if_index = ~0;
16912 u32 mtu = 0;
16913
16914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16915 {
16916 if (unformat (i, "mtu %d", &mtu))
16917 ;
16918 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16919 ;
16920 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16921 ;
16922 else
16923 break;
16924 }
16925
16926 if (sw_if_index == ~0)
16927 {
16928 errmsg ("missing interface name or sw_if_index\n");
16929 return -99;
16930 }
16931
16932 if (mtu == 0)
16933 {
16934 errmsg ("no mtu specified\n");
16935 return -99;
16936 }
16937
16938 /* Construct the API message */
16939 M (SW_INTERFACE_SET_MTU, sw_interface_set_mtu);
16940 mp->sw_if_index = ntohl (sw_if_index);
16941 mp->mtu = ntohs ((u16) mtu);
16942
16943 S;
16944 W;
16945}
16946
16947
16948static int
Dave Barach72d72232016-08-04 10:15:08 -040016949q_or_quit (vat_main_t * vam)
16950{
16951 longjmp (vam->jump_buf, 1);
16952 return 0; /* not so much */
16953}
16954
16955static int
16956q (vat_main_t * vam)
16957{
16958 return q_or_quit (vam);
16959}
16960
16961static int
16962quit (vat_main_t * vam)
16963{
16964 return q_or_quit (vam);
16965}
16966
16967static int
16968comment (vat_main_t * vam)
16969{
16970 return 0;
16971}
16972
16973static int
16974cmd_cmp (void *a1, void *a2)
16975{
16976 u8 **c1 = a1;
16977 u8 **c2 = a2;
16978
16979 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
16980}
16981
16982static int
16983help (vat_main_t * vam)
16984{
16985 u8 **cmds = 0;
16986 u8 *name = 0;
16987 hash_pair_t *p;
16988 unformat_input_t *i = vam->input;
16989 int j;
16990
16991 if (unformat (i, "%s", &name))
16992 {
16993 uword *hs;
16994
16995 vec_add1 (name, 0);
16996
16997 hs = hash_get_mem (vam->help_by_name, name);
16998 if (hs)
16999 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
17000 else
17001 fformat (vam->ofp, "No such msg / command '%s'\n", name);
17002 vec_free (name);
17003 return 0;
17004 }
17005
17006 fformat (vam->ofp, "Help is available for the following:\n");
17007
17008 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017009 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017010 ({
Dave Barach72d72232016-08-04 10:15:08 -040017011 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017012 }));
Dave Barach72d72232016-08-04 10:15:08 -040017013 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017014
Dave Barach72d72232016-08-04 10:15:08 -040017015 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017016
Dave Barach72d72232016-08-04 10:15:08 -040017017 for (j = 0; j < vec_len (cmds); j++)
17018 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017019
Dave Barach72d72232016-08-04 10:15:08 -040017020 vec_free (cmds);
17021 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017022}
17023
Dave Barach72d72232016-08-04 10:15:08 -040017024static int
17025set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017026{
Dave Barach72d72232016-08-04 10:15:08 -040017027 u8 *name = 0, *value = 0;
17028 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017029
Dave Barach72d72232016-08-04 10:15:08 -040017030 if (unformat (i, "%s", &name))
17031 {
17032 /* The input buffer is a vector, not a string. */
17033 value = vec_dup (i->buffer);
17034 vec_delete (value, i->index, 0);
17035 /* Almost certainly has a trailing newline */
17036 if (value[vec_len (value) - 1] == '\n')
17037 value[vec_len (value) - 1] = 0;
17038 /* Make sure it's a proper string, one way or the other */
17039 vec_add1 (value, 0);
17040 (void) clib_macro_set_value (&vam->macro_main,
17041 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017042 }
Dave Barach72d72232016-08-04 10:15:08 -040017043 else
17044 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017045
Dave Barach72d72232016-08-04 10:15:08 -040017046 vec_free (name);
17047 vec_free (value);
17048 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017049}
17050
Dave Barach72d72232016-08-04 10:15:08 -040017051static int
17052unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017053{
Dave Barach72d72232016-08-04 10:15:08 -040017054 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017055
Dave Barach72d72232016-08-04 10:15:08 -040017056 if (unformat (vam->input, "%s", &name))
17057 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
17058 errmsg ("unset: %s wasn't set\n", name);
17059 vec_free (name);
17060 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017061}
17062
Dave Barach72d72232016-08-04 10:15:08 -040017063typedef struct
17064{
17065 u8 *name;
17066 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017067} macro_sort_t;
17068
17069
Dave Barach72d72232016-08-04 10:15:08 -040017070static int
17071macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017072{
Dave Barach72d72232016-08-04 10:15:08 -040017073 macro_sort_t *s1 = a1;
17074 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017075
Dave Barach72d72232016-08-04 10:15:08 -040017076 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017077}
17078
Dave Barach72d72232016-08-04 10:15:08 -040017079static int
17080dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017081{
Dave Barach72d72232016-08-04 10:15:08 -040017082 macro_sort_t *sort_me = 0, *sm;
17083 int i;
17084 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017085
Dave Barach72d72232016-08-04 10:15:08 -040017086 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017087 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017088 ({
Dave Barach72d72232016-08-04 10:15:08 -040017089 vec_add2 (sort_me, sm, 1);
17090 sm->name = (u8 *)(p->key);
17091 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017092 }));
Dave Barach72d72232016-08-04 10:15:08 -040017093 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017094
Dave Barach72d72232016-08-04 10:15:08 -040017095 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017096
Dave Barach72d72232016-08-04 10:15:08 -040017097 if (vec_len (sort_me))
17098 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
17099 else
17100 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017101
Dave Barach72d72232016-08-04 10:15:08 -040017102 for (i = 0; i < vec_len (sort_me); i++)
17103 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
17104 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017105}
17106
Dave Barach72d72232016-08-04 10:15:08 -040017107static int
17108dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017109{
Dave Barach72d72232016-08-04 10:15:08 -040017110 int i, j;
17111 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017112
Dave Barach72d72232016-08-04 10:15:08 -040017113 if (vec_len (vam->graph_nodes) == 0)
17114 {
17115 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17116 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017117 }
17118
Dave Barach72d72232016-08-04 10:15:08 -040017119 for (i = 0; i < vec_len (vam->graph_nodes); i++)
17120 {
17121 node = vam->graph_nodes[i];
17122 fformat (vam->ofp, "[%d] %s\n", i, node->name);
17123 for (j = 0; j < vec_len (node->next_nodes); j++)
17124 {
17125 if (node->next_nodes[j] != ~0)
17126 {
17127 next_node = vam->graph_nodes[node->next_nodes[j]];
17128 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17129 }
17130 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017131 }
Dave Barach72d72232016-08-04 10:15:08 -040017132 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017133}
17134
Dave Barach72d72232016-08-04 10:15:08 -040017135static int
Dave Barach557d1282016-11-10 14:22:49 -050017136value_sort_cmp (void *a1, void *a2)
17137{
17138 name_sort_t *n1 = a1;
17139 name_sort_t *n2 = a2;
17140
17141 if (n1->value < n2->value)
17142 return -1;
17143 if (n1->value > n2->value)
17144 return 1;
17145 return 0;
17146}
17147
17148
17149static int
17150dump_msg_api_table (vat_main_t * vam)
17151{
17152 api_main_t *am = &api_main;
17153 name_sort_t *nses = 0, *ns;
17154 hash_pair_t *hp;
17155 int i;
17156
17157 /* *INDENT-OFF* */
17158 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
17159 ({
17160 vec_add2 (nses, ns, 1);
17161 ns->name = (u8 *)(hp->key);
17162 ns->value = (u32) hp->value[0];
17163 }));
17164 /* *INDENT-ON* */
17165
17166 vec_sort_with_function (nses, value_sort_cmp);
17167
17168 for (i = 0; i < vec_len (nses); i++)
17169 fformat (vam->ofp, " [%d]: %s\n", nses[i].value, nses[i].name);
17170 vec_free (nses);
17171 return 0;
17172}
17173
17174static int
17175get_msg_id (vat_main_t * vam)
17176{
17177 u8 *name_and_crc;
17178 u32 message_index;
17179
17180 if (unformat (vam->input, "%s", &name_and_crc))
17181 {
17182 message_index = vl_api_get_msg_index (name_and_crc);
17183 if (message_index == ~0)
17184 {
17185 fformat (vam->ofp, " '%s' not found\n", name_and_crc);
17186 return 0;
17187 }
17188 fformat (vam->ofp, " '%s' has message index %d\n",
17189 name_and_crc, message_index);
17190 return 0;
17191 }
17192 errmsg ("name_and_crc required...\n");
17193 return 0;
17194}
17195
17196static int
Dave Barach72d72232016-08-04 10:15:08 -040017197search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017198{
Dave Barach72d72232016-08-04 10:15:08 -040017199 unformat_input_t *line_input = vam->input;
17200 u8 *node_to_find;
17201 int j;
17202 vlib_node_t *node, *next_node;
17203 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017204
Dave Barach72d72232016-08-04 10:15:08 -040017205 if (vam->graph_node_index_by_name == 0)
17206 {
17207 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17208 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017209 }
17210
Dave Barach72d72232016-08-04 10:15:08 -040017211 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
17212 {
17213 if (unformat (line_input, "%s", &node_to_find))
17214 {
17215 vec_add1 (node_to_find, 0);
17216 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
17217 if (p == 0)
17218 {
17219 fformat (vam->ofp, "%s not found...\n", node_to_find);
17220 goto out;
17221 }
17222 node = vam->graph_nodes[p[0]];
17223 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
17224 for (j = 0; j < vec_len (node->next_nodes); j++)
17225 {
17226 if (node->next_nodes[j] != ~0)
17227 {
17228 next_node = vam->graph_nodes[node->next_nodes[j]];
17229 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17230 }
17231 }
17232 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017233
Dave Barach72d72232016-08-04 10:15:08 -040017234 else
17235 {
17236 clib_warning ("parse error '%U'", format_unformat_error,
17237 line_input);
17238 return -99;
17239 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017240
17241 out:
Dave Barach72d72232016-08-04 10:15:08 -040017242 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017243
Dave Barachb44e9bc2016-02-19 09:06:23 -050017244 }
17245
Dave Barach72d72232016-08-04 10:15:08 -040017246 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017247}
17248
17249
Dave Barach72d72232016-08-04 10:15:08 -040017250static int
17251script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017252{
Dave Barach72d72232016-08-04 10:15:08 -040017253 u8 *s = 0;
17254 char *save_current_file;
17255 unformat_input_t save_input;
17256 jmp_buf save_jump_buf;
17257 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017258
Dave Barach72d72232016-08-04 10:15:08 -040017259 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017260
Dave Barach72d72232016-08-04 10:15:08 -040017261 if (unformat (vam->input, "%s", &s))
17262 {
17263 new_fp = fopen ((char *) s, "r");
17264 if (new_fp == 0)
17265 {
17266 errmsg ("Couldn't open script file %s\n", s);
17267 vec_free (s);
17268 return -99;
17269 }
17270 }
17271 else
17272 {
17273 errmsg ("Missing script name\n");
17274 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017275 }
17276
Dave Barach72d72232016-08-04 10:15:08 -040017277 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
17278 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
17279 save_ifp = vam->ifp;
17280 save_line_number = vam->input_line_number;
17281 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017282
Dave Barach72d72232016-08-04 10:15:08 -040017283 vam->input_line_number = 0;
17284 vam->ifp = new_fp;
17285 vam->current_file = s;
17286 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017287
Dave Barach72d72232016-08-04 10:15:08 -040017288 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
17289 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
17290 vam->ifp = save_ifp;
17291 vam->input_line_number = save_line_number;
17292 vam->current_file = (u8 *) save_current_file;
17293 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017294
Dave Barach72d72232016-08-04 10:15:08 -040017295 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017296}
17297
Dave Barach72d72232016-08-04 10:15:08 -040017298static int
17299echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017300{
Dave Barach72d72232016-08-04 10:15:08 -040017301 fformat (vam->ofp, "%v", vam->input->buffer);
17302 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017303}
17304
17305/* List of API message constructors, CLI names map to api_xxx */
17306#define foreach_vpe_api_msg \
17307_(create_loopback,"[mac <mac-addr>]") \
17308_(sw_interface_dump,"") \
17309_(sw_interface_set_flags, \
17310 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
17311_(sw_interface_add_del_address, \
17312 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
17313_(sw_interface_set_table, \
17314 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040017315_(sw_interface_set_mpls_enable, \
17316 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017317_(sw_interface_set_vpath, \
17318 "<intfc> | sw_if_index <id> enable | disable") \
John Lo37682e12016-11-30 12:51:39 -050017319_(sw_interface_set_vxlan_bypass, \
17320 "<intfc> | sw_if_index <id> [ip4 | ip6] enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017321_(sw_interface_set_l2_xconnect, \
17322 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17323 "enable | disable") \
17324_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040017325 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017326 "[shg <split-horizon-group>] [bvi]\n" \
17327 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010017328_(sw_interface_set_dpdk_hqos_pipe, \
17329 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
17330 "profile <profile-id>\n") \
17331_(sw_interface_set_dpdk_hqos_subport, \
17332 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
17333 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
17334_(sw_interface_set_dpdk_hqos_tctbl, \
17335 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017336_(bridge_domain_add_del, \
17337 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
17338_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
17339_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070017340 "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 -070017341_(l2_flags, \
17342 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
17343_(bridge_flags, \
17344 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
17345_(tap_connect, \
Dave Barach7be864a2016-11-28 11:41:35 -050017346 "tapname <name> mac <mac-addr> | random-mac [tag <string>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017347_(tap_modify, \
17348 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
17349_(tap_delete, \
17350 "<vpp-if-name> | sw_if_index <id>") \
17351_(sw_interface_tap_dump, "") \
17352_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017353 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017354 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17355 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17356 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017357_(mpls_route_add_del, \
17358 "<label> <eos> via <addr> [table-id <n>]\n" \
17359 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17360 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17361 "[multipath] [count <n>]") \
17362_(mpls_ip_bind_unbind, \
17363 "<label> <addr/len>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017364_(mpls_tunnel_add_del, \
17365 " via <addr> [table-id <n>]\n" \
17366 "sw_if_index <id>] [l2] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017367_(proxy_arp_add_del, \
17368 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
17369_(proxy_arp_intfc_enable_disable, \
17370 "<intfc> | sw_if_index <id> enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017371_(sw_interface_set_unnumbered, \
17372 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
17373_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040017374 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
17375 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017376_(reset_vrf, "vrf <id> [ipv6]") \
17377_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
17378_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
17379 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
17380 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
17381 "[outer_vlan_id_any][inner_vlan_id_any]") \
17382_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
17383_(reset_fib, "vrf <n> [ipv6]") \
17384_(dhcp_proxy_config, \
17385 "svr <v46-address> src <v46-address>\n" \
17386 "insert-cid <n> [del]") \
17387_(dhcp_proxy_config_2, \
17388 "svr <v46-address> src <v46-address>\n" \
17389 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
17390_(dhcp_proxy_set_vss, \
17391 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
17392_(dhcp_client_config, \
17393 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
17394_(set_ip_flow_hash, \
17395 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
17396_(sw_interface_ip6_enable_disable, \
17397 "<intfc> | sw_if_index <id> enable | disable") \
17398_(sw_interface_ip6_set_link_local_address, \
17399 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
17400_(sw_interface_ip6nd_ra_prefix, \
17401 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
17402 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
17403 "[nolink] [isno]") \
17404_(sw_interface_ip6nd_ra_config, \
17405 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040017406 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017407 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
17408_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
17409_(l2_patch_add_del, \
17410 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17411 "enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017412_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070017413 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
17414 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
17415 "[policy <policy_name>]") \
17416_(sr_policy_add_del, \
17417 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
17418_(sr_multicast_map_add_del, \
17419 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017420_(classify_add_del_table, \
17421 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017422 " [del] mask <mask-value>\n" \
17423 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
17424 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017425_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017426 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
17427 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017428 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
17429 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017430_(classify_set_interface_ip_table, \
17431 "<intfc> | sw_if_index <nn> table <nn>") \
17432_(classify_set_interface_l2_tables, \
17433 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17434 " [other-table <nn>]") \
17435_(get_node_index, "node <node-name") \
17436_(add_node_next, "node <node-name> next <next-node-name>") \
17437_(l2tpv3_create_tunnel, \
17438 "client_address <ip6-addr> our_address <ip6-addr>\n" \
17439 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
17440 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
17441_(l2tpv3_set_tunnel_cookies, \
17442 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
17443 "[new_remote_cookie <nn>]\n") \
17444_(l2tpv3_interface_enable_disable, \
17445 "<intfc> | sw_if_index <nn> enable | disable") \
17446_(l2tpv3_set_lookup_key, \
17447 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
17448_(sw_if_l2tpv3_tunnel_dump, "") \
17449_(vxlan_add_del_tunnel, \
Eyal Baric5b13602016-11-24 19:42:43 +020017450 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
17451 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
Hongjun Nibeb4bf72016-11-25 00:03:46 +080017452 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050017453_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017454_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070017455 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017456_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017457_(l2_fib_clear_table, "") \
17458_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
17459_(l2_interface_vlan_tag_rewrite, \
17460 "<intfc> | sw_if_index <nn> \n" \
17461 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
17462 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
17463_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000017464 "socket <filename> [server] [renumber <dev_instance>] " \
17465 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017466_(modify_vhost_user_if, \
17467 "<intfc> | sw_if_index <nn> socket <filename>\n" \
17468 "[server] [renumber <dev_instance>]") \
17469_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
17470_(sw_interface_vhost_user_dump, "") \
17471_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080017472_(vxlan_gpe_add_del_tunnel, \
17473 "local <addr> remote <addr> vni <nn>\n" \
17474 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
17475 "[next-ethernet] [next-nsh]\n") \
17476_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017477_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017478_(interface_name_renumber, \
17479 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
17480_(input_acl_set_interface, \
17481 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17482 " [l2-table <nn>] [del]") \
17483_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040017484_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017485_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
17486_(ip_dump, "ipv4 | ipv6") \
17487_(ipsec_spd_add_del, "spd_id <n> [del]") \
17488_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
17489 " spid_id <n> ") \
17490_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
17491 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
17492 " integ_alg <alg> integ_key <hex>") \
17493_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
17494 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
17495 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
17496 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
17497_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020017498_(ikev2_profile_add_del, "name <profile_name> [del]") \
17499_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
17500 "(auth_data 0x<data> | auth_data <data>)") \
17501_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
17502 "(id_data 0x<data> | id_data <data>) (local|remote)") \
17503_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
17504 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
17505 "(local|remote)") \
17506_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017507_(delete_loopback,"sw_if_index <nn>") \
17508_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
17509_(map_add_domain, \
17510 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
17511 "ip6-src <ip6addr> " \
17512 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
17513_(map_del_domain, "index <n>") \
17514_(map_add_del_rule, \
17515 "index <n> psid <n> dst <ip6addr> [del]") \
17516_(map_domain_dump, "") \
17517_(map_rule_dump, "index <map-domain>") \
17518_(want_interface_events, "enable|disable") \
17519_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050017520_(get_first_msg_id, "client <name>") \
17521_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
17522_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017523 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010017524_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000017525_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070017526_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
17527_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020017528_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
17529 " sw_if_index <sw_if_index> p <priority> " \
17530 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017531_(lisp_add_del_locator, "locator-set <locator_name> " \
17532 "iface <intf> | sw_if_index <sw_if_index> " \
17533 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017534_(lisp_add_del_local_eid,"vni <vni> eid " \
17535 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017536 "locator-set <locator_name> [del]" \
17537 "[key-id sha1|sha256 secret-key <secret-key>]")\
Florin Coras429e7952016-08-02 02:31:03 +020017538_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
17539 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017540_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017541_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020017542_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020017543_(lisp_enable_disable, "enable|disable") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017544_(lisp_map_register_enable_disable, "enable|disable") \
17545_(lisp_rloc_probe_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017546_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017547_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
17548 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017549 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020017550 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017551 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020017552_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
17553 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020017554_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020017555_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017556_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020017557_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017558_(lisp_locator_set_dump, "[local | remote]") \
17559_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020017560_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
17561 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020017562_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020017563_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017564_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020017565_(lisp_map_resolver_dump, "") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017566_(lisp_map_server_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020017567_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017568_(show_lisp_rloc_probe_state, "") \
17569_(show_lisp_map_register_state, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017570_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017571_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020017572_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020017573_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020017574_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070017575_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017576_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070017577_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017578_(policer_classify_set_interface, \
17579 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17580 " [l2-table <nn>] [del]") \
17581_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017582_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
17583 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020017584_(netmap_delete, "name <interface name>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017585_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017586_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020017587_(classify_table_ids, "") \
17588_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
17589_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070017590_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070017591_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
17592 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
17593 "[template_interval <nn>] [udp_checksum]") \
17594_(ipfix_exporter_dump, "") \
17595_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
17596_(ipfix_classify_stream_dump, "") \
17597_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
17598_(ipfix_classify_table_dump, "") \
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010017599_(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 +010017600_(sw_interface_span_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020017601_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
17602_(pg_create_interface, "if_id <nn>") \
17603_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040017604_(pg_enable_disable, "[stream <id>] disable") \
17605_(ip_source_and_port_range_check_add_del, \
17606 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
17607_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070017608 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070017609 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
17610_(ipsec_gre_add_del_tunnel, \
17611 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020017612_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020017613_(delete_subif,"<intfc> | sw_if_index <nn>") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020017614_(l2_interface_pbb_tag_rewrite, \
17615 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070017616 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
17617 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070017618_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
17619_(flow_classify_set_interface, \
17620 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
Steven01b07122016-11-02 10:40:09 -070017621_(flow_classify_dump, "type [ip4|ip6]") \
17622_(ip_fib_dump, "") \
Pavel Kotucek7490a752016-11-15 09:19:11 +010017623_(ip6_fib_dump, "") \
17624_(feature_enable_disable, "arc_name <arc_name> " \
Dave Barach7be864a2016-11-28 11:41:35 -050017625 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
17626_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
Matus Fabianf468e232016-12-02 06:00:53 -080017627"[disable]") \
Matus Fabiand162f3d2016-12-05 01:05:35 -080017628_(l2_xconnect_dump, "") \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010017629_(sw_interface_set_mtu, "<intfc> | sw_if_index <nn> mtu <nn>") \
17630_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>")
Ed Warnickecb9cada2015-12-08 15:45:58 -070017631
17632/* List of command functions, CLI names map directly to functions */
17633#define foreach_cli_function \
17634_(comment, "usage: comment <ignore-rest-of-line>") \
17635_(dump_interface_table, "usage: dump_interface_table") \
17636_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
17637_(dump_ipv4_table, "usage: dump_ipv4_table") \
17638_(dump_ipv6_table, "usage: dump_ipv6_table") \
17639_(dump_stats_table, "usage: dump_stats_table") \
17640_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017641_(dump_node_table, "usage: dump_node_table") \
Dave Barach557d1282016-11-10 14:22:49 -050017642_(dump_msg_api_table, "usage: dump_msg_api_table") \
17643_(get_msg_id, "usage: get_msg_id name_and_crc") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017644_(echo, "usage: echo <message>") \
17645_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020017646_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017647_(help, "usage: help") \
17648_(q, "usage: quit") \
17649_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017650_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017651_(set, "usage: set <variable-name> <value>") \
17652_(script, "usage: script <file-name>") \
17653_(unset, "usage: unset <variable-name>")
17654
17655#define _(N,n) \
17656 static void vl_api_##n##_t_handler_uni \
17657 (vl_api_##n##_t * mp) \
17658 { \
17659 vat_main_t * vam = &vat_main; \
17660 if (vam->json_output) { \
17661 vl_api_##n##_t_handler_json(mp); \
17662 } else { \
17663 vl_api_##n##_t_handler(mp); \
17664 } \
17665 }
17666foreach_vpe_api_reply_msg;
17667#undef _
17668
Dave Barach72d72232016-08-04 10:15:08 -040017669void
17670vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017671{
17672#define _(N,n) \
17673 vl_msg_api_set_handlers(VL_API_##N, #n, \
17674 vl_api_##n##_t_handler_uni, \
17675 vl_noop_handler, \
17676 vl_api_##n##_t_endian, \
17677 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017678 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040017679 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017680#undef _
17681
Dave Barach72d72232016-08-04 10:15:08 -040017682 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017683
Dave Barach72d72232016-08-04 10:15:08 -040017684 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017685
Dave Barach72d72232016-08-04 10:15:08 -040017686 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017687
Dave Barach72d72232016-08-04 10:15:08 -040017688 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017689
Dave Barach72d72232016-08-04 10:15:08 -040017690 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017691#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040017692 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017693#undef _
17694
Dave Barach72d72232016-08-04 10:15:08 -040017695 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017696#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017697 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017698#undef _
17699
Dave Barach72d72232016-08-04 10:15:08 -040017700 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017701#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040017702 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017703#undef _
17704
Dave Barach72d72232016-08-04 10:15:08 -040017705 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017706#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017707 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017708#undef _
17709}
17710
17711#undef vl_api_version
Dave Barachaff70772016-10-31 11:59:07 -040017712#define vl_api_version(n,v) static u32 memory_api_version = v;
17713#include <vlibmemory/vl_memory_api_h.h>
17714#undef vl_api_version
17715
17716#undef vl_api_version
17717#define vl_api_version(n,v) static u32 vnet_interface_api_version = v;
17718#include <vnet/interface.api.h>
17719#undef vl_api_version
17720
17721#undef vl_api_version
17722#define vl_api_version(n,v) static u32 vpp_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040017723#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070017724#undef vl_api_version
17725
Dave Barachaff70772016-10-31 11:59:07 -040017726static u32 *api_versions[] = {
17727 &memory_api_version,
17728 &vnet_interface_api_version,
17729 &vpp_api_version,
17730};
17731
Dave Barach72d72232016-08-04 10:15:08 -040017732void
17733vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017734{
Dave Barachaff70772016-10-31 11:59:07 -040017735 int i;
17736
17737 ASSERT (ARRAY_LEN (mp->api_versions) >= ARRAY_LEN (api_versions));
17738
Dave Barach72d72232016-08-04 10:15:08 -040017739 /*
Dave Barachaff70772016-10-31 11:59:07 -040017740 * Send the API signatures. This bit of code must
Dave Barach72d72232016-08-04 10:15:08 -040017741 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
17742 */
Dave Barachaff70772016-10-31 11:59:07 -040017743
17744 for (i = 0; i < ARRAY_LEN (api_versions); i++)
17745 mp->api_versions[i] = clib_host_to_net_u32 (*api_versions[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017746}
Dave Barach72d72232016-08-04 10:15:08 -040017747
17748/*
17749 * fd.io coding-style-patch-verification: ON
17750 *
17751 * Local Variables:
17752 * eval: (c-set-style "gnu")
17753 * End:
17754 */