blob: 9b02f1e48737d094041d4e8ac0be346a0f918c36 [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
1443static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001444 (vl_api_mpls_ethernet_add_del_tunnel_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
1459static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001460 (vl_api_mpls_ethernet_add_del_tunnel_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",
1468 ntohl (mp->tunnel_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
2340 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-d\n",
2341 clib_net_to_host_u32 (mp->vni),
2342 eid,
2343 mp->is_local ? "local" : "remote",
2344 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative);
2345 vec_free (s);
2346 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002347}
2348
2349static void
Dave Barach72d72232016-08-04 10:15:08 -04002350vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2351 * mp)
2352{
2353 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002354 vat_json_node_t *node = 0;
2355 u8 *eid = 0;
2356
2357 if (VAT_JSON_ARRAY != vam->json_tree.type)
2358 {
2359 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2360 vat_json_init_array (&vam->json_tree);
2361 }
2362 node = vat_json_array_add (&vam->json_tree);
2363
2364 vat_json_init_object (node);
2365 if (~0 == mp->locator_set_index)
2366 vat_json_object_add_uint (node, "action", mp->action);
2367 else
2368 vat_json_object_add_uint (node, "locator_set_index",
2369 clib_net_to_host_u32 (mp->locator_set_index));
2370
2371 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2372 eid = format (0, "%U", format_lisp_eid_vat,
2373 mp->eid_type,
2374 mp->eid,
2375 mp->eid_prefix_len,
2376 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2377 vec_add1 (eid, 0);
2378 vat_json_object_add_string_copy (node, "eid", eid);
2379 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2380 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2381 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
2382 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002383}
2384
2385static void
2386 vl_api_lisp_eid_table_map_details_t_handler
2387 (vl_api_lisp_eid_table_map_details_t * mp)
2388{
2389 vat_main_t *vam = &vat_main;
2390
2391 u8 *line = format (0, "%=10d%=10d",
2392 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002393 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002394 fformat (vam->ofp, "%v\n", line);
2395 vec_free (line);
2396}
2397
2398static void
2399 vl_api_lisp_eid_table_map_details_t_handler_json
2400 (vl_api_lisp_eid_table_map_details_t * mp)
2401{
2402 vat_main_t *vam = &vat_main;
2403 vat_json_node_t *node = NULL;
2404
2405 if (VAT_JSON_ARRAY != vam->json_tree.type)
2406 {
2407 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2408 vat_json_init_array (&vam->json_tree);
2409 }
2410 node = vat_json_array_add (&vam->json_tree);
2411 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002412 vat_json_object_add_uint (node, "dp_table",
2413 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002414 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002415}
2416
Filip Tehlar50a4e142016-08-24 11:28:02 +02002417static void
2418 vl_api_lisp_eid_table_vni_details_t_handler
2419 (vl_api_lisp_eid_table_vni_details_t * mp)
2420{
2421 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002422
Filip Tehlar50a4e142016-08-24 11:28:02 +02002423 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2424 fformat (vam->ofp, "%v\n", line);
2425 vec_free (line);
2426}
2427
2428static void
2429 vl_api_lisp_eid_table_vni_details_t_handler_json
2430 (vl_api_lisp_eid_table_vni_details_t * mp)
2431{
2432 vat_main_t *vam = &vat_main;
2433 vat_json_node_t *node = NULL;
2434
2435 if (VAT_JSON_ARRAY != vam->json_tree.type)
2436 {
2437 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2438 vat_json_init_array (&vam->json_tree);
2439 }
2440 node = vat_json_array_add (&vam->json_tree);
2441 vat_json_init_object (node);
2442 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2443}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002444
2445static u8 *
2446format_decap_next (u8 * s, va_list * args)
2447{
2448 u32 next_index = va_arg (*args, u32);
2449
2450 switch (next_index)
2451 {
2452 case LISP_GPE_INPUT_NEXT_DROP:
2453 return format (s, "drop");
2454 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2455 return format (s, "ip4");
2456 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2457 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002458 default:
2459 return format (s, "unknown %d", next_index);
2460 }
2461 return s;
2462}
2463
2464static void
Dave Barach72d72232016-08-04 10:15:08 -04002465vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2466 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002467{
Dave Barach72d72232016-08-04 10:15:08 -04002468 vat_main_t *vam = &vat_main;
2469 u8 *iid_str;
2470 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002471
Dave Barach72d72232016-08-04 10:15:08 -04002472 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002473
2474#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2475 foreach_lisp_gpe_flag_bit;
2476#undef _
2477
Dave Barach72d72232016-08-04 10:15:08 -04002478 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2479 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2480 mp->tunnels,
2481 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2482 mp->source_ip,
2483 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2484 mp->destination_ip,
2485 ntohl (mp->encap_fib_id),
2486 ntohl (mp->decap_fib_id),
2487 format_decap_next, ntohl (mp->dcap_next),
2488 mp->ver_res >> 6,
2489 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002490
Dave Barach72d72232016-08-04 10:15:08 -04002491 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002492}
2493
2494static void
Dave Barach72d72232016-08-04 10:15:08 -04002495 vl_api_lisp_gpe_tunnel_details_t_handler_json
2496 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002497{
Dave Barach72d72232016-08-04 10:15:08 -04002498 vat_main_t *vam = &vat_main;
2499 vat_json_node_t *node = NULL;
2500 struct in6_addr ip6;
2501 struct in_addr ip4;
2502 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002503
Dave Barach72d72232016-08-04 10:15:08 -04002504 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002505
Dave Barach72d72232016-08-04 10:15:08 -04002506 if (VAT_JSON_ARRAY != vam->json_tree.type)
2507 {
2508 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2509 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002510 }
Dave Barach72d72232016-08-04 10:15:08 -04002511 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002512
Dave Barach72d72232016-08-04 10:15:08 -04002513 vat_json_init_object (node);
2514 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2515 if (mp->is_ipv6)
2516 {
2517 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2518 vat_json_object_add_ip6 (node, "source address", ip6);
2519 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2520 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002521 }
Dave Barach72d72232016-08-04 10:15:08 -04002522 else
2523 {
2524 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2525 vat_json_object_add_ip4 (node, "source address", ip4);
2526 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2527 vat_json_object_add_ip4 (node, "destination address", ip4);
2528 }
2529 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2530 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2531 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2532 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2533 vat_json_object_add_uint (node, "flags", mp->flags);
2534 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2535 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2536 vat_json_object_add_uint (node, "res", mp->res);
2537 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002538
Dave Barach72d72232016-08-04 10:15:08 -04002539 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002540}
2541
2542static void
Filip Tehlar69a9b762016-09-23 10:00:52 +02002543 vl_api_lisp_adjacencies_get_reply_t_handler
2544 (vl_api_lisp_adjacencies_get_reply_t * mp)
2545{
2546 vat_main_t *vam = &vat_main;
2547 u32 i, n;
2548 int retval = clib_net_to_host_u32 (mp->retval);
2549 vl_api_lisp_adjacency_t *a;
2550
2551 if (retval)
2552 goto end;
2553
2554 n = clib_net_to_host_u32 (mp->count);
2555
2556 for (i = 0; i < n; i++)
2557 {
2558 a = &mp->adjacencies[i];
2559 fformat (vam->ofp, "%U %40U\n",
2560 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
2561 format_lisp_flat_eid, a->eid_type, a->reid,
2562 a->reid_prefix_len);
2563 }
2564
2565end:
2566 vam->retval = retval;
2567 vam->result_ready = 1;
2568}
2569
2570static void
2571 vl_api_lisp_adjacencies_get_reply_t_handler_json
2572 (vl_api_lisp_adjacencies_get_reply_t * mp)
2573{
2574 u8 *s = 0;
2575 vat_main_t *vam = &vat_main;
2576 vat_json_node_t *e = 0, root;
2577 u32 i, n;
2578 int retval = clib_net_to_host_u32 (mp->retval);
2579 vl_api_lisp_adjacency_t *a;
2580
2581 if (retval)
2582 goto end;
2583
2584 n = clib_net_to_host_u32 (mp->count);
2585 vat_json_init_array (&root);
2586
2587 for (i = 0; i < n; i++)
2588 {
2589 e = vat_json_array_add (&root);
2590 a = &mp->adjacencies[i];
2591
2592 vat_json_init_object (e);
2593 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
2594 a->leid_prefix_len);
2595 vec_add1 (s, 0);
2596 vat_json_object_add_string_copy (e, "leid", s);
2597 vec_free (s);
2598
2599 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
2600 a->reid_prefix_len);
2601 vec_add1 (s, 0);
2602 vat_json_object_add_string_copy (e, "reid", s);
2603 vec_free (s);
2604 }
2605
2606 vat_json_print (vam->ofp, &root);
2607 vat_json_free (&root);
2608
2609end:
2610 vam->retval = retval;
2611 vam->result_ready = 1;
2612}
2613
2614static void
Dave Barach72d72232016-08-04 10:15:08 -04002615vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2616 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002617{
Dave Barach72d72232016-08-04 10:15:08 -04002618 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002619
Dave Barach72d72232016-08-04 10:15:08 -04002620 fformat (vam->ofp, "%=20U\n",
2621 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2622 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002623}
2624
2625static void
Dave Barach72d72232016-08-04 10:15:08 -04002626 vl_api_lisp_map_resolver_details_t_handler_json
2627 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002628{
Dave Barach72d72232016-08-04 10:15:08 -04002629 vat_main_t *vam = &vat_main;
2630 vat_json_node_t *node = NULL;
2631 struct in6_addr ip6;
2632 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002633
Dave Barach72d72232016-08-04 10:15:08 -04002634 if (VAT_JSON_ARRAY != vam->json_tree.type)
2635 {
2636 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2637 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002638 }
Dave Barach72d72232016-08-04 10:15:08 -04002639 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002640
Dave Barach72d72232016-08-04 10:15:08 -04002641 vat_json_init_object (node);
2642 if (mp->is_ipv6)
2643 {
2644 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2645 vat_json_object_add_ip6 (node, "map resolver", ip6);
2646 }
2647 else
2648 {
2649 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2650 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002651 }
2652}
2653
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002654static void
Dave Barach72d72232016-08-04 10:15:08 -04002655 vl_api_show_lisp_status_reply_t_handler
2656 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002657{
Dave Barach72d72232016-08-04 10:15:08 -04002658 vat_main_t *vam = &vat_main;
2659 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002660
Dave Barach72d72232016-08-04 10:15:08 -04002661 if (0 <= retval)
2662 {
2663 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2664 mp->feature_status ? "enabled" : "disabled",
2665 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002666 }
2667
Dave Barach72d72232016-08-04 10:15:08 -04002668 vam->retval = retval;
2669 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002670}
2671
2672static void
Dave Barach72d72232016-08-04 10:15:08 -04002673 vl_api_show_lisp_status_reply_t_handler_json
2674 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002675{
Dave Barach72d72232016-08-04 10:15:08 -04002676 vat_main_t *vam = &vat_main;
2677 vat_json_node_t node;
2678 u8 *gpe_status = NULL;
2679 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002680
Dave Barach72d72232016-08-04 10:15:08 -04002681 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2682 feature_status = format (0, "%s",
2683 mp->feature_status ? "enabled" : "disabled");
2684 vec_add1 (gpe_status, 0);
2685 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002686
Dave Barach72d72232016-08-04 10:15:08 -04002687 vat_json_init_object (&node);
2688 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2689 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002690
Dave Barach72d72232016-08-04 10:15:08 -04002691 vec_free (gpe_status);
2692 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002693
Dave Barach72d72232016-08-04 10:15:08 -04002694 vat_json_print (vam->ofp, &node);
2695 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002696
Dave Barach72d72232016-08-04 10:15:08 -04002697 vam->retval = ntohl (mp->retval);
2698 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002699}
2700
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002701static void
Dave Barach72d72232016-08-04 10:15:08 -04002702 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2703 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002704{
Dave Barach72d72232016-08-04 10:15:08 -04002705 vat_main_t *vam = &vat_main;
2706 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002707
Dave Barach72d72232016-08-04 10:15:08 -04002708 if (retval >= 0)
2709 {
2710 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002711 }
2712
Dave Barach72d72232016-08-04 10:15:08 -04002713 vam->retval = retval;
2714 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002715}
2716
2717static void
Dave Barach72d72232016-08-04 10:15:08 -04002718 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2719 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002720{
Dave Barach72d72232016-08-04 10:15:08 -04002721 vat_main_t *vam = &vat_main;
2722 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002723
Dave Barach72d72232016-08-04 10:15:08 -04002724 if (VAT_JSON_ARRAY != vam->json_tree.type)
2725 {
2726 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2727 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002728 }
Dave Barach72d72232016-08-04 10:15:08 -04002729 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002730
Dave Barach72d72232016-08-04 10:15:08 -04002731 vat_json_init_object (node);
2732 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002733
Dave Barach72d72232016-08-04 10:15:08 -04002734 vat_json_print (vam->ofp, node);
2735 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002736
Dave Barach72d72232016-08-04 10:15:08 -04002737 vam->retval = ntohl (mp->retval);
2738 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002739}
2740
Florin Corasdca88042016-09-14 16:01:38 +02002741static u8 *
2742format_lisp_map_request_mode (u8 * s, va_list * args)
2743{
2744 u32 mode = va_arg (*args, u32);
2745
2746 switch (mode)
2747 {
2748 case 0:
2749 return format (0, "dst-only");
2750 case 1:
2751 return format (0, "src-dst");
2752 }
2753 return 0;
2754}
2755
2756static void
2757 vl_api_show_lisp_map_request_mode_reply_t_handler
2758 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2759{
2760 vat_main_t *vam = &vat_main;
2761 i32 retval = ntohl (mp->retval);
2762
2763 if (0 <= retval)
2764 {
2765 u32 mode = mp->mode;
2766 fformat (vam->ofp, "map_request_mode: %U\n",
2767 format_lisp_map_request_mode, mode);
2768 }
2769
2770 vam->retval = retval;
2771 vam->result_ready = 1;
2772}
2773
2774static void
2775 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2776 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2777{
2778 vat_main_t *vam = &vat_main;
2779 vat_json_node_t node;
2780 u8 *s = 0;
2781 u32 mode;
2782
2783 mode = mp->mode;
2784 s = format (0, "%U", format_lisp_map_request_mode, mode);
2785 vec_add1 (s, 0);
2786
2787 vat_json_init_object (&node);
2788 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2789 vat_json_print (vam->ofp, &node);
2790 vat_json_free (&node);
2791
2792 vec_free (s);
2793 vam->retval = ntohl (mp->retval);
2794 vam->result_ready = 1;
2795}
2796
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002797static void
2798vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2799{
Dave Barach72d72232016-08-04 10:15:08 -04002800 vat_main_t *vam = &vat_main;
2801 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002802
Dave Barach72d72232016-08-04 10:15:08 -04002803 if (0 <= retval)
2804 {
2805 fformat (vam->ofp, "%-20s%-16s\n",
2806 mp->status ? "enabled" : "disabled",
2807 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002808 }
2809
Dave Barach72d72232016-08-04 10:15:08 -04002810 vam->retval = retval;
2811 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002812}
2813
2814static void
Dave Barach72d72232016-08-04 10:15:08 -04002815vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2816 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002817{
Dave Barach72d72232016-08-04 10:15:08 -04002818 vat_main_t *vam = &vat_main;
2819 vat_json_node_t node;
2820 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002821
Dave Barach72d72232016-08-04 10:15:08 -04002822 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2823 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002824
Dave Barach72d72232016-08-04 10:15:08 -04002825 vat_json_init_object (&node);
2826 vat_json_object_add_string_copy (&node, "status", status);
2827 if (mp->status)
2828 {
2829 vat_json_object_add_string_copy (&node, "locator_set",
2830 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002831 }
2832
Dave Barach72d72232016-08-04 10:15:08 -04002833 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002834
Dave Barach72d72232016-08-04 10:15:08 -04002835 vat_json_print (vam->ofp, &node);
2836 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002837
Dave Barach72d72232016-08-04 10:15:08 -04002838 vam->retval = ntohl (mp->retval);
2839 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002840}
2841
Dave Barach72d72232016-08-04 10:15:08 -04002842static u8 *
2843format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002844{
Dave Barach72d72232016-08-04 10:15:08 -04002845 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002846
Dave Barach72d72232016-08-04 10:15:08 -04002847 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2848 s = format (s, "1r2c");
2849 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2850 s = format (s, "1r3c");
2851 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2852 s = format (s, "2r3c-2698");
2853 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2854 s = format (s, "2r3c-4115");
2855 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2856 s = format (s, "2r3c-mef5cf1");
2857 else
2858 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002859 return s;
2860}
2861
Dave Barach72d72232016-08-04 10:15:08 -04002862static u8 *
2863format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002864{
2865 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002866
Dave Barach72d72232016-08-04 10:15:08 -04002867 if (i == SSE2_QOS_RATE_KBPS)
2868 s = format (s, "kbps");
2869 else if (i == SSE2_QOS_RATE_PPS)
2870 s = format (s, "pps");
2871 else
2872 s = format (s, "ILLEGAL");
2873 return s;
2874}
2875
2876static u8 *
2877format_policer_round_type (u8 * s, va_list * va)
2878{
2879 u32 i = va_arg (*va, u32);
2880
2881 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2882 s = format (s, "closest");
2883 else if (i == SSE2_QOS_ROUND_TO_UP)
2884 s = format (s, "up");
2885 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2886 s = format (s, "down");
2887 else
2888 s = format (s, "ILLEGAL");
2889 return s;
2890}
2891
2892static u8 *
2893format_policer_action_type (u8 * s, va_list * va)
2894{
2895 u32 i = va_arg (*va, u32);
2896
2897 if (i == SSE2_QOS_ACTION_DROP)
2898 s = format (s, "drop");
2899 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2900 s = format (s, "transmit");
2901 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2902 s = format (s, "mark-and-transmit");
2903 else
2904 s = format (s, "ILLEGAL");
2905 return s;
2906}
2907
2908static u8 *
2909format_dscp (u8 * s, va_list * va)
2910{
2911 u32 i = va_arg (*va, u32);
2912 char *t = 0;
2913
2914 switch (i)
2915 {
2916#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2917 foreach_vnet_dscp
2918#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07002919 default:
2920 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04002921 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07002922 s = format (s, "%s", t);
2923 return s;
2924}
2925
Dave Barach72d72232016-08-04 10:15:08 -04002926static void
2927vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002928{
Dave Barach72d72232016-08-04 10:15:08 -04002929 vat_main_t *vam = &vat_main;
2930 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07002931
Dave Barach72d72232016-08-04 10:15:08 -04002932 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2933 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
2934 else
2935 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002936
Dave Barach72d72232016-08-04 10:15:08 -04002937 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2938 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
2939 else
2940 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07002941
Dave Barach72d72232016-08-04 10:15:08 -04002942 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2943 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
2944 else
2945 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07002946
Dave Barach72d72232016-08-04 10:15:08 -04002947 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2948 "rate type %U, round type %U, %s rate, %s color-aware, "
2949 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2950 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2951 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2952 mp->name,
2953 format_policer_type, mp->type,
2954 ntohl (mp->cir),
2955 ntohl (mp->eir),
2956 clib_net_to_host_u64 (mp->cb),
2957 clib_net_to_host_u64 (mp->eb),
2958 format_policer_rate_type, mp->rate_type,
2959 format_policer_round_type, mp->round_type,
2960 mp->single_rate ? "single" : "dual",
2961 mp->color_aware ? "is" : "not",
2962 ntohl (mp->cir_tokens_per_period),
2963 ntohl (mp->pir_tokens_per_period),
2964 ntohl (mp->scale),
2965 ntohl (mp->current_limit),
2966 ntohl (mp->current_bucket),
2967 ntohl (mp->extended_limit),
2968 ntohl (mp->extended_bucket),
2969 clib_net_to_host_u64 (mp->last_update_time),
2970 format_policer_action_type, mp->conform_action_type,
2971 conform_dscp_str,
2972 format_policer_action_type, mp->exceed_action_type,
2973 exceed_dscp_str,
2974 format_policer_action_type, mp->violate_action_type,
2975 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002976
Dave Barach72d72232016-08-04 10:15:08 -04002977 vec_free (conform_dscp_str);
2978 vec_free (exceed_dscp_str);
2979 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07002980}
2981
2982static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002983 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07002984{
Dave Barach72d72232016-08-04 10:15:08 -04002985 vat_main_t *vam = &vat_main;
2986 vat_json_node_t *node;
2987 u8 *rate_type_str, *round_type_str, *type_str;
2988 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07002989
Dave Barach72d72232016-08-04 10:15:08 -04002990 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2991 round_type_str =
2992 format (0, "%U", format_policer_round_type, mp->round_type);
2993 type_str = format (0, "%U", format_policer_type, mp->type);
2994 conform_action_str = format (0, "%U", format_policer_action_type,
2995 mp->conform_action_type);
2996 exceed_action_str = format (0, "%U", format_policer_action_type,
2997 mp->exceed_action_type);
2998 violate_action_str = format (0, "%U", format_policer_action_type,
2999 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07003000
Dave Barach72d72232016-08-04 10:15:08 -04003001 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003002 {
Dave Barach72d72232016-08-04 10:15:08 -04003003 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3004 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003005 }
Dave Barach72d72232016-08-04 10:15:08 -04003006 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003007
Dave Barach72d72232016-08-04 10:15:08 -04003008 vat_json_init_object (node);
3009 vat_json_object_add_string_copy (node, "name", mp->name);
3010 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
3011 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
3012 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
3013 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
3014 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
3015 vat_json_object_add_string_copy (node, "round_type", round_type_str);
3016 vat_json_object_add_string_copy (node, "type", type_str);
3017 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
3018 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
3019 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
3020 vat_json_object_add_uint (node, "cir_tokens_per_period",
3021 ntohl (mp->cir_tokens_per_period));
3022 vat_json_object_add_uint (node, "eir_tokens_per_period",
3023 ntohl (mp->pir_tokens_per_period));
3024 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
3025 vat_json_object_add_uint (node, "current_bucket",
3026 ntohl (mp->current_bucket));
3027 vat_json_object_add_uint (node, "extended_limit",
3028 ntohl (mp->extended_limit));
3029 vat_json_object_add_uint (node, "extended_bucket",
3030 ntohl (mp->extended_bucket));
3031 vat_json_object_add_uint (node, "last_update_time",
3032 ntohl (mp->last_update_time));
3033 vat_json_object_add_string_copy (node, "conform_action",
3034 conform_action_str);
3035 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3036 {
3037 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3038 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3039 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003040 }
Dave Barach72d72232016-08-04 10:15:08 -04003041 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3042 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3043 {
3044 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3045 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3046 vec_free (dscp_str);
3047 }
3048 vat_json_object_add_string_copy (node, "violate_action",
3049 violate_action_str);
3050 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3051 {
3052 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3053 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3054 vec_free (dscp_str);
3055 }
3056
3057 vec_free (rate_type_str);
3058 vec_free (round_type_str);
3059 vec_free (type_str);
3060 vec_free (conform_action_str);
3061 vec_free (exceed_action_str);
3062 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003063}
3064
Dave Barach72d72232016-08-04 10:15:08 -04003065static void
3066vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3067 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003068{
Dave Barach72d72232016-08-04 10:15:08 -04003069 vat_main_t *vam = &vat_main;
3070 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003071
Dave Barach72d72232016-08-04 10:15:08 -04003072 if (count > 0)
3073 fformat (vam->ofp, "classify table ids (%d) : ", count);
3074 for (i = 0; i < count; i++)
3075 {
3076 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3077 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3078 }
3079 vam->retval = ntohl (mp->retval);
3080 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003081}
3082
Dave Barach72d72232016-08-04 10:15:08 -04003083static void
3084 vl_api_classify_table_ids_reply_t_handler_json
3085 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003086{
Dave Barach72d72232016-08-04 10:15:08 -04003087 vat_main_t *vam = &vat_main;
3088 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003089
Dave Barach72d72232016-08-04 10:15:08 -04003090 if (count > 0)
3091 {
3092 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003093
Dave Barach72d72232016-08-04 10:15:08 -04003094 vat_json_init_object (&node);
3095 for (i = 0; i < count; i++)
3096 {
3097 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3098 }
3099 vat_json_print (vam->ofp, &node);
3100 vat_json_free (&node);
3101 }
3102 vam->retval = ntohl (mp->retval);
3103 vam->result_ready = 1;
3104}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003105
Dave Barach72d72232016-08-04 10:15:08 -04003106static void
3107 vl_api_classify_table_by_interface_reply_t_handler
3108 (vl_api_classify_table_by_interface_reply_t * mp)
3109{
3110 vat_main_t *vam = &vat_main;
3111 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003112
Dave Barach72d72232016-08-04 10:15:08 -04003113 table_id = ntohl (mp->l2_table_id);
3114 if (table_id != ~0)
3115 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3116 else
3117 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3118 table_id = ntohl (mp->ip4_table_id);
3119 if (table_id != ~0)
3120 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3121 else
3122 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3123 table_id = ntohl (mp->ip6_table_id);
3124 if (table_id != ~0)
3125 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3126 else
3127 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3128 vam->retval = ntohl (mp->retval);
3129 vam->result_ready = 1;
3130}
3131
3132static void
3133 vl_api_classify_table_by_interface_reply_t_handler_json
3134 (vl_api_classify_table_by_interface_reply_t * mp)
3135{
3136 vat_main_t *vam = &vat_main;
3137 vat_json_node_t node;
3138
3139 vat_json_init_object (&node);
3140
3141 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3142 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3143 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3144
3145 vat_json_print (vam->ofp, &node);
3146 vat_json_free (&node);
3147
3148 vam->retval = ntohl (mp->retval);
3149 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003150}
3151
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003152static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003153 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003154{
Dave Barach72d72232016-08-04 10:15:08 -04003155 vat_main_t *vam = &vat_main;
3156 i32 retval = ntohl (mp->retval);
3157 if (vam->async_mode)
3158 {
3159 vam->async_errors += (retval < 0);
3160 }
3161 else
3162 {
3163 vam->retval = retval;
3164 vam->result_ready = 1;
3165 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3166 /*
3167 * Note: this is just barely thread-safe, depends on
3168 * the main thread spinning waiting for an answer...
3169 */
3170 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003171 }
3172}
3173
3174static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003175 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003176{
Dave Barach72d72232016-08-04 10:15:08 -04003177 vat_main_t *vam = &vat_main;
3178 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003179
Dave Barach72d72232016-08-04 10:15:08 -04003180 vat_json_init_object (&node);
3181 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3182 vat_json_object_add_uint (&node, "policer_index",
3183 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003184
Dave Barach72d72232016-08-04 10:15:08 -04003185 vat_json_print (vam->ofp, &node);
3186 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003187
Dave Barach72d72232016-08-04 10:15:08 -04003188 vam->retval = ntohl (mp->retval);
3189 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003190}
3191
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003192/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003193u8 *
3194format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003195{
Dave Barach72d72232016-08-04 10:15:08 -04003196 u8 *bytes = va_arg (*va, u8 *);
3197 int n_bytes = va_arg (*va, int);
3198 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003199
Dave Barach72d72232016-08-04 10:15:08 -04003200 /* Print short or long form depending on byte count. */
3201 uword short_form = n_bytes <= 32;
3202 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003203
Dave Barach72d72232016-08-04 10:15:08 -04003204 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003205 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003206
Dave Barach72d72232016-08-04 10:15:08 -04003207 for (i = 0; i < n_bytes; i++)
3208 {
3209 if (!short_form && (i % 32) == 0)
3210 s = format (s, "%08x: ", i);
3211 s = format (s, "%02x", bytes[i]);
3212 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3213 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003214 }
Dave Barach72d72232016-08-04 10:15:08 -04003215
3216 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003217}
3218
Dave Barach72d72232016-08-04 10:15:08 -04003219static void
3220vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3221 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003222{
Dave Barach72d72232016-08-04 10:15:08 -04003223 vat_main_t *vam = &vat_main;
3224 i32 retval = ntohl (mp->retval);
3225 if (retval == 0)
3226 {
3227 fformat (vam->ofp, "classify table info :\n");
3228 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3229 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3230 ntohl (mp->miss_next_index));
3231 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3232 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3233 ntohl (mp->match_n_vectors));
3234 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3235 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003236 }
Dave Barach72d72232016-08-04 10:15:08 -04003237 vam->retval = retval;
3238 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003239}
3240
Dave Barach72d72232016-08-04 10:15:08 -04003241static void
3242 vl_api_classify_table_info_reply_t_handler_json
3243 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003244{
Dave Barach72d72232016-08-04 10:15:08 -04003245 vat_main_t *vam = &vat_main;
3246 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003247
Dave Barach72d72232016-08-04 10:15:08 -04003248 i32 retval = ntohl (mp->retval);
3249 if (retval == 0)
3250 {
3251 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003252
Dave Barach72d72232016-08-04 10:15:08 -04003253 vat_json_object_add_int (&node, "sessions",
3254 ntohl (mp->active_sessions));
3255 vat_json_object_add_int (&node, "nexttbl",
3256 ntohl (mp->next_table_index));
3257 vat_json_object_add_int (&node, "nextnode",
3258 ntohl (mp->miss_next_index));
3259 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3260 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3261 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3262 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3263 ntohl (mp->mask_length), 0);
3264 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003265
Dave Barach72d72232016-08-04 10:15:08 -04003266 vat_json_print (vam->ofp, &node);
3267 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003268 }
Dave Barach72d72232016-08-04 10:15:08 -04003269 vam->retval = ntohl (mp->retval);
3270 vam->result_ready = 1;
3271}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003272
Dave Barach72d72232016-08-04 10:15:08 -04003273static void
3274vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3275 mp)
3276{
3277 vat_main_t *vam = &vat_main;
3278
3279 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3280 ntohl (mp->hit_next_index), ntohl (mp->advance),
3281 ntohl (mp->opaque_index));
3282 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3283 ntohl (mp->match_length));
3284}
3285
3286static void
3287 vl_api_classify_session_details_t_handler_json
3288 (vl_api_classify_session_details_t * mp)
3289{
3290 vat_main_t *vam = &vat_main;
3291 vat_json_node_t *node = NULL;
3292
3293 if (VAT_JSON_ARRAY != vam->json_tree.type)
3294 {
3295 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3296 vat_json_init_array (&vam->json_tree);
3297 }
3298 node = vat_json_array_add (&vam->json_tree);
3299
3300 vat_json_init_object (node);
3301 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3302 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3303 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3304 u8 *s =
3305 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3306 0);
3307 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003308}
Matus Fabiane8554802016-05-18 23:40:37 -07003309
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003310static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003311 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003312{
Dave Barach72d72232016-08-04 10:15:08 -04003313 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003314
Dave Barach72d72232016-08-04 10:15:08 -04003315 vam->retval = ntohl (mp->retval);
3316 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003317}
3318
3319static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003320 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003321{
Dave Barach72d72232016-08-04 10:15:08 -04003322 vat_main_t *vam = &vat_main;
3323 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003324
Dave Barach72d72232016-08-04 10:15:08 -04003325 i32 retval = ntohl (mp->retval);
3326 if (retval == 0)
3327 {
3328 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003329
Dave Barach72d72232016-08-04 10:15:08 -04003330 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003331
Dave Barach72d72232016-08-04 10:15:08 -04003332 vat_json_print (vam->ofp, &node);
3333 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003334 }
Dave Barach72d72232016-08-04 10:15:08 -04003335 vam->retval = ntohl (mp->retval);
3336 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003337}
3338
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003339static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003340 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003341{
Dave Barach72d72232016-08-04 10:15:08 -04003342 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003343
Dave Barach72d72232016-08-04 10:15:08 -04003344 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3345 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003346}
3347
3348static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003349 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003350{
Dave Barach72d72232016-08-04 10:15:08 -04003351 vat_main_t *vam = &vat_main;
3352 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003353
Dave Barach72d72232016-08-04 10:15:08 -04003354 if (VAT_JSON_ARRAY != vam->json_tree.type)
3355 {
3356 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3357 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003358 }
Dave Barach72d72232016-08-04 10:15:08 -04003359 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003360
Dave Barach72d72232016-08-04 10:15:08 -04003361 vat_json_init_object (node);
3362 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3363 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003364}
3365
Matus Fabian694265d2016-08-10 01:55:36 -07003366static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3367 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3368{
3369 vat_main_t *vam = &vat_main;
3370 i32 retval = ntohl (mp->retval);
3371 if (vam->async_mode)
3372 {
3373 vam->async_errors += (retval < 0);
3374 }
3375 else
3376 {
3377 vam->retval = retval;
3378 vam->sw_if_index = ntohl (mp->sw_if_index);
3379 vam->result_ready = 1;
3380 }
3381}
3382
3383static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3384 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3385{
3386 vat_main_t *vam = &vat_main;
3387 vat_json_node_t node;
3388
3389 vat_json_init_object (&node);
3390 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3391 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3392
3393 vat_json_print (vam->ofp, &node);
3394 vat_json_free (&node);
3395
3396 vam->retval = ntohl (mp->retval);
3397 vam->result_ready = 1;
3398}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003399
Juraj Sloboda506b2452016-08-07 23:45:24 -07003400static void vl_api_flow_classify_details_t_handler
3401 (vl_api_flow_classify_details_t * mp)
3402{
3403 vat_main_t *vam = &vat_main;
3404
3405 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3406 ntohl (mp->table_index));
3407}
3408
3409static void vl_api_flow_classify_details_t_handler_json
3410 (vl_api_flow_classify_details_t * mp)
3411{
3412 vat_main_t *vam = &vat_main;
3413 vat_json_node_t *node;
3414
3415 if (VAT_JSON_ARRAY != vam->json_tree.type)
3416 {
3417 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3418 vat_json_init_array (&vam->json_tree);
3419 }
3420 node = vat_json_array_add (&vam->json_tree);
3421
3422 vat_json_init_object (node);
3423 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3424 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3425}
3426
3427
3428
Ed Warnickecb9cada2015-12-08 15:45:58 -07003429#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3430#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3431#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3432#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
Filip Tehlar69a9b762016-09-23 10:00:52 +02003433#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler
3434#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler
Ed Warnickecb9cada2015-12-08 15:45:58 -07003435
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003436/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003437 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003438 * dig the return value out of the xxx_reply_t API message,
3439 * stick it into vam->retval, and set vam->result_ready
3440 *
3441 * Could also do this by pointing N message decode slots at
3442 * a single function, but that could break in subtle ways.
3443 */
3444
3445#define foreach_standard_reply_retval_handler \
3446_(sw_interface_set_flags_reply) \
3447_(sw_interface_add_del_address_reply) \
3448_(sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003449_(sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003450_(sw_interface_set_vpath_reply) \
3451_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003452_(sw_interface_set_dpdk_hqos_pipe_reply) \
3453_(sw_interface_set_dpdk_hqos_subport_reply) \
3454_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003455_(bridge_domain_add_del_reply) \
3456_(sw_interface_set_l2_xconnect_reply) \
3457_(l2fib_add_del_reply) \
3458_(ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003459_(mpls_route_add_del_reply) \
3460_(mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003461_(proxy_arp_add_del_reply) \
3462_(proxy_arp_intfc_enable_disable_reply) \
3463_(mpls_add_del_encap_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003464_(mpls_ethernet_add_del_tunnel_2_reply) \
3465_(sw_interface_set_unnumbered_reply) \
3466_(ip_neighbor_add_del_reply) \
3467_(reset_vrf_reply) \
3468_(oam_add_del_reply) \
3469_(reset_fib_reply) \
3470_(dhcp_proxy_config_reply) \
3471_(dhcp_proxy_config_2_reply) \
3472_(dhcp_proxy_set_vss_reply) \
3473_(dhcp_client_config_reply) \
3474_(set_ip_flow_hash_reply) \
3475_(sw_interface_ip6_enable_disable_reply) \
3476_(sw_interface_ip6_set_link_local_address_reply) \
3477_(sw_interface_ip6nd_ra_prefix_reply) \
3478_(sw_interface_ip6nd_ra_config_reply) \
3479_(set_arp_neighbor_limit_reply) \
3480_(l2_patch_add_del_reply) \
3481_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003482_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003483_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003484_(classify_add_del_session_reply) \
3485_(classify_set_interface_ip_table_reply) \
3486_(classify_set_interface_l2_tables_reply) \
3487_(l2tpv3_set_tunnel_cookies_reply) \
3488_(l2tpv3_interface_enable_disable_reply) \
3489_(l2tpv3_set_lookup_key_reply) \
3490_(l2_fib_clear_table_reply) \
3491_(l2_interface_efp_filter_reply) \
3492_(l2_interface_vlan_tag_rewrite_reply) \
3493_(modify_vhost_user_if_reply) \
3494_(delete_vhost_user_if_reply) \
3495_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003496_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003497_(input_acl_set_interface_reply) \
3498_(ipsec_spd_add_del_reply) \
3499_(ipsec_interface_add_del_spd_reply) \
3500_(ipsec_spd_add_del_entry_reply) \
3501_(ipsec_sad_add_del_entry_reply) \
3502_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003503_(ikev2_profile_add_del_reply) \
3504_(ikev2_profile_set_auth_reply) \
3505_(ikev2_profile_set_id_reply) \
3506_(ikev2_profile_set_ts_reply) \
3507_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003508_(delete_loopback_reply) \
3509_(bd_ip_mac_add_del_reply) \
3510_(map_del_domain_reply) \
3511_(map_add_del_rule_reply) \
3512_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003513_(want_stats_reply) \
3514_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003515_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003516_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003517_(ioam_enable_reply) \
3518_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003519_(lisp_add_del_locator_reply) \
3520_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003521_(lisp_add_del_remote_mapping_reply) \
3522_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003523_(lisp_gpe_add_del_fwd_entry_reply) \
3524_(lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003525_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003526_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003527_(lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003528_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003529_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003530_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003531_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003532_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003533_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003534_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003535_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003536_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003537_(set_ipfix_exporter_reply) \
3538_(set_ipfix_classify_stream_reply) \
3539_(ipfix_classify_table_add_del_reply) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003540_(flow_classify_set_interface_reply) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003541_(sw_interface_span_enable_disable_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003542_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003543_(pg_enable_disable_reply) \
3544_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003545_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003546_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003547_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003548_(punt_reply) \
3549_(feature_enable_disable_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003550
3551#define _(n) \
3552 static void vl_api_##n##_t_handler \
3553 (vl_api_##n##_t * mp) \
3554 { \
3555 vat_main_t * vam = &vat_main; \
3556 i32 retval = ntohl(mp->retval); \
3557 if (vam->async_mode) { \
3558 vam->async_errors += (retval < 0); \
3559 } else { \
3560 vam->retval = retval; \
3561 vam->result_ready = 1; \
3562 } \
3563 }
3564foreach_standard_reply_retval_handler;
3565#undef _
3566
3567#define _(n) \
3568 static void vl_api_##n##_t_handler_json \
3569 (vl_api_##n##_t * mp) \
3570 { \
3571 vat_main_t * vam = &vat_main; \
3572 vat_json_node_t node; \
3573 vat_json_init_object(&node); \
3574 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3575 vat_json_print(vam->ofp, &node); \
3576 vam->retval = ntohl(mp->retval); \
3577 vam->result_ready = 1; \
3578 }
3579foreach_standard_reply_retval_handler;
3580#undef _
3581
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003582/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003583 * Table of message reply handlers, must include boilerplate handlers
3584 * we just generated
3585 */
3586
3587#define foreach_vpe_api_reply_msg \
3588_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3589_(SW_INTERFACE_DETAILS, sw_interface_details) \
3590_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3591_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3592_(CONTROL_PING_REPLY, control_ping_reply) \
3593_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003594_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003595_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3596 sw_interface_add_del_address_reply) \
3597_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003598_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003599_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3600_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3601 sw_interface_set_l2_xconnect_reply) \
3602_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3603 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003604_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3605 sw_interface_set_dpdk_hqos_pipe_reply) \
3606_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3607 sw_interface_set_dpdk_hqos_subport_reply) \
3608_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3609 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003610_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3611_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3612_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3613_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3614_(L2_FLAGS_REPLY, l2_flags_reply) \
3615_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3616_(TAP_CONNECT_REPLY, tap_connect_reply) \
3617_(TAP_MODIFY_REPLY, tap_modify_reply) \
3618_(TAP_DELETE_REPLY, tap_delete_reply) \
3619_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3620_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003621_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3622_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003623_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3624_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3625 proxy_arp_intfc_enable_disable_reply) \
3626_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003627_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3628 mpls_ethernet_add_del_tunnel_reply) \
3629_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3630 mpls_ethernet_add_del_tunnel_2_reply) \
3631_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3632 sw_interface_set_unnumbered_reply) \
3633_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3634_(RESET_VRF_REPLY, reset_vrf_reply) \
3635_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3636_(CREATE_SUBIF_REPLY, create_subif_reply) \
3637_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3638_(RESET_FIB_REPLY, reset_fib_reply) \
3639_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3640_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3641_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3642_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3643_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3644_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3645 sw_interface_ip6_enable_disable_reply) \
3646_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3647 sw_interface_ip6_set_link_local_address_reply) \
3648_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3649 sw_interface_ip6nd_ra_prefix_reply) \
3650_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3651 sw_interface_ip6nd_ra_config_reply) \
3652_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3653_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3654_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003655_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3656_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003657_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3658_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3659_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3660classify_set_interface_ip_table_reply) \
3661_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3662 classify_set_interface_l2_tables_reply) \
3663_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3664_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3665_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3666_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3667_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3668 l2tpv3_interface_enable_disable_reply) \
3669_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3670_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3671_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003672_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003673_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3674_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003675_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3676_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3677_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3678_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3679_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3680_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3681_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3682_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003683_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003684_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3685_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003686_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3687_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3688_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003689_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3690_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003691_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3692_(IP_ADDRESS_DETAILS, ip_address_details) \
3693_(IP_DETAILS, ip_details) \
3694_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3695_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3696_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3697_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3698_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003699_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3700_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3701_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3702_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3703_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003704_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3705_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3706_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3707_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3708_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3709_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3710_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3711_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003712_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003713_(MAP_DOMAIN_DETAILS, map_domain_details) \
3714_(MAP_RULE_DETAILS, map_rule_details) \
3715_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3716_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003717_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3718_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003719_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003720_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003721_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003722_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3723_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003724_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3725_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3726_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003727_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3728_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003729_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3730_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003731_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003732_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003733_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003734_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003735_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003736_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3737_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003738_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003739_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003740_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003741_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003742_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003743_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Filip Tehlar69a9b762016-09-23 10:00:52 +02003744_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003745_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003746_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3747 lisp_add_del_map_request_itr_rlocs_reply) \
3748_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3749 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003750_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003751_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003752_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003753_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003754_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003755_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003756_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3757_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003758_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003759_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003760_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3761_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003762_(MPLS_FIB_DETAILS, mpls_fib_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003763_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3764_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3765_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003766_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003767_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3768_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3769_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3770_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3771_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3772_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003773_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3774_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003775_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3776_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003777_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3778_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3779_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003780_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3781_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3782 ip_source_and_port_range_check_add_del_reply) \
3783_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003784 ip_source_and_port_range_check_interface_add_del_reply) \
3785_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003786_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003787_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003788_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Steven01b07122016-11-02 10:40:09 -07003789_(PUNT_REPLY, punt_reply) \
3790_(IP_FIB_DETAILS, ip_fib_details) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003791_(IP6_FIB_DETAILS, ip6_fib_details) \
3792_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003793
3794/* M: construct, but don't yet send a message */
3795
3796#define M(T,t) \
3797do { \
3798 vam->result_ready = 0; \
3799 mp = vl_msg_api_alloc(sizeof(*mp)); \
3800 memset (mp, 0, sizeof (*mp)); \
3801 mp->_vl_msg_id = ntohs (VL_API_##T); \
3802 mp->client_index = vam->my_client_index; \
3803} while(0);
3804
3805#define M2(T,t,n) \
3806do { \
3807 vam->result_ready = 0; \
3808 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3809 memset (mp, 0, sizeof (*mp)); \
3810 mp->_vl_msg_id = ntohs (VL_API_##T); \
3811 mp->client_index = vam->my_client_index; \
3812} while(0);
3813
3814
3815/* S: send a message */
3816#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3817
3818/* W: wait for results, with timeout */
3819#define W \
3820do { \
3821 timeout = vat_time_now (vam) + 1.0; \
3822 \
3823 while (vat_time_now (vam) < timeout) { \
3824 if (vam->result_ready == 1) { \
3825 return (vam->retval); \
3826 } \
3827 } \
3828 return -99; \
3829} while(0);
3830
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003831/* W2: wait for results, with timeout */
3832#define W2(body) \
3833do { \
3834 timeout = vat_time_now (vam) + 1.0; \
3835 \
3836 while (vat_time_now (vam) < timeout) { \
3837 if (vam->result_ready == 1) { \
3838 (body); \
3839 return (vam->retval); \
3840 } \
3841 } \
3842 return -99; \
3843} while(0);
3844
Dave Barach72d72232016-08-04 10:15:08 -04003845typedef struct
3846{
3847 u8 *name;
3848 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003849} name_sort_t;
3850
3851
3852#define STR_VTR_OP_CASE(op) \
3853 case L2_VTR_ ## op: \
3854 return "" # op;
3855
Dave Barach72d72232016-08-04 10:15:08 -04003856static const char *
3857str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003858{
Dave Barach72d72232016-08-04 10:15:08 -04003859 switch (vtr_op)
3860 {
3861 STR_VTR_OP_CASE (DISABLED);
3862 STR_VTR_OP_CASE (PUSH_1);
3863 STR_VTR_OP_CASE (PUSH_2);
3864 STR_VTR_OP_CASE (POP_1);
3865 STR_VTR_OP_CASE (POP_2);
3866 STR_VTR_OP_CASE (TRANSLATE_1_1);
3867 STR_VTR_OP_CASE (TRANSLATE_1_2);
3868 STR_VTR_OP_CASE (TRANSLATE_2_1);
3869 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003870 }
3871
Dave Barach72d72232016-08-04 10:15:08 -04003872 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003873}
3874
Dave Barach72d72232016-08-04 10:15:08 -04003875static int
3876dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003877{
Dave Barach72d72232016-08-04 10:15:08 -04003878 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003879
Dave Barach72d72232016-08-04 10:15:08 -04003880 if (vam->json_output)
3881 {
3882 clib_warning
3883 ("JSON output supported only for VPE API calls and dump_stats_table");
3884 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003885 }
3886
Dave Barach72d72232016-08-04 10:15:08 -04003887 fformat (vam->ofp,
3888 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3889 "Interface", "sw_if_index",
3890 "sub id", "dot1ad", "tags", "outer id",
3891 "inner id", "exact", "default", "outer any", "inner any");
3892
3893 vec_foreach (sub, vam->sw_if_subif_table)
3894 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003895 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003896 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3897 sub->interface_name,
3898 sub->sw_if_index,
3899 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3900 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3901 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3902 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3903 if (sub->vtr_op != L2_VTR_DISABLED)
3904 {
3905 fformat (vam->ofp,
3906 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3907 "tag1: %d tag2: %d ]\n",
3908 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3909 sub->vtr_tag1, sub->vtr_tag2);
3910 }
3911 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003912
Dave Barach72d72232016-08-04 10:15:08 -04003913 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003914}
3915
Dave Barach72d72232016-08-04 10:15:08 -04003916static int
3917name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003918{
Dave Barach72d72232016-08-04 10:15:08 -04003919 name_sort_t *n1 = a1;
3920 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003921
Dave Barach72d72232016-08-04 10:15:08 -04003922 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003923}
3924
Dave Barach72d72232016-08-04 10:15:08 -04003925static int
3926dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003927{
Dave Barach72d72232016-08-04 10:15:08 -04003928 hash_pair_t *p;
3929 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003930
Dave Barach72d72232016-08-04 10:15:08 -04003931 if (vam->json_output)
3932 {
3933 clib_warning
3934 ("JSON output supported only for VPE API calls and dump_stats_table");
3935 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003936 }
3937
Dave Barach72d72232016-08-04 10:15:08 -04003938 /* *INDENT-OFF* */
3939 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3940 ({
3941 vec_add2 (nses, ns, 1);
3942 ns->name = (u8 *)(p->key);
3943 ns->value = (u32) p->value[0];
3944 }));
3945 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003946
Dave Barach72d72232016-08-04 10:15:08 -04003947 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003948
Dave Barach72d72232016-08-04 10:15:08 -04003949 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3950 vec_foreach (ns, nses)
3951 {
3952 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3953 }
3954 vec_free (nses);
3955 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003956}
3957
Dave Barach72d72232016-08-04 10:15:08 -04003958static int
3959dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003960{
Dave Barach72d72232016-08-04 10:15:08 -04003961 const ip_details_t *det = NULL;
3962 const ip_address_details_t *address = NULL;
3963 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003964
Dave Barach72d72232016-08-04 10:15:08 -04003965 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3966
Dave Barach72d72232016-08-04 10:15:08 -04003967 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3968 {
3969 i++;
3970 if (!det->present)
3971 {
3972 continue;
3973 }
3974 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003975 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003976 " %-30s%-13s\n", "Address", "Prefix length");
3977 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003978 {
Dave Barach72d72232016-08-04 10:15:08 -04003979 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003980 }
Dave Barach72d72232016-08-04 10:15:08 -04003981 vec_foreach (address, det->addr)
3982 {
3983 fformat (vam->ofp,
3984 " %-30U%-13d\n",
3985 is_ipv6 ? format_ip6_address : format_ip4_address,
3986 address->ip, address->prefix_length);
3987 }
3988 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003989
Dave Barach72d72232016-08-04 10:15:08 -04003990 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003991}
3992
Dave Barach72d72232016-08-04 10:15:08 -04003993static int
3994dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003995{
Dave Barach72d72232016-08-04 10:15:08 -04003996 if (vam->json_output)
3997 {
3998 clib_warning
3999 ("JSON output supported only for VPE API calls and dump_stats_table");
4000 return -99;
4001 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004002
Dave Barach72d72232016-08-04 10:15:08 -04004003 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004004}
4005
Dave Barach72d72232016-08-04 10:15:08 -04004006static int
4007dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004008{
Dave Barach72d72232016-08-04 10:15:08 -04004009 if (vam->json_output)
4010 {
4011 clib_warning
4012 ("JSON output supported only for VPE API calls and dump_stats_table");
4013 return -99;
4014 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004015
Dave Barach72d72232016-08-04 10:15:08 -04004016 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004017}
4018
Dave Barach72d72232016-08-04 10:15:08 -04004019static char *
4020counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004021{
Dave Barach72d72232016-08-04 10:15:08 -04004022 if (!is_combined)
4023 {
4024 switch (counter_type)
4025 {
4026 case VNET_INTERFACE_COUNTER_DROP:
4027 return "drop";
4028 case VNET_INTERFACE_COUNTER_PUNT:
4029 return "punt";
4030 case VNET_INTERFACE_COUNTER_IP4:
4031 return "ip4";
4032 case VNET_INTERFACE_COUNTER_IP6:
4033 return "ip6";
4034 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4035 return "rx-no-buf";
4036 case VNET_INTERFACE_COUNTER_RX_MISS:
4037 return "rx-miss";
4038 case VNET_INTERFACE_COUNTER_RX_ERROR:
4039 return "rx-error";
4040 case VNET_INTERFACE_COUNTER_TX_ERROR:
4041 return "tx-error";
4042 default:
4043 return "INVALID-COUNTER-TYPE";
4044 }
4045 }
4046 else
4047 {
4048 switch (counter_type)
4049 {
4050 case VNET_INTERFACE_COUNTER_RX:
4051 return "rx";
4052 case VNET_INTERFACE_COUNTER_TX:
4053 return "tx";
4054 default:
4055 return "INVALID-COUNTER-TYPE";
4056 }
4057 }
4058}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004059
Dave Barach72d72232016-08-04 10:15:08 -04004060static int
4061dump_stats_table (vat_main_t * vam)
4062{
4063 vat_json_node_t node;
4064 vat_json_node_t *msg_array;
4065 vat_json_node_t *msg;
4066 vat_json_node_t *counter_array;
4067 vat_json_node_t *counter;
4068 interface_counter_t c;
4069 u64 packets;
4070 ip4_fib_counter_t *c4;
4071 ip6_fib_counter_t *c6;
4072 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004073
Dave Barach72d72232016-08-04 10:15:08 -04004074 if (!vam->json_output)
4075 {
4076 clib_warning ("dump_stats_table supported only in JSON format");
4077 return -99;
4078 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004079
Dave Barach72d72232016-08-04 10:15:08 -04004080 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004081
Dave Barach72d72232016-08-04 10:15:08 -04004082 /* interface counters */
4083 msg_array = vat_json_object_add (&node, "interface_counters");
4084 vat_json_init_array (msg_array);
4085 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4086 {
4087 msg = vat_json_array_add (msg_array);
4088 vat_json_init_object (msg);
4089 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4090 (u8 *) counter_type_to_str (i, 0));
4091 vat_json_object_add_int (msg, "is_combined", 0);
4092 counter_array = vat_json_object_add (msg, "data");
4093 vat_json_init_array (counter_array);
4094 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4095 {
4096 packets = vam->simple_interface_counters[i][j];
4097 vat_json_array_add_uint (counter_array, packets);
4098 }
4099 }
4100 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4101 {
4102 msg = vat_json_array_add (msg_array);
4103 vat_json_init_object (msg);
4104 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4105 (u8 *) counter_type_to_str (i, 1));
4106 vat_json_object_add_int (msg, "is_combined", 1);
4107 counter_array = vat_json_object_add (msg, "data");
4108 vat_json_init_array (counter_array);
4109 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4110 {
4111 c = vam->combined_interface_counters[i][j];
4112 counter = vat_json_array_add (counter_array);
4113 vat_json_init_object (counter);
4114 vat_json_object_add_uint (counter, "packets", c.packets);
4115 vat_json_object_add_uint (counter, "bytes", c.bytes);
4116 }
4117 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004118
Dave Barach72d72232016-08-04 10:15:08 -04004119 /* ip4 fib counters */
4120 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4121 vat_json_init_array (msg_array);
4122 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4123 {
4124 msg = vat_json_array_add (msg_array);
4125 vat_json_init_object (msg);
4126 vat_json_object_add_uint (msg, "vrf_id",
4127 vam->ip4_fib_counters_vrf_id_by_index[i]);
4128 counter_array = vat_json_object_add (msg, "c");
4129 vat_json_init_array (counter_array);
4130 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4131 {
4132 counter = vat_json_array_add (counter_array);
4133 vat_json_init_object (counter);
4134 c4 = &vam->ip4_fib_counters[i][j];
4135 vat_json_object_add_ip4 (counter, "address", c4->address);
4136 vat_json_object_add_uint (counter, "address_length",
4137 c4->address_length);
4138 vat_json_object_add_uint (counter, "packets", c4->packets);
4139 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4140 }
4141 }
4142
4143 /* ip6 fib counters */
4144 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4145 vat_json_init_array (msg_array);
4146 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4147 {
4148 msg = vat_json_array_add (msg_array);
4149 vat_json_init_object (msg);
4150 vat_json_object_add_uint (msg, "vrf_id",
4151 vam->ip6_fib_counters_vrf_id_by_index[i]);
4152 counter_array = vat_json_object_add (msg, "c");
4153 vat_json_init_array (counter_array);
4154 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4155 {
4156 counter = vat_json_array_add (counter_array);
4157 vat_json_init_object (counter);
4158 c6 = &vam->ip6_fib_counters[i][j];
4159 vat_json_object_add_ip6 (counter, "address", c6->address);
4160 vat_json_object_add_uint (counter, "address_length",
4161 c6->address_length);
4162 vat_json_object_add_uint (counter, "packets", c6->packets);
4163 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4164 }
4165 }
4166
4167 vat_json_print (vam->ofp, &node);
4168 vat_json_free (&node);
4169
4170 return 0;
4171}
4172
4173int
4174exec (vat_main_t * vam)
4175{
4176 api_main_t *am = &api_main;
4177 vl_api_cli_request_t *mp;
4178 f64 timeout;
4179 void *oldheap;
4180 u8 *cmd = 0;
4181 unformat_input_t *i = vam->input;
4182
4183 if (vec_len (i->buffer) == 0)
4184 return -1;
4185
4186 if (vam->exec_mode == 0 && unformat (i, "mode"))
4187 {
4188 vam->exec_mode = 1;
4189 return 0;
4190 }
4191 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4192 {
4193 vam->exec_mode = 0;
4194 return 0;
4195 }
4196
4197
4198 M (CLI_REQUEST, cli_request);
4199
4200 /*
4201 * Copy cmd into shared memory.
4202 * In order for the CLI command to work, it
4203 * must be a vector ending in \n, not a C-string ending
4204 * in \n\0.
4205 */
4206 pthread_mutex_lock (&am->vlib_rp->mutex);
4207 oldheap = svm_push_data_heap (am->vlib_rp);
4208
4209 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4210 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4211
4212 svm_pop_heap (oldheap);
4213 pthread_mutex_unlock (&am->vlib_rp->mutex);
4214
4215 mp->cmd_in_shmem = (u64) cmd;
4216 S;
4217 timeout = vat_time_now (vam) + 10.0;
4218
4219 while (vat_time_now (vam) < timeout)
4220 {
4221 if (vam->result_ready == 1)
4222 {
4223 u8 *free_me;
4224 if (vam->shmem_result != NULL)
4225 fformat (vam->ofp, "%s", vam->shmem_result);
4226 pthread_mutex_lock (&am->vlib_rp->mutex);
4227 oldheap = svm_push_data_heap (am->vlib_rp);
4228
4229 free_me = (u8 *) vam->shmem_result;
4230 vec_free (free_me);
4231
4232 svm_pop_heap (oldheap);
4233 pthread_mutex_unlock (&am->vlib_rp->mutex);
4234 return 0;
4235 }
4236 }
4237 return -99;
4238}
4239
Ole Troanc27213a2016-08-31 14:50:49 +02004240/*
4241 * Future replacement of exec() that passes CLI buffers directly in
4242 * the API messages instead of an additional shared memory area.
4243 */
4244static int
4245exec_inband (vat_main_t * vam)
4246{
4247 vl_api_cli_inband_t *mp;
4248 f64 timeout;
4249 unformat_input_t *i = vam->input;
4250
4251 if (vec_len (i->buffer) == 0)
4252 return -1;
4253
4254 if (vam->exec_mode == 0 && unformat (i, "mode"))
4255 {
4256 vam->exec_mode = 1;
4257 return 0;
4258 }
4259 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4260 {
4261 vam->exec_mode = 0;
4262 return 0;
4263 }
4264
4265 /*
4266 * In order for the CLI command to work, it
4267 * must be a vector ending in \n, not a C-string ending
4268 * in \n\0.
4269 */
4270 u32 len = vec_len (vam->input->buffer);
4271 M2 (CLI_INBAND, cli_inband, len);
4272 clib_memcpy (mp->cmd, vam->input->buffer, len);
4273 mp->length = htonl (len);
4274
4275 S;
4276 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4277}
4278
Dave Barach72d72232016-08-04 10:15:08 -04004279static int
4280api_create_loopback (vat_main_t * vam)
4281{
4282 unformat_input_t *i = vam->input;
4283 vl_api_create_loopback_t *mp;
4284 f64 timeout;
4285 u8 mac_address[6];
4286 u8 mac_set = 0;
4287
4288 memset (mac_address, 0, sizeof (mac_address));
4289
4290 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4291 {
4292 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4293 mac_set = 1;
4294 else
4295 break;
4296 }
4297
4298 /* Construct the API message */
4299 M (CREATE_LOOPBACK, create_loopback);
4300 if (mac_set)
4301 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4302
4303 S;
4304 W;
4305}
4306
4307static int
4308api_delete_loopback (vat_main_t * vam)
4309{
4310 unformat_input_t *i = vam->input;
4311 vl_api_delete_loopback_t *mp;
4312 f64 timeout;
4313 u32 sw_if_index = ~0;
4314
4315 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4316 {
4317 if (unformat (i, "sw_if_index %d", &sw_if_index))
4318 ;
4319 else
4320 break;
4321 }
4322
4323 if (sw_if_index == ~0)
4324 {
4325 errmsg ("missing sw_if_index\n");
4326 return -99;
4327 }
4328
4329 /* Construct the API message */
4330 M (DELETE_LOOPBACK, delete_loopback);
4331 mp->sw_if_index = ntohl (sw_if_index);
4332
4333 S;
4334 W;
4335}
4336
4337static int
4338api_want_stats (vat_main_t * vam)
4339{
4340 unformat_input_t *i = vam->input;
4341 vl_api_want_stats_t *mp;
4342 f64 timeout;
4343 int enable = -1;
4344
4345 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4346 {
4347 if (unformat (i, "enable"))
4348 enable = 1;
4349 else if (unformat (i, "disable"))
4350 enable = 0;
4351 else
4352 break;
4353 }
4354
4355 if (enable == -1)
4356 {
4357 errmsg ("missing enable|disable\n");
4358 return -99;
4359 }
4360
4361 M (WANT_STATS, want_stats);
4362 mp->enable_disable = enable;
4363
4364 S;
4365 W;
4366}
4367
4368static int
4369api_want_interface_events (vat_main_t * vam)
4370{
4371 unformat_input_t *i = vam->input;
4372 vl_api_want_interface_events_t *mp;
4373 f64 timeout;
4374 int enable = -1;
4375
4376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4377 {
4378 if (unformat (i, "enable"))
4379 enable = 1;
4380 else if (unformat (i, "disable"))
4381 enable = 0;
4382 else
4383 break;
4384 }
4385
4386 if (enable == -1)
4387 {
4388 errmsg ("missing enable|disable\n");
4389 return -99;
4390 }
4391
4392 M (WANT_INTERFACE_EVENTS, want_interface_events);
4393 mp->enable_disable = enable;
4394
4395 vam->interface_event_display = enable;
4396
4397 S;
4398 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004399}
4400
4401
4402/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004403int
4404api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004405{
Dave Barach72d72232016-08-04 10:15:08 -04004406 vl_api_sw_interface_dump_t *mp;
4407 f64 timeout;
4408 hash_pair_t *p;
4409 name_sort_t *nses = 0, *ns;
4410 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004411
Dave Barach72d72232016-08-04 10:15:08 -04004412 /* Toss the old name table */
4413 /* *INDENT-OFF* */
4414 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4415 ({
4416 vec_add2 (nses, ns, 1);
4417 ns->name = (u8 *)(p->key);
4418 ns->value = (u32) p->value[0];
4419 }));
4420 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004421
Dave Barach72d72232016-08-04 10:15:08 -04004422 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004423
Dave Barach72d72232016-08-04 10:15:08 -04004424 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004425
Dave Barach72d72232016-08-04 10:15:08 -04004426 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004427
Dave Barach72d72232016-08-04 10:15:08 -04004428 vec_foreach (sub, vam->sw_if_subif_table)
4429 {
4430 vec_free (sub->interface_name);
4431 }
4432 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004433
Dave Barach72d72232016-08-04 10:15:08 -04004434 /* recreate the interface name hash table */
4435 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004436
Dave Barach72d72232016-08-04 10:15:08 -04004437 /* Get list of ethernets */
4438 M (SW_INTERFACE_DUMP, sw_interface_dump);
4439 mp->name_filter_valid = 1;
4440 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4441 S;
4442
4443 /* and local / loopback interfaces */
4444 M (SW_INTERFACE_DUMP, sw_interface_dump);
4445 mp->name_filter_valid = 1;
4446 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4447 S;
4448
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004449 /* and packet-generator interfaces */
4450 M (SW_INTERFACE_DUMP, sw_interface_dump);
4451 mp->name_filter_valid = 1;
4452 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4453 S;
Dave Barach72d72232016-08-04 10:15:08 -04004454
4455 /* and vxlan-gpe tunnel interfaces */
4456 M (SW_INTERFACE_DUMP, sw_interface_dump);
4457 mp->name_filter_valid = 1;
4458 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4459 sizeof (mp->name_filter) - 1);
4460 S;
4461
4462 /* and vxlan tunnel interfaces */
4463 M (SW_INTERFACE_DUMP, sw_interface_dump);
4464 mp->name_filter_valid = 1;
4465 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4466 S;
4467
4468 /* and host (af_packet) interfaces */
4469 M (SW_INTERFACE_DUMP, sw_interface_dump);
4470 mp->name_filter_valid = 1;
4471 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4472 S;
4473
4474 /* and l2tpv3 tunnel interfaces */
4475 M (SW_INTERFACE_DUMP, sw_interface_dump);
4476 mp->name_filter_valid = 1;
4477 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4478 sizeof (mp->name_filter) - 1);
4479 S;
4480
4481 /* and GRE tunnel interfaces */
4482 M (SW_INTERFACE_DUMP, sw_interface_dump);
4483 mp->name_filter_valid = 1;
4484 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4485 S;
4486
Florin Corasce982752016-09-06 13:36:11 +02004487 /* and LISP-GPE interfaces */
4488 M (SW_INTERFACE_DUMP, sw_interface_dump);
4489 mp->name_filter_valid = 1;
4490 strncpy ((char *) mp->name_filter, "lisp_gpe",
4491 sizeof (mp->name_filter) - 1);
4492 S;
4493
Matus Fabian8fce3e32016-09-06 23:19:43 -07004494 /* and IPSEC tunnel interfaces */
4495 M (SW_INTERFACE_DUMP, sw_interface_dump);
4496 mp->name_filter_valid = 1;
4497 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4498 S;
4499
Dave Barach72d72232016-08-04 10:15:08 -04004500 /* Use a control ping for synchronization */
4501 {
4502 vl_api_control_ping_t *mp;
4503 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004504 S;
Dave Barach72d72232016-08-04 10:15:08 -04004505 }
4506 W;
4507}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004508
Dave Barach72d72232016-08-04 10:15:08 -04004509static int
4510api_sw_interface_set_flags (vat_main_t * vam)
4511{
4512 unformat_input_t *i = vam->input;
4513 vl_api_sw_interface_set_flags_t *mp;
4514 f64 timeout;
4515 u32 sw_if_index;
4516 u8 sw_if_index_set = 0;
4517 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004518
Dave Barach72d72232016-08-04 10:15:08 -04004519 /* Parse args required to build the message */
4520 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004521 {
Dave Barach72d72232016-08-04 10:15:08 -04004522 if (unformat (i, "admin-up"))
4523 admin_up = 1;
4524 else if (unformat (i, "admin-down"))
4525 admin_up = 0;
4526 else if (unformat (i, "link-up"))
4527 link_up = 1;
4528 else if (unformat (i, "link-down"))
4529 link_up = 0;
4530 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4531 sw_if_index_set = 1;
4532 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4533 sw_if_index_set = 1;
4534 else
4535 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004536 }
4537
Dave Barach72d72232016-08-04 10:15:08 -04004538 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004539 {
Dave Barach72d72232016-08-04 10:15:08 -04004540 errmsg ("missing interface name or sw_if_index\n");
4541 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004542 }
4543
Dave Barach72d72232016-08-04 10:15:08 -04004544 /* Construct the API message */
4545 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4546 mp->sw_if_index = ntohl (sw_if_index);
4547 mp->admin_up_down = admin_up;
4548 mp->link_up_down = link_up;
4549
4550 /* send it... */
4551 S;
4552
4553 /* Wait for a reply, return the good/bad news... */
4554 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004555}
4556
Dave Barach72d72232016-08-04 10:15:08 -04004557static int
4558api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004559{
Dave Barach72d72232016-08-04 10:15:08 -04004560 unformat_input_t *i = vam->input;
4561 vl_api_sw_interface_clear_stats_t *mp;
4562 f64 timeout;
4563 u32 sw_if_index;
4564 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004565
Dave Barach72d72232016-08-04 10:15:08 -04004566 /* Parse args required to build the message */
4567 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4568 {
4569 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4570 sw_if_index_set = 1;
4571 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4572 sw_if_index_set = 1;
4573 else
4574 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004575 }
4576
Dave Barach72d72232016-08-04 10:15:08 -04004577 /* Construct the API message */
4578 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004579
Dave Barach72d72232016-08-04 10:15:08 -04004580 if (sw_if_index_set == 1)
4581 mp->sw_if_index = ntohl (sw_if_index);
4582 else
4583 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004584
Dave Barach72d72232016-08-04 10:15:08 -04004585 /* send it... */
4586 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004587
Dave Barach72d72232016-08-04 10:15:08 -04004588 /* Wait for a reply, return the good/bad news... */
4589 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004590}
4591
Dave Barach72d72232016-08-04 10:15:08 -04004592static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004593api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4594{
4595 unformat_input_t *i = vam->input;
4596 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4597 f64 timeout;
4598 u32 sw_if_index;
4599 u8 sw_if_index_set = 0;
4600 u32 subport;
4601 u8 subport_set = 0;
4602 u32 pipe;
4603 u8 pipe_set = 0;
4604 u32 profile;
4605 u8 profile_set = 0;
4606
4607 /* Parse args required to build the message */
4608 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4609 {
4610 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4611 sw_if_index_set = 1;
4612 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4613 sw_if_index_set = 1;
4614 else if (unformat (i, "subport %u", &subport))
4615 subport_set = 1;
4616 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4617 sw_if_index_set = 1;
4618 else if (unformat (i, "pipe %u", &pipe))
4619 pipe_set = 1;
4620 else if (unformat (i, "profile %u", &profile))
4621 profile_set = 1;
4622 else
4623 break;
4624 }
4625
4626 if (sw_if_index_set == 0)
4627 {
4628 errmsg ("missing interface name or sw_if_index\n");
4629 return -99;
4630 }
4631
4632 if (subport_set == 0)
4633 {
4634 errmsg ("missing subport \n");
4635 return -99;
4636 }
4637
4638 if (pipe_set == 0)
4639 {
4640 errmsg ("missing pipe\n");
4641 return -99;
4642 }
4643
4644 if (profile_set == 0)
4645 {
4646 errmsg ("missing profile\n");
4647 return -99;
4648 }
4649
4650 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4651
4652 mp->sw_if_index = ntohl (sw_if_index);
4653 mp->subport = ntohl (subport);
4654 mp->pipe = ntohl (pipe);
4655 mp->profile = ntohl (profile);
4656
4657
4658 S;
4659 W;
4660 /* NOTREACHED */
4661 return 0;
4662}
4663
4664static int
4665api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4666{
4667 unformat_input_t *i = vam->input;
4668 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4669 f64 timeout;
4670 u32 sw_if_index;
4671 u8 sw_if_index_set = 0;
4672 u32 subport;
4673 u8 subport_set = 0;
4674 u32 tb_rate = 1250000000; /* 10GbE */
4675 u32 tb_size = 1000000;
4676 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4677 u32 tc_period = 10;
4678
4679 /* Parse args required to build the message */
4680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4681 {
4682 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4683 sw_if_index_set = 1;
4684 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4685 sw_if_index_set = 1;
4686 else if (unformat (i, "subport %u", &subport))
4687 subport_set = 1;
4688 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4689 sw_if_index_set = 1;
4690 else if (unformat (i, "rate %u", &tb_rate))
4691 {
4692 u32 tc_id;
4693
4694 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4695 tc_id++)
4696 tc_rate[tc_id] = tb_rate;
4697 }
4698 else if (unformat (i, "bktsize %u", &tb_size))
4699 ;
4700 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4701 ;
4702 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4703 ;
4704 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4705 ;
4706 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4707 ;
4708 else if (unformat (i, "period %u", &tc_period))
4709 ;
4710 else
4711 break;
4712 }
4713
4714 if (sw_if_index_set == 0)
4715 {
4716 errmsg ("missing interface name or sw_if_index\n");
4717 return -99;
4718 }
4719
4720 if (subport_set == 0)
4721 {
4722 errmsg ("missing subport \n");
4723 return -99;
4724 }
4725
4726 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4727
4728 mp->sw_if_index = ntohl (sw_if_index);
4729 mp->subport = ntohl (subport);
4730 mp->tb_rate = ntohl (tb_rate);
4731 mp->tb_size = ntohl (tb_size);
4732 mp->tc_rate[0] = ntohl (tc_rate[0]);
4733 mp->tc_rate[1] = ntohl (tc_rate[1]);
4734 mp->tc_rate[2] = ntohl (tc_rate[2]);
4735 mp->tc_rate[3] = ntohl (tc_rate[3]);
4736 mp->tc_period = ntohl (tc_period);
4737
4738 S;
4739 W;
4740 /* NOTREACHED */
4741 return 0;
4742}
4743
4744static int
4745api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4746{
4747 unformat_input_t *i = vam->input;
4748 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4749 f64 timeout;
4750 u32 sw_if_index;
4751 u8 sw_if_index_set = 0;
4752 u8 entry_set = 0;
4753 u8 tc_set = 0;
4754 u8 queue_set = 0;
4755 u32 entry, tc, queue;
4756
4757 /* Parse args required to build the message */
4758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4759 {
4760 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4761 sw_if_index_set = 1;
4762 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4763 sw_if_index_set = 1;
4764 else if (unformat (i, "entry %d", &entry))
4765 entry_set = 1;
4766 else if (unformat (i, "tc %d", &tc))
4767 tc_set = 1;
4768 else if (unformat (i, "queue %d", &queue))
4769 queue_set = 1;
4770 else
4771 break;
4772 }
4773
4774 if (sw_if_index_set == 0)
4775 {
4776 errmsg ("missing interface name or sw_if_index\n");
4777 return -99;
4778 }
4779
4780 if (entry_set == 0)
4781 {
4782 errmsg ("missing entry \n");
4783 return -99;
4784 }
4785
4786 if (tc_set == 0)
4787 {
4788 errmsg ("missing traffic class \n");
4789 return -99;
4790 }
4791
4792 if (queue_set == 0)
4793 {
4794 errmsg ("missing queue \n");
4795 return -99;
4796 }
4797
4798 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4799
4800 mp->sw_if_index = ntohl (sw_if_index);
4801 mp->entry = ntohl (entry);
4802 mp->tc = ntohl (tc);
4803 mp->queue = ntohl (queue);
4804
4805 S;
4806 W;
4807 /* NOTREACHED */
4808 return 0;
4809}
4810
4811static int
Dave Barach72d72232016-08-04 10:15:08 -04004812api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004813{
Dave Barach72d72232016-08-04 10:15:08 -04004814 unformat_input_t *i = vam->input;
4815 vl_api_sw_interface_add_del_address_t *mp;
4816 f64 timeout;
4817 u32 sw_if_index;
4818 u8 sw_if_index_set = 0;
4819 u8 is_add = 1, del_all = 0;
4820 u32 address_length = 0;
4821 u8 v4_address_set = 0;
4822 u8 v6_address_set = 0;
4823 ip4_address_t v4address;
4824 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004825
Dave Barach72d72232016-08-04 10:15:08 -04004826 /* Parse args required to build the message */
4827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4828 {
4829 if (unformat (i, "del-all"))
4830 del_all = 1;
4831 else if (unformat (i, "del"))
4832 is_add = 0;
4833 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4834 sw_if_index_set = 1;
4835 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4836 sw_if_index_set = 1;
4837 else if (unformat (i, "%U/%d",
4838 unformat_ip4_address, &v4address, &address_length))
4839 v4_address_set = 1;
4840 else if (unformat (i, "%U/%d",
4841 unformat_ip6_address, &v6address, &address_length))
4842 v6_address_set = 1;
4843 else
4844 break;
4845 }
4846
4847 if (sw_if_index_set == 0)
4848 {
4849 errmsg ("missing interface name or sw_if_index\n");
4850 return -99;
4851 }
4852 if (v4_address_set && v6_address_set)
4853 {
4854 errmsg ("both v4 and v6 addresses set\n");
4855 return -99;
4856 }
4857 if (!v4_address_set && !v6_address_set && !del_all)
4858 {
4859 errmsg ("no addresses set\n");
4860 return -99;
4861 }
4862
4863 /* Construct the API message */
4864 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4865
4866 mp->sw_if_index = ntohl (sw_if_index);
4867 mp->is_add = is_add;
4868 mp->del_all = del_all;
4869 if (v6_address_set)
4870 {
4871 mp->is_ipv6 = 1;
4872 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4873 }
4874 else
4875 {
4876 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4877 }
4878 mp->address_length = address_length;
4879
4880 /* send it... */
4881 S;
4882
4883 /* Wait for a reply, return good/bad news */
4884 W;
4885}
4886
4887static int
John Lo06b14b92016-10-24 20:20:11 -04004888api_sw_interface_set_mpls_enable (vat_main_t * vam)
4889{
4890 unformat_input_t *i = vam->input;
4891 vl_api_sw_interface_set_mpls_enable_t *mp;
4892 f64 timeout;
4893 u32 sw_if_index;
4894 u8 sw_if_index_set = 0;
4895 u8 enable = 1;
4896
4897 /* Parse args required to build the message */
4898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4899 {
4900 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4901 sw_if_index_set = 1;
4902 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4903 sw_if_index_set = 1;
4904 else if (unformat (i, "disable"))
4905 enable = 0;
4906 else if (unformat (i, "dis"))
4907 enable = 0;
4908 else
4909 break;
4910 }
4911
4912 if (sw_if_index_set == 0)
4913 {
4914 errmsg ("missing interface name or sw_if_index\n");
4915 return -99;
4916 }
4917
4918 /* Construct the API message */
4919 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
4920
4921 mp->sw_if_index = ntohl (sw_if_index);
4922 mp->enable = enable;
4923
4924 /* send it... */
4925 S;
4926
4927 /* Wait for a reply... */
4928 W;
4929}
4930
4931static int
Dave Barach72d72232016-08-04 10:15:08 -04004932api_sw_interface_set_table (vat_main_t * vam)
4933{
4934 unformat_input_t *i = vam->input;
4935 vl_api_sw_interface_set_table_t *mp;
4936 f64 timeout;
4937 u32 sw_if_index, vrf_id = 0;
4938 u8 sw_if_index_set = 0;
4939 u8 is_ipv6 = 0;
4940
4941 /* Parse args required to build the message */
4942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4943 {
4944 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4945 sw_if_index_set = 1;
4946 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4947 sw_if_index_set = 1;
4948 else if (unformat (i, "vrf %d", &vrf_id))
4949 ;
4950 else if (unformat (i, "ipv6"))
4951 is_ipv6 = 1;
4952 else
4953 break;
4954 }
4955
4956 if (sw_if_index_set == 0)
4957 {
4958 errmsg ("missing interface name or sw_if_index\n");
4959 return -99;
4960 }
4961
4962 /* Construct the API message */
4963 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4964
4965 mp->sw_if_index = ntohl (sw_if_index);
4966 mp->is_ipv6 = is_ipv6;
4967 mp->vrf_id = ntohl (vrf_id);
4968
4969 /* send it... */
4970 S;
4971
4972 /* Wait for a reply... */
4973 W;
4974}
4975
4976static int
4977api_sw_interface_set_vpath (vat_main_t * vam)
4978{
4979 unformat_input_t *i = vam->input;
4980 vl_api_sw_interface_set_vpath_t *mp;
4981 f64 timeout;
4982 u32 sw_if_index = 0;
4983 u8 sw_if_index_set = 0;
4984 u8 is_enable = 0;
4985
4986 /* Parse args required to build the message */
4987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4988 {
4989 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4990 sw_if_index_set = 1;
4991 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4992 sw_if_index_set = 1;
4993 else if (unformat (i, "enable"))
4994 is_enable = 1;
4995 else if (unformat (i, "disable"))
4996 is_enable = 0;
4997 else
4998 break;
4999 }
5000
5001 if (sw_if_index_set == 0)
5002 {
5003 errmsg ("missing interface name or sw_if_index\n");
5004 return -99;
5005 }
5006
5007 /* Construct the API message */
5008 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5009
5010 mp->sw_if_index = ntohl (sw_if_index);
5011 mp->enable = is_enable;
5012
5013 /* send it... */
5014 S;
5015
5016 /* Wait for a reply... */
5017 W;
5018}
5019
5020static int
5021api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5022{
5023 unformat_input_t *i = vam->input;
5024 vl_api_sw_interface_set_l2_xconnect_t *mp;
5025 f64 timeout;
5026 u32 rx_sw_if_index;
5027 u8 rx_sw_if_index_set = 0;
5028 u32 tx_sw_if_index;
5029 u8 tx_sw_if_index_set = 0;
5030 u8 enable = 1;
5031
5032 /* Parse args required to build the message */
5033 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5034 {
5035 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5036 rx_sw_if_index_set = 1;
5037 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5038 tx_sw_if_index_set = 1;
5039 else if (unformat (i, "rx"))
5040 {
5041 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5042 {
5043 if (unformat (i, "%U", unformat_sw_if_index, vam,
5044 &rx_sw_if_index))
5045 rx_sw_if_index_set = 1;
5046 }
5047 else
Dave Barach41da02d2016-07-11 16:48:42 -07005048 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005049 }
Dave Barach72d72232016-08-04 10:15:08 -04005050 else if (unformat (i, "tx"))
5051 {
5052 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5053 {
5054 if (unformat (i, "%U", unformat_sw_if_index, vam,
5055 &tx_sw_if_index))
5056 tx_sw_if_index_set = 1;
5057 }
5058 else
5059 break;
5060 }
5061 else if (unformat (i, "enable"))
5062 enable = 1;
5063 else if (unformat (i, "disable"))
5064 enable = 0;
5065 else
5066 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005067 }
5068
Dave Barach72d72232016-08-04 10:15:08 -04005069 if (rx_sw_if_index_set == 0)
5070 {
5071 errmsg ("missing rx interface name or rx_sw_if_index\n");
5072 return -99;
5073 }
Dave Barach41da02d2016-07-11 16:48:42 -07005074
Dave Barach72d72232016-08-04 10:15:08 -04005075 if (enable && (tx_sw_if_index_set == 0))
5076 {
5077 errmsg ("missing tx interface name or tx_sw_if_index\n");
5078 return -99;
5079 }
Dave Barach41da02d2016-07-11 16:48:42 -07005080
Dave Barach72d72232016-08-04 10:15:08 -04005081 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005082
Dave Barach72d72232016-08-04 10:15:08 -04005083 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5084 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5085 mp->enable = enable;
5086
5087 S;
5088 W;
5089 /* NOTREACHED */
5090 return 0;
5091}
5092
5093static int
5094api_sw_interface_set_l2_bridge (vat_main_t * vam)
5095{
5096 unformat_input_t *i = vam->input;
5097 vl_api_sw_interface_set_l2_bridge_t *mp;
5098 f64 timeout;
5099 u32 rx_sw_if_index;
5100 u8 rx_sw_if_index_set = 0;
5101 u32 bd_id;
5102 u8 bd_id_set = 0;
5103 u8 bvi = 0;
5104 u32 shg = 0;
5105 u8 enable = 1;
5106
5107 /* Parse args required to build the message */
5108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5109 {
5110 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5111 rx_sw_if_index_set = 1;
5112 else if (unformat (i, "bd_id %d", &bd_id))
5113 bd_id_set = 1;
5114 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5115 rx_sw_if_index_set = 1;
5116 else if (unformat (i, "shg %d", &shg))
5117 ;
5118 else if (unformat (i, "bvi"))
5119 bvi = 1;
5120 else if (unformat (i, "enable"))
5121 enable = 1;
5122 else if (unformat (i, "disable"))
5123 enable = 0;
5124 else
5125 break;
5126 }
5127
5128 if (rx_sw_if_index_set == 0)
5129 {
5130 errmsg ("missing rx interface name or sw_if_index\n");
5131 return -99;
5132 }
5133
5134 if (enable && (bd_id_set == 0))
5135 {
5136 errmsg ("missing bridge domain\n");
5137 return -99;
5138 }
5139
5140 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5141
5142 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5143 mp->bd_id = ntohl (bd_id);
5144 mp->shg = (u8) shg;
5145 mp->bvi = bvi;
5146 mp->enable = enable;
5147
5148 S;
5149 W;
5150 /* NOTREACHED */
5151 return 0;
5152}
5153
5154static int
5155api_bridge_domain_dump (vat_main_t * vam)
5156{
5157 unformat_input_t *i = vam->input;
5158 vl_api_bridge_domain_dump_t *mp;
5159 f64 timeout;
5160 u32 bd_id = ~0;
5161
5162 /* Parse args required to build the message */
5163 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5164 {
5165 if (unformat (i, "bd_id %d", &bd_id))
5166 ;
5167 else
5168 break;
5169 }
5170
5171 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5172 mp->bd_id = ntohl (bd_id);
5173 S;
5174
5175 /* Use a control ping for synchronization */
5176 {
5177 vl_api_control_ping_t *mp;
5178 M (CONTROL_PING, control_ping);
5179 S;
5180 }
5181
5182 W;
5183 /* NOTREACHED */
5184 return 0;
5185}
5186
5187static int
5188api_bridge_domain_add_del (vat_main_t * vam)
5189{
5190 unformat_input_t *i = vam->input;
5191 vl_api_bridge_domain_add_del_t *mp;
5192 f64 timeout;
5193 u32 bd_id = ~0;
5194 u8 is_add = 1;
5195 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5196
5197 /* Parse args required to build the message */
5198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5199 {
5200 if (unformat (i, "bd_id %d", &bd_id))
5201 ;
5202 else if (unformat (i, "flood %d", &flood))
5203 ;
5204 else if (unformat (i, "uu-flood %d", &uu_flood))
5205 ;
5206 else if (unformat (i, "forward %d", &forward))
5207 ;
5208 else if (unformat (i, "learn %d", &learn))
5209 ;
5210 else if (unformat (i, "arp-term %d", &arp_term))
5211 ;
5212 else if (unformat (i, "del"))
5213 {
5214 is_add = 0;
5215 flood = uu_flood = forward = learn = 0;
5216 }
5217 else
5218 break;
5219 }
5220
5221 if (bd_id == ~0)
5222 {
5223 errmsg ("missing bridge domain\n");
5224 return -99;
5225 }
5226
5227 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5228
5229 mp->bd_id = ntohl (bd_id);
5230 mp->flood = flood;
5231 mp->uu_flood = uu_flood;
5232 mp->forward = forward;
5233 mp->learn = learn;
5234 mp->arp_term = arp_term;
5235 mp->is_add = is_add;
5236
5237 S;
5238 W;
5239 /* NOTREACHED */
5240 return 0;
5241}
5242
5243static int
5244api_l2fib_add_del (vat_main_t * vam)
5245{
5246 unformat_input_t *i = vam->input;
5247 vl_api_l2fib_add_del_t *mp;
5248 f64 timeout;
5249 u64 mac = 0;
5250 u8 mac_set = 0;
5251 u32 bd_id;
5252 u8 bd_id_set = 0;
5253 u32 sw_if_index;
5254 u8 sw_if_index_set = 0;
5255 u8 is_add = 1;
5256 u8 static_mac = 0;
5257 u8 filter_mac = 0;
5258 u8 bvi_mac = 0;
5259 int count = 1;
5260 f64 before = 0;
5261 int j;
5262
5263 /* Parse args required to build the message */
5264 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5265 {
5266 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5267 mac_set = 1;
5268 else if (unformat (i, "bd_id %d", &bd_id))
5269 bd_id_set = 1;
5270 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5271 sw_if_index_set = 1;
5272 else if (unformat (i, "sw_if"))
5273 {
5274 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5275 {
5276 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5277 sw_if_index_set = 1;
5278 }
5279 else
5280 break;
5281 }
5282 else if (unformat (i, "static"))
5283 static_mac = 1;
5284 else if (unformat (i, "filter"))
5285 {
5286 filter_mac = 1;
5287 static_mac = 1;
5288 }
5289 else if (unformat (i, "bvi"))
5290 {
5291 bvi_mac = 1;
5292 static_mac = 1;
5293 }
5294 else if (unformat (i, "del"))
5295 is_add = 0;
5296 else if (unformat (i, "count %d", &count))
5297 ;
5298 else
5299 break;
5300 }
5301
5302 if (mac_set == 0)
5303 {
5304 errmsg ("missing mac address\n");
5305 return -99;
5306 }
5307
5308 if (bd_id_set == 0)
5309 {
5310 errmsg ("missing bridge domain\n");
5311 return -99;
5312 }
5313
5314 if (is_add && (sw_if_index_set == 0))
5315 {
5316 errmsg ("missing interface name or sw_if_index\n");
5317 return -99;
5318 }
5319
5320 if (count > 1)
5321 {
5322 /* Turn on async mode */
5323 vam->async_mode = 1;
5324 vam->async_errors = 0;
5325 before = vat_time_now (vam);
5326 }
5327
5328 for (j = 0; j < count; j++)
5329 {
5330 M (L2FIB_ADD_DEL, l2fib_add_del);
5331
5332 mp->mac = mac;
5333 mp->bd_id = ntohl (bd_id);
5334 mp->is_add = is_add;
5335
5336 if (is_add)
5337 {
5338 mp->sw_if_index = ntohl (sw_if_index);
5339 mp->static_mac = static_mac;
5340 mp->filter_mac = filter_mac;
5341 mp->bvi_mac = bvi_mac;
5342 }
5343 increment_mac_address (&mac);
5344 /* send it... */
5345 S;
5346 }
5347
5348 if (count > 1)
5349 {
5350 vl_api_control_ping_t *mp;
5351 f64 after;
5352
5353 /* Shut off async mode */
5354 vam->async_mode = 0;
5355
5356 M (CONTROL_PING, control_ping);
5357 S;
5358
5359 timeout = vat_time_now (vam) + 1.0;
5360 while (vat_time_now (vam) < timeout)
5361 if (vam->result_ready == 1)
5362 goto out;
5363 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005364
5365 out:
Dave Barach72d72232016-08-04 10:15:08 -04005366 if (vam->retval == -99)
5367 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005368
Dave Barach72d72232016-08-04 10:15:08 -04005369 if (vam->async_errors > 0)
5370 {
5371 errmsg ("%d asynchronous errors\n", vam->async_errors);
5372 vam->retval = -98;
5373 }
5374 vam->async_errors = 0;
5375 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005376
Dave Barach72d72232016-08-04 10:15:08 -04005377 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5378 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005379 }
Dave Barach72d72232016-08-04 10:15:08 -04005380 else
5381 {
5382 /* Wait for a reply... */
5383 W;
5384 }
5385 /* Return the good/bad news */
5386 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005387}
5388
Dave Barach72d72232016-08-04 10:15:08 -04005389static int
5390api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005391{
Dave Barach72d72232016-08-04 10:15:08 -04005392 unformat_input_t *i = vam->input;
5393 vl_api_l2_flags_t *mp;
5394 f64 timeout;
5395 u32 sw_if_index;
5396 u32 feature_bitmap = 0;
5397 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005398
Dave Barach72d72232016-08-04 10:15:08 -04005399 /* Parse args required to build the message */
5400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5401 {
5402 if (unformat (i, "sw_if_index %d", &sw_if_index))
5403 sw_if_index_set = 1;
5404 else if (unformat (i, "sw_if"))
5405 {
5406 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5407 {
5408 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5409 sw_if_index_set = 1;
5410 }
5411 else
5412 break;
5413 }
5414 else if (unformat (i, "learn"))
5415 feature_bitmap |= L2INPUT_FEAT_LEARN;
5416 else if (unformat (i, "forward"))
5417 feature_bitmap |= L2INPUT_FEAT_FWD;
5418 else if (unformat (i, "flood"))
5419 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5420 else if (unformat (i, "uu-flood"))
5421 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5422 else
5423 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005424 }
5425
Dave Barach72d72232016-08-04 10:15:08 -04005426 if (sw_if_index_set == 0)
5427 {
5428 errmsg ("missing interface name or sw_if_index\n");
5429 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005430 }
5431
Dave Barach72d72232016-08-04 10:15:08 -04005432 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005433
Dave Barach72d72232016-08-04 10:15:08 -04005434 mp->sw_if_index = ntohl (sw_if_index);
5435 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005436
Dave Barach72d72232016-08-04 10:15:08 -04005437 S;
5438 W;
5439 /* NOTREACHED */
5440 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005441}
5442
Dave Barach72d72232016-08-04 10:15:08 -04005443static int
5444api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005445{
Dave Barach72d72232016-08-04 10:15:08 -04005446 unformat_input_t *i = vam->input;
5447 vl_api_bridge_flags_t *mp;
5448 f64 timeout;
5449 u32 bd_id;
5450 u8 bd_id_set = 0;
5451 u8 is_set = 1;
5452 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005453
Dave Barach72d72232016-08-04 10:15:08 -04005454 /* Parse args required to build the message */
5455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5456 {
5457 if (unformat (i, "bd_id %d", &bd_id))
5458 bd_id_set = 1;
5459 else if (unformat (i, "learn"))
5460 flags |= L2_LEARN;
5461 else if (unformat (i, "forward"))
5462 flags |= L2_FWD;
5463 else if (unformat (i, "flood"))
5464 flags |= L2_FLOOD;
5465 else if (unformat (i, "uu-flood"))
5466 flags |= L2_UU_FLOOD;
5467 else if (unformat (i, "arp-term"))
5468 flags |= L2_ARP_TERM;
5469 else if (unformat (i, "off"))
5470 is_set = 0;
5471 else if (unformat (i, "disable"))
5472 is_set = 0;
5473 else
5474 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005475 }
5476
Dave Barach72d72232016-08-04 10:15:08 -04005477 if (bd_id_set == 0)
5478 {
5479 errmsg ("missing bridge domain\n");
5480 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005481 }
5482
Dave Barach72d72232016-08-04 10:15:08 -04005483 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005484
Dave Barach72d72232016-08-04 10:15:08 -04005485 mp->bd_id = ntohl (bd_id);
5486 mp->feature_bitmap = ntohl (flags);
5487 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005488
Dave Barach72d72232016-08-04 10:15:08 -04005489 S;
5490 W;
5491 /* NOTREACHED */
5492 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005493}
5494
Dave Barach72d72232016-08-04 10:15:08 -04005495static int
5496api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005497{
Dave Barach72d72232016-08-04 10:15:08 -04005498 unformat_input_t *i = vam->input;
5499 vl_api_bd_ip_mac_add_del_t *mp;
5500 f64 timeout;
5501 u32 bd_id;
5502 u8 is_ipv6 = 0;
5503 u8 is_add = 1;
5504 u8 bd_id_set = 0;
5505 u8 ip_set = 0;
5506 u8 mac_set = 0;
5507 ip4_address_t v4addr;
5508 ip6_address_t v6addr;
5509 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005510
Ed Warnickecb9cada2015-12-08 15:45:58 -07005511
Dave Barach72d72232016-08-04 10:15:08 -04005512 /* Parse args required to build the message */
5513 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5514 {
5515 if (unformat (i, "bd_id %d", &bd_id))
5516 {
5517 bd_id_set++;
5518 }
5519 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5520 {
5521 ip_set++;
5522 }
5523 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5524 {
5525 ip_set++;
5526 is_ipv6++;
5527 }
5528 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5529 {
5530 mac_set++;
5531 }
5532 else if (unformat (i, "del"))
5533 is_add = 0;
5534 else
5535 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005536 }
5537
Dave Barach72d72232016-08-04 10:15:08 -04005538 if (bd_id_set == 0)
5539 {
5540 errmsg ("missing bridge domain\n");
5541 return -99;
5542 }
5543 else if (ip_set == 0)
5544 {
5545 errmsg ("missing IP address\n");
5546 return -99;
5547 }
5548 else if (mac_set == 0)
5549 {
5550 errmsg ("missing MAC address\n");
5551 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005552 }
5553
Dave Barach72d72232016-08-04 10:15:08 -04005554 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005555
Dave Barach72d72232016-08-04 10:15:08 -04005556 mp->bd_id = ntohl (bd_id);
5557 mp->is_ipv6 = is_ipv6;
5558 mp->is_add = is_add;
5559 if (is_ipv6)
5560 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5561 else
5562 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5563 clib_memcpy (mp->mac_address, macaddr, 6);
5564 S;
5565 W;
5566 /* NOTREACHED */
5567 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005568}
5569
Dave Barach72d72232016-08-04 10:15:08 -04005570static int
5571api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005572{
Dave Barach72d72232016-08-04 10:15:08 -04005573 unformat_input_t *i = vam->input;
5574 vl_api_tap_connect_t *mp;
5575 f64 timeout;
5576 u8 mac_address[6];
5577 u8 random_mac = 1;
5578 u8 name_set = 0;
5579 u8 *tap_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005580
Dave Barach72d72232016-08-04 10:15:08 -04005581 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005582
Dave Barach72d72232016-08-04 10:15:08 -04005583 /* Parse args required to build the message */
5584 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5585 {
5586 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5587 {
5588 random_mac = 0;
5589 }
5590 else if (unformat (i, "random-mac"))
5591 random_mac = 1;
5592 else if (unformat (i, "tapname %s", &tap_name))
5593 name_set = 1;
5594 else
5595 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005596 }
5597
Dave Barach72d72232016-08-04 10:15:08 -04005598 if (name_set == 0)
5599 {
5600 errmsg ("missing tap name\n");
5601 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005602 }
Dave Barach72d72232016-08-04 10:15:08 -04005603 if (vec_len (tap_name) > 63)
5604 {
5605 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005606 }
Dave Barach72d72232016-08-04 10:15:08 -04005607 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005608
Dave Barach72d72232016-08-04 10:15:08 -04005609 /* Construct the API message */
5610 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005611
Dave Barach72d72232016-08-04 10:15:08 -04005612 mp->use_random_mac = random_mac;
5613 clib_memcpy (mp->mac_address, mac_address, 6);
5614 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5615 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005616
Dave Barach72d72232016-08-04 10:15:08 -04005617 /* send it... */
5618 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005619
Dave Barach72d72232016-08-04 10:15:08 -04005620 /* Wait for a reply... */
5621 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005622}
5623
Dave Barach72d72232016-08-04 10:15:08 -04005624static int
5625api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005626{
Dave Barach72d72232016-08-04 10:15:08 -04005627 unformat_input_t *i = vam->input;
5628 vl_api_tap_modify_t *mp;
5629 f64 timeout;
5630 u8 mac_address[6];
5631 u8 random_mac = 1;
5632 u8 name_set = 0;
5633 u8 *tap_name;
5634 u32 sw_if_index = ~0;
5635 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005636
Dave Barach72d72232016-08-04 10:15:08 -04005637 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005638
Dave Barach72d72232016-08-04 10:15:08 -04005639 /* Parse args required to build the message */
5640 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5641 {
5642 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5643 sw_if_index_set = 1;
5644 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5645 sw_if_index_set = 1;
5646 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5647 {
5648 random_mac = 0;
5649 }
5650 else if (unformat (i, "random-mac"))
5651 random_mac = 1;
5652 else if (unformat (i, "tapname %s", &tap_name))
5653 name_set = 1;
5654 else
5655 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005656 }
5657
Dave Barach72d72232016-08-04 10:15:08 -04005658 if (sw_if_index_set == 0)
5659 {
5660 errmsg ("missing vpp interface name");
5661 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005662 }
Dave Barach72d72232016-08-04 10:15:08 -04005663 if (name_set == 0)
5664 {
5665 errmsg ("missing tap name\n");
5666 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005667 }
Dave Barach72d72232016-08-04 10:15:08 -04005668 if (vec_len (tap_name) > 63)
5669 {
5670 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005671 }
Dave Barach72d72232016-08-04 10:15:08 -04005672 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005673
Dave Barach72d72232016-08-04 10:15:08 -04005674 /* Construct the API message */
5675 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005676
Dave Barach72d72232016-08-04 10:15:08 -04005677 mp->use_random_mac = random_mac;
5678 mp->sw_if_index = ntohl (sw_if_index);
5679 clib_memcpy (mp->mac_address, mac_address, 6);
5680 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5681 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005682
Dave Barach72d72232016-08-04 10:15:08 -04005683 /* send it... */
5684 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005685
Dave Barach72d72232016-08-04 10:15:08 -04005686 /* Wait for a reply... */
5687 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005688}
5689
Dave Barach72d72232016-08-04 10:15:08 -04005690static int
5691api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005692{
Dave Barach72d72232016-08-04 10:15:08 -04005693 unformat_input_t *i = vam->input;
5694 vl_api_tap_delete_t *mp;
5695 f64 timeout;
5696 u32 sw_if_index = ~0;
5697 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005698
Dave Barach72d72232016-08-04 10:15:08 -04005699 /* Parse args required to build the message */
5700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5701 {
5702 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5703 sw_if_index_set = 1;
5704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5705 sw_if_index_set = 1;
5706 else
5707 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005708 }
5709
Dave Barach72d72232016-08-04 10:15:08 -04005710 if (sw_if_index_set == 0)
5711 {
5712 errmsg ("missing vpp interface name");
5713 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005714 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005715
Dave Barach72d72232016-08-04 10:15:08 -04005716 /* Construct the API message */
5717 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005718
Dave Barach72d72232016-08-04 10:15:08 -04005719 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005720
Dave Barach72d72232016-08-04 10:15:08 -04005721 /* send it... */
5722 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005723
Dave Barach72d72232016-08-04 10:15:08 -04005724 /* Wait for a reply... */
5725 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005726}
5727
Dave Barach72d72232016-08-04 10:15:08 -04005728static int
5729api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005730{
Dave Barach72d72232016-08-04 10:15:08 -04005731 unformat_input_t *i = vam->input;
5732 vl_api_ip_add_del_route_t *mp;
5733 f64 timeout;
5734 u32 sw_if_index = ~0, vrf_id = 0;
5735 u8 sw_if_index_set = 0;
5736 u8 is_ipv6 = 0;
5737 u8 is_local = 0, is_drop = 0;
Neale Ranns948e00f2016-10-20 13:39:34 +01005738 u8 is_unreach = 0, is_prohibit = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005739 u8 create_vrf_if_needed = 0;
5740 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00005741 u32 next_hop_weight = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005742 u8 not_last = 0;
5743 u8 is_multipath = 0;
5744 u8 address_set = 0;
5745 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005746 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005747 u32 resolve_attempts = 0;
5748 u32 dst_address_length = 0;
5749 u8 next_hop_set = 0;
5750 ip4_address_t v4_dst_address, v4_next_hop_address;
5751 ip6_address_t v6_dst_address, v6_next_hop_address;
5752 int count = 1;
5753 int j;
5754 f64 before = 0;
5755 u32 random_add_del = 0;
5756 u32 *random_vector = 0;
5757 uword *random_hash;
5758 u32 random_seed = 0xdeaddabe;
5759 u32 classify_table_index = ~0;
5760 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01005761 u8 resolve_host = 0, resolve_attached = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005762 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005763
Dave Barach72d72232016-08-04 10:15:08 -04005764 /* Parse args required to build the message */
5765 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5766 {
5767 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5768 sw_if_index_set = 1;
5769 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5770 sw_if_index_set = 1;
5771 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5772 {
5773 address_set = 1;
5774 is_ipv6 = 0;
5775 }
5776 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5777 {
5778 address_set = 1;
5779 is_ipv6 = 1;
5780 }
5781 else if (unformat (i, "/%d", &dst_address_length))
5782 {
5783 address_length_set = 1;
5784 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005785
Dave Barach72d72232016-08-04 10:15:08 -04005786 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5787 &v4_next_hop_address))
5788 {
5789 next_hop_set = 1;
5790 }
5791 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5792 &v6_next_hop_address))
5793 {
5794 next_hop_set = 1;
5795 }
5796 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5797 ;
5798 else if (unformat (i, "weight %d", &next_hop_weight))
5799 ;
5800 else if (unformat (i, "drop"))
5801 {
5802 is_drop = 1;
5803 }
Neale Ranns948e00f2016-10-20 13:39:34 +01005804 else if (unformat (i, "null-send-unreach"))
5805 {
5806 is_unreach = 1;
5807 }
5808 else if (unformat (i, "null-send-prohibit"))
5809 {
5810 is_prohibit = 1;
5811 }
Dave Barach72d72232016-08-04 10:15:08 -04005812 else if (unformat (i, "local"))
5813 {
5814 is_local = 1;
5815 }
5816 else if (unformat (i, "classify %d", &classify_table_index))
5817 {
5818 is_classify = 1;
5819 }
5820 else if (unformat (i, "del"))
5821 is_add = 0;
5822 else if (unformat (i, "add"))
5823 is_add = 1;
5824 else if (unformat (i, "not-last"))
5825 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005826 else if (unformat (i, "resolve-via-host"))
5827 resolve_host = 1;
5828 else if (unformat (i, "resolve-via-attached"))
5829 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005830 else if (unformat (i, "multipath"))
5831 is_multipath = 1;
5832 else if (unformat (i, "vrf %d", &vrf_id))
5833 ;
5834 else if (unformat (i, "create-vrf"))
5835 create_vrf_if_needed = 1;
5836 else if (unformat (i, "count %d", &count))
5837 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005838 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
5839 ;
5840 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
5841 ;
5842 else if (unformat (i, "out-label %d", &next_hop_out_label))
Dave Barach72d72232016-08-04 10:15:08 -04005843 ;
5844 else if (unformat (i, "random"))
5845 random_add_del = 1;
5846 else if (unformat (i, "seed %d", &random_seed))
5847 ;
5848 else
5849 {
5850 clib_warning ("parse error '%U'", format_unformat_error, i);
5851 return -99;
5852 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005853 }
5854
Dave Barach72d72232016-08-04 10:15:08 -04005855 if (resolve_attempts > 0 && sw_if_index_set == 0)
5856 {
5857 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
5858 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005859 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005860
Neale Ranns948e00f2016-10-20 13:39:34 +01005861 if (!next_hop_set && !is_drop && !is_local &&
5862 !is_classify && !is_unreach && !is_prohibit)
Dave Barach72d72232016-08-04 10:15:08 -04005863 {
Neale Ranns948e00f2016-10-20 13:39:34 +01005864 errmsg
5865 ("next hop / local / drop / unreach / prohibit / classify not set\n");
Dave Barach72d72232016-08-04 10:15:08 -04005866 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005867 }
5868
Dave Barach72d72232016-08-04 10:15:08 -04005869 if (address_set == 0)
5870 {
5871 errmsg ("missing addresses\n");
5872 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005873 }
5874
Dave Barach72d72232016-08-04 10:15:08 -04005875 if (address_length_set == 0)
5876 {
5877 errmsg ("missing address length\n");
5878 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005879 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005880
Dave Barach72d72232016-08-04 10:15:08 -04005881 /* Generate a pile of unique, random routes */
5882 if (random_add_del)
5883 {
5884 u32 this_random_address;
5885 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005886
Dave Barach72d72232016-08-04 10:15:08 -04005887 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5888 for (j = 0; j <= count; j++)
5889 {
5890 do
5891 {
5892 this_random_address = random_u32 (&random_seed);
5893 this_random_address =
5894 clib_host_to_net_u32 (this_random_address);
5895 }
5896 while (hash_get (random_hash, this_random_address));
5897 vec_add1 (random_vector, this_random_address);
5898 hash_set (random_hash, this_random_address, 1);
5899 }
5900 hash_free (random_hash);
5901 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005902 }
5903
Dave Barach72d72232016-08-04 10:15:08 -04005904 if (count > 1)
5905 {
5906 /* Turn on async mode */
5907 vam->async_mode = 1;
5908 vam->async_errors = 0;
5909 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005910 }
5911
Dave Barach72d72232016-08-04 10:15:08 -04005912 for (j = 0; j < count; j++)
5913 {
5914 /* Construct the API message */
5915 M (IP_ADD_DEL_ROUTE, ip_add_del_route);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005916
Dave Barach72d72232016-08-04 10:15:08 -04005917 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07005918 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04005919 if (resolve_attempts > 0)
5920 {
5921 mp->resolve_attempts = ntohl (resolve_attempts);
5922 mp->resolve_if_needed = 1;
5923 }
5924 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005925
Dave Barach72d72232016-08-04 10:15:08 -04005926 mp->is_add = is_add;
5927 mp->is_drop = is_drop;
Neale Ranns948e00f2016-10-20 13:39:34 +01005928 mp->is_unreach = is_unreach;
5929 mp->is_prohibit = is_prohibit;
Dave Barach72d72232016-08-04 10:15:08 -04005930 mp->is_ipv6 = is_ipv6;
5931 mp->is_local = is_local;
5932 mp->is_classify = is_classify;
5933 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005934 mp->is_resolve_host = resolve_host;
5935 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005936 mp->not_last = not_last;
5937 mp->next_hop_weight = next_hop_weight;
5938 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005939 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04005940 mp->classify_table_index = ntohl (classify_table_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07005941 mp->next_hop_out_label = ntohl (next_hop_out_label);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005942
Dave Barach72d72232016-08-04 10:15:08 -04005943 if (is_ipv6)
5944 {
5945 clib_memcpy (mp->dst_address, &v6_dst_address,
5946 sizeof (v6_dst_address));
5947 if (next_hop_set)
5948 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
5949 sizeof (v6_next_hop_address));
5950 increment_v6_address (&v6_dst_address);
5951 }
5952 else
5953 {
5954 clib_memcpy (mp->dst_address, &v4_dst_address,
5955 sizeof (v4_dst_address));
5956 if (next_hop_set)
5957 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
5958 sizeof (v4_next_hop_address));
5959 if (random_add_del)
5960 v4_dst_address.as_u32 = random_vector[j + 1];
5961 else
5962 increment_v4_address (&v4_dst_address);
5963 }
5964 /* send it... */
5965 S;
Dave Barach477570e2016-10-09 17:43:22 -04005966 /* If we receive SIGTERM, stop now... */
5967 if (vam->do_exit)
5968 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005969 }
5970
Dave Barach72d72232016-08-04 10:15:08 -04005971 /* When testing multiple add/del ops, use a control-ping to sync */
5972 if (count > 1)
5973 {
5974 vl_api_control_ping_t *mp;
5975 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005976
Dave Barach72d72232016-08-04 10:15:08 -04005977 /* Shut off async mode */
5978 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005979
Dave Barach72d72232016-08-04 10:15:08 -04005980 M (CONTROL_PING, control_ping);
5981 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005982
Dave Barach72d72232016-08-04 10:15:08 -04005983 timeout = vat_time_now (vam) + 1.0;
5984 while (vat_time_now (vam) < timeout)
5985 if (vam->result_ready == 1)
5986 goto out;
5987 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005988
5989 out:
Dave Barach72d72232016-08-04 10:15:08 -04005990 if (vam->retval == -99)
5991 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005992
Dave Barach72d72232016-08-04 10:15:08 -04005993 if (vam->async_errors > 0)
5994 {
5995 errmsg ("%d asynchronous errors\n", vam->async_errors);
5996 vam->retval = -98;
5997 }
5998 vam->async_errors = 0;
5999 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006000
Dave Barach477570e2016-10-09 17:43:22 -04006001 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6002 if (j > 0)
6003 count = j;
6004
Dave Barach72d72232016-08-04 10:15:08 -04006005 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6006 count, after - before, count / (after - before));
6007 }
6008 else
6009 {
6010 /* Wait for a reply... */
6011 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006012 }
6013
Dave Barach72d72232016-08-04 10:15:08 -04006014 /* Return the good/bad news */
6015 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006016}
6017
Dave Barach72d72232016-08-04 10:15:08 -04006018static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006019api_mpls_route_add_del (vat_main_t * vam)
6020{
6021 unformat_input_t *i = vam->input;
6022 vl_api_mpls_route_add_del_t *mp;
6023 f64 timeout;
6024 u32 sw_if_index = ~0, table_id = 0;
6025 u8 create_table_if_needed = 0;
6026 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006027 u32 next_hop_weight = 1;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006028 u8 is_multipath = 0;
6029 u32 next_hop_table_id = 0;
6030 u8 next_hop_set = 0;
6031 ip4_address_t v4_next_hop_address = {
6032 .as_u32 = 0,
6033 };
6034 ip6_address_t v6_next_hop_address = { {0} };
6035 int count = 1;
6036 int j;
6037 f64 before = 0;
6038 u32 classify_table_index = ~0;
6039 u8 is_classify = 0;
6040 u8 resolve_host = 0, resolve_attached = 0;
6041 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6042 mpls_label_t local_label = MPLS_LABEL_INVALID;
6043 u8 is_eos = 1;
6044 u8 next_hop_proto_is_ip4 = 1;
6045
6046 /* Parse args required to build the message */
6047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6048 {
6049 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6050 ;
6051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6052 ;
6053 else if (unformat (i, "%d", &local_label))
6054 ;
6055 else if (unformat (i, "eos"))
6056 is_eos = 1;
6057 else if (unformat (i, "non-eos"))
6058 is_eos = 0;
6059 else if (unformat (i, "via %U", unformat_ip4_address,
6060 &v4_next_hop_address))
6061 {
6062 next_hop_set = 1;
6063 next_hop_proto_is_ip4 = 1;
6064 }
6065 else if (unformat (i, "via %U", unformat_ip6_address,
6066 &v6_next_hop_address))
6067 {
6068 next_hop_set = 1;
6069 next_hop_proto_is_ip4 = 0;
6070 }
6071 else if (unformat (i, "weight %d", &next_hop_weight))
6072 ;
6073 else if (unformat (i, "create-table"))
6074 create_table_if_needed = 1;
6075 else if (unformat (i, "classify %d", &classify_table_index))
6076 {
6077 is_classify = 1;
6078 }
6079 else if (unformat (i, "del"))
6080 is_add = 0;
6081 else if (unformat (i, "add"))
6082 is_add = 1;
6083 else if (unformat (i, "resolve-via-host"))
6084 resolve_host = 1;
6085 else if (unformat (i, "resolve-via-attached"))
6086 resolve_attached = 1;
6087 else if (unformat (i, "multipath"))
6088 is_multipath = 1;
6089 else if (unformat (i, "count %d", &count))
6090 ;
6091 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6092 {
6093 next_hop_set = 1;
6094 next_hop_proto_is_ip4 = 1;
6095 }
6096 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6097 {
6098 next_hop_set = 1;
6099 next_hop_proto_is_ip4 = 0;
6100 }
6101 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6102 ;
6103 else if (unformat (i, "out-label %d", &next_hop_out_label))
6104 ;
6105 else
6106 {
6107 clib_warning ("parse error '%U'", format_unformat_error, i);
6108 return -99;
6109 }
6110 }
6111
6112 if (!next_hop_set && !is_classify)
6113 {
6114 errmsg ("next hop / classify not set\n");
6115 return -99;
6116 }
6117
6118 if (MPLS_LABEL_INVALID == local_label)
6119 {
6120 errmsg ("missing label\n");
6121 return -99;
6122 }
6123
6124 if (count > 1)
6125 {
6126 /* Turn on async mode */
6127 vam->async_mode = 1;
6128 vam->async_errors = 0;
6129 before = vat_time_now (vam);
6130 }
6131
6132 for (j = 0; j < count; j++)
6133 {
6134 /* Construct the API message */
6135 M (MPLS_ROUTE_ADD_DEL, mpls_route_add_del);
6136
6137 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6138 mp->mr_table_id = ntohl (table_id);
6139 mp->mr_create_table_if_needed = create_table_if_needed;
6140
6141 mp->mr_is_add = is_add;
6142 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6143 mp->mr_is_classify = is_classify;
6144 mp->mr_is_multipath = is_multipath;
6145 mp->mr_is_resolve_host = resolve_host;
6146 mp->mr_is_resolve_attached = resolve_attached;
6147 mp->mr_next_hop_weight = next_hop_weight;
6148 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6149 mp->mr_classify_table_index = ntohl (classify_table_index);
6150 mp->mr_next_hop_out_label = ntohl (next_hop_out_label);
6151 mp->mr_label = ntohl (local_label);
6152 mp->mr_eos = is_eos;
6153
6154 if (next_hop_set)
6155 {
6156 if (next_hop_proto_is_ip4)
6157 {
6158 clib_memcpy (mp->mr_next_hop,
6159 &v4_next_hop_address,
6160 sizeof (v4_next_hop_address));
6161 }
6162 else
6163 {
6164 clib_memcpy (mp->mr_next_hop,
6165 &v6_next_hop_address,
6166 sizeof (v6_next_hop_address));
6167 }
6168 }
6169 local_label++;
6170
6171 /* send it... */
6172 S;
6173 /* If we receive SIGTERM, stop now... */
6174 if (vam->do_exit)
6175 break;
6176 }
6177
6178 /* When testing multiple add/del ops, use a control-ping to sync */
6179 if (count > 1)
6180 {
6181 vl_api_control_ping_t *mp;
6182 f64 after;
6183
6184 /* Shut off async mode */
6185 vam->async_mode = 0;
6186
6187 M (CONTROL_PING, control_ping);
6188 S;
6189
6190 timeout = vat_time_now (vam) + 1.0;
6191 while (vat_time_now (vam) < timeout)
6192 if (vam->result_ready == 1)
6193 goto out;
6194 vam->retval = -99;
6195
6196 out:
6197 if (vam->retval == -99)
6198 errmsg ("timeout\n");
6199
6200 if (vam->async_errors > 0)
6201 {
6202 errmsg ("%d asynchronous errors\n", vam->async_errors);
6203 vam->retval = -98;
6204 }
6205 vam->async_errors = 0;
6206 after = vat_time_now (vam);
6207
6208 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6209 if (j > 0)
6210 count = j;
6211
6212 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6213 count, after - before, count / (after - before));
6214 }
6215 else
6216 {
6217 /* Wait for a reply... */
6218 W;
6219 }
6220
6221 /* Return the good/bad news */
6222 return (vam->retval);
6223}
6224
6225static int
6226api_mpls_ip_bind_unbind (vat_main_t * vam)
6227{
6228 unformat_input_t *i = vam->input;
6229 vl_api_mpls_ip_bind_unbind_t *mp;
6230 f64 timeout;
6231 u32 ip_table_id = 0;
6232 u8 create_table_if_needed = 0;
6233 u8 is_bind = 1;
6234 u8 is_ip4 = 1;
6235 ip4_address_t v4_address;
6236 ip6_address_t v6_address;
6237 u32 address_length;
6238 u8 address_set = 0;
6239 mpls_label_t local_label = MPLS_LABEL_INVALID;
6240
6241 /* Parse args required to build the message */
6242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6243 {
6244 if (unformat (i, "%U/%d", unformat_ip4_address,
6245 &v4_address, &address_length))
6246 {
6247 is_ip4 = 1;
6248 address_set = 1;
6249 }
6250 else if (unformat (i, "%U/%d", unformat_ip6_address,
6251 &v6_address, &address_length))
6252 {
6253 is_ip4 = 0;
6254 address_set = 1;
6255 }
6256 else if (unformat (i, "%d", &local_label))
6257 ;
6258 else if (unformat (i, "create-table"))
6259 create_table_if_needed = 1;
6260 else if (unformat (i, "table-id %d", &ip_table_id))
6261 ;
6262 else if (unformat (i, "unbind"))
6263 is_bind = 0;
6264 else if (unformat (i, "bind"))
6265 is_bind = 1;
6266 else
6267 {
6268 clib_warning ("parse error '%U'", format_unformat_error, i);
6269 return -99;
6270 }
6271 }
6272
6273 if (!address_set)
6274 {
6275 errmsg ("IP addres not set\n");
6276 return -99;
6277 }
6278
6279 if (MPLS_LABEL_INVALID == local_label)
6280 {
6281 errmsg ("missing label\n");
6282 return -99;
6283 }
6284
6285 /* Construct the API message */
6286 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6287
6288 mp->mb_create_table_if_needed = create_table_if_needed;
6289 mp->mb_is_bind = is_bind;
6290 mp->mb_is_ip4 = is_ip4;
6291 mp->mb_ip_table_id = ntohl (ip_table_id);
6292 mp->mb_mpls_table_id = 0;
6293 mp->mb_label = ntohl (local_label);
6294 mp->mb_address_length = address_length;
6295
6296 if (is_ip4)
6297 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6298 else
6299 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6300
6301 /* send it... */
6302 S;
6303
6304 /* Wait for a reply... */
6305 W;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006306}
6307
6308static int
Dave Barach72d72232016-08-04 10:15:08 -04006309api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006310{
Dave Barach72d72232016-08-04 10:15:08 -04006311 unformat_input_t *i = vam->input;
6312 vl_api_proxy_arp_add_del_t *mp;
6313 f64 timeout;
6314 u32 vrf_id = 0;
6315 u8 is_add = 1;
6316 ip4_address_t lo, hi;
6317 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006318
Dave Barach72d72232016-08-04 10:15:08 -04006319 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6320 {
6321 if (unformat (i, "vrf %d", &vrf_id))
6322 ;
6323 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6324 unformat_ip4_address, &hi))
6325 range_set = 1;
6326 else if (unformat (i, "del"))
6327 is_add = 0;
6328 else
6329 {
6330 clib_warning ("parse error '%U'", format_unformat_error, i);
6331 return -99;
6332 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006333 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006334
Dave Barach72d72232016-08-04 10:15:08 -04006335 if (range_set == 0)
6336 {
6337 errmsg ("address range not set\n");
6338 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006339 }
6340
Dave Barach72d72232016-08-04 10:15:08 -04006341 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006342
Dave Barach72d72232016-08-04 10:15:08 -04006343 mp->vrf_id = ntohl (vrf_id);
6344 mp->is_add = is_add;
6345 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6346 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006347
Dave Barach72d72232016-08-04 10:15:08 -04006348 S;
6349 W;
6350 /* NOTREACHED */
6351 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006352}
6353
Dave Barach72d72232016-08-04 10:15:08 -04006354static int
6355api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006356{
Dave Barach72d72232016-08-04 10:15:08 -04006357 unformat_input_t *i = vam->input;
6358 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6359 f64 timeout;
6360 u32 sw_if_index;
6361 u8 enable = 1;
6362 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006363
Dave Barach72d72232016-08-04 10:15:08 -04006364 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6365 {
6366 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6367 sw_if_index_set = 1;
6368 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6369 sw_if_index_set = 1;
6370 else if (unformat (i, "enable"))
6371 enable = 1;
6372 else if (unformat (i, "disable"))
6373 enable = 0;
6374 else
6375 {
6376 clib_warning ("parse error '%U'", format_unformat_error, i);
6377 return -99;
6378 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006379 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006380
Dave Barach72d72232016-08-04 10:15:08 -04006381 if (sw_if_index_set == 0)
6382 {
6383 errmsg ("missing interface name or sw_if_index\n");
6384 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006385 }
6386
Dave Barach72d72232016-08-04 10:15:08 -04006387 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006388
Dave Barach72d72232016-08-04 10:15:08 -04006389 mp->sw_if_index = ntohl (sw_if_index);
6390 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006391
Dave Barach72d72232016-08-04 10:15:08 -04006392 S;
6393 W;
6394 /* NOTREACHED */
6395 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006396}
6397
Dave Barach72d72232016-08-04 10:15:08 -04006398static int
Dave Barach72d72232016-08-04 10:15:08 -04006399api_mpls_add_del_encap (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006400{
Dave Barach72d72232016-08-04 10:15:08 -04006401 unformat_input_t *i = vam->input;
6402 vl_api_mpls_add_del_encap_t *mp;
6403 f64 timeout;
6404 u32 vrf_id = 0;
6405 u32 *labels = 0;
6406 u32 label;
6407 ip4_address_t dst_address;
6408 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006409
Dave Barach72d72232016-08-04 10:15:08 -04006410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6411 {
6412 if (unformat (i, "vrf %d", &vrf_id))
6413 ;
6414 else if (unformat (i, "label %d", &label))
6415 vec_add1 (labels, ntohl (label));
6416 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
6417 ;
6418 else if (unformat (i, "del"))
6419 is_add = 0;
6420 else
6421 {
6422 clib_warning ("parse error '%U'", format_unformat_error, i);
6423 return -99;
6424 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006425 }
6426
Dave Barach72d72232016-08-04 10:15:08 -04006427 if (vec_len (labels) == 0)
6428 {
6429 errmsg ("missing encap label stack\n");
6430 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006431 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006432
Dave Barach72d72232016-08-04 10:15:08 -04006433 M2 (MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
6434 sizeof (u32) * vec_len (labels));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006435
Dave Barach72d72232016-08-04 10:15:08 -04006436 mp->vrf_id = ntohl (vrf_id);
6437 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
6438 mp->is_add = is_add;
6439 mp->nlabels = vec_len (labels);
6440 clib_memcpy (mp->labels, labels, sizeof (u32) * mp->nlabels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006441
Dave Barach72d72232016-08-04 10:15:08 -04006442 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006443
Dave Barach72d72232016-08-04 10:15:08 -04006444 S;
6445 W;
6446 /* NOTREACHED */
6447 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006448}
6449
Dave Barach72d72232016-08-04 10:15:08 -04006450static int
Dave Barach72d72232016-08-04 10:15:08 -04006451api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006452{
Dave Barach72d72232016-08-04 10:15:08 -04006453 unformat_input_t *i = vam->input;
6454 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
6455 f64 timeout;
6456 u32 inner_vrf_id = 0;
6457 ip4_address_t intfc_address;
6458 u8 dst_mac_address[6];
6459 int dst_set = 1;
6460 u32 tmp;
6461 u8 intfc_address_length = 0;
6462 u8 is_add = 1;
6463 u8 l2_only = 0;
6464 u32 tx_sw_if_index;
6465 int tx_sw_if_index_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006466
Dave Barach75665d32016-11-17 11:36:59 -05006467 /* Shut up coverity */
6468 memset (dst_mac_address, 0, sizeof (dst_mac_address));
6469
Dave Barach72d72232016-08-04 10:15:08 -04006470 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6471 {
6472 if (unformat (i, "vrf %d", &inner_vrf_id))
6473 ;
6474 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6475 &intfc_address, &tmp))
6476 intfc_address_length = tmp;
6477 else if (unformat (i, "%U", unformat_sw_if_index, vam, &tx_sw_if_index))
6478 tx_sw_if_index_set = 1;
6479 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6480 tx_sw_if_index_set = 1;
6481 else if (unformat (i, "dst %U", unformat_ethernet_address,
6482 dst_mac_address))
6483 dst_set = 1;
6484 else if (unformat (i, "l2-only"))
6485 l2_only = 1;
6486 else if (unformat (i, "del"))
6487 is_add = 0;
6488 else
6489 {
6490 clib_warning ("parse error '%U'", format_unformat_error, i);
6491 return -99;
6492 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006493 }
6494
Dave Barach72d72232016-08-04 10:15:08 -04006495 if (!dst_set)
6496 {
6497 errmsg ("dst (mac address) not set\n");
6498 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006499 }
Dave Barach72d72232016-08-04 10:15:08 -04006500 if (!tx_sw_if_index_set)
6501 {
6502 errmsg ("tx-intfc not set\n");
6503 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006504 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006505
Dave Barach72d72232016-08-04 10:15:08 -04006506 M (MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006507
Dave Barach72d72232016-08-04 10:15:08 -04006508 mp->vrf_id = ntohl (inner_vrf_id);
6509 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
6510 mp->adj_address_length = intfc_address_length;
6511 clib_memcpy (mp->dst_mac_address, dst_mac_address,
6512 sizeof (dst_mac_address));
6513 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6514 mp->l2_only = l2_only;
6515 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006516
Dave Barach72d72232016-08-04 10:15:08 -04006517 S;
6518 W;
6519 /* NOTREACHED */
6520 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006521}
6522
Dave Barach72d72232016-08-04 10:15:08 -04006523static int
6524api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006525{
Dave Barach72d72232016-08-04 10:15:08 -04006526 unformat_input_t *i = vam->input;
6527 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
6528 f64 timeout;
6529 u32 inner_vrf_id = 0;
6530 u32 outer_vrf_id = 0;
6531 ip4_address_t adj_address;
6532 int adj_address_set = 0;
6533 ip4_address_t next_hop_address;
6534 int next_hop_address_set = 0;
6535 u32 tmp;
6536 u8 adj_address_length = 0;
6537 u8 l2_only = 0;
6538 u8 is_add = 1;
6539 u32 resolve_attempts = 5;
6540 u8 resolve_if_needed = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006541
Dave Barach72d72232016-08-04 10:15:08 -04006542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6543 {
6544 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
6545 ;
6546 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
6547 ;
6548 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
6549 &adj_address, &tmp))
6550 {
6551 adj_address_length = tmp;
6552 adj_address_set = 1;
6553 }
6554 else if (unformat (i, "next-hop %U", unformat_ip4_address,
6555 &next_hop_address))
6556 next_hop_address_set = 1;
6557 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6558 ;
6559 else if (unformat (i, "resolve-if-needed %d", &tmp))
6560 resolve_if_needed = tmp;
6561 else if (unformat (i, "l2-only"))
6562 l2_only = 1;
6563 else if (unformat (i, "del"))
6564 is_add = 0;
6565 else
6566 {
6567 clib_warning ("parse error '%U'", format_unformat_error, i);
6568 return -99;
6569 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006570 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006571
Dave Barach72d72232016-08-04 10:15:08 -04006572 if (!adj_address_set)
6573 {
6574 errmsg ("adjacency address/mask not set\n");
6575 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006576 }
Dave Barach72d72232016-08-04 10:15:08 -04006577 if (!next_hop_address_set)
6578 {
6579 errmsg ("ip4 next hop address (in outer fib) not set\n");
6580 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006581 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006582
Dave Barach72d72232016-08-04 10:15:08 -04006583 M (MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006584
Dave Barach72d72232016-08-04 10:15:08 -04006585 mp->inner_vrf_id = ntohl (inner_vrf_id);
6586 mp->outer_vrf_id = ntohl (outer_vrf_id);
6587 mp->resolve_attempts = ntohl (resolve_attempts);
6588 mp->resolve_if_needed = resolve_if_needed;
6589 mp->is_add = is_add;
6590 mp->l2_only = l2_only;
6591 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
6592 mp->adj_address_length = adj_address_length;
6593 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
6594 sizeof (next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006595
Dave Barach72d72232016-08-04 10:15:08 -04006596 S;
6597 W;
6598 /* NOTREACHED */
6599 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006600}
6601
Dave Barach72d72232016-08-04 10:15:08 -04006602static int
6603api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006604{
Dave Barach72d72232016-08-04 10:15:08 -04006605 unformat_input_t *i = vam->input;
6606 vl_api_sw_interface_set_unnumbered_t *mp;
6607 f64 timeout;
6608 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006609 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006610 u8 is_add = 1;
6611 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006612
Dave Barach72d72232016-08-04 10:15:08 -04006613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6614 {
6615 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6616 sw_if_index_set = 1;
6617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6618 sw_if_index_set = 1;
6619 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6620 ;
6621 else if (unformat (i, "del"))
6622 is_add = 0;
6623 else
6624 {
6625 clib_warning ("parse error '%U'", format_unformat_error, i);
6626 return -99;
6627 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006628 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006629
Dave Barach72d72232016-08-04 10:15:08 -04006630 if (sw_if_index_set == 0)
6631 {
6632 errmsg ("missing interface name or sw_if_index\n");
6633 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006634 }
6635
Dave Barach72d72232016-08-04 10:15:08 -04006636 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006637
Dave Barach72d72232016-08-04 10:15:08 -04006638 mp->sw_if_index = ntohl (sw_if_index);
6639 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6640 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006641
Dave Barach72d72232016-08-04 10:15:08 -04006642 S;
6643 W;
6644 /* NOTREACHED */
6645 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006646}
6647
Dave Barach72d72232016-08-04 10:15:08 -04006648static int
6649api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006650{
Dave Barach72d72232016-08-04 10:15:08 -04006651 unformat_input_t *i = vam->input;
6652 vl_api_ip_neighbor_add_del_t *mp;
6653 f64 timeout;
6654 u32 sw_if_index;
6655 u8 sw_if_index_set = 0;
6656 u32 vrf_id = 0;
6657 u8 is_add = 1;
6658 u8 is_static = 0;
6659 u8 mac_address[6];
6660 u8 mac_set = 0;
6661 u8 v4_address_set = 0;
6662 u8 v6_address_set = 0;
6663 ip4_address_t v4address;
6664 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006665
Dave Barach72d72232016-08-04 10:15:08 -04006666 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006667
Dave Barach72d72232016-08-04 10:15:08 -04006668 /* Parse args required to build the message */
6669 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6670 {
6671 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6672 {
6673 mac_set = 1;
6674 }
6675 else if (unformat (i, "del"))
6676 is_add = 0;
6677 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6678 sw_if_index_set = 1;
6679 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6680 sw_if_index_set = 1;
6681 else if (unformat (i, "is_static"))
6682 is_static = 1;
6683 else if (unformat (i, "vrf %d", &vrf_id))
6684 ;
6685 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6686 v4_address_set = 1;
6687 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6688 v6_address_set = 1;
6689 else
6690 {
6691 clib_warning ("parse error '%U'", format_unformat_error, i);
6692 return -99;
6693 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006694 }
6695
Dave Barach72d72232016-08-04 10:15:08 -04006696 if (sw_if_index_set == 0)
6697 {
6698 errmsg ("missing interface name or sw_if_index\n");
6699 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006700 }
Dave Barach72d72232016-08-04 10:15:08 -04006701 if (v4_address_set && v6_address_set)
6702 {
6703 errmsg ("both v4 and v6 addresses set\n");
6704 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006705 }
Dave Barach72d72232016-08-04 10:15:08 -04006706 if (!v4_address_set && !v6_address_set)
6707 {
6708 errmsg ("no address set\n");
6709 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006710 }
6711
Dave Barach72d72232016-08-04 10:15:08 -04006712 /* Construct the API message */
6713 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006714
Dave Barach72d72232016-08-04 10:15:08 -04006715 mp->sw_if_index = ntohl (sw_if_index);
6716 mp->is_add = is_add;
6717 mp->vrf_id = ntohl (vrf_id);
6718 mp->is_static = is_static;
6719 if (mac_set)
6720 clib_memcpy (mp->mac_address, mac_address, 6);
6721 if (v6_address_set)
6722 {
6723 mp->is_ipv6 = 1;
6724 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6725 }
6726 else
6727 {
6728 /* mp->is_ipv6 = 0; via memset in M macro above */
6729 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006730 }
6731
Dave Barach72d72232016-08-04 10:15:08 -04006732 /* send it... */
6733 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006734
Dave Barach72d72232016-08-04 10:15:08 -04006735 /* Wait for a reply, return good/bad news */
6736 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006737
Dave Barach72d72232016-08-04 10:15:08 -04006738 /* NOTREACHED */
6739 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006740}
6741
Dave Barach72d72232016-08-04 10:15:08 -04006742static int
6743api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006744{
Dave Barach72d72232016-08-04 10:15:08 -04006745 unformat_input_t *i = vam->input;
6746 vl_api_reset_vrf_t *mp;
6747 f64 timeout;
6748 u32 vrf_id = 0;
6749 u8 is_ipv6 = 0;
6750 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006751
Dave Barach72d72232016-08-04 10:15:08 -04006752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6753 {
6754 if (unformat (i, "vrf %d", &vrf_id))
6755 vrf_id_set = 1;
6756 else if (unformat (i, "ipv6"))
6757 is_ipv6 = 1;
6758 else
6759 {
6760 clib_warning ("parse error '%U'", format_unformat_error, i);
6761 return -99;
6762 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006763 }
6764
Dave Barach72d72232016-08-04 10:15:08 -04006765 if (vrf_id_set == 0)
6766 {
6767 errmsg ("missing vrf id\n");
6768 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006769 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006770
Dave Barach72d72232016-08-04 10:15:08 -04006771 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006772
Dave Barach72d72232016-08-04 10:15:08 -04006773 mp->vrf_id = ntohl (vrf_id);
6774 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006775
Dave Barach72d72232016-08-04 10:15:08 -04006776 S;
6777 W;
6778 /* NOTREACHED */
6779 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006780}
6781
Dave Barach72d72232016-08-04 10:15:08 -04006782static int
6783api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006784{
Dave Barach72d72232016-08-04 10:15:08 -04006785 unformat_input_t *i = vam->input;
6786 vl_api_create_vlan_subif_t *mp;
6787 f64 timeout;
6788 u32 sw_if_index;
6789 u8 sw_if_index_set = 0;
6790 u32 vlan_id;
6791 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006792
Dave Barach72d72232016-08-04 10:15:08 -04006793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6794 {
6795 if (unformat (i, "sw_if_index %d", &sw_if_index))
6796 sw_if_index_set = 1;
6797 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6798 sw_if_index_set = 1;
6799 else if (unformat (i, "vlan %d", &vlan_id))
6800 vlan_id_set = 1;
6801 else
6802 {
6803 clib_warning ("parse error '%U'", format_unformat_error, i);
6804 return -99;
6805 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006806 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006807
Dave Barach72d72232016-08-04 10:15:08 -04006808 if (sw_if_index_set == 0)
6809 {
6810 errmsg ("missing interface name or sw_if_index\n");
6811 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006812 }
6813
Dave Barach72d72232016-08-04 10:15:08 -04006814 if (vlan_id_set == 0)
6815 {
6816 errmsg ("missing vlan_id\n");
6817 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006818 }
Dave Barach72d72232016-08-04 10:15:08 -04006819 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006820
Dave Barach72d72232016-08-04 10:15:08 -04006821 mp->sw_if_index = ntohl (sw_if_index);
6822 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006823
Dave Barach72d72232016-08-04 10:15:08 -04006824 S;
6825 W;
6826 /* NOTREACHED */
6827 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006828}
6829
6830#define foreach_create_subif_bit \
6831_(no_tags) \
6832_(one_tag) \
6833_(two_tags) \
6834_(dot1ad) \
6835_(exact_match) \
6836_(default_sub) \
6837_(outer_vlan_id_any) \
6838_(inner_vlan_id_any)
6839
Dave Barach72d72232016-08-04 10:15:08 -04006840static int
6841api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006842{
Dave Barach72d72232016-08-04 10:15:08 -04006843 unformat_input_t *i = vam->input;
6844 vl_api_create_subif_t *mp;
6845 f64 timeout;
6846 u32 sw_if_index;
6847 u8 sw_if_index_set = 0;
6848 u32 sub_id;
6849 u8 sub_id_set = 0;
6850 u32 no_tags = 0;
6851 u32 one_tag = 0;
6852 u32 two_tags = 0;
6853 u32 dot1ad = 0;
6854 u32 exact_match = 0;
6855 u32 default_sub = 0;
6856 u32 outer_vlan_id_any = 0;
6857 u32 inner_vlan_id_any = 0;
6858 u32 tmp;
6859 u16 outer_vlan_id = 0;
6860 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006861
Dave Barach72d72232016-08-04 10:15:08 -04006862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6863 {
6864 if (unformat (i, "sw_if_index %d", &sw_if_index))
6865 sw_if_index_set = 1;
6866 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6867 sw_if_index_set = 1;
6868 else if (unformat (i, "sub_id %d", &sub_id))
6869 sub_id_set = 1;
6870 else if (unformat (i, "outer_vlan_id %d", &tmp))
6871 outer_vlan_id = tmp;
6872 else if (unformat (i, "inner_vlan_id %d", &tmp))
6873 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006874
6875#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006876 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006877#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006878 else
6879 {
6880 clib_warning ("parse error '%U'", format_unformat_error, i);
6881 return -99;
6882 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006883 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006884
Dave Barach72d72232016-08-04 10:15:08 -04006885 if (sw_if_index_set == 0)
6886 {
6887 errmsg ("missing interface name or sw_if_index\n");
6888 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006889 }
6890
Dave Barach72d72232016-08-04 10:15:08 -04006891 if (sub_id_set == 0)
6892 {
6893 errmsg ("missing sub_id\n");
6894 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006895 }
Dave Barach72d72232016-08-04 10:15:08 -04006896 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006897
Dave Barach72d72232016-08-04 10:15:08 -04006898 mp->sw_if_index = ntohl (sw_if_index);
6899 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006900
Ed Warnickecb9cada2015-12-08 15:45:58 -07006901#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006902 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006903#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006904
Dave Barach72d72232016-08-04 10:15:08 -04006905 mp->outer_vlan_id = ntohs (outer_vlan_id);
6906 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006907
Dave Barach72d72232016-08-04 10:15:08 -04006908 S;
6909 W;
6910 /* NOTREACHED */
6911 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006912}
6913
Dave Barach72d72232016-08-04 10:15:08 -04006914static int
6915api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006916{
Dave Barach72d72232016-08-04 10:15:08 -04006917 unformat_input_t *i = vam->input;
6918 vl_api_oam_add_del_t *mp;
6919 f64 timeout;
6920 u32 vrf_id = 0;
6921 u8 is_add = 1;
6922 ip4_address_t src, dst;
6923 u8 src_set = 0;
6924 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006925
Dave Barach72d72232016-08-04 10:15:08 -04006926 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6927 {
6928 if (unformat (i, "vrf %d", &vrf_id))
6929 ;
6930 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6931 src_set = 1;
6932 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6933 dst_set = 1;
6934 else if (unformat (i, "del"))
6935 is_add = 0;
6936 else
6937 {
6938 clib_warning ("parse error '%U'", format_unformat_error, i);
6939 return -99;
6940 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006941 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006942
Dave Barach72d72232016-08-04 10:15:08 -04006943 if (src_set == 0)
6944 {
6945 errmsg ("missing src addr\n");
6946 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006947 }
6948
Dave Barach72d72232016-08-04 10:15:08 -04006949 if (dst_set == 0)
6950 {
6951 errmsg ("missing dst addr\n");
6952 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006953 }
6954
Dave Barach72d72232016-08-04 10:15:08 -04006955 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006956
Dave Barach72d72232016-08-04 10:15:08 -04006957 mp->vrf_id = ntohl (vrf_id);
6958 mp->is_add = is_add;
6959 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6960 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006961
Dave Barach72d72232016-08-04 10:15:08 -04006962 S;
6963 W;
6964 /* NOTREACHED */
6965 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006966}
6967
Dave Barach72d72232016-08-04 10:15:08 -04006968static int
6969api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006970{
Dave Barach72d72232016-08-04 10:15:08 -04006971 unformat_input_t *i = vam->input;
6972 vl_api_reset_fib_t *mp;
6973 f64 timeout;
6974 u32 vrf_id = 0;
6975 u8 is_ipv6 = 0;
6976 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006977
Dave Barach72d72232016-08-04 10:15:08 -04006978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6979 {
6980 if (unformat (i, "vrf %d", &vrf_id))
6981 vrf_id_set = 1;
6982 else if (unformat (i, "ipv6"))
6983 is_ipv6 = 1;
6984 else
6985 {
6986 clib_warning ("parse error '%U'", format_unformat_error, i);
6987 return -99;
6988 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006989 }
6990
Dave Barach72d72232016-08-04 10:15:08 -04006991 if (vrf_id_set == 0)
6992 {
6993 errmsg ("missing vrf id\n");
6994 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006995 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006996
Dave Barach72d72232016-08-04 10:15:08 -04006997 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006998
Dave Barach72d72232016-08-04 10:15:08 -04006999 mp->vrf_id = ntohl (vrf_id);
7000 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007001
Dave Barach72d72232016-08-04 10:15:08 -04007002 S;
7003 W;
7004 /* NOTREACHED */
7005 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007006}
7007
Dave Barach72d72232016-08-04 10:15:08 -04007008static int
7009api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007010{
Dave Barach72d72232016-08-04 10:15:08 -04007011 unformat_input_t *i = vam->input;
7012 vl_api_dhcp_proxy_config_t *mp;
7013 f64 timeout;
7014 u32 vrf_id = 0;
7015 u8 is_add = 1;
7016 u8 insert_cid = 1;
7017 u8 v4_address_set = 0;
7018 u8 v6_address_set = 0;
7019 ip4_address_t v4address;
7020 ip6_address_t v6address;
7021 u8 v4_src_address_set = 0;
7022 u8 v6_src_address_set = 0;
7023 ip4_address_t v4srcaddress;
7024 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007025
Dave Barach72d72232016-08-04 10:15:08 -04007026 /* Parse args required to build the message */
7027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7028 {
7029 if (unformat (i, "del"))
7030 is_add = 0;
7031 else if (unformat (i, "vrf %d", &vrf_id))
7032 ;
7033 else if (unformat (i, "insert-cid %d", &insert_cid))
7034 ;
7035 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7036 v4_address_set = 1;
7037 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7038 v6_address_set = 1;
7039 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7040 v4_src_address_set = 1;
7041 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7042 v6_src_address_set = 1;
7043 else
7044 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007045 }
7046
Dave Barach72d72232016-08-04 10:15:08 -04007047 if (v4_address_set && v6_address_set)
7048 {
7049 errmsg ("both v4 and v6 server addresses set\n");
7050 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007051 }
Dave Barach72d72232016-08-04 10:15:08 -04007052 if (!v4_address_set && !v6_address_set)
7053 {
7054 errmsg ("no server addresses set\n");
7055 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007056 }
7057
Dave Barach72d72232016-08-04 10:15:08 -04007058 if (v4_src_address_set && v6_src_address_set)
7059 {
7060 errmsg ("both v4 and v6 src addresses set\n");
7061 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007062 }
Dave Barach72d72232016-08-04 10:15:08 -04007063 if (!v4_src_address_set && !v6_src_address_set)
7064 {
7065 errmsg ("no src addresses set\n");
7066 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007067 }
7068
Dave Barach72d72232016-08-04 10:15:08 -04007069 if (!(v4_src_address_set && v4_address_set) &&
7070 !(v6_src_address_set && v6_address_set))
7071 {
7072 errmsg ("no matching server and src addresses set\n");
7073 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007074 }
7075
Dave Barach72d72232016-08-04 10:15:08 -04007076 /* Construct the API message */
7077 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007078
Dave Barach72d72232016-08-04 10:15:08 -04007079 mp->insert_circuit_id = insert_cid;
7080 mp->is_add = is_add;
7081 mp->vrf_id = ntohl (vrf_id);
7082 if (v6_address_set)
7083 {
7084 mp->is_ipv6 = 1;
7085 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7086 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7087 }
7088 else
7089 {
7090 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7091 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007092 }
7093
Dave Barach72d72232016-08-04 10:15:08 -04007094 /* send it... */
7095 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007096
Dave Barach72d72232016-08-04 10:15:08 -04007097 /* Wait for a reply, return good/bad news */
7098 W;
7099 /* NOTREACHED */
7100 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007101}
7102
Dave Barach72d72232016-08-04 10:15:08 -04007103static int
7104api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007105{
Dave Barach72d72232016-08-04 10:15:08 -04007106 unformat_input_t *i = vam->input;
7107 vl_api_dhcp_proxy_config_2_t *mp;
7108 f64 timeout;
7109 u32 rx_vrf_id = 0;
7110 u32 server_vrf_id = 0;
7111 u8 is_add = 1;
7112 u8 insert_cid = 1;
7113 u8 v4_address_set = 0;
7114 u8 v6_address_set = 0;
7115 ip4_address_t v4address;
7116 ip6_address_t v6address;
7117 u8 v4_src_address_set = 0;
7118 u8 v6_src_address_set = 0;
7119 ip4_address_t v4srcaddress;
7120 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007121
Dave Barach72d72232016-08-04 10:15:08 -04007122 /* Parse args required to build the message */
7123 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7124 {
7125 if (unformat (i, "del"))
7126 is_add = 0;
7127 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7128 ;
7129 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7130 ;
7131 else if (unformat (i, "insert-cid %d", &insert_cid))
7132 ;
7133 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7134 v4_address_set = 1;
7135 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7136 v6_address_set = 1;
7137 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7138 v4_src_address_set = 1;
7139 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7140 v6_src_address_set = 1;
7141 else
7142 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007143 }
7144
Dave Barach72d72232016-08-04 10:15:08 -04007145 if (v4_address_set && v6_address_set)
7146 {
7147 errmsg ("both v4 and v6 server addresses set\n");
7148 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007149 }
Dave Barach72d72232016-08-04 10:15:08 -04007150 if (!v4_address_set && !v6_address_set)
7151 {
7152 errmsg ("no server addresses set\n");
7153 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007154 }
7155
Dave Barach72d72232016-08-04 10:15:08 -04007156 if (v4_src_address_set && v6_src_address_set)
7157 {
7158 errmsg ("both v4 and v6 src addresses set\n");
7159 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007160 }
Dave Barach72d72232016-08-04 10:15:08 -04007161 if (!v4_src_address_set && !v6_src_address_set)
7162 {
7163 errmsg ("no src addresses set\n");
7164 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007165 }
7166
Dave Barach72d72232016-08-04 10:15:08 -04007167 if (!(v4_src_address_set && v4_address_set) &&
7168 !(v6_src_address_set && v6_address_set))
7169 {
7170 errmsg ("no matching server and src addresses set\n");
7171 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007172 }
7173
Dave Barach72d72232016-08-04 10:15:08 -04007174 /* Construct the API message */
7175 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007176
Dave Barach72d72232016-08-04 10:15:08 -04007177 mp->insert_circuit_id = insert_cid;
7178 mp->is_add = is_add;
7179 mp->rx_vrf_id = ntohl (rx_vrf_id);
7180 mp->server_vrf_id = ntohl (server_vrf_id);
7181 if (v6_address_set)
7182 {
7183 mp->is_ipv6 = 1;
7184 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7185 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7186 }
7187 else
7188 {
7189 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7190 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007191 }
7192
Dave Barach72d72232016-08-04 10:15:08 -04007193 /* send it... */
7194 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007195
Dave Barach72d72232016-08-04 10:15:08 -04007196 /* Wait for a reply, return good/bad news */
7197 W;
7198 /* NOTREACHED */
7199 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007200}
7201
Dave Barach72d72232016-08-04 10:15:08 -04007202static int
7203api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007204{
Dave Barach72d72232016-08-04 10:15:08 -04007205 unformat_input_t *i = vam->input;
7206 vl_api_dhcp_proxy_set_vss_t *mp;
7207 f64 timeout;
7208 u8 is_ipv6 = 0;
7209 u8 is_add = 1;
7210 u32 tbl_id;
7211 u8 tbl_id_set = 0;
7212 u32 oui;
7213 u8 oui_set = 0;
7214 u32 fib_id;
7215 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007216
Dave Barach72d72232016-08-04 10:15:08 -04007217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7218 {
7219 if (unformat (i, "tbl_id %d", &tbl_id))
7220 tbl_id_set = 1;
7221 if (unformat (i, "fib_id %d", &fib_id))
7222 fib_id_set = 1;
7223 if (unformat (i, "oui %d", &oui))
7224 oui_set = 1;
7225 else if (unformat (i, "ipv6"))
7226 is_ipv6 = 1;
7227 else if (unformat (i, "del"))
7228 is_add = 0;
7229 else
7230 {
7231 clib_warning ("parse error '%U'", format_unformat_error, i);
7232 return -99;
7233 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007234 }
7235
Dave Barach72d72232016-08-04 10:15:08 -04007236 if (tbl_id_set == 0)
7237 {
7238 errmsg ("missing tbl id\n");
7239 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007240 }
7241
Dave Barach72d72232016-08-04 10:15:08 -04007242 if (fib_id_set == 0)
7243 {
7244 errmsg ("missing fib id\n");
7245 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007246 }
Dave Barach72d72232016-08-04 10:15:08 -04007247 if (oui_set == 0)
7248 {
7249 errmsg ("missing oui\n");
7250 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007251 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007252
Dave Barach72d72232016-08-04 10:15:08 -04007253 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7254 mp->tbl_id = ntohl (tbl_id);
7255 mp->fib_id = ntohl (fib_id);
7256 mp->oui = ntohl (oui);
7257 mp->is_ipv6 = is_ipv6;
7258 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007259
Dave Barach72d72232016-08-04 10:15:08 -04007260 S;
7261 W;
7262 /* NOTREACHED */
7263 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007264}
7265
Dave Barach72d72232016-08-04 10:15:08 -04007266static int
7267api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007268{
Dave Barach72d72232016-08-04 10:15:08 -04007269 unformat_input_t *i = vam->input;
7270 vl_api_dhcp_client_config_t *mp;
7271 f64 timeout;
7272 u32 sw_if_index;
7273 u8 sw_if_index_set = 0;
7274 u8 is_add = 1;
7275 u8 *hostname = 0;
7276 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007277
Dave Barach72d72232016-08-04 10:15:08 -04007278 /* Parse args required to build the message */
7279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7280 {
7281 if (unformat (i, "del"))
7282 is_add = 0;
7283 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7284 sw_if_index_set = 1;
7285 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7286 sw_if_index_set = 1;
7287 else if (unformat (i, "hostname %s", &hostname))
7288 ;
7289 else if (unformat (i, "disable_event"))
7290 disable_event = 1;
7291 else
7292 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007293 }
7294
Dave Barach72d72232016-08-04 10:15:08 -04007295 if (sw_if_index_set == 0)
7296 {
7297 errmsg ("missing interface name or sw_if_index\n");
7298 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007299 }
7300
Dave Barach72d72232016-08-04 10:15:08 -04007301 if (vec_len (hostname) > 63)
7302 {
7303 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007304 }
Dave Barach72d72232016-08-04 10:15:08 -04007305 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007306
Dave Barach72d72232016-08-04 10:15:08 -04007307 /* Construct the API message */
7308 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007309
Dave Barach72d72232016-08-04 10:15:08 -04007310 mp->sw_if_index = ntohl (sw_if_index);
7311 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7312 vec_free (hostname);
7313 mp->is_add = is_add;
7314 mp->want_dhcp_event = disable_event ? 0 : 1;
7315 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007316
Dave Barach72d72232016-08-04 10:15:08 -04007317 /* send it... */
7318 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007319
Dave Barach72d72232016-08-04 10:15:08 -04007320 /* Wait for a reply, return good/bad news */
7321 W;
7322 /* NOTREACHED */
7323 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007324}
7325
Dave Barach72d72232016-08-04 10:15:08 -04007326static int
7327api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007328{
Dave Barach72d72232016-08-04 10:15:08 -04007329 unformat_input_t *i = vam->input;
7330 vl_api_set_ip_flow_hash_t *mp;
7331 f64 timeout;
7332 u32 vrf_id = 0;
7333 u8 is_ipv6 = 0;
7334 u8 vrf_id_set = 0;
7335 u8 src = 0;
7336 u8 dst = 0;
7337 u8 sport = 0;
7338 u8 dport = 0;
7339 u8 proto = 0;
7340 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007341
Dave Barach72d72232016-08-04 10:15:08 -04007342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7343 {
7344 if (unformat (i, "vrf %d", &vrf_id))
7345 vrf_id_set = 1;
7346 else if (unformat (i, "ipv6"))
7347 is_ipv6 = 1;
7348 else if (unformat (i, "src"))
7349 src = 1;
7350 else if (unformat (i, "dst"))
7351 dst = 1;
7352 else if (unformat (i, "sport"))
7353 sport = 1;
7354 else if (unformat (i, "dport"))
7355 dport = 1;
7356 else if (unformat (i, "proto"))
7357 proto = 1;
7358 else if (unformat (i, "reverse"))
7359 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007360
Dave Barach72d72232016-08-04 10:15:08 -04007361 else
7362 {
7363 clib_warning ("parse error '%U'", format_unformat_error, i);
7364 return -99;
7365 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007366 }
7367
Dave Barach72d72232016-08-04 10:15:08 -04007368 if (vrf_id_set == 0)
7369 {
7370 errmsg ("missing vrf id\n");
7371 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007372 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007373
Dave Barach72d72232016-08-04 10:15:08 -04007374 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7375 mp->src = src;
7376 mp->dst = dst;
7377 mp->sport = sport;
7378 mp->dport = dport;
7379 mp->proto = proto;
7380 mp->reverse = reverse;
7381 mp->vrf_id = ntohl (vrf_id);
7382 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007383
Dave Barach72d72232016-08-04 10:15:08 -04007384 S;
7385 W;
7386 /* NOTREACHED */
7387 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007388}
7389
Dave Barach72d72232016-08-04 10:15:08 -04007390static int
7391api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007392{
Dave Barach72d72232016-08-04 10:15:08 -04007393 unformat_input_t *i = vam->input;
7394 vl_api_sw_interface_ip6_enable_disable_t *mp;
7395 f64 timeout;
7396 u32 sw_if_index;
7397 u8 sw_if_index_set = 0;
7398 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007399
Dave Barach72d72232016-08-04 10:15:08 -04007400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7401 {
7402 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7403 sw_if_index_set = 1;
7404 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7405 sw_if_index_set = 1;
7406 else if (unformat (i, "enable"))
7407 enable = 1;
7408 else if (unformat (i, "disable"))
7409 enable = 0;
7410 else
7411 {
7412 clib_warning ("parse error '%U'", format_unformat_error, i);
7413 return -99;
7414 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007415 }
7416
Dave Barach72d72232016-08-04 10:15:08 -04007417 if (sw_if_index_set == 0)
7418 {
7419 errmsg ("missing interface name or sw_if_index\n");
7420 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007421 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007422
Dave Barach72d72232016-08-04 10:15:08 -04007423 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007424
Dave Barach72d72232016-08-04 10:15:08 -04007425 mp->sw_if_index = ntohl (sw_if_index);
7426 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007427
Dave Barach72d72232016-08-04 10:15:08 -04007428 S;
7429 W;
7430 /* NOTREACHED */
7431 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007432}
7433
Dave Barach72d72232016-08-04 10:15:08 -04007434static int
7435api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007436{
Dave Barach72d72232016-08-04 10:15:08 -04007437 unformat_input_t *i = vam->input;
7438 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7439 f64 timeout;
7440 u32 sw_if_index;
7441 u8 sw_if_index_set = 0;
7442 u32 address_length = 0;
7443 u8 v6_address_set = 0;
7444 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007445
Dave Barach72d72232016-08-04 10:15:08 -04007446 /* Parse args required to build the message */
7447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7448 {
7449 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7450 sw_if_index_set = 1;
7451 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7452 sw_if_index_set = 1;
7453 else if (unformat (i, "%U/%d",
7454 unformat_ip6_address, &v6address, &address_length))
7455 v6_address_set = 1;
7456 else
7457 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007458 }
7459
Dave Barach72d72232016-08-04 10:15:08 -04007460 if (sw_if_index_set == 0)
7461 {
7462 errmsg ("missing interface name or sw_if_index\n");
7463 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007464 }
Dave Barach72d72232016-08-04 10:15:08 -04007465 if (!v6_address_set)
7466 {
7467 errmsg ("no address set\n");
7468 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007469 }
7470
Dave Barach72d72232016-08-04 10:15:08 -04007471 /* Construct the API message */
7472 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7473 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007474
Dave Barach72d72232016-08-04 10:15:08 -04007475 mp->sw_if_index = ntohl (sw_if_index);
7476 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7477 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007478
Dave Barach72d72232016-08-04 10:15:08 -04007479 /* send it... */
7480 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007481
Dave Barach72d72232016-08-04 10:15:08 -04007482 /* Wait for a reply, return good/bad news */
7483 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007484
Dave Barach72d72232016-08-04 10:15:08 -04007485 /* NOTREACHED */
7486 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007487}
7488
7489
Dave Barach72d72232016-08-04 10:15:08 -04007490static int
7491api_sw_interface_ip6nd_ra_prefix (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_ip6nd_ra_prefix_t *mp;
7495 f64 timeout;
7496 u32 sw_if_index;
7497 u8 sw_if_index_set = 0;
7498 u32 address_length = 0;
7499 u8 v6_address_set = 0;
7500 ip6_address_t v6address;
7501 u8 use_default = 0;
7502 u8 no_advertise = 0;
7503 u8 off_link = 0;
7504 u8 no_autoconfig = 0;
7505 u8 no_onlink = 0;
7506 u8 is_no = 0;
7507 u32 val_lifetime = 0;
7508 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007509
Dave Barach72d72232016-08-04 10:15:08 -04007510 /* Parse args required to build the message */
7511 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7512 {
7513 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7514 sw_if_index_set = 1;
7515 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7516 sw_if_index_set = 1;
7517 else if (unformat (i, "%U/%d",
7518 unformat_ip6_address, &v6address, &address_length))
7519 v6_address_set = 1;
7520 else if (unformat (i, "val_life %d", &val_lifetime))
7521 ;
7522 else if (unformat (i, "pref_life %d", &pref_lifetime))
7523 ;
7524 else if (unformat (i, "def"))
7525 use_default = 1;
7526 else if (unformat (i, "noadv"))
7527 no_advertise = 1;
7528 else if (unformat (i, "offl"))
7529 off_link = 1;
7530 else if (unformat (i, "noauto"))
7531 no_autoconfig = 1;
7532 else if (unformat (i, "nolink"))
7533 no_onlink = 1;
7534 else if (unformat (i, "isno"))
7535 is_no = 1;
7536 else
7537 {
7538 clib_warning ("parse error '%U'", format_unformat_error, i);
7539 return -99;
7540 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007541 }
7542
Dave Barach72d72232016-08-04 10:15:08 -04007543 if (sw_if_index_set == 0)
7544 {
7545 errmsg ("missing interface name or sw_if_index\n");
7546 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007547 }
Dave Barach72d72232016-08-04 10:15:08 -04007548 if (!v6_address_set)
7549 {
7550 errmsg ("no address set\n");
7551 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007552 }
7553
Dave Barach72d72232016-08-04 10:15:08 -04007554 /* Construct the API message */
7555 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007556
Dave Barach72d72232016-08-04 10:15:08 -04007557 mp->sw_if_index = ntohl (sw_if_index);
7558 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7559 mp->address_length = address_length;
7560 mp->use_default = use_default;
7561 mp->no_advertise = no_advertise;
7562 mp->off_link = off_link;
7563 mp->no_autoconfig = no_autoconfig;
7564 mp->no_onlink = no_onlink;
7565 mp->is_no = is_no;
7566 mp->val_lifetime = ntohl (val_lifetime);
7567 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007568
Dave Barach72d72232016-08-04 10:15:08 -04007569 /* send it... */
7570 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007571
Dave Barach72d72232016-08-04 10:15:08 -04007572 /* Wait for a reply, return good/bad news */
7573 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007574
Dave Barach72d72232016-08-04 10:15:08 -04007575 /* NOTREACHED */
7576 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007577}
7578
Dave Barach72d72232016-08-04 10:15:08 -04007579static int
7580api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007581{
Dave Barach72d72232016-08-04 10:15:08 -04007582 unformat_input_t *i = vam->input;
7583 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7584 f64 timeout;
7585 u32 sw_if_index;
7586 u8 sw_if_index_set = 0;
7587 u8 suppress = 0;
7588 u8 managed = 0;
7589 u8 other = 0;
7590 u8 ll_option = 0;
7591 u8 send_unicast = 0;
7592 u8 cease = 0;
7593 u8 is_no = 0;
7594 u8 default_router = 0;
7595 u32 max_interval = 0;
7596 u32 min_interval = 0;
7597 u32 lifetime = 0;
7598 u32 initial_count = 0;
7599 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007600
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007601
Dave Barach72d72232016-08-04 10:15:08 -04007602 /* Parse args required to build the message */
7603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7604 {
7605 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7606 sw_if_index_set = 1;
7607 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7608 sw_if_index_set = 1;
7609 else if (unformat (i, "maxint %d", &max_interval))
7610 ;
7611 else if (unformat (i, "minint %d", &min_interval))
7612 ;
7613 else if (unformat (i, "life %d", &lifetime))
7614 ;
7615 else if (unformat (i, "count %d", &initial_count))
7616 ;
7617 else if (unformat (i, "interval %d", &initial_interval))
7618 ;
7619 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7620 suppress = 1;
7621 else if (unformat (i, "managed"))
7622 managed = 1;
7623 else if (unformat (i, "other"))
7624 other = 1;
7625 else if (unformat (i, "ll"))
7626 ll_option = 1;
7627 else if (unformat (i, "send"))
7628 send_unicast = 1;
7629 else if (unformat (i, "cease"))
7630 cease = 1;
7631 else if (unformat (i, "isno"))
7632 is_no = 1;
7633 else if (unformat (i, "def"))
7634 default_router = 1;
7635 else
7636 {
7637 clib_warning ("parse error '%U'", format_unformat_error, i);
7638 return -99;
7639 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007640 }
7641
Dave Barach72d72232016-08-04 10:15:08 -04007642 if (sw_if_index_set == 0)
7643 {
7644 errmsg ("missing interface name or sw_if_index\n");
7645 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007646 }
7647
Dave Barach72d72232016-08-04 10:15:08 -04007648 /* Construct the API message */
7649 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007650
Dave Barach72d72232016-08-04 10:15:08 -04007651 mp->sw_if_index = ntohl (sw_if_index);
7652 mp->max_interval = ntohl (max_interval);
7653 mp->min_interval = ntohl (min_interval);
7654 mp->lifetime = ntohl (lifetime);
7655 mp->initial_count = ntohl (initial_count);
7656 mp->initial_interval = ntohl (initial_interval);
7657 mp->suppress = suppress;
7658 mp->managed = managed;
7659 mp->other = other;
7660 mp->ll_option = ll_option;
7661 mp->send_unicast = send_unicast;
7662 mp->cease = cease;
7663 mp->is_no = is_no;
7664 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007665
Dave Barach72d72232016-08-04 10:15:08 -04007666 /* send it... */
7667 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007668
Dave Barach72d72232016-08-04 10:15:08 -04007669 /* Wait for a reply, return good/bad news */
7670 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007671
Dave Barach72d72232016-08-04 10:15:08 -04007672 /* NOTREACHED */
7673 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007674}
7675
Dave Barach72d72232016-08-04 10:15:08 -04007676static int
7677api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007678{
Dave Barach72d72232016-08-04 10:15:08 -04007679 unformat_input_t *i = vam->input;
7680 vl_api_set_arp_neighbor_limit_t *mp;
7681 f64 timeout;
7682 u32 arp_nbr_limit;
7683 u8 limit_set = 0;
7684 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007685
Dave Barach72d72232016-08-04 10:15:08 -04007686 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7687 {
7688 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7689 limit_set = 1;
7690 else if (unformat (i, "ipv6"))
7691 is_ipv6 = 1;
7692 else
7693 {
7694 clib_warning ("parse error '%U'", format_unformat_error, i);
7695 return -99;
7696 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007697 }
7698
Dave Barach72d72232016-08-04 10:15:08 -04007699 if (limit_set == 0)
7700 {
7701 errmsg ("missing limit value\n");
7702 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007703 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007704
Dave Barach72d72232016-08-04 10:15:08 -04007705 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007706
Dave Barach72d72232016-08-04 10:15:08 -04007707 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7708 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007709
Dave Barach72d72232016-08-04 10:15:08 -04007710 S;
7711 W;
7712 /* NOTREACHED */
7713 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007714}
7715
Dave Barach72d72232016-08-04 10:15:08 -04007716static int
7717api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007718{
Dave Barach72d72232016-08-04 10:15:08 -04007719 unformat_input_t *i = vam->input;
7720 vl_api_l2_patch_add_del_t *mp;
7721 f64 timeout;
7722 u32 rx_sw_if_index;
7723 u8 rx_sw_if_index_set = 0;
7724 u32 tx_sw_if_index;
7725 u8 tx_sw_if_index_set = 0;
7726 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007727
Dave Barach72d72232016-08-04 10:15:08 -04007728 /* Parse args required to build the message */
7729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7730 {
7731 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7732 rx_sw_if_index_set = 1;
7733 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7734 tx_sw_if_index_set = 1;
7735 else if (unformat (i, "rx"))
7736 {
7737 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7738 {
7739 if (unformat (i, "%U", unformat_sw_if_index, vam,
7740 &rx_sw_if_index))
7741 rx_sw_if_index_set = 1;
7742 }
7743 else
7744 break;
7745 }
7746 else if (unformat (i, "tx"))
7747 {
7748 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7749 {
7750 if (unformat (i, "%U", unformat_sw_if_index, vam,
7751 &tx_sw_if_index))
7752 tx_sw_if_index_set = 1;
7753 }
7754 else
7755 break;
7756 }
7757 else if (unformat (i, "del"))
7758 is_add = 0;
7759 else
7760 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007761 }
7762
Dave Barach72d72232016-08-04 10:15:08 -04007763 if (rx_sw_if_index_set == 0)
7764 {
7765 errmsg ("missing rx interface name or rx_sw_if_index\n");
7766 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007767 }
7768
Dave Barach72d72232016-08-04 10:15:08 -04007769 if (tx_sw_if_index_set == 0)
7770 {
7771 errmsg ("missing tx interface name or tx_sw_if_index\n");
7772 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007773 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007774
Dave Barach72d72232016-08-04 10:15:08 -04007775 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007776
Dave Barach72d72232016-08-04 10:15:08 -04007777 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7778 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7779 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007780
Dave Barach72d72232016-08-04 10:15:08 -04007781 S;
7782 W;
7783 /* NOTREACHED */
7784 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007785}
Dave Barach72d72232016-08-04 10:15:08 -04007786
7787static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007788api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007789{
Dave Barach72d72232016-08-04 10:15:08 -04007790 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007791 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007792 f64 timeout;
7793 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007794 int has_trace_option = 0;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307795 int has_pot_option = 0;
7796 int has_seqno_option = 0;
7797 int has_analyse_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007798
Shwetha20a64f52016-03-25 10:55:01 +00007799 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7800 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007801 if (unformat (input, "trace"))
7802 has_trace_option = 1;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307803 else if (unformat (input, "pot"))
7804 has_pot_option = 1;
7805 else if (unformat (input, "seqno"))
7806 has_seqno_option = 1;
7807 else if (unformat (input, "analyse"))
7808 has_analyse_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007809 else
Dave Barach72d72232016-08-04 10:15:08 -04007810 break;
Shwetha20a64f52016-03-25 10:55:01 +00007811 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007812 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007813 mp->id = htons (id);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307814 mp->seqno = has_seqno_option;
7815 mp->analyse = has_analyse_option;
7816 mp->pot_enable = has_pot_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007817 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007818
Dave Barach72d72232016-08-04 10:15:08 -04007819 S;
7820 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007821
Dave Barach72d72232016-08-04 10:15:08 -04007822 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007823
Shwetha20a64f52016-03-25 10:55:01 +00007824}
Dave Barach72d72232016-08-04 10:15:08 -04007825
Shwetha20a64f52016-03-25 10:55:01 +00007826
Dave Barach72d72232016-08-04 10:15:08 -04007827static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007828api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007829{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007830 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007831 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007832
Vengada Govindan07d2f842016-08-25 10:34:34 -07007833 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007834 S;
7835 W;
7836 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007837}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007838
Dave Barach72d72232016-08-04 10:15:08 -04007839static int
7840api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007841{
Dave Barach72d72232016-08-04 10:15:08 -04007842 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007843 vl_api_sr_tunnel_add_del_t *mp;
7844 f64 timeout;
7845 int is_del = 0;
7846 int pl_index;
7847 ip6_address_t src_address;
7848 int src_address_set = 0;
7849 ip6_address_t dst_address;
7850 u32 dst_mask_width;
7851 int dst_address_set = 0;
7852 u16 flags = 0;
7853 u32 rx_table_id = 0;
7854 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007855 ip6_address_t *segments = 0;
7856 ip6_address_t *this_seg;
7857 ip6_address_t *tags = 0;
7858 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007859 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007860 u8 *name = 0;
7861 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007862
7863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7864 {
7865 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007866 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007867 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007868 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007869 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007870 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007871 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007872 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007873 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007874 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007875 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007876 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007877 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007878 unformat_ip6_address, &dst_address, &dst_mask_width))
7879 dst_address_set = 1;
7880 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7881 {
7882 vec_add2 (segments, this_seg, 1);
7883 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7884 sizeof (*this_seg));
7885 }
7886 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7887 {
7888 vec_add2 (tags, this_tag, 1);
7889 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7890 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007891 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007892 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007893 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007894 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007895 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007896 {
7897 if (pl_index <= 0 || pl_index > 4)
7898 {
7899 pl_index_range_error:
7900 errmsg ("pl index %d out of range\n", pl_index);
7901 return -99;
7902 }
7903 flags |=
7904 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7905 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007906 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007907 {
7908 if (pl_index <= 0 || pl_index > 4)
7909 goto pl_index_range_error;
7910 flags |=
7911 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7912 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007913 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007914 {
7915 if (pl_index <= 0 || pl_index > 4)
7916 goto pl_index_range_error;
7917 flags |=
7918 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7919 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007920 else
Dave Barach72d72232016-08-04 10:15:08 -04007921 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007922 }
7923
7924 if (!src_address_set)
7925 {
7926 errmsg ("src address required\n");
7927 return -99;
7928 }
7929
7930 if (!dst_address_set)
7931 {
7932 errmsg ("dst address required\n");
7933 return -99;
7934 }
7935
7936 if (!segments)
7937 {
7938 errmsg ("at least one sr segment required\n");
7939 return -99;
7940 }
7941
Dave Barach72d72232016-08-04 10:15:08 -04007942 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7943 vec_len (segments) * sizeof (ip6_address_t)
7944 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007945
Damjan Marionf1213b82016-03-13 02:22:06 +01007946 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7947 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007948 mp->dst_mask_width = dst_mask_width;
7949 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7950 mp->n_segments = vec_len (segments);
7951 mp->n_tags = vec_len (tags);
7952 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007953 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007954 vec_len (segments) * sizeof (ip6_address_t));
7955 clib_memcpy (mp->segs_and_tags +
7956 vec_len (segments) * sizeof (ip6_address_t), tags,
7957 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007958
7959 mp->outer_vrf_id = ntohl (rx_table_id);
7960 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007961 memcpy (mp->name, name, vec_len (name));
7962 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007963
7964 vec_free (segments);
7965 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007966
Dave Barach72d72232016-08-04 10:15:08 -04007967 S;
7968 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007969 /* NOTREACHED */
7970}
7971
Dave Barach72d72232016-08-04 10:15:08 -04007972static int
7973api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007974{
Dave Barach72d72232016-08-04 10:15:08 -04007975 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007976 vl_api_sr_policy_add_del_t *mp;
7977 f64 timeout;
7978 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007979 u8 *name = 0;
7980 u8 *tunnel_name = 0;
7981 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007982
Dave Barach72d72232016-08-04 10:15:08 -04007983 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007984 int tunnel_set = 0;
7985 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007986 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7987 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 -07007988
7989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7990 {
7991 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007992 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007993 else if (unformat (input, "name %s", &name))
7994 name_set = 1;
7995 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04007996 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007997 if (tunnel_name)
7998 {
7999 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008000 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04008001 - length = #bytes to store in serial vector
8002 - +1 = byte to store that length
8003 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008004 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008005 tunnel_set = 1;
8006 tunnel_name = 0;
8007 }
Dave Barach72d72232016-08-04 10:15:08 -04008008 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008009 else
Dave Barach72d72232016-08-04 10:15:08 -04008010 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008011 }
8012
8013 if (!name_set)
8014 {
8015 errmsg ("policy name required\n");
8016 return -99;
8017 }
8018
8019 if ((!tunnel_set) && (!is_del))
8020 {
8021 errmsg ("tunnel name required\n");
8022 return -99;
8023 }
8024
Dave Barach72d72232016-08-04 10:15:08 -04008025 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008026
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008027
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008028
8029 mp->is_add = !is_del;
8030
Dave Barach72d72232016-08-04 10:15:08 -04008031 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008032 // 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 -04008033 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008034 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008035 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8036 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008037
Dave Barach72d72232016-08-04 10:15:08 -04008038 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008039 {
8040 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008041 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8042 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008043 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008044 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008045 }
Dave Barach72d72232016-08-04 10:15:08 -04008046 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 -07008047
8048 vec_free (tunnel_names);
8049 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008050
Dave Barach72d72232016-08-04 10:15:08 -04008051 S;
8052 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008053 /* NOTREACHED */
8054}
8055
Dave Barach72d72232016-08-04 10:15:08 -04008056static int
8057api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008058{
Dave Barach72d72232016-08-04 10:15:08 -04008059 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008060 vl_api_sr_multicast_map_add_del_t *mp;
8061 f64 timeout;
8062 int is_del = 0;
8063 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008064 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008065 int multicast_address_set = 0;
8066
8067 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8068 {
8069 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008070 is_del = 1;
8071 else
8072 if (unformat
8073 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008074 multicast_address_set = 1;
8075 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008076 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008077 else
Dave Barach72d72232016-08-04 10:15:08 -04008078 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008079 }
8080
8081 if (!is_del && !policy_name)
8082 {
8083 errmsg ("sr-policy name required\n");
8084 return -99;
8085 }
8086
8087
8088 if (!multicast_address_set)
8089 {
8090 errmsg ("address required\n");
8091 return -99;
8092 }
8093
Dave Barach72d72232016-08-04 10:15:08 -04008094 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008095
8096 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008097 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8098 clib_memcpy (mp->multicast_address, &multicast_address,
8099 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008100
8101
8102 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008103
Dave Barach72d72232016-08-04 10:15:08 -04008104 S;
8105 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008106 /* NOTREACHED */
8107}
8108
Ed Warnickecb9cada2015-12-08 15:45:58 -07008109
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008110#define foreach_tcp_proto_field \
8111_(src_port) \
8112_(dst_port)
8113
8114#define foreach_udp_proto_field \
8115_(src_port) \
8116_(dst_port)
8117
Ed Warnickecb9cada2015-12-08 15:45:58 -07008118#define foreach_ip4_proto_field \
8119_(src_address) \
8120_(dst_address) \
8121_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008122_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008123_(fragment_id) \
8124_(ttl) \
8125_(protocol) \
8126_(checksum)
8127
Dave Barach72d72232016-08-04 10:15:08 -04008128uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008129unformat_tcp_mask (unformat_input_t * input, va_list * args)
8130{
8131 u8 **maskp = va_arg (*args, u8 **);
8132 u8 *mask = 0;
8133 u8 found_something = 0;
8134 tcp_header_t *tcp;
8135
8136#define _(a) u8 a=0;
8137 foreach_tcp_proto_field;
8138#undef _
8139
8140 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8141 {
8142 if (0);
8143#define _(a) else if (unformat (input, #a)) a=1;
8144 foreach_tcp_proto_field
8145#undef _
8146 else
8147 break;
8148 }
8149
8150#define _(a) found_something += a;
8151 foreach_tcp_proto_field;
8152#undef _
8153
8154 if (found_something == 0)
8155 return 0;
8156
8157 vec_validate (mask, sizeof (*tcp) - 1);
8158
8159 tcp = (tcp_header_t *) mask;
8160
8161#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8162 foreach_tcp_proto_field;
8163#undef _
8164
8165 *maskp = mask;
8166 return 1;
8167}
8168
8169uword
8170unformat_udp_mask (unformat_input_t * input, va_list * args)
8171{
8172 u8 **maskp = va_arg (*args, u8 **);
8173 u8 *mask = 0;
8174 u8 found_something = 0;
8175 udp_header_t *udp;
8176
8177#define _(a) u8 a=0;
8178 foreach_udp_proto_field;
8179#undef _
8180
8181 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8182 {
8183 if (0);
8184#define _(a) else if (unformat (input, #a)) a=1;
8185 foreach_udp_proto_field
8186#undef _
8187 else
8188 break;
8189 }
8190
8191#define _(a) found_something += a;
8192 foreach_udp_proto_field;
8193#undef _
8194
8195 if (found_something == 0)
8196 return 0;
8197
8198 vec_validate (mask, sizeof (*udp) - 1);
8199
8200 udp = (udp_header_t *) mask;
8201
8202#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8203 foreach_udp_proto_field;
8204#undef _
8205
8206 *maskp = mask;
8207 return 1;
8208}
8209
8210typedef struct
8211{
8212 u16 src_port, dst_port;
8213} tcpudp_header_t;
8214
8215uword
8216unformat_l4_mask (unformat_input_t * input, va_list * args)
8217{
8218 u8 **maskp = va_arg (*args, u8 **);
8219 u16 src_port = 0, dst_port = 0;
8220 tcpudp_header_t *tcpudp;
8221
8222 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8223 {
8224 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8225 return 1;
8226 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8227 return 1;
8228 else if (unformat (input, "src_port"))
8229 src_port = 0xFFFF;
8230 else if (unformat (input, "dst_port"))
8231 dst_port = 0xFFFF;
8232 else
8233 return 0;
8234 }
8235
8236 if (!src_port && !dst_port)
8237 return 0;
8238
8239 u8 *mask = 0;
8240 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8241
8242 tcpudp = (tcpudp_header_t *) mask;
8243 tcpudp->src_port = src_port;
8244 tcpudp->dst_port = dst_port;
8245
8246 *maskp = mask;
8247
8248 return 1;
8249}
8250
8251uword
Dave Barach72d72232016-08-04 10:15:08 -04008252unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008253{
Dave Barach72d72232016-08-04 10:15:08 -04008254 u8 **maskp = va_arg (*args, u8 **);
8255 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008256 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008257 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008258
Ed Warnickecb9cada2015-12-08 15:45:58 -07008259#define _(a) u8 a=0;
8260 foreach_ip4_proto_field;
8261#undef _
8262 u8 version = 0;
8263 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008264
8265
8266 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008267 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008268 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008269 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008270 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008271 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008272 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008273 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008274 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008275 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008276 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008277 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008278
Ed Warnickecb9cada2015-12-08 15:45:58 -07008279#define _(a) else if (unformat (input, #a)) a=1;
8280 foreach_ip4_proto_field
8281#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008282 else
8283 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008284 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008285
Ed Warnickecb9cada2015-12-08 15:45:58 -07008286#define _(a) found_something += a;
8287 foreach_ip4_proto_field;
8288#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008289
Ed Warnickecb9cada2015-12-08 15:45:58 -07008290 if (found_something == 0)
8291 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008292
Ed Warnickecb9cada2015-12-08 15:45:58 -07008293 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008294
Ed Warnickecb9cada2015-12-08 15:45:58 -07008295 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008296
Ed Warnickecb9cada2015-12-08 15:45:58 -07008297#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8298 foreach_ip4_proto_field;
8299#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008300
Ed Warnickecb9cada2015-12-08 15:45:58 -07008301 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008302
Ed Warnickecb9cada2015-12-08 15:45:58 -07008303 if (version)
8304 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008305
Ed Warnickecb9cada2015-12-08 15:45:58 -07008306 if (hdr_length)
8307 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008308
Ed Warnickecb9cada2015-12-08 15:45:58 -07008309 *maskp = mask;
8310 return 1;
8311}
8312
8313#define foreach_ip6_proto_field \
8314_(src_address) \
8315_(dst_address) \
8316_(payload_length) \
8317_(hop_limit) \
8318_(protocol)
8319
Dave Barach72d72232016-08-04 10:15:08 -04008320uword
8321unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008322{
Dave Barach72d72232016-08-04 10:15:08 -04008323 u8 **maskp = va_arg (*args, u8 **);
8324 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008325 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008326 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008327 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008328
Ed Warnickecb9cada2015-12-08 15:45:58 -07008329#define _(a) u8 a=0;
8330 foreach_ip6_proto_field;
8331#undef _
8332 u8 version = 0;
8333 u8 traffic_class = 0;
8334 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008335
8336 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008337 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008338 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008339 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008340 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008341 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008342 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008343 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008344 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008345 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008346 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008347 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008348 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008349 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008350
Ed Warnickecb9cada2015-12-08 15:45:58 -07008351#define _(a) else if (unformat (input, #a)) a=1;
8352 foreach_ip6_proto_field
8353#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008354 else
8355 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008356 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008357
Ed Warnickecb9cada2015-12-08 15:45:58 -07008358#define _(a) found_something += a;
8359 foreach_ip6_proto_field;
8360#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008361
Ed Warnickecb9cada2015-12-08 15:45:58 -07008362 if (found_something == 0)
8363 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008364
Ed Warnickecb9cada2015-12-08 15:45:58 -07008365 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008366
Ed Warnickecb9cada2015-12-08 15:45:58 -07008367 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008368
Ed Warnickecb9cada2015-12-08 15:45:58 -07008369#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8370 foreach_ip6_proto_field;
8371#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008372
Ed Warnickecb9cada2015-12-08 15:45:58 -07008373 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008374
Ed Warnickecb9cada2015-12-08 15:45:58 -07008375 if (version)
8376 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8377
8378 if (traffic_class)
8379 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8380
8381 if (flow_label)
8382 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8383
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008384 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008385 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008386
Ed Warnickecb9cada2015-12-08 15:45:58 -07008387 *maskp = mask;
8388 return 1;
8389}
8390
Dave Barach72d72232016-08-04 10:15:08 -04008391uword
8392unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008393{
Dave Barach72d72232016-08-04 10:15:08 -04008394 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008395
Dave Barach72d72232016-08-04 10:15:08 -04008396 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8397 {
8398 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8399 return 1;
8400 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8401 return 1;
8402 else
8403 break;
8404 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008405 return 0;
8406}
8407
Dave Barach72d72232016-08-04 10:15:08 -04008408uword
8409unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008410{
Dave Barach72d72232016-08-04 10:15:08 -04008411 u8 **maskp = va_arg (*args, u8 **);
8412 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008413 u8 src = 0;
8414 u8 dst = 0;
8415 u8 proto = 0;
8416 u8 tag1 = 0;
8417 u8 tag2 = 0;
8418 u8 ignore_tag1 = 0;
8419 u8 ignore_tag2 = 0;
8420 u8 cos1 = 0;
8421 u8 cos2 = 0;
8422 u8 dot1q = 0;
8423 u8 dot1ad = 0;
8424 int len = 14;
8425
Dave Barach72d72232016-08-04 10:15:08 -04008426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8427 {
8428 if (unformat (input, "src"))
8429 src = 1;
8430 else if (unformat (input, "dst"))
8431 dst = 1;
8432 else if (unformat (input, "proto"))
8433 proto = 1;
8434 else if (unformat (input, "tag1"))
8435 tag1 = 1;
8436 else if (unformat (input, "tag2"))
8437 tag2 = 1;
8438 else if (unformat (input, "ignore-tag1"))
8439 ignore_tag1 = 1;
8440 else if (unformat (input, "ignore-tag2"))
8441 ignore_tag2 = 1;
8442 else if (unformat (input, "cos1"))
8443 cos1 = 1;
8444 else if (unformat (input, "cos2"))
8445 cos2 = 1;
8446 else if (unformat (input, "dot1q"))
8447 dot1q = 1;
8448 else if (unformat (input, "dot1ad"))
8449 dot1ad = 1;
8450 else
8451 break;
8452 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008453 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008454 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008455 return 0;
8456
8457 if (tag1 || ignore_tag1 || cos1 || dot1q)
8458 len = 18;
8459 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8460 len = 22;
8461
Dave Barach72d72232016-08-04 10:15:08 -04008462 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008463
8464 if (dst)
8465 memset (mask, 0xff, 6);
8466
8467 if (src)
8468 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008469
Ed Warnickecb9cada2015-12-08 15:45:58 -07008470 if (tag2 || dot1ad)
8471 {
8472 /* inner vlan tag */
8473 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008474 {
8475 mask[19] = 0xff;
8476 mask[18] = 0x0f;
8477 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008478 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008479 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008480 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008481 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008482 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008483 {
8484 mask[15] = 0xff;
8485 mask[14] = 0x0f;
8486 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008487 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008488 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008489 *maskp = mask;
8490 return 1;
8491 }
8492 if (tag1 | dot1q)
8493 {
8494 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008495 {
8496 mask[15] = 0xff;
8497 mask[14] = 0x0f;
8498 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008499 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008500 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008501 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008502 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008503
8504 *maskp = mask;
8505 return 1;
8506 }
8507 if (cos2)
8508 mask[18] |= 0xe0;
8509 if (cos1)
8510 mask[14] |= 0xe0;
8511 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008512 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008513
Ed Warnickecb9cada2015-12-08 15:45:58 -07008514 *maskp = mask;
8515 return 1;
8516}
8517
Dave Barach72d72232016-08-04 10:15:08 -04008518uword
8519unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008520{
Dave Barach72d72232016-08-04 10:15:08 -04008521 u8 **maskp = va_arg (*args, u8 **);
8522 u32 *skipp = va_arg (*args, u32 *);
8523 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008524 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008525 u8 *mask = 0;
8526 u8 *l2 = 0;
8527 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008528 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008529 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008530
Dave Barach72d72232016-08-04 10:15:08 -04008531 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8532 {
8533 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8534 ;
8535 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8536 ;
8537 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8538 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008539 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8540 ;
Dave Barach72d72232016-08-04 10:15:08 -04008541 else
8542 break;
8543 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008544
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008545 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008546 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008547 vec_free (mask);
8548 vec_free (l2);
8549 vec_free (l4);
8550 return 0;
8551 }
8552
8553 if (mask || l2 || l3 || l4)
8554 {
8555 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008556 {
8557 /* "With a free Ethernet header in every package" */
8558 if (l2 == 0)
8559 vec_validate (l2, 13);
8560 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008561 if (vec_len (l3))
8562 {
8563 vec_append (mask, l3);
8564 vec_free (l3);
8565 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008566 if (vec_len (l4))
8567 {
8568 vec_append (mask, l4);
8569 vec_free (l4);
8570 }
Dave Barach72d72232016-08-04 10:15:08 -04008571 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008572
8573 /* Scan forward looking for the first significant mask octet */
8574 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008575 if (mask[i])
8576 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008577
8578 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008579 *skipp = i / sizeof (u32x4);
8580 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008581
8582 /* Pad mask to an even multiple of the vector size */
8583 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008584 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008585
8586 match = vec_len (mask) / sizeof (u32x4);
8587
Dave Barach72d72232016-08-04 10:15:08 -04008588 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8589 {
8590 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8591 if (*tmp || *(tmp + 1))
8592 break;
8593 match--;
8594 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008595 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008596 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008597
Dave Barach72d72232016-08-04 10:15:08 -04008598 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008599
8600 *matchp = match;
8601 *maskp = mask;
8602
8603 return 1;
8604 }
8605
8606 return 0;
8607}
8608
8609#define foreach_l2_next \
8610_(drop, DROP) \
8611_(ethernet, ETHERNET_INPUT) \
8612_(ip4, IP4_INPUT) \
8613_(ip6, IP6_INPUT)
8614
Dave Barach72d72232016-08-04 10:15:08 -04008615uword
8616unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008617{
Dave Barach72d72232016-08-04 10:15:08 -04008618 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008619 u32 next_index = 0;
8620 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008621
Ed Warnickecb9cada2015-12-08 15:45:58 -07008622#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008623 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008624 foreach_l2_next;
8625#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008626
Ed Warnickecb9cada2015-12-08 15:45:58 -07008627 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008628 {
8629 next_index = tmp;
8630 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008631 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008632
Ed Warnickecb9cada2015-12-08 15:45:58 -07008633 return 0;
8634
Dave Barach72d72232016-08-04 10:15:08 -04008635out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008636 *miss_next_indexp = next_index;
8637 return 1;
8638}
8639
8640#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008641_(drop, DROP) \
8642_(local, LOCAL) \
8643_(rewrite, REWRITE)
8644
Dave Barach72d72232016-08-04 10:15:08 -04008645uword
8646unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008647{
Dave Barach72d72232016-08-04 10:15:08 -04008648 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008649 u32 next_index = 0;
8650 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008651
Ed Warnickecb9cada2015-12-08 15:45:58 -07008652#define _(n,N) \
8653 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8654 foreach_ip_next;
8655#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008656
Ed Warnickecb9cada2015-12-08 15:45:58 -07008657 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008658 {
8659 next_index = tmp;
8660 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008661 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008662
Ed Warnickecb9cada2015-12-08 15:45:58 -07008663 return 0;
8664
Dave Barach72d72232016-08-04 10:15:08 -04008665out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008666 *miss_next_indexp = next_index;
8667 return 1;
8668}
8669
8670#define foreach_acl_next \
8671_(deny, DENY)
8672
Dave Barach72d72232016-08-04 10:15:08 -04008673uword
8674unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008675{
Dave Barach72d72232016-08-04 10:15:08 -04008676 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008677 u32 next_index = 0;
8678 u32 tmp;
8679
8680#define _(n,N) \
8681 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8682 foreach_acl_next;
8683#undef _
8684
8685 if (unformat (input, "permit"))
8686 {
8687 next_index = ~0;
8688 goto out;
8689 }
8690 else if (unformat (input, "%d", &tmp))
8691 {
8692 next_index = tmp;
8693 goto out;
8694 }
8695
8696 return 0;
8697
Dave Barach72d72232016-08-04 10:15:08 -04008698out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008699 *miss_next_indexp = next_index;
8700 return 1;
8701}
8702
Dave Barach72d72232016-08-04 10:15:08 -04008703uword
8704unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008705{
Dave Barach72d72232016-08-04 10:15:08 -04008706 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008707
8708 if (unformat (input, "conform-color"))
8709 *r = POLICE_CONFORM;
8710 else if (unformat (input, "exceed-color"))
8711 *r = POLICE_EXCEED;
8712 else
8713 return 0;
8714
8715 return 1;
8716}
8717
Dave Barach72d72232016-08-04 10:15:08 -04008718static int
8719api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008720{
Dave Barach72d72232016-08-04 10:15:08 -04008721 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008722 vl_api_classify_add_del_table_t *mp;
8723
8724 u32 nbuckets = 2;
8725 u32 skip = ~0;
8726 u32 match = ~0;
8727 int is_add = 1;
8728 u32 table_index = ~0;
8729 u32 next_table_index = ~0;
8730 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008731 u32 memory_size = 32 << 20;
8732 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008733 f64 timeout;
Steve Shin25e26dc2016-11-08 10:47:10 -08008734 u32 current_data_flag = 0;
8735 int current_data_offset = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008736
Dave Barach72d72232016-08-04 10:15:08 -04008737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8738 {
8739 if (unformat (i, "del"))
8740 is_add = 0;
8741 else if (unformat (i, "buckets %d", &nbuckets))
8742 ;
8743 else if (unformat (i, "memory_size %d", &memory_size))
8744 ;
8745 else if (unformat (i, "skip %d", &skip))
8746 ;
8747 else if (unformat (i, "match %d", &match))
8748 ;
8749 else if (unformat (i, "table %d", &table_index))
8750 ;
8751 else if (unformat (i, "mask %U", unformat_classify_mask,
8752 &mask, &skip, &match))
8753 ;
8754 else if (unformat (i, "next-table %d", &next_table_index))
8755 ;
8756 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8757 &miss_next_index))
8758 ;
8759 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8760 &miss_next_index))
8761 ;
8762 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8763 &miss_next_index))
8764 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08008765 else if (unformat (i, "current-data-flag %d", &current_data_flag))
8766 ;
8767 else if (unformat (i, "current-data-offset %d", &current_data_offset))
8768 ;
Dave Barach72d72232016-08-04 10:15:08 -04008769 else
8770 break;
8771 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008772
Dave Barach72d72232016-08-04 10:15:08 -04008773 if (is_add && mask == 0)
8774 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008775 errmsg ("Mask required\n");
8776 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008777 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008778
Dave Barach72d72232016-08-04 10:15:08 -04008779 if (is_add && skip == ~0)
8780 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008781 errmsg ("skip count required\n");
8782 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008783 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008784
Dave Barach72d72232016-08-04 10:15:08 -04008785 if (is_add && match == ~0)
8786 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008787 errmsg ("match count required\n");
8788 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008789 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008790
Dave Barach72d72232016-08-04 10:15:08 -04008791 if (!is_add && table_index == ~0)
8792 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008793 errmsg ("table index required for delete\n");
8794 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008795 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008796
Dave Barach72d72232016-08-04 10:15:08 -04008797 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008798
8799 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008800 mp->table_index = ntohl (table_index);
8801 mp->nbuckets = ntohl (nbuckets);
8802 mp->memory_size = ntohl (memory_size);
8803 mp->skip_n_vectors = ntohl (skip);
8804 mp->match_n_vectors = ntohl (match);
8805 mp->next_table_index = ntohl (next_table_index);
8806 mp->miss_next_index = ntohl (miss_next_index);
Steve Shin25e26dc2016-11-08 10:47:10 -08008807 mp->current_data_flag = ntohl (current_data_flag);
8808 mp->current_data_offset = ntohl (current_data_offset);
Dave Barach72d72232016-08-04 10:15:08 -04008809 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008810
Dave Barach72d72232016-08-04 10:15:08 -04008811 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008812
Dave Barach72d72232016-08-04 10:15:08 -04008813 S;
8814 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008815 /* NOTREACHED */
8816}
8817
Dave Barach72d72232016-08-04 10:15:08 -04008818uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008819unformat_l4_match (unformat_input_t * input, va_list * args)
8820{
8821 u8 **matchp = va_arg (*args, u8 **);
8822
8823 u8 *proto_header = 0;
8824 int src_port = 0;
8825 int dst_port = 0;
8826
8827 tcpudp_header_t h;
8828
8829 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8830 {
8831 if (unformat (input, "src_port %d", &src_port))
8832 ;
8833 else if (unformat (input, "dst_port %d", &dst_port))
8834 ;
8835 else
8836 return 0;
8837 }
8838
8839 h.src_port = clib_host_to_net_u16 (src_port);
8840 h.dst_port = clib_host_to_net_u16 (dst_port);
8841 vec_validate (proto_header, sizeof (h) - 1);
8842 memcpy (proto_header, &h, sizeof (h));
8843
8844 *matchp = proto_header;
8845
8846 return 1;
8847}
8848
8849uword
Dave Barach72d72232016-08-04 10:15:08 -04008850unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008851{
Dave Barach72d72232016-08-04 10:15:08 -04008852 u8 **matchp = va_arg (*args, u8 **);
8853 u8 *match = 0;
8854 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008855 int version = 0;
8856 u32 version_val;
8857 int hdr_length = 0;
8858 u32 hdr_length_val;
8859 int src = 0, dst = 0;
8860 ip4_address_t src_val, dst_val;
8861 int proto = 0;
8862 u32 proto_val;
8863 int tos = 0;
8864 u32 tos_val;
8865 int length = 0;
8866 u32 length_val;
8867 int fragment_id = 0;
8868 u32 fragment_id_val;
8869 int ttl = 0;
8870 int ttl_val;
8871 int checksum = 0;
8872 u32 checksum_val;
8873
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008874 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008875 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008876 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008877 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008878 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008879 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008880 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008881 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008882 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008883 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008884 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008885 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008886 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008887 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008888 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008889 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008890 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008891 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008892 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008893 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008894 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008895 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008896 else
Dave Barach72d72232016-08-04 10:15:08 -04008897 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008898 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008899
Ed Warnickecb9cada2015-12-08 15:45:58 -07008900 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8901 + ttl + checksum == 0)
8902 return 0;
8903
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008904 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008905 * Aligned because we use the real comparison functions
8906 */
Dave Barach72d72232016-08-04 10:15:08 -04008907 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008908
Ed Warnickecb9cada2015-12-08 15:45:58 -07008909 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008910
Ed Warnickecb9cada2015-12-08 15:45:58 -07008911 /* These are realistically matched in practice */
8912 if (src)
8913 ip->src_address.as_u32 = src_val.as_u32;
8914
8915 if (dst)
8916 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008917
Ed Warnickecb9cada2015-12-08 15:45:58 -07008918 if (proto)
8919 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008920
Ed Warnickecb9cada2015-12-08 15:45:58 -07008921
8922 /* These are not, but they're included for completeness */
8923 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008924 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008925
8926 if (hdr_length)
8927 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008928
Ed Warnickecb9cada2015-12-08 15:45:58 -07008929 if (tos)
8930 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008931
Ed Warnickecb9cada2015-12-08 15:45:58 -07008932 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008933 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008934
Ed Warnickecb9cada2015-12-08 15:45:58 -07008935 if (ttl)
8936 ip->ttl = ttl_val;
8937
8938 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008939 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008940
8941 *matchp = match;
8942 return 1;
8943}
8944
Dave Barach72d72232016-08-04 10:15:08 -04008945uword
8946unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008947{
Dave Barach72d72232016-08-04 10:15:08 -04008948 u8 **matchp = va_arg (*args, u8 **);
8949 u8 *match = 0;
8950 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008951 int version = 0;
8952 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008953 u8 traffic_class = 0;
8954 u32 traffic_class_val = 0;
8955 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008956 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008957 int src = 0, dst = 0;
8958 ip6_address_t src_val, dst_val;
8959 int proto = 0;
8960 u32 proto_val;
8961 int payload_length = 0;
8962 u32 payload_length_val;
8963 int hop_limit = 0;
8964 int hop_limit_val;
8965 u32 ip_version_traffic_class_and_flow_label;
8966
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008967 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008968 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008969 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008970 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008971 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008972 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008973 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008974 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008975 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008976 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008977 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008978 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008979 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008980 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008981 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008982 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008983 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008984 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008985 else
Dave Barach72d72232016-08-04 10:15:08 -04008986 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008987 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008988
Ed Warnickecb9cada2015-12-08 15:45:58 -07008989 if (version + traffic_class + flow_label + src + dst + proto +
8990 payload_length + hop_limit == 0)
8991 return 0;
8992
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008993 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008994 * Aligned because we use the real comparison functions
8995 */
Dave Barach72d72232016-08-04 10:15:08 -04008996 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008997
Ed Warnickecb9cada2015-12-08 15:45:58 -07008998 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008999
Ed Warnickecb9cada2015-12-08 15:45:58 -07009000 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009001 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009002
9003 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009004 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009005
Ed Warnickecb9cada2015-12-08 15:45:58 -07009006 if (proto)
9007 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009008
Ed Warnickecb9cada2015-12-08 15:45:58 -07009009 ip_version_traffic_class_and_flow_label = 0;
9010
9011 if (version)
9012 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
9013
9014 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04009015 ip_version_traffic_class_and_flow_label |=
9016 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009017
9018 if (flow_label)
9019 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009020
9021 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07009022 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9023
9024 if (payload_length)
9025 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009026
Ed Warnickecb9cada2015-12-08 15:45:58 -07009027 if (hop_limit)
9028 ip->hop_limit = hop_limit_val;
9029
9030 *matchp = match;
9031 return 1;
9032}
9033
Dave Barach72d72232016-08-04 10:15:08 -04009034uword
9035unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009036{
Dave Barach72d72232016-08-04 10:15:08 -04009037 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009038
Dave Barach72d72232016-08-04 10:15:08 -04009039 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9040 {
9041 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9042 return 1;
9043 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9044 return 1;
9045 else
9046 break;
9047 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009048 return 0;
9049}
9050
Dave Barach72d72232016-08-04 10:15:08 -04009051uword
9052unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009053{
Dave Barach72d72232016-08-04 10:15:08 -04009054 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009055 u32 tag;
9056
Dave Barach72d72232016-08-04 10:15:08 -04009057 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009058 {
Dave Barach72d72232016-08-04 10:15:08 -04009059 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009060 tagp[1] = tag & 0xFF;
9061 return 1;
9062 }
9063
9064 return 0;
9065}
9066
Dave Barach72d72232016-08-04 10:15:08 -04009067uword
9068unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009069{
Dave Barach72d72232016-08-04 10:15:08 -04009070 u8 **matchp = va_arg (*args, u8 **);
9071 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009072 u8 src = 0;
9073 u8 src_val[6];
9074 u8 dst = 0;
9075 u8 dst_val[6];
9076 u8 proto = 0;
9077 u16 proto_val;
9078 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009079 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009080 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009081 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009082 int len = 14;
9083 u8 ignore_tag1 = 0;
9084 u8 ignore_tag2 = 0;
9085 u8 cos1 = 0;
9086 u8 cos2 = 0;
9087 u32 cos1_val = 0;
9088 u32 cos2_val = 0;
9089
Dave Barach72d72232016-08-04 10:15:08 -04009090 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9091 {
9092 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9093 src = 1;
9094 else
9095 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9096 dst = 1;
9097 else if (unformat (input, "proto %U",
9098 unformat_ethernet_type_host_byte_order, &proto_val))
9099 proto = 1;
9100 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9101 tag1 = 1;
9102 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9103 tag2 = 1;
9104 else if (unformat (input, "ignore-tag1"))
9105 ignore_tag1 = 1;
9106 else if (unformat (input, "ignore-tag2"))
9107 ignore_tag2 = 1;
9108 else if (unformat (input, "cos1 %d", &cos1_val))
9109 cos1 = 1;
9110 else if (unformat (input, "cos2 %d", &cos2_val))
9111 cos2 = 1;
9112 else
9113 break;
9114 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009115 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009116 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009117 return 0;
9118
9119 if (tag1 || ignore_tag1 || cos1)
9120 len = 18;
9121 if (tag2 || ignore_tag2 || cos2)
9122 len = 22;
9123
Dave Barach72d72232016-08-04 10:15:08 -04009124 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009125
9126 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009127 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009128
9129 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009130 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009131
Ed Warnickecb9cada2015-12-08 15:45:58 -07009132 if (tag2)
9133 {
9134 /* inner vlan tag */
9135 match[19] = tag2_val[1];
9136 match[18] = tag2_val[0];
9137 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009138 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009139 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009140 {
9141 match[21] = proto_val & 0xff;
9142 match[20] = proto_val >> 8;
9143 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009144 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009145 {
9146 match[15] = tag1_val[1];
9147 match[14] = tag1_val[0];
9148 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009149 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009150 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009151 *matchp = match;
9152 return 1;
9153 }
9154 if (tag1)
9155 {
Dave Barach72d72232016-08-04 10:15:08 -04009156 match[15] = tag1_val[1];
9157 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009158 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009159 {
9160 match[17] = proto_val & 0xff;
9161 match[16] = proto_val >> 8;
9162 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009163 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009164 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009165
9166 *matchp = match;
9167 return 1;
9168 }
9169 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009170 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009171 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009172 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009173 if (proto)
9174 {
9175 match[13] = proto_val & 0xff;
9176 match[12] = proto_val >> 8;
9177 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009178
Ed Warnickecb9cada2015-12-08 15:45:58 -07009179 *matchp = match;
9180 return 1;
9181}
9182
9183
Dave Barach72d72232016-08-04 10:15:08 -04009184uword
9185unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009186{
Dave Barach72d72232016-08-04 10:15:08 -04009187 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009188 u32 skip_n_vectors = va_arg (*args, u32);
9189 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009190
Dave Barach72d72232016-08-04 10:15:08 -04009191 u8 *match = 0;
9192 u8 *l2 = 0;
9193 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009194 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009195
Dave Barach72d72232016-08-04 10:15:08 -04009196 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9197 {
9198 if (unformat (input, "hex %U", unformat_hex_string, &match))
9199 ;
9200 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9201 ;
9202 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9203 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009204 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9205 ;
Dave Barach72d72232016-08-04 10:15:08 -04009206 else
9207 break;
9208 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009209
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009210 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009211 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009212 vec_free (match);
9213 vec_free (l2);
9214 vec_free (l4);
9215 return 0;
9216 }
9217
9218 if (match || l2 || l3 || l4)
9219 {
9220 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009221 {
9222 /* "Win a free Ethernet header in every packet" */
9223 if (l2 == 0)
9224 vec_validate_aligned (l2, 13, sizeof (u32x4));
9225 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009226 if (vec_len (l3))
9227 {
9228 vec_append_aligned (match, l3, sizeof (u32x4));
9229 vec_free (l3);
9230 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009231 if (vec_len (l4))
9232 {
9233 vec_append_aligned (match, l4, sizeof (u32x4));
9234 vec_free (l4);
9235 }
Dave Barach72d72232016-08-04 10:15:08 -04009236 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009237
9238 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009239 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009240 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9241 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009242
Dave Barach72d72232016-08-04 10:15:08 -04009243 /* Set size, include skipped vectors */
9244 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009245
9246 *matchp = match;
9247
9248 return 1;
9249 }
9250
9251 return 0;
9252}
9253
Dave Barach72d72232016-08-04 10:15:08 -04009254static int
9255api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009256{
Dave Barach72d72232016-08-04 10:15:08 -04009257 unformat_input_t *i = vam->input;
9258 vl_api_classify_add_del_session_t *mp;
9259 int is_add = 1;
9260 u32 table_index = ~0;
9261 u32 hit_next_index = ~0;
9262 u32 opaque_index = ~0;
9263 u8 *match = 0;
9264 i32 advance = 0;
9265 f64 timeout;
9266 u32 skip_n_vectors = 0;
9267 u32 match_n_vectors = 0;
Steve Shin25e26dc2016-11-08 10:47:10 -08009268 u32 action = 0;
9269 u32 metadata = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009270
Dave Barach72d72232016-08-04 10:15:08 -04009271 /*
9272 * Warning: you have to supply skip_n and match_n
9273 * because the API client cant simply look at the classify
9274 * table object.
9275 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009276
Dave Barach72d72232016-08-04 10:15:08 -04009277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9278 {
9279 if (unformat (i, "del"))
9280 is_add = 0;
9281 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9282 &hit_next_index))
9283 ;
9284 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9285 &hit_next_index))
9286 ;
9287 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9288 &hit_next_index))
9289 ;
9290 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9291 ;
9292 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9293 ;
9294 else if (unformat (i, "opaque-index %d", &opaque_index))
9295 ;
9296 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9297 ;
9298 else if (unformat (i, "match_n %d", &match_n_vectors))
9299 ;
9300 else if (unformat (i, "match %U", unformat_classify_match,
9301 &match, skip_n_vectors, match_n_vectors))
9302 ;
9303 else if (unformat (i, "advance %d", &advance))
9304 ;
9305 else if (unformat (i, "table-index %d", &table_index))
9306 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08009307 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
9308 action = 1;
9309 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
9310 action = 2;
9311 else if (unformat (i, "action %d", &action))
9312 ;
9313 else if (unformat (i, "metadata %d", &metadata))
9314 ;
Dave Barach72d72232016-08-04 10:15:08 -04009315 else
9316 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009317 }
9318
Dave Barach72d72232016-08-04 10:15:08 -04009319 if (table_index == ~0)
9320 {
9321 errmsg ("Table index required\n");
9322 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009323 }
9324
Dave Barach72d72232016-08-04 10:15:08 -04009325 if (is_add && match == 0)
9326 {
9327 errmsg ("Match value required\n");
9328 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009329 }
9330
Dave Barach72d72232016-08-04 10:15:08 -04009331 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009332
Dave Barach72d72232016-08-04 10:15:08 -04009333 mp->is_add = is_add;
9334 mp->table_index = ntohl (table_index);
9335 mp->hit_next_index = ntohl (hit_next_index);
9336 mp->opaque_index = ntohl (opaque_index);
9337 mp->advance = ntohl (advance);
Steve Shin25e26dc2016-11-08 10:47:10 -08009338 mp->action = action;
9339 mp->metadata = ntohl (metadata);
Dave Barach72d72232016-08-04 10:15:08 -04009340 clib_memcpy (mp->match, match, vec_len (match));
9341 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009342
Dave Barach72d72232016-08-04 10:15:08 -04009343 S;
9344 W;
9345 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009346}
9347
Dave Barach72d72232016-08-04 10:15:08 -04009348static int
9349api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009350{
Dave Barach72d72232016-08-04 10:15:08 -04009351 unformat_input_t *i = vam->input;
9352 vl_api_classify_set_interface_ip_table_t *mp;
9353 f64 timeout;
9354 u32 sw_if_index;
9355 int sw_if_index_set;
9356 u32 table_index = ~0;
9357 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009358
Dave Barach72d72232016-08-04 10:15:08 -04009359 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9360 {
9361 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9362 sw_if_index_set = 1;
9363 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9364 sw_if_index_set = 1;
9365 else if (unformat (i, "table %d", &table_index))
9366 ;
9367 else
9368 {
9369 clib_warning ("parse error '%U'", format_unformat_error, i);
9370 return -99;
9371 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009372 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009373
Dave Barach72d72232016-08-04 10:15:08 -04009374 if (sw_if_index_set == 0)
9375 {
9376 errmsg ("missing interface name or sw_if_index\n");
9377 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009378 }
9379
9380
Dave Barach72d72232016-08-04 10:15:08 -04009381 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009382
Dave Barach72d72232016-08-04 10:15:08 -04009383 mp->sw_if_index = ntohl (sw_if_index);
9384 mp->table_index = ntohl (table_index);
9385 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009386
Dave Barach72d72232016-08-04 10:15:08 -04009387 S;
9388 W;
9389 /* NOTREACHED */
9390 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009391}
9392
Dave Barach72d72232016-08-04 10:15:08 -04009393static int
9394api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009395{
Dave Barach72d72232016-08-04 10:15:08 -04009396 unformat_input_t *i = vam->input;
9397 vl_api_classify_set_interface_l2_tables_t *mp;
9398 f64 timeout;
9399 u32 sw_if_index;
9400 int sw_if_index_set;
9401 u32 ip4_table_index = ~0;
9402 u32 ip6_table_index = ~0;
9403 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009404 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009405
Dave Barach72d72232016-08-04 10:15:08 -04009406 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9407 {
9408 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9409 sw_if_index_set = 1;
9410 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9411 sw_if_index_set = 1;
9412 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9413 ;
9414 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9415 ;
9416 else if (unformat (i, "other-table %d", &other_table_index))
9417 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009418 else if (unformat (i, "is-input %d", &is_input))
9419 ;
Dave Barach72d72232016-08-04 10:15:08 -04009420 else
9421 {
9422 clib_warning ("parse error '%U'", format_unformat_error, i);
9423 return -99;
9424 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009425 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009426
Dave Barach72d72232016-08-04 10:15:08 -04009427 if (sw_if_index_set == 0)
9428 {
9429 errmsg ("missing interface name or sw_if_index\n");
9430 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009431 }
9432
9433
Dave Barach72d72232016-08-04 10:15:08 -04009434 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009435
Dave Barach72d72232016-08-04 10:15:08 -04009436 mp->sw_if_index = ntohl (sw_if_index);
9437 mp->ip4_table_index = ntohl (ip4_table_index);
9438 mp->ip6_table_index = ntohl (ip6_table_index);
9439 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009440 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009441
Dave Barach72d72232016-08-04 10:15:08 -04009442 S;
9443 W;
9444 /* NOTREACHED */
9445 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009446}
9447
Dave Barach72d72232016-08-04 10:15:08 -04009448static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009449api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009450{
Dave Barach72d72232016-08-04 10:15:08 -04009451 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009452 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009453 ip4_address_t collector_address;
9454 u8 collector_address_set = 0;
9455 u32 collector_port = ~0;
9456 ip4_address_t src_address;
9457 u8 src_address_set = 0;
9458 u32 vrf_id = ~0;
9459 u32 path_mtu = ~0;
9460 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009461 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009462 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009463
Dave Barach72d72232016-08-04 10:15:08 -04009464 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9465 {
9466 if (unformat (i, "collector_address %U", unformat_ip4_address,
9467 &collector_address))
9468 collector_address_set = 1;
9469 else if (unformat (i, "collector_port %d", &collector_port))
9470 ;
9471 else if (unformat (i, "src_address %U", unformat_ip4_address,
9472 &src_address))
9473 src_address_set = 1;
9474 else if (unformat (i, "vrf_id %d", &vrf_id))
9475 ;
9476 else if (unformat (i, "path_mtu %d", &path_mtu))
9477 ;
9478 else if (unformat (i, "template_interval %d", &template_interval))
9479 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009480 else if (unformat (i, "udp_checksum"))
9481 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009482 else
9483 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009484 }
9485
Dave Barach72d72232016-08-04 10:15:08 -04009486 if (collector_address_set == 0)
9487 {
9488 errmsg ("collector_address required\n");
9489 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009490 }
9491
Dave Barach72d72232016-08-04 10:15:08 -04009492 if (src_address_set == 0)
9493 {
9494 errmsg ("src_address required\n");
9495 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009496 }
9497
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009498 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009499
Dave Barach72d72232016-08-04 10:15:08 -04009500 memcpy (mp->collector_address, collector_address.data,
9501 sizeof (collector_address.data));
9502 mp->collector_port = htons ((u16) collector_port);
9503 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9504 mp->vrf_id = htonl (vrf_id);
9505 mp->path_mtu = htonl (path_mtu);
9506 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009507 mp->udp_checksum = udp_checksum;
9508
9509 S;
9510 W;
9511 /* NOTREACHED */
9512}
9513
9514static int
9515api_set_ipfix_classify_stream (vat_main_t * vam)
9516{
9517 unformat_input_t *i = vam->input;
9518 vl_api_set_ipfix_classify_stream_t *mp;
9519 u32 domain_id = 0;
9520 u32 src_port = UDP_DST_PORT_ipfix;
9521 f64 timeout;
9522
9523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9524 {
9525 if (unformat (i, "domain %d", &domain_id))
9526 ;
9527 else if (unformat (i, "src_port %d", &src_port))
9528 ;
9529 else
9530 {
9531 errmsg ("unknown input `%U'", format_unformat_error, i);
9532 return -99;
9533 }
9534 }
9535
9536 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9537
9538 mp->domain_id = htonl (domain_id);
9539 mp->src_port = htons ((u16) src_port);
9540
9541 S;
9542 W;
9543 /* NOTREACHED */
9544}
9545
9546static int
9547api_ipfix_classify_table_add_del (vat_main_t * vam)
9548{
9549 unformat_input_t *i = vam->input;
9550 vl_api_ipfix_classify_table_add_del_t *mp;
9551 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009552 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009553 u8 ip_version = 0;
9554 u8 transport_protocol = 255;
9555 f64 timeout;
9556
9557 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9558 {
9559 if (unformat (i, "add"))
9560 is_add = 1;
9561 else if (unformat (i, "del"))
9562 is_add = 0;
9563 else if (unformat (i, "table %d", &classify_table_index))
9564 ;
9565 else if (unformat (i, "ip4"))
9566 ip_version = 4;
9567 else if (unformat (i, "ip6"))
9568 ip_version = 6;
9569 else if (unformat (i, "tcp"))
9570 transport_protocol = 6;
9571 else if (unformat (i, "udp"))
9572 transport_protocol = 17;
9573 else
9574 {
9575 errmsg ("unknown input `%U'", format_unformat_error, i);
9576 return -99;
9577 }
9578 }
9579
9580 if (is_add == -1)
9581 {
9582 errmsg ("expecting: add|del");
9583 return -99;
9584 }
9585 if (classify_table_index == ~0)
9586 {
9587 errmsg ("classifier table not specified");
9588 return -99;
9589 }
9590 if (ip_version == 0)
9591 {
9592 errmsg ("IP version not specified");
9593 return -99;
9594 }
9595
9596 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9597
9598 mp->is_add = is_add;
9599 mp->table_id = htonl (classify_table_index);
9600 mp->ip_version = ip_version;
9601 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009602
Dave Barach72d72232016-08-04 10:15:08 -04009603 S;
9604 W;
9605 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009606}
9607
Dave Barach72d72232016-08-04 10:15:08 -04009608static int
9609api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009610{
Dave Barach72d72232016-08-04 10:15:08 -04009611 unformat_input_t *i = vam->input;
9612 vl_api_get_node_index_t *mp;
9613 f64 timeout;
9614 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009615
Dave Barach72d72232016-08-04 10:15:08 -04009616 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9617 {
9618 if (unformat (i, "node %s", &name))
9619 ;
9620 else
9621 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009622 }
Dave Barach72d72232016-08-04 10:15:08 -04009623 if (name == 0)
9624 {
9625 errmsg ("node name required\n");
9626 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009627 }
Dave Barach72d72232016-08-04 10:15:08 -04009628 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9629 {
9630 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9631 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009632 }
9633
Dave Barach72d72232016-08-04 10:15:08 -04009634 M (GET_NODE_INDEX, get_node_index);
9635 clib_memcpy (mp->node_name, name, vec_len (name));
9636 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009637
Dave Barach72d72232016-08-04 10:15:08 -04009638 S;
9639 W;
9640 /* NOTREACHED */
9641 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009642}
9643
Dave Barach72d72232016-08-04 10:15:08 -04009644static int
9645api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009646{
Dave Barach72d72232016-08-04 10:15:08 -04009647 unformat_input_t *i = vam->input;
9648 vl_api_get_next_index_t *mp;
9649 f64 timeout;
9650 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009651
Dave Barach72d72232016-08-04 10:15:08 -04009652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9653 {
9654 if (unformat (i, "node-name %s", &node_name))
9655 ;
9656 else if (unformat (i, "next-node-name %s", &next_node_name))
9657 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009658 }
9659
Dave Barach72d72232016-08-04 10:15:08 -04009660 if (node_name == 0)
9661 {
9662 errmsg ("node name required\n");
9663 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009664 }
Dave Barach72d72232016-08-04 10:15:08 -04009665 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9666 {
9667 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9668 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009669 }
9670
Dave Barach72d72232016-08-04 10:15:08 -04009671 if (next_node_name == 0)
9672 {
9673 errmsg ("next node name required\n");
9674 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009675 }
Dave Barach72d72232016-08-04 10:15:08 -04009676 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9677 {
9678 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9679 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009680 }
9681
Dave Barach72d72232016-08-04 10:15:08 -04009682 M (GET_NEXT_INDEX, get_next_index);
9683 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9684 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9685 vec_free (node_name);
9686 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009687
Dave Barach72d72232016-08-04 10:15:08 -04009688 S;
9689 W;
9690 /* NOTREACHED */
9691 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009692}
9693
Dave Barach72d72232016-08-04 10:15:08 -04009694static int
9695api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009696{
Dave Barach72d72232016-08-04 10:15:08 -04009697 unformat_input_t *i = vam->input;
9698 vl_api_add_node_next_t *mp;
9699 f64 timeout;
9700 u8 *name = 0;
9701 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009702
Dave Barach72d72232016-08-04 10:15:08 -04009703 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9704 {
9705 if (unformat (i, "node %s", &name))
9706 ;
9707 else if (unformat (i, "next %s", &next))
9708 ;
9709 else
9710 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009711 }
Dave Barach72d72232016-08-04 10:15:08 -04009712 if (name == 0)
9713 {
9714 errmsg ("node name required\n");
9715 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009716 }
Dave Barach72d72232016-08-04 10:15:08 -04009717 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9718 {
9719 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9720 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009721 }
Dave Barach72d72232016-08-04 10:15:08 -04009722 if (next == 0)
9723 {
9724 errmsg ("next node required\n");
9725 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009726 }
Dave Barach72d72232016-08-04 10:15:08 -04009727 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9728 {
9729 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9730 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009731 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009732
Dave Barach72d72232016-08-04 10:15:08 -04009733 M (ADD_NODE_NEXT, add_node_next);
9734 clib_memcpy (mp->node_name, name, vec_len (name));
9735 clib_memcpy (mp->next_name, next, vec_len (next));
9736 vec_free (name);
9737 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009738
Dave Barach72d72232016-08-04 10:15:08 -04009739 S;
9740 W;
9741 /* NOTREACHED */
9742 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009743}
9744
Dave Barach72d72232016-08-04 10:15:08 -04009745static int
9746api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009747{
Dave Barach72d72232016-08-04 10:15:08 -04009748 unformat_input_t *i = vam->input;
9749 ip6_address_t client_address, our_address;
9750 int client_address_set = 0;
9751 int our_address_set = 0;
9752 u32 local_session_id = 0;
9753 u32 remote_session_id = 0;
9754 u64 local_cookie = 0;
9755 u64 remote_cookie = 0;
9756 u8 l2_sublayer_present = 0;
9757 vl_api_l2tpv3_create_tunnel_t *mp;
9758 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009759
Dave Barach72d72232016-08-04 10:15:08 -04009760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9761 {
9762 if (unformat (i, "client_address %U", unformat_ip6_address,
9763 &client_address))
9764 client_address_set = 1;
9765 else if (unformat (i, "our_address %U", unformat_ip6_address,
9766 &our_address))
9767 our_address_set = 1;
9768 else if (unformat (i, "local_session_id %d", &local_session_id))
9769 ;
9770 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9771 ;
9772 else if (unformat (i, "local_cookie %lld", &local_cookie))
9773 ;
9774 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9775 ;
9776 else if (unformat (i, "l2-sublayer-present"))
9777 l2_sublayer_present = 1;
9778 else
9779 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009780 }
9781
Dave Barach72d72232016-08-04 10:15:08 -04009782 if (client_address_set == 0)
9783 {
9784 errmsg ("client_address required\n");
9785 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009786 }
9787
Dave Barach72d72232016-08-04 10:15:08 -04009788 if (our_address_set == 0)
9789 {
9790 errmsg ("our_address required\n");
9791 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009792 }
9793
Dave Barach72d72232016-08-04 10:15:08 -04009794 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009795
Dave Barach72d72232016-08-04 10:15:08 -04009796 clib_memcpy (mp->client_address, client_address.as_u8,
9797 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009798
Dave Barach72d72232016-08-04 10:15:08 -04009799 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009800
Dave Barach72d72232016-08-04 10:15:08 -04009801 mp->local_session_id = ntohl (local_session_id);
9802 mp->remote_session_id = ntohl (remote_session_id);
9803 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9804 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9805 mp->l2_sublayer_present = l2_sublayer_present;
9806 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009807
Dave Barach72d72232016-08-04 10:15:08 -04009808 S;
9809 W;
9810 /* NOTREACHED */
9811 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009812}
9813
Dave Barach72d72232016-08-04 10:15:08 -04009814static int
9815api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009816{
Dave Barach72d72232016-08-04 10:15:08 -04009817 unformat_input_t *i = vam->input;
9818 u32 sw_if_index;
9819 u8 sw_if_index_set = 0;
9820 u64 new_local_cookie = 0;
9821 u64 new_remote_cookie = 0;
9822 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9823 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009824
Dave Barach72d72232016-08-04 10:15:08 -04009825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9826 {
9827 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9828 sw_if_index_set = 1;
9829 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9830 sw_if_index_set = 1;
9831 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9832 ;
9833 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9834 ;
9835 else
9836 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009837 }
9838
Dave Barach72d72232016-08-04 10:15:08 -04009839 if (sw_if_index_set == 0)
9840 {
9841 errmsg ("missing interface name or sw_if_index\n");
9842 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009843 }
9844
Dave Barach72d72232016-08-04 10:15:08 -04009845 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009846
Dave Barach72d72232016-08-04 10:15:08 -04009847 mp->sw_if_index = ntohl (sw_if_index);
9848 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9849 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009850
Dave Barach72d72232016-08-04 10:15:08 -04009851 S;
9852 W;
9853 /* NOTREACHED */
9854 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009855}
9856
Dave Barach72d72232016-08-04 10:15:08 -04009857static int
9858api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009859{
Dave Barach72d72232016-08-04 10:15:08 -04009860 unformat_input_t *i = vam->input;
9861 vl_api_l2tpv3_interface_enable_disable_t *mp;
9862 f64 timeout;
9863 u32 sw_if_index;
9864 u8 sw_if_index_set = 0;
9865 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009866
Dave Barach72d72232016-08-04 10:15:08 -04009867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9868 {
9869 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9870 sw_if_index_set = 1;
9871 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9872 sw_if_index_set = 1;
9873 else if (unformat (i, "enable"))
9874 enable_disable = 1;
9875 else if (unformat (i, "disable"))
9876 enable_disable = 0;
9877 else
9878 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009879 }
9880
Dave Barach72d72232016-08-04 10:15:08 -04009881 if (sw_if_index_set == 0)
9882 {
9883 errmsg ("missing interface name or sw_if_index\n");
9884 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009885 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009886
Dave Barach72d72232016-08-04 10:15:08 -04009887 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009888
Dave Barach72d72232016-08-04 10:15:08 -04009889 mp->sw_if_index = ntohl (sw_if_index);
9890 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009891
Dave Barach72d72232016-08-04 10:15:08 -04009892 S;
9893 W;
9894 /* NOTREACHED */
9895 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009896}
9897
Dave Barach72d72232016-08-04 10:15:08 -04009898static int
9899api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009900{
Dave Barach72d72232016-08-04 10:15:08 -04009901 unformat_input_t *i = vam->input;
9902 vl_api_l2tpv3_set_lookup_key_t *mp;
9903 f64 timeout;
9904 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009905
Dave Barach72d72232016-08-04 10:15:08 -04009906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9907 {
9908 if (unformat (i, "lookup_v6_src"))
9909 key = L2T_LOOKUP_SRC_ADDRESS;
9910 else if (unformat (i, "lookup_v6_dst"))
9911 key = L2T_LOOKUP_DST_ADDRESS;
9912 else if (unformat (i, "lookup_session_id"))
9913 key = L2T_LOOKUP_SESSION_ID;
9914 else
9915 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009916 }
9917
Dave Barach72d72232016-08-04 10:15:08 -04009918 if (key == (u8) ~ 0)
9919 {
9920 errmsg ("l2tp session lookup key unset\n");
9921 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009922 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009923
Dave Barach72d72232016-08-04 10:15:08 -04009924 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009925
Dave Barach72d72232016-08-04 10:15:08 -04009926 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009927
Dave Barach72d72232016-08-04 10:15:08 -04009928 S;
9929 W;
9930 /* NOTREACHED */
9931 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009932}
9933
9934static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009935 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009936{
Dave Barach72d72232016-08-04 10:15:08 -04009937 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009938
Dave Barach72d72232016-08-04 10:15:08 -04009939 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9940 format_ip6_address, mp->our_address,
9941 format_ip6_address, mp->client_address,
9942 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009943
Dave Barach72d72232016-08-04 10:15:08 -04009944 fformat (vam->ofp,
9945 " local cookies %016llx %016llx remote cookie %016llx\n",
9946 clib_net_to_host_u64 (mp->local_cookie[0]),
9947 clib_net_to_host_u64 (mp->local_cookie[1]),
9948 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009949
Dave Barach72d72232016-08-04 10:15:08 -04009950 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9951 clib_net_to_host_u32 (mp->local_session_id),
9952 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009953
Dave Barach72d72232016-08-04 10:15:08 -04009954 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9955 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009956
9957}
9958
9959static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009960 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009961{
Dave Barach72d72232016-08-04 10:15:08 -04009962 vat_main_t *vam = &vat_main;
9963 vat_json_node_t *node = NULL;
9964 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009965
Dave Barach72d72232016-08-04 10:15:08 -04009966 if (VAT_JSON_ARRAY != vam->json_tree.type)
9967 {
9968 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9969 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009970 }
Dave Barach72d72232016-08-04 10:15:08 -04009971 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009972
Dave Barach72d72232016-08-04 10:15:08 -04009973 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009974
Dave Barach72d72232016-08-04 10:15:08 -04009975 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9976 vat_json_object_add_ip6 (node, "our_address", addr);
9977 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9978 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009979
Dave Barach72d72232016-08-04 10:15:08 -04009980 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9981 vat_json_init_array (lc);
9982 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9983 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9984 vat_json_object_add_uint (node, "remote_cookie",
9985 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009986
Dave Barach72d72232016-08-04 10:15:08 -04009987 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9988 vat_json_object_add_uint (node, "local_session_id",
9989 clib_net_to_host_u32 (mp->local_session_id));
9990 vat_json_object_add_uint (node, "remote_session_id",
9991 clib_net_to_host_u32 (mp->remote_session_id));
9992 vat_json_object_add_string_copy (node, "l2_sublayer",
9993 mp->l2_sublayer_present ? (u8 *) "present"
9994 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009995}
9996
Dave Barach72d72232016-08-04 10:15:08 -04009997static int
9998api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009999{
Dave Barach72d72232016-08-04 10:15:08 -040010000 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
10001 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010002
Dave Barach72d72232016-08-04 10:15:08 -040010003 /* Get list of l2tpv3-tunnel interfaces */
10004 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
10005 S;
10006
10007 /* Use a control ping for synchronization */
10008 {
10009 vl_api_control_ping_t *mp;
10010 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010011 S;
Dave Barach72d72232016-08-04 10:15:08 -040010012 }
10013 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010014}
10015
10016
10017static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010018 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010019{
Dave Barach72d72232016-08-04 10:15:08 -040010020 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010021
Dave Barach72d72232016-08-04 10:15:08 -040010022 fformat (vam->ofp, "%-16s %d\n",
10023 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010024}
10025
10026static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010027 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010028{
Dave Barach72d72232016-08-04 10:15:08 -040010029 vat_main_t *vam = &vat_main;
10030 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010031
Dave Barach72d72232016-08-04 10:15:08 -040010032 if (VAT_JSON_ARRAY != vam->json_tree.type)
10033 {
10034 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10035 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010036 }
Dave Barach72d72232016-08-04 10:15:08 -040010037 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010038
Dave Barach72d72232016-08-04 10:15:08 -040010039 vat_json_init_object (node);
10040 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10041 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010042}
10043
Dave Barach72d72232016-08-04 10:15:08 -040010044static int
10045api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010046{
Dave Barach72d72232016-08-04 10:15:08 -040010047 vl_api_sw_interface_tap_dump_t *mp;
10048 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010049
Dave Barach72d72232016-08-04 10:15:08 -040010050 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10051 /* Get list of tap interfaces */
10052 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10053 S;
10054
10055 /* Use a control ping for synchronization */
10056 {
10057 vl_api_control_ping_t *mp;
10058 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010059 S;
Dave Barach72d72232016-08-04 10:15:08 -040010060 }
10061 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010062}
10063
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010064static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010065 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010066{
Dave Barach72d72232016-08-04 10:15:08 -040010067 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010068 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010069
John Loc42912d2016-11-07 18:30:47 -050010070 if (unformat (input, "l2"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070010071 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10072 else if (unformat (input, "%d", &tmp))
10073 *result = tmp;
10074 else
10075 return 0;
10076 return 1;
10077}
10078
Dave Barach72d72232016-08-04 10:15:08 -040010079static int
10080api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010081{
Dave Barach72d72232016-08-04 10:15:08 -040010082 unformat_input_t *line_input = vam->input;
10083 vl_api_vxlan_add_del_tunnel_t *mp;
10084 f64 timeout;
10085 ip4_address_t src4, dst4;
10086 ip6_address_t src6, dst6;
10087 u8 is_add = 1;
10088 u8 ipv4_set = 0, ipv6_set = 0;
10089 u8 src_set = 0;
10090 u8 dst_set = 0;
10091 u32 encap_vrf_id = 0;
10092 u32 decap_next_index = ~0;
10093 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010094
Dave Barach72d72232016-08-04 10:15:08 -040010095 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10096 {
10097 if (unformat (line_input, "del"))
10098 is_add = 0;
10099 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10100 {
10101 ipv4_set = 1;
10102 src_set = 1;
10103 }
10104 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10105 {
10106 ipv4_set = 1;
10107 dst_set = 1;
10108 }
10109 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
10110 {
10111 ipv6_set = 1;
10112 src_set = 1;
10113 }
10114 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
10115 {
10116 ipv6_set = 1;
10117 dst_set = 1;
10118 }
10119 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10120 ;
10121 else if (unformat (line_input, "decap-next %U",
10122 unformat_vxlan_decap_next, &decap_next_index))
10123 ;
10124 else if (unformat (line_input, "vni %d", &vni))
10125 ;
10126 else
10127 {
10128 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10129 return -99;
10130 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010131 }
10132
Dave Barach72d72232016-08-04 10:15:08 -040010133 if (src_set == 0)
10134 {
10135 errmsg ("tunnel src address not specified\n");
10136 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010137 }
Dave Barach72d72232016-08-04 10:15:08 -040010138 if (dst_set == 0)
10139 {
10140 errmsg ("tunnel dst address not specified\n");
10141 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010142 }
10143
Dave Barach72d72232016-08-04 10:15:08 -040010144 if (ipv4_set && ipv6_set)
10145 {
10146 errmsg ("both IPv4 and IPv6 addresses specified");
10147 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010148 }
10149
Dave Barach72d72232016-08-04 10:15:08 -040010150 if ((vni == 0) || (vni >> 24))
10151 {
10152 errmsg ("vni not specified or out of range\n");
10153 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010154 }
10155
Dave Barach72d72232016-08-04 10:15:08 -040010156 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010157
Dave Barach72d72232016-08-04 10:15:08 -040010158 if (ipv6_set)
10159 {
10160 clib_memcpy (&mp->src_address, &src6, sizeof (src6));
10161 clib_memcpy (&mp->dst_address, &dst6, sizeof (dst6));
Chris Luke99cb3352016-04-26 10:49:53 -040010162 }
Dave Barach72d72232016-08-04 10:15:08 -040010163 else
10164 {
10165 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10166 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10167 }
10168 mp->encap_vrf_id = ntohl (encap_vrf_id);
10169 mp->decap_next_index = ntohl (decap_next_index);
10170 mp->vni = ntohl (vni);
10171 mp->is_add = is_add;
10172 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010173
Dave Barach72d72232016-08-04 10:15:08 -040010174 S;
10175 W;
10176 /* NOTREACHED */
10177 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010178}
10179
Dave Wallace60231f32015-12-17 21:04:30 -050010180static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010181 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010182{
Dave Barach72d72232016-08-04 10:15:08 -040010183 vat_main_t *vam = &vat_main;
Dave Wallace60231f32015-12-17 21:04:30 -050010184
Dave Barach72d72232016-08-04 10:15:08 -040010185 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
10186 ntohl (mp->sw_if_index),
10187 format_ip46_address, &(mp->src_address[0]),
10188 IP46_TYPE_ANY,
10189 format_ip46_address, &(mp->dst_address[0]),
10190 IP46_TYPE_ANY,
10191 ntohl (mp->encap_vrf_id),
10192 ntohl (mp->decap_next_index), ntohl (mp->vni));
Dave Wallace60231f32015-12-17 21:04:30 -050010193}
10194
10195static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010196 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010197{
Dave Barach72d72232016-08-04 10:15:08 -040010198 vat_main_t *vam = &vat_main;
10199 vat_json_node_t *node = NULL;
10200 struct in_addr ip4;
10201 struct in6_addr ip6;
Dave Wallace60231f32015-12-17 21:04:30 -050010202
Dave Barach72d72232016-08-04 10:15:08 -040010203 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010204 {
Dave Barach72d72232016-08-04 10:15:08 -040010205 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10206 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010207 }
Dave Barach72d72232016-08-04 10:15:08 -040010208 node = vat_json_array_add (&vam->json_tree);
10209
10210 vat_json_init_object (node);
10211 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10212 if (mp->is_ipv6)
10213 {
10214 clib_memcpy (&ip6, &(mp->src_address[0]), sizeof (ip6));
10215 vat_json_object_add_ip6 (node, "src_address", ip6);
10216 clib_memcpy (&ip6, &(mp->dst_address[0]), sizeof (ip6));
10217 vat_json_object_add_ip6 (node, "dst_address", ip6);
10218 }
10219 else
10220 {
10221 clib_memcpy (&ip4, &(mp->src_address[0]), sizeof (ip4));
10222 vat_json_object_add_ip4 (node, "src_address", ip4);
10223 clib_memcpy (&ip4, &(mp->dst_address[0]), sizeof (ip4));
10224 vat_json_object_add_ip4 (node, "dst_address", ip4);
10225 }
10226 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10227 vat_json_object_add_uint (node, "decap_next_index",
10228 ntohl (mp->decap_next_index));
10229 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10230 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Dave Wallace60231f32015-12-17 21:04:30 -050010231}
10232
Dave Barach72d72232016-08-04 10:15:08 -040010233static int
10234api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010235{
Dave Barach72d72232016-08-04 10:15:08 -040010236 unformat_input_t *i = vam->input;
10237 vl_api_vxlan_tunnel_dump_t *mp;
10238 f64 timeout;
10239 u32 sw_if_index;
10240 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010241
Dave Barach72d72232016-08-04 10:15:08 -040010242 /* Parse args required to build the message */
10243 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10244 {
10245 if (unformat (i, "sw_if_index %d", &sw_if_index))
10246 sw_if_index_set = 1;
10247 else
10248 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010249 }
10250
Dave Barach72d72232016-08-04 10:15:08 -040010251 if (sw_if_index_set == 0)
10252 {
10253 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010254 }
Dave Barach72d72232016-08-04 10:15:08 -040010255
10256 if (!vam->json_output)
10257 {
10258 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
10259 "sw_if_index", "src_address", "dst_address",
10260 "encap_vrf_id", "decap_next_index", "vni");
10261 }
10262
10263 /* Get list of vxlan-tunnel interfaces */
10264 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10265
10266 mp->sw_if_index = htonl (sw_if_index);
10267
10268 S;
10269
10270 /* Use a control ping for synchronization */
10271 {
10272 vl_api_control_ping_t *mp;
10273 M (CONTROL_PING, control_ping);
10274 S;
10275 }
10276 W;
10277}
10278
10279static int
10280api_gre_add_del_tunnel (vat_main_t * vam)
10281{
10282 unformat_input_t *line_input = vam->input;
10283 vl_api_gre_add_del_tunnel_t *mp;
10284 f64 timeout;
10285 ip4_address_t src4, dst4;
10286 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010287 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010288 u8 src_set = 0;
10289 u8 dst_set = 0;
10290 u32 outer_fib_id = 0;
10291
10292 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10293 {
10294 if (unformat (line_input, "del"))
10295 is_add = 0;
10296 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10297 src_set = 1;
10298 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10299 dst_set = 1;
10300 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10301 ;
David Hothama8cd3092016-09-19 09:55:07 -070010302 else if (unformat (line_input, "teb"))
10303 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010304 else
10305 {
10306 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10307 return -99;
10308 }
10309 }
10310
10311 if (src_set == 0)
10312 {
10313 errmsg ("tunnel src address not specified\n");
10314 return -99;
10315 }
10316 if (dst_set == 0)
10317 {
10318 errmsg ("tunnel dst address not specified\n");
10319 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010320 }
10321
10322
Dave Barach72d72232016-08-04 10:15:08 -040010323 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010324
Dave Barach72d72232016-08-04 10:15:08 -040010325 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10326 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10327 mp->outer_fib_id = ntohl (outer_fib_id);
10328 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010329 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010330
Dave Barach72d72232016-08-04 10:15:08 -040010331 S;
10332 W;
10333 /* NOTREACHED */
10334 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010335}
10336
10337static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010338 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010339{
Dave Barach72d72232016-08-04 10:15:08 -040010340 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010341
David Hothama8cd3092016-09-19 09:55:07 -070010342 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010343 ntohl (mp->sw_if_index),
10344 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010345 format_ip4_address, &mp->dst_address,
10346 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010347}
10348
10349static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010350 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010351{
Dave Barach72d72232016-08-04 10:15:08 -040010352 vat_main_t *vam = &vat_main;
10353 vat_json_node_t *node = NULL;
10354 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010355
Dave Barach72d72232016-08-04 10:15:08 -040010356 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010357 {
Dave Barach72d72232016-08-04 10:15:08 -040010358 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10359 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010360 }
Dave Barach72d72232016-08-04 10:15:08 -040010361 node = vat_json_array_add (&vam->json_tree);
10362
10363 vat_json_init_object (node);
10364 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10365 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10366 vat_json_object_add_ip4 (node, "src_address", ip4);
10367 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10368 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010369 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010370 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010371}
10372
Dave Barach72d72232016-08-04 10:15:08 -040010373static int
10374api_gre_tunnel_dump (vat_main_t * vam)
10375{
10376 unformat_input_t *i = vam->input;
10377 vl_api_gre_tunnel_dump_t *mp;
10378 f64 timeout;
10379 u32 sw_if_index;
10380 u8 sw_if_index_set = 0;
10381
10382 /* Parse args required to build the message */
10383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10384 {
10385 if (unformat (i, "sw_if_index %d", &sw_if_index))
10386 sw_if_index_set = 1;
10387 else
10388 break;
10389 }
10390
10391 if (sw_if_index_set == 0)
10392 {
10393 sw_if_index = ~0;
10394 }
10395
10396 if (!vam->json_output)
10397 {
David Hothama8cd3092016-09-19 09:55:07 -070010398 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10399 "sw_if_index", "src_address", "dst_address", "teb",
10400 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010401 }
10402
10403 /* Get list of gre-tunnel interfaces */
10404 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10405
10406 mp->sw_if_index = htonl (sw_if_index);
10407
10408 S;
10409
10410 /* Use a control ping for synchronization */
10411 {
10412 vl_api_control_ping_t *mp;
10413 M (CONTROL_PING, control_ping);
10414 S;
10415 }
10416 W;
10417}
10418
10419static int
10420api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010421{
10422// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010423 vl_api_l2_fib_clear_table_t *mp;
10424 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010425
Dave Barach72d72232016-08-04 10:15:08 -040010426 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010427
Dave Barach72d72232016-08-04 10:15:08 -040010428 S;
10429 W;
10430 /* NOTREACHED */
10431 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010432}
10433
Dave Barach72d72232016-08-04 10:15:08 -040010434static int
10435api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010436{
Dave Barach72d72232016-08-04 10:15:08 -040010437 unformat_input_t *i = vam->input;
10438 vl_api_l2_interface_efp_filter_t *mp;
10439 f64 timeout;
10440 u32 sw_if_index;
10441 u8 enable = 1;
10442 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010443
Dave Barach72d72232016-08-04 10:15:08 -040010444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10445 {
10446 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10447 sw_if_index_set = 1;
10448 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10449 sw_if_index_set = 1;
10450 else if (unformat (i, "enable"))
10451 enable = 1;
10452 else if (unformat (i, "disable"))
10453 enable = 0;
10454 else
10455 {
10456 clib_warning ("parse error '%U'", format_unformat_error, i);
10457 return -99;
10458 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010459 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010460
Dave Barach72d72232016-08-04 10:15:08 -040010461 if (sw_if_index_set == 0)
10462 {
10463 errmsg ("missing sw_if_index\n");
10464 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010465 }
10466
Dave Barach72d72232016-08-04 10:15:08 -040010467 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010468
Dave Barach72d72232016-08-04 10:15:08 -040010469 mp->sw_if_index = ntohl (sw_if_index);
10470 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010471
Dave Barach72d72232016-08-04 10:15:08 -040010472 S;
10473 W;
10474 /* NOTREACHED */
10475 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010476}
10477
10478#define foreach_vtr_op \
10479_("disable", L2_VTR_DISABLED) \
10480_("push-1", L2_VTR_PUSH_1) \
10481_("push-2", L2_VTR_PUSH_2) \
10482_("pop-1", L2_VTR_POP_1) \
10483_("pop-2", L2_VTR_POP_2) \
10484_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10485_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10486_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10487_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10488
Dave Barach72d72232016-08-04 10:15:08 -040010489static int
10490api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010491{
Dave Barach72d72232016-08-04 10:15:08 -040010492 unformat_input_t *i = vam->input;
10493 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10494 f64 timeout;
10495 u32 sw_if_index;
10496 u8 sw_if_index_set = 0;
10497 u8 vtr_op_set = 0;
10498 u32 vtr_op = 0;
10499 u32 push_dot1q = 1;
10500 u32 tag1 = ~0;
10501 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010502
Dave Barach72d72232016-08-04 10:15:08 -040010503 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10504 {
10505 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10506 sw_if_index_set = 1;
10507 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10508 sw_if_index_set = 1;
10509 else if (unformat (i, "vtr_op %d", &vtr_op))
10510 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010511#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010512 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010513#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010514 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10515 ;
10516 else if (unformat (i, "tag1 %d", &tag1))
10517 ;
10518 else if (unformat (i, "tag2 %d", &tag2))
10519 ;
10520 else
10521 {
10522 clib_warning ("parse error '%U'", format_unformat_error, i);
10523 return -99;
10524 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010525 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010526
Dave Barach72d72232016-08-04 10:15:08 -040010527 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
10528 {
10529 errmsg ("missing vtr operation or sw_if_index\n");
10530 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010531 }
10532
Dave Barach72d72232016-08-04 10:15:08 -040010533 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10534 mp->sw_if_index = ntohl (sw_if_index);
10535 mp->vtr_op = ntohl (vtr_op);
10536 mp->push_dot1q = ntohl (push_dot1q);
10537 mp->tag1 = ntohl (tag1);
10538 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010539
Dave Barach72d72232016-08-04 10:15:08 -040010540 S;
10541 W;
10542 /* NOTREACHED */
10543 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010544}
10545
Dave Barach72d72232016-08-04 10:15:08 -040010546static int
10547api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010548{
Dave Barach72d72232016-08-04 10:15:08 -040010549 unformat_input_t *i = vam->input;
10550 vl_api_create_vhost_user_if_t *mp;
10551 f64 timeout;
10552 u8 *file_name;
10553 u8 is_server = 0;
10554 u8 file_name_set = 0;
10555 u32 custom_dev_instance = ~0;
10556 u8 hwaddr[6];
10557 u8 use_custom_mac = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010558
Dave Barach75665d32016-11-17 11:36:59 -050010559 /* Shut up coverity */
10560 memset (hwaddr, 0, sizeof (hwaddr));
10561
Dave Barach72d72232016-08-04 10:15:08 -040010562 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10563 {
10564 if (unformat (i, "socket %s", &file_name))
10565 {
10566 file_name_set = 1;
10567 }
10568 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10569 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010570 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010571 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010572 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010573 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010574 else
Dave Barach72d72232016-08-04 10:15:08 -040010575 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010576 }
10577
Dave Barach72d72232016-08-04 10:15:08 -040010578 if (file_name_set == 0)
10579 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010580 errmsg ("missing socket file name\n");
10581 return -99;
10582 }
10583
Dave Barach72d72232016-08-04 10:15:08 -040010584 if (vec_len (file_name) > 255)
10585 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010586 errmsg ("socket file name too long\n");
10587 return -99;
10588 }
Dave Barach72d72232016-08-04 10:15:08 -040010589 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010590
Dave Barach72d72232016-08-04 10:15:08 -040010591 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010592
Dave Barach72d72232016-08-04 10:15:08 -040010593 mp->is_server = is_server;
10594 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10595 vec_free (file_name);
10596 if (custom_dev_instance != ~0)
10597 {
10598 mp->renumber = 1;
10599 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010600 }
Dave Barach72d72232016-08-04 10:15:08 -040010601 mp->use_custom_mac = use_custom_mac;
10602 clib_memcpy (mp->mac_address, hwaddr, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010603
Dave Barach72d72232016-08-04 10:15:08 -040010604 S;
10605 W;
10606 /* NOTREACHED */
10607 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010608}
10609
Dave Barach72d72232016-08-04 10:15:08 -040010610static int
10611api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010612{
Dave Barach72d72232016-08-04 10:15:08 -040010613 unformat_input_t *i = vam->input;
10614 vl_api_modify_vhost_user_if_t *mp;
10615 f64 timeout;
10616 u8 *file_name;
10617 u8 is_server = 0;
10618 u8 file_name_set = 0;
10619 u32 custom_dev_instance = ~0;
10620 u8 sw_if_index_set = 0;
10621 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010622
Dave Barach72d72232016-08-04 10:15:08 -040010623 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10624 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010625 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010626 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010627 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010628 sw_if_index_set = 1;
10629 else if (unformat (i, "socket %s", &file_name))
10630 {
10631 file_name_set = 1;
10632 }
10633 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10634 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010635 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010636 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010637 else
Dave Barach72d72232016-08-04 10:15:08 -040010638 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010639 }
10640
Dave Barach72d72232016-08-04 10:15:08 -040010641 if (sw_if_index_set == 0)
10642 {
10643 errmsg ("missing sw_if_index or interface name\n");
10644 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010645 }
10646
Dave Barach72d72232016-08-04 10:15:08 -040010647 if (file_name_set == 0)
10648 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010649 errmsg ("missing socket file name\n");
10650 return -99;
10651 }
10652
Dave Barach72d72232016-08-04 10:15:08 -040010653 if (vec_len (file_name) > 255)
10654 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010655 errmsg ("socket file name too long\n");
10656 return -99;
10657 }
Dave Barach72d72232016-08-04 10:15:08 -040010658 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010659
Dave Barach72d72232016-08-04 10:15:08 -040010660 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010661
Dave Barach72d72232016-08-04 10:15:08 -040010662 mp->sw_if_index = ntohl (sw_if_index);
10663 mp->is_server = is_server;
10664 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10665 vec_free (file_name);
10666 if (custom_dev_instance != ~0)
10667 {
10668 mp->renumber = 1;
10669 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010670 }
10671
Dave Barach72d72232016-08-04 10:15:08 -040010672 S;
10673 W;
10674 /* NOTREACHED */
10675 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010676}
10677
Dave Barach72d72232016-08-04 10:15:08 -040010678static int
10679api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010680{
Dave Barach72d72232016-08-04 10:15:08 -040010681 unformat_input_t *i = vam->input;
10682 vl_api_delete_vhost_user_if_t *mp;
10683 f64 timeout;
10684 u32 sw_if_index = ~0;
10685 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010686
Dave Barach72d72232016-08-04 10:15:08 -040010687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10688 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010689 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010690 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010691 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010692 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010693 else
Dave Barach72d72232016-08-04 10:15:08 -040010694 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010695 }
10696
Dave Barach72d72232016-08-04 10:15:08 -040010697 if (sw_if_index_set == 0)
10698 {
10699 errmsg ("missing sw_if_index or interface name\n");
10700 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010701 }
10702
10703
Dave Barach72d72232016-08-04 10:15:08 -040010704 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010705
Dave Barach72d72232016-08-04 10:15:08 -040010706 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010707
Dave Barach72d72232016-08-04 10:15:08 -040010708 S;
10709 W;
10710 /* NOTREACHED */
10711 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010712}
10713
10714static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010715 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010716{
Dave Barach72d72232016-08-04 10:15:08 -040010717 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010718
Dave Barach72d72232016-08-04 10:15:08 -040010719 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10720 (char *) mp->interface_name,
10721 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10722 clib_net_to_host_u64 (mp->features), mp->is_server,
10723 ntohl (mp->num_regions), (char *) mp->sock_filename);
10724 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010725}
10726
10727static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010728 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010729{
Dave Barach72d72232016-08-04 10:15:08 -040010730 vat_main_t *vam = &vat_main;
10731 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010732
Dave Barach72d72232016-08-04 10:15:08 -040010733 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010734 {
Dave Barach72d72232016-08-04 10:15:08 -040010735 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10736 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010737 }
Dave Barach72d72232016-08-04 10:15:08 -040010738 node = vat_json_array_add (&vam->json_tree);
10739
10740 vat_json_init_object (node);
10741 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10742 vat_json_object_add_string_copy (node, "interface_name",
10743 mp->interface_name);
10744 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10745 ntohl (mp->virtio_net_hdr_sz));
10746 vat_json_object_add_uint (node, "features",
10747 clib_net_to_host_u64 (mp->features));
10748 vat_json_object_add_uint (node, "is_server", mp->is_server);
10749 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10750 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10751 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010752}
10753
Dave Barach72d72232016-08-04 10:15:08 -040010754static int
10755api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010756{
Dave Barach72d72232016-08-04 10:15:08 -040010757 vl_api_sw_interface_vhost_user_dump_t *mp;
10758 f64 timeout;
10759 fformat (vam->ofp,
10760 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010761
Dave Barach72d72232016-08-04 10:15:08 -040010762 /* Get list of vhost-user interfaces */
10763 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10764 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010765
Dave Barach72d72232016-08-04 10:15:08 -040010766 /* Use a control ping for synchronization */
10767 {
10768 vl_api_control_ping_t *mp;
10769 M (CONTROL_PING, control_ping);
10770 S;
10771 }
10772 W;
10773}
10774
10775static int
10776api_show_version (vat_main_t * vam)
10777{
10778 vl_api_show_version_t *mp;
10779 f64 timeout;
10780
10781 M (SHOW_VERSION, show_version);
10782
10783 S;
10784 W;
10785 /* NOTREACHED */
10786 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010787}
10788
Ed Warnickecb9cada2015-12-08 15:45:58 -070010789
Dave Barach72d72232016-08-04 10:15:08 -040010790static int
10791api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010792{
Dave Barach72d72232016-08-04 10:15:08 -040010793 unformat_input_t *line_input = vam->input;
10794 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10795 f64 timeout;
10796 ip4_address_t local4, remote4;
10797 ip6_address_t local6, remote6;
10798 u8 is_add = 1;
10799 u8 ipv4_set = 0, ipv6_set = 0;
10800 u8 local_set = 0;
10801 u8 remote_set = 0;
10802 u32 encap_vrf_id = 0;
10803 u32 decap_vrf_id = 0;
10804 u8 protocol = ~0;
10805 u32 vni;
10806 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010807
Dave Barach72d72232016-08-04 10:15:08 -040010808 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10809 {
10810 if (unformat (line_input, "del"))
10811 is_add = 0;
10812 else if (unformat (line_input, "local %U",
10813 unformat_ip4_address, &local4))
10814 {
10815 local_set = 1;
10816 ipv4_set = 1;
10817 }
10818 else if (unformat (line_input, "remote %U",
10819 unformat_ip4_address, &remote4))
10820 {
10821 remote_set = 1;
10822 ipv4_set = 1;
10823 }
10824 else if (unformat (line_input, "local %U",
10825 unformat_ip6_address, &local6))
10826 {
10827 local_set = 1;
10828 ipv6_set = 1;
10829 }
10830 else if (unformat (line_input, "remote %U",
10831 unformat_ip6_address, &remote6))
10832 {
10833 remote_set = 1;
10834 ipv6_set = 1;
10835 }
10836 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10837 ;
10838 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10839 ;
10840 else if (unformat (line_input, "vni %d", &vni))
10841 vni_set = 1;
10842 else if (unformat (line_input, "next-ip4"))
10843 protocol = 1;
10844 else if (unformat (line_input, "next-ip6"))
10845 protocol = 2;
10846 else if (unformat (line_input, "next-ethernet"))
10847 protocol = 3;
10848 else if (unformat (line_input, "next-nsh"))
10849 protocol = 4;
10850 else
10851 {
10852 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10853 return -99;
10854 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010855 }
10856
Dave Barach72d72232016-08-04 10:15:08 -040010857 if (local_set == 0)
10858 {
10859 errmsg ("tunnel local address not specified\n");
10860 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010861 }
Dave Barach72d72232016-08-04 10:15:08 -040010862 if (remote_set == 0)
10863 {
10864 errmsg ("tunnel remote address not specified\n");
10865 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010866 }
Dave Barach72d72232016-08-04 10:15:08 -040010867 if (ipv4_set && ipv6_set)
10868 {
10869 errmsg ("both IPv4 and IPv6 addresses specified");
10870 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010871 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010872
Dave Barach72d72232016-08-04 10:15:08 -040010873 if (vni_set == 0)
10874 {
10875 errmsg ("vni not specified\n");
10876 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010877 }
10878
Dave Barach72d72232016-08-04 10:15:08 -040010879 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010880
Hongjun Nidf921cc2016-05-25 01:16:19 +080010881
Dave Barach72d72232016-08-04 10:15:08 -040010882 if (ipv6_set)
10883 {
10884 clib_memcpy (&mp->local, &local6, sizeof (local6));
10885 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10886 }
10887 else
10888 {
10889 clib_memcpy (&mp->local, &local4, sizeof (local4));
10890 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010891 }
10892
Dave Barach72d72232016-08-04 10:15:08 -040010893 mp->encap_vrf_id = ntohl (encap_vrf_id);
10894 mp->decap_vrf_id = ntohl (decap_vrf_id);
10895 mp->protocol = ntohl (protocol);
10896 mp->vni = ntohl (vni);
10897 mp->is_add = is_add;
10898 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010899
Dave Barach72d72232016-08-04 10:15:08 -040010900 S;
10901 W;
10902 /* NOTREACHED */
10903 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010904}
10905
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010906static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010907 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010908{
Dave Barach72d72232016-08-04 10:15:08 -040010909 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010910
Dave Barach72d72232016-08-04 10:15:08 -040010911 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10912 ntohl (mp->sw_if_index),
10913 format_ip46_address, &(mp->local[0]),
10914 format_ip46_address, &(mp->remote[0]),
10915 ntohl (mp->vni),
10916 ntohl (mp->protocol),
10917 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010918}
10919
10920static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010921 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010922{
Dave Barach72d72232016-08-04 10:15:08 -040010923 vat_main_t *vam = &vat_main;
10924 vat_json_node_t *node = NULL;
10925 struct in_addr ip4;
10926 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010927
Dave Barach72d72232016-08-04 10:15:08 -040010928 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010929 {
Dave Barach72d72232016-08-04 10:15:08 -040010930 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10931 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010932 }
Dave Barach72d72232016-08-04 10:15:08 -040010933 node = vat_json_array_add (&vam->json_tree);
10934
10935 vat_json_init_object (node);
10936 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10937 if (mp->is_ipv6)
10938 {
10939 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10940 vat_json_object_add_ip6 (node, "local", ip6);
10941 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10942 vat_json_object_add_ip6 (node, "remote", ip6);
10943 }
10944 else
10945 {
10946 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10947 vat_json_object_add_ip4 (node, "local", ip4);
10948 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10949 vat_json_object_add_ip4 (node, "remote", ip4);
10950 }
10951 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10952 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10953 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10954 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10955 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010956}
10957
Dave Barach72d72232016-08-04 10:15:08 -040010958static int
10959api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010960{
Dave Barach72d72232016-08-04 10:15:08 -040010961 unformat_input_t *i = vam->input;
10962 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10963 f64 timeout;
10964 u32 sw_if_index;
10965 u8 sw_if_index_set = 0;
10966
10967 /* Parse args required to build the message */
10968 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10969 {
10970 if (unformat (i, "sw_if_index %d", &sw_if_index))
10971 sw_if_index_set = 1;
10972 else
10973 break;
10974 }
10975
10976 if (sw_if_index_set == 0)
10977 {
10978 sw_if_index = ~0;
10979 }
10980
10981 if (!vam->json_output)
10982 {
10983 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
10984 "sw_if_index", "local", "remote", "vni",
10985 "protocol", "encap_vrf_id", "decap_vrf_id");
10986 }
10987
10988 /* Get list of vxlan-tunnel interfaces */
10989 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
10990
10991 mp->sw_if_index = htonl (sw_if_index);
10992
10993 S;
10994
10995 /* Use a control ping for synchronization */
10996 {
10997 vl_api_control_ping_t *mp;
10998 M (CONTROL_PING, control_ping);
10999 S;
11000 }
11001 W;
11002}
11003
11004u8 *
11005format_l2_fib_mac_address (u8 * s, va_list * args)
11006{
11007 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011008
11009 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011010 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011011}
11012
11013static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011014 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011015{
Dave Barach72d72232016-08-04 10:15:08 -040011016 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011017
Dave Barach72d72232016-08-04 10:15:08 -040011018 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11019 " %d %d %d\n",
11020 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11021 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11022 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011023}
11024
11025static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011026 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011027{
Dave Barach72d72232016-08-04 10:15:08 -040011028 vat_main_t *vam = &vat_main;
11029 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011030
Dave Barach72d72232016-08-04 10:15:08 -040011031 if (VAT_JSON_ARRAY != vam->json_tree.type)
11032 {
11033 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11034 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011035 }
Dave Barach72d72232016-08-04 10:15:08 -040011036 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011037
Dave Barach72d72232016-08-04 10:15:08 -040011038 vat_json_init_object (node);
11039 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11040 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11041 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11042 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11043 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11044 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011045}
11046
Dave Barach72d72232016-08-04 10:15:08 -040011047static int
11048api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011049{
Dave Barach72d72232016-08-04 10:15:08 -040011050 unformat_input_t *i = vam->input;
11051 vl_api_l2_fib_table_dump_t *mp;
11052 f64 timeout;
11053 u32 bd_id;
11054 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011055
Dave Barach72d72232016-08-04 10:15:08 -040011056 /* Parse args required to build the message */
11057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011058 {
Dave Barach72d72232016-08-04 10:15:08 -040011059 if (unformat (i, "bd_id %d", &bd_id))
11060 bd_id_set = 1;
11061 else
11062 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011063 }
Dave Barach72d72232016-08-04 10:15:08 -040011064
11065 if (bd_id_set == 0)
11066 {
11067 errmsg ("missing bridge domain\n");
11068 return -99;
11069 }
11070
11071 fformat (vam->ofp,
11072 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11073
11074 /* Get list of l2 fib entries */
11075 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11076
11077 mp->bd_id = ntohl (bd_id);
11078 S;
11079
11080 /* Use a control ping for synchronization */
11081 {
11082 vl_api_control_ping_t *mp;
11083 M (CONTROL_PING, control_ping);
11084 S;
11085 }
11086 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011087}
11088
11089
11090static int
11091api_interface_name_renumber (vat_main_t * vam)
11092{
Dave Barach72d72232016-08-04 10:15:08 -040011093 unformat_input_t *line_input = vam->input;
11094 vl_api_interface_name_renumber_t *mp;
11095 u32 sw_if_index = ~0;
11096 f64 timeout;
11097 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011098
Dave Barach72d72232016-08-04 10:15:08 -040011099 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11100 {
11101 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11102 &sw_if_index))
11103 ;
11104 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11105 ;
11106 else if (unformat (line_input, "new_show_dev_instance %d",
11107 &new_show_dev_instance))
11108 ;
11109 else
11110 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011111 }
11112
Dave Barach72d72232016-08-04 10:15:08 -040011113 if (sw_if_index == ~0)
11114 {
11115 errmsg ("missing interface name or sw_if_index\n");
11116 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011117 }
11118
Dave Barach72d72232016-08-04 10:15:08 -040011119 if (new_show_dev_instance == ~0)
11120 {
11121 errmsg ("missing new_show_dev_instance\n");
11122 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011123 }
11124
Dave Barach72d72232016-08-04 10:15:08 -040011125 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011126
Dave Barach72d72232016-08-04 10:15:08 -040011127 mp->sw_if_index = ntohl (sw_if_index);
11128 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011129
Dave Barach72d72232016-08-04 10:15:08 -040011130 S;
11131 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011132}
11133
11134static int
11135api_want_ip4_arp_events (vat_main_t * vam)
11136{
Dave Barach72d72232016-08-04 10:15:08 -040011137 unformat_input_t *line_input = vam->input;
11138 vl_api_want_ip4_arp_events_t *mp;
11139 f64 timeout;
11140 ip4_address_t address;
11141 int address_set = 0;
11142 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011143
Dave Barach72d72232016-08-04 10:15:08 -040011144 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11145 {
11146 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11147 address_set = 1;
11148 else if (unformat (line_input, "del"))
11149 enable_disable = 0;
11150 else
11151 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011152 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011153
Dave Barach72d72232016-08-04 10:15:08 -040011154 if (address_set == 0)
11155 {
11156 errmsg ("missing addresses\n");
11157 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011158 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011159
Dave Barach72d72232016-08-04 10:15:08 -040011160 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11161 mp->enable_disable = enable_disable;
11162 mp->pid = getpid ();
11163 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011164
Dave Barach72d72232016-08-04 10:15:08 -040011165 S;
11166 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011167}
11168
Dave Barach72d72232016-08-04 10:15:08 -040011169static int
John Lo1edfba92016-08-27 01:11:57 -040011170api_want_ip6_nd_events (vat_main_t * vam)
11171{
11172 unformat_input_t *line_input = vam->input;
11173 vl_api_want_ip6_nd_events_t *mp;
11174 f64 timeout;
11175 ip6_address_t address;
11176 int address_set = 0;
11177 u32 enable_disable = 1;
11178
11179 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11180 {
11181 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11182 address_set = 1;
11183 else if (unformat (line_input, "del"))
11184 enable_disable = 0;
11185 else
11186 break;
11187 }
11188
11189 if (address_set == 0)
11190 {
11191 errmsg ("missing addresses\n");
11192 return -99;
11193 }
11194
11195 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11196 mp->enable_disable = enable_disable;
11197 mp->pid = getpid ();
11198 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11199
11200 S;
11201 W;
11202}
11203
11204static int
Dave Barach72d72232016-08-04 10:15:08 -040011205api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011206{
Dave Barach72d72232016-08-04 10:15:08 -040011207 unformat_input_t *i = vam->input;
11208 vl_api_input_acl_set_interface_t *mp;
11209 f64 timeout;
11210 u32 sw_if_index;
11211 int sw_if_index_set;
11212 u32 ip4_table_index = ~0;
11213 u32 ip6_table_index = ~0;
11214 u32 l2_table_index = ~0;
11215 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011216
Dave Barach72d72232016-08-04 10:15:08 -040011217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11218 {
11219 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11220 sw_if_index_set = 1;
11221 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11222 sw_if_index_set = 1;
11223 else if (unformat (i, "del"))
11224 is_add = 0;
11225 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11226 ;
11227 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11228 ;
11229 else if (unformat (i, "l2-table %d", &l2_table_index))
11230 ;
11231 else
11232 {
11233 clib_warning ("parse error '%U'", format_unformat_error, i);
11234 return -99;
11235 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011236 }
11237
Dave Barach72d72232016-08-04 10:15:08 -040011238 if (sw_if_index_set == 0)
11239 {
11240 errmsg ("missing interface name or sw_if_index\n");
11241 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011242 }
11243
Dave Barach72d72232016-08-04 10:15:08 -040011244 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011245
Dave Barach72d72232016-08-04 10:15:08 -040011246 mp->sw_if_index = ntohl (sw_if_index);
11247 mp->ip4_table_index = ntohl (ip4_table_index);
11248 mp->ip6_table_index = ntohl (ip6_table_index);
11249 mp->l2_table_index = ntohl (l2_table_index);
11250 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011251
Dave Barach72d72232016-08-04 10:15:08 -040011252 S;
11253 W;
11254 /* NOTREACHED */
11255 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011256}
11257
11258static int
11259api_ip_address_dump (vat_main_t * vam)
11260{
Dave Barach72d72232016-08-04 10:15:08 -040011261 unformat_input_t *i = vam->input;
11262 vl_api_ip_address_dump_t *mp;
11263 u32 sw_if_index = ~0;
11264 u8 sw_if_index_set = 0;
11265 u8 ipv4_set = 0;
11266 u8 ipv6_set = 0;
11267 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011268
Dave Barach72d72232016-08-04 10:15:08 -040011269 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011270 {
Dave Barach72d72232016-08-04 10:15:08 -040011271 if (unformat (i, "sw_if_index %d", &sw_if_index))
11272 sw_if_index_set = 1;
11273 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11274 sw_if_index_set = 1;
11275 else if (unformat (i, "ipv4"))
11276 ipv4_set = 1;
11277 else if (unformat (i, "ipv6"))
11278 ipv6_set = 1;
11279 else
11280 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011281 }
Dave Barach72d72232016-08-04 10:15:08 -040011282
11283 if (ipv4_set && ipv6_set)
11284 {
11285 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11286 return -99;
11287 }
11288
11289 if ((!ipv4_set) && (!ipv6_set))
11290 {
11291 errmsg ("no ipv4 nor ipv6 flag set\n");
11292 return -99;
11293 }
11294
11295 if (sw_if_index_set == 0)
11296 {
11297 errmsg ("missing interface name or sw_if_index\n");
11298 return -99;
11299 }
11300
11301 vam->current_sw_if_index = sw_if_index;
11302 vam->is_ipv6 = ipv6_set;
11303
11304 M (IP_ADDRESS_DUMP, ip_address_dump);
11305 mp->sw_if_index = ntohl (sw_if_index);
11306 mp->is_ipv6 = ipv6_set;
11307 S;
11308
11309 /* Use a control ping for synchronization */
11310 {
11311 vl_api_control_ping_t *mp;
11312 M (CONTROL_PING, control_ping);
11313 S;
11314 }
11315 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011316}
11317
11318static int
11319api_ip_dump (vat_main_t * vam)
11320{
Dave Barach72d72232016-08-04 10:15:08 -040011321 vl_api_ip_dump_t *mp;
11322 unformat_input_t *in = vam->input;
11323 int ipv4_set = 0;
11324 int ipv6_set = 0;
11325 int is_ipv6;
11326 f64 timeout;
11327 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011328
Dave Barach72d72232016-08-04 10:15:08 -040011329 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011330 {
Dave Barach72d72232016-08-04 10:15:08 -040011331 if (unformat (in, "ipv4"))
11332 ipv4_set = 1;
11333 else if (unformat (in, "ipv6"))
11334 ipv6_set = 1;
11335 else
11336 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011337 }
Dave Barach72d72232016-08-04 10:15:08 -040011338
11339 if (ipv4_set && ipv6_set)
11340 {
11341 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11342 return -99;
11343 }
11344
11345 if ((!ipv4_set) && (!ipv6_set))
11346 {
11347 errmsg ("no ipv4 nor ipv6 flag set\n");
11348 return -99;
11349 }
11350
11351 is_ipv6 = ipv6_set;
11352 vam->is_ipv6 = is_ipv6;
11353
11354 /* free old data */
11355 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11356 {
11357 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11358 }
11359 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11360
11361 M (IP_DUMP, ip_dump);
11362 mp->is_ipv6 = ipv6_set;
11363 S;
11364
11365 /* Use a control ping for synchronization */
11366 {
11367 vl_api_control_ping_t *mp;
11368 M (CONTROL_PING, control_ping);
11369 S;
11370 }
11371 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011372}
11373
11374static int
11375api_ipsec_spd_add_del (vat_main_t * vam)
11376{
Dave Barach72d72232016-08-04 10:15:08 -040011377 unformat_input_t *i = vam->input;
11378 vl_api_ipsec_spd_add_del_t *mp;
11379 f64 timeout;
11380 u32 spd_id = ~0;
11381 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011382
Dave Barach72d72232016-08-04 10:15:08 -040011383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11384 {
11385 if (unformat (i, "spd_id %d", &spd_id))
11386 ;
11387 else if (unformat (i, "del"))
11388 is_add = 0;
11389 else
11390 {
11391 clib_warning ("parse error '%U'", format_unformat_error, i);
11392 return -99;
11393 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011394 }
Dave Barach72d72232016-08-04 10:15:08 -040011395 if (spd_id == ~0)
11396 {
11397 errmsg ("spd_id must be set\n");
11398 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011399 }
11400
Dave Barach72d72232016-08-04 10:15:08 -040011401 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011402
Dave Barach72d72232016-08-04 10:15:08 -040011403 mp->spd_id = ntohl (spd_id);
11404 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011405
Dave Barach72d72232016-08-04 10:15:08 -040011406 S;
11407 W;
11408 /* NOTREACHED */
11409 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011410}
11411
11412static int
11413api_ipsec_interface_add_del_spd (vat_main_t * vam)
11414{
Dave Barach72d72232016-08-04 10:15:08 -040011415 unformat_input_t *i = vam->input;
11416 vl_api_ipsec_interface_add_del_spd_t *mp;
11417 f64 timeout;
11418 u32 sw_if_index;
11419 u8 sw_if_index_set = 0;
11420 u32 spd_id = (u32) ~ 0;
11421 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011422
Dave Barach72d72232016-08-04 10:15:08 -040011423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11424 {
11425 if (unformat (i, "del"))
11426 is_add = 0;
11427 else if (unformat (i, "spd_id %d", &spd_id))
11428 ;
11429 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11430 sw_if_index_set = 1;
11431 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11432 sw_if_index_set = 1;
11433 else
11434 {
11435 clib_warning ("parse error '%U'", format_unformat_error, i);
11436 return -99;
11437 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011438
11439 }
11440
Dave Barach72d72232016-08-04 10:15:08 -040011441 if (spd_id == (u32) ~ 0)
11442 {
11443 errmsg ("spd_id must be set\n");
11444 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011445 }
11446
Dave Barach72d72232016-08-04 10:15:08 -040011447 if (sw_if_index_set == 0)
11448 {
11449 errmsg ("missing interface name or sw_if_index\n");
11450 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011451 }
11452
Dave Barach72d72232016-08-04 10:15:08 -040011453 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011454
Dave Barach72d72232016-08-04 10:15:08 -040011455 mp->spd_id = ntohl (spd_id);
11456 mp->sw_if_index = ntohl (sw_if_index);
11457 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011458
Dave Barach72d72232016-08-04 10:15:08 -040011459 S;
11460 W;
11461 /* NOTREACHED */
11462 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011463}
11464
11465static int
11466api_ipsec_spd_add_del_entry (vat_main_t * vam)
11467{
Dave Barach72d72232016-08-04 10:15:08 -040011468 unformat_input_t *i = vam->input;
11469 vl_api_ipsec_spd_add_del_entry_t *mp;
11470 f64 timeout;
11471 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011472 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011473 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011474 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11475 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11476 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11477 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011478
Dave Barach72d72232016-08-04 10:15:08 -040011479 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11480 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11481 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11482 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11483 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11484 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011485
Dave Barach72d72232016-08-04 10:15:08 -040011486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11487 {
11488 if (unformat (i, "del"))
11489 is_add = 0;
11490 if (unformat (i, "outbound"))
11491 is_outbound = 1;
11492 if (unformat (i, "inbound"))
11493 is_outbound = 0;
11494 else if (unformat (i, "spd_id %d", &spd_id))
11495 ;
11496 else if (unformat (i, "sa_id %d", &sa_id))
11497 ;
11498 else if (unformat (i, "priority %d", &priority))
11499 ;
11500 else if (unformat (i, "protocol %d", &protocol))
11501 ;
11502 else if (unformat (i, "lport_start %d", &lport_start))
11503 ;
11504 else if (unformat (i, "lport_stop %d", &lport_stop))
11505 ;
11506 else if (unformat (i, "rport_start %d", &rport_start))
11507 ;
11508 else if (unformat (i, "rport_stop %d", &rport_stop))
11509 ;
11510 else
11511 if (unformat
11512 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11513 {
11514 is_ipv6 = 0;
11515 is_ip_any = 0;
11516 }
11517 else
11518 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11519 {
11520 is_ipv6 = 0;
11521 is_ip_any = 0;
11522 }
11523 else
11524 if (unformat
11525 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11526 {
11527 is_ipv6 = 0;
11528 is_ip_any = 0;
11529 }
11530 else
11531 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11532 {
11533 is_ipv6 = 0;
11534 is_ip_any = 0;
11535 }
11536 else
11537 if (unformat
11538 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11539 {
11540 is_ipv6 = 1;
11541 is_ip_any = 0;
11542 }
11543 else
11544 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11545 {
11546 is_ipv6 = 1;
11547 is_ip_any = 0;
11548 }
11549 else
11550 if (unformat
11551 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11552 {
11553 is_ipv6 = 1;
11554 is_ip_any = 0;
11555 }
11556 else
11557 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11558 {
11559 is_ipv6 = 1;
11560 is_ip_any = 0;
11561 }
11562 else
11563 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11564 {
11565 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11566 {
11567 clib_warning ("unsupported action: 'resolve'");
11568 return -99;
11569 }
11570 }
11571 else
11572 {
11573 clib_warning ("parse error '%U'", format_unformat_error, i);
11574 return -99;
11575 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011576
11577 }
11578
Dave Barach72d72232016-08-04 10:15:08 -040011579 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011580
Dave Barach72d72232016-08-04 10:15:08 -040011581 mp->spd_id = ntohl (spd_id);
11582 mp->priority = ntohl (priority);
11583 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011584
Dave Barach72d72232016-08-04 10:15:08 -040011585 mp->is_ipv6 = is_ipv6;
11586 if (is_ipv6 || is_ip_any)
11587 {
11588 clib_memcpy (mp->remote_address_start, &raddr6_start,
11589 sizeof (ip6_address_t));
11590 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11591 sizeof (ip6_address_t));
11592 clib_memcpy (mp->local_address_start, &laddr6_start,
11593 sizeof (ip6_address_t));
11594 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11595 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011596 }
Dave Barach72d72232016-08-04 10:15:08 -040011597 else
11598 {
11599 clib_memcpy (mp->remote_address_start, &raddr4_start,
11600 sizeof (ip4_address_t));
11601 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11602 sizeof (ip4_address_t));
11603 clib_memcpy (mp->local_address_start, &laddr4_start,
11604 sizeof (ip4_address_t));
11605 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11606 sizeof (ip4_address_t));
11607 }
11608 mp->protocol = (u8) protocol;
11609 mp->local_port_start = ntohs ((u16) lport_start);
11610 mp->local_port_stop = ntohs ((u16) lport_stop);
11611 mp->remote_port_start = ntohs ((u16) rport_start);
11612 mp->remote_port_stop = ntohs ((u16) rport_stop);
11613 mp->policy = (u8) policy;
11614 mp->sa_id = ntohl (sa_id);
11615 mp->is_add = is_add;
11616 mp->is_ip_any = is_ip_any;
11617 S;
11618 W;
11619 /* NOTREACHED */
11620 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011621}
11622
11623static int
11624api_ipsec_sad_add_del_entry (vat_main_t * vam)
11625{
Dave Barach72d72232016-08-04 10:15:08 -040011626 unformat_input_t *i = vam->input;
11627 vl_api_ipsec_sad_add_del_entry_t *mp;
11628 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011629 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011630 u8 *ck = 0, *ik = 0;
11631 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011632
Dave Barach72d72232016-08-04 10:15:08 -040011633 u8 protocol = IPSEC_PROTOCOL_AH;
11634 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11635 u32 crypto_alg = 0, integ_alg = 0;
11636 ip4_address_t tun_src4;
11637 ip4_address_t tun_dst4;
11638 ip6_address_t tun_src6;
11639 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011640
Dave Barach72d72232016-08-04 10:15:08 -040011641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11642 {
11643 if (unformat (i, "del"))
11644 is_add = 0;
11645 else if (unformat (i, "sad_id %d", &sad_id))
11646 ;
11647 else if (unformat (i, "spi %d", &spi))
11648 ;
11649 else if (unformat (i, "esp"))
11650 protocol = IPSEC_PROTOCOL_ESP;
11651 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11652 {
11653 is_tunnel = 1;
11654 is_tunnel_ipv6 = 0;
11655 }
11656 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11657 {
11658 is_tunnel = 1;
11659 is_tunnel_ipv6 = 0;
11660 }
11661 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11662 {
11663 is_tunnel = 1;
11664 is_tunnel_ipv6 = 1;
11665 }
11666 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11667 {
11668 is_tunnel = 1;
11669 is_tunnel_ipv6 = 1;
11670 }
11671 else
11672 if (unformat
11673 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11674 {
11675 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
11676 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256)
11677 {
11678 clib_warning ("unsupported crypto-alg: '%U'",
11679 format_ipsec_crypto_alg, crypto_alg);
11680 return -99;
11681 }
11682 }
11683 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11684 ;
11685 else
11686 if (unformat
11687 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11688 {
11689 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
11690 integ_alg > IPSEC_INTEG_ALG_SHA_512_256)
11691 {
11692 clib_warning ("unsupported integ-alg: '%U'",
11693 format_ipsec_integ_alg, integ_alg);
11694 return -99;
11695 }
11696 }
11697 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11698 ;
11699 else
11700 {
11701 clib_warning ("parse error '%U'", format_unformat_error, i);
11702 return -99;
11703 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011704
11705 }
11706
Dave Barach72d72232016-08-04 10:15:08 -040011707 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011708
Dave Barach72d72232016-08-04 10:15:08 -040011709 mp->sad_id = ntohl (sad_id);
11710 mp->is_add = is_add;
11711 mp->protocol = protocol;
11712 mp->spi = ntohl (spi);
11713 mp->is_tunnel = is_tunnel;
11714 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11715 mp->crypto_algorithm = crypto_alg;
11716 mp->integrity_algorithm = integ_alg;
11717 mp->crypto_key_length = vec_len (ck);
11718 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011719
Dave Barach72d72232016-08-04 10:15:08 -040011720 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11721 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011722
Dave Barach72d72232016-08-04 10:15:08 -040011723 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11724 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011725
Dave Barach839fe3e2016-08-10 11:35:54 -040011726 if (ck)
11727 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11728 if (ik)
11729 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011730
Dave Barach72d72232016-08-04 10:15:08 -040011731 if (is_tunnel)
11732 {
11733 if (is_tunnel_ipv6)
11734 {
11735 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11736 sizeof (ip6_address_t));
11737 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11738 sizeof (ip6_address_t));
11739 }
11740 else
11741 {
11742 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11743 sizeof (ip4_address_t));
11744 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11745 sizeof (ip4_address_t));
11746 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011747 }
11748
Dave Barach72d72232016-08-04 10:15:08 -040011749 S;
11750 W;
11751 /* NOTREACHED */
11752 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011753}
11754
11755static int
11756api_ipsec_sa_set_key (vat_main_t * vam)
11757{
Dave Barach72d72232016-08-04 10:15:08 -040011758 unformat_input_t *i = vam->input;
11759 vl_api_ipsec_sa_set_key_t *mp;
11760 f64 timeout;
11761 u32 sa_id;
11762 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011763
Dave Barach72d72232016-08-04 10:15:08 -040011764 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11765 {
11766 if (unformat (i, "sa_id %d", &sa_id))
11767 ;
11768 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11769 ;
11770 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11771 ;
11772 else
11773 {
11774 clib_warning ("parse error '%U'", format_unformat_error, i);
11775 return -99;
11776 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011777 }
11778
Dave Barach72d72232016-08-04 10:15:08 -040011779 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011780
Dave Barach72d72232016-08-04 10:15:08 -040011781 mp->sa_id = ntohl (sa_id);
11782 mp->crypto_key_length = vec_len (ck);
11783 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011784
Dave Barach72d72232016-08-04 10:15:08 -040011785 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11786 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011787
Dave Barach72d72232016-08-04 10:15:08 -040011788 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11789 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011790
Dave Barach839fe3e2016-08-10 11:35:54 -040011791 if (ck)
11792 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11793 if (ik)
11794 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011795
Dave Barach72d72232016-08-04 10:15:08 -040011796 S;
11797 W;
11798 /* NOTREACHED */
11799 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011800}
11801
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011802static int
11803api_ikev2_profile_add_del (vat_main_t * vam)
11804{
Dave Barach72d72232016-08-04 10:15:08 -040011805 unformat_input_t *i = vam->input;
11806 vl_api_ikev2_profile_add_del_t *mp;
11807 f64 timeout;
11808 u8 is_add = 1;
11809 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011810
Dave Barach72d72232016-08-04 10:15:08 -040011811 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011812
Dave Barach72d72232016-08-04 10:15:08 -040011813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11814 {
11815 if (unformat (i, "del"))
11816 is_add = 0;
11817 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11818 vec_add1 (name, 0);
11819 else
11820 {
11821 errmsg ("parse error '%U'", format_unformat_error, i);
11822 return -99;
11823 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011824 }
11825
Dave Barach72d72232016-08-04 10:15:08 -040011826 if (!vec_len (name))
11827 {
11828 errmsg ("profile name must be specified");
11829 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011830 }
11831
Dave Barach72d72232016-08-04 10:15:08 -040011832 if (vec_len (name) > 64)
11833 {
11834 errmsg ("profile name too long");
11835 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011836 }
11837
Dave Barach72d72232016-08-04 10:15:08 -040011838 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011839
Dave Barach72d72232016-08-04 10:15:08 -040011840 clib_memcpy (mp->name, name, vec_len (name));
11841 mp->is_add = is_add;
11842 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011843
Dave Barach72d72232016-08-04 10:15:08 -040011844 S;
11845 W;
11846 /* NOTREACHED */
11847 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011848}
11849
11850static int
11851api_ikev2_profile_set_auth (vat_main_t * vam)
11852{
Dave Barach72d72232016-08-04 10:15:08 -040011853 unformat_input_t *i = vam->input;
11854 vl_api_ikev2_profile_set_auth_t *mp;
11855 f64 timeout;
11856 u8 *name = 0;
11857 u8 *data = 0;
11858 u32 auth_method = 0;
11859 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011860
Dave Barach72d72232016-08-04 10:15:08 -040011861 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011862
Dave Barach72d72232016-08-04 10:15:08 -040011863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11864 {
11865 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11866 vec_add1 (name, 0);
11867 else if (unformat (i, "auth_method %U",
11868 unformat_ikev2_auth_method, &auth_method))
11869 ;
11870 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11871 is_hex = 1;
11872 else if (unformat (i, "auth_data %v", &data))
11873 ;
11874 else
11875 {
11876 errmsg ("parse error '%U'", format_unformat_error, i);
11877 return -99;
11878 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011879 }
11880
Dave Barach72d72232016-08-04 10:15:08 -040011881 if (!vec_len (name))
11882 {
11883 errmsg ("profile name must be specified");
11884 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011885 }
11886
Dave Barach72d72232016-08-04 10:15:08 -040011887 if (vec_len (name) > 64)
11888 {
11889 errmsg ("profile name too long");
11890 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011891 }
11892
Dave Barach72d72232016-08-04 10:15:08 -040011893 if (!vec_len (data))
11894 {
11895 errmsg ("auth_data must be specified");
11896 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011897 }
11898
Dave Barach72d72232016-08-04 10:15:08 -040011899 if (!auth_method)
11900 {
11901 errmsg ("auth_method must be specified");
11902 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011903 }
11904
Dave Barach72d72232016-08-04 10:15:08 -040011905 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011906
Dave Barach72d72232016-08-04 10:15:08 -040011907 mp->is_hex = is_hex;
11908 mp->auth_method = (u8) auth_method;
11909 mp->data_len = vec_len (data);
11910 clib_memcpy (mp->name, name, vec_len (name));
11911 clib_memcpy (mp->data, data, vec_len (data));
11912 vec_free (name);
11913 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011914
Dave Barach72d72232016-08-04 10:15:08 -040011915 S;
11916 W;
11917 /* NOTREACHED */
11918 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011919}
11920
11921static int
11922api_ikev2_profile_set_id (vat_main_t * vam)
11923{
Dave Barach72d72232016-08-04 10:15:08 -040011924 unformat_input_t *i = vam->input;
11925 vl_api_ikev2_profile_set_id_t *mp;
11926 f64 timeout;
11927 u8 *name = 0;
11928 u8 *data = 0;
11929 u8 is_local = 0;
11930 u32 id_type = 0;
11931 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011932
Dave Barach72d72232016-08-04 10:15:08 -040011933 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011934
Dave Barach72d72232016-08-04 10:15:08 -040011935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11936 {
11937 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11938 vec_add1 (name, 0);
11939 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
11940 ;
11941 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
11942 {
11943 data = vec_new (u8, 4);
11944 clib_memcpy (data, ip4.as_u8, 4);
11945 }
11946 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
11947 ;
11948 else if (unformat (i, "id_data %v", &data))
11949 ;
11950 else if (unformat (i, "local"))
11951 is_local = 1;
11952 else if (unformat (i, "remote"))
11953 is_local = 0;
11954 else
11955 {
11956 errmsg ("parse error '%U'", format_unformat_error, i);
11957 return -99;
11958 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011959 }
11960
Dave Barach72d72232016-08-04 10:15:08 -040011961 if (!vec_len (name))
11962 {
11963 errmsg ("profile name must be specified");
11964 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011965 }
11966
Dave Barach72d72232016-08-04 10:15:08 -040011967 if (vec_len (name) > 64)
11968 {
11969 errmsg ("profile name too long");
11970 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011971 }
11972
Dave Barach72d72232016-08-04 10:15:08 -040011973 if (!vec_len (data))
11974 {
11975 errmsg ("id_data must be specified");
11976 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011977 }
11978
Dave Barach72d72232016-08-04 10:15:08 -040011979 if (!id_type)
11980 {
11981 errmsg ("id_type must be specified");
11982 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011983 }
11984
Dave Barach72d72232016-08-04 10:15:08 -040011985 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011986
Dave Barach72d72232016-08-04 10:15:08 -040011987 mp->is_local = is_local;
11988 mp->id_type = (u8) id_type;
11989 mp->data_len = vec_len (data);
11990 clib_memcpy (mp->name, name, vec_len (name));
11991 clib_memcpy (mp->data, data, vec_len (data));
11992 vec_free (name);
11993 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011994
Dave Barach72d72232016-08-04 10:15:08 -040011995 S;
11996 W;
11997 /* NOTREACHED */
11998 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011999}
12000
12001static int
12002api_ikev2_profile_set_ts (vat_main_t * vam)
12003{
Dave Barach72d72232016-08-04 10:15:08 -040012004 unformat_input_t *i = vam->input;
12005 vl_api_ikev2_profile_set_ts_t *mp;
12006 f64 timeout;
12007 u8 *name = 0;
12008 u8 is_local = 0;
12009 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12010 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012011
Dave Barach72d72232016-08-04 10:15:08 -040012012 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012013
Dave Barach72d72232016-08-04 10:15:08 -040012014 start_addr.as_u32 = 0;
12015 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012016
Dave Barach72d72232016-08-04 10:15:08 -040012017 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12018 {
12019 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12020 vec_add1 (name, 0);
12021 else if (unformat (i, "protocol %d", &proto))
12022 ;
12023 else if (unformat (i, "start_port %d", &start_port))
12024 ;
12025 else if (unformat (i, "end_port %d", &end_port))
12026 ;
12027 else
12028 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12029 ;
12030 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12031 ;
12032 else if (unformat (i, "local"))
12033 is_local = 1;
12034 else if (unformat (i, "remote"))
12035 is_local = 0;
12036 else
12037 {
12038 errmsg ("parse error '%U'", format_unformat_error, i);
12039 return -99;
12040 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012041 }
12042
Dave Barach72d72232016-08-04 10:15:08 -040012043 if (!vec_len (name))
12044 {
12045 errmsg ("profile name must be specified");
12046 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012047 }
12048
Dave Barach72d72232016-08-04 10:15:08 -040012049 if (vec_len (name) > 64)
12050 {
12051 errmsg ("profile name too long");
12052 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012053 }
12054
Dave Barach72d72232016-08-04 10:15:08 -040012055 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012056
Dave Barach72d72232016-08-04 10:15:08 -040012057 mp->is_local = is_local;
12058 mp->proto = (u8) proto;
12059 mp->start_port = (u16) start_port;
12060 mp->end_port = (u16) end_port;
12061 mp->start_addr = start_addr.as_u32;
12062 mp->end_addr = end_addr.as_u32;
12063 clib_memcpy (mp->name, name, vec_len (name));
12064 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012065
Dave Barach72d72232016-08-04 10:15:08 -040012066 S;
12067 W;
12068 /* NOTREACHED */
12069 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012070}
12071
12072static int
12073api_ikev2_set_local_key (vat_main_t * vam)
12074{
Dave Barach72d72232016-08-04 10:15:08 -040012075 unformat_input_t *i = vam->input;
12076 vl_api_ikev2_set_local_key_t *mp;
12077 f64 timeout;
12078 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012079
Dave Barach72d72232016-08-04 10:15:08 -040012080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12081 {
12082 if (unformat (i, "file %v", &file))
12083 vec_add1 (file, 0);
12084 else
12085 {
12086 errmsg ("parse error '%U'", format_unformat_error, i);
12087 return -99;
12088 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012089 }
12090
Dave Barach72d72232016-08-04 10:15:08 -040012091 if (!vec_len (file))
12092 {
12093 errmsg ("RSA key file must be specified");
12094 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012095 }
12096
Dave Barach72d72232016-08-04 10:15:08 -040012097 if (vec_len (file) > 256)
12098 {
12099 errmsg ("file name too long");
12100 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012101 }
12102
Dave Barach72d72232016-08-04 10:15:08 -040012103 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012104
Dave Barach72d72232016-08-04 10:15:08 -040012105 clib_memcpy (mp->key_file, file, vec_len (file));
12106 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012107
Dave Barach72d72232016-08-04 10:15:08 -040012108 S;
12109 W;
12110 /* NOTREACHED */
12111 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012112}
12113
Ed Warnickecb9cada2015-12-08 15:45:58 -070012114/*
12115 * MAP
12116 */
Dave Barach72d72232016-08-04 10:15:08 -040012117static int
12118api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012119{
12120 unformat_input_t *i = vam->input;
12121 vl_api_map_add_domain_t *mp;
12122 f64 timeout;
12123
12124 ip4_address_t ip4_prefix;
12125 ip6_address_t ip6_prefix;
12126 ip6_address_t ip6_src;
12127 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012128 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12129 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012130 u8 is_translation = 0;
12131 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012132 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012133
Dave Barach72d72232016-08-04 10:15:08 -040012134 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12135 {
12136 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12137 &ip4_prefix, &ip4_prefix_len))
12138 num_m_args++;
12139 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12140 &ip6_prefix, &ip6_prefix_len))
12141 num_m_args++;
12142 else
12143 if (unformat
12144 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12145 &ip6_src_len))
12146 num_m_args++;
12147 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12148 num_m_args++;
12149 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12150 num_m_args++;
12151 else if (unformat (i, "psid-offset %d", &psid_offset))
12152 num_m_args++;
12153 else if (unformat (i, "psid-len %d", &psid_length))
12154 num_m_args++;
12155 else if (unformat (i, "mtu %d", &mtu))
12156 num_m_args++;
12157 else if (unformat (i, "map-t"))
12158 is_translation = 1;
12159 else
12160 {
12161 clib_warning ("parse error '%U'", format_unformat_error, i);
12162 return -99;
12163 }
12164 }
12165
Ole Troan07e7eab2016-08-25 00:24:08 +020012166 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012167 {
12168 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012169 return -99;
12170 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012171
12172 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012173 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012174
Dave Barach72d72232016-08-04 10:15:08 -040012175 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012176 mp->ip4_prefix_len = ip4_prefix_len;
12177
Dave Barach72d72232016-08-04 10:15:08 -040012178 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012179 mp->ip6_prefix_len = ip6_prefix_len;
12180
Dave Barach72d72232016-08-04 10:15:08 -040012181 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012182 mp->ip6_src_prefix_len = ip6_src_len;
12183
12184 mp->ea_bits_len = ea_bits_len;
12185 mp->psid_offset = psid_offset;
12186 mp->psid_length = psid_length;
12187 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012188 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012189
12190 /* send it... */
12191 S;
12192
12193 /* Wait for a reply, return good/bad news */
12194 W;
12195}
12196
Dave Barach72d72232016-08-04 10:15:08 -040012197static int
12198api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012199{
12200 unformat_input_t *i = vam->input;
12201 vl_api_map_del_domain_t *mp;
12202 f64 timeout;
12203
12204 u32 num_m_args = 0;
12205 u32 index;
12206
Dave Barach72d72232016-08-04 10:15:08 -040012207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12208 {
12209 if (unformat (i, "index %d", &index))
12210 num_m_args++;
12211 else
12212 {
12213 clib_warning ("parse error '%U'", format_unformat_error, i);
12214 return -99;
12215 }
12216 }
12217
12218 if (num_m_args != 1)
12219 {
12220 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012221 return -99;
12222 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012223
12224 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012225 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012226
Dave Barach72d72232016-08-04 10:15:08 -040012227 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012228
12229 /* send it... */
12230 S;
12231
12232 /* Wait for a reply, return good/bad news */
12233 W;
12234}
12235
Dave Barach72d72232016-08-04 10:15:08 -040012236static int
12237api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012238{
12239 unformat_input_t *i = vam->input;
12240 vl_api_map_add_del_rule_t *mp;
12241 f64 timeout;
12242 u8 is_add = 1;
12243 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012244 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012245
Dave Barach72d72232016-08-04 10:15:08 -040012246 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12247 {
12248 if (unformat (i, "index %d", &index))
12249 num_m_args++;
12250 else if (unformat (i, "psid %d", &psid))
12251 num_m_args++;
12252 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12253 num_m_args++;
12254 else if (unformat (i, "del"))
12255 {
12256 is_add = 0;
12257 }
12258 else
12259 {
12260 clib_warning ("parse error '%U'", format_unformat_error, i);
12261 return -99;
12262 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012263 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012264
12265 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012266 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012267
Dave Barach72d72232016-08-04 10:15:08 -040012268 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012269 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012270 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12271 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012272
12273 /* send it... */
12274 S;
12275
12276 /* Wait for a reply, return good/bad news */
12277 W;
12278}
12279
Dave Barach72d72232016-08-04 10:15:08 -040012280static int
12281api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012282{
Dave Barach72d72232016-08-04 10:15:08 -040012283 vl_api_map_domain_dump_t *mp;
12284 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012285
Dave Barach72d72232016-08-04 10:15:08 -040012286 /* Construct the API message */
12287 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012288
Dave Barach72d72232016-08-04 10:15:08 -040012289 /* send it... */
12290 S;
12291
12292 /* Use a control ping for synchronization */
12293 {
12294 vl_api_control_ping_t *mp;
12295 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012296 S;
Dave Barach72d72232016-08-04 10:15:08 -040012297 }
12298 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012299}
12300
Dave Barach72d72232016-08-04 10:15:08 -040012301static int
12302api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012303{
Dave Barach72d72232016-08-04 10:15:08 -040012304 unformat_input_t *i = vam->input;
12305 vl_api_map_rule_dump_t *mp;
12306 f64 timeout;
12307 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012308
Dave Barach72d72232016-08-04 10:15:08 -040012309 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012310 {
Dave Barach72d72232016-08-04 10:15:08 -040012311 if (unformat (i, "index %u", &domain_index))
12312 ;
12313 else
12314 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012315 }
Dave Barach72d72232016-08-04 10:15:08 -040012316
12317 if (domain_index == ~0)
12318 {
12319 clib_warning ("parse error: domain index expected");
12320 return -99;
12321 }
12322
12323 /* Construct the API message */
12324 M (MAP_RULE_DUMP, map_rule_dump);
12325
12326 mp->domain_index = htonl (domain_index);
12327
12328 /* send it... */
12329 S;
12330
12331 /* Use a control ping for synchronization */
12332 {
12333 vl_api_control_ping_t *mp;
12334 M (CONTROL_PING, control_ping);
12335 S;
12336 }
12337 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012338}
12339
12340static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012341 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012342{
Dave Barach72d72232016-08-04 10:15:08 -040012343 vat_main_t *vam = &vat_main;
12344 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012345
Dave Barach72d72232016-08-04 10:15:08 -040012346 if (vam->async_mode)
12347 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012348 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012349 }
12350 else
12351 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012352 vam->retval = retval;
12353 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012354 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012355}
12356
12357static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012358 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012359{
Dave Barach72d72232016-08-04 10:15:08 -040012360 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012361 vat_json_node_t node;
12362
Dave Barach72d72232016-08-04 10:15:08 -040012363 vat_json_init_object (&node);
12364 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12365 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012366
Dave Barach72d72232016-08-04 10:15:08 -040012367 vat_json_print (vam->ofp, &node);
12368 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012369
Dave Barach72d72232016-08-04 10:15:08 -040012370 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012371 vam->result_ready = 1;
12372}
12373
12374static int
12375api_get_first_msg_id (vat_main_t * vam)
12376{
Dave Barach72d72232016-08-04 10:15:08 -040012377 vl_api_get_first_msg_id_t *mp;
12378 f64 timeout;
12379 unformat_input_t *i = vam->input;
12380 u8 *name;
12381 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012382
Dave Barach72d72232016-08-04 10:15:08 -040012383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12384 {
12385 if (unformat (i, "client %s", &name))
12386 name_set = 1;
12387 else
12388 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012389 }
12390
Dave Barach72d72232016-08-04 10:15:08 -040012391 if (name_set == 0)
12392 {
12393 errmsg ("missing client name\n");
12394 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012395 }
Dave Barach72d72232016-08-04 10:15:08 -040012396 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012397
Dave Barach72d72232016-08-04 10:15:08 -040012398 if (vec_len (name) > 63)
12399 {
12400 errmsg ("client name too long\n");
12401 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012402 }
12403
Dave Barach72d72232016-08-04 10:15:08 -040012404 M (GET_FIRST_MSG_ID, get_first_msg_id);
12405 clib_memcpy (mp->name, name, vec_len (name));
12406 S;
12407 W;
12408 /* NOTREACHED */
12409 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012410}
12411
Dave Barach72d72232016-08-04 10:15:08 -040012412static int
12413api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012414{
Dave Barach72d72232016-08-04 10:15:08 -040012415 unformat_input_t *line_input = vam->input;
12416 vl_api_cop_interface_enable_disable_t *mp;
12417 f64 timeout;
12418 u32 sw_if_index = ~0;
12419 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012420
Dave Barach72d72232016-08-04 10:15:08 -040012421 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12422 {
12423 if (unformat (line_input, "disable"))
12424 enable_disable = 0;
12425 if (unformat (line_input, "enable"))
12426 enable_disable = 1;
12427 else if (unformat (line_input, "%U", unformat_sw_if_index,
12428 vam, &sw_if_index))
12429 ;
12430 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12431 ;
12432 else
12433 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012434 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012435
Dave Barach72d72232016-08-04 10:15:08 -040012436 if (sw_if_index == ~0)
12437 {
12438 errmsg ("missing interface name or sw_if_index\n");
12439 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012440 }
12441
Dave Barach72d72232016-08-04 10:15:08 -040012442 /* Construct the API message */
12443 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12444 mp->sw_if_index = ntohl (sw_if_index);
12445 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012446
Dave Barach72d72232016-08-04 10:15:08 -040012447 /* send it... */
12448 S;
12449 /* Wait for the reply */
12450 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012451}
12452
Dave Barach72d72232016-08-04 10:15:08 -040012453static int
12454api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012455{
Dave Barach72d72232016-08-04 10:15:08 -040012456 unformat_input_t *line_input = vam->input;
12457 vl_api_cop_whitelist_enable_disable_t *mp;
12458 f64 timeout;
12459 u32 sw_if_index = ~0;
12460 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012461 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012462
Dave Barach72d72232016-08-04 10:15:08 -040012463 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12464 {
12465 if (unformat (line_input, "ip4"))
12466 ip4 = 1;
12467 else if (unformat (line_input, "ip6"))
12468 ip6 = 1;
12469 else if (unformat (line_input, "default"))
12470 default_cop = 1;
12471 else if (unformat (line_input, "%U", unformat_sw_if_index,
12472 vam, &sw_if_index))
12473 ;
12474 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12475 ;
12476 else if (unformat (line_input, "fib-id %d", &fib_id))
12477 ;
12478 else
12479 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012480 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012481
Dave Barach72d72232016-08-04 10:15:08 -040012482 if (sw_if_index == ~0)
12483 {
12484 errmsg ("missing interface name or sw_if_index\n");
12485 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012486 }
12487
Dave Barach72d72232016-08-04 10:15:08 -040012488 /* Construct the API message */
12489 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12490 mp->sw_if_index = ntohl (sw_if_index);
12491 mp->fib_id = ntohl (fib_id);
12492 mp->ip4 = ip4;
12493 mp->ip6 = ip6;
12494 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012495
Dave Barach72d72232016-08-04 10:15:08 -040012496 /* send it... */
12497 S;
12498 /* Wait for the reply */
12499 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012500}
12501
Dave Barach72d72232016-08-04 10:15:08 -040012502static int
12503api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012504{
Dave Barach72d72232016-08-04 10:15:08 -040012505 vl_api_get_node_graph_t *mp;
12506 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012507
Dave Barach72d72232016-08-04 10:15:08 -040012508 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012509
Dave Barach72d72232016-08-04 10:15:08 -040012510 /* send it... */
12511 S;
12512 /* Wait for the reply */
12513 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012514}
12515
Dave Barach72d72232016-08-04 10:15:08 -040012516/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012517/** Used for parsing LISP eids */
12518typedef CLIB_PACKED(struct{
12519 u8 addr[16]; /**< eid address */
12520 u32 len; /**< prefix length if IP */
12521 u8 type; /**< type of eid */
12522}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012523/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012524
12525static uword
12526unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12527{
Dave Barach72d72232016-08-04 10:15:08 -040012528 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012529
Dave Barach72d72232016-08-04 10:15:08 -040012530 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012531
Dave Barach72d72232016-08-04 10:15:08 -040012532 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12533 {
12534 a->type = 0; /* ipv4 type */
12535 }
12536 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12537 {
12538 a->type = 1; /* ipv6 type */
12539 }
12540 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12541 {
12542 a->type = 2; /* mac type */
12543 }
12544 else
12545 {
Florin Coras429e7952016-08-02 02:31:03 +020012546 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012547 }
Florin Coras429e7952016-08-02 02:31:03 +020012548
Dave Barach72d72232016-08-04 10:15:08 -040012549 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12550 {
Florin Coras429e7952016-08-02 02:31:03 +020012551 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012552 }
Florin Coras429e7952016-08-02 02:31:03 +020012553
12554 return 1;
12555}
12556
12557static int
12558lisp_eid_size_vat (u8 type)
12559{
Dave Barach72d72232016-08-04 10:15:08 -040012560 switch (type)
12561 {
Florin Coras429e7952016-08-02 02:31:03 +020012562 case 0:
12563 return 4;
12564 case 1:
12565 return 16;
12566 case 2:
12567 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012568 }
Florin Coras429e7952016-08-02 02:31:03 +020012569 return 0;
12570}
12571
12572static void
12573lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12574{
Dave Barach72d72232016-08-04 10:15:08 -040012575 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012576}
12577
Dave Barach72d72232016-08-04 10:15:08 -040012578/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012579/** Used for transferring locators via VPP API */
12580typedef CLIB_PACKED(struct
12581{
Dave Barach72d72232016-08-04 10:15:08 -040012582 u32 sw_if_index; /**< locator sw_if_index */
12583 u8 priority; /**< locator priority */
12584 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012585}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012586/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012587
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012588static int
Dave Barach72d72232016-08-04 10:15:08 -040012589api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012590{
Dave Barach72d72232016-08-04 10:15:08 -040012591 unformat_input_t *input = vam->input;
12592 vl_api_lisp_add_del_locator_set_t *mp;
12593 f64 timeout = ~0;
12594 u8 is_add = 1;
12595 u8 *locator_set_name = NULL;
12596 u8 locator_set_name_set = 0;
12597 ls_locator_t locator, *locators = 0;
12598 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012599 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012600
Dave Barach72d72232016-08-04 10:15:08 -040012601 /* Parse args required to build the message */
12602 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12603 {
12604 if (unformat (input, "del"))
12605 {
12606 is_add = 0;
12607 }
12608 else if (unformat (input, "locator-set %s", &locator_set_name))
12609 {
12610 locator_set_name_set = 1;
12611 }
12612 else if (unformat (input, "sw_if_index %u p %u w %u",
12613 &sw_if_index, &priority, &weight))
12614 {
12615 locator.sw_if_index = htonl (sw_if_index);
12616 locator.priority = priority;
12617 locator.weight = weight;
12618 vec_add1 (locators, locator);
12619 }
12620 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12621 vam, &sw_if_index, &priority, &weight))
12622 {
12623 locator.sw_if_index = htonl (sw_if_index);
12624 locator.priority = priority;
12625 locator.weight = weight;
12626 vec_add1 (locators, locator);
12627 }
12628 else
12629 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012630 }
12631
Dave Barach72d72232016-08-04 10:15:08 -040012632 if (locator_set_name_set == 0)
12633 {
12634 errmsg ("missing locator-set name");
12635 vec_free (locators);
12636 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012637 }
12638
Dave Barach72d72232016-08-04 10:15:08 -040012639 if (vec_len (locator_set_name) > 64)
12640 {
12641 errmsg ("locator-set name too long\n");
12642 vec_free (locator_set_name);
12643 vec_free (locators);
12644 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012645 }
Dave Barach72d72232016-08-04 10:15:08 -040012646 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012647
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012648 data_len = sizeof (ls_locator_t) * vec_len (locators);
12649
Dave Barach72d72232016-08-04 10:15:08 -040012650 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012651 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012652
Dave Barach72d72232016-08-04 10:15:08 -040012653 mp->is_add = is_add;
12654 clib_memcpy (mp->locator_set_name, locator_set_name,
12655 vec_len (locator_set_name));
12656 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012657
Filip Tehlare3552c42016-08-26 12:44:38 +020012658 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012659 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012660 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012661 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012662
Dave Barach72d72232016-08-04 10:15:08 -040012663 /* send it... */
12664 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012665
Dave Barach72d72232016-08-04 10:15:08 -040012666 /* Wait for a reply... */
12667 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012668
Dave Barach72d72232016-08-04 10:15:08 -040012669 /* NOTREACHED */
12670 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012671}
12672
12673static int
Dave Barach72d72232016-08-04 10:15:08 -040012674api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012675{
Dave Barach72d72232016-08-04 10:15:08 -040012676 unformat_input_t *input = vam->input;
12677 vl_api_lisp_add_del_locator_t *mp;
12678 f64 timeout = ~0;
12679 u32 tmp_if_index = ~0;
12680 u32 sw_if_index = ~0;
12681 u8 sw_if_index_set = 0;
12682 u8 sw_if_index_if_name_set = 0;
12683 u32 priority = ~0;
12684 u8 priority_set = 0;
12685 u32 weight = ~0;
12686 u8 weight_set = 0;
12687 u8 is_add = 1;
12688 u8 *locator_set_name = NULL;
12689 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012690
Dave Barach72d72232016-08-04 10:15:08 -040012691 /* Parse args required to build the message */
12692 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12693 {
12694 if (unformat (input, "del"))
12695 {
12696 is_add = 0;
12697 }
12698 else if (unformat (input, "locator-set %s", &locator_set_name))
12699 {
12700 locator_set_name_set = 1;
12701 }
12702 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12703 &tmp_if_index))
12704 {
12705 sw_if_index_if_name_set = 1;
12706 sw_if_index = tmp_if_index;
12707 }
12708 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12709 {
12710 sw_if_index_set = 1;
12711 sw_if_index = tmp_if_index;
12712 }
12713 else if (unformat (input, "p %d", &priority))
12714 {
12715 priority_set = 1;
12716 }
12717 else if (unformat (input, "w %d", &weight))
12718 {
12719 weight_set = 1;
12720 }
12721 else
12722 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012723 }
12724
Dave Barach72d72232016-08-04 10:15:08 -040012725 if (locator_set_name_set == 0)
12726 {
12727 errmsg ("missing locator-set name");
12728 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012729 }
12730
Dave Barach72d72232016-08-04 10:15:08 -040012731 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12732 {
12733 errmsg ("missing sw_if_index");
12734 vec_free (locator_set_name);
12735 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012736 }
12737
Dave Barach72d72232016-08-04 10:15:08 -040012738 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12739 {
12740 errmsg ("cannot use both params interface name and sw_if_index");
12741 vec_free (locator_set_name);
12742 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012743 }
12744
Dave Barach72d72232016-08-04 10:15:08 -040012745 if (priority_set == 0)
12746 {
12747 errmsg ("missing locator-set priority\n");
12748 vec_free (locator_set_name);
12749 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012750 }
12751
Dave Barach72d72232016-08-04 10:15:08 -040012752 if (weight_set == 0)
12753 {
12754 errmsg ("missing locator-set weight\n");
12755 vec_free (locator_set_name);
12756 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012757 }
12758
Dave Barach72d72232016-08-04 10:15:08 -040012759 if (vec_len (locator_set_name) > 64)
12760 {
12761 errmsg ("locator-set name too long\n");
12762 vec_free (locator_set_name);
12763 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012764 }
Dave Barach72d72232016-08-04 10:15:08 -040012765 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012766
Dave Barach72d72232016-08-04 10:15:08 -040012767 /* Construct the API message */
12768 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012769
Dave Barach72d72232016-08-04 10:15:08 -040012770 mp->is_add = is_add;
12771 mp->sw_if_index = ntohl (sw_if_index);
12772 mp->priority = priority;
12773 mp->weight = weight;
12774 clib_memcpy (mp->locator_set_name, locator_set_name,
12775 vec_len (locator_set_name));
12776 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012777
Dave Barach72d72232016-08-04 10:15:08 -040012778 /* send it... */
12779 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012780
Dave Barach72d72232016-08-04 10:15:08 -040012781 /* Wait for a reply... */
12782 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012783
Dave Barach72d72232016-08-04 10:15:08 -040012784 /* NOTREACHED */
12785 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012786}
12787
12788static int
Dave Barach72d72232016-08-04 10:15:08 -040012789api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012790{
Dave Barach72d72232016-08-04 10:15:08 -040012791 unformat_input_t *input = vam->input;
12792 vl_api_lisp_add_del_local_eid_t *mp;
12793 f64 timeout = ~0;
12794 u8 is_add = 1;
12795 u8 eid_set = 0;
12796 lisp_eid_vat_t _eid, *eid = &_eid;
12797 u8 *locator_set_name = 0;
12798 u8 locator_set_name_set = 0;
12799 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012800
Dave Barach72d72232016-08-04 10:15:08 -040012801 /* Parse args required to build the message */
12802 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12803 {
12804 if (unformat (input, "del"))
12805 {
12806 is_add = 0;
12807 }
12808 else if (unformat (input, "vni %d", &vni))
12809 {
12810 ;
12811 }
12812 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12813 {
12814 eid_set = 1;
12815 }
12816 else if (unformat (input, "locator-set %s", &locator_set_name))
12817 {
12818 locator_set_name_set = 1;
12819 }
12820 else
12821 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012822 }
12823
Dave Barach72d72232016-08-04 10:15:08 -040012824 if (locator_set_name_set == 0)
12825 {
12826 errmsg ("missing locator-set name\n");
12827 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012828 }
12829
Dave Barach72d72232016-08-04 10:15:08 -040012830 if (0 == eid_set)
12831 {
12832 errmsg ("EID address not set!");
12833 vec_free (locator_set_name);
12834 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012835 }
12836
Dave Barach72d72232016-08-04 10:15:08 -040012837 if (vec_len (locator_set_name) > 64)
12838 {
12839 errmsg ("locator-set name too long\n");
12840 vec_free (locator_set_name);
12841 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012842 }
Dave Barach72d72232016-08-04 10:15:08 -040012843 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012844
Dave Barach72d72232016-08-04 10:15:08 -040012845 /* Construct the API message */
12846 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012847
Dave Barach72d72232016-08-04 10:15:08 -040012848 mp->is_add = is_add;
12849 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12850 mp->eid_type = eid->type;
12851 mp->prefix_len = eid->len;
12852 mp->vni = clib_host_to_net_u32 (vni);
12853 clib_memcpy (mp->locator_set_name, locator_set_name,
12854 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012855
Dave Barach72d72232016-08-04 10:15:08 -040012856 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012857
Dave Barach72d72232016-08-04 10:15:08 -040012858 /* send it... */
12859 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012860
Dave Barach72d72232016-08-04 10:15:08 -040012861 /* Wait for a reply... */
12862 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012863
Dave Barach72d72232016-08-04 10:15:08 -040012864 /* NOTREACHED */
12865 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012866}
12867
Dave Barach72d72232016-08-04 10:15:08 -040012868/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012869/** Used for transferring locators via VPP API */
12870typedef CLIB_PACKED(struct
12871{
Dave Barach72d72232016-08-04 10:15:08 -040012872 u8 is_ip4; /**< is locator an IPv4 address? */
12873 u8 priority; /**< locator priority */
12874 u8 weight; /**< locator weight */
12875 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012876}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012877/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012878
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012879static int
Dave Barach72d72232016-08-04 10:15:08 -040012880api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012881{
Dave Barach72d72232016-08-04 10:15:08 -040012882 unformat_input_t *input = vam->input;
12883 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12884 f64 timeout = ~0;
12885 u8 is_add = 1;
12886 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12887 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12888 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12889 u32 action = ~0, p, w;
12890 ip4_address_t rmt_rloc4, lcl_rloc4;
12891 ip6_address_t rmt_rloc6, lcl_rloc6;
12892 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012893
Dave Barach839fe3e2016-08-10 11:35:54 -040012894 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012895
Dave Barach72d72232016-08-04 10:15:08 -040012896 /* Parse args required to build the message */
12897 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12898 {
12899 if (unformat (input, "del"))
12900 {
12901 is_add = 0;
12902 }
12903 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12904 {
12905 rmt_eid_set = 1;
12906 }
12907 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12908 {
12909 lcl_eid_set = 1;
12910 }
12911 else if (unformat (input, "p %d w %d", &p, &w))
12912 {
12913 if (!curr_rloc)
12914 {
12915 errmsg ("No RLOC configured for setting priority/weight!");
12916 return -99;
12917 }
12918 curr_rloc->priority = p;
12919 curr_rloc->weight = w;
12920 }
12921 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12922 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12923 {
12924 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012925
Dave Barach72d72232016-08-04 10:15:08 -040012926 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012927 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012928 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012929
Dave Barach72d72232016-08-04 10:15:08 -040012930 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12931 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012932 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012933 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12934 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012935 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012936 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12937 {
12938 rloc.is_ip4 = 0;
12939 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020012940 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012941 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012942
Dave Barach72d72232016-08-04 10:15:08 -040012943 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
12944 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012945 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012946 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12947 }
12948 else if (unformat (input, "action %d", &action))
12949 {
12950 ;
12951 }
12952 else
12953 {
12954 clib_warning ("parse error '%U'", format_unformat_error, input);
12955 return -99;
12956 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012957 }
12958
Dave Barach72d72232016-08-04 10:15:08 -040012959 if (!rmt_eid_set)
12960 {
12961 errmsg ("remote eid addresses not set\n");
12962 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012963 }
12964
Dave Barach72d72232016-08-04 10:15:08 -040012965 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
12966 {
12967 errmsg ("eid types don't match\n");
12968 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012969 }
12970
Dave Barach839fe3e2016-08-10 11:35:54 -040012971 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020012972 {
12973 errmsg ("action not set for negative mapping\n");
12974 return -99;
12975 }
12976
Dave Barach72d72232016-08-04 10:15:08 -040012977 /* Construct the API message */
12978 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012979
Dave Barach72d72232016-08-04 10:15:08 -040012980 mp->is_add = is_add;
12981 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
12982 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
12983 mp->eid_type = rmt_eid->type;
12984 mp->rmt_len = rmt_eid->len;
12985 mp->lcl_len = lcl_eid->len;
12986 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020012987
Florin Coras7fbfad32016-08-05 16:57:33 +020012988 if (0 != rmt_locs && 0 != lcl_locs)
12989 {
Dave Barach839fe3e2016-08-10 11:35:54 -040012990 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020012991 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012992 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012993 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040012994 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020012995 }
Dave Barach72d72232016-08-04 10:15:08 -040012996 vec_free (lcl_locs);
12997 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012998
Dave Barach72d72232016-08-04 10:15:08 -040012999 /* send it... */
13000 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013001
Dave Barach72d72232016-08-04 10:15:08 -040013002 /* Wait for a reply... */
13003 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013004
Dave Barach72d72232016-08-04 10:15:08 -040013005 /* NOTREACHED */
13006 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013007}
13008
13009static int
Dave Barach72d72232016-08-04 10:15:08 -040013010api_lisp_add_del_map_resolver (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_map_resolver_t *mp;
13014 f64 timeout = ~0;
13015 u8 is_add = 1;
13016 u8 ipv4_set = 0;
13017 u8 ipv6_set = 0;
13018 ip4_address_t ipv4;
13019 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013020
Dave Barach72d72232016-08-04 10:15:08 -040013021 /* Parse args required to build the message */
13022 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13023 {
13024 if (unformat (input, "del"))
13025 {
13026 is_add = 0;
13027 }
13028 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13029 {
13030 ipv4_set = 1;
13031 }
13032 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13033 {
13034 ipv6_set = 1;
13035 }
13036 else
13037 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013038 }
13039
Dave Barach72d72232016-08-04 10:15:08 -040013040 if (ipv4_set && ipv6_set)
13041 {
13042 errmsg ("both eid v4 and v6 addresses set\n");
13043 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013044 }
13045
Dave Barach72d72232016-08-04 10:15:08 -040013046 if (!ipv4_set && !ipv6_set)
13047 {
13048 errmsg ("eid addresses not set\n");
13049 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013050 }
13051
Dave Barach72d72232016-08-04 10:15:08 -040013052 /* Construct the API message */
13053 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013054
Dave Barach72d72232016-08-04 10:15:08 -040013055 mp->is_add = is_add;
13056 if (ipv6_set)
13057 {
13058 mp->is_ipv6 = 1;
13059 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13060 }
13061 else
13062 {
13063 mp->is_ipv6 = 0;
13064 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013065 }
13066
Dave Barach72d72232016-08-04 10:15:08 -040013067 /* send it... */
13068 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013069
Dave Barach72d72232016-08-04 10:15:08 -040013070 /* Wait for a reply... */
13071 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013072
Dave Barach72d72232016-08-04 10:15:08 -040013073 /* NOTREACHED */
13074 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013075}
13076
13077static int
Florin Coras577c3552016-04-21 00:45:40 +020013078api_lisp_gpe_enable_disable (vat_main_t * vam)
13079{
Dave Barach72d72232016-08-04 10:15:08 -040013080 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013081 vl_api_lisp_gpe_enable_disable_t *mp;
13082 f64 timeout = ~0;
13083 u8 is_set = 0;
13084 u8 is_en = 1;
13085
13086 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013087 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13088 {
13089 if (unformat (input, "enable"))
13090 {
13091 is_set = 1;
13092 is_en = 1;
13093 }
13094 else if (unformat (input, "disable"))
13095 {
13096 is_set = 1;
13097 is_en = 0;
13098 }
13099 else
13100 break;
13101 }
Florin Coras577c3552016-04-21 00:45:40 +020013102
Dave Barach72d72232016-08-04 10:15:08 -040013103 if (is_set == 0)
13104 {
13105 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013106 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013107 }
Florin Coras577c3552016-04-21 00:45:40 +020013108
13109 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013110 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013111
13112 mp->is_en = is_en;
13113
13114 /* send it... */
13115 S;
13116
13117 /* Wait for a reply... */
13118 W;
13119
13120 /* NOTREACHED */
13121 return 0;
13122}
13123
13124static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013125api_lisp_enable_disable (vat_main_t * vam)
13126{
Dave Barach72d72232016-08-04 10:15:08 -040013127 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013128 vl_api_lisp_enable_disable_t *mp;
13129 f64 timeout = ~0;
13130 u8 is_set = 0;
13131 u8 is_en = 0;
13132
13133 /* Parse args required to build the message */
13134 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13135 {
13136 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013137 {
13138 is_set = 1;
13139 is_en = 1;
13140 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013141 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013142 {
13143 is_set = 1;
13144 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013145 else
Dave Barach72d72232016-08-04 10:15:08 -040013146 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013147 }
13148
13149 if (!is_set)
13150 {
13151 errmsg ("Value not set\n");
13152 return -99;
13153 }
13154
13155 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013156 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013157
13158 mp->is_en = is_en;
13159
13160 /* send it... */
13161 S;
13162
13163 /* Wait for a reply... */
13164 W;
13165
13166 /* NOTREACHED */
13167 return 0;
13168}
13169
Florin Corasdca88042016-09-14 16:01:38 +020013170static int
13171api_show_lisp_map_request_mode (vat_main_t * vam)
13172{
13173 f64 timeout = ~0;
13174 vl_api_show_lisp_map_request_mode_t *mp;
13175
13176 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13177
13178 /* send */
13179 S;
13180
13181 /* wait for reply */
13182 W;
13183
13184 return 0;
13185}
13186
13187static int
13188api_lisp_map_request_mode (vat_main_t * vam)
13189{
13190 f64 timeout = ~0;
13191 unformat_input_t *input = vam->input;
13192 vl_api_lisp_map_request_mode_t *mp;
13193 u8 mode = 0;
13194
13195 /* Parse args required to build the message */
13196 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13197 {
13198 if (unformat (input, "dst-only"))
13199 mode = 0;
13200 else if (unformat (input, "src-dst"))
13201 mode = 1;
13202 else
13203 {
13204 errmsg ("parse error '%U'", format_unformat_error, input);
13205 return -99;
13206 }
13207 }
13208
13209 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13210
13211 mp->mode = mode;
13212
13213 /* send */
13214 S;
13215
13216 /* wait for reply */
13217 W;
13218
13219 /* notreached */
13220 return 0;
13221}
13222
Filip Tehlar195bcee2016-05-13 17:37:35 +020013223/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013224 * Enable/disable LISP proxy ITR.
13225 *
13226 * @param vam vpp API test context
13227 * @return return code
13228 */
13229static int
13230api_lisp_pitr_set_locator_set (vat_main_t * vam)
13231{
13232 f64 timeout = ~0;
13233 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013234 unformat_input_t *input = vam->input;
13235 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013236 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013237 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013238
13239 /* Parse args required to build the message */
13240 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13241 {
13242 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013243 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013244 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013245 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013246 else
Dave Barach72d72232016-08-04 10:15:08 -040013247 {
13248 errmsg ("parse error '%U'", format_unformat_error, input);
13249 return -99;
13250 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013251 }
13252
13253 if (!ls_name_set)
13254 {
13255 errmsg ("locator-set name not set!");
13256 return -99;
13257 }
13258
Dave Barach72d72232016-08-04 10:15:08 -040013259 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013260
13261 mp->is_add = is_add;
13262 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13263 vec_free (ls_name);
13264
13265 /* send */
13266 S;
13267
13268 /* wait for reply */
13269 W;
13270
Dave Barach72d72232016-08-04 10:15:08 -040013271 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013272 return 0;
13273}
13274
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013275static int
13276api_show_lisp_pitr (vat_main_t * vam)
13277{
Dave Barach72d72232016-08-04 10:15:08 -040013278 vl_api_show_lisp_pitr_t *mp;
13279 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013280
Dave Barach72d72232016-08-04 10:15:08 -040013281 if (!vam->json_output)
13282 {
13283 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013284 }
13285
Dave Barach72d72232016-08-04 10:15:08 -040013286 M (SHOW_LISP_PITR, show_lisp_pitr);
13287 /* send it... */
13288 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013289
Dave Barach72d72232016-08-04 10:15:08 -040013290 /* Wait for a reply... */
13291 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013292
Dave Barach72d72232016-08-04 10:15:08 -040013293 /* NOTREACHED */
13294 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013295}
13296
Filip Tehlar53f09e32016-05-19 14:25:44 +020013297/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013298 * Add/delete mapping between vni and vrf
13299 */
13300static int
13301api_lisp_eid_table_add_del_map (vat_main_t * vam)
13302{
13303 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013304 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013305 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013306 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13307 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013308
13309 /* Parse args required to build the message */
13310 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13311 {
13312 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013313 is_add = 0;
13314 else if (unformat (input, "vrf %d", &vrf))
13315 vrf_set = 1;
13316 else if (unformat (input, "bd_index %d", &bd_index))
13317 bd_index_set = 1;
13318 else if (unformat (input, "vni %d", &vni))
13319 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013320 else
Dave Barach72d72232016-08-04 10:15:08 -040013321 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013322 }
13323
Florin Coras1a1adc72016-07-22 01:45:30 +020013324 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013325 {
13326 errmsg ("missing arguments!");
13327 return -99;
13328 }
13329
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013330 if (vrf_set && bd_index_set)
13331 {
13332 errmsg ("error: both vrf and bd entered!");
13333 return -99;
13334 }
13335
Dave Barach72d72232016-08-04 10:15:08 -040013336 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013337
13338 mp->is_add = is_add;
13339 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013340 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013341 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013342
13343 /* send */
13344 S;
13345
13346 /* wait for reply */
13347 W;
13348
Dave Barach72d72232016-08-04 10:15:08 -040013349 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013350 return 0;
13351}
13352
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013353uword
13354unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13355{
13356 u32 *action = va_arg (*args, u32 *);
13357 u8 *s = 0;
13358
13359 if (unformat (input, "%s", &s))
13360 {
13361 if (!strcmp ((char *) s, "no-action"))
13362 action[0] = 0;
13363 else if (!strcmp ((char *) s, "natively-forward"))
13364 action[0] = 1;
13365 else if (!strcmp ((char *) s, "send-map-request"))
13366 action[0] = 2;
13367 else if (!strcmp ((char *) s, "drop"))
13368 action[0] = 3;
13369 else
13370 {
13371 clib_warning ("invalid action: '%s'", s);
13372 action[0] = 3;
13373 }
13374 }
13375 else
13376 return 0;
13377
13378 vec_free (s);
13379 return 1;
13380}
13381
Filip Tehlar324112f2016-06-02 16:07:38 +020013382/**
Florin Corasf727db92016-06-23 15:01:58 +020013383 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013384 *
13385 * @param vam vpp API test context
13386 * @return return code
13387 */
13388static int
13389api_lisp_add_del_remote_mapping (vat_main_t * vam)
13390{
Dave Barach72d72232016-08-04 10:15:08 -040013391 unformat_input_t *input = vam->input;
13392 vl_api_lisp_add_del_remote_mapping_t *mp;
13393 f64 timeout = ~0;
13394 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013395 lisp_eid_vat_t _eid, *eid = &_eid;
13396 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013397 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013398 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013399 ip4_address_t rloc4;
13400 ip6_address_t rloc6;
13401 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013402
Dave Barach839fe3e2016-08-10 11:35:54 -040013403 memset (&rloc, 0, sizeof (rloc));
13404
Dave Barach72d72232016-08-04 10:15:08 -040013405 /* Parse args required to build the message */
13406 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13407 {
13408 if (unformat (input, "del-all"))
13409 {
13410 del_all = 1;
13411 }
13412 else if (unformat (input, "del"))
13413 {
13414 is_add = 0;
13415 }
13416 else if (unformat (input, "add"))
13417 {
13418 is_add = 1;
13419 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013420 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013421 {
13422 eid_set = 1;
13423 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013424 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013425 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013426 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013427 }
13428 else if (unformat (input, "vni %d", &vni))
13429 {
13430 ;
13431 }
13432 else if (unformat (input, "p %d w %d", &p, &w))
13433 {
13434 if (!curr_rloc)
13435 {
13436 errmsg ("No RLOC configured for setting priority/weight!");
13437 return -99;
13438 }
13439 curr_rloc->priority = p;
13440 curr_rloc->weight = w;
13441 }
13442 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13443 {
13444 rloc.is_ip4 = 1;
13445 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13446 vec_add1 (rlocs, rloc);
13447 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13448 }
13449 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13450 {
13451 rloc.is_ip4 = 0;
13452 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13453 vec_add1 (rlocs, rloc);
13454 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13455 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013456 else if (unformat (input, "action %U",
13457 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013458 {
13459 ;
13460 }
13461 else
13462 {
13463 clib_warning ("parse error '%U'", format_unformat_error, input);
13464 return -99;
13465 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013466 }
13467
Dave Barach72d72232016-08-04 10:15:08 -040013468 if (0 == eid_set)
13469 {
13470 errmsg ("missing params!");
13471 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013472 }
13473
Dave Barach72d72232016-08-04 10:15:08 -040013474 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13475 {
13476 errmsg ("no action set for negative map-reply!");
13477 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013478 }
13479
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013480 data_len = vec_len (rlocs) * sizeof (rloc_t);
13481
13482 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013483 mp->is_add = is_add;
13484 mp->vni = htonl (vni);
13485 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013486 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013487 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013488 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013489 mp->del_all = del_all;
13490 mp->eid_type = eid->type;
13491 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013492 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013493
Filip Tehlare3552c42016-08-26 12:44:38 +020013494 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013495 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013496 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013497
Dave Barach72d72232016-08-04 10:15:08 -040013498 /* send it... */
13499 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013500
Dave Barach72d72232016-08-04 10:15:08 -040013501 /* Wait for a reply... */
13502 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013503
Dave Barach72d72232016-08-04 10:15:08 -040013504 /* NOTREACHED */
13505 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013506}
13507
Florin Corasf727db92016-06-23 15:01:58 +020013508/**
13509 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13510 * forwarding entries in data-plane accordingly.
13511 *
13512 * @param vam vpp API test context
13513 * @return return code
13514 */
13515static int
13516api_lisp_add_del_adjacency (vat_main_t * vam)
13517{
Dave Barach72d72232016-08-04 10:15:08 -040013518 unformat_input_t *input = vam->input;
13519 vl_api_lisp_add_del_adjacency_t *mp;
13520 f64 timeout = ~0;
13521 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013522 ip4_address_t leid4, reid4;
13523 ip6_address_t leid6, reid6;
13524 u8 reid_mac[6] = { 0 };
13525 u8 leid_mac[6] = { 0 };
13526 u8 reid_type, leid_type;
13527 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013528 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013529
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013530 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013531
Dave Barach72d72232016-08-04 10:15:08 -040013532 /* Parse args required to build the message */
13533 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13534 {
13535 if (unformat (input, "del"))
13536 {
13537 is_add = 0;
13538 }
13539 else if (unformat (input, "add"))
13540 {
13541 is_add = 1;
13542 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013543 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13544 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013545 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013546 reid_type = 0; /* ipv4 */
13547 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013548 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013549 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13550 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013551 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013552 reid_type = 1; /* ipv6 */
13553 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013554 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013555 else if (unformat (input, "reid %U", unformat_ethernet_address,
13556 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013557 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013558 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013559 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013560 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13561 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013562 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013563 leid_type = 0; /* ipv4 */
13564 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013565 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013566 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
13567 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013568 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013569 leid_type = 1; /* ipv6 */
13570 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013571 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013572 else if (unformat (input, "leid %U", unformat_ethernet_address,
13573 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013574 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013575 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013576 }
13577 else if (unformat (input, "vni %d", &vni))
13578 {
13579 ;
13580 }
13581 else
13582 {
13583 errmsg ("parse error '%U'", format_unformat_error, input);
13584 return -99;
13585 }
Florin Corasf727db92016-06-23 15:01:58 +020013586 }
13587
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013588 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013589 {
13590 errmsg ("missing params!");
13591 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013592 }
13593
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013594 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013595 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013596 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040013597 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013598 }
13599
Dave Barach72d72232016-08-04 10:15:08 -040013600 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13601 mp->is_add = is_add;
13602 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013603 mp->leid_len = leid_len;
13604 mp->reid_len = reid_len;
13605 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013606
Dave Barach72d72232016-08-04 10:15:08 -040013607 switch (mp->eid_type)
13608 {
Florin Corasf727db92016-06-23 15:01:58 +020013609 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013610 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
13611 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040013612 break;
Florin Corasf727db92016-06-23 15:01:58 +020013613 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013614 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
13615 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040013616 break;
Florin Corasf727db92016-06-23 15:01:58 +020013617 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013618 clib_memcpy (mp->leid, leid_mac, 6);
13619 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040013620 break;
Florin Corasf727db92016-06-23 15:01:58 +020013621 default:
Dave Barach72d72232016-08-04 10:15:08 -040013622 errmsg ("unknown EID type %d!", mp->eid_type);
13623 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013624 }
13625
Dave Barach72d72232016-08-04 10:15:08 -040013626 /* send it... */
13627 S;
Florin Corasf727db92016-06-23 15:01:58 +020013628
Dave Barach72d72232016-08-04 10:15:08 -040013629 /* Wait for a reply... */
13630 W;
Florin Corasf727db92016-06-23 15:01:58 +020013631
Dave Barach72d72232016-08-04 10:15:08 -040013632 /* NOTREACHED */
13633 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013634}
13635
Filip Tehlar46d4e362016-05-09 09:39:26 +020013636static int
Dave Barach72d72232016-08-04 10:15:08 -040013637api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013638{
Dave Barach72d72232016-08-04 10:15:08 -040013639 unformat_input_t *input = vam->input;
13640 vl_api_lisp_gpe_add_del_iface_t *mp;
13641 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013642 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013643 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013644
Dave Barach72d72232016-08-04 10:15:08 -040013645 /* Parse args required to build the message */
13646 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13647 {
13648 if (unformat (input, "up"))
13649 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013650 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013651 is_add = 1;
13652 }
13653 else if (unformat (input, "down"))
13654 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013655 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013656 is_add = 0;
13657 }
13658 else if (unformat (input, "table_id %d", &dp_table))
13659 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013660 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013661 }
13662 else if (unformat (input, "bd_id %d", &dp_table))
13663 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013664 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013665 is_l2 = 1;
13666 }
13667 else if (unformat (input, "vni %d", &vni))
13668 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013669 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013670 }
13671 else
13672 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013673 }
13674
Florin Coras7fbfad32016-08-05 16:57:33 +020013675 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013676 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013677 errmsg ("Action not set\n");
13678 return -99;
13679 }
13680 if (dp_table_set == 0 || vni_set == 0)
13681 {
13682 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013683 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013684 }
13685
Dave Barach72d72232016-08-04 10:15:08 -040013686 /* Construct the API message */
13687 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013688
Dave Barach72d72232016-08-04 10:15:08 -040013689 mp->is_add = is_add;
13690 mp->dp_table = dp_table;
13691 mp->is_l2 = is_l2;
13692 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013693
Dave Barach72d72232016-08-04 10:15:08 -040013694 /* send it... */
13695 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013696
Dave Barach72d72232016-08-04 10:15:08 -040013697 /* Wait for a reply... */
13698 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013699
Dave Barach72d72232016-08-04 10:15:08 -040013700 /* NOTREACHED */
13701 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013702}
13703
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013704/**
13705 * Add/del map request itr rlocs from LISP control plane and updates
13706 *
13707 * @param vam vpp API test context
13708 * @return return code
13709 */
13710static int
Dave Barach72d72232016-08-04 10:15:08 -040013711api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013712{
Dave Barach72d72232016-08-04 10:15:08 -040013713 unformat_input_t *input = vam->input;
13714 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13715 f64 timeout = ~0;
13716 u8 *locator_set_name = 0;
13717 u8 locator_set_name_set = 0;
13718 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013719
Dave Barach72d72232016-08-04 10:15:08 -040013720 /* Parse args required to build the message */
13721 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013722 {
Dave Barach72d72232016-08-04 10:15:08 -040013723 if (unformat (input, "del"))
13724 {
13725 is_add = 0;
13726 }
13727 else if (unformat (input, "%_%v%_", &locator_set_name))
13728 {
13729 locator_set_name_set = 1;
13730 }
13731 else
13732 {
13733 clib_warning ("parse error '%U'", format_unformat_error, input);
13734 return -99;
13735 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013736 }
13737
Dave Barach72d72232016-08-04 10:15:08 -040013738 if (is_add && !locator_set_name_set)
13739 {
13740 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013741 return -99;
13742 }
13743
Dave Barach72d72232016-08-04 10:15:08 -040013744 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013745 {
Dave Barach72d72232016-08-04 10:15:08 -040013746 errmsg ("itr-rloc locator-set name too long\n");
13747 vec_free (locator_set_name);
13748 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013749 }
13750
Dave Barach72d72232016-08-04 10:15:08 -040013751 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13752 mp->is_add = is_add;
13753 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013754 {
Dave Barach72d72232016-08-04 10:15:08 -040013755 clib_memcpy (mp->locator_set_name, locator_set_name,
13756 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013757 }
Dave Barach72d72232016-08-04 10:15:08 -040013758 else
13759 {
13760 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013761 }
Dave Barach72d72232016-08-04 10:15:08 -040013762 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013763
Dave Barach72d72232016-08-04 10:15:08 -040013764 /* send it... */
13765 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013766
Dave Barach72d72232016-08-04 10:15:08 -040013767 /* Wait for a reply... */
13768 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013769
Dave Barach72d72232016-08-04 10:15:08 -040013770 /* NOTREACHED */
13771 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013772}
13773
13774static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013775api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013776{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013777 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013778 vl_api_lisp_locator_dump_t *mp;
13779 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013780 u8 is_index_set = 0, is_name_set = 0;
13781 u8 *ls_name = 0;
13782 u32 ls_index = ~0;
13783
13784 /* Parse args required to build the message */
13785 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13786 {
13787 if (unformat (input, "ls_name %_%v%_", &ls_name))
13788 {
13789 is_name_set = 1;
13790 }
13791 else if (unformat (input, "ls_index %d", &ls_index))
13792 {
13793 is_index_set = 1;
13794 }
13795 else
13796 {
13797 errmsg ("parse error '%U'", format_unformat_error, input);
13798 return -99;
13799 }
13800 }
13801
13802 if (!is_index_set && !is_name_set)
13803 {
13804 errmsg ("error: expected one of index or name!\n");
13805 return -99;
13806 }
13807
13808 if (is_index_set && is_name_set)
13809 {
13810 errmsg ("error: only one param expected!\n");
13811 return -99;
13812 }
13813
Florin Coras042d2122016-09-21 16:38:19 +020013814 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013815 {
13816 errmsg ("error: locator set name too long!");
13817 return -99;
13818 }
13819
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013820 if (!vam->json_output)
13821 {
13822 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13823 "weight");
13824 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013825
Dave Barach72d72232016-08-04 10:15:08 -040013826 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013827 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013828
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013829 if (is_index_set)
13830 mp->ls_index = clib_host_to_net_u32 (ls_index);
13831 else
13832 {
13833 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013834 strncpy ((char *) mp->ls_name, (char *) ls_name,
13835 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013836 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013837
Dave Barach72d72232016-08-04 10:15:08 -040013838 /* send it... */
13839 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013840
Dave Barach72d72232016-08-04 10:15:08 -040013841 /* Use a control ping for synchronization */
13842 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013843 vl_api_control_ping_t *mp;
13844 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013845 S;
13846 }
13847 /* Wait for a reply... */
13848 W;
Dave Barach72d72232016-08-04 10:15:08 -040013849
13850 /* NOTREACHED */
13851 return 0;
13852}
13853
13854static int
13855api_lisp_locator_set_dump (vat_main_t * vam)
13856{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013857 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013858 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013859 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013860 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013861
13862 /* Parse args required to build the message */
13863 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13864 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013865 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013866 {
13867 filter = 1;
13868 }
13869 else if (unformat (input, "remote"))
13870 {
13871 filter = 2;
13872 }
13873 else
13874 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013875 errmsg ("parse error '%U'", format_unformat_error, input);
13876 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013877 }
13878 }
13879
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013880 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013881 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013882 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013883 }
13884
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013885 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013886
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013887 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013888
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013889 /* send it... */
13890 S;
13891
13892 /* Use a control ping for synchronization */
13893 {
13894 vl_api_control_ping_t *mp;
13895 M (CONTROL_PING, control_ping);
13896 S;
13897 }
13898 /* Wait for a reply... */
13899 W;
13900
13901 /* NOTREACHED */
13902 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013903}
13904
13905static int
13906api_lisp_eid_table_map_dump (vat_main_t * vam)
13907{
Filip Tehlarc0681792016-08-24 14:11:07 +020013908 u8 is_l2 = 0;
13909 u8 mode_set = 0;
13910 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013911 vl_api_lisp_eid_table_map_dump_t *mp;
13912 f64 timeout = ~0;
13913
Filip Tehlarc0681792016-08-24 14:11:07 +020013914 /* Parse args required to build the message */
13915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13916 {
13917 if (unformat (input, "l2"))
13918 {
13919 is_l2 = 1;
13920 mode_set = 1;
13921 }
13922 else if (unformat (input, "l3"))
13923 {
13924 is_l2 = 0;
13925 mode_set = 1;
13926 }
13927 else
13928 {
13929 errmsg ("parse error '%U'", format_unformat_error, input);
13930 return -99;
13931 }
13932 }
13933
13934 if (!mode_set)
13935 {
13936 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13937 return -99;
13938 }
13939
Dave Barach72d72232016-08-04 10:15:08 -040013940 if (!vam->json_output)
13941 {
Filip Tehlarc0681792016-08-24 14:11:07 +020013942 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040013943 }
13944
13945 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020013946 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040013947
13948 /* send it... */
13949 S;
13950
13951 /* Use a control ping for synchronization */
13952 {
13953 vl_api_control_ping_t *mp;
13954 M (CONTROL_PING, control_ping);
13955 S;
13956 }
13957 /* Wait for a reply... */
13958 W;
13959
13960 /* NOTREACHED */
13961 return 0;
13962}
13963
13964static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020013965api_lisp_eid_table_vni_dump (vat_main_t * vam)
13966{
13967 vl_api_lisp_eid_table_vni_dump_t *mp;
13968 f64 timeout = ~0;
13969
13970 if (!vam->json_output)
13971 {
13972 fformat (vam->ofp, "VNI\n");
13973 }
13974
13975 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
13976
13977 /* send it... */
13978 S;
13979
13980 /* Use a control ping for synchronization */
13981 {
13982 vl_api_control_ping_t *mp;
13983 M (CONTROL_PING, control_ping);
13984 S;
13985 }
13986 /* Wait for a reply... */
13987 W;
13988
13989 /* NOTREACHED */
13990 return 0;
13991}
13992
13993static int
Dave Barach72d72232016-08-04 10:15:08 -040013994api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013995{
Dave Barach72d72232016-08-04 10:15:08 -040013996 unformat_input_t *i = vam->input;
13997 vl_api_lisp_eid_table_dump_t *mp;
13998 f64 timeout = ~0;
13999 struct in_addr ip4;
14000 struct in6_addr ip6;
14001 u8 mac[6];
14002 u8 eid_type = ~0, eid_set = 0;
14003 u32 prefix_length = ~0, t, vni = 0;
14004 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014005
Dave Barach72d72232016-08-04 10:15:08 -040014006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014007 {
Dave Barach72d72232016-08-04 10:15:08 -040014008 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14009 {
14010 eid_set = 1;
14011 eid_type = 0;
14012 prefix_length = t;
14013 }
14014 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14015 {
14016 eid_set = 1;
14017 eid_type = 1;
14018 prefix_length = t;
14019 }
14020 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14021 {
14022 eid_set = 1;
14023 eid_type = 2;
14024 }
14025 else if (unformat (i, "vni %d", &t))
14026 {
14027 vni = t;
14028 }
14029 else if (unformat (i, "local"))
14030 {
14031 filter = 1;
14032 }
14033 else if (unformat (i, "remote"))
14034 {
14035 filter = 2;
14036 }
14037 else
14038 {
14039 errmsg ("parse error '%U'", format_unformat_error, i);
14040 return -99;
14041 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014042 }
14043
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014044 if (!vam->json_output)
14045 {
14046 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
14047 "ls_index", "ttl", "authoritative");
14048 }
14049
Dave Barach72d72232016-08-04 10:15:08 -040014050 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014051
Dave Barach72d72232016-08-04 10:15:08 -040014052 mp->filter = filter;
14053 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014054 {
Dave Barach72d72232016-08-04 10:15:08 -040014055 mp->eid_set = 1;
14056 mp->vni = htonl (vni);
14057 mp->eid_type = eid_type;
14058 switch (eid_type)
14059 {
14060 case 0:
14061 mp->prefix_length = prefix_length;
14062 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14063 break;
14064 case 1:
14065 mp->prefix_length = prefix_length;
14066 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14067 break;
14068 case 2:
14069 clib_memcpy (mp->eid, mac, sizeof (mac));
14070 break;
14071 default:
14072 errmsg ("unknown EID type %d!", eid_type);
14073 return -99;
14074 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014075 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014076
Dave Barach72d72232016-08-04 10:15:08 -040014077 /* send it... */
14078 S;
14079
14080 /* Use a control ping for synchronization */
14081 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014082 vl_api_control_ping_t *mp;
14083 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014084 S;
14085 }
14086
14087 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014088 W;
Dave Barach72d72232016-08-04 10:15:08 -040014089
14090 /* NOTREACHED */
14091 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014092}
14093
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014094static int
Dave Barach72d72232016-08-04 10:15:08 -040014095api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014096{
Dave Barach72d72232016-08-04 10:15:08 -040014097 vl_api_lisp_gpe_tunnel_dump_t *mp;
14098 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014099
Dave Barach72d72232016-08-04 10:15:08 -040014100 if (!vam->json_output)
14101 {
14102 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14103 "%=16s%=16s%=16s%=16s%=16s\n",
14104 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14105 "Decap next", "Lisp version", "Flags", "Next protocol",
14106 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014107 }
14108
Dave Barach72d72232016-08-04 10:15:08 -040014109 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14110 /* send it... */
14111 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014112
Dave Barach72d72232016-08-04 10:15:08 -040014113 /* Use a control ping for synchronization */
14114 {
14115 vl_api_control_ping_t *mp;
14116 M (CONTROL_PING, control_ping);
14117 S;
14118 }
14119 /* Wait for a reply... */
14120 W;
14121
14122 /* NOTREACHED */
14123 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014124}
14125
Matus Fabian8a95a482016-05-06 15:14:13 +020014126static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014127api_lisp_adjacencies_get (vat_main_t * vam)
14128{
14129 unformat_input_t *i = vam->input;
14130 vl_api_lisp_adjacencies_get_t *mp;
14131 f64 timeout = ~0;
14132 u8 vni_set = 0;
14133 u32 vni = ~0;
14134
14135 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14136 {
14137 if (unformat (i, "vni %d", &vni))
14138 {
14139 vni_set = 1;
14140 }
14141 else
14142 {
14143 errmsg ("parse error '%U'\n", format_unformat_error, i);
14144 return -99;
14145 }
14146 }
14147
14148 if (!vni_set)
14149 {
14150 errmsg ("vni not set!\n");
14151 return -99;
14152 }
14153
14154 if (!vam->json_output)
14155 {
14156 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14157 }
14158
14159 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14160 mp->vni = clib_host_to_net_u32 (vni);
14161
14162 /* send it... */
14163 S;
14164
14165 /* Wait for a reply... */
14166 W;
14167
14168 /* NOTREACHED */
14169 return 0;
14170}
14171
14172static int
Dave Barach72d72232016-08-04 10:15:08 -040014173api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014174{
Dave Barach72d72232016-08-04 10:15:08 -040014175 vl_api_lisp_map_resolver_dump_t *mp;
14176 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014177
Dave Barach72d72232016-08-04 10:15:08 -040014178 if (!vam->json_output)
14179 {
14180 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014181 }
14182
Dave Barach72d72232016-08-04 10:15:08 -040014183 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14184 /* send it... */
14185 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014186
Dave Barach72d72232016-08-04 10:15:08 -040014187 /* Use a control ping for synchronization */
14188 {
14189 vl_api_control_ping_t *mp;
14190 M (CONTROL_PING, control_ping);
14191 S;
14192 }
14193 /* Wait for a reply... */
14194 W;
14195
14196 /* NOTREACHED */
14197 return 0;
14198}
14199
14200static int
14201api_show_lisp_status (vat_main_t * vam)
14202{
14203 vl_api_show_lisp_status_t *mp;
14204 f64 timeout = ~0;
14205
14206 if (!vam->json_output)
14207 {
14208 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14209 }
14210
14211 M (SHOW_LISP_STATUS, show_lisp_status);
14212 /* send it... */
14213 S;
14214 /* Wait for a reply... */
14215 W;
14216
14217 /* NOTREACHED */
14218 return 0;
14219}
14220
14221static int
14222api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14223{
14224 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14225 f64 timeout = ~0;
14226
14227 if (!vam->json_output)
14228 {
14229 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14230 }
14231
14232 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14233 /* send it... */
14234 S;
14235 /* Wait for a reply... */
14236 W;
14237
14238 /* NOTREACHED */
14239 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014240}
14241
14242static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014243api_af_packet_create (vat_main_t * vam)
14244{
Dave Barach72d72232016-08-04 10:15:08 -040014245 unformat_input_t *i = vam->input;
14246 vl_api_af_packet_create_t *mp;
14247 f64 timeout;
14248 u8 *host_if_name = 0;
14249 u8 hw_addr[6];
14250 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014251
Dave Barach72d72232016-08-04 10:15:08 -040014252 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014253
Dave Barach72d72232016-08-04 10:15:08 -040014254 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14255 {
14256 if (unformat (i, "name %s", &host_if_name))
14257 vec_add1 (host_if_name, 0);
14258 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14259 random_hw_addr = 0;
14260 else
14261 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014262 }
14263
Dave Barach72d72232016-08-04 10:15:08 -040014264 if (!vec_len (host_if_name))
14265 {
14266 errmsg ("host-interface name must be specified");
14267 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014268 }
14269
Dave Barach72d72232016-08-04 10:15:08 -040014270 if (vec_len (host_if_name) > 64)
14271 {
14272 errmsg ("host-interface name too long");
14273 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014274 }
14275
Dave Barach72d72232016-08-04 10:15:08 -040014276 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014277
Dave Barach72d72232016-08-04 10:15:08 -040014278 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14279 clib_memcpy (mp->hw_addr, hw_addr, 6);
14280 mp->use_random_hw_addr = random_hw_addr;
14281 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014282
Dave Barach72d72232016-08-04 10:15:08 -040014283 S;
14284 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14285 /* NOTREACHED */
14286 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014287}
14288
14289static int
14290api_af_packet_delete (vat_main_t * vam)
14291{
Dave Barach72d72232016-08-04 10:15:08 -040014292 unformat_input_t *i = vam->input;
14293 vl_api_af_packet_delete_t *mp;
14294 f64 timeout;
14295 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014296
Dave Barach72d72232016-08-04 10:15:08 -040014297 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14298 {
14299 if (unformat (i, "name %s", &host_if_name))
14300 vec_add1 (host_if_name, 0);
14301 else
14302 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014303 }
14304
Dave Barach72d72232016-08-04 10:15:08 -040014305 if (!vec_len (host_if_name))
14306 {
14307 errmsg ("host-interface name must be specified");
14308 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014309 }
14310
Dave Barach72d72232016-08-04 10:15:08 -040014311 if (vec_len (host_if_name) > 64)
14312 {
14313 errmsg ("host-interface name too long");
14314 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014315 }
14316
Dave Barach72d72232016-08-04 10:15:08 -040014317 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014318
Dave Barach72d72232016-08-04 10:15:08 -040014319 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14320 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014321
Dave Barach72d72232016-08-04 10:15:08 -040014322 S;
14323 W;
14324 /* NOTREACHED */
14325 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014326}
14327
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014328static int
14329api_policer_add_del (vat_main_t * vam)
14330{
Dave Barach72d72232016-08-04 10:15:08 -040014331 unformat_input_t *i = vam->input;
14332 vl_api_policer_add_del_t *mp;
14333 f64 timeout;
14334 u8 is_add = 1;
14335 u8 *name = 0;
14336 u32 cir = 0;
14337 u32 eir = 0;
14338 u64 cb = 0;
14339 u64 eb = 0;
14340 u8 rate_type = 0;
14341 u8 round_type = 0;
14342 u8 type = 0;
14343 u8 color_aware = 0;
14344 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014345
Dave Barach839fe3e2016-08-10 11:35:54 -040014346 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14347 conform_action.dscp = 0;
14348 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14349 exceed_action.dscp = 0;
14350 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14351 violate_action.dscp = 0;
14352
Dave Barach72d72232016-08-04 10:15:08 -040014353 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14354 {
14355 if (unformat (i, "del"))
14356 is_add = 0;
14357 else if (unformat (i, "name %s", &name))
14358 vec_add1 (name, 0);
14359 else if (unformat (i, "cir %u", &cir))
14360 ;
14361 else if (unformat (i, "eir %u", &eir))
14362 ;
14363 else if (unformat (i, "cb %u", &cb))
14364 ;
14365 else if (unformat (i, "eb %u", &eb))
14366 ;
14367 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14368 &rate_type))
14369 ;
14370 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14371 &round_type))
14372 ;
14373 else if (unformat (i, "type %U", unformat_policer_type, &type))
14374 ;
14375 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14376 &conform_action))
14377 ;
14378 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14379 &exceed_action))
14380 ;
14381 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14382 &violate_action))
14383 ;
14384 else if (unformat (i, "color-aware"))
14385 color_aware = 1;
14386 else
14387 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014388 }
14389
Dave Barach72d72232016-08-04 10:15:08 -040014390 if (!vec_len (name))
14391 {
14392 errmsg ("policer name must be specified");
14393 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014394 }
14395
Dave Barach72d72232016-08-04 10:15:08 -040014396 if (vec_len (name) > 64)
14397 {
14398 errmsg ("policer name too long");
14399 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014400 }
14401
Dave Barach72d72232016-08-04 10:15:08 -040014402 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014403
Dave Barach72d72232016-08-04 10:15:08 -040014404 clib_memcpy (mp->name, name, vec_len (name));
14405 vec_free (name);
14406 mp->is_add = is_add;
14407 mp->cir = cir;
14408 mp->eir = eir;
14409 mp->cb = cb;
14410 mp->eb = eb;
14411 mp->rate_type = rate_type;
14412 mp->round_type = round_type;
14413 mp->type = type;
14414 mp->conform_action_type = conform_action.action_type;
14415 mp->conform_dscp = conform_action.dscp;
14416 mp->exceed_action_type = exceed_action.action_type;
14417 mp->exceed_dscp = exceed_action.dscp;
14418 mp->violate_action_type = violate_action.action_type;
14419 mp->violate_dscp = violate_action.dscp;
14420 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014421
Dave Barach72d72232016-08-04 10:15:08 -040014422 S;
14423 W;
14424 /* NOTREACHED */
14425 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014426}
14427
Matus Fabian82e29c42016-05-11 04:49:46 -070014428static int
Dave Barach72d72232016-08-04 10:15:08 -040014429api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014430{
Dave Barach72d72232016-08-04 10:15:08 -040014431 unformat_input_t *i = vam->input;
14432 vl_api_policer_dump_t *mp;
14433 f64 timeout = ~0;
14434 u8 *match_name = 0;
14435 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014436
Dave Barach72d72232016-08-04 10:15:08 -040014437 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014438 {
Dave Barach72d72232016-08-04 10:15:08 -040014439 if (unformat (i, "name %s", &match_name))
14440 {
14441 vec_add1 (match_name, 0);
14442 match_name_valid = 1;
14443 }
14444 else
14445 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014446 }
Matus Fabiane8554802016-05-18 23:40:37 -070014447
Dave Barach72d72232016-08-04 10:15:08 -040014448 M (POLICER_DUMP, policer_dump);
14449 mp->match_name_valid = match_name_valid;
14450 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14451 vec_free (match_name);
14452 /* send it... */
14453 S;
14454
14455 /* Use a control ping for synchronization */
14456 {
14457 vl_api_control_ping_t *mp;
14458 M (CONTROL_PING, control_ping);
14459 S;
14460 }
14461 /* Wait for a reply... */
14462 W;
14463
14464 /* NOTREACHED */
14465 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014466}
14467
14468static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014469api_policer_classify_set_interface (vat_main_t * vam)
14470{
Dave Barach72d72232016-08-04 10:15:08 -040014471 unformat_input_t *i = vam->input;
14472 vl_api_policer_classify_set_interface_t *mp;
14473 f64 timeout;
14474 u32 sw_if_index;
14475 int sw_if_index_set;
14476 u32 ip4_table_index = ~0;
14477 u32 ip6_table_index = ~0;
14478 u32 l2_table_index = ~0;
14479 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014480
Dave Barach72d72232016-08-04 10:15:08 -040014481 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14482 {
14483 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
14484 sw_if_index_set = 1;
14485 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14486 sw_if_index_set = 1;
14487 else if (unformat (i, "del"))
14488 is_add = 0;
14489 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14490 ;
14491 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14492 ;
14493 else if (unformat (i, "l2-table %d", &l2_table_index))
14494 ;
14495 else
14496 {
14497 clib_warning ("parse error '%U'", format_unformat_error, i);
14498 return -99;
14499 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014500 }
14501
Dave Barach72d72232016-08-04 10:15:08 -040014502 if (sw_if_index_set == 0)
14503 {
14504 errmsg ("missing interface name or sw_if_index\n");
14505 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014506 }
14507
Dave Barach72d72232016-08-04 10:15:08 -040014508 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014509
Dave Barach72d72232016-08-04 10:15:08 -040014510 mp->sw_if_index = ntohl (sw_if_index);
14511 mp->ip4_table_index = ntohl (ip4_table_index);
14512 mp->ip6_table_index = ntohl (ip6_table_index);
14513 mp->l2_table_index = ntohl (l2_table_index);
14514 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014515
Dave Barach72d72232016-08-04 10:15:08 -040014516 S;
14517 W;
14518 /* NOTREACHED */
14519 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014520}
14521
14522static int
Dave Barach72d72232016-08-04 10:15:08 -040014523api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014524{
Dave Barach72d72232016-08-04 10:15:08 -040014525 unformat_input_t *i = vam->input;
14526 vl_api_policer_classify_dump_t *mp;
14527 f64 timeout = ~0;
14528 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014529
Juraj Sloboda506b2452016-08-07 23:45:24 -070014530 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040014531 ;
14532 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014533 {
Dave Barach72d72232016-08-04 10:15:08 -040014534 errmsg ("classify table type must be specified\n");
14535 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014536 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014537
Dave Barach72d72232016-08-04 10:15:08 -040014538 if (!vam->json_output)
14539 {
14540 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
14541 }
14542
14543 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14544 mp->type = type;
14545 /* send it... */
14546 S;
14547
14548 /* Use a control ping for synchronization */
14549 {
14550 vl_api_control_ping_t *mp;
14551 M (CONTROL_PING, control_ping);
14552 S;
14553 }
14554 /* Wait for a reply... */
14555 W;
14556
14557 /* NOTREACHED */
14558 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014559}
14560
14561static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014562api_netmap_create (vat_main_t * vam)
14563{
Dave Barach72d72232016-08-04 10:15:08 -040014564 unformat_input_t *i = vam->input;
14565 vl_api_netmap_create_t *mp;
14566 f64 timeout;
14567 u8 *if_name = 0;
14568 u8 hw_addr[6];
14569 u8 random_hw_addr = 1;
14570 u8 is_pipe = 0;
14571 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014572
Dave Barach72d72232016-08-04 10:15:08 -040014573 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014574
Dave Barach72d72232016-08-04 10:15:08 -040014575 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14576 {
14577 if (unformat (i, "name %s", &if_name))
14578 vec_add1 (if_name, 0);
14579 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14580 random_hw_addr = 0;
14581 else if (unformat (i, "pipe"))
14582 is_pipe = 1;
14583 else if (unformat (i, "master"))
14584 is_master = 1;
14585 else if (unformat (i, "slave"))
14586 is_master = 0;
14587 else
14588 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014589 }
14590
Dave Barach72d72232016-08-04 10:15:08 -040014591 if (!vec_len (if_name))
14592 {
14593 errmsg ("interface name must be specified");
14594 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014595 }
14596
Dave Barach72d72232016-08-04 10:15:08 -040014597 if (vec_len (if_name) > 64)
14598 {
14599 errmsg ("interface name too long");
14600 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014601 }
14602
Dave Barach72d72232016-08-04 10:15:08 -040014603 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014604
Dave Barach72d72232016-08-04 10:15:08 -040014605 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14606 clib_memcpy (mp->hw_addr, hw_addr, 6);
14607 mp->use_random_hw_addr = random_hw_addr;
14608 mp->is_pipe = is_pipe;
14609 mp->is_master = is_master;
14610 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014611
Dave Barach72d72232016-08-04 10:15:08 -040014612 S;
14613 W;
14614 /* NOTREACHED */
14615 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014616}
14617
14618static int
14619api_netmap_delete (vat_main_t * vam)
14620{
Dave Barach72d72232016-08-04 10:15:08 -040014621 unformat_input_t *i = vam->input;
14622 vl_api_netmap_delete_t *mp;
14623 f64 timeout;
14624 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014625
Dave Barach72d72232016-08-04 10:15:08 -040014626 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14627 {
14628 if (unformat (i, "name %s", &if_name))
14629 vec_add1 (if_name, 0);
14630 else
14631 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014632 }
14633
Dave Barach72d72232016-08-04 10:15:08 -040014634 if (!vec_len (if_name))
14635 {
14636 errmsg ("interface name must be specified");
14637 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014638 }
14639
Dave Barach72d72232016-08-04 10:15:08 -040014640 if (vec_len (if_name) > 64)
14641 {
14642 errmsg ("interface name too long");
14643 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014644 }
14645
Dave Barach72d72232016-08-04 10:15:08 -040014646 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014647
Dave Barach72d72232016-08-04 10:15:08 -040014648 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14649 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014650
Dave Barach72d72232016-08-04 10:15:08 -040014651 S;
14652 W;
14653 /* NOTREACHED */
14654 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014655}
14656
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014657static void vl_api_mpls_eth_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014658 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014659{
Dave Barach72d72232016-08-04 10:15:08 -040014660 vat_main_t *vam = &vat_main;
14661 i32 i;
14662 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014663
Dave Barach72d72232016-08-04 10:15:08 -040014664 fformat (vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
14665 ntohl (mp->tunnel_index),
14666 format_ethernet_address, &mp->tunnel_dst_mac,
14667 format_ip4_address, &mp->intfc_address, ntohl (mp->mask_width));
14668 for (i = 0; i < len; i++)
14669 {
14670 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014671 }
Dave Barach72d72232016-08-04 10:15:08 -040014672 fformat (vam->ofp, "\n");
14673 fformat (vam->ofp, " tx on %d, rx fib index %d\n",
14674 ntohl (mp->tx_sw_if_index), ntohl (mp->inner_fib_index));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014675}
14676
14677static void vl_api_mpls_eth_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014678 (vl_api_mpls_eth_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014679{
Dave Barach72d72232016-08-04 10:15:08 -040014680 vat_main_t *vam = &vat_main;
14681 vat_json_node_t *node = NULL;
14682 struct in_addr ip4;
14683 i32 i;
14684 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014685
Dave Barach72d72232016-08-04 10:15:08 -040014686 if (VAT_JSON_ARRAY != vam->json_tree.type)
14687 {
14688 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14689 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014690 }
Dave Barach72d72232016-08-04 10:15:08 -040014691 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014692
Dave Barach72d72232016-08-04 10:15:08 -040014693 vat_json_init_object (node);
14694 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
14695 clib_memcpy (&ip4, &(mp->intfc_address), sizeof (ip4));
14696 vat_json_object_add_ip4 (node, "intfc_address", ip4);
14697 vat_json_object_add_uint (node, "inner_fib_index",
14698 ntohl (mp->inner_fib_index));
14699 vat_json_object_add_uint (node, "mask_width", ntohl (mp->mask_width));
14700 vat_json_object_add_uint (node, "encap_index", ntohl (mp->encap_index));
14701 vat_json_object_add_uint (node, "hw_if_index", ntohl (mp->hw_if_index));
14702 vat_json_object_add_uint (node, "l2_only", ntohl (mp->l2_only));
14703 vat_json_object_add_string_copy (node, "tunnel_dst_mac",
14704 format (0, "%U", format_ethernet_address,
14705 &mp->tunnel_dst_mac));
14706 vat_json_object_add_uint (node, "tx_sw_if_index",
14707 ntohl (mp->tx_sw_if_index));
14708 vat_json_object_add_uint (node, "label_count", len);
14709 for (i = 0; i < len; i++)
14710 {
14711 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014712 }
14713}
14714
Dave Barach72d72232016-08-04 10:15:08 -040014715static int
14716api_mpls_eth_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014717{
Dave Barach72d72232016-08-04 10:15:08 -040014718 vl_api_mpls_eth_tunnel_dump_t *mp;
14719 f64 timeout;
14720 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014721
Dave Barach72d72232016-08-04 10:15:08 -040014722 /* Parse args required to build the message */
14723 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014724 {
Dave Barach72d72232016-08-04 10:15:08 -040014725 if (!unformat (vam->input, "tunnel_index %d", &index))
14726 {
14727 index = -1;
14728 break;
14729 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014730 }
Dave Barach72d72232016-08-04 10:15:08 -040014731
14732 fformat (vam->ofp, " tunnel_index %d\n", index);
14733
14734 M (MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
14735 mp->tunnel_index = htonl (index);
14736 S;
14737
14738 /* Use a control ping for synchronization */
14739 {
14740 vl_api_control_ping_t *mp;
14741 M (CONTROL_PING, control_ping);
14742 S;
14743 }
14744 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014745}
14746
14747static void vl_api_mpls_fib_encap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040014748 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014749{
Dave Barach72d72232016-08-04 10:15:08 -040014750 vat_main_t *vam = &vat_main;
14751 i32 i;
14752 i32 len = ntohl (mp->nlabels);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014753
Dave Barach72d72232016-08-04 10:15:08 -040014754 fformat (vam->ofp, "table %d, dest %U, label ",
14755 ntohl (mp->fib_index), format_ip4_address, &mp->dest, len);
14756 for (i = 0; i < len; i++)
14757 {
14758 fformat (vam->ofp, "%u ", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014759 }
Dave Barach72d72232016-08-04 10:15:08 -040014760 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014761}
14762
14763static void vl_api_mpls_fib_encap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040014764 (vl_api_mpls_fib_encap_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014765{
Dave Barach72d72232016-08-04 10:15:08 -040014766 vat_main_t *vam = &vat_main;
14767 vat_json_node_t *node = NULL;
14768 i32 i;
14769 i32 len = ntohl (mp->nlabels);
14770 struct in_addr ip4;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014771
Dave Barach72d72232016-08-04 10:15:08 -040014772 if (VAT_JSON_ARRAY != vam->json_tree.type)
14773 {
14774 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14775 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014776 }
Dave Barach72d72232016-08-04 10:15:08 -040014777 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014778
Dave Barach72d72232016-08-04 10:15:08 -040014779 vat_json_init_object (node);
14780 vat_json_object_add_uint (node, "table", ntohl (mp->fib_index));
14781 vat_json_object_add_uint (node, "entry_index", ntohl (mp->entry_index));
14782 clib_memcpy (&ip4, &(mp->dest), sizeof (ip4));
14783 vat_json_object_add_ip4 (node, "dest", ip4);
14784 vat_json_object_add_uint (node, "s_bit", ntohl (mp->s_bit));
14785 vat_json_object_add_uint (node, "label_count", len);
14786 for (i = 0; i < len; i++)
14787 {
14788 vat_json_object_add_uint (node, "label", ntohl (mp->labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014789 }
14790}
14791
Dave Barach72d72232016-08-04 10:15:08 -040014792static int
14793api_mpls_fib_encap_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014794{
Dave Barach72d72232016-08-04 10:15:08 -040014795 vl_api_mpls_fib_encap_dump_t *mp;
14796 f64 timeout;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014797
Dave Barach72d72232016-08-04 10:15:08 -040014798 M (MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
14799 S;
14800
14801 /* Use a control ping for synchronization */
14802 {
14803 vl_api_control_ping_t *mp;
14804 M (CONTROL_PING, control_ping);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014805 S;
Dave Barach72d72232016-08-04 10:15:08 -040014806 }
14807 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014808}
14809
Steven01b07122016-11-02 10:40:09 -070014810#define vl_api_mpls_fib_details_t_endian vl_noop_handler
14811#define vl_api_mpls_fib_details_t_print vl_noop_handler
14812
Neale Ranns1357f3b2016-10-16 12:01:42 -070014813static void
14814vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014815{
Dave Barach72d72232016-08-04 10:15:08 -040014816 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070014817 int count = ntohl (mp->count);
14818 vl_api_fib_path_t *fp;
14819 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014820
Dave Barach72d72232016-08-04 10:15:08 -040014821 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070014822 "table-id %d, label %u, ess_bit %u\n",
14823 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
Steven01b07122016-11-02 10:40:09 -070014824 fp = mp->path;
14825 for (i = 0; i < count; i++)
14826 {
Steven5858a822016-11-16 13:26:27 -080014827 if (fp->afi == IP46_TYPE_IP6)
14828 fformat (vam->ofp,
14829 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14830 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14831 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14832 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14833 format_ip6_address, fp->next_hop);
14834 else if (fp->afi == IP46_TYPE_IP4)
14835 fformat (vam->ofp,
14836 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14837 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14838 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14839 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14840 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070014841 fp++;
14842 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014843}
14844
Neale Ranns1357f3b2016-10-16 12:01:42 -070014845static void vl_api_mpls_fib_details_t_handler_json
14846 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014847{
Dave Barach72d72232016-08-04 10:15:08 -040014848 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070014849 int count = ntohl (mp->count);
Dave Barach72d72232016-08-04 10:15:08 -040014850 vat_json_node_t *node = NULL;
Steven01b07122016-11-02 10:40:09 -070014851 struct in_addr ip4;
14852 struct in6_addr ip6;
14853 vl_api_fib_path_t *fp;
14854 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014855
Dave Barach72d72232016-08-04 10:15:08 -040014856 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014857 {
Dave Barach72d72232016-08-04 10:15:08 -040014858 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14859 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014860 }
Dave Barach72d72232016-08-04 10:15:08 -040014861 node = vat_json_array_add (&vam->json_tree);
14862
14863 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070014864 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
14865 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040014866 vat_json_object_add_uint (node, "label", ntohl (mp->label));
Steven01b07122016-11-02 10:40:09 -070014867 vat_json_object_add_uint (node, "path_count", count);
14868 fp = mp->path;
14869 for (i = 0; i < count; i++)
14870 {
14871 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
14872 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
14873 vat_json_object_add_uint (node, "is_local", fp->is_local);
14874 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
14875 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
14876 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
14877 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
14878 if (fp->afi == IP46_TYPE_IP4)
14879 {
14880 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
14881 vat_json_object_add_ip4 (node, "next_hop", ip4);
14882 }
14883 else if (fp->afi == IP46_TYPE_IP6)
14884 {
14885 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
14886 vat_json_object_add_ip6 (node, "next_hop", ip6);
14887 }
14888 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014889}
14890
Dave Barach72d72232016-08-04 10:15:08 -040014891static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070014892api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014893{
Neale Ranns1357f3b2016-10-16 12:01:42 -070014894 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014895 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014896
Neale Ranns1357f3b2016-10-16 12:01:42 -070014897 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014898 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014899
Dave Barach72d72232016-08-04 10:15:08 -040014900 /* Use a control ping for synchronization */
14901 {
14902 vl_api_control_ping_t *mp;
14903 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014904 S;
Dave Barach72d72232016-08-04 10:15:08 -040014905 }
14906 W;
14907}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014908
Steven01b07122016-11-02 10:40:09 -070014909#define vl_api_ip_fib_details_t_endian vl_noop_handler
14910#define vl_api_ip_fib_details_t_print vl_noop_handler
14911
14912static void
14913vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
14914{
14915 vat_main_t *vam = &vat_main;
14916 int count = ntohl (mp->count);
14917 vl_api_fib_path_t *fp;
14918 int i;
14919
14920 fformat (vam->ofp,
14921 "table-id %d, prefix %U/%d\n",
14922 ntohl (mp->table_id), format_ip4_address, mp->address,
14923 mp->address_length);
14924 fp = mp->path;
14925 for (i = 0; i < count; i++)
14926 {
Steven5858a822016-11-16 13:26:27 -080014927 if (fp->afi == IP46_TYPE_IP6)
14928 fformat (vam->ofp,
14929 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14930 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14931 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14932 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14933 format_ip6_address, fp->next_hop);
14934 else if (fp->afi == IP46_TYPE_IP4)
14935 fformat (vam->ofp,
14936 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14937 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14938 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14939 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14940 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070014941 fp++;
14942 }
14943}
14944
14945static void vl_api_ip_fib_details_t_handler_json
14946 (vl_api_ip_fib_details_t * mp)
14947{
14948 vat_main_t *vam = &vat_main;
14949 int count = ntohl (mp->count);
14950 vat_json_node_t *node = NULL;
14951 struct in_addr ip4;
14952 struct in6_addr ip6;
14953 vl_api_fib_path_t *fp;
14954 int i;
14955
14956 if (VAT_JSON_ARRAY != vam->json_tree.type)
14957 {
14958 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14959 vat_json_init_array (&vam->json_tree);
14960 }
14961 node = vat_json_array_add (&vam->json_tree);
14962
14963 vat_json_init_object (node);
14964 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
14965 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
14966 vat_json_object_add_ip4 (node, "prefix", ip4);
14967 vat_json_object_add_uint (node, "mask_length", mp->address_length);
14968 vat_json_object_add_uint (node, "path_count", count);
14969 fp = mp->path;
14970 for (i = 0; i < count; i++)
14971 {
14972 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
14973 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
14974 vat_json_object_add_uint (node, "is_local", fp->is_local);
14975 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
14976 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
14977 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
14978 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
14979 if (fp->afi == IP46_TYPE_IP4)
14980 {
14981 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
14982 vat_json_object_add_ip4 (node, "next_hop", ip4);
14983 }
14984 else if (fp->afi == IP46_TYPE_IP6)
14985 {
14986 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
14987 vat_json_object_add_ip6 (node, "next_hop", ip6);
14988 }
14989 }
14990}
14991
14992static int
14993api_ip_fib_dump (vat_main_t * vam)
14994{
14995 vl_api_ip_fib_dump_t *mp;
14996 f64 timeout;
14997
14998 M (IP_FIB_DUMP, ip_fib_dump);
14999 S;
15000
15001 /* Use a control ping for synchronization */
15002 {
15003 vl_api_control_ping_t *mp;
15004 M (CONTROL_PING, control_ping);
15005 S;
15006 }
15007 W;
15008}
15009
15010#define vl_api_ip6_fib_details_t_endian vl_noop_handler
15011#define vl_api_ip6_fib_details_t_print vl_noop_handler
15012
15013static void
15014vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
15015{
15016 vat_main_t *vam = &vat_main;
15017 int count = ntohl (mp->count);
15018 vl_api_fib_path_t *fp;
15019 int i;
15020
15021 fformat (vam->ofp,
15022 "table-id %d, prefix %U/%d\n",
15023 ntohl (mp->table_id), format_ip6_address, mp->address,
15024 mp->address_length);
15025 fp = mp->path;
15026 for (i = 0; i < count; i++)
15027 {
Steven5858a822016-11-16 13:26:27 -080015028 if (fp->afi == IP46_TYPE_IP6)
15029 fformat (vam->ofp,
15030 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15031 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15032 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15033 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15034 format_ip6_address, fp->next_hop);
15035 else if (fp->afi == IP46_TYPE_IP4)
15036 fformat (vam->ofp,
15037 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15038 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15039 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15040 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15041 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015042 fp++;
15043 }
15044}
15045
15046static void vl_api_ip6_fib_details_t_handler_json
15047 (vl_api_ip6_fib_details_t * mp)
15048{
15049 vat_main_t *vam = &vat_main;
15050 int count = ntohl (mp->count);
15051 vat_json_node_t *node = NULL;
15052 struct in_addr ip4;
15053 struct in6_addr ip6;
15054 vl_api_fib_path_t *fp;
15055 int i;
15056
15057 if (VAT_JSON_ARRAY != vam->json_tree.type)
15058 {
15059 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15060 vat_json_init_array (&vam->json_tree);
15061 }
15062 node = vat_json_array_add (&vam->json_tree);
15063
15064 vat_json_init_object (node);
15065 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15066 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
15067 vat_json_object_add_ip6 (node, "prefix", ip6);
15068 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15069 vat_json_object_add_uint (node, "path_count", count);
15070 fp = mp->path;
15071 for (i = 0; i < count; i++)
15072 {
15073 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15074 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15075 vat_json_object_add_uint (node, "is_local", fp->is_local);
15076 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15077 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15078 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15079 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15080 if (fp->afi == IP46_TYPE_IP4)
15081 {
15082 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15083 vat_json_object_add_ip4 (node, "next_hop", ip4);
15084 }
15085 else if (fp->afi == IP46_TYPE_IP6)
15086 {
15087 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15088 vat_json_object_add_ip6 (node, "next_hop", ip6);
15089 }
15090 }
15091}
15092
15093static int
15094api_ip6_fib_dump (vat_main_t * vam)
15095{
15096 vl_api_ip6_fib_dump_t *mp;
15097 f64 timeout;
15098
15099 M (IP6_FIB_DUMP, ip6_fib_dump);
15100 S;
15101
15102 /* Use a control ping for synchronization */
15103 {
15104 vl_api_control_ping_t *mp;
15105 M (CONTROL_PING, control_ping);
15106 S;
15107 }
15108 W;
15109}
15110
Dave Barach72d72232016-08-04 10:15:08 -040015111int
15112api_classify_table_ids (vat_main_t * vam)
15113{
15114 vl_api_classify_table_ids_t *mp;
15115 f64 timeout;
15116
15117 /* Construct the API message */
15118 M (CLASSIFY_TABLE_IDS, classify_table_ids);
15119 mp->context = 0;
15120
15121 S;
15122 W;
15123 /* NOTREACHED */
15124 return 0;
15125}
15126
15127int
15128api_classify_table_by_interface (vat_main_t * vam)
15129{
15130 unformat_input_t *input = vam->input;
15131 vl_api_classify_table_by_interface_t *mp;
15132 f64 timeout;
15133
15134 u32 sw_if_index = ~0;
15135 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015136 {
Dave Barach72d72232016-08-04 10:15:08 -040015137 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15138 ;
15139 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15140 ;
15141 else
15142 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015143 }
Dave Barach72d72232016-08-04 10:15:08 -040015144 if (sw_if_index == ~0)
15145 {
15146 errmsg ("missing interface name or sw_if_index\n");
15147 return -99;
15148 }
15149
15150 /* Construct the API message */
15151 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
15152 mp->context = 0;
15153 mp->sw_if_index = ntohl (sw_if_index);
15154
15155 S;
15156 W;
15157 /* NOTREACHED */
15158 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015159}
15160
Dave Barach72d72232016-08-04 10:15:08 -040015161int
15162api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015163{
Dave Barach72d72232016-08-04 10:15:08 -040015164 unformat_input_t *input = vam->input;
15165 vl_api_classify_table_info_t *mp;
15166 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015167
Dave Barach72d72232016-08-04 10:15:08 -040015168 u32 table_id = ~0;
15169 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15170 {
15171 if (unformat (input, "table_id %d", &table_id))
15172 ;
15173 else
15174 break;
15175 }
15176 if (table_id == ~0)
15177 {
15178 errmsg ("missing table id\n");
15179 return -99;
15180 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015181
Dave Barach72d72232016-08-04 10:15:08 -040015182 /* Construct the API message */
15183 M (CLASSIFY_TABLE_INFO, classify_table_info);
15184 mp->context = 0;
15185 mp->table_id = ntohl (table_id);
15186
15187 S;
15188 W;
15189 /* NOTREACHED */
15190 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015191}
15192
Dave Barach72d72232016-08-04 10:15:08 -040015193int
15194api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015195{
Dave Barach72d72232016-08-04 10:15:08 -040015196 unformat_input_t *input = vam->input;
15197 vl_api_classify_session_dump_t *mp;
15198 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015199
Dave Barach72d72232016-08-04 10:15:08 -040015200 u32 table_id = ~0;
15201 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15202 {
15203 if (unformat (input, "table_id %d", &table_id))
15204 ;
15205 else
15206 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015207 }
Dave Barach72d72232016-08-04 10:15:08 -040015208 if (table_id == ~0)
15209 {
15210 errmsg ("missing table id\n");
15211 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015212 }
15213
Dave Barach72d72232016-08-04 10:15:08 -040015214 /* Construct the API message */
15215 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15216 mp->context = 0;
15217 mp->table_id = ntohl (table_id);
15218 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015219
Dave Barach72d72232016-08-04 10:15:08 -040015220 /* Use a control ping for synchronization */
15221 {
15222 vl_api_control_ping_t *mp;
15223 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015224 S;
Dave Barach72d72232016-08-04 10:15:08 -040015225 }
15226 W;
15227 /* NOTREACHED */
15228 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015229}
15230
Dave Barach72d72232016-08-04 10:15:08 -040015231static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015232vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015233{
Dave Barach72d72232016-08-04 10:15:08 -040015234 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015235
Dave Barach72d72232016-08-04 10:15:08 -040015236 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015237 "src_address %U, vrf_id %d, path_mtu %u, "
15238 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015239 format_ip4_address, mp->collector_address,
15240 ntohs (mp->collector_port),
15241 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015242 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15243 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015244
15245 vam->retval = 0;
15246 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015247}
15248
Dave Barach72d72232016-08-04 10:15:08 -040015249static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015250 vl_api_ipfix_exporter_details_t_handler_json
15251 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015252{
Dave Barach72d72232016-08-04 10:15:08 -040015253 vat_main_t *vam = &vat_main;
15254 vat_json_node_t node;
15255 struct in_addr collector_address;
15256 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015257
Dave Barach72d72232016-08-04 10:15:08 -040015258 vat_json_init_object (&node);
15259 clib_memcpy (&collector_address, &mp->collector_address,
15260 sizeof (collector_address));
15261 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15262 vat_json_object_add_uint (&node, "collector_port",
15263 ntohs (mp->collector_port));
15264 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15265 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015266 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015267 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15268 vat_json_object_add_uint (&node, "template_interval",
15269 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015270 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015271
15272 vat_json_print (vam->ofp, &node);
15273 vat_json_free (&node);
15274 vam->retval = 0;
15275 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015276}
15277
Dave Barach72d72232016-08-04 10:15:08 -040015278int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015279api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015280{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015281 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015282 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015283
Dave Barach72d72232016-08-04 10:15:08 -040015284 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015285 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015286 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015287
Dave Barach72d72232016-08-04 10:15:08 -040015288 S;
15289 W;
15290 /* NOTREACHED */
15291 return 0;
15292}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015293
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015294static int
15295api_ipfix_classify_stream_dump (vat_main_t * vam)
15296{
15297 vl_api_ipfix_classify_stream_dump_t *mp;
15298 f64 timeout;
15299
15300 /* Construct the API message */
15301 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15302 mp->context = 0;
15303
15304 S;
15305 W;
15306 /* NOTREACHED */
15307 return 0;
15308}
15309
15310static void
15311 vl_api_ipfix_classify_stream_details_t_handler
15312 (vl_api_ipfix_classify_stream_details_t * mp)
15313{
15314 vat_main_t *vam = &vat_main;
15315 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15316 ntohl (mp->domain_id), ntohs (mp->src_port));
15317 vam->retval = 0;
15318 vam->result_ready = 1;
15319}
15320
15321static void
15322 vl_api_ipfix_classify_stream_details_t_handler_json
15323 (vl_api_ipfix_classify_stream_details_t * mp)
15324{
15325 vat_main_t *vam = &vat_main;
15326 vat_json_node_t node;
15327
15328 vat_json_init_object (&node);
15329 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15330 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15331
15332 vat_json_print (vam->ofp, &node);
15333 vat_json_free (&node);
15334 vam->retval = 0;
15335 vam->result_ready = 1;
15336}
15337
15338static int
15339api_ipfix_classify_table_dump (vat_main_t * vam)
15340{
15341 vl_api_ipfix_classify_table_dump_t *mp;
15342 f64 timeout;
15343
15344 if (!vam->json_output)
15345 {
15346 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15347 "transport_protocol");
15348 }
15349
15350 /* Construct the API message */
15351 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15352
15353 /* send it... */
15354 S;
15355
15356 /* Use a control ping for synchronization */
15357 {
15358 vl_api_control_ping_t *mp;
15359 M (CONTROL_PING, control_ping);
15360 S;
15361 }
15362 W;
15363}
15364
15365static void
15366 vl_api_ipfix_classify_table_details_t_handler
15367 (vl_api_ipfix_classify_table_details_t * mp)
15368{
15369 vat_main_t *vam = &vat_main;
15370 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15371 mp->transport_protocol);
15372}
15373
15374static void
15375 vl_api_ipfix_classify_table_details_t_handler_json
15376 (vl_api_ipfix_classify_table_details_t * mp)
15377{
15378 vat_json_node_t *node = NULL;
15379 vat_main_t *vam = &vat_main;
15380
15381 if (VAT_JSON_ARRAY != vam->json_tree.type)
15382 {
15383 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15384 vat_json_init_array (&vam->json_tree);
15385 }
15386
15387 node = vat_json_array_add (&vam->json_tree);
15388 vat_json_init_object (node);
15389
15390 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15391 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15392 vat_json_object_add_uint (node, "transport_protocol",
15393 mp->transport_protocol);
15394}
15395
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015396static int
15397api_sw_interface_span_enable_disable (vat_main_t * vam)
15398{
15399 unformat_input_t *i = vam->input;
15400 vl_api_sw_interface_span_enable_disable_t *mp;
15401 f64 timeout;
15402 u32 src_sw_if_index = ~0;
15403 u32 dst_sw_if_index = ~0;
15404 u8 enable = 1;
15405
15406 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15407 {
15408 if (unformat (i, "src %U", unformat_sw_if_index, vam, &src_sw_if_index))
15409 ;
15410 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
15411 ;
15412 else
15413 if (unformat
15414 (i, "dst %U", unformat_sw_if_index, vam, &dst_sw_if_index))
15415 ;
15416 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
15417 ;
15418 else if (unformat (i, "disable"))
15419 enable = 0;
15420 else
15421 break;
15422 }
15423
15424 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable);
15425
15426 mp->sw_if_index_from = htonl (src_sw_if_index);
15427 mp->sw_if_index_to = htonl (dst_sw_if_index);
15428 mp->enable = enable;
15429
15430 S;
15431 W;
15432 /* NOTREACHED */
15433 return 0;
15434}
15435
15436static void
15437vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
15438 * mp)
15439{
15440 vat_main_t *vam = &vat_main;
15441
15442 fformat (vam->ofp, "%u => %u\n",
15443 ntohl (mp->sw_if_index_from), ntohl (mp->sw_if_index_to));
15444}
15445
15446static void
15447 vl_api_sw_interface_span_details_t_handler_json
15448 (vl_api_sw_interface_span_details_t * mp)
15449{
15450 vat_main_t *vam = &vat_main;
15451 vat_json_node_t *node = NULL;
15452
15453 if (VAT_JSON_ARRAY != vam->json_tree.type)
15454 {
15455 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15456 vat_json_init_array (&vam->json_tree);
15457 }
15458 node = vat_json_array_add (&vam->json_tree);
15459
15460 vat_json_init_object (node);
15461 vat_json_object_add_uint (node, "src-if-index",
15462 ntohl (mp->sw_if_index_from));
15463 vat_json_object_add_uint (node, "dst-if-index", ntohl (mp->sw_if_index_to));
15464}
15465
15466static int
15467api_sw_interface_span_dump (vat_main_t * vam)
15468{
15469 vl_api_sw_interface_span_dump_t *mp;
15470 f64 timeout;
15471
15472 M (SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump);
15473 S;
15474
15475 /* Use a control ping for synchronization */
15476 {
15477 vl_api_control_ping_t *mp;
15478 M (CONTROL_PING, control_ping);
15479 S;
15480 }
15481 W;
15482}
15483
Dave Barach72d72232016-08-04 10:15:08 -040015484int
15485api_pg_create_interface (vat_main_t * vam)
15486{
15487 unformat_input_t *input = vam->input;
15488 vl_api_pg_create_interface_t *mp;
15489 f64 timeout;
15490
15491 u32 if_id = ~0;
15492 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15493 {
15494 if (unformat (input, "if_id %d", &if_id))
15495 ;
15496 else
15497 break;
15498 }
15499 if (if_id == ~0)
15500 {
15501 errmsg ("missing pg interface index\n");
15502 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015503 }
15504
Dave Barach72d72232016-08-04 10:15:08 -040015505 /* Construct the API message */
15506 M (PG_CREATE_INTERFACE, pg_create_interface);
15507 mp->context = 0;
15508 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015509
Dave Barach72d72232016-08-04 10:15:08 -040015510 S;
15511 W;
15512 /* NOTREACHED */
15513 return 0;
15514}
15515
15516int
15517api_pg_capture (vat_main_t * vam)
15518{
15519 unformat_input_t *input = vam->input;
15520 vl_api_pg_capture_t *mp;
15521 f64 timeout;
15522
15523 u32 if_id = ~0;
15524 u8 enable = 1;
15525 u32 count = 1;
15526 u8 pcap_file_set = 0;
15527 u8 *pcap_file = 0;
15528 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15529 {
15530 if (unformat (input, "if_id %d", &if_id))
15531 ;
15532 else if (unformat (input, "pcap %s", &pcap_file))
15533 pcap_file_set = 1;
15534 else if (unformat (input, "count %d", &count))
15535 ;
15536 else if (unformat (input, "disable"))
15537 enable = 0;
15538 else
15539 break;
15540 }
15541 if (if_id == ~0)
15542 {
15543 errmsg ("missing pg interface index\n");
15544 return -99;
15545 }
15546 if (pcap_file_set > 0)
15547 {
15548 if (vec_len (pcap_file) > 255)
15549 {
15550 errmsg ("pcap file name is too long\n");
15551 return -99;
15552 }
15553 }
15554
15555 u32 name_len = vec_len (pcap_file);
15556 /* Construct the API message */
15557 M (PG_CAPTURE, pg_capture);
15558 mp->context = 0;
15559 mp->interface_id = ntohl (if_id);
15560 mp->is_enabled = enable;
15561 mp->count = ntohl (count);
15562 mp->pcap_name_length = ntohl (name_len);
15563 if (pcap_file_set != 0)
15564 {
15565 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
15566 }
15567 vec_free (pcap_file);
15568
15569 S;
15570 W;
15571 /* NOTREACHED */
15572 return 0;
15573}
15574
15575int
15576api_pg_enable_disable (vat_main_t * vam)
15577{
15578 unformat_input_t *input = vam->input;
15579 vl_api_pg_enable_disable_t *mp;
15580 f64 timeout;
15581
15582 u8 enable = 1;
15583 u8 stream_name_set = 0;
15584 u8 *stream_name = 0;
15585 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15586 {
15587 if (unformat (input, "stream %s", &stream_name))
15588 stream_name_set = 1;
15589 else if (unformat (input, "disable"))
15590 enable = 0;
15591 else
15592 break;
15593 }
15594
15595 if (stream_name_set > 0)
15596 {
15597 if (vec_len (stream_name) > 255)
15598 {
15599 errmsg ("stream name too long\n");
15600 return -99;
15601 }
15602 }
15603
15604 u32 name_len = vec_len (stream_name);
15605 /* Construct the API message */
15606 M (PG_ENABLE_DISABLE, pg_enable_disable);
15607 mp->context = 0;
15608 mp->is_enabled = enable;
15609 if (stream_name_set != 0)
15610 {
15611 mp->stream_name_length = ntohl (name_len);
15612 clib_memcpy (mp->stream_name, stream_name, name_len);
15613 }
15614 vec_free (stream_name);
15615
15616 S;
15617 W;
15618 /* NOTREACHED */
15619 return 0;
15620}
15621
15622int
15623api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
15624{
15625 unformat_input_t *input = vam->input;
15626 vl_api_ip_source_and_port_range_check_add_del_t *mp;
15627 f64 timeout;
15628
15629 u16 *low_ports = 0;
15630 u16 *high_ports = 0;
15631 u16 this_low;
15632 u16 this_hi;
15633 ip4_address_t ip4_addr;
15634 ip6_address_t ip6_addr;
15635 u32 length;
15636 u32 tmp, tmp2;
15637 u8 prefix_set = 0;
15638 u32 vrf_id = ~0;
15639 u8 is_add = 1;
15640 u8 is_ipv6 = 0;
15641
15642 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15643 {
15644 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
15645 {
15646 prefix_set = 1;
15647 }
15648 else
15649 if (unformat
15650 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
15651 {
15652 prefix_set = 1;
15653 is_ipv6 = 1;
15654 }
15655 else if (unformat (input, "vrf %d", &vrf_id))
15656 ;
15657 else if (unformat (input, "del"))
15658 is_add = 0;
15659 else if (unformat (input, "port %d", &tmp))
15660 {
15661 if (tmp == 0 || tmp > 65535)
15662 {
15663 errmsg ("port %d out of range", tmp);
15664 return -99;
15665 }
15666 this_low = tmp;
15667 this_hi = this_low + 1;
15668 vec_add1 (low_ports, this_low);
15669 vec_add1 (high_ports, this_hi);
15670 }
15671 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
15672 {
15673 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
15674 {
15675 errmsg ("incorrect range parameters\n");
15676 return -99;
15677 }
15678 this_low = tmp;
15679 /* Note: in debug CLI +1 is added to high before
15680 passing to real fn that does "the work"
15681 (ip_source_and_port_range_check_add_del).
15682 This fn is a wrapper around the binary API fn a
15683 control plane will call, which expects this increment
15684 to have occurred. Hence letting the binary API control
15685 plane fn do the increment for consistency between VAT
15686 and other control planes.
15687 */
15688 this_hi = tmp2;
15689 vec_add1 (low_ports, this_low);
15690 vec_add1 (high_ports, this_hi);
15691 }
15692 else
15693 break;
15694 }
15695
15696 if (prefix_set == 0)
15697 {
15698 errmsg ("<address>/<mask> not specified\n");
15699 return -99;
15700 }
15701
15702 if (vrf_id == ~0)
15703 {
15704 errmsg ("VRF ID required, not specified\n");
15705 return -99;
15706 }
15707
15708 if (vrf_id == 0)
15709 {
15710 errmsg
15711 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15712 return -99;
15713 }
15714
15715 if (vec_len (low_ports) == 0)
15716 {
15717 errmsg ("At least one port or port range required\n");
15718 return -99;
15719 }
15720
15721 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
15722 ip_source_and_port_range_check_add_del);
15723
15724 mp->is_add = is_add;
15725
15726 if (is_ipv6)
15727 {
15728 mp->is_ipv6 = 1;
15729 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
15730 }
15731 else
15732 {
15733 mp->is_ipv6 = 0;
15734 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
15735 }
15736
15737 mp->mask_length = length;
15738 mp->number_of_ranges = vec_len (low_ports);
15739
15740 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
15741 vec_free (low_ports);
15742
15743 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
15744 vec_free (high_ports);
15745
15746 mp->vrf_id = ntohl (vrf_id);
15747
15748 S;
15749 W;
15750 /* NOTREACHED */
15751 return 0;
15752}
15753
15754int
15755api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
15756{
15757 unformat_input_t *input = vam->input;
15758 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
15759 f64 timeout;
15760 u32 sw_if_index = ~0;
15761 int vrf_set = 0;
15762 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
15763 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
15764 u8 is_add = 1;
15765
15766 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15767 {
15768 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15769 ;
15770 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15771 ;
15772 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15773 vrf_set = 1;
15774 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15775 vrf_set = 1;
15776 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15777 vrf_set = 1;
15778 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15779 vrf_set = 1;
15780 else if (unformat (input, "del"))
15781 is_add = 0;
15782 else
15783 break;
15784 }
15785
15786 if (sw_if_index == ~0)
15787 {
15788 errmsg ("Interface required but not specified\n");
15789 return -99;
15790 }
15791
15792 if (vrf_set == 0)
15793 {
15794 errmsg ("VRF ID required but not specified\n");
15795 return -99;
15796 }
15797
15798 if (tcp_out_vrf_id == 0
15799 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15800 {
15801 errmsg
15802 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15803 return -99;
15804 }
15805
15806 /* Construct the API message */
15807 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15808 ip_source_and_port_range_check_interface_add_del);
15809
15810 mp->sw_if_index = ntohl (sw_if_index);
15811 mp->is_add = is_add;
15812 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15813 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15814 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15815 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15816
15817 /* send it... */
15818 S;
15819
15820 /* Wait for a reply... */
15821 W;
15822}
15823
15824static int
Matus Fabian694265d2016-08-10 01:55:36 -070015825api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15826{
15827 unformat_input_t *i = vam->input;
15828 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15829 f64 timeout;
15830 u32 local_sa_id = 0;
15831 u32 remote_sa_id = 0;
15832 ip4_address_t src_address;
15833 ip4_address_t dst_address;
15834 u8 is_add = 1;
15835
15836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15837 {
15838 if (unformat (i, "local_sa %d", &local_sa_id))
15839 ;
15840 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15841 ;
15842 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15843 ;
15844 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15845 ;
15846 else if (unformat (i, "del"))
15847 is_add = 0;
15848 else
15849 {
15850 clib_warning ("parse error '%U'", format_unformat_error, i);
15851 return -99;
15852 }
15853 }
15854
15855 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15856
15857 mp->local_sa_id = ntohl (local_sa_id);
15858 mp->remote_sa_id = ntohl (remote_sa_id);
15859 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15860 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15861 mp->is_add = is_add;
15862
15863 S;
15864 W;
15865 /* NOTREACHED */
15866 return 0;
15867}
15868
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070015869static int
15870api_punt (vat_main_t * vam)
15871{
15872 unformat_input_t *i = vam->input;
15873 vl_api_punt_t *mp;
15874 f64 timeout;
15875 u32 ipv = ~0;
15876 u32 protocol = ~0;
15877 u32 port = ~0;
15878 int is_add = 1;
15879
15880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15881 {
15882 if (unformat (i, "ip %d", &ipv))
15883 ;
15884 else if (unformat (i, "protocol %d", &protocol))
15885 ;
15886 else if (unformat (i, "port %d", &port))
15887 ;
15888 else if (unformat (i, "del"))
15889 is_add = 0;
15890 else
15891 {
15892 clib_warning ("parse error '%U'", format_unformat_error, i);
15893 return -99;
15894 }
15895 }
15896
15897 M (PUNT, punt);
15898
15899 mp->is_add = (u8) is_add;
15900 mp->ipv = (u8) ipv;
15901 mp->l4_protocol = (u8) protocol;
15902 mp->l4_port = htons ((u16) port);
15903
15904 S;
15905 W;
15906 /* NOTREACHED */
15907 return 0;
15908}
15909
Matus Fabian694265d2016-08-10 01:55:36 -070015910static void vl_api_ipsec_gre_tunnel_details_t_handler
15911 (vl_api_ipsec_gre_tunnel_details_t * mp)
15912{
15913 vat_main_t *vam = &vat_main;
15914
15915 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15916 ntohl (mp->sw_if_index),
15917 format_ip4_address, &mp->src_address,
15918 format_ip4_address, &mp->dst_address,
15919 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15920}
15921
15922static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15923 (vl_api_ipsec_gre_tunnel_details_t * mp)
15924{
15925 vat_main_t *vam = &vat_main;
15926 vat_json_node_t *node = NULL;
15927 struct in_addr ip4;
15928
15929 if (VAT_JSON_ARRAY != vam->json_tree.type)
15930 {
15931 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15932 vat_json_init_array (&vam->json_tree);
15933 }
15934 node = vat_json_array_add (&vam->json_tree);
15935
15936 vat_json_init_object (node);
15937 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15938 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15939 vat_json_object_add_ip4 (node, "src_address", ip4);
15940 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15941 vat_json_object_add_ip4 (node, "dst_address", ip4);
15942 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15943 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15944}
15945
15946static int
15947api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15948{
15949 unformat_input_t *i = vam->input;
15950 vl_api_ipsec_gre_tunnel_dump_t *mp;
15951 f64 timeout;
15952 u32 sw_if_index;
15953 u8 sw_if_index_set = 0;
15954
15955 /* Parse args required to build the message */
15956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15957 {
15958 if (unformat (i, "sw_if_index %d", &sw_if_index))
15959 sw_if_index_set = 1;
15960 else
15961 break;
15962 }
15963
15964 if (sw_if_index_set == 0)
15965 {
15966 sw_if_index = ~0;
15967 }
15968
15969 if (!vam->json_output)
15970 {
15971 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15972 "sw_if_index", "src_address", "dst_address",
15973 "local_sa_id", "remote_sa_id");
15974 }
15975
15976 /* Get list of gre-tunnel interfaces */
15977 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15978
15979 mp->sw_if_index = htonl (sw_if_index);
15980
15981 S;
15982
15983 /* Use a control ping for synchronization */
15984 {
15985 vl_api_control_ping_t *mp;
15986 M (CONTROL_PING, control_ping);
15987 S;
15988 }
15989 W;
15990}
15991
15992static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015993api_delete_subif (vat_main_t * vam)
15994{
15995 unformat_input_t *i = vam->input;
15996 vl_api_delete_subif_t *mp;
15997 f64 timeout;
15998 u32 sw_if_index = ~0;
15999
16000 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16001 {
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016002 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16003 ;
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016004 if (unformat (i, "sw_if_index %d", &sw_if_index))
16005 ;
16006 else
16007 break;
16008 }
16009
16010 if (sw_if_index == ~0)
16011 {
16012 errmsg ("missing sw_if_index\n");
16013 return -99;
16014 }
16015
16016 /* Construct the API message */
16017 M (DELETE_SUBIF, delete_subif);
16018 mp->sw_if_index = ntohl (sw_if_index);
16019
16020 S;
16021 W;
16022}
16023
Pavel Kotucek95300d12016-08-26 16:11:36 +020016024#define foreach_pbb_vtr_op \
16025_("disable", L2_VTR_DISABLED) \
16026_("pop", L2_VTR_POP_2) \
16027_("push", L2_VTR_PUSH_2)
16028
16029static int
16030api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
16031{
16032 unformat_input_t *i = vam->input;
16033 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
16034 f64 timeout;
16035 u32 sw_if_index = ~0, vtr_op = ~0;
16036 u16 outer_tag = ~0;
16037 u8 dmac[6], smac[6];
16038 u8 dmac_set = 0, smac_set = 0;
16039 u16 vlanid = 0;
16040 u32 sid = ~0;
16041 u32 tmp;
16042
Dave Barach75665d32016-11-17 11:36:59 -050016043 /* Shut up coverity */
16044 memset (dmac, 0, sizeof (dmac));
16045 memset (smac, 0, sizeof (smac));
16046
Pavel Kotucek95300d12016-08-26 16:11:36 +020016047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16048 {
16049 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16050 ;
16051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16052 ;
16053 else if (unformat (i, "vtr_op %d", &vtr_op))
16054 ;
16055#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
16056 foreach_pbb_vtr_op
16057#undef _
16058 else if (unformat (i, "translate_pbb_stag"))
16059 {
16060 if (unformat (i, "%d", &tmp))
16061 {
16062 vtr_op = L2_VTR_TRANSLATE_2_1;
16063 outer_tag = tmp;
16064 }
16065 else
16066 {
16067 errmsg
16068 ("translate_pbb_stag operation requires outer tag definition\n");
16069 return -99;
16070 }
16071 }
16072 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
16073 dmac_set++;
16074 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
16075 smac_set++;
16076 else if (unformat (i, "sid %d", &sid))
16077 ;
16078 else if (unformat (i, "vlanid %d", &tmp))
16079 vlanid = tmp;
16080 else
16081 {
16082 clib_warning ("parse error '%U'", format_unformat_error, i);
16083 return -99;
16084 }
16085 }
16086
16087 if ((sw_if_index == ~0) || (vtr_op == ~0))
16088 {
16089 errmsg ("missing sw_if_index or vtr operation\n");
16090 return -99;
16091 }
16092 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
16093 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
16094 {
16095 errmsg
16096 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
16097 return -99;
16098 }
16099
16100 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
16101 mp->sw_if_index = ntohl (sw_if_index);
16102 mp->vtr_op = ntohl (vtr_op);
16103 mp->outer_tag = ntohs (outer_tag);
16104 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
16105 clib_memcpy (mp->b_smac, smac, sizeof (smac));
16106 mp->b_vlanid = ntohs (vlanid);
16107 mp->i_sid = ntohl (sid);
16108
16109 S;
16110 W;
16111 /* NOTREACHED */
16112 return 0;
16113}
16114
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016115static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070016116api_flow_classify_set_interface (vat_main_t * vam)
16117{
16118 unformat_input_t *i = vam->input;
16119 vl_api_flow_classify_set_interface_t *mp;
16120 f64 timeout;
16121 u32 sw_if_index;
16122 int sw_if_index_set;
16123 u32 ip4_table_index = ~0;
16124 u32 ip6_table_index = ~0;
16125 u8 is_add = 1;
16126
16127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16128 {
16129 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16130 sw_if_index_set = 1;
16131 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16132 sw_if_index_set = 1;
16133 else if (unformat (i, "del"))
16134 is_add = 0;
16135 else if (unformat (i, "ip4-table %d", &ip4_table_index))
16136 ;
16137 else if (unformat (i, "ip6-table %d", &ip6_table_index))
16138 ;
16139 else
16140 {
16141 clib_warning ("parse error '%U'", format_unformat_error, i);
16142 return -99;
16143 }
16144 }
16145
16146 if (sw_if_index_set == 0)
16147 {
16148 errmsg ("missing interface name or sw_if_index\n");
16149 return -99;
16150 }
16151
16152 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
16153
16154 mp->sw_if_index = ntohl (sw_if_index);
16155 mp->ip4_table_index = ntohl (ip4_table_index);
16156 mp->ip6_table_index = ntohl (ip6_table_index);
16157 mp->is_add = is_add;
16158
16159 S;
16160 W;
16161 /* NOTREACHED */
16162 return 0;
16163}
16164
16165static int
16166api_flow_classify_dump (vat_main_t * vam)
16167{
16168 unformat_input_t *i = vam->input;
16169 vl_api_flow_classify_dump_t *mp;
16170 f64 timeout = ~0;
16171 u8 type = FLOW_CLASSIFY_N_TABLES;
16172
16173 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
16174 ;
16175 else
16176 {
16177 errmsg ("classify table type must be specified\n");
16178 return -99;
16179 }
16180
16181 if (!vam->json_output)
16182 {
16183 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
16184 }
16185
16186 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
16187 mp->type = type;
16188 /* send it... */
16189 S;
16190
16191 /* Use a control ping for synchronization */
16192 {
16193 vl_api_control_ping_t *mp;
16194 M (CONTROL_PING, control_ping);
16195 S;
16196 }
16197 /* Wait for a reply... */
16198 W;
16199
16200 /* NOTREACHED */
16201 return 0;
16202}
16203
16204static int
Pavel Kotucek7490a752016-11-15 09:19:11 +010016205api_feature_enable_disable (vat_main_t * vam)
16206{
16207 unformat_input_t *i = vam->input;
16208 vl_api_feature_enable_disable_t *mp;
16209 f64 timeout;
16210 u8 *arc_name = 0;
16211 u8 *feature_name = 0;
16212 u32 sw_if_index = ~0;
16213 u8 enable = 1;
16214
16215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16216 {
16217 if (unformat (i, "arc_name %s", &arc_name))
16218 ;
16219 else if (unformat (i, "feature_name %s", &feature_name))
16220 ;
16221 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16222 ;
16223 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16224 ;
16225 else if (unformat (i, "disable"))
16226 enable = 0;
16227 else
16228 break;
16229 }
16230
16231 if (arc_name == 0)
16232 {
16233 errmsg ("missing arc name\n");
16234 return -99;
16235 }
16236 if (vec_len (arc_name) > 63)
16237 {
16238 errmsg ("arc name too long\n");
16239 }
16240
16241 if (feature_name == 0)
16242 {
16243 errmsg ("missing feature name\n");
16244 return -99;
16245 }
16246 if (vec_len (feature_name) > 63)
16247 {
16248 errmsg ("feature name too long\n");
16249 }
16250
16251 if (sw_if_index == ~0)
16252 {
16253 errmsg ("missing interface name or sw_if_index\n");
16254 return -99;
16255 }
16256
16257 /* Construct the API message */
16258 M (FEATURE_ENABLE_DISABLE, feature_enable_disable);
16259 mp->sw_if_index = ntohl (sw_if_index);
16260 mp->enable = enable;
16261 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
16262 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
16263 vec_free (arc_name);
16264 vec_free (feature_name);
16265
16266 S;
16267 W;
16268}
16269
16270static int
Dave Barach72d72232016-08-04 10:15:08 -040016271q_or_quit (vat_main_t * vam)
16272{
16273 longjmp (vam->jump_buf, 1);
16274 return 0; /* not so much */
16275}
16276
16277static int
16278q (vat_main_t * vam)
16279{
16280 return q_or_quit (vam);
16281}
16282
16283static int
16284quit (vat_main_t * vam)
16285{
16286 return q_or_quit (vam);
16287}
16288
16289static int
16290comment (vat_main_t * vam)
16291{
16292 return 0;
16293}
16294
16295static int
16296cmd_cmp (void *a1, void *a2)
16297{
16298 u8 **c1 = a1;
16299 u8 **c2 = a2;
16300
16301 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
16302}
16303
16304static int
16305help (vat_main_t * vam)
16306{
16307 u8 **cmds = 0;
16308 u8 *name = 0;
16309 hash_pair_t *p;
16310 unformat_input_t *i = vam->input;
16311 int j;
16312
16313 if (unformat (i, "%s", &name))
16314 {
16315 uword *hs;
16316
16317 vec_add1 (name, 0);
16318
16319 hs = hash_get_mem (vam->help_by_name, name);
16320 if (hs)
16321 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
16322 else
16323 fformat (vam->ofp, "No such msg / command '%s'\n", name);
16324 vec_free (name);
16325 return 0;
16326 }
16327
16328 fformat (vam->ofp, "Help is available for the following:\n");
16329
16330 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016331 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070016332 ({
Dave Barach72d72232016-08-04 10:15:08 -040016333 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016334 }));
Dave Barach72d72232016-08-04 10:15:08 -040016335 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016336
Dave Barach72d72232016-08-04 10:15:08 -040016337 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016338
Dave Barach72d72232016-08-04 10:15:08 -040016339 for (j = 0; j < vec_len (cmds); j++)
16340 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016341
Dave Barach72d72232016-08-04 10:15:08 -040016342 vec_free (cmds);
16343 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016344}
16345
Dave Barach72d72232016-08-04 10:15:08 -040016346static int
16347set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016348{
Dave Barach72d72232016-08-04 10:15:08 -040016349 u8 *name = 0, *value = 0;
16350 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016351
Dave Barach72d72232016-08-04 10:15:08 -040016352 if (unformat (i, "%s", &name))
16353 {
16354 /* The input buffer is a vector, not a string. */
16355 value = vec_dup (i->buffer);
16356 vec_delete (value, i->index, 0);
16357 /* Almost certainly has a trailing newline */
16358 if (value[vec_len (value) - 1] == '\n')
16359 value[vec_len (value) - 1] = 0;
16360 /* Make sure it's a proper string, one way or the other */
16361 vec_add1 (value, 0);
16362 (void) clib_macro_set_value (&vam->macro_main,
16363 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016364 }
Dave Barach72d72232016-08-04 10:15:08 -040016365 else
16366 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070016367
Dave Barach72d72232016-08-04 10:15:08 -040016368 vec_free (name);
16369 vec_free (value);
16370 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016371}
16372
Dave Barach72d72232016-08-04 10:15:08 -040016373static int
16374unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016375{
Dave Barach72d72232016-08-04 10:15:08 -040016376 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016377
Dave Barach72d72232016-08-04 10:15:08 -040016378 if (unformat (vam->input, "%s", &name))
16379 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
16380 errmsg ("unset: %s wasn't set\n", name);
16381 vec_free (name);
16382 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016383}
16384
Dave Barach72d72232016-08-04 10:15:08 -040016385typedef struct
16386{
16387 u8 *name;
16388 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016389} macro_sort_t;
16390
16391
Dave Barach72d72232016-08-04 10:15:08 -040016392static int
16393macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016394{
Dave Barach72d72232016-08-04 10:15:08 -040016395 macro_sort_t *s1 = a1;
16396 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016397
Dave Barach72d72232016-08-04 10:15:08 -040016398 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016399}
16400
Dave Barach72d72232016-08-04 10:15:08 -040016401static int
16402dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016403{
Dave Barach72d72232016-08-04 10:15:08 -040016404 macro_sort_t *sort_me = 0, *sm;
16405 int i;
16406 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016407
Dave Barach72d72232016-08-04 10:15:08 -040016408 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016409 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070016410 ({
Dave Barach72d72232016-08-04 10:15:08 -040016411 vec_add2 (sort_me, sm, 1);
16412 sm->name = (u8 *)(p->key);
16413 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016414 }));
Dave Barach72d72232016-08-04 10:15:08 -040016415 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016416
Dave Barach72d72232016-08-04 10:15:08 -040016417 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016418
Dave Barach72d72232016-08-04 10:15:08 -040016419 if (vec_len (sort_me))
16420 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
16421 else
16422 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070016423
Dave Barach72d72232016-08-04 10:15:08 -040016424 for (i = 0; i < vec_len (sort_me); i++)
16425 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
16426 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016427}
16428
Dave Barach72d72232016-08-04 10:15:08 -040016429static int
16430dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016431{
Dave Barach72d72232016-08-04 10:15:08 -040016432 int i, j;
16433 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016434
Dave Barach72d72232016-08-04 10:15:08 -040016435 if (vec_len (vam->graph_nodes) == 0)
16436 {
16437 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16438 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016439 }
16440
Dave Barach72d72232016-08-04 10:15:08 -040016441 for (i = 0; i < vec_len (vam->graph_nodes); i++)
16442 {
16443 node = vam->graph_nodes[i];
16444 fformat (vam->ofp, "[%d] %s\n", i, node->name);
16445 for (j = 0; j < vec_len (node->next_nodes); j++)
16446 {
16447 if (node->next_nodes[j] != ~0)
16448 {
16449 next_node = vam->graph_nodes[node->next_nodes[j]];
16450 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16451 }
16452 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016453 }
Dave Barach72d72232016-08-04 10:15:08 -040016454 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016455}
16456
Dave Barach72d72232016-08-04 10:15:08 -040016457static int
Dave Barach557d1282016-11-10 14:22:49 -050016458value_sort_cmp (void *a1, void *a2)
16459{
16460 name_sort_t *n1 = a1;
16461 name_sort_t *n2 = a2;
16462
16463 if (n1->value < n2->value)
16464 return -1;
16465 if (n1->value > n2->value)
16466 return 1;
16467 return 0;
16468}
16469
16470
16471static int
16472dump_msg_api_table (vat_main_t * vam)
16473{
16474 api_main_t *am = &api_main;
16475 name_sort_t *nses = 0, *ns;
16476 hash_pair_t *hp;
16477 int i;
16478
16479 /* *INDENT-OFF* */
16480 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
16481 ({
16482 vec_add2 (nses, ns, 1);
16483 ns->name = (u8 *)(hp->key);
16484 ns->value = (u32) hp->value[0];
16485 }));
16486 /* *INDENT-ON* */
16487
16488 vec_sort_with_function (nses, value_sort_cmp);
16489
16490 for (i = 0; i < vec_len (nses); i++)
16491 fformat (vam->ofp, " [%d]: %s\n", nses[i].value, nses[i].name);
16492 vec_free (nses);
16493 return 0;
16494}
16495
16496static int
16497get_msg_id (vat_main_t * vam)
16498{
16499 u8 *name_and_crc;
16500 u32 message_index;
16501
16502 if (unformat (vam->input, "%s", &name_and_crc))
16503 {
16504 message_index = vl_api_get_msg_index (name_and_crc);
16505 if (message_index == ~0)
16506 {
16507 fformat (vam->ofp, " '%s' not found\n", name_and_crc);
16508 return 0;
16509 }
16510 fformat (vam->ofp, " '%s' has message index %d\n",
16511 name_and_crc, message_index);
16512 return 0;
16513 }
16514 errmsg ("name_and_crc required...\n");
16515 return 0;
16516}
16517
16518static int
Dave Barach72d72232016-08-04 10:15:08 -040016519search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016520{
Dave Barach72d72232016-08-04 10:15:08 -040016521 unformat_input_t *line_input = vam->input;
16522 u8 *node_to_find;
16523 int j;
16524 vlib_node_t *node, *next_node;
16525 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016526
Dave Barach72d72232016-08-04 10:15:08 -040016527 if (vam->graph_node_index_by_name == 0)
16528 {
16529 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16530 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016531 }
16532
Dave Barach72d72232016-08-04 10:15:08 -040016533 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
16534 {
16535 if (unformat (line_input, "%s", &node_to_find))
16536 {
16537 vec_add1 (node_to_find, 0);
16538 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
16539 if (p == 0)
16540 {
16541 fformat (vam->ofp, "%s not found...\n", node_to_find);
16542 goto out;
16543 }
16544 node = vam->graph_nodes[p[0]];
16545 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
16546 for (j = 0; j < vec_len (node->next_nodes); j++)
16547 {
16548 if (node->next_nodes[j] != ~0)
16549 {
16550 next_node = vam->graph_nodes[node->next_nodes[j]];
16551 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16552 }
16553 }
16554 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016555
Dave Barach72d72232016-08-04 10:15:08 -040016556 else
16557 {
16558 clib_warning ("parse error '%U'", format_unformat_error,
16559 line_input);
16560 return -99;
16561 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016562
16563 out:
Dave Barach72d72232016-08-04 10:15:08 -040016564 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016565
Dave Barachb44e9bc2016-02-19 09:06:23 -050016566 }
16567
Dave Barach72d72232016-08-04 10:15:08 -040016568 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016569}
16570
16571
Dave Barach72d72232016-08-04 10:15:08 -040016572static int
16573script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016574{
Dave Barach72d72232016-08-04 10:15:08 -040016575 u8 *s = 0;
16576 char *save_current_file;
16577 unformat_input_t save_input;
16578 jmp_buf save_jump_buf;
16579 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016580
Dave Barach72d72232016-08-04 10:15:08 -040016581 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016582
Dave Barach72d72232016-08-04 10:15:08 -040016583 if (unformat (vam->input, "%s", &s))
16584 {
16585 new_fp = fopen ((char *) s, "r");
16586 if (new_fp == 0)
16587 {
16588 errmsg ("Couldn't open script file %s\n", s);
16589 vec_free (s);
16590 return -99;
16591 }
16592 }
16593 else
16594 {
16595 errmsg ("Missing script name\n");
16596 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016597 }
16598
Dave Barach72d72232016-08-04 10:15:08 -040016599 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
16600 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
16601 save_ifp = vam->ifp;
16602 save_line_number = vam->input_line_number;
16603 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016604
Dave Barach72d72232016-08-04 10:15:08 -040016605 vam->input_line_number = 0;
16606 vam->ifp = new_fp;
16607 vam->current_file = s;
16608 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016609
Dave Barach72d72232016-08-04 10:15:08 -040016610 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
16611 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
16612 vam->ifp = save_ifp;
16613 vam->input_line_number = save_line_number;
16614 vam->current_file = (u8 *) save_current_file;
16615 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016616
Dave Barach72d72232016-08-04 10:15:08 -040016617 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016618}
16619
Dave Barach72d72232016-08-04 10:15:08 -040016620static int
16621echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016622{
Dave Barach72d72232016-08-04 10:15:08 -040016623 fformat (vam->ofp, "%v", vam->input->buffer);
16624 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016625}
16626
16627/* List of API message constructors, CLI names map to api_xxx */
16628#define foreach_vpe_api_msg \
16629_(create_loopback,"[mac <mac-addr>]") \
16630_(sw_interface_dump,"") \
16631_(sw_interface_set_flags, \
16632 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
16633_(sw_interface_add_del_address, \
16634 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
16635_(sw_interface_set_table, \
16636 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040016637_(sw_interface_set_mpls_enable, \
16638 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016639_(sw_interface_set_vpath, \
16640 "<intfc> | sw_if_index <id> enable | disable") \
16641_(sw_interface_set_l2_xconnect, \
16642 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16643 "enable | disable") \
16644_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040016645 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016646 "[shg <split-horizon-group>] [bvi]\n" \
16647 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010016648_(sw_interface_set_dpdk_hqos_pipe, \
16649 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
16650 "profile <profile-id>\n") \
16651_(sw_interface_set_dpdk_hqos_subport, \
16652 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
16653 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
16654_(sw_interface_set_dpdk_hqos_tctbl, \
16655 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016656_(bridge_domain_add_del, \
16657 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
16658_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
16659_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070016660 "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 -070016661_(l2_flags, \
16662 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
16663_(bridge_flags, \
16664 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
16665_(tap_connect, \
16666 "tapname <name> mac <mac-addr> | random-mac") \
16667_(tap_modify, \
16668 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
16669_(tap_delete, \
16670 "<vpp-if-name> | sw_if_index <id>") \
16671_(sw_interface_tap_dump, "") \
16672_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016673 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016674 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16675 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16676 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016677_(mpls_route_add_del, \
16678 "<label> <eos> via <addr> [table-id <n>]\n" \
16679 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16680 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16681 "[multipath] [count <n>]") \
16682_(mpls_ip_bind_unbind, \
16683 "<label> <addr/len>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016684_(proxy_arp_add_del, \
16685 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
16686_(proxy_arp_intfc_enable_disable, \
16687 "<intfc> | sw_if_index <id> enable | disable") \
16688_(mpls_add_del_encap, \
16689 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016690_(sw_interface_set_unnumbered, \
16691 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
16692_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040016693 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
16694 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016695_(reset_vrf, "vrf <id> [ipv6]") \
16696_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
16697_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
16698 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
16699 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
16700 "[outer_vlan_id_any][inner_vlan_id_any]") \
16701_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
16702_(reset_fib, "vrf <n> [ipv6]") \
16703_(dhcp_proxy_config, \
16704 "svr <v46-address> src <v46-address>\n" \
16705 "insert-cid <n> [del]") \
16706_(dhcp_proxy_config_2, \
16707 "svr <v46-address> src <v46-address>\n" \
16708 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
16709_(dhcp_proxy_set_vss, \
16710 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
16711_(dhcp_client_config, \
16712 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
16713_(set_ip_flow_hash, \
16714 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
16715_(sw_interface_ip6_enable_disable, \
16716 "<intfc> | sw_if_index <id> enable | disable") \
16717_(sw_interface_ip6_set_link_local_address, \
16718 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
16719_(sw_interface_ip6nd_ra_prefix, \
16720 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
16721 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
16722 "[nolink] [isno]") \
16723_(sw_interface_ip6nd_ra_config, \
16724 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040016725 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016726 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
16727_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
16728_(l2_patch_add_del, \
16729 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16730 "enable | disable") \
16731_(mpls_ethernet_add_del_tunnel, \
16732 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
16733 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
16734_(mpls_ethernet_add_del_tunnel_2, \
16735 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
16736 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
16737_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070016738 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
16739 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
16740 "[policy <policy_name>]") \
16741_(sr_policy_add_del, \
16742 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
16743_(sr_multicast_map_add_del, \
16744 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016745_(classify_add_del_table, \
16746 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080016747 " [del] mask <mask-value>\n" \
16748 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
16749 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016750_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016751 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
16752 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080016753 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
16754 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016755_(classify_set_interface_ip_table, \
16756 "<intfc> | sw_if_index <nn> table <nn>") \
16757_(classify_set_interface_l2_tables, \
16758 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16759 " [other-table <nn>]") \
16760_(get_node_index, "node <node-name") \
16761_(add_node_next, "node <node-name> next <next-node-name>") \
16762_(l2tpv3_create_tunnel, \
16763 "client_address <ip6-addr> our_address <ip6-addr>\n" \
16764 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
16765 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
16766_(l2tpv3_set_tunnel_cookies, \
16767 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
16768 "[new_remote_cookie <nn>]\n") \
16769_(l2tpv3_interface_enable_disable, \
16770 "<intfc> | sw_if_index <nn> enable | disable") \
16771_(l2tpv3_set_lookup_key, \
16772 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
16773_(sw_if_l2tpv3_tunnel_dump, "") \
16774_(vxlan_add_del_tunnel, \
Chris Luke404be662016-05-27 12:11:24 -040016775 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016776 " [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050016777_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016778_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070016779 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016780_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016781_(l2_fib_clear_table, "") \
16782_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
16783_(l2_interface_vlan_tag_rewrite, \
16784 "<intfc> | sw_if_index <nn> \n" \
16785 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
16786 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
16787_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000016788 "socket <filename> [server] [renumber <dev_instance>] " \
16789 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016790_(modify_vhost_user_if, \
16791 "<intfc> | sw_if_index <nn> socket <filename>\n" \
16792 "[server] [renumber <dev_instance>]") \
16793_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
16794_(sw_interface_vhost_user_dump, "") \
16795_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080016796_(vxlan_gpe_add_del_tunnel, \
16797 "local <addr> remote <addr> vni <nn>\n" \
16798 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
16799 "[next-ethernet] [next-nsh]\n") \
16800_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016801_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016802_(interface_name_renumber, \
16803 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
16804_(input_acl_set_interface, \
16805 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16806 " [l2-table <nn>] [del]") \
16807_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040016808_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016809_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
16810_(ip_dump, "ipv4 | ipv6") \
16811_(ipsec_spd_add_del, "spd_id <n> [del]") \
16812_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
16813 " spid_id <n> ") \
16814_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
16815 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
16816 " integ_alg <alg> integ_key <hex>") \
16817_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
16818 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
16819 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
16820 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
16821_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020016822_(ikev2_profile_add_del, "name <profile_name> [del]") \
16823_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
16824 "(auth_data 0x<data> | auth_data <data>)") \
16825_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
16826 "(id_data 0x<data> | id_data <data>) (local|remote)") \
16827_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
16828 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
16829 "(local|remote)") \
16830_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016831_(delete_loopback,"sw_if_index <nn>") \
16832_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
16833_(map_add_domain, \
16834 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
16835 "ip6-src <ip6addr> " \
16836 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
16837_(map_del_domain, "index <n>") \
16838_(map_add_del_rule, \
16839 "index <n> psid <n> dst <ip6addr> [del]") \
16840_(map_domain_dump, "") \
16841_(map_rule_dump, "index <map-domain>") \
16842_(want_interface_events, "enable|disable") \
16843_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050016844_(get_first_msg_id, "client <name>") \
16845_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
16846_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016847 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010016848_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000016849_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070016850_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
16851_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020016852_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
16853 " sw_if_index <sw_if_index> p <priority> " \
16854 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016855_(lisp_add_del_locator, "locator-set <locator_name> " \
16856 "iface <intf> | sw_if_index <sw_if_index> " \
16857 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016858_(lisp_add_del_local_eid,"vni <vni> eid " \
16859 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016860 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020016861_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
16862 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016863_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020016864_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020016865_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016866_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016867_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
16868 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016869 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020016870 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016871 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020016872_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
16873 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020016874_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020016875_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016876_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020016877_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016878_(lisp_locator_set_dump, "[local | remote]") \
16879_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020016880_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
16881 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020016882_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020016883_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016884_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020016885_(lisp_map_resolver_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020016886_(lisp_adjacencies_get, "vni <vni>") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016887_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016888_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020016889_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020016890_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020016891_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070016892_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016893_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070016894_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016895_(policer_classify_set_interface, \
16896 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16897 " [l2-table <nn>] [del]") \
16898_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016899_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
16900 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020016901_(netmap_delete, "name <interface name>") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020016902_(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
16903_(mpls_fib_encap_dump, "") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016904_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020016905_(classify_table_ids, "") \
16906_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
16907_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070016908_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070016909_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
16910 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
16911 "[template_interval <nn>] [udp_checksum]") \
16912_(ipfix_exporter_dump, "") \
16913_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
16914_(ipfix_classify_stream_dump, "") \
16915_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
16916_(ipfix_classify_table_dump, "") \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016917_(sw_interface_span_enable_disable, "[src <intfc> | src_sw_if_index <id>] [[dst <intfc> | dst_sw_if_index <id>] | disable]") \
16918_(sw_interface_span_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020016919_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
16920_(pg_create_interface, "if_id <nn>") \
16921_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040016922_(pg_enable_disable, "[stream <id>] disable") \
16923_(ip_source_and_port_range_check_add_del, \
16924 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
16925_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070016926 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070016927 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
16928_(ipsec_gre_add_del_tunnel, \
16929 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016930_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016931_(delete_subif,"<intfc> | sw_if_index <nn>") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020016932_(l2_interface_pbb_tag_rewrite, \
16933 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016934 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
16935 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070016936_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
16937_(flow_classify_set_interface, \
16938 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
Steven01b07122016-11-02 10:40:09 -070016939_(flow_classify_dump, "type [ip4|ip6]") \
16940_(ip_fib_dump, "") \
Pavel Kotucek7490a752016-11-15 09:19:11 +010016941_(ip6_fib_dump, "") \
16942_(feature_enable_disable, "arc_name <arc_name> " \
16943 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070016944
16945/* List of command functions, CLI names map directly to functions */
16946#define foreach_cli_function \
16947_(comment, "usage: comment <ignore-rest-of-line>") \
16948_(dump_interface_table, "usage: dump_interface_table") \
16949_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
16950_(dump_ipv4_table, "usage: dump_ipv4_table") \
16951_(dump_ipv6_table, "usage: dump_ipv6_table") \
16952_(dump_stats_table, "usage: dump_stats_table") \
16953_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016954_(dump_node_table, "usage: dump_node_table") \
Dave Barach557d1282016-11-10 14:22:49 -050016955_(dump_msg_api_table, "usage: dump_msg_api_table") \
16956_(get_msg_id, "usage: get_msg_id name_and_crc") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016957_(echo, "usage: echo <message>") \
16958_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020016959_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016960_(help, "usage: help") \
16961_(q, "usage: quit") \
16962_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016963_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016964_(set, "usage: set <variable-name> <value>") \
16965_(script, "usage: script <file-name>") \
16966_(unset, "usage: unset <variable-name>")
16967
16968#define _(N,n) \
16969 static void vl_api_##n##_t_handler_uni \
16970 (vl_api_##n##_t * mp) \
16971 { \
16972 vat_main_t * vam = &vat_main; \
16973 if (vam->json_output) { \
16974 vl_api_##n##_t_handler_json(mp); \
16975 } else { \
16976 vl_api_##n##_t_handler(mp); \
16977 } \
16978 }
16979foreach_vpe_api_reply_msg;
16980#undef _
16981
Dave Barach72d72232016-08-04 10:15:08 -040016982void
16983vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016984{
16985#define _(N,n) \
16986 vl_msg_api_set_handlers(VL_API_##N, #n, \
16987 vl_api_##n##_t_handler_uni, \
16988 vl_noop_handler, \
16989 vl_api_##n##_t_endian, \
16990 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016991 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040016992 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016993#undef _
16994
Dave Barach72d72232016-08-04 10:15:08 -040016995 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016996
Dave Barach72d72232016-08-04 10:15:08 -040016997 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016998
Dave Barach72d72232016-08-04 10:15:08 -040016999 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017000
Dave Barach72d72232016-08-04 10:15:08 -040017001 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017002
Dave Barach72d72232016-08-04 10:15:08 -040017003 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017004#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040017005 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017006#undef _
17007
Dave Barach72d72232016-08-04 10:15:08 -040017008 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017009#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017010 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017011#undef _
17012
Dave Barach72d72232016-08-04 10:15:08 -040017013 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017014#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040017015 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017016#undef _
17017
Dave Barach72d72232016-08-04 10:15:08 -040017018 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017019#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017020 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017021#undef _
17022}
17023
17024#undef vl_api_version
Dave Barachaff70772016-10-31 11:59:07 -040017025#define vl_api_version(n,v) static u32 memory_api_version = v;
17026#include <vlibmemory/vl_memory_api_h.h>
17027#undef vl_api_version
17028
17029#undef vl_api_version
17030#define vl_api_version(n,v) static u32 vnet_interface_api_version = v;
17031#include <vnet/interface.api.h>
17032#undef vl_api_version
17033
17034#undef vl_api_version
17035#define vl_api_version(n,v) static u32 vpp_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040017036#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070017037#undef vl_api_version
17038
Dave Barachaff70772016-10-31 11:59:07 -040017039static u32 *api_versions[] = {
17040 &memory_api_version,
17041 &vnet_interface_api_version,
17042 &vpp_api_version,
17043};
17044
Dave Barach72d72232016-08-04 10:15:08 -040017045void
17046vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017047{
Dave Barachaff70772016-10-31 11:59:07 -040017048 int i;
17049
17050 ASSERT (ARRAY_LEN (mp->api_versions) >= ARRAY_LEN (api_versions));
17051
Dave Barach72d72232016-08-04 10:15:08 -040017052 /*
Dave Barachaff70772016-10-31 11:59:07 -040017053 * Send the API signatures. This bit of code must
Dave Barach72d72232016-08-04 10:15:08 -040017054 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
17055 */
Dave Barachaff70772016-10-31 11:59:07 -040017056
17057 for (i = 0; i < ARRAY_LEN (api_versions); i++)
17058 mp->api_versions[i] = clib_host_to_net_u32 (*api_versions[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017059}
Dave Barach72d72232016-08-04 10:15:08 -040017060
17061/*
17062 * fd.io coding-style-patch-verification: ON
17063 *
17064 * Local Variables:
17065 * eval: (c-set-style "gnu")
17066 * End:
17067 */