blob: 9d80c42aba2be477e0d16fef954e78d4ce38d5b5 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07005 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016 * limitations under the License.
Ed Warnickecb9cada2015-12-08 15:45:58 -070017 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlibapi/api.h>
22#include <vlibmemory/api.h>
23#include <vlibsocket/api.h>
24#include <vnet/ip/ip.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/l2/l2_input.h>
27#include <vnet/l2tp/l2tp.h>
28#include <vnet/vxlan/vxlan.h>
Chris Luke27fe48f2016-04-28 13:44:38 -040029#include <vnet/gre/gre.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031#include <vnet/lisp-gpe/lisp_gpe.h>
32
Dave Barachaa6920e2016-06-27 09:25:13 -040033#include <vpp-api/vpe_msg_enum.h>
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080034#include <vnet/l2/l2_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#include <vnet/l2/l2_vtr.h>
36#include <vnet/classify/input_acl.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070037#include <vnet/classify/policer_classify.h>
Juraj Sloboda506b2452016-08-07 23:45:24 -070038#include <vnet/classify/flow_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039#include <vnet/mpls/mpls.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#include <vnet/ipsec/ipsec.h>
Matus Fabiane5f42fe2016-04-08 11:18:08 +020041#include <vnet/ipsec/ikev2.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050042#include <inttypes.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070043#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050044#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000045#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040046#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070047#include <vnet/policer/xlate.h>
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010048#include <vnet/span/span.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070049#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070050#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
52#include "vat/json_format.h"
53
Damjan Marion67655492016-11-15 12:50:28 +010054#include <inttypes.h>
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020055#include <sys/stat.h>
56
Dave Barach72d72232016-08-04 10:15:08 -040057#define vl_typedefs /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080058#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070059#undef vl_typedefs
60
61/* declare message handlers for each api */
62
Dave Barach72d72232016-08-04 10:15:08 -040063#define vl_endianfun /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080064#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070065#undef vl_endianfun
66
67/* instantiate all the print functions we know about */
68#define vl_print(handle, ...)
69#define vl_printfun
Dave Barachaa6920e2016-06-27 09:25:13 -040070#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#undef vl_printfun
72
Dave Barach72d72232016-08-04 10:15:08 -040073uword
74unformat_sw_if_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
Dave Barach72d72232016-08-04 10:15:08 -040076 vat_main_t *vam = va_arg (*args, vat_main_t *);
77 u32 *result = va_arg (*args, u32 *);
78 u8 *if_name;
79 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 if (!unformat (input, "%s", &if_name))
Dave Barach72d72232016-08-04 10:15:08 -040082 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
84 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
85 if (p == 0)
Dave Barach72d72232016-08-04 10:15:08 -040086 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 *result = p[0];
88 return 1;
89}
90
91/* Parse an IP4 address %d.%d.%d.%d. */
Dave Barach72d72232016-08-04 10:15:08 -040092uword
93unformat_ip4_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070094{
Dave Barach72d72232016-08-04 10:15:08 -040095 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 unsigned a[4];
97
Dave Barach72d72232016-08-04 10:15:08 -040098 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 return 0;
100
101 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 return 0;
103
104 result[0] = a[0];
105 result[1] = a[1];
106 result[2] = a[2];
107 result[3] = a[3];
108
109 return 1;
110}
111
112
113uword
114unformat_ethernet_address (unformat_input_t * input, va_list * args)
115{
Dave Barach72d72232016-08-04 10:15:08 -0400116 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u32 i, a[6];
118
Dave Barach72d72232016-08-04 10:15:08 -0400119 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
120 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 return 0;
122
123 /* Check range. */
124 for (i = 0; i < 6; i++)
125 if (a[i] >= (1 << 8))
126 return 0;
127
128 for (i = 0; i < 6; i++)
129 result[i] = a[i];
130
131 return 1;
132}
133
134/* Returns ethernet type as an int in host byte order. */
135uword
136unformat_ethernet_type_host_byte_order (unformat_input_t * input,
137 va_list * args)
138{
Dave Barach72d72232016-08-04 10:15:08 -0400139 u16 *result = va_arg (*args, u16 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140 int type;
141
142 /* Numeric type. */
Dave Barach72d72232016-08-04 10:15:08 -0400143 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 {
145 if (type >= (1 << 16))
146 return 0;
147 *result = type;
148 return 1;
149 }
150 return 0;
151}
152
153/* Parse an IP6 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400154uword
155unformat_ip6_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156{
Dave Barach72d72232016-08-04 10:15:08 -0400157 ip6_address_t *result = va_arg (*args, ip6_address_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 u16 hex_quads[8];
159 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
160 uword c, n_colon, double_colon_index;
161
162 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
163 double_colon_index = ARRAY_LEN (hex_quads);
164 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
165 {
166 hex_digit = 16;
167 if (c >= '0' && c <= '9')
168 hex_digit = c - '0';
169 else if (c >= 'a' && c <= 'f')
170 hex_digit = c + 10 - 'a';
171 else if (c >= 'A' && c <= 'F')
172 hex_digit = c + 10 - 'A';
173 else if (c == ':' && n_colon < 2)
174 n_colon++;
175 else
176 {
177 unformat_put_input (input);
178 break;
179 }
180
181 /* Too many hex quads. */
182 if (n_hex_quads >= ARRAY_LEN (hex_quads))
183 return 0;
184
185 if (hex_digit < 16)
186 {
187 hex_quad = (hex_quad << 4) | hex_digit;
188
189 /* Hex quad must fit in 16 bits. */
190 if (n_hex_digits >= 4)
191 return 0;
192
193 n_colon = 0;
194 n_hex_digits++;
195 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800196
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197 /* Save position of :: */
198 if (n_colon == 2)
199 {
200 /* More than one :: ? */
201 if (double_colon_index < ARRAY_LEN (hex_quads))
202 return 0;
203 double_colon_index = n_hex_quads;
204 }
205
206 if (n_colon > 0 && n_hex_digits > 0)
207 {
208 hex_quads[n_hex_quads++] = hex_quad;
209 hex_quad = 0;
210 n_hex_digits = 0;
211 }
212 }
213
214 if (n_hex_digits > 0)
215 hex_quads[n_hex_quads++] = hex_quad;
216
217 {
218 word i;
219
220 /* Expand :: to appropriate number of zero hex quads. */
221 if (double_colon_index < ARRAY_LEN (hex_quads))
222 {
223 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
224
225 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
226 hex_quads[n_zero + i] = hex_quads[i];
227
228 for (i = 0; i < n_zero; i++)
229 hex_quads[double_colon_index + i] = 0;
230
231 n_hex_quads = ARRAY_LEN (hex_quads);
232 }
233
234 /* Too few hex quads given. */
235 if (n_hex_quads < ARRAY_LEN (hex_quads))
236 return 0;
237
238 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
239 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
240
241 return 1;
242 }
243}
244
245uword
246unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
247{
Dave Barach72d72232016-08-04 10:15:08 -0400248 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249
Dave Barach72d72232016-08-04 10:15:08 -0400250 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
252 foreach_ipsec_policy_action
253#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400254 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255 return 0;
256 return 1;
257}
258
259uword
260unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
261{
Dave Barach72d72232016-08-04 10:15:08 -0400262 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263
Dave Barach72d72232016-08-04 10:15:08 -0400264 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
266 foreach_ipsec_crypto_alg
267#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400268 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269 return 0;
270 return 1;
271}
272
273u8 *
274format_ipsec_crypto_alg (u8 * s, va_list * args)
275{
276 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400277 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
279 switch (i)
280 {
281#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400282 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400284 default:
285 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286 }
287 return format (s, "%s", t);
288}
289
290uword
291unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
292{
Dave Barach72d72232016-08-04 10:15:08 -0400293 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
Dave Barach72d72232016-08-04 10:15:08 -0400295 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
297 foreach_ipsec_integ_alg
298#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400299 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300 return 0;
301 return 1;
302}
303
304u8 *
305format_ipsec_integ_alg (u8 * s, va_list * args)
306{
307 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400308 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309
310 switch (i)
311 {
312#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400313 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400315 default:
316 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317 }
318 return format (s, "%s", t);
319}
320
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200321uword
322unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
323{
Dave Barach72d72232016-08-04 10:15:08 -0400324 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200325
Dave Barach72d72232016-08-04 10:15:08 -0400326 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200327#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
328 foreach_ikev2_auth_method
329#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400330 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200331 return 0;
332 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200333}
334
335uword
336unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
337{
Dave Barach72d72232016-08-04 10:15:08 -0400338 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200339
Dave Barach72d72232016-08-04 10:15:08 -0400340 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200341#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
342 foreach_ikev2_id_type
343#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400344 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200345 return 0;
346 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200347}
348
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700349uword
350unformat_policer_rate_type (unformat_input_t * input, va_list * args)
351{
Dave Barach72d72232016-08-04 10:15:08 -0400352 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700353
354 if (unformat (input, "kbps"))
355 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400356 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700357 *r = SSE2_QOS_RATE_PPS;
358 else
359 return 0;
360 return 1;
361}
362
363uword
364unformat_policer_round_type (unformat_input_t * input, va_list * args)
365{
Dave Barach72d72232016-08-04 10:15:08 -0400366 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700367
Dave Barach72d72232016-08-04 10:15:08 -0400368 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700369 *r = SSE2_QOS_ROUND_TO_CLOSEST;
370 else if (unformat (input, "up"))
371 *r = SSE2_QOS_ROUND_TO_UP;
372 else if (unformat (input, "down"))
373 *r = SSE2_QOS_ROUND_TO_DOWN;
374 else
375 return 0;
376 return 1;
377}
378
379uword
380unformat_policer_type (unformat_input_t * input, va_list * args)
381{
Dave Barach72d72232016-08-04 10:15:08 -0400382 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700383
384 if (unformat (input, "1r2c"))
385 *r = SSE2_QOS_POLICER_TYPE_1R2C;
386 else if (unformat (input, "1r3c"))
387 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
388 else if (unformat (input, "2r3c-2698"))
389 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
390 else if (unformat (input, "2r3c-4115"))
391 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
392 else if (unformat (input, "2r3c-mef5cf1"))
393 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
394 else
395 return 0;
396 return 1;
397}
398
Matus Fabian4ac74c92016-05-31 07:33:29 -0700399uword
400unformat_dscp (unformat_input_t * input, va_list * va)
401{
Dave Barach72d72232016-08-04 10:15:08 -0400402 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700403
Dave Barach72d72232016-08-04 10:15:08 -0400404 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700405#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400406 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700407#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400408 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700409 return 0;
410 return 1;
411}
412
413uword
414unformat_policer_action_type (unformat_input_t * input, va_list * va)
415{
Dave Barach72d72232016-08-04 10:15:08 -0400416 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700417 = va_arg (*va, sse2_qos_pol_action_params_st *);
418
419 if (unformat (input, "drop"))
420 a->action_type = SSE2_QOS_ACTION_DROP;
421 else if (unformat (input, "transmit"))
422 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
423 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
424 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
425 else
426 return 0;
427 return 1;
428}
429
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700430uword
Juraj Sloboda506b2452016-08-07 23:45:24 -0700431unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700432{
Dave Barach72d72232016-08-04 10:15:08 -0400433 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700434 u32 tid;
435
436 if (unformat (input, "ip4"))
437 tid = POLICER_CLASSIFY_TABLE_IP4;
438 else if (unformat (input, "ip6"))
439 tid = POLICER_CLASSIFY_TABLE_IP6;
440 else if (unformat (input, "l2"))
441 tid = POLICER_CLASSIFY_TABLE_L2;
442 else
443 return 0;
444
445 *r = tid;
446 return 1;
447}
448
Juraj Sloboda506b2452016-08-07 23:45:24 -0700449uword
450unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
451{
452 u32 *r = va_arg (*va, u32 *);
453 u32 tid;
454
455 if (unformat (input, "ip4"))
456 tid = FLOW_CLASSIFY_TABLE_IP4;
457 else if (unformat (input, "ip6"))
458 tid = FLOW_CLASSIFY_TABLE_IP6;
459 else
460 return 0;
461
462 *r = tid;
463 return 1;
464}
465
Dave Barach72d72232016-08-04 10:15:08 -0400466u8 *
467format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468{
Dave Barach72d72232016-08-04 10:15:08 -0400469 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
471}
472
Dave Barach72d72232016-08-04 10:15:08 -0400473u8 *
474format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475{
Dave Barach72d72232016-08-04 10:15:08 -0400476 ip6_address_t *a = va_arg (*args, ip6_address_t *);
477 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478
Dave Barach72d72232016-08-04 10:15:08 -0400479 i_max_n_zero = ARRAY_LEN (a->as_u16);
480 max_n_zeros = 0;
481 i_first_zero = i_max_n_zero;
482 n_zeros = 0;
483 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
484 {
485 u32 is_zero = a->as_u16[i] == 0;
486 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
487 {
488 i_first_zero = i;
489 n_zeros = 0;
490 }
491 n_zeros += is_zero;
492 if ((!is_zero && n_zeros > max_n_zeros)
493 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
494 {
495 i_max_n_zero = i_first_zero;
496 max_n_zeros = n_zeros;
497 i_first_zero = ARRAY_LEN (a->as_u16);
498 n_zeros = 0;
499 }
500 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501
Dave Barach72d72232016-08-04 10:15:08 -0400502 last_double_colon = 0;
503 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
504 {
505 if (i == i_max_n_zero && max_n_zeros > 1)
506 {
507 s = format (s, "::");
508 i += max_n_zeros - 1;
509 last_double_colon = 1;
510 }
511 else
512 {
513 s = format (s, "%s%x",
514 (last_double_colon || i == 0) ? "" : ":",
515 clib_net_to_host_u16 (a->as_u16[i]));
516 last_double_colon = 0;
517 }
518 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519
Dave Barach72d72232016-08-04 10:15:08 -0400520 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521}
522
Chris Luke99cb3352016-04-26 10:49:53 -0400523/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400524u8 *
525format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400526{
527 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200528 ip46_type_t type = va_arg (*args, ip46_type_t);
529 int is_ip4 = 1;
530
531 switch (type)
532 {
Dave Barach72d72232016-08-04 10:15:08 -0400533 case IP46_TYPE_ANY:
534 is_ip4 = ip46_address_is_ip4 (ip46);
535 break;
536 case IP46_TYPE_IP4:
537 is_ip4 = 1;
538 break;
539 case IP46_TYPE_IP6:
540 is_ip4 = 0;
541 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200542 }
543
544 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400545 format (s, "%U", format_ip4_address, &ip46->ip4) :
546 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400547}
548
Dave Barach72d72232016-08-04 10:15:08 -0400549u8 *
550format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700551{
Dave Barach72d72232016-08-04 10:15:08 -0400552 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553
554 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400555 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700556}
557
Dave Barach72d72232016-08-04 10:15:08 -0400558void
559increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700560{
Dave Barach72d72232016-08-04 10:15:08 -0400561 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562
Dave Barach72d72232016-08-04 10:15:08 -0400563 v = ntohl (a->as_u32) + 1;
564 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565}
566
Dave Barach72d72232016-08-04 10:15:08 -0400567void
568increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569{
Dave Barach72d72232016-08-04 10:15:08 -0400570 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571
Dave Barach72d72232016-08-04 10:15:08 -0400572 v0 = clib_net_to_host_u64 (a->as_u64[0]);
573 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700574
Dave Barach72d72232016-08-04 10:15:08 -0400575 v1 += 1;
576 if (v1 == 0)
577 v0 += 1;
578 a->as_u64[0] = clib_net_to_host_u64 (v0);
579 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580}
581
Dave Barach72d72232016-08-04 10:15:08 -0400582void
583increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700584{
Dave Barach72d72232016-08-04 10:15:08 -0400585 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700586
Dave Barach72d72232016-08-04 10:15:08 -0400587 tmp = clib_net_to_host_u64 (tmp);
588 tmp += 1 << 16; /* skip unused (least significant) octets */
589 tmp = clib_host_to_net_u64 (tmp);
590 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700591}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800593static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400594 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700595{
Dave Barach72d72232016-08-04 10:15:08 -0400596 vat_main_t *vam = &vat_main;
597 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598
Dave Barach72d72232016-08-04 10:15:08 -0400599 vam->retval = retval;
600 vam->regenerate_interface_table = 1;
601 vam->sw_if_index = ntohl (mp->sw_if_index);
602 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603}
604
605static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400606 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700607{
Dave Barach72d72232016-08-04 10:15:08 -0400608 vat_main_t *vam = &vat_main;
609 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610
Dave Barach72d72232016-08-04 10:15:08 -0400611 vat_json_init_object (&node);
612 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
613 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
Dave Barach72d72232016-08-04 10:15:08 -0400615 vat_json_print (vam->ofp, &node);
616 vat_json_free (&node);
617 vam->retval = ntohl (mp->retval);
618 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700619}
620
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800621static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400622 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700623{
Dave Barach72d72232016-08-04 10:15:08 -0400624 vat_main_t *vam = &vat_main;
625 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700626
Dave Barach72d72232016-08-04 10:15:08 -0400627 vam->retval = retval;
628 vam->regenerate_interface_table = 1;
629 vam->sw_if_index = ntohl (mp->sw_if_index);
630 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700631}
632
633static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400634 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700635{
Dave Barach72d72232016-08-04 10:15:08 -0400636 vat_main_t *vam = &vat_main;
637 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700638
Dave Barach72d72232016-08-04 10:15:08 -0400639 vat_json_init_object (&node);
640 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
641 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700642
Dave Barach72d72232016-08-04 10:15:08 -0400643 vat_json_print (vam->ofp, &node);
644 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700645
Dave Barach72d72232016-08-04 10:15:08 -0400646 vam->retval = ntohl (mp->retval);
647 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700648}
649
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800650static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400651 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700652{
Dave Barach72d72232016-08-04 10:15:08 -0400653 vat_main_t *vam = &vat_main;
654 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700655
Dave Barach72d72232016-08-04 10:15:08 -0400656 vam->retval = retval;
657 vam->regenerate_interface_table = 1;
658 vam->sw_if_index = ntohl (mp->sw_if_index);
659 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700660}
661
662static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400663 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700664{
Dave Barach72d72232016-08-04 10:15:08 -0400665 vat_main_t *vam = &vat_main;
666 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700667
Dave Barach72d72232016-08-04 10:15:08 -0400668 vat_json_init_object (&node);
669 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
670 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671
Dave Barach72d72232016-08-04 10:15:08 -0400672 vat_json_print (vam->ofp, &node);
673 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674
Dave Barach72d72232016-08-04 10:15:08 -0400675 vam->retval = ntohl (mp->retval);
676 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700677}
678
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800679static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400680 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681{
Dave Barach72d72232016-08-04 10:15:08 -0400682 vat_main_t *vam = &vat_main;
683 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700684
Dave Barach72d72232016-08-04 10:15:08 -0400685 vam->retval = retval;
686 vam->regenerate_interface_table = 1;
687 vam->sw_if_index = ntohl (mp->sw_if_index);
688 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700689}
690
691static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400692 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693{
Dave Barach72d72232016-08-04 10:15:08 -0400694 vat_main_t *vam = &vat_main;
695 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
Dave Barach72d72232016-08-04 10:15:08 -0400697 vat_json_init_object (&node);
698 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
699 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700
Dave Barach72d72232016-08-04 10:15:08 -0400701 vat_json_print (vam->ofp, &node);
702 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703
Dave Barach72d72232016-08-04 10:15:08 -0400704 vam->retval = ntohl (mp->retval);
705 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706}
707
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800708static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400709 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710{
Dave Barach72d72232016-08-04 10:15:08 -0400711 vat_main_t *vam = &vat_main;
712 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713
Dave Barach72d72232016-08-04 10:15:08 -0400714 vam->retval = retval;
715 vam->regenerate_interface_table = 1;
716 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717}
718
719static void vl_api_interface_name_renumber_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400720 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700721{
Dave Barach72d72232016-08-04 10:15:08 -0400722 vat_main_t *vam = &vat_main;
723 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
Dave Barach72d72232016-08-04 10:15:08 -0400725 vat_json_init_object (&node);
726 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700727
Dave Barach72d72232016-08-04 10:15:08 -0400728 vat_json_print (vam->ofp, &node);
729 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700730
Dave Barach72d72232016-08-04 10:15:08 -0400731 vam->retval = ntohl (mp->retval);
732 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700733}
734
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800735/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736 * Special-case: build the interface table, maintain
737 * the next loopback sw_if_index vbl.
738 */
739static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400740 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741{
Dave Barach72d72232016-08-04 10:15:08 -0400742 vat_main_t *vam = &vat_main;
743 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744
Dave Barach72d72232016-08-04 10:15:08 -0400745 hash_set_mem (vam->sw_if_index_by_interface_name, s,
746 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747
Dave Barach72d72232016-08-04 10:15:08 -0400748 /* In sub interface case, fill the sub interface table entry */
749 if (mp->sw_if_index != mp->sup_sw_if_index)
750 {
751 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752
Dave Barach72d72232016-08-04 10:15:08 -0400753 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700754
Dave Barach72d72232016-08-04 10:15:08 -0400755 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
756 strncpy ((char *) sub->interface_name, (char *) s,
757 vec_len (sub->interface_name));
758 sub->sw_if_index = ntohl (mp->sw_if_index);
759 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760
Dave Barach72d72232016-08-04 10:15:08 -0400761 sub->sub_dot1ad = mp->sub_dot1ad;
762 sub->sub_number_of_tags = mp->sub_number_of_tags;
763 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
764 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
765 sub->sub_exact_match = mp->sub_exact_match;
766 sub->sub_default = mp->sub_default;
767 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
768 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769
Dave Barach72d72232016-08-04 10:15:08 -0400770 /* vlan tag rewrite */
771 sub->vtr_op = ntohl (mp->vtr_op);
772 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
773 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
774 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775 }
776}
777
778static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400779 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780{
Dave Barach72d72232016-08-04 10:15:08 -0400781 vat_main_t *vam = &vat_main;
782 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783
Dave Barach72d72232016-08-04 10:15:08 -0400784 if (VAT_JSON_ARRAY != vam->json_tree.type)
785 {
786 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
787 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 }
Dave Barach72d72232016-08-04 10:15:08 -0400789 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700790
Dave Barach72d72232016-08-04 10:15:08 -0400791 vat_json_init_object (node);
792 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
793 vat_json_object_add_uint (node, "sup_sw_if_index",
794 ntohl (mp->sup_sw_if_index));
795 vat_json_object_add_uint (node, "l2_address_length",
796 ntohl (mp->l2_address_length));
797 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
798 sizeof (mp->l2_address));
799 vat_json_object_add_string_copy (node, "interface_name",
800 mp->interface_name);
801 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
802 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
803 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
804 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
805 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
806 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
807 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
808 vat_json_object_add_uint (node, "sub_number_of_tags",
809 mp->sub_number_of_tags);
810 vat_json_object_add_uint (node, "sub_outer_vlan_id",
811 ntohs (mp->sub_outer_vlan_id));
812 vat_json_object_add_uint (node, "sub_inner_vlan_id",
813 ntohs (mp->sub_inner_vlan_id));
814 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
815 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
816 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
817 mp->sub_outer_vlan_id_any);
818 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
819 mp->sub_inner_vlan_id_any);
820 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
821 vat_json_object_add_uint (node, "vtr_push_dot1q",
822 ntohl (mp->vtr_push_dot1q));
823 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
824 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700825}
826
827static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400828 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700829{
Dave Barach72d72232016-08-04 10:15:08 -0400830 vat_main_t *vam = &vat_main;
831 if (vam->interface_event_display)
832 errmsg ("interface flags: sw_if_index %d %s %s\n",
833 ntohl (mp->sw_if_index),
834 mp->admin_up_down ? "admin-up" : "admin-down",
835 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836}
837
838static void vl_api_sw_interface_set_flags_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400839 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840{
Dave Barach72d72232016-08-04 10:15:08 -0400841 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700842}
843
Dave Barach72d72232016-08-04 10:15:08 -0400844static void
845vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700846{
Dave Barach72d72232016-08-04 10:15:08 -0400847 vat_main_t *vam = &vat_main;
848 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700849
Dave Barach72d72232016-08-04 10:15:08 -0400850 vam->retval = retval;
851 vam->shmem_result = (u8 *) mp->reply_in_shmem;
852 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853}
854
Dave Barach72d72232016-08-04 10:15:08 -0400855static void
856vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700857{
Dave Barach72d72232016-08-04 10:15:08 -0400858 vat_main_t *vam = &vat_main;
859 vat_json_node_t node;
860 api_main_t *am = &api_main;
861 void *oldheap;
862 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700863
Dave Barach72d72232016-08-04 10:15:08 -0400864 vat_json_init_object (&node);
865 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
866 vat_json_object_add_uint (&node, "reply_in_shmem",
867 ntohl (mp->reply_in_shmem));
868 /* Toss the shared-memory original... */
869 pthread_mutex_lock (&am->vlib_rp->mutex);
870 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500871
Dave Barach72d72232016-08-04 10:15:08 -0400872 reply = (u8 *) (mp->reply_in_shmem);
873 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800874
Dave Barach72d72232016-08-04 10:15:08 -0400875 svm_pop_heap (oldheap);
876 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877
Dave Barach72d72232016-08-04 10:15:08 -0400878 vat_json_print (vam->ofp, &node);
879 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700880
Dave Barach72d72232016-08-04 10:15:08 -0400881 vam->retval = ntohl (mp->retval);
882 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883}
884
Ole Troanc27213a2016-08-31 14:50:49 +0200885static void
886vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
887{
888 vat_main_t *vam = &vat_main;
889 i32 retval = ntohl (mp->retval);
890
891 vam->retval = retval;
892 vam->cmd_reply = mp->reply;
893 vam->result_ready = 1;
894}
895
896static void
897vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
898{
899 vat_main_t *vam = &vat_main;
900 vat_json_node_t node;
901
902 vat_json_init_object (&node);
903 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
904 vat_json_object_add_string_copy (&node, "reply", mp->reply);
905
906 vat_json_print (vam->ofp, &node);
907 vat_json_free (&node);
908
909 vam->retval = ntohl (mp->retval);
910 vam->result_ready = 1;
911}
912
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400914 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700915{
Dave Barach72d72232016-08-04 10:15:08 -0400916 vat_main_t *vam = &vat_main;
917 i32 retval = ntohl (mp->retval);
918 if (vam->async_mode)
919 {
920 vam->async_errors += (retval < 0);
921 }
922 else
923 {
924 vam->retval = retval;
925 if (retval == 0 &&
926 ((mp->new_table_index != 0xFFFFFFFF) ||
927 (mp->skip_n_vectors != 0xFFFFFFFF) ||
928 (mp->match_n_vectors != 0xFFFFFFFF)))
929 /*
930 * Note: this is just barely thread-safe, depends on
931 * the main thread spinning waiting for an answer...
932 */
933 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
934 ntohl (mp->new_table_index),
935 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
936 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937 }
938}
939
940static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400941 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942{
Dave Barach72d72232016-08-04 10:15:08 -0400943 vat_main_t *vam = &vat_main;
944 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700945
Dave Barach72d72232016-08-04 10:15:08 -0400946 vat_json_init_object (&node);
947 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
948 vat_json_object_add_uint (&node, "new_table_index",
949 ntohl (mp->new_table_index));
950 vat_json_object_add_uint (&node, "skip_n_vectors",
951 ntohl (mp->skip_n_vectors));
952 vat_json_object_add_uint (&node, "match_n_vectors",
953 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700954
Dave Barach72d72232016-08-04 10:15:08 -0400955 vat_json_print (vam->ofp, &node);
956 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700957
Dave Barach72d72232016-08-04 10:15:08 -0400958 vam->retval = ntohl (mp->retval);
959 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960}
961
962static void vl_api_get_node_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400963 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964{
Dave Barach72d72232016-08-04 10:15:08 -0400965 vat_main_t *vam = &vat_main;
966 i32 retval = ntohl (mp->retval);
967 if (vam->async_mode)
968 {
969 vam->async_errors += (retval < 0);
970 }
971 else
972 {
973 vam->retval = retval;
974 if (retval == 0)
975 errmsg ("node index %d\n", ntohl (mp->node_index));
976 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977 }
978}
979
980static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400981 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982{
Dave Barach72d72232016-08-04 10:15:08 -0400983 vat_main_t *vam = &vat_main;
984 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985
Dave Barach72d72232016-08-04 10:15:08 -0400986 vat_json_init_object (&node);
987 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
988 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989
Dave Barach72d72232016-08-04 10:15:08 -0400990 vat_json_print (vam->ofp, &node);
991 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992
Dave Barach72d72232016-08-04 10:15:08 -0400993 vam->retval = ntohl (mp->retval);
994 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995}
996
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700997static void vl_api_get_next_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400998 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700999{
Dave Barach72d72232016-08-04 10:15:08 -04001000 vat_main_t *vam = &vat_main;
1001 i32 retval = ntohl (mp->retval);
1002 if (vam->async_mode)
1003 {
1004 vam->async_errors += (retval < 0);
1005 }
1006 else
1007 {
1008 vam->retval = retval;
1009 if (retval == 0)
1010 errmsg ("next node index %d\n", ntohl (mp->next_index));
1011 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001012 }
1013}
1014
1015static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001016 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001017{
Dave Barach72d72232016-08-04 10:15:08 -04001018 vat_main_t *vam = &vat_main;
1019 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001020
Dave Barach72d72232016-08-04 10:15:08 -04001021 vat_json_init_object (&node);
1022 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1023 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001024
Dave Barach72d72232016-08-04 10:15:08 -04001025 vat_json_print (vam->ofp, &node);
1026 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001027
Dave Barach72d72232016-08-04 10:15:08 -04001028 vam->retval = ntohl (mp->retval);
1029 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001030}
1031
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032static void vl_api_add_node_next_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001033 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034{
Dave Barach72d72232016-08-04 10:15:08 -04001035 vat_main_t *vam = &vat_main;
1036 i32 retval = ntohl (mp->retval);
1037 if (vam->async_mode)
1038 {
1039 vam->async_errors += (retval < 0);
1040 }
1041 else
1042 {
1043 vam->retval = retval;
1044 if (retval == 0)
1045 errmsg ("next index %d\n", ntohl (mp->next_index));
1046 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001047 }
1048}
1049
1050static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001051 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052{
Dave Barach72d72232016-08-04 10:15:08 -04001053 vat_main_t *vam = &vat_main;
1054 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001055
Dave Barach72d72232016-08-04 10:15:08 -04001056 vat_json_init_object (&node);
1057 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1058 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001059
Dave Barach72d72232016-08-04 10:15:08 -04001060 vat_json_print (vam->ofp, &node);
1061 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001062
Dave Barach72d72232016-08-04 10:15:08 -04001063 vam->retval = ntohl (mp->retval);
1064 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001065}
1066
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001067static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001068 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069{
Dave Barach72d72232016-08-04 10:15:08 -04001070 vat_main_t *vam = &vat_main;
1071 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072
Dave Barach72d72232016-08-04 10:15:08 -04001073 if (retval >= 0)
1074 {
1075 errmsg (" program: %s\n", mp->program);
1076 errmsg (" version: %s\n", mp->version);
1077 errmsg (" build date: %s\n", mp->build_date);
1078 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001079 }
Dave Barach72d72232016-08-04 10:15:08 -04001080 vam->retval = retval;
1081 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001082}
1083
1084static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001085 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001086{
Dave Barach72d72232016-08-04 10:15:08 -04001087 vat_main_t *vam = &vat_main;
1088 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089
Dave Barach72d72232016-08-04 10:15:08 -04001090 vat_json_init_object (&node);
1091 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1092 vat_json_object_add_string_copy (&node, "program", mp->program);
1093 vat_json_object_add_string_copy (&node, "version", mp->version);
1094 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1095 vat_json_object_add_string_copy (&node, "build_directory",
1096 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001097
Dave Barach72d72232016-08-04 10:15:08 -04001098 vat_json_print (vam->ofp, &node);
1099 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100
Dave Barach72d72232016-08-04 10:15:08 -04001101 vam->retval = ntohl (mp->retval);
1102 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103}
1104
Dave Barach72d72232016-08-04 10:15:08 -04001105static void
1106vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001107{
Dave Barach72d72232016-08-04 10:15:08 -04001108 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001109 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1110 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001111 format_ip4_address, &mp->address,
1112 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001113}
1114
Dave Barach72d72232016-08-04 10:15:08 -04001115static void
1116vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117{
Dave Barach72d72232016-08-04 10:15:08 -04001118 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001119}
1120
John Lo1edfba92016-08-27 01:11:57 -04001121static void
1122vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1123{
1124 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001125 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1126 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001127 format_ip6_address, mp->address,
1128 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1129}
1130
1131static void
1132vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1133{
1134 /* JSON output not supported */
1135}
1136
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001137/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001138 * Special-case: build the bridge domain table, maintain
1139 * the next bd id vbl.
1140 */
1141static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001142 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001143{
Dave Barach72d72232016-08-04 10:15:08 -04001144 vat_main_t *vam = &vat_main;
1145 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146
Dave Barach72d72232016-08-04 10:15:08 -04001147 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1148 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149
Dave Barach72d72232016-08-04 10:15:08 -04001150 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1151 ntohl (mp->bd_id), mp->learn, mp->forward,
1152 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153
Dave Barach72d72232016-08-04 10:15:08 -04001154 if (n_sw_ifs)
1155 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1156 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001157}
1158
1159static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001160 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001161{
Dave Barach72d72232016-08-04 10:15:08 -04001162 vat_main_t *vam = &vat_main;
1163 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001164
Dave Barach72d72232016-08-04 10:15:08 -04001165 if (VAT_JSON_ARRAY != vam->json_tree.type)
1166 {
1167 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1168 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001169 }
Dave Barach72d72232016-08-04 10:15:08 -04001170 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001171
Dave Barach72d72232016-08-04 10:15:08 -04001172 vat_json_init_object (node);
1173 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1174 vat_json_object_add_uint (node, "flood", mp->flood);
1175 vat_json_object_add_uint (node, "forward", mp->forward);
1176 vat_json_object_add_uint (node, "learn", mp->learn);
1177 vat_json_object_add_uint (node, "bvi_sw_if_index",
1178 ntohl (mp->bvi_sw_if_index));
1179 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1180 array = vat_json_object_add (node, "sw_if");
1181 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001182}
1183
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001184/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001185 * Special-case: build the bridge domain sw if table.
1186 */
1187static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001188 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001189{
Dave Barach72d72232016-08-04 10:15:08 -04001190 vat_main_t *vam = &vat_main;
1191 hash_pair_t *p;
1192 u8 *sw_if_name = 0;
1193 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
Dave Barach72d72232016-08-04 10:15:08 -04001195 sw_if_index = ntohl (mp->sw_if_index);
1196 /* *INDENT-OFF* */
1197 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1198 ({
1199 if ((u32) p->value[0] == sw_if_index)
1200 {
1201 sw_if_name = (u8 *)(p->key);
1202 break;
1203 }
1204 }));
1205 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001206
Dave Barach72d72232016-08-04 10:15:08 -04001207 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1208 mp->shg, sw_if_name ? (char *) sw_if_name :
1209 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001210}
1211
1212static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001213 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214{
Dave Barach72d72232016-08-04 10:15:08 -04001215 vat_main_t *vam = &vat_main;
1216 vat_json_node_t *node = NULL;
1217 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218
Dave Barach72d72232016-08-04 10:15:08 -04001219 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1220 ASSERT (vec_len (vam->json_tree.array) >= 1);
1221 last_index = vec_len (vam->json_tree.array) - 1;
1222 node = &vam->json_tree.array[last_index];
1223 node = vat_json_object_get_element (node, "sw_if");
1224 ASSERT (NULL != node);
1225 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001226
Dave Barach72d72232016-08-04 10:15:08 -04001227 vat_json_init_object (node);
1228 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1229 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1230 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001231}
1232
1233static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001234 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001235{
Dave Barach72d72232016-08-04 10:15:08 -04001236 vat_main_t *vam = &vat_main;
1237 i32 retval = ntohl (mp->retval);
1238 if (vam->async_mode)
1239 {
1240 vam->async_errors += (retval < 0);
1241 }
1242 else
1243 {
1244 vam->retval = retval;
1245 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001246 }
1247}
1248
1249static void vl_api_control_ping_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001250 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001251{
Dave Barach72d72232016-08-04 10:15:08 -04001252 vat_main_t *vam = &vat_main;
1253 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001254
Dave Barach72d72232016-08-04 10:15:08 -04001255 if (VAT_JSON_NONE != vam->json_tree.type)
1256 {
1257 vat_json_print (vam->ofp, &vam->json_tree);
1258 vat_json_free (&vam->json_tree);
1259 vam->json_tree.type = VAT_JSON_NONE;
1260 }
1261 else
1262 {
1263 /* just print [] */
1264 vat_json_init_array (&vam->json_tree);
1265 vat_json_print (vam->ofp, &vam->json_tree);
1266 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001267 }
1268
Dave Barach72d72232016-08-04 10:15:08 -04001269 vam->retval = retval;
1270 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271}
1272
Dave Barach72d72232016-08-04 10:15:08 -04001273static void
1274vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001275{
Dave Barach72d72232016-08-04 10:15:08 -04001276 vat_main_t *vam = &vat_main;
1277 i32 retval = ntohl (mp->retval);
1278 if (vam->async_mode)
1279 {
1280 vam->async_errors += (retval < 0);
1281 }
1282 else
1283 {
1284 vam->retval = retval;
1285 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001286 }
1287}
1288
1289static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001290 (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001291{
Dave Barach72d72232016-08-04 10:15:08 -04001292 vat_main_t *vam = &vat_main;
1293 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001294
Dave Barach72d72232016-08-04 10:15:08 -04001295 vat_json_init_object (&node);
1296 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1297 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1298 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299
Dave Barach72d72232016-08-04 10:15:08 -04001300 vat_json_print (vam->ofp, &node);
1301 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001302
Dave Barach72d72232016-08-04 10:15:08 -04001303 vam->retval = ntohl (mp->retval);
1304 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001305}
1306
1307static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001308 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001309{
Dave Barach72d72232016-08-04 10:15:08 -04001310 vat_main_t *vam = &vat_main;
1311 i32 retval = ntohl (mp->retval);
1312 if (vam->async_mode)
1313 {
1314 vam->async_errors += (retval < 0);
1315 }
1316 else
1317 {
1318 vam->retval = retval;
1319 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001320 }
1321}
1322
1323static void vl_api_bridge_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001324 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001325{
Dave Barach72d72232016-08-04 10:15:08 -04001326 vat_main_t *vam = &vat_main;
1327 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328
Dave Barach72d72232016-08-04 10:15:08 -04001329 vat_json_init_object (&node);
1330 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1331 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1332 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001333
Dave Barach72d72232016-08-04 10:15:08 -04001334 vat_json_print (vam->ofp, &node);
1335 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336
Dave Barach72d72232016-08-04 10:15:08 -04001337 vam->retval = ntohl (mp->retval);
1338 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339}
1340
1341static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001342 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001343{
Dave Barach72d72232016-08-04 10:15:08 -04001344 vat_main_t *vam = &vat_main;
1345 i32 retval = ntohl (mp->retval);
1346 if (vam->async_mode)
1347 {
1348 vam->async_errors += (retval < 0);
1349 }
1350 else
1351 {
1352 vam->retval = retval;
1353 vam->sw_if_index = ntohl (mp->sw_if_index);
1354 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001355 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001356
Ed Warnickecb9cada2015-12-08 15:45:58 -07001357}
1358
1359static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001360 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001361{
Dave Barach72d72232016-08-04 10:15:08 -04001362 vat_main_t *vam = &vat_main;
1363 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001364
Dave Barach72d72232016-08-04 10:15:08 -04001365 vat_json_init_object (&node);
1366 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1367 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001368
Dave Barach72d72232016-08-04 10:15:08 -04001369 vat_json_print (vam->ofp, &node);
1370 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001371
Dave Barach72d72232016-08-04 10:15:08 -04001372 vam->retval = ntohl (mp->retval);
1373 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001374
Ed Warnickecb9cada2015-12-08 15:45:58 -07001375}
1376
Dave Barach72d72232016-08-04 10:15:08 -04001377static void
1378vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001379{
Dave Barach72d72232016-08-04 10:15:08 -04001380 vat_main_t *vam = &vat_main;
1381 i32 retval = ntohl (mp->retval);
1382 if (vam->async_mode)
1383 {
1384 vam->async_errors += (retval < 0);
1385 }
1386 else
1387 {
1388 vam->retval = retval;
1389 vam->sw_if_index = ntohl (mp->sw_if_index);
1390 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001391 }
1392}
1393
1394static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001395 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001396{
Dave Barach72d72232016-08-04 10:15:08 -04001397 vat_main_t *vam = &vat_main;
1398 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001399
Dave Barach72d72232016-08-04 10:15:08 -04001400 vat_json_init_object (&node);
1401 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1402 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001403
Dave Barach72d72232016-08-04 10:15:08 -04001404 vat_json_print (vam->ofp, &node);
1405 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001406
Dave Barach72d72232016-08-04 10:15:08 -04001407 vam->retval = ntohl (mp->retval);
1408 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409}
1410
Dave Barach72d72232016-08-04 10:15:08 -04001411static void
1412vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413{
Dave Barach72d72232016-08-04 10:15:08 -04001414 vat_main_t *vam = &vat_main;
1415 i32 retval = ntohl (mp->retval);
1416 if (vam->async_mode)
1417 {
1418 vam->async_errors += (retval < 0);
1419 }
1420 else
1421 {
1422 vam->retval = retval;
1423 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424 }
1425}
1426
1427static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001428 (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001429{
Dave Barach72d72232016-08-04 10:15:08 -04001430 vat_main_t *vam = &vat_main;
1431 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432
Dave Barach72d72232016-08-04 10:15:08 -04001433 vat_json_init_object (&node);
1434 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001435
Dave Barach72d72232016-08-04 10:15:08 -04001436 vat_json_print (vam->ofp, &node);
1437 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438
Dave Barach72d72232016-08-04 10:15:08 -04001439 vam->retval = ntohl (mp->retval);
1440 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001441}
1442
Neale Rannsad422ed2016-11-02 14:20:04 +00001443static void vl_api_mpls_tunnel_add_del_reply_t_handler
1444 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001445{
Dave Barach72d72232016-08-04 10:15:08 -04001446 vat_main_t *vam = &vat_main;
1447 i32 retval = ntohl (mp->retval);
1448 if (vam->async_mode)
1449 {
1450 vam->async_errors += (retval < 0);
1451 }
1452 else
1453 {
1454 vam->retval = retval;
1455 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001456 }
1457}
1458
Neale Rannsad422ed2016-11-02 14:20:04 +00001459static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
1460 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001461{
Dave Barach72d72232016-08-04 10:15:08 -04001462 vat_main_t *vam = &vat_main;
1463 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464
Dave Barach72d72232016-08-04 10:15:08 -04001465 vat_json_init_object (&node);
1466 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1467 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
Neale Rannsad422ed2016-11-02 14:20:04 +00001468 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469
Dave Barach72d72232016-08-04 10:15:08 -04001470 vat_json_print (vam->ofp, &node);
1471 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001472
Dave Barach72d72232016-08-04 10:15:08 -04001473 vam->retval = ntohl (mp->retval);
1474 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001475}
1476
1477static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001478 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001479{
Dave Barach72d72232016-08-04 10:15:08 -04001480 vat_main_t *vam = &vat_main;
1481 i32 retval = ntohl (mp->retval);
1482 if (vam->async_mode)
1483 {
1484 vam->async_errors += (retval < 0);
1485 }
1486 else
1487 {
1488 vam->retval = retval;
1489 vam->sw_if_index = ntohl (mp->sw_if_index);
1490 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001491 }
1492}
1493
1494static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001495 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001496{
Dave Barach72d72232016-08-04 10:15:08 -04001497 vat_main_t *vam = &vat_main;
1498 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001499
Dave Barach72d72232016-08-04 10:15:08 -04001500 vat_json_init_object (&node);
1501 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1502 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001503
Dave Barach72d72232016-08-04 10:15:08 -04001504 vat_json_print (vam->ofp, &node);
1505 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001506
Dave Barach72d72232016-08-04 10:15:08 -04001507 vam->retval = ntohl (mp->retval);
1508 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001509}
1510
Filip Tehlar3a834602016-08-11 12:21:37 +02001511
1512static void vl_api_lisp_add_del_locator_set_reply_t_handler
1513 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1514{
1515 vat_main_t *vam = &vat_main;
1516 i32 retval = ntohl (mp->retval);
1517 if (vam->async_mode)
1518 {
1519 vam->async_errors += (retval < 0);
1520 }
1521 else
1522 {
1523 vam->retval = retval;
1524 vam->result_ready = 1;
1525 }
1526}
1527
1528static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1529 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1530{
1531 vat_main_t *vam = &vat_main;
1532 vat_json_node_t node;
1533
1534 vat_json_init_object (&node);
1535 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1536 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1537
1538 vat_json_print (vam->ofp, &node);
1539 vat_json_free (&node);
1540
1541 vam->retval = ntohl (mp->retval);
1542 vam->result_ready = 1;
1543}
1544
Ed Warnickecb9cada2015-12-08 15:45:58 -07001545static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001546 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001547{
Dave Barach72d72232016-08-04 10:15:08 -04001548 vat_main_t *vam = &vat_main;
1549 i32 retval = ntohl (mp->retval);
1550 if (vam->async_mode)
1551 {
1552 vam->async_errors += (retval < 0);
1553 }
1554 else
1555 {
1556 vam->retval = retval;
1557 vam->sw_if_index = ntohl (mp->sw_if_index);
1558 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001559 }
1560}
1561
1562static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001563 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001564{
Dave Barach72d72232016-08-04 10:15:08 -04001565 vat_main_t *vam = &vat_main;
1566 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001567
Dave Barach72d72232016-08-04 10:15:08 -04001568 vat_json_init_object (&node);
1569 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1570 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001571
Dave Barach72d72232016-08-04 10:15:08 -04001572 vat_json_print (vam->ofp, &node);
1573 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001574
Dave Barach72d72232016-08-04 10:15:08 -04001575 vam->retval = ntohl (mp->retval);
1576 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001577}
1578
Chris Luke27fe48f2016-04-28 13:44:38 -04001579static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001580 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001581{
Dave Barach72d72232016-08-04 10:15:08 -04001582 vat_main_t *vam = &vat_main;
1583 i32 retval = ntohl (mp->retval);
1584 if (vam->async_mode)
1585 {
1586 vam->async_errors += (retval < 0);
1587 }
1588 else
1589 {
1590 vam->retval = retval;
1591 vam->sw_if_index = ntohl (mp->sw_if_index);
1592 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001593 }
1594}
1595
1596static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001597 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001598{
Dave Barach72d72232016-08-04 10:15:08 -04001599 vat_main_t *vam = &vat_main;
1600 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001601
Dave Barach72d72232016-08-04 10:15:08 -04001602 vat_json_init_object (&node);
1603 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1604 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001605
Dave Barach72d72232016-08-04 10:15:08 -04001606 vat_json_print (vam->ofp, &node);
1607 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001608
Dave Barach72d72232016-08-04 10:15:08 -04001609 vam->retval = ntohl (mp->retval);
1610 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001611}
1612
Ed Warnickecb9cada2015-12-08 15:45:58 -07001613static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001614 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001615{
Dave Barach72d72232016-08-04 10:15:08 -04001616 vat_main_t *vam = &vat_main;
1617 i32 retval = ntohl (mp->retval);
1618 if (vam->async_mode)
1619 {
1620 vam->async_errors += (retval < 0);
1621 }
1622 else
1623 {
1624 vam->retval = retval;
1625 vam->sw_if_index = ntohl (mp->sw_if_index);
1626 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001627 }
1628}
1629
1630static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001631 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001632{
Dave Barach72d72232016-08-04 10:15:08 -04001633 vat_main_t *vam = &vat_main;
1634 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001635
Dave Barach72d72232016-08-04 10:15:08 -04001636 vat_json_init_object (&node);
1637 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1638 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639
Dave Barach72d72232016-08-04 10:15:08 -04001640 vat_json_print (vam->ofp, &node);
1641 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001642
Dave Barach72d72232016-08-04 10:15:08 -04001643 vam->retval = ntohl (mp->retval);
1644 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001645}
1646
1647static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001648 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001649{
Dave Barach72d72232016-08-04 10:15:08 -04001650 vat_main_t *vam = &vat_main;
1651 static ip_address_details_t empty_ip_address_details = { {0} };
1652 ip_address_details_t *address = NULL;
1653 ip_details_t *current_ip_details = NULL;
1654 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001655
Dave Barach72d72232016-08-04 10:15:08 -04001656 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001657
Dave Barach72d72232016-08-04 10:15:08 -04001658 if (!details || vam->current_sw_if_index >= vec_len (details)
1659 || !details[vam->current_sw_if_index].present)
1660 {
1661 errmsg ("ip address details arrived but not stored\n");
1662 errmsg ("ip_dump should be called first\n");
1663 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664 }
1665
Dave Barach72d72232016-08-04 10:15:08 -04001666 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001667
1668#define addresses (current_ip_details->addr)
1669
Dave Barach72d72232016-08-04 10:15:08 -04001670 vec_validate_init_empty (addresses, vec_len (addresses),
1671 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672
Dave Barach72d72232016-08-04 10:15:08 -04001673 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001674
Dave Barach72d72232016-08-04 10:15:08 -04001675 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1676 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677#undef addresses
1678}
1679
1680static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001681 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001682{
Dave Barach72d72232016-08-04 10:15:08 -04001683 vat_main_t *vam = &vat_main;
1684 vat_json_node_t *node = NULL;
1685 struct in6_addr ip6;
1686 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barach72d72232016-08-04 10:15:08 -04001688 if (VAT_JSON_ARRAY != vam->json_tree.type)
1689 {
1690 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1691 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001692 }
Dave Barach72d72232016-08-04 10:15:08 -04001693 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001694
Dave Barach72d72232016-08-04 10:15:08 -04001695 vat_json_init_object (node);
1696 if (vam->is_ipv6)
1697 {
1698 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1699 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700 }
Dave Barach72d72232016-08-04 10:15:08 -04001701 else
1702 {
1703 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1704 vat_json_object_add_ip4 (node, "ip", ip4);
1705 }
1706 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001707}
1708
Dave Barach72d72232016-08-04 10:15:08 -04001709static void
1710vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001711{
Dave Barach72d72232016-08-04 10:15:08 -04001712 vat_main_t *vam = &vat_main;
1713 static ip_details_t empty_ip_details = { 0 };
1714 ip_details_t *ip = NULL;
1715 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001716
Dave Barach72d72232016-08-04 10:15:08 -04001717 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001718
Dave Barach72d72232016-08-04 10:15:08 -04001719 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1720 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001721
Dave Barach72d72232016-08-04 10:15:08 -04001722 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1723 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001724
Dave Barach72d72232016-08-04 10:15:08 -04001725 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001726}
1727
Dave Barach72d72232016-08-04 10:15:08 -04001728static void
1729vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001730{
Dave Barach72d72232016-08-04 10:15:08 -04001731 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001732
Dave Barach72d72232016-08-04 10:15:08 -04001733 if (VAT_JSON_ARRAY != vam->json_tree.type)
1734 {
1735 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1736 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001737 }
Dave Barach72d72232016-08-04 10:15:08 -04001738 vat_json_array_add_uint (&vam->json_tree,
1739 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001740}
1741
1742static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001743 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001744{
Dave Barach72d72232016-08-04 10:15:08 -04001745 vat_json_node_t *node = NULL;
1746 vat_main_t *vam = &vat_main;
1747 struct in6_addr ip6;
1748 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001749
Dave Barach72d72232016-08-04 10:15:08 -04001750 if (VAT_JSON_ARRAY != vam->json_tree.type)
1751 {
1752 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1753 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001754 }
1755
Dave Barach72d72232016-08-04 10:15:08 -04001756 node = vat_json_array_add (&vam->json_tree);
1757 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001758
Dave Barach72d72232016-08-04 10:15:08 -04001759 vat_json_object_add_uint (node, "domain_index",
1760 clib_net_to_host_u32 (mp->domain_index));
1761 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1762 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1763 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1764 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1765 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1766 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1767 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1768 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1769 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1770 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1771 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1772 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1773 vat_json_object_add_uint (node, "flags", mp->flags);
1774 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1775 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001776}
1777
1778static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001779 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001780{
Dave Barach72d72232016-08-04 10:15:08 -04001781 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001782
Dave Barach72d72232016-08-04 10:15:08 -04001783 if (mp->is_translation)
1784 {
1785 fformat (vam->ofp,
1786 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1787 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1788 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1789 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1790 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001791 }
Dave Barach72d72232016-08-04 10:15:08 -04001792 else
1793 {
1794 fformat (vam->ofp,
1795 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1796 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1797 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1798 format_ip6_address, mp->ip6_src,
1799 clib_net_to_host_u32 (mp->domain_index));
1800 }
1801 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1802 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1803 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001804}
1805
1806static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001807 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001808{
Dave Barach72d72232016-08-04 10:15:08 -04001809 struct in6_addr ip6;
1810 vat_json_node_t *node = NULL;
1811 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001812
Dave Barach72d72232016-08-04 10:15:08 -04001813 if (VAT_JSON_ARRAY != vam->json_tree.type)
1814 {
1815 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1816 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001817 }
1818
Dave Barach72d72232016-08-04 10:15:08 -04001819 node = vat_json_array_add (&vam->json_tree);
1820 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001821
Dave Barach72d72232016-08-04 10:15:08 -04001822 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1823 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1824 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825}
1826
Dave Barach72d72232016-08-04 10:15:08 -04001827static void
1828vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001829{
Dave Barach72d72232016-08-04 10:15:08 -04001830 vat_main_t *vam = &vat_main;
1831 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1832 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833}
1834
Dave Barach72d72232016-08-04 10:15:08 -04001835static void
1836vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001837{
Dave Barach72d72232016-08-04 10:15:08 -04001838 vat_main_t *vam = &vat_main;
1839 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1840 "router_addr %U host_mac %U\n",
1841 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1842 format_ip4_address, &mp->host_address,
1843 format_ip4_address, &mp->router_address,
1844 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845}
1846
1847static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001848 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849{
Dave Barach72d72232016-08-04 10:15:08 -04001850 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001851}
1852
Dave Barach72d72232016-08-04 10:15:08 -04001853static void
1854set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1855 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001856{
Dave Barach72d72232016-08-04 10:15:08 -04001857 vat_main_t *vam = &vat_main;
1858 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001859
Dave Barach72d72232016-08-04 10:15:08 -04001860 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1861 NULL);
1862 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1863 sw_if_index, default_counter);
1864 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001865}
1866
Dave Barach72d72232016-08-04 10:15:08 -04001867static void
1868set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1869 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870{
Dave Barach72d72232016-08-04 10:15:08 -04001871 vat_main_t *vam = &vat_main;
1872 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001873
Dave Barach72d72232016-08-04 10:15:08 -04001874 vec_validate_init_empty (vam->combined_interface_counters,
1875 vnet_counter_type, NULL);
1876 vec_validate_init_empty (vam->combined_interface_counters
1877 [vnet_counter_type], sw_if_index, default_counter);
1878 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001879}
1880
1881static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001882 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001883{
Dave Barach72d72232016-08-04 10:15:08 -04001884 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001885}
1886
1887static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001888 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001889{
Dave Barach72d72232016-08-04 10:15:08 -04001890 interface_counter_t counter;
1891 vlib_counter_t *v;
1892 u64 *v_packets;
1893 u64 packets;
1894 u32 count;
1895 u32 first_sw_if_index;
1896 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001897
Dave Barach72d72232016-08-04 10:15:08 -04001898 count = ntohl (mp->count);
1899 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900
Dave Barach72d72232016-08-04 10:15:08 -04001901 if (!mp->is_combined)
1902 {
1903 v_packets = (u64 *) & mp->data;
1904 for (i = 0; i < count; i++)
1905 {
1906 packets =
1907 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1908 set_simple_interface_counter (mp->vnet_counter_type,
1909 first_sw_if_index + i, packets);
1910 v_packets++;
1911 }
1912 }
1913 else
1914 {
1915 v = (vlib_counter_t *) & mp->data;
1916 for (i = 0; i < count; i++)
1917 {
1918 counter.packets =
1919 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1920 counter.bytes =
1921 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1922 set_combined_interface_counter (mp->vnet_counter_type,
1923 first_sw_if_index + i, counter);
1924 v++;
1925 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001926 }
1927}
1928
Dave Barach72d72232016-08-04 10:15:08 -04001929static u32
1930ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001931{
Dave Barach72d72232016-08-04 10:15:08 -04001932 vat_main_t *vam = &vat_main;
1933 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001934
Dave Barach72d72232016-08-04 10:15:08 -04001935 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1936 {
1937 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1938 {
1939 return i;
1940 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001941 }
Dave Barach72d72232016-08-04 10:15:08 -04001942 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001943}
1944
Dave Barach72d72232016-08-04 10:15:08 -04001945static u32
1946ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001947{
Dave Barach72d72232016-08-04 10:15:08 -04001948 vat_main_t *vam = &vat_main;
1949 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001950
Dave Barach72d72232016-08-04 10:15:08 -04001951 for (i = 0; i < vec_len (vam->ip6_fib_counters_vrf_id_by_index); i++)
1952 {
1953 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id)
1954 {
1955 return i;
1956 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001957 }
Dave Barach72d72232016-08-04 10:15:08 -04001958 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959}
1960
1961static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001962 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001963{
Dave Barach72d72232016-08-04 10:15:08 -04001964 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001965}
1966
1967static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001968 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001969{
Dave Barach72d72232016-08-04 10:15:08 -04001970 vat_main_t *vam = &vat_main;
1971 vl_api_ip4_fib_counter_t *v;
1972 ip4_fib_counter_t *counter;
1973 struct in_addr ip4;
1974 u32 vrf_id;
1975 u32 vrf_index;
1976 u32 count;
1977 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001978
Dave Barach72d72232016-08-04 10:15:08 -04001979 vrf_id = ntohl (mp->vrf_id);
1980 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
1981 if (~0 == vrf_index)
1982 {
1983 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
1984 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1985 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1986 vec_validate (vam->ip4_fib_counters, vrf_index);
1987 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001988 }
1989
Dave Barach72d72232016-08-04 10:15:08 -04001990 vec_free (vam->ip4_fib_counters[vrf_index]);
1991 v = (vl_api_ip4_fib_counter_t *) & mp->c;
1992 count = ntohl (mp->count);
1993 for (i = 0; i < count; i++)
1994 {
1995 vec_validate (vam->ip4_fib_counters[vrf_index], i);
1996 counter = &vam->ip4_fib_counters[vrf_index][i];
1997 clib_memcpy (&ip4, &v->address, sizeof (ip4));
1998 counter->address = ip4;
1999 counter->address_length = v->address_length;
2000 counter->packets = clib_net_to_host_u64 (v->packets);
2001 counter->bytes = clib_net_to_host_u64 (v->bytes);
2002 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002003 }
2004}
2005
2006static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002007 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002008{
Dave Barach72d72232016-08-04 10:15:08 -04002009 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010}
2011
2012static void vl_api_vnet_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002013 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014{
Dave Barach72d72232016-08-04 10:15:08 -04002015 vat_main_t *vam = &vat_main;
2016 vl_api_ip6_fib_counter_t *v;
2017 ip6_fib_counter_t *counter;
2018 struct in6_addr ip6;
2019 u32 vrf_id;
2020 u32 vrf_index;
2021 u32 count;
2022 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002023
Dave Barach72d72232016-08-04 10:15:08 -04002024 vrf_id = ntohl (mp->vrf_id);
2025 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2026 if (~0 == vrf_index)
2027 {
2028 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2029 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2030 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2031 vec_validate (vam->ip6_fib_counters, vrf_index);
2032 vam->ip6_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002033 }
2034
Dave Barach72d72232016-08-04 10:15:08 -04002035 vec_free (vam->ip6_fib_counters[vrf_index]);
2036 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2037 count = ntohl (mp->count);
2038 for (i = 0; i < count; i++)
2039 {
2040 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2041 counter = &vam->ip6_fib_counters[vrf_index][i];
2042 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2043 counter->address = ip6;
2044 counter->address_length = v->address_length;
2045 counter->packets = clib_net_to_host_u64 (v->packets);
2046 counter->bytes = clib_net_to_host_u64 (v->bytes);
2047 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002048 }
2049}
2050
2051static void vl_api_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002052 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053{
Dave Barach72d72232016-08-04 10:15:08 -04002054 vat_main_t *vam = &vat_main;
2055 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002056
Dave Barach72d72232016-08-04 10:15:08 -04002057 if (vam->async_mode)
2058 {
2059 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002060 }
Dave Barach72d72232016-08-04 10:15:08 -04002061 else
2062 {
2063 vam->retval = retval;
2064 vam->result_ready = 1;
2065 }
2066 if (retval >= 0)
2067 {
2068 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002069 }
2070}
2071
2072static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002073 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002074{
Dave Barach72d72232016-08-04 10:15:08 -04002075 vat_main_t *vam = &vat_main;
2076 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002077
Dave Barach72d72232016-08-04 10:15:08 -04002078 vat_json_init_object (&node);
2079 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2080 vat_json_object_add_uint (&node, "first_msg_id",
2081 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002082
Dave Barach72d72232016-08-04 10:15:08 -04002083 vat_json_print (vam->ofp, &node);
2084 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002085
Dave Barach72d72232016-08-04 10:15:08 -04002086 vam->retval = ntohl (mp->retval);
2087 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002088}
2089
Dave Barachb44e9bc2016-02-19 09:06:23 -05002090static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002091 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002092{
Dave Barach72d72232016-08-04 10:15:08 -04002093 vat_main_t *vam = &vat_main;
2094 api_main_t *am = &api_main;
2095 i32 retval = ntohl (mp->retval);
2096 u8 *pvt_copy, *reply;
2097 void *oldheap;
2098 vlib_node_t *node;
2099 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002100
Dave Barach72d72232016-08-04 10:15:08 -04002101 if (vam->async_mode)
2102 {
2103 vam->async_errors += (retval < 0);
2104 }
2105 else
2106 {
2107 vam->retval = retval;
2108 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002109 }
2110
Dave Barach72d72232016-08-04 10:15:08 -04002111 /* "Should never happen..." */
2112 if (retval != 0)
2113 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002114
Dave Barach72d72232016-08-04 10:15:08 -04002115 reply = (u8 *) (mp->reply_in_shmem);
2116 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002117
Dave Barach72d72232016-08-04 10:15:08 -04002118 /* Toss the shared-memory original... */
2119 pthread_mutex_lock (&am->vlib_rp->mutex);
2120 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002121
Dave Barach72d72232016-08-04 10:15:08 -04002122 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002123
Dave Barach72d72232016-08-04 10:15:08 -04002124 svm_pop_heap (oldheap);
2125 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002126
Dave Barach72d72232016-08-04 10:15:08 -04002127 if (vam->graph_nodes)
2128 {
2129 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002130
Dave Barach72d72232016-08-04 10:15:08 -04002131 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2132 {
2133 node = vam->graph_nodes[i];
2134 vec_free (node->name);
2135 vec_free (node->next_nodes);
2136 vec_free (node);
2137 }
2138 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002139 }
2140
Dave Barach72d72232016-08-04 10:15:08 -04002141 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2142 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2143 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002144
Dave Barach72d72232016-08-04 10:15:08 -04002145 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2146 {
2147 node = vam->graph_nodes[i];
2148 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002149 }
2150}
2151
2152static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002153 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002154{
Dave Barach72d72232016-08-04 10:15:08 -04002155 vat_main_t *vam = &vat_main;
2156 api_main_t *am = &api_main;
2157 void *oldheap;
2158 vat_json_node_t node;
2159 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002160
Dave Barach72d72232016-08-04 10:15:08 -04002161 /* $$$$ make this real? */
2162 vat_json_init_object (&node);
2163 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2164 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002165
Dave Barach72d72232016-08-04 10:15:08 -04002166 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002167
Dave Barach72d72232016-08-04 10:15:08 -04002168 /* Toss the shared-memory original... */
2169 pthread_mutex_lock (&am->vlib_rp->mutex);
2170 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002171
Dave Barach72d72232016-08-04 10:15:08 -04002172 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002173
Dave Barach72d72232016-08-04 10:15:08 -04002174 svm_pop_heap (oldheap);
2175 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002176
Dave Barach72d72232016-08-04 10:15:08 -04002177 vat_json_print (vam->ofp, &node);
2178 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002179
Dave Barach72d72232016-08-04 10:15:08 -04002180 vam->retval = ntohl (mp->retval);
2181 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002182}
2183
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002184static void
Dave Barach72d72232016-08-04 10:15:08 -04002185vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002186{
Dave Barach72d72232016-08-04 10:15:08 -04002187 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002188 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002189
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002190 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002191 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002192 s = format (s, "%=16d%=16d%=16d\n",
2193 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002194 }
2195 else
2196 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002197 s = format (s, "%=16U%=16d%=16d\n",
2198 mp->is_ipv6 ? format_ip6_address :
2199 format_ip4_address,
2200 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002201 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002202
2203 fformat (vam->ofp, "%v", s);
2204 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002205}
2206
2207static void
Dave Barach72d72232016-08-04 10:15:08 -04002208vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2209 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002210{
Dave Barach72d72232016-08-04 10:15:08 -04002211 vat_main_t *vam = &vat_main;
2212 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002213 struct in6_addr ip6;
2214 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002215
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002216 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002217 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002218 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2219 vat_json_init_array (&vam->json_tree);
2220 }
2221 node = vat_json_array_add (&vam->json_tree);
2222 vat_json_init_object (node);
2223
2224 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2225 vat_json_object_add_uint (node, "priority", mp->priority);
2226 vat_json_object_add_uint (node, "weight", mp->weight);
2227
2228 if (mp->local)
2229 vat_json_object_add_uint (node, "sw_if_index",
2230 clib_net_to_host_u32 (mp->sw_if_index));
2231 else
2232 {
2233 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002234 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002235 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2236 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002237 }
2238 else
2239 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002240 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2241 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002242 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002243 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002244}
2245
2246static void
2247vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2248 mp)
2249{
2250 vat_main_t *vam = &vat_main;
2251 u8 *ls_name = 0;
2252
2253 ls_name = format (0, "%s", mp->ls_name);
2254
2255 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2256 ls_name);
2257 vec_free (ls_name);
2258}
2259
2260static void
2261 vl_api_lisp_locator_set_details_t_handler_json
2262 (vl_api_lisp_locator_set_details_t * mp)
2263{
2264 vat_main_t *vam = &vat_main;
2265 vat_json_node_t *node = 0;
2266 u8 *ls_name = 0;
2267
2268 ls_name = format (0, "%s", mp->ls_name);
2269 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002270
Dave Barach72d72232016-08-04 10:15:08 -04002271 if (VAT_JSON_ARRAY != vam->json_tree.type)
2272 {
2273 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2274 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002275 }
Dave Barach72d72232016-08-04 10:15:08 -04002276 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002277
Dave Barach72d72232016-08-04 10:15:08 -04002278 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002279 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2280 vat_json_object_add_uint (node, "ls_index",
2281 clib_net_to_host_u32 (mp->ls_index));
2282 vec_free (ls_name);
2283}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002284
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002285static u8 *
2286format_lisp_flat_eid (u8 * s, va_list * args)
2287{
2288 u32 type = va_arg (*args, u32);
2289 u8 *eid = va_arg (*args, u8 *);
2290 u32 eid_len = va_arg (*args, u32);
2291
2292 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002293 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002294 case 0:
2295 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2296 case 1:
2297 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2298 case 2:
2299 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002300 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002301 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002302}
2303
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002304static u8 *
2305format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002306{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002307 u32 type = va_arg (*args, u32);
2308 u8 *eid = va_arg (*args, u8 *);
2309 u32 eid_len = va_arg (*args, u32);
2310 u8 *seid = va_arg (*args, u8 *);
2311 u32 seid_len = va_arg (*args, u32);
2312 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002313
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002314 if (is_src_dst)
2315 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002316
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002317 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002318
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002319 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002320}
2321
2322static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002323vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2324{
2325 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002326 u8 *s = 0, *eid = 0;
2327
2328 if (~0 == mp->locator_set_index)
2329 s = format (0, "action: %d", mp->action);
2330 else
2331 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2332
2333 eid = format (0, "%U", format_lisp_eid_vat,
2334 mp->eid_type,
2335 mp->eid,
2336 mp->eid_prefix_len,
2337 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2338 vec_add1 (eid, 0);
2339
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) \
John Lo37682e12016-11-30 12:51:39 -05003451_(sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003452_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003453_(sw_interface_set_dpdk_hqos_pipe_reply) \
3454_(sw_interface_set_dpdk_hqos_subport_reply) \
3455_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003456_(bridge_domain_add_del_reply) \
3457_(sw_interface_set_l2_xconnect_reply) \
3458_(l2fib_add_del_reply) \
3459_(ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003460_(mpls_route_add_del_reply) \
3461_(mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003462_(proxy_arp_add_del_reply) \
3463_(proxy_arp_intfc_enable_disable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003464_(sw_interface_set_unnumbered_reply) \
3465_(ip_neighbor_add_del_reply) \
3466_(reset_vrf_reply) \
3467_(oam_add_del_reply) \
3468_(reset_fib_reply) \
3469_(dhcp_proxy_config_reply) \
3470_(dhcp_proxy_config_2_reply) \
3471_(dhcp_proxy_set_vss_reply) \
3472_(dhcp_client_config_reply) \
3473_(set_ip_flow_hash_reply) \
3474_(sw_interface_ip6_enable_disable_reply) \
3475_(sw_interface_ip6_set_link_local_address_reply) \
3476_(sw_interface_ip6nd_ra_prefix_reply) \
3477_(sw_interface_ip6nd_ra_config_reply) \
3478_(set_arp_neighbor_limit_reply) \
3479_(l2_patch_add_del_reply) \
3480_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003481_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003482_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003483_(classify_add_del_session_reply) \
3484_(classify_set_interface_ip_table_reply) \
3485_(classify_set_interface_l2_tables_reply) \
3486_(l2tpv3_set_tunnel_cookies_reply) \
3487_(l2tpv3_interface_enable_disable_reply) \
3488_(l2tpv3_set_lookup_key_reply) \
3489_(l2_fib_clear_table_reply) \
3490_(l2_interface_efp_filter_reply) \
3491_(l2_interface_vlan_tag_rewrite_reply) \
3492_(modify_vhost_user_if_reply) \
3493_(delete_vhost_user_if_reply) \
3494_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003495_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003496_(input_acl_set_interface_reply) \
3497_(ipsec_spd_add_del_reply) \
3498_(ipsec_interface_add_del_spd_reply) \
3499_(ipsec_spd_add_del_entry_reply) \
3500_(ipsec_sad_add_del_entry_reply) \
3501_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003502_(ikev2_profile_add_del_reply) \
3503_(ikev2_profile_set_auth_reply) \
3504_(ikev2_profile_set_id_reply) \
3505_(ikev2_profile_set_ts_reply) \
3506_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003507_(delete_loopback_reply) \
3508_(bd_ip_mac_add_del_reply) \
3509_(map_del_domain_reply) \
3510_(map_add_del_rule_reply) \
3511_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003512_(want_stats_reply) \
3513_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003514_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003515_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003516_(ioam_enable_reply) \
3517_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003518_(lisp_add_del_locator_reply) \
3519_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003520_(lisp_add_del_remote_mapping_reply) \
3521_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003522_(lisp_gpe_add_del_fwd_entry_reply) \
3523_(lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003524_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003525_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003526_(lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003527_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003528_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003529_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003530_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003531_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003532_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003533_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003534_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003535_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003536_(set_ipfix_exporter_reply) \
3537_(set_ipfix_classify_stream_reply) \
3538_(ipfix_classify_table_add_del_reply) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003539_(flow_classify_set_interface_reply) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003540_(sw_interface_span_enable_disable_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003541_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003542_(pg_enable_disable_reply) \
3543_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003544_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003545_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003546_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003547_(punt_reply) \
Dave Barach7be864a2016-11-28 11:41:35 -05003548_(feature_enable_disable_reply) \
3549_(sw_interface_tag_add_del_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) \
John Lo37682e12016-11-30 12:51:39 -05003600_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003601_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3602 sw_interface_set_l2_xconnect_reply) \
3603_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3604 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003605_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3606 sw_interface_set_dpdk_hqos_pipe_reply) \
3607_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3608 sw_interface_set_dpdk_hqos_subport_reply) \
3609_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3610 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003611_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3612_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3613_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3614_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3615_(L2_FLAGS_REPLY, l2_flags_reply) \
3616_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3617_(TAP_CONNECT_REPLY, tap_connect_reply) \
3618_(TAP_MODIFY_REPLY, tap_modify_reply) \
3619_(TAP_DELETE_REPLY, tap_delete_reply) \
3620_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3621_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003622_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3623_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003624_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3625_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3626 proxy_arp_intfc_enable_disable_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003627_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003628_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3629 sw_interface_set_unnumbered_reply) \
3630_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3631_(RESET_VRF_REPLY, reset_vrf_reply) \
3632_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3633_(CREATE_SUBIF_REPLY, create_subif_reply) \
3634_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3635_(RESET_FIB_REPLY, reset_fib_reply) \
3636_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3637_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3638_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3639_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3640_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3641_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3642 sw_interface_ip6_enable_disable_reply) \
3643_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3644 sw_interface_ip6_set_link_local_address_reply) \
3645_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3646 sw_interface_ip6nd_ra_prefix_reply) \
3647_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3648 sw_interface_ip6nd_ra_config_reply) \
3649_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3650_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3651_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003652_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3653_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003654_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3655_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3656_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3657classify_set_interface_ip_table_reply) \
3658_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3659 classify_set_interface_l2_tables_reply) \
3660_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3661_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3662_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3663_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3664_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3665 l2tpv3_interface_enable_disable_reply) \
3666_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3667_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3668_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003669_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003670_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3671_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003672_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3673_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3674_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3675_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3676_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3677_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3678_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3679_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003680_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003681_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3682_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003683_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3684_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3685_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003686_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3687_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003688_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3689_(IP_ADDRESS_DETAILS, ip_address_details) \
3690_(IP_DETAILS, ip_details) \
3691_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3692_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3693_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3694_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3695_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003696_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3697_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3698_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3699_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3700_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003701_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3702_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3703_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3704_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3705_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3706_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3707_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3708_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003709_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003710_(MAP_DOMAIN_DETAILS, map_domain_details) \
3711_(MAP_RULE_DETAILS, map_rule_details) \
3712_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3713_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003714_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3715_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003716_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003717_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003718_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003719_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3720_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003721_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3722_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3723_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003724_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3725_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003726_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3727_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003728_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003729_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003730_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003731_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003732_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003733_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3734_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003735_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003736_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003737_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003738_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003739_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003740_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Filip Tehlar69a9b762016-09-23 10:00:52 +02003741_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003742_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003743_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3744 lisp_add_del_map_request_itr_rlocs_reply) \
3745_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3746 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003747_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003748_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003749_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003750_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003751_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003752_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003753_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3754_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003755_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003756_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003757_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003758_(MPLS_FIB_DETAILS, mpls_fib_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003759_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3760_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3761_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003762_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003763_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3764_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3765_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3766_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3767_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3768_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003769_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3770_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003771_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3772_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003773_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3774_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3775_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003776_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3777_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3778 ip_source_and_port_range_check_add_del_reply) \
3779_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003780 ip_source_and_port_range_check_interface_add_del_reply) \
3781_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003782_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003783_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003784_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Steven01b07122016-11-02 10:40:09 -07003785_(PUNT_REPLY, punt_reply) \
3786_(IP_FIB_DETAILS, ip_fib_details) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003787_(IP6_FIB_DETAILS, ip6_fib_details) \
Dave Barach7be864a2016-11-28 11:41:35 -05003788_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3789_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003790
3791/* M: construct, but don't yet send a message */
3792
3793#define M(T,t) \
3794do { \
3795 vam->result_ready = 0; \
3796 mp = vl_msg_api_alloc(sizeof(*mp)); \
3797 memset (mp, 0, sizeof (*mp)); \
3798 mp->_vl_msg_id = ntohs (VL_API_##T); \
3799 mp->client_index = vam->my_client_index; \
3800} while(0);
3801
3802#define M2(T,t,n) \
3803do { \
3804 vam->result_ready = 0; \
3805 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3806 memset (mp, 0, sizeof (*mp)); \
3807 mp->_vl_msg_id = ntohs (VL_API_##T); \
3808 mp->client_index = vam->my_client_index; \
3809} while(0);
3810
3811
3812/* S: send a message */
3813#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3814
3815/* W: wait for results, with timeout */
3816#define W \
3817do { \
3818 timeout = vat_time_now (vam) + 1.0; \
3819 \
3820 while (vat_time_now (vam) < timeout) { \
3821 if (vam->result_ready == 1) { \
3822 return (vam->retval); \
3823 } \
3824 } \
3825 return -99; \
3826} while(0);
3827
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003828/* W2: wait for results, with timeout */
3829#define W2(body) \
3830do { \
3831 timeout = vat_time_now (vam) + 1.0; \
3832 \
3833 while (vat_time_now (vam) < timeout) { \
3834 if (vam->result_ready == 1) { \
3835 (body); \
3836 return (vam->retval); \
3837 } \
3838 } \
3839 return -99; \
3840} while(0);
3841
Dave Barach72d72232016-08-04 10:15:08 -04003842typedef struct
3843{
3844 u8 *name;
3845 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003846} name_sort_t;
3847
3848
3849#define STR_VTR_OP_CASE(op) \
3850 case L2_VTR_ ## op: \
3851 return "" # op;
3852
Dave Barach72d72232016-08-04 10:15:08 -04003853static const char *
3854str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003855{
Dave Barach72d72232016-08-04 10:15:08 -04003856 switch (vtr_op)
3857 {
3858 STR_VTR_OP_CASE (DISABLED);
3859 STR_VTR_OP_CASE (PUSH_1);
3860 STR_VTR_OP_CASE (PUSH_2);
3861 STR_VTR_OP_CASE (POP_1);
3862 STR_VTR_OP_CASE (POP_2);
3863 STR_VTR_OP_CASE (TRANSLATE_1_1);
3864 STR_VTR_OP_CASE (TRANSLATE_1_2);
3865 STR_VTR_OP_CASE (TRANSLATE_2_1);
3866 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003867 }
3868
Dave Barach72d72232016-08-04 10:15:08 -04003869 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07003870}
3871
Dave Barach72d72232016-08-04 10:15:08 -04003872static int
3873dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003874{
Dave Barach72d72232016-08-04 10:15:08 -04003875 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003876
Dave Barach72d72232016-08-04 10:15:08 -04003877 if (vam->json_output)
3878 {
3879 clib_warning
3880 ("JSON output supported only for VPE API calls and dump_stats_table");
3881 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003882 }
3883
Dave Barach72d72232016-08-04 10:15:08 -04003884 fformat (vam->ofp,
3885 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3886 "Interface", "sw_if_index",
3887 "sub id", "dot1ad", "tags", "outer id",
3888 "inner id", "exact", "default", "outer any", "inner any");
3889
3890 vec_foreach (sub, vam->sw_if_subif_table)
3891 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07003892 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003893 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3894 sub->interface_name,
3895 sub->sw_if_index,
3896 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3897 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3898 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3899 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3900 if (sub->vtr_op != L2_VTR_DISABLED)
3901 {
3902 fformat (vam->ofp,
3903 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3904 "tag1: %d tag2: %d ]\n",
3905 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3906 sub->vtr_tag1, sub->vtr_tag2);
3907 }
3908 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003909
Dave Barach72d72232016-08-04 10:15:08 -04003910 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003911}
3912
Dave Barach72d72232016-08-04 10:15:08 -04003913static int
3914name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003915{
Dave Barach72d72232016-08-04 10:15:08 -04003916 name_sort_t *n1 = a1;
3917 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003918
Dave Barach72d72232016-08-04 10:15:08 -04003919 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05003920}
3921
Dave Barach72d72232016-08-04 10:15:08 -04003922static int
3923dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003924{
Dave Barach72d72232016-08-04 10:15:08 -04003925 hash_pair_t *p;
3926 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003927
Dave Barach72d72232016-08-04 10:15:08 -04003928 if (vam->json_output)
3929 {
3930 clib_warning
3931 ("JSON output supported only for VPE API calls and dump_stats_table");
3932 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003933 }
3934
Dave Barach72d72232016-08-04 10:15:08 -04003935 /* *INDENT-OFF* */
3936 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3937 ({
3938 vec_add2 (nses, ns, 1);
3939 ns->name = (u8 *)(p->key);
3940 ns->value = (u32) p->value[0];
3941 }));
3942 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003943
Dave Barach72d72232016-08-04 10:15:08 -04003944 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003945
Dave Barach72d72232016-08-04 10:15:08 -04003946 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3947 vec_foreach (ns, nses)
3948 {
3949 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3950 }
3951 vec_free (nses);
3952 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003953}
3954
Dave Barach72d72232016-08-04 10:15:08 -04003955static int
3956dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003957{
Dave Barach72d72232016-08-04 10:15:08 -04003958 const ip_details_t *det = NULL;
3959 const ip_address_details_t *address = NULL;
3960 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003961
Dave Barach72d72232016-08-04 10:15:08 -04003962 fformat (vam->ofp, "%-12s\n", "sw_if_index");
3963
Dave Barach72d72232016-08-04 10:15:08 -04003964 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3965 {
3966 i++;
3967 if (!det->present)
3968 {
3969 continue;
3970 }
3971 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003972 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04003973 " %-30s%-13s\n", "Address", "Prefix length");
3974 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003975 {
Dave Barach72d72232016-08-04 10:15:08 -04003976 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003977 }
Dave Barach72d72232016-08-04 10:15:08 -04003978 vec_foreach (address, det->addr)
3979 {
3980 fformat (vam->ofp,
3981 " %-30U%-13d\n",
3982 is_ipv6 ? format_ip6_address : format_ip4_address,
3983 address->ip, address->prefix_length);
3984 }
3985 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003986
Dave Barach72d72232016-08-04 10:15:08 -04003987 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003988}
3989
Dave Barach72d72232016-08-04 10:15:08 -04003990static int
3991dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003992{
Dave Barach72d72232016-08-04 10:15:08 -04003993 if (vam->json_output)
3994 {
3995 clib_warning
3996 ("JSON output supported only for VPE API calls and dump_stats_table");
3997 return -99;
3998 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003999
Dave Barach72d72232016-08-04 10:15:08 -04004000 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004001}
4002
Dave Barach72d72232016-08-04 10:15:08 -04004003static int
4004dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004005{
Dave Barach72d72232016-08-04 10:15:08 -04004006 if (vam->json_output)
4007 {
4008 clib_warning
4009 ("JSON output supported only for VPE API calls and dump_stats_table");
4010 return -99;
4011 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004012
Dave Barach72d72232016-08-04 10:15:08 -04004013 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004014}
4015
Dave Barach72d72232016-08-04 10:15:08 -04004016static char *
4017counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004018{
Dave Barach72d72232016-08-04 10:15:08 -04004019 if (!is_combined)
4020 {
4021 switch (counter_type)
4022 {
4023 case VNET_INTERFACE_COUNTER_DROP:
4024 return "drop";
4025 case VNET_INTERFACE_COUNTER_PUNT:
4026 return "punt";
4027 case VNET_INTERFACE_COUNTER_IP4:
4028 return "ip4";
4029 case VNET_INTERFACE_COUNTER_IP6:
4030 return "ip6";
4031 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4032 return "rx-no-buf";
4033 case VNET_INTERFACE_COUNTER_RX_MISS:
4034 return "rx-miss";
4035 case VNET_INTERFACE_COUNTER_RX_ERROR:
4036 return "rx-error";
4037 case VNET_INTERFACE_COUNTER_TX_ERROR:
4038 return "tx-error";
4039 default:
4040 return "INVALID-COUNTER-TYPE";
4041 }
4042 }
4043 else
4044 {
4045 switch (counter_type)
4046 {
4047 case VNET_INTERFACE_COUNTER_RX:
4048 return "rx";
4049 case VNET_INTERFACE_COUNTER_TX:
4050 return "tx";
4051 default:
4052 return "INVALID-COUNTER-TYPE";
4053 }
4054 }
4055}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004056
Dave Barach72d72232016-08-04 10:15:08 -04004057static int
4058dump_stats_table (vat_main_t * vam)
4059{
4060 vat_json_node_t node;
4061 vat_json_node_t *msg_array;
4062 vat_json_node_t *msg;
4063 vat_json_node_t *counter_array;
4064 vat_json_node_t *counter;
4065 interface_counter_t c;
4066 u64 packets;
4067 ip4_fib_counter_t *c4;
4068 ip6_fib_counter_t *c6;
4069 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004070
Dave Barach72d72232016-08-04 10:15:08 -04004071 if (!vam->json_output)
4072 {
4073 clib_warning ("dump_stats_table supported only in JSON format");
4074 return -99;
4075 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004076
Dave Barach72d72232016-08-04 10:15:08 -04004077 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004078
Dave Barach72d72232016-08-04 10:15:08 -04004079 /* interface counters */
4080 msg_array = vat_json_object_add (&node, "interface_counters");
4081 vat_json_init_array (msg_array);
4082 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4083 {
4084 msg = vat_json_array_add (msg_array);
4085 vat_json_init_object (msg);
4086 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4087 (u8 *) counter_type_to_str (i, 0));
4088 vat_json_object_add_int (msg, "is_combined", 0);
4089 counter_array = vat_json_object_add (msg, "data");
4090 vat_json_init_array (counter_array);
4091 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4092 {
4093 packets = vam->simple_interface_counters[i][j];
4094 vat_json_array_add_uint (counter_array, packets);
4095 }
4096 }
4097 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4098 {
4099 msg = vat_json_array_add (msg_array);
4100 vat_json_init_object (msg);
4101 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4102 (u8 *) counter_type_to_str (i, 1));
4103 vat_json_object_add_int (msg, "is_combined", 1);
4104 counter_array = vat_json_object_add (msg, "data");
4105 vat_json_init_array (counter_array);
4106 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4107 {
4108 c = vam->combined_interface_counters[i][j];
4109 counter = vat_json_array_add (counter_array);
4110 vat_json_init_object (counter);
4111 vat_json_object_add_uint (counter, "packets", c.packets);
4112 vat_json_object_add_uint (counter, "bytes", c.bytes);
4113 }
4114 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004115
Dave Barach72d72232016-08-04 10:15:08 -04004116 /* ip4 fib counters */
4117 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4118 vat_json_init_array (msg_array);
4119 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4120 {
4121 msg = vat_json_array_add (msg_array);
4122 vat_json_init_object (msg);
4123 vat_json_object_add_uint (msg, "vrf_id",
4124 vam->ip4_fib_counters_vrf_id_by_index[i]);
4125 counter_array = vat_json_object_add (msg, "c");
4126 vat_json_init_array (counter_array);
4127 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4128 {
4129 counter = vat_json_array_add (counter_array);
4130 vat_json_init_object (counter);
4131 c4 = &vam->ip4_fib_counters[i][j];
4132 vat_json_object_add_ip4 (counter, "address", c4->address);
4133 vat_json_object_add_uint (counter, "address_length",
4134 c4->address_length);
4135 vat_json_object_add_uint (counter, "packets", c4->packets);
4136 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4137 }
4138 }
4139
4140 /* ip6 fib counters */
4141 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4142 vat_json_init_array (msg_array);
4143 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4144 {
4145 msg = vat_json_array_add (msg_array);
4146 vat_json_init_object (msg);
4147 vat_json_object_add_uint (msg, "vrf_id",
4148 vam->ip6_fib_counters_vrf_id_by_index[i]);
4149 counter_array = vat_json_object_add (msg, "c");
4150 vat_json_init_array (counter_array);
4151 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4152 {
4153 counter = vat_json_array_add (counter_array);
4154 vat_json_init_object (counter);
4155 c6 = &vam->ip6_fib_counters[i][j];
4156 vat_json_object_add_ip6 (counter, "address", c6->address);
4157 vat_json_object_add_uint (counter, "address_length",
4158 c6->address_length);
4159 vat_json_object_add_uint (counter, "packets", c6->packets);
4160 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4161 }
4162 }
4163
4164 vat_json_print (vam->ofp, &node);
4165 vat_json_free (&node);
4166
4167 return 0;
4168}
4169
4170int
4171exec (vat_main_t * vam)
4172{
4173 api_main_t *am = &api_main;
4174 vl_api_cli_request_t *mp;
4175 f64 timeout;
4176 void *oldheap;
4177 u8 *cmd = 0;
4178 unformat_input_t *i = vam->input;
4179
4180 if (vec_len (i->buffer) == 0)
4181 return -1;
4182
4183 if (vam->exec_mode == 0 && unformat (i, "mode"))
4184 {
4185 vam->exec_mode = 1;
4186 return 0;
4187 }
4188 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4189 {
4190 vam->exec_mode = 0;
4191 return 0;
4192 }
4193
4194
4195 M (CLI_REQUEST, cli_request);
4196
4197 /*
4198 * Copy cmd into shared memory.
4199 * In order for the CLI command to work, it
4200 * must be a vector ending in \n, not a C-string ending
4201 * in \n\0.
4202 */
4203 pthread_mutex_lock (&am->vlib_rp->mutex);
4204 oldheap = svm_push_data_heap (am->vlib_rp);
4205
4206 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4207 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4208
4209 svm_pop_heap (oldheap);
4210 pthread_mutex_unlock (&am->vlib_rp->mutex);
4211
4212 mp->cmd_in_shmem = (u64) cmd;
4213 S;
4214 timeout = vat_time_now (vam) + 10.0;
4215
4216 while (vat_time_now (vam) < timeout)
4217 {
4218 if (vam->result_ready == 1)
4219 {
4220 u8 *free_me;
4221 if (vam->shmem_result != NULL)
4222 fformat (vam->ofp, "%s", vam->shmem_result);
4223 pthread_mutex_lock (&am->vlib_rp->mutex);
4224 oldheap = svm_push_data_heap (am->vlib_rp);
4225
4226 free_me = (u8 *) vam->shmem_result;
4227 vec_free (free_me);
4228
4229 svm_pop_heap (oldheap);
4230 pthread_mutex_unlock (&am->vlib_rp->mutex);
4231 return 0;
4232 }
4233 }
4234 return -99;
4235}
4236
Ole Troanc27213a2016-08-31 14:50:49 +02004237/*
4238 * Future replacement of exec() that passes CLI buffers directly in
4239 * the API messages instead of an additional shared memory area.
4240 */
4241static int
4242exec_inband (vat_main_t * vam)
4243{
4244 vl_api_cli_inband_t *mp;
4245 f64 timeout;
4246 unformat_input_t *i = vam->input;
4247
4248 if (vec_len (i->buffer) == 0)
4249 return -1;
4250
4251 if (vam->exec_mode == 0 && unformat (i, "mode"))
4252 {
4253 vam->exec_mode = 1;
4254 return 0;
4255 }
4256 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4257 {
4258 vam->exec_mode = 0;
4259 return 0;
4260 }
4261
4262 /*
4263 * In order for the CLI command to work, it
4264 * must be a vector ending in \n, not a C-string ending
4265 * in \n\0.
4266 */
4267 u32 len = vec_len (vam->input->buffer);
4268 M2 (CLI_INBAND, cli_inband, len);
4269 clib_memcpy (mp->cmd, vam->input->buffer, len);
4270 mp->length = htonl (len);
4271
4272 S;
4273 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4274}
4275
Dave Barach72d72232016-08-04 10:15:08 -04004276static int
4277api_create_loopback (vat_main_t * vam)
4278{
4279 unformat_input_t *i = vam->input;
4280 vl_api_create_loopback_t *mp;
4281 f64 timeout;
4282 u8 mac_address[6];
4283 u8 mac_set = 0;
4284
4285 memset (mac_address, 0, sizeof (mac_address));
4286
4287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4288 {
4289 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4290 mac_set = 1;
4291 else
4292 break;
4293 }
4294
4295 /* Construct the API message */
4296 M (CREATE_LOOPBACK, create_loopback);
4297 if (mac_set)
4298 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4299
4300 S;
4301 W;
4302}
4303
4304static int
4305api_delete_loopback (vat_main_t * vam)
4306{
4307 unformat_input_t *i = vam->input;
4308 vl_api_delete_loopback_t *mp;
4309 f64 timeout;
4310 u32 sw_if_index = ~0;
4311
4312 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4313 {
4314 if (unformat (i, "sw_if_index %d", &sw_if_index))
4315 ;
4316 else
4317 break;
4318 }
4319
4320 if (sw_if_index == ~0)
4321 {
4322 errmsg ("missing sw_if_index\n");
4323 return -99;
4324 }
4325
4326 /* Construct the API message */
4327 M (DELETE_LOOPBACK, delete_loopback);
4328 mp->sw_if_index = ntohl (sw_if_index);
4329
4330 S;
4331 W;
4332}
4333
4334static int
4335api_want_stats (vat_main_t * vam)
4336{
4337 unformat_input_t *i = vam->input;
4338 vl_api_want_stats_t *mp;
4339 f64 timeout;
4340 int enable = -1;
4341
4342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4343 {
4344 if (unformat (i, "enable"))
4345 enable = 1;
4346 else if (unformat (i, "disable"))
4347 enable = 0;
4348 else
4349 break;
4350 }
4351
4352 if (enable == -1)
4353 {
4354 errmsg ("missing enable|disable\n");
4355 return -99;
4356 }
4357
4358 M (WANT_STATS, want_stats);
4359 mp->enable_disable = enable;
4360
4361 S;
4362 W;
4363}
4364
4365static int
4366api_want_interface_events (vat_main_t * vam)
4367{
4368 unformat_input_t *i = vam->input;
4369 vl_api_want_interface_events_t *mp;
4370 f64 timeout;
4371 int enable = -1;
4372
4373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4374 {
4375 if (unformat (i, "enable"))
4376 enable = 1;
4377 else if (unformat (i, "disable"))
4378 enable = 0;
4379 else
4380 break;
4381 }
4382
4383 if (enable == -1)
4384 {
4385 errmsg ("missing enable|disable\n");
4386 return -99;
4387 }
4388
4389 M (WANT_INTERFACE_EVENTS, want_interface_events);
4390 mp->enable_disable = enable;
4391
4392 vam->interface_event_display = enable;
4393
4394 S;
4395 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004396}
4397
4398
4399/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004400int
4401api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004402{
Dave Barach72d72232016-08-04 10:15:08 -04004403 vl_api_sw_interface_dump_t *mp;
4404 f64 timeout;
4405 hash_pair_t *p;
4406 name_sort_t *nses = 0, *ns;
4407 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004408
Dave Barach72d72232016-08-04 10:15:08 -04004409 /* Toss the old name table */
4410 /* *INDENT-OFF* */
4411 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4412 ({
4413 vec_add2 (nses, ns, 1);
4414 ns->name = (u8 *)(p->key);
4415 ns->value = (u32) p->value[0];
4416 }));
4417 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004418
Dave Barach72d72232016-08-04 10:15:08 -04004419 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004420
Dave Barach72d72232016-08-04 10:15:08 -04004421 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004422
Dave Barach72d72232016-08-04 10:15:08 -04004423 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004424
Dave Barach72d72232016-08-04 10:15:08 -04004425 vec_foreach (sub, vam->sw_if_subif_table)
4426 {
4427 vec_free (sub->interface_name);
4428 }
4429 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004430
Dave Barach72d72232016-08-04 10:15:08 -04004431 /* recreate the interface name hash table */
4432 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004433
Dave Barach72d72232016-08-04 10:15:08 -04004434 /* Get list of ethernets */
4435 M (SW_INTERFACE_DUMP, sw_interface_dump);
4436 mp->name_filter_valid = 1;
4437 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4438 S;
4439
4440 /* and local / loopback interfaces */
4441 M (SW_INTERFACE_DUMP, sw_interface_dump);
4442 mp->name_filter_valid = 1;
4443 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4444 S;
4445
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004446 /* and packet-generator interfaces */
4447 M (SW_INTERFACE_DUMP, sw_interface_dump);
4448 mp->name_filter_valid = 1;
4449 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4450 S;
Dave Barach72d72232016-08-04 10:15:08 -04004451
4452 /* and vxlan-gpe tunnel interfaces */
4453 M (SW_INTERFACE_DUMP, sw_interface_dump);
4454 mp->name_filter_valid = 1;
4455 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4456 sizeof (mp->name_filter) - 1);
4457 S;
4458
4459 /* and vxlan tunnel interfaces */
4460 M (SW_INTERFACE_DUMP, sw_interface_dump);
4461 mp->name_filter_valid = 1;
4462 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4463 S;
4464
4465 /* and host (af_packet) interfaces */
4466 M (SW_INTERFACE_DUMP, sw_interface_dump);
4467 mp->name_filter_valid = 1;
4468 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4469 S;
4470
4471 /* and l2tpv3 tunnel interfaces */
4472 M (SW_INTERFACE_DUMP, sw_interface_dump);
4473 mp->name_filter_valid = 1;
4474 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4475 sizeof (mp->name_filter) - 1);
4476 S;
4477
4478 /* and GRE tunnel interfaces */
4479 M (SW_INTERFACE_DUMP, sw_interface_dump);
4480 mp->name_filter_valid = 1;
4481 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4482 S;
4483
Florin Corasce982752016-09-06 13:36:11 +02004484 /* and LISP-GPE interfaces */
4485 M (SW_INTERFACE_DUMP, sw_interface_dump);
4486 mp->name_filter_valid = 1;
4487 strncpy ((char *) mp->name_filter, "lisp_gpe",
4488 sizeof (mp->name_filter) - 1);
4489 S;
4490
Matus Fabian8fce3e32016-09-06 23:19:43 -07004491 /* and IPSEC tunnel interfaces */
4492 M (SW_INTERFACE_DUMP, sw_interface_dump);
4493 mp->name_filter_valid = 1;
4494 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4495 S;
4496
Dave Barach72d72232016-08-04 10:15:08 -04004497 /* Use a control ping for synchronization */
4498 {
4499 vl_api_control_ping_t *mp;
4500 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004501 S;
Dave Barach72d72232016-08-04 10:15:08 -04004502 }
4503 W;
4504}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004505
Dave Barach72d72232016-08-04 10:15:08 -04004506static int
4507api_sw_interface_set_flags (vat_main_t * vam)
4508{
4509 unformat_input_t *i = vam->input;
4510 vl_api_sw_interface_set_flags_t *mp;
4511 f64 timeout;
4512 u32 sw_if_index;
4513 u8 sw_if_index_set = 0;
4514 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004515
Dave Barach72d72232016-08-04 10:15:08 -04004516 /* Parse args required to build the message */
4517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004518 {
Dave Barach72d72232016-08-04 10:15:08 -04004519 if (unformat (i, "admin-up"))
4520 admin_up = 1;
4521 else if (unformat (i, "admin-down"))
4522 admin_up = 0;
4523 else if (unformat (i, "link-up"))
4524 link_up = 1;
4525 else if (unformat (i, "link-down"))
4526 link_up = 0;
4527 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4528 sw_if_index_set = 1;
4529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4530 sw_if_index_set = 1;
4531 else
4532 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004533 }
4534
Dave Barach72d72232016-08-04 10:15:08 -04004535 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004536 {
Dave Barach72d72232016-08-04 10:15:08 -04004537 errmsg ("missing interface name or sw_if_index\n");
4538 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004539 }
4540
Dave Barach72d72232016-08-04 10:15:08 -04004541 /* Construct the API message */
4542 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4543 mp->sw_if_index = ntohl (sw_if_index);
4544 mp->admin_up_down = admin_up;
4545 mp->link_up_down = link_up;
4546
4547 /* send it... */
4548 S;
4549
4550 /* Wait for a reply, return the good/bad news... */
4551 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004552}
4553
Dave Barach72d72232016-08-04 10:15:08 -04004554static int
4555api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004556{
Dave Barach72d72232016-08-04 10:15:08 -04004557 unformat_input_t *i = vam->input;
4558 vl_api_sw_interface_clear_stats_t *mp;
4559 f64 timeout;
4560 u32 sw_if_index;
4561 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004562
Dave Barach72d72232016-08-04 10:15:08 -04004563 /* Parse args required to build the message */
4564 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4565 {
4566 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4567 sw_if_index_set = 1;
4568 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4569 sw_if_index_set = 1;
4570 else
4571 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004572 }
4573
Dave Barach72d72232016-08-04 10:15:08 -04004574 /* Construct the API message */
4575 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004576
Dave Barach72d72232016-08-04 10:15:08 -04004577 if (sw_if_index_set == 1)
4578 mp->sw_if_index = ntohl (sw_if_index);
4579 else
4580 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004581
Dave Barach72d72232016-08-04 10:15:08 -04004582 /* send it... */
4583 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004584
Dave Barach72d72232016-08-04 10:15:08 -04004585 /* Wait for a reply, return the good/bad news... */
4586 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004587}
4588
Dave Barach72d72232016-08-04 10:15:08 -04004589static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004590api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4591{
4592 unformat_input_t *i = vam->input;
4593 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4594 f64 timeout;
4595 u32 sw_if_index;
4596 u8 sw_if_index_set = 0;
4597 u32 subport;
4598 u8 subport_set = 0;
4599 u32 pipe;
4600 u8 pipe_set = 0;
4601 u32 profile;
4602 u8 profile_set = 0;
4603
4604 /* Parse args required to build the message */
4605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4606 {
4607 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4608 sw_if_index_set = 1;
4609 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4610 sw_if_index_set = 1;
4611 else if (unformat (i, "subport %u", &subport))
4612 subport_set = 1;
4613 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4614 sw_if_index_set = 1;
4615 else if (unformat (i, "pipe %u", &pipe))
4616 pipe_set = 1;
4617 else if (unformat (i, "profile %u", &profile))
4618 profile_set = 1;
4619 else
4620 break;
4621 }
4622
4623 if (sw_if_index_set == 0)
4624 {
4625 errmsg ("missing interface name or sw_if_index\n");
4626 return -99;
4627 }
4628
4629 if (subport_set == 0)
4630 {
4631 errmsg ("missing subport \n");
4632 return -99;
4633 }
4634
4635 if (pipe_set == 0)
4636 {
4637 errmsg ("missing pipe\n");
4638 return -99;
4639 }
4640
4641 if (profile_set == 0)
4642 {
4643 errmsg ("missing profile\n");
4644 return -99;
4645 }
4646
4647 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4648
4649 mp->sw_if_index = ntohl (sw_if_index);
4650 mp->subport = ntohl (subport);
4651 mp->pipe = ntohl (pipe);
4652 mp->profile = ntohl (profile);
4653
4654
4655 S;
4656 W;
4657 /* NOTREACHED */
4658 return 0;
4659}
4660
4661static int
4662api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4663{
4664 unformat_input_t *i = vam->input;
4665 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4666 f64 timeout;
4667 u32 sw_if_index;
4668 u8 sw_if_index_set = 0;
4669 u32 subport;
4670 u8 subport_set = 0;
4671 u32 tb_rate = 1250000000; /* 10GbE */
4672 u32 tb_size = 1000000;
4673 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4674 u32 tc_period = 10;
4675
4676 /* Parse args required to build the message */
4677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4678 {
4679 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4680 sw_if_index_set = 1;
4681 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4682 sw_if_index_set = 1;
4683 else if (unformat (i, "subport %u", &subport))
4684 subport_set = 1;
4685 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4686 sw_if_index_set = 1;
4687 else if (unformat (i, "rate %u", &tb_rate))
4688 {
4689 u32 tc_id;
4690
4691 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4692 tc_id++)
4693 tc_rate[tc_id] = tb_rate;
4694 }
4695 else if (unformat (i, "bktsize %u", &tb_size))
4696 ;
4697 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4698 ;
4699 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4700 ;
4701 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4702 ;
4703 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4704 ;
4705 else if (unformat (i, "period %u", &tc_period))
4706 ;
4707 else
4708 break;
4709 }
4710
4711 if (sw_if_index_set == 0)
4712 {
4713 errmsg ("missing interface name or sw_if_index\n");
4714 return -99;
4715 }
4716
4717 if (subport_set == 0)
4718 {
4719 errmsg ("missing subport \n");
4720 return -99;
4721 }
4722
4723 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4724
4725 mp->sw_if_index = ntohl (sw_if_index);
4726 mp->subport = ntohl (subport);
4727 mp->tb_rate = ntohl (tb_rate);
4728 mp->tb_size = ntohl (tb_size);
4729 mp->tc_rate[0] = ntohl (tc_rate[0]);
4730 mp->tc_rate[1] = ntohl (tc_rate[1]);
4731 mp->tc_rate[2] = ntohl (tc_rate[2]);
4732 mp->tc_rate[3] = ntohl (tc_rate[3]);
4733 mp->tc_period = ntohl (tc_period);
4734
4735 S;
4736 W;
4737 /* NOTREACHED */
4738 return 0;
4739}
4740
4741static int
4742api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4743{
4744 unformat_input_t *i = vam->input;
4745 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4746 f64 timeout;
4747 u32 sw_if_index;
4748 u8 sw_if_index_set = 0;
4749 u8 entry_set = 0;
4750 u8 tc_set = 0;
4751 u8 queue_set = 0;
4752 u32 entry, tc, queue;
4753
4754 /* Parse args required to build the message */
4755 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4756 {
4757 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4758 sw_if_index_set = 1;
4759 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4760 sw_if_index_set = 1;
4761 else if (unformat (i, "entry %d", &entry))
4762 entry_set = 1;
4763 else if (unformat (i, "tc %d", &tc))
4764 tc_set = 1;
4765 else if (unformat (i, "queue %d", &queue))
4766 queue_set = 1;
4767 else
4768 break;
4769 }
4770
4771 if (sw_if_index_set == 0)
4772 {
4773 errmsg ("missing interface name or sw_if_index\n");
4774 return -99;
4775 }
4776
4777 if (entry_set == 0)
4778 {
4779 errmsg ("missing entry \n");
4780 return -99;
4781 }
4782
4783 if (tc_set == 0)
4784 {
4785 errmsg ("missing traffic class \n");
4786 return -99;
4787 }
4788
4789 if (queue_set == 0)
4790 {
4791 errmsg ("missing queue \n");
4792 return -99;
4793 }
4794
4795 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4796
4797 mp->sw_if_index = ntohl (sw_if_index);
4798 mp->entry = ntohl (entry);
4799 mp->tc = ntohl (tc);
4800 mp->queue = ntohl (queue);
4801
4802 S;
4803 W;
4804 /* NOTREACHED */
4805 return 0;
4806}
4807
4808static int
Dave Barach72d72232016-08-04 10:15:08 -04004809api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004810{
Dave Barach72d72232016-08-04 10:15:08 -04004811 unformat_input_t *i = vam->input;
4812 vl_api_sw_interface_add_del_address_t *mp;
4813 f64 timeout;
4814 u32 sw_if_index;
4815 u8 sw_if_index_set = 0;
4816 u8 is_add = 1, del_all = 0;
4817 u32 address_length = 0;
4818 u8 v4_address_set = 0;
4819 u8 v6_address_set = 0;
4820 ip4_address_t v4address;
4821 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004822
Dave Barach72d72232016-08-04 10:15:08 -04004823 /* Parse args required to build the message */
4824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4825 {
4826 if (unformat (i, "del-all"))
4827 del_all = 1;
4828 else if (unformat (i, "del"))
4829 is_add = 0;
4830 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4831 sw_if_index_set = 1;
4832 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4833 sw_if_index_set = 1;
4834 else if (unformat (i, "%U/%d",
4835 unformat_ip4_address, &v4address, &address_length))
4836 v4_address_set = 1;
4837 else if (unformat (i, "%U/%d",
4838 unformat_ip6_address, &v6address, &address_length))
4839 v6_address_set = 1;
4840 else
4841 break;
4842 }
4843
4844 if (sw_if_index_set == 0)
4845 {
4846 errmsg ("missing interface name or sw_if_index\n");
4847 return -99;
4848 }
4849 if (v4_address_set && v6_address_set)
4850 {
4851 errmsg ("both v4 and v6 addresses set\n");
4852 return -99;
4853 }
4854 if (!v4_address_set && !v6_address_set && !del_all)
4855 {
4856 errmsg ("no addresses set\n");
4857 return -99;
4858 }
4859
4860 /* Construct the API message */
4861 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4862
4863 mp->sw_if_index = ntohl (sw_if_index);
4864 mp->is_add = is_add;
4865 mp->del_all = del_all;
4866 if (v6_address_set)
4867 {
4868 mp->is_ipv6 = 1;
4869 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4870 }
4871 else
4872 {
4873 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4874 }
4875 mp->address_length = address_length;
4876
4877 /* send it... */
4878 S;
4879
4880 /* Wait for a reply, return good/bad news */
4881 W;
4882}
4883
4884static int
John Lo06b14b92016-10-24 20:20:11 -04004885api_sw_interface_set_mpls_enable (vat_main_t * vam)
4886{
4887 unformat_input_t *i = vam->input;
4888 vl_api_sw_interface_set_mpls_enable_t *mp;
4889 f64 timeout;
4890 u32 sw_if_index;
4891 u8 sw_if_index_set = 0;
4892 u8 enable = 1;
4893
4894 /* Parse args required to build the message */
4895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4896 {
4897 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4898 sw_if_index_set = 1;
4899 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4900 sw_if_index_set = 1;
4901 else if (unformat (i, "disable"))
4902 enable = 0;
4903 else if (unformat (i, "dis"))
4904 enable = 0;
4905 else
4906 break;
4907 }
4908
4909 if (sw_if_index_set == 0)
4910 {
4911 errmsg ("missing interface name or sw_if_index\n");
4912 return -99;
4913 }
4914
4915 /* Construct the API message */
4916 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
4917
4918 mp->sw_if_index = ntohl (sw_if_index);
4919 mp->enable = enable;
4920
4921 /* send it... */
4922 S;
4923
4924 /* Wait for a reply... */
4925 W;
4926}
4927
4928static int
Dave Barach72d72232016-08-04 10:15:08 -04004929api_sw_interface_set_table (vat_main_t * vam)
4930{
4931 unformat_input_t *i = vam->input;
4932 vl_api_sw_interface_set_table_t *mp;
4933 f64 timeout;
4934 u32 sw_if_index, vrf_id = 0;
4935 u8 sw_if_index_set = 0;
4936 u8 is_ipv6 = 0;
4937
4938 /* Parse args required to build the message */
4939 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4940 {
4941 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4942 sw_if_index_set = 1;
4943 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4944 sw_if_index_set = 1;
4945 else if (unformat (i, "vrf %d", &vrf_id))
4946 ;
4947 else if (unformat (i, "ipv6"))
4948 is_ipv6 = 1;
4949 else
4950 break;
4951 }
4952
4953 if (sw_if_index_set == 0)
4954 {
4955 errmsg ("missing interface name or sw_if_index\n");
4956 return -99;
4957 }
4958
4959 /* Construct the API message */
4960 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4961
4962 mp->sw_if_index = ntohl (sw_if_index);
4963 mp->is_ipv6 = is_ipv6;
4964 mp->vrf_id = ntohl (vrf_id);
4965
4966 /* send it... */
4967 S;
4968
4969 /* Wait for a reply... */
4970 W;
4971}
4972
4973static int
4974api_sw_interface_set_vpath (vat_main_t * vam)
4975{
4976 unformat_input_t *i = vam->input;
4977 vl_api_sw_interface_set_vpath_t *mp;
4978 f64 timeout;
4979 u32 sw_if_index = 0;
4980 u8 sw_if_index_set = 0;
4981 u8 is_enable = 0;
4982
4983 /* Parse args required to build the message */
4984 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4985 {
4986 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4987 sw_if_index_set = 1;
4988 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4989 sw_if_index_set = 1;
4990 else if (unformat (i, "enable"))
4991 is_enable = 1;
4992 else if (unformat (i, "disable"))
4993 is_enable = 0;
4994 else
4995 break;
4996 }
4997
4998 if (sw_if_index_set == 0)
4999 {
5000 errmsg ("missing interface name or sw_if_index\n");
5001 return -99;
5002 }
5003
5004 /* Construct the API message */
5005 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5006
5007 mp->sw_if_index = ntohl (sw_if_index);
5008 mp->enable = is_enable;
5009
5010 /* send it... */
5011 S;
5012
5013 /* Wait for a reply... */
5014 W;
5015}
5016
5017static int
John Lo37682e12016-11-30 12:51:39 -05005018api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
5019{
5020 unformat_input_t *i = vam->input;
5021 vl_api_sw_interface_set_vxlan_bypass_t *mp;
5022 f64 timeout;
5023 u32 sw_if_index = 0;
5024 u8 sw_if_index_set = 0;
5025 u8 is_enable = 0;
5026 u8 is_ipv6 = 0;
5027
5028 /* Parse args required to build the message */
5029 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5030 {
5031 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5032 sw_if_index_set = 1;
5033 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5034 sw_if_index_set = 1;
5035 else if (unformat (i, "enable"))
5036 is_enable = 1;
5037 else if (unformat (i, "disable"))
5038 is_enable = 0;
5039 else if (unformat (i, "ip4"))
5040 is_ipv6 = 0;
5041 else if (unformat (i, "ip6"))
5042 is_ipv6 = 1;
5043 else
5044 break;
5045 }
5046
5047 if (sw_if_index_set == 0)
5048 {
5049 errmsg ("missing interface name or sw_if_index\n");
5050 return -99;
5051 }
5052
5053 /* Construct the API message */
5054 M (SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass);
5055
5056 mp->sw_if_index = ntohl (sw_if_index);
5057 mp->enable = is_enable;
5058 mp->is_ipv6 = is_ipv6;
5059
5060 /* send it... */
5061 S;
5062
5063 /* Wait for a reply... */
5064 W;
5065}
5066
5067static int
Dave Barach72d72232016-08-04 10:15:08 -04005068api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5069{
5070 unformat_input_t *i = vam->input;
5071 vl_api_sw_interface_set_l2_xconnect_t *mp;
5072 f64 timeout;
5073 u32 rx_sw_if_index;
5074 u8 rx_sw_if_index_set = 0;
5075 u32 tx_sw_if_index;
5076 u8 tx_sw_if_index_set = 0;
5077 u8 enable = 1;
5078
5079 /* Parse args required to build the message */
5080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5081 {
5082 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5083 rx_sw_if_index_set = 1;
5084 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5085 tx_sw_if_index_set = 1;
5086 else if (unformat (i, "rx"))
5087 {
5088 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5089 {
5090 if (unformat (i, "%U", unformat_sw_if_index, vam,
5091 &rx_sw_if_index))
5092 rx_sw_if_index_set = 1;
5093 }
5094 else
Dave Barach41da02d2016-07-11 16:48:42 -07005095 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005096 }
Dave Barach72d72232016-08-04 10:15:08 -04005097 else if (unformat (i, "tx"))
5098 {
5099 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5100 {
5101 if (unformat (i, "%U", unformat_sw_if_index, vam,
5102 &tx_sw_if_index))
5103 tx_sw_if_index_set = 1;
5104 }
5105 else
5106 break;
5107 }
5108 else if (unformat (i, "enable"))
5109 enable = 1;
5110 else if (unformat (i, "disable"))
5111 enable = 0;
5112 else
5113 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005114 }
5115
Dave Barach72d72232016-08-04 10:15:08 -04005116 if (rx_sw_if_index_set == 0)
5117 {
5118 errmsg ("missing rx interface name or rx_sw_if_index\n");
5119 return -99;
5120 }
Dave Barach41da02d2016-07-11 16:48:42 -07005121
Dave Barach72d72232016-08-04 10:15:08 -04005122 if (enable && (tx_sw_if_index_set == 0))
5123 {
5124 errmsg ("missing tx interface name or tx_sw_if_index\n");
5125 return -99;
5126 }
Dave Barach41da02d2016-07-11 16:48:42 -07005127
Dave Barach72d72232016-08-04 10:15:08 -04005128 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005129
Dave Barach72d72232016-08-04 10:15:08 -04005130 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5131 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5132 mp->enable = enable;
5133
5134 S;
5135 W;
5136 /* NOTREACHED */
5137 return 0;
5138}
5139
5140static int
5141api_sw_interface_set_l2_bridge (vat_main_t * vam)
5142{
5143 unformat_input_t *i = vam->input;
5144 vl_api_sw_interface_set_l2_bridge_t *mp;
5145 f64 timeout;
5146 u32 rx_sw_if_index;
5147 u8 rx_sw_if_index_set = 0;
5148 u32 bd_id;
5149 u8 bd_id_set = 0;
5150 u8 bvi = 0;
5151 u32 shg = 0;
5152 u8 enable = 1;
5153
5154 /* Parse args required to build the message */
5155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5156 {
5157 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5158 rx_sw_if_index_set = 1;
5159 else if (unformat (i, "bd_id %d", &bd_id))
5160 bd_id_set = 1;
5161 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5162 rx_sw_if_index_set = 1;
5163 else if (unformat (i, "shg %d", &shg))
5164 ;
5165 else if (unformat (i, "bvi"))
5166 bvi = 1;
5167 else if (unformat (i, "enable"))
5168 enable = 1;
5169 else if (unformat (i, "disable"))
5170 enable = 0;
5171 else
5172 break;
5173 }
5174
5175 if (rx_sw_if_index_set == 0)
5176 {
5177 errmsg ("missing rx interface name or sw_if_index\n");
5178 return -99;
5179 }
5180
5181 if (enable && (bd_id_set == 0))
5182 {
5183 errmsg ("missing bridge domain\n");
5184 return -99;
5185 }
5186
5187 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5188
5189 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5190 mp->bd_id = ntohl (bd_id);
5191 mp->shg = (u8) shg;
5192 mp->bvi = bvi;
5193 mp->enable = enable;
5194
5195 S;
5196 W;
5197 /* NOTREACHED */
5198 return 0;
5199}
5200
5201static int
5202api_bridge_domain_dump (vat_main_t * vam)
5203{
5204 unformat_input_t *i = vam->input;
5205 vl_api_bridge_domain_dump_t *mp;
5206 f64 timeout;
5207 u32 bd_id = ~0;
5208
5209 /* Parse args required to build the message */
5210 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5211 {
5212 if (unformat (i, "bd_id %d", &bd_id))
5213 ;
5214 else
5215 break;
5216 }
5217
5218 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5219 mp->bd_id = ntohl (bd_id);
5220 S;
5221
5222 /* Use a control ping for synchronization */
5223 {
5224 vl_api_control_ping_t *mp;
5225 M (CONTROL_PING, control_ping);
5226 S;
5227 }
5228
5229 W;
5230 /* NOTREACHED */
5231 return 0;
5232}
5233
5234static int
5235api_bridge_domain_add_del (vat_main_t * vam)
5236{
5237 unformat_input_t *i = vam->input;
5238 vl_api_bridge_domain_add_del_t *mp;
5239 f64 timeout;
5240 u32 bd_id = ~0;
5241 u8 is_add = 1;
5242 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5243
5244 /* Parse args required to build the message */
5245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5246 {
5247 if (unformat (i, "bd_id %d", &bd_id))
5248 ;
5249 else if (unformat (i, "flood %d", &flood))
5250 ;
5251 else if (unformat (i, "uu-flood %d", &uu_flood))
5252 ;
5253 else if (unformat (i, "forward %d", &forward))
5254 ;
5255 else if (unformat (i, "learn %d", &learn))
5256 ;
5257 else if (unformat (i, "arp-term %d", &arp_term))
5258 ;
5259 else if (unformat (i, "del"))
5260 {
5261 is_add = 0;
5262 flood = uu_flood = forward = learn = 0;
5263 }
5264 else
5265 break;
5266 }
5267
5268 if (bd_id == ~0)
5269 {
5270 errmsg ("missing bridge domain\n");
5271 return -99;
5272 }
5273
5274 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5275
5276 mp->bd_id = ntohl (bd_id);
5277 mp->flood = flood;
5278 mp->uu_flood = uu_flood;
5279 mp->forward = forward;
5280 mp->learn = learn;
5281 mp->arp_term = arp_term;
5282 mp->is_add = is_add;
5283
5284 S;
5285 W;
5286 /* NOTREACHED */
5287 return 0;
5288}
5289
5290static int
5291api_l2fib_add_del (vat_main_t * vam)
5292{
5293 unformat_input_t *i = vam->input;
5294 vl_api_l2fib_add_del_t *mp;
5295 f64 timeout;
5296 u64 mac = 0;
5297 u8 mac_set = 0;
5298 u32 bd_id;
5299 u8 bd_id_set = 0;
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005300 u32 sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04005301 u8 sw_if_index_set = 0;
5302 u8 is_add = 1;
5303 u8 static_mac = 0;
5304 u8 filter_mac = 0;
5305 u8 bvi_mac = 0;
5306 int count = 1;
5307 f64 before = 0;
5308 int j;
5309
5310 /* Parse args required to build the message */
5311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5312 {
5313 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5314 mac_set = 1;
5315 else if (unformat (i, "bd_id %d", &bd_id))
5316 bd_id_set = 1;
5317 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5318 sw_if_index_set = 1;
5319 else if (unformat (i, "sw_if"))
5320 {
5321 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5322 {
5323 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5324 sw_if_index_set = 1;
5325 }
5326 else
5327 break;
5328 }
5329 else if (unformat (i, "static"))
5330 static_mac = 1;
5331 else if (unformat (i, "filter"))
5332 {
5333 filter_mac = 1;
5334 static_mac = 1;
5335 }
5336 else if (unformat (i, "bvi"))
5337 {
5338 bvi_mac = 1;
5339 static_mac = 1;
5340 }
5341 else if (unformat (i, "del"))
5342 is_add = 0;
5343 else if (unformat (i, "count %d", &count))
5344 ;
5345 else
5346 break;
5347 }
5348
5349 if (mac_set == 0)
5350 {
5351 errmsg ("missing mac address\n");
5352 return -99;
5353 }
5354
5355 if (bd_id_set == 0)
5356 {
5357 errmsg ("missing bridge domain\n");
5358 return -99;
5359 }
5360
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005361 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
Dave Barach72d72232016-08-04 10:15:08 -04005362 {
5363 errmsg ("missing interface name or sw_if_index\n");
5364 return -99;
5365 }
5366
5367 if (count > 1)
5368 {
5369 /* Turn on async mode */
5370 vam->async_mode = 1;
5371 vam->async_errors = 0;
5372 before = vat_time_now (vam);
5373 }
5374
5375 for (j = 0; j < count; j++)
5376 {
5377 M (L2FIB_ADD_DEL, l2fib_add_del);
5378
5379 mp->mac = mac;
5380 mp->bd_id = ntohl (bd_id);
5381 mp->is_add = is_add;
5382
5383 if (is_add)
5384 {
5385 mp->sw_if_index = ntohl (sw_if_index);
5386 mp->static_mac = static_mac;
5387 mp->filter_mac = filter_mac;
5388 mp->bvi_mac = bvi_mac;
5389 }
5390 increment_mac_address (&mac);
5391 /* send it... */
5392 S;
5393 }
5394
5395 if (count > 1)
5396 {
5397 vl_api_control_ping_t *mp;
5398 f64 after;
5399
5400 /* Shut off async mode */
5401 vam->async_mode = 0;
5402
5403 M (CONTROL_PING, control_ping);
5404 S;
5405
5406 timeout = vat_time_now (vam) + 1.0;
5407 while (vat_time_now (vam) < timeout)
5408 if (vam->result_ready == 1)
5409 goto out;
5410 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005411
5412 out:
Dave Barach72d72232016-08-04 10:15:08 -04005413 if (vam->retval == -99)
5414 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005415
Dave Barach72d72232016-08-04 10:15:08 -04005416 if (vam->async_errors > 0)
5417 {
5418 errmsg ("%d asynchronous errors\n", vam->async_errors);
5419 vam->retval = -98;
5420 }
5421 vam->async_errors = 0;
5422 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005423
Dave Barach72d72232016-08-04 10:15:08 -04005424 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5425 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005426 }
Dave Barach72d72232016-08-04 10:15:08 -04005427 else
5428 {
5429 /* Wait for a reply... */
5430 W;
5431 }
5432 /* Return the good/bad news */
5433 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005434}
5435
Dave Barach72d72232016-08-04 10:15:08 -04005436static int
5437api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005438{
Dave Barach72d72232016-08-04 10:15:08 -04005439 unformat_input_t *i = vam->input;
5440 vl_api_l2_flags_t *mp;
5441 f64 timeout;
5442 u32 sw_if_index;
5443 u32 feature_bitmap = 0;
5444 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005445
Dave Barach72d72232016-08-04 10:15:08 -04005446 /* Parse args required to build the message */
5447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5448 {
5449 if (unformat (i, "sw_if_index %d", &sw_if_index))
5450 sw_if_index_set = 1;
5451 else if (unformat (i, "sw_if"))
5452 {
5453 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5454 {
5455 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5456 sw_if_index_set = 1;
5457 }
5458 else
5459 break;
5460 }
5461 else if (unformat (i, "learn"))
5462 feature_bitmap |= L2INPUT_FEAT_LEARN;
5463 else if (unformat (i, "forward"))
5464 feature_bitmap |= L2INPUT_FEAT_FWD;
5465 else if (unformat (i, "flood"))
5466 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5467 else if (unformat (i, "uu-flood"))
5468 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5469 else
5470 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005471 }
5472
Dave Barach72d72232016-08-04 10:15:08 -04005473 if (sw_if_index_set == 0)
5474 {
5475 errmsg ("missing interface name or sw_if_index\n");
5476 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005477 }
5478
Dave Barach72d72232016-08-04 10:15:08 -04005479 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005480
Dave Barach72d72232016-08-04 10:15:08 -04005481 mp->sw_if_index = ntohl (sw_if_index);
5482 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005483
Dave Barach72d72232016-08-04 10:15:08 -04005484 S;
5485 W;
5486 /* NOTREACHED */
5487 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005488}
5489
Dave Barach72d72232016-08-04 10:15:08 -04005490static int
5491api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005492{
Dave Barach72d72232016-08-04 10:15:08 -04005493 unformat_input_t *i = vam->input;
5494 vl_api_bridge_flags_t *mp;
5495 f64 timeout;
5496 u32 bd_id;
5497 u8 bd_id_set = 0;
5498 u8 is_set = 1;
5499 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005500
Dave Barach72d72232016-08-04 10:15:08 -04005501 /* Parse args required to build the message */
5502 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5503 {
5504 if (unformat (i, "bd_id %d", &bd_id))
5505 bd_id_set = 1;
5506 else if (unformat (i, "learn"))
5507 flags |= L2_LEARN;
5508 else if (unformat (i, "forward"))
5509 flags |= L2_FWD;
5510 else if (unformat (i, "flood"))
5511 flags |= L2_FLOOD;
5512 else if (unformat (i, "uu-flood"))
5513 flags |= L2_UU_FLOOD;
5514 else if (unformat (i, "arp-term"))
5515 flags |= L2_ARP_TERM;
5516 else if (unformat (i, "off"))
5517 is_set = 0;
5518 else if (unformat (i, "disable"))
5519 is_set = 0;
5520 else
5521 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005522 }
5523
Dave Barach72d72232016-08-04 10:15:08 -04005524 if (bd_id_set == 0)
5525 {
5526 errmsg ("missing bridge domain\n");
5527 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005528 }
5529
Dave Barach72d72232016-08-04 10:15:08 -04005530 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005531
Dave Barach72d72232016-08-04 10:15:08 -04005532 mp->bd_id = ntohl (bd_id);
5533 mp->feature_bitmap = ntohl (flags);
5534 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005535
Dave Barach72d72232016-08-04 10:15:08 -04005536 S;
5537 W;
5538 /* NOTREACHED */
5539 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005540}
5541
Dave Barach72d72232016-08-04 10:15:08 -04005542static int
5543api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005544{
Dave Barach72d72232016-08-04 10:15:08 -04005545 unformat_input_t *i = vam->input;
5546 vl_api_bd_ip_mac_add_del_t *mp;
5547 f64 timeout;
5548 u32 bd_id;
5549 u8 is_ipv6 = 0;
5550 u8 is_add = 1;
5551 u8 bd_id_set = 0;
5552 u8 ip_set = 0;
5553 u8 mac_set = 0;
5554 ip4_address_t v4addr;
5555 ip6_address_t v6addr;
5556 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005557
Ed Warnickecb9cada2015-12-08 15:45:58 -07005558
Dave Barach72d72232016-08-04 10:15:08 -04005559 /* Parse args required to build the message */
5560 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5561 {
5562 if (unformat (i, "bd_id %d", &bd_id))
5563 {
5564 bd_id_set++;
5565 }
5566 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5567 {
5568 ip_set++;
5569 }
5570 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5571 {
5572 ip_set++;
5573 is_ipv6++;
5574 }
5575 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5576 {
5577 mac_set++;
5578 }
5579 else if (unformat (i, "del"))
5580 is_add = 0;
5581 else
5582 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005583 }
5584
Dave Barach72d72232016-08-04 10:15:08 -04005585 if (bd_id_set == 0)
5586 {
5587 errmsg ("missing bridge domain\n");
5588 return -99;
5589 }
5590 else if (ip_set == 0)
5591 {
5592 errmsg ("missing IP address\n");
5593 return -99;
5594 }
5595 else if (mac_set == 0)
5596 {
5597 errmsg ("missing MAC address\n");
5598 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005599 }
5600
Dave Barach72d72232016-08-04 10:15:08 -04005601 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005602
Dave Barach72d72232016-08-04 10:15:08 -04005603 mp->bd_id = ntohl (bd_id);
5604 mp->is_ipv6 = is_ipv6;
5605 mp->is_add = is_add;
5606 if (is_ipv6)
5607 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5608 else
5609 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5610 clib_memcpy (mp->mac_address, macaddr, 6);
5611 S;
5612 W;
5613 /* NOTREACHED */
5614 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005615}
5616
Dave Barach72d72232016-08-04 10:15:08 -04005617static int
5618api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005619{
Dave Barach72d72232016-08-04 10:15:08 -04005620 unformat_input_t *i = vam->input;
5621 vl_api_tap_connect_t *mp;
5622 f64 timeout;
5623 u8 mac_address[6];
5624 u8 random_mac = 1;
5625 u8 name_set = 0;
5626 u8 *tap_name;
Dave Barach7be864a2016-11-28 11:41:35 -05005627 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005628
Dave Barach72d72232016-08-04 10:15:08 -04005629 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005630
Dave Barach72d72232016-08-04 10:15:08 -04005631 /* Parse args required to build the message */
5632 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5633 {
5634 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5635 {
5636 random_mac = 0;
5637 }
5638 else if (unformat (i, "random-mac"))
5639 random_mac = 1;
5640 else if (unformat (i, "tapname %s", &tap_name))
5641 name_set = 1;
Dave Barach7be864a2016-11-28 11:41:35 -05005642 else if (unformat (i, "tag %s", &tag));
Dave Barach72d72232016-08-04 10:15:08 -04005643 else
5644 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005645 }
5646
Dave Barach72d72232016-08-04 10:15:08 -04005647 if (name_set == 0)
5648 {
5649 errmsg ("missing tap name\n");
5650 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005651 }
Dave Barach72d72232016-08-04 10:15:08 -04005652 if (vec_len (tap_name) > 63)
5653 {
5654 errmsg ("tap name too long\n");
Dave Barach7be864a2016-11-28 11:41:35 -05005655 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005656 }
Dave Barach72d72232016-08-04 10:15:08 -04005657 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005658
Dave Barach7be864a2016-11-28 11:41:35 -05005659 if (vec_len (tag) > 63)
5660 {
5661 errmsg ("tag too long\n");
5662 return -99;
5663 }
5664 vec_add1 (tag, 0);
5665
Dave Barach72d72232016-08-04 10:15:08 -04005666 /* Construct the API message */
5667 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005668
Dave Barach72d72232016-08-04 10:15:08 -04005669 mp->use_random_mac = random_mac;
5670 clib_memcpy (mp->mac_address, mac_address, 6);
5671 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
Dave Barach7be864a2016-11-28 11:41:35 -05005672 if (tag)
5673 clib_memcpy (mp->tag, tag, vec_len (tag));
5674
Dave Barach72d72232016-08-04 10:15:08 -04005675 vec_free (tap_name);
Dave Barach7be864a2016-11-28 11:41:35 -05005676 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005677
Dave Barach72d72232016-08-04 10:15:08 -04005678 /* send it... */
5679 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005680
Dave Barach72d72232016-08-04 10:15:08 -04005681 /* Wait for a reply... */
5682 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005683}
5684
Dave Barach72d72232016-08-04 10:15:08 -04005685static int
5686api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005687{
Dave Barach72d72232016-08-04 10:15:08 -04005688 unformat_input_t *i = vam->input;
5689 vl_api_tap_modify_t *mp;
5690 f64 timeout;
5691 u8 mac_address[6];
5692 u8 random_mac = 1;
5693 u8 name_set = 0;
5694 u8 *tap_name;
5695 u32 sw_if_index = ~0;
5696 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005697
Dave Barach72d72232016-08-04 10:15:08 -04005698 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005699
Dave Barach72d72232016-08-04 10:15:08 -04005700 /* Parse args required to build the message */
5701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5702 {
5703 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5704 sw_if_index_set = 1;
5705 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5706 sw_if_index_set = 1;
5707 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5708 {
5709 random_mac = 0;
5710 }
5711 else if (unformat (i, "random-mac"))
5712 random_mac = 1;
5713 else if (unformat (i, "tapname %s", &tap_name))
5714 name_set = 1;
5715 else
5716 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005717 }
5718
Dave Barach72d72232016-08-04 10:15:08 -04005719 if (sw_if_index_set == 0)
5720 {
5721 errmsg ("missing vpp interface name");
5722 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005723 }
Dave Barach72d72232016-08-04 10:15:08 -04005724 if (name_set == 0)
5725 {
5726 errmsg ("missing tap name\n");
5727 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005728 }
Dave Barach72d72232016-08-04 10:15:08 -04005729 if (vec_len (tap_name) > 63)
5730 {
5731 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005732 }
Dave Barach72d72232016-08-04 10:15:08 -04005733 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005734
Dave Barach72d72232016-08-04 10:15:08 -04005735 /* Construct the API message */
5736 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005737
Dave Barach72d72232016-08-04 10:15:08 -04005738 mp->use_random_mac = random_mac;
5739 mp->sw_if_index = ntohl (sw_if_index);
5740 clib_memcpy (mp->mac_address, mac_address, 6);
5741 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5742 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005743
Dave Barach72d72232016-08-04 10:15:08 -04005744 /* send it... */
5745 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005746
Dave Barach72d72232016-08-04 10:15:08 -04005747 /* Wait for a reply... */
5748 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005749}
5750
Dave Barach72d72232016-08-04 10:15:08 -04005751static int
5752api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005753{
Dave Barach72d72232016-08-04 10:15:08 -04005754 unformat_input_t *i = vam->input;
5755 vl_api_tap_delete_t *mp;
5756 f64 timeout;
5757 u32 sw_if_index = ~0;
5758 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005759
Dave Barach72d72232016-08-04 10:15:08 -04005760 /* Parse args required to build the message */
5761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5762 {
5763 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5764 sw_if_index_set = 1;
5765 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5766 sw_if_index_set = 1;
5767 else
5768 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005769 }
5770
Dave Barach72d72232016-08-04 10:15:08 -04005771 if (sw_if_index_set == 0)
5772 {
5773 errmsg ("missing vpp interface name");
5774 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005775 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005776
Dave Barach72d72232016-08-04 10:15:08 -04005777 /* Construct the API message */
5778 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005779
Dave Barach72d72232016-08-04 10:15:08 -04005780 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005781
Dave Barach72d72232016-08-04 10:15:08 -04005782 /* send it... */
5783 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005784
Dave Barach72d72232016-08-04 10:15:08 -04005785 /* Wait for a reply... */
5786 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005787}
5788
Dave Barach72d72232016-08-04 10:15:08 -04005789static int
5790api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005791{
Dave Barach72d72232016-08-04 10:15:08 -04005792 unformat_input_t *i = vam->input;
5793 vl_api_ip_add_del_route_t *mp;
5794 f64 timeout;
5795 u32 sw_if_index = ~0, vrf_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005796 u8 is_ipv6 = 0;
5797 u8 is_local = 0, is_drop = 0;
Neale Ranns948e00f2016-10-20 13:39:34 +01005798 u8 is_unreach = 0, is_prohibit = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005799 u8 create_vrf_if_needed = 0;
5800 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00005801 u32 next_hop_weight = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005802 u8 not_last = 0;
5803 u8 is_multipath = 0;
5804 u8 address_set = 0;
5805 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005806 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005807 u32 resolve_attempts = 0;
5808 u32 dst_address_length = 0;
5809 u8 next_hop_set = 0;
5810 ip4_address_t v4_dst_address, v4_next_hop_address;
5811 ip6_address_t v6_dst_address, v6_next_hop_address;
5812 int count = 1;
5813 int j;
5814 f64 before = 0;
5815 u32 random_add_del = 0;
5816 u32 *random_vector = 0;
5817 uword *random_hash;
5818 u32 random_seed = 0xdeaddabe;
5819 u32 classify_table_index = ~0;
5820 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01005821 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00005822 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005823 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00005824 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005825
Dave Barach72d72232016-08-04 10:15:08 -04005826 /* Parse args required to build the message */
5827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5828 {
5829 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00005830 ;
Dave Barach72d72232016-08-04 10:15:08 -04005831 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00005832 ;
Dave Barach72d72232016-08-04 10:15:08 -04005833 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
5834 {
5835 address_set = 1;
5836 is_ipv6 = 0;
5837 }
5838 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
5839 {
5840 address_set = 1;
5841 is_ipv6 = 1;
5842 }
5843 else if (unformat (i, "/%d", &dst_address_length))
5844 {
5845 address_length_set = 1;
5846 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005847
Dave Barach72d72232016-08-04 10:15:08 -04005848 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
5849 &v4_next_hop_address))
5850 {
5851 next_hop_set = 1;
5852 }
5853 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
5854 &v6_next_hop_address))
5855 {
5856 next_hop_set = 1;
5857 }
5858 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5859 ;
5860 else if (unformat (i, "weight %d", &next_hop_weight))
5861 ;
5862 else if (unformat (i, "drop"))
5863 {
5864 is_drop = 1;
5865 }
Neale Ranns948e00f2016-10-20 13:39:34 +01005866 else if (unformat (i, "null-send-unreach"))
5867 {
5868 is_unreach = 1;
5869 }
5870 else if (unformat (i, "null-send-prohibit"))
5871 {
5872 is_prohibit = 1;
5873 }
Dave Barach72d72232016-08-04 10:15:08 -04005874 else if (unformat (i, "local"))
5875 {
5876 is_local = 1;
5877 }
5878 else if (unformat (i, "classify %d", &classify_table_index))
5879 {
5880 is_classify = 1;
5881 }
5882 else if (unformat (i, "del"))
5883 is_add = 0;
5884 else if (unformat (i, "add"))
5885 is_add = 1;
5886 else if (unformat (i, "not-last"))
5887 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005888 else if (unformat (i, "resolve-via-host"))
5889 resolve_host = 1;
5890 else if (unformat (i, "resolve-via-attached"))
5891 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04005892 else if (unformat (i, "multipath"))
5893 is_multipath = 1;
5894 else if (unformat (i, "vrf %d", &vrf_id))
5895 ;
5896 else if (unformat (i, "create-vrf"))
5897 create_vrf_if_needed = 1;
5898 else if (unformat (i, "count %d", &count))
5899 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005900 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
5901 ;
5902 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
5903 ;
5904 else if (unformat (i, "out-label %d", &next_hop_out_label))
Neale Rannsad422ed2016-11-02 14:20:04 +00005905 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
5906 else if (unformat (i, "via-label %d", &next_hop_via_label))
Dave Barach72d72232016-08-04 10:15:08 -04005907 ;
5908 else if (unformat (i, "random"))
5909 random_add_del = 1;
5910 else if (unformat (i, "seed %d", &random_seed))
5911 ;
5912 else
5913 {
5914 clib_warning ("parse error '%U'", format_unformat_error, i);
5915 return -99;
5916 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07005917 }
5918
Neale Ranns948e00f2016-10-20 13:39:34 +01005919 if (!next_hop_set && !is_drop && !is_local &&
Neale Rannsad422ed2016-11-02 14:20:04 +00005920 !is_classify && !is_unreach && !is_prohibit &&
5921 MPLS_LABEL_INVALID == next_hop_via_label)
Dave Barach72d72232016-08-04 10:15:08 -04005922 {
Neale Ranns948e00f2016-10-20 13:39:34 +01005923 errmsg
5924 ("next hop / local / drop / unreach / prohibit / classify not set\n");
Dave Barach72d72232016-08-04 10:15:08 -04005925 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005926 }
5927
Neale Rannsad422ed2016-11-02 14:20:04 +00005928 if (next_hop_set && MPLS_LABEL_INVALID != next_hop_via_label)
5929 {
5930 errmsg ("next hop and next-hop via label set\n");
5931 return -99;
5932 }
Dave Barach72d72232016-08-04 10:15:08 -04005933 if (address_set == 0)
5934 {
5935 errmsg ("missing addresses\n");
5936 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005937 }
5938
Dave Barach72d72232016-08-04 10:15:08 -04005939 if (address_length_set == 0)
5940 {
5941 errmsg ("missing address length\n");
5942 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005943 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005944
Dave Barach72d72232016-08-04 10:15:08 -04005945 /* Generate a pile of unique, random routes */
5946 if (random_add_del)
5947 {
5948 u32 this_random_address;
5949 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07005950
Dave Barach72d72232016-08-04 10:15:08 -04005951 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
5952 for (j = 0; j <= count; j++)
5953 {
5954 do
5955 {
5956 this_random_address = random_u32 (&random_seed);
5957 this_random_address =
5958 clib_host_to_net_u32 (this_random_address);
5959 }
5960 while (hash_get (random_hash, this_random_address));
5961 vec_add1 (random_vector, this_random_address);
5962 hash_set (random_hash, this_random_address, 1);
5963 }
5964 hash_free (random_hash);
5965 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07005966 }
5967
Dave Barach72d72232016-08-04 10:15:08 -04005968 if (count > 1)
5969 {
5970 /* Turn on async mode */
5971 vam->async_mode = 1;
5972 vam->async_errors = 0;
5973 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005974 }
5975
Dave Barach72d72232016-08-04 10:15:08 -04005976 for (j = 0; j < count; j++)
5977 {
5978 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00005979 M2 (IP_ADD_DEL_ROUTE, ip_add_del_route,
5980 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005981
Dave Barach72d72232016-08-04 10:15:08 -04005982 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07005983 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04005984 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005985
Dave Barach72d72232016-08-04 10:15:08 -04005986 mp->is_add = is_add;
5987 mp->is_drop = is_drop;
Neale Ranns948e00f2016-10-20 13:39:34 +01005988 mp->is_unreach = is_unreach;
5989 mp->is_prohibit = is_prohibit;
Dave Barach72d72232016-08-04 10:15:08 -04005990 mp->is_ipv6 = is_ipv6;
5991 mp->is_local = is_local;
5992 mp->is_classify = is_classify;
5993 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01005994 mp->is_resolve_host = resolve_host;
5995 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04005996 mp->not_last = not_last;
5997 mp->next_hop_weight = next_hop_weight;
5998 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07005999 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04006000 mp->classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006001 mp->next_hop_via_label = ntohl (next_hop_via_label);
6002 mp->next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6003 if (0 != mp->next_hop_n_out_labels)
6004 {
6005 memcpy (mp->next_hop_out_label_stack,
6006 next_hop_out_label_stack,
6007 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6008 vec_free (next_hop_out_label_stack);
6009 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006010
Dave Barach72d72232016-08-04 10:15:08 -04006011 if (is_ipv6)
6012 {
6013 clib_memcpy (mp->dst_address, &v6_dst_address,
6014 sizeof (v6_dst_address));
6015 if (next_hop_set)
6016 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
6017 sizeof (v6_next_hop_address));
6018 increment_v6_address (&v6_dst_address);
6019 }
6020 else
6021 {
6022 clib_memcpy (mp->dst_address, &v4_dst_address,
6023 sizeof (v4_dst_address));
6024 if (next_hop_set)
6025 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
6026 sizeof (v4_next_hop_address));
6027 if (random_add_del)
6028 v4_dst_address.as_u32 = random_vector[j + 1];
6029 else
6030 increment_v4_address (&v4_dst_address);
6031 }
6032 /* send it... */
6033 S;
Dave Barach477570e2016-10-09 17:43:22 -04006034 /* If we receive SIGTERM, stop now... */
6035 if (vam->do_exit)
6036 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006037 }
6038
Dave Barach72d72232016-08-04 10:15:08 -04006039 /* When testing multiple add/del ops, use a control-ping to sync */
6040 if (count > 1)
6041 {
6042 vl_api_control_ping_t *mp;
6043 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006044
Dave Barach72d72232016-08-04 10:15:08 -04006045 /* Shut off async mode */
6046 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006047
Dave Barach72d72232016-08-04 10:15:08 -04006048 M (CONTROL_PING, control_ping);
6049 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006050
Dave Barach72d72232016-08-04 10:15:08 -04006051 timeout = vat_time_now (vam) + 1.0;
6052 while (vat_time_now (vam) < timeout)
6053 if (vam->result_ready == 1)
6054 goto out;
6055 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006056
6057 out:
Dave Barach72d72232016-08-04 10:15:08 -04006058 if (vam->retval == -99)
6059 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006060
Dave Barach72d72232016-08-04 10:15:08 -04006061 if (vam->async_errors > 0)
6062 {
6063 errmsg ("%d asynchronous errors\n", vam->async_errors);
6064 vam->retval = -98;
6065 }
6066 vam->async_errors = 0;
6067 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006068
Dave Barach477570e2016-10-09 17:43:22 -04006069 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6070 if (j > 0)
6071 count = j;
6072
Dave Barach72d72232016-08-04 10:15:08 -04006073 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6074 count, after - before, count / (after - before));
6075 }
6076 else
6077 {
6078 /* Wait for a reply... */
6079 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006080 }
6081
Dave Barach72d72232016-08-04 10:15:08 -04006082 /* Return the good/bad news */
6083 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006084}
6085
Dave Barach72d72232016-08-04 10:15:08 -04006086static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006087api_mpls_route_add_del (vat_main_t * vam)
6088{
6089 unformat_input_t *i = vam->input;
6090 vl_api_mpls_route_add_del_t *mp;
6091 f64 timeout;
6092 u32 sw_if_index = ~0, table_id = 0;
6093 u8 create_table_if_needed = 0;
6094 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006095 u32 next_hop_weight = 1;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006096 u8 is_multipath = 0;
6097 u32 next_hop_table_id = 0;
6098 u8 next_hop_set = 0;
6099 ip4_address_t v4_next_hop_address = {
6100 .as_u32 = 0,
6101 };
6102 ip6_address_t v6_next_hop_address = { {0} };
6103 int count = 1;
6104 int j;
6105 f64 before = 0;
6106 u32 classify_table_index = ~0;
6107 u8 is_classify = 0;
6108 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006109 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006110 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006111 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006112 mpls_label_t local_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006113 u8 is_eos = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006114 u8 next_hop_proto_is_ip4 = 1;
6115
6116 /* Parse args required to build the message */
6117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6118 {
6119 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6120 ;
6121 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6122 ;
6123 else if (unformat (i, "%d", &local_label))
6124 ;
6125 else if (unformat (i, "eos"))
6126 is_eos = 1;
6127 else if (unformat (i, "non-eos"))
6128 is_eos = 0;
6129 else if (unformat (i, "via %U", unformat_ip4_address,
6130 &v4_next_hop_address))
6131 {
6132 next_hop_set = 1;
6133 next_hop_proto_is_ip4 = 1;
6134 }
6135 else if (unformat (i, "via %U", unformat_ip6_address,
6136 &v6_next_hop_address))
6137 {
6138 next_hop_set = 1;
6139 next_hop_proto_is_ip4 = 0;
6140 }
6141 else if (unformat (i, "weight %d", &next_hop_weight))
6142 ;
6143 else if (unformat (i, "create-table"))
6144 create_table_if_needed = 1;
6145 else if (unformat (i, "classify %d", &classify_table_index))
6146 {
6147 is_classify = 1;
6148 }
6149 else if (unformat (i, "del"))
6150 is_add = 0;
6151 else if (unformat (i, "add"))
6152 is_add = 1;
6153 else if (unformat (i, "resolve-via-host"))
6154 resolve_host = 1;
6155 else if (unformat (i, "resolve-via-attached"))
6156 resolve_attached = 1;
6157 else if (unformat (i, "multipath"))
6158 is_multipath = 1;
6159 else if (unformat (i, "count %d", &count))
6160 ;
6161 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6162 {
6163 next_hop_set = 1;
6164 next_hop_proto_is_ip4 = 1;
6165 }
6166 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6167 {
6168 next_hop_set = 1;
6169 next_hop_proto_is_ip4 = 0;
6170 }
6171 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6172 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006173 else if (unformat (i, "via-label %d", &next_hop_via_label))
Neale Ranns1357f3b2016-10-16 12:01:42 -07006174 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006175 else if (unformat (i, "out-label %d", &next_hop_out_label))
6176 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006177 else
6178 {
6179 clib_warning ("parse error '%U'", format_unformat_error, i);
6180 return -99;
6181 }
6182 }
6183
6184 if (!next_hop_set && !is_classify)
6185 {
6186 errmsg ("next hop / classify not set\n");
6187 return -99;
6188 }
6189
6190 if (MPLS_LABEL_INVALID == local_label)
6191 {
6192 errmsg ("missing label\n");
6193 return -99;
6194 }
6195
6196 if (count > 1)
6197 {
6198 /* Turn on async mode */
6199 vam->async_mode = 1;
6200 vam->async_errors = 0;
6201 before = vat_time_now (vam);
6202 }
6203
6204 for (j = 0; j < count; j++)
6205 {
6206 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006207 M2 (MPLS_ROUTE_ADD_DEL, mpls_route_add_del,
6208 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006209
6210 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6211 mp->mr_table_id = ntohl (table_id);
6212 mp->mr_create_table_if_needed = create_table_if_needed;
6213
6214 mp->mr_is_add = is_add;
6215 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6216 mp->mr_is_classify = is_classify;
6217 mp->mr_is_multipath = is_multipath;
6218 mp->mr_is_resolve_host = resolve_host;
6219 mp->mr_is_resolve_attached = resolve_attached;
6220 mp->mr_next_hop_weight = next_hop_weight;
6221 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6222 mp->mr_classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006223 mp->mr_next_hop_via_label = ntohl (next_hop_via_label);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006224 mp->mr_label = ntohl (local_label);
6225 mp->mr_eos = is_eos;
6226
Neale Rannsad422ed2016-11-02 14:20:04 +00006227 mp->mr_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6228 if (0 != mp->mr_next_hop_n_out_labels)
6229 {
6230 memcpy (mp->mr_next_hop_out_label_stack,
6231 next_hop_out_label_stack,
6232 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6233 vec_free (next_hop_out_label_stack);
6234 }
6235
Neale Ranns1357f3b2016-10-16 12:01:42 -07006236 if (next_hop_set)
6237 {
6238 if (next_hop_proto_is_ip4)
6239 {
6240 clib_memcpy (mp->mr_next_hop,
6241 &v4_next_hop_address,
6242 sizeof (v4_next_hop_address));
6243 }
6244 else
6245 {
6246 clib_memcpy (mp->mr_next_hop,
6247 &v6_next_hop_address,
6248 sizeof (v6_next_hop_address));
6249 }
6250 }
6251 local_label++;
6252
6253 /* send it... */
6254 S;
6255 /* If we receive SIGTERM, stop now... */
6256 if (vam->do_exit)
6257 break;
6258 }
6259
6260 /* When testing multiple add/del ops, use a control-ping to sync */
6261 if (count > 1)
6262 {
6263 vl_api_control_ping_t *mp;
6264 f64 after;
6265
6266 /* Shut off async mode */
6267 vam->async_mode = 0;
6268
6269 M (CONTROL_PING, control_ping);
6270 S;
6271
6272 timeout = vat_time_now (vam) + 1.0;
6273 while (vat_time_now (vam) < timeout)
6274 if (vam->result_ready == 1)
6275 goto out;
6276 vam->retval = -99;
6277
6278 out:
6279 if (vam->retval == -99)
6280 errmsg ("timeout\n");
6281
6282 if (vam->async_errors > 0)
6283 {
6284 errmsg ("%d asynchronous errors\n", vam->async_errors);
6285 vam->retval = -98;
6286 }
6287 vam->async_errors = 0;
6288 after = vat_time_now (vam);
6289
6290 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6291 if (j > 0)
6292 count = j;
6293
6294 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6295 count, after - before, count / (after - before));
6296 }
6297 else
6298 {
6299 /* Wait for a reply... */
6300 W;
6301 }
6302
6303 /* Return the good/bad news */
6304 return (vam->retval);
6305}
6306
6307static int
6308api_mpls_ip_bind_unbind (vat_main_t * vam)
6309{
6310 unformat_input_t *i = vam->input;
6311 vl_api_mpls_ip_bind_unbind_t *mp;
6312 f64 timeout;
6313 u32 ip_table_id = 0;
6314 u8 create_table_if_needed = 0;
6315 u8 is_bind = 1;
6316 u8 is_ip4 = 1;
6317 ip4_address_t v4_address;
6318 ip6_address_t v6_address;
6319 u32 address_length;
6320 u8 address_set = 0;
6321 mpls_label_t local_label = MPLS_LABEL_INVALID;
6322
6323 /* Parse args required to build the message */
6324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6325 {
6326 if (unformat (i, "%U/%d", unformat_ip4_address,
6327 &v4_address, &address_length))
6328 {
6329 is_ip4 = 1;
6330 address_set = 1;
6331 }
6332 else if (unformat (i, "%U/%d", unformat_ip6_address,
6333 &v6_address, &address_length))
6334 {
6335 is_ip4 = 0;
6336 address_set = 1;
6337 }
6338 else if (unformat (i, "%d", &local_label))
6339 ;
6340 else if (unformat (i, "create-table"))
6341 create_table_if_needed = 1;
6342 else if (unformat (i, "table-id %d", &ip_table_id))
6343 ;
6344 else if (unformat (i, "unbind"))
6345 is_bind = 0;
6346 else if (unformat (i, "bind"))
6347 is_bind = 1;
6348 else
6349 {
6350 clib_warning ("parse error '%U'", format_unformat_error, i);
6351 return -99;
6352 }
6353 }
6354
6355 if (!address_set)
6356 {
6357 errmsg ("IP addres not set\n");
6358 return -99;
6359 }
6360
6361 if (MPLS_LABEL_INVALID == local_label)
6362 {
6363 errmsg ("missing label\n");
6364 return -99;
6365 }
6366
6367 /* Construct the API message */
6368 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6369
6370 mp->mb_create_table_if_needed = create_table_if_needed;
6371 mp->mb_is_bind = is_bind;
6372 mp->mb_is_ip4 = is_ip4;
6373 mp->mb_ip_table_id = ntohl (ip_table_id);
6374 mp->mb_mpls_table_id = 0;
6375 mp->mb_label = ntohl (local_label);
6376 mp->mb_address_length = address_length;
6377
6378 if (is_ip4)
6379 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6380 else
6381 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6382
6383 /* send it... */
6384 S;
6385
6386 /* Wait for a reply... */
6387 W;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006388}
6389
6390static int
Dave Barach72d72232016-08-04 10:15:08 -04006391api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006392{
Dave Barach72d72232016-08-04 10:15:08 -04006393 unformat_input_t *i = vam->input;
6394 vl_api_proxy_arp_add_del_t *mp;
6395 f64 timeout;
6396 u32 vrf_id = 0;
6397 u8 is_add = 1;
6398 ip4_address_t lo, hi;
6399 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006400
Dave Barach72d72232016-08-04 10:15:08 -04006401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6402 {
6403 if (unformat (i, "vrf %d", &vrf_id))
6404 ;
6405 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6406 unformat_ip4_address, &hi))
6407 range_set = 1;
6408 else if (unformat (i, "del"))
6409 is_add = 0;
6410 else
6411 {
6412 clib_warning ("parse error '%U'", format_unformat_error, i);
6413 return -99;
6414 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006415 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006416
Dave Barach72d72232016-08-04 10:15:08 -04006417 if (range_set == 0)
6418 {
6419 errmsg ("address range not set\n");
6420 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006421 }
6422
Dave Barach72d72232016-08-04 10:15:08 -04006423 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006424
Dave Barach72d72232016-08-04 10:15:08 -04006425 mp->vrf_id = ntohl (vrf_id);
6426 mp->is_add = is_add;
6427 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6428 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006429
Dave Barach72d72232016-08-04 10:15:08 -04006430 S;
6431 W;
6432 /* NOTREACHED */
6433 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006434}
6435
Dave Barach72d72232016-08-04 10:15:08 -04006436static int
6437api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006438{
Dave Barach72d72232016-08-04 10:15:08 -04006439 unformat_input_t *i = vam->input;
6440 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6441 f64 timeout;
6442 u32 sw_if_index;
6443 u8 enable = 1;
6444 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006445
Dave Barach72d72232016-08-04 10:15:08 -04006446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6447 {
6448 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6449 sw_if_index_set = 1;
6450 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6451 sw_if_index_set = 1;
6452 else if (unformat (i, "enable"))
6453 enable = 1;
6454 else if (unformat (i, "disable"))
6455 enable = 0;
6456 else
6457 {
6458 clib_warning ("parse error '%U'", format_unformat_error, i);
6459 return -99;
6460 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006461 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006462
Dave Barach72d72232016-08-04 10:15:08 -04006463 if (sw_if_index_set == 0)
6464 {
6465 errmsg ("missing interface name or sw_if_index\n");
6466 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006467 }
6468
Dave Barach72d72232016-08-04 10:15:08 -04006469 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006470
Dave Barach72d72232016-08-04 10:15:08 -04006471 mp->sw_if_index = ntohl (sw_if_index);
6472 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006473
Dave Barach72d72232016-08-04 10:15:08 -04006474 S;
6475 W;
6476 /* NOTREACHED */
6477 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006478}
6479
Dave Barach72d72232016-08-04 10:15:08 -04006480static int
Neale Rannsad422ed2016-11-02 14:20:04 +00006481api_mpls_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006482{
Dave Barach72d72232016-08-04 10:15:08 -04006483 unformat_input_t *i = vam->input;
Neale Rannsad422ed2016-11-02 14:20:04 +00006484 vl_api_mpls_tunnel_add_del_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04006485 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006486
Dave Barach72d72232016-08-04 10:15:08 -04006487 u8 is_add = 1;
6488 u8 l2_only = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006489 u32 sw_if_index = ~0;
6490 u32 next_hop_sw_if_index = ~0;
6491 u32 next_hop_proto_is_ip4 = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006492
Neale Rannsad422ed2016-11-02 14:20:04 +00006493 u32 next_hop_table_id = 0;
6494 ip4_address_t v4_next_hop_address = {
6495 .as_u32 = 0,
6496 };
6497 ip6_address_t v6_next_hop_address = { {0} };
6498 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID, *labels = NULL;
Dave Barach75665d32016-11-17 11:36:59 -05006499
Dave Barach72d72232016-08-04 10:15:08 -04006500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6501 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006502 if (unformat (i, "add"))
6503 is_add = 1;
6504 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6505 is_add = 0;
6506 else if (unformat (i, "sw_if_index %d", &next_hop_sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -04006507 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006508 else if (unformat (i, "via %U",
6509 unformat_ip4_address, &v4_next_hop_address))
6510 {
6511 next_hop_proto_is_ip4 = 1;
6512 }
6513 else if (unformat (i, "via %U",
6514 unformat_ip6_address, &v6_next_hop_address))
6515 {
6516 next_hop_proto_is_ip4 = 0;
6517 }
Dave Barach72d72232016-08-04 10:15:08 -04006518 else if (unformat (i, "l2-only"))
6519 l2_only = 1;
Neale Rannsad422ed2016-11-02 14:20:04 +00006520 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6521 ;
6522 else if (unformat (i, "out-label %d", &next_hop_out_label))
6523 vec_add1 (labels, ntohl (next_hop_out_label));
Dave Barach72d72232016-08-04 10:15:08 -04006524 else
6525 {
6526 clib_warning ("parse error '%U'", format_unformat_error, i);
6527 return -99;
6528 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006529 }
6530
Neale Rannsad422ed2016-11-02 14:20:04 +00006531 M2 (MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del,
6532 sizeof (mpls_label_t) * vec_len (labels));
6533
6534 mp->mt_next_hop_sw_if_index = ntohl (next_hop_sw_if_index);
6535 mp->mt_sw_if_index = ntohl (sw_if_index);
6536 mp->mt_is_add = is_add;
6537 mp->mt_l2_only = l2_only;
6538 mp->mt_next_hop_table_id = ntohl (next_hop_table_id);
6539 mp->mt_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6540
6541 mp->mt_next_hop_n_out_labels = vec_len (labels);
6542
6543 if (0 != mp->mt_next_hop_n_out_labels)
Dave Barach72d72232016-08-04 10:15:08 -04006544 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006545 clib_memcpy (mp->mt_next_hop_out_label_stack, labels,
6546 sizeof (mpls_label_t) * mp->mt_next_hop_n_out_labels);
6547 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006548 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006549
Neale Rannsad422ed2016-11-02 14:20:04 +00006550 if (next_hop_proto_is_ip4)
Dave Barach72d72232016-08-04 10:15:08 -04006551 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006552 clib_memcpy (mp->mt_next_hop,
6553 &v4_next_hop_address, sizeof (v4_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006554 }
Neale Rannsad422ed2016-11-02 14:20:04 +00006555 else
Dave Barach72d72232016-08-04 10:15:08 -04006556 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006557 clib_memcpy (mp->mt_next_hop,
6558 &v6_next_hop_address, sizeof (v6_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006559 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006560
Dave Barach72d72232016-08-04 10:15:08 -04006561 S;
6562 W;
6563 /* NOTREACHED */
6564 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006565}
6566
Dave Barach72d72232016-08-04 10:15:08 -04006567static int
6568api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006569{
Dave Barach72d72232016-08-04 10:15:08 -04006570 unformat_input_t *i = vam->input;
6571 vl_api_sw_interface_set_unnumbered_t *mp;
6572 f64 timeout;
6573 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006574 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006575 u8 is_add = 1;
6576 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006577
Dave Barach72d72232016-08-04 10:15:08 -04006578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6579 {
6580 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6581 sw_if_index_set = 1;
6582 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6583 sw_if_index_set = 1;
6584 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6585 ;
6586 else if (unformat (i, "del"))
6587 is_add = 0;
6588 else
6589 {
6590 clib_warning ("parse error '%U'", format_unformat_error, i);
6591 return -99;
6592 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006593 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006594
Dave Barach72d72232016-08-04 10:15:08 -04006595 if (sw_if_index_set == 0)
6596 {
6597 errmsg ("missing interface name or sw_if_index\n");
6598 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006599 }
6600
Dave Barach72d72232016-08-04 10:15:08 -04006601 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006602
Dave Barach72d72232016-08-04 10:15:08 -04006603 mp->sw_if_index = ntohl (sw_if_index);
6604 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6605 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006606
Dave Barach72d72232016-08-04 10:15:08 -04006607 S;
6608 W;
6609 /* NOTREACHED */
6610 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006611}
6612
Dave Barach72d72232016-08-04 10:15:08 -04006613static int
6614api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006615{
Dave Barach72d72232016-08-04 10:15:08 -04006616 unformat_input_t *i = vam->input;
6617 vl_api_ip_neighbor_add_del_t *mp;
6618 f64 timeout;
6619 u32 sw_if_index;
6620 u8 sw_if_index_set = 0;
6621 u32 vrf_id = 0;
6622 u8 is_add = 1;
6623 u8 is_static = 0;
6624 u8 mac_address[6];
6625 u8 mac_set = 0;
6626 u8 v4_address_set = 0;
6627 u8 v6_address_set = 0;
6628 ip4_address_t v4address;
6629 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006630
Dave Barach72d72232016-08-04 10:15:08 -04006631 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006632
Dave Barach72d72232016-08-04 10:15:08 -04006633 /* Parse args required to build the message */
6634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6635 {
6636 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6637 {
6638 mac_set = 1;
6639 }
6640 else if (unformat (i, "del"))
6641 is_add = 0;
6642 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6643 sw_if_index_set = 1;
6644 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6645 sw_if_index_set = 1;
6646 else if (unformat (i, "is_static"))
6647 is_static = 1;
6648 else if (unformat (i, "vrf %d", &vrf_id))
6649 ;
6650 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6651 v4_address_set = 1;
6652 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6653 v6_address_set = 1;
6654 else
6655 {
6656 clib_warning ("parse error '%U'", format_unformat_error, i);
6657 return -99;
6658 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006659 }
6660
Dave Barach72d72232016-08-04 10:15:08 -04006661 if (sw_if_index_set == 0)
6662 {
6663 errmsg ("missing interface name or sw_if_index\n");
6664 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006665 }
Dave Barach72d72232016-08-04 10:15:08 -04006666 if (v4_address_set && v6_address_set)
6667 {
6668 errmsg ("both v4 and v6 addresses set\n");
6669 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006670 }
Dave Barach72d72232016-08-04 10:15:08 -04006671 if (!v4_address_set && !v6_address_set)
6672 {
6673 errmsg ("no address set\n");
6674 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006675 }
6676
Dave Barach72d72232016-08-04 10:15:08 -04006677 /* Construct the API message */
6678 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006679
Dave Barach72d72232016-08-04 10:15:08 -04006680 mp->sw_if_index = ntohl (sw_if_index);
6681 mp->is_add = is_add;
6682 mp->vrf_id = ntohl (vrf_id);
6683 mp->is_static = is_static;
6684 if (mac_set)
6685 clib_memcpy (mp->mac_address, mac_address, 6);
6686 if (v6_address_set)
6687 {
6688 mp->is_ipv6 = 1;
6689 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6690 }
6691 else
6692 {
6693 /* mp->is_ipv6 = 0; via memset in M macro above */
6694 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006695 }
6696
Dave Barach72d72232016-08-04 10:15:08 -04006697 /* send it... */
6698 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006699
Dave Barach72d72232016-08-04 10:15:08 -04006700 /* Wait for a reply, return good/bad news */
6701 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006702
Dave Barach72d72232016-08-04 10:15:08 -04006703 /* NOTREACHED */
6704 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006705}
6706
Dave Barach72d72232016-08-04 10:15:08 -04006707static int
6708api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006709{
Dave Barach72d72232016-08-04 10:15:08 -04006710 unformat_input_t *i = vam->input;
6711 vl_api_reset_vrf_t *mp;
6712 f64 timeout;
6713 u32 vrf_id = 0;
6714 u8 is_ipv6 = 0;
6715 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006716
Dave Barach72d72232016-08-04 10:15:08 -04006717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6718 {
6719 if (unformat (i, "vrf %d", &vrf_id))
6720 vrf_id_set = 1;
6721 else if (unformat (i, "ipv6"))
6722 is_ipv6 = 1;
6723 else
6724 {
6725 clib_warning ("parse error '%U'", format_unformat_error, i);
6726 return -99;
6727 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006728 }
6729
Dave Barach72d72232016-08-04 10:15:08 -04006730 if (vrf_id_set == 0)
6731 {
6732 errmsg ("missing vrf id\n");
6733 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006734 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006735
Dave Barach72d72232016-08-04 10:15:08 -04006736 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006737
Dave Barach72d72232016-08-04 10:15:08 -04006738 mp->vrf_id = ntohl (vrf_id);
6739 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006740
Dave Barach72d72232016-08-04 10:15:08 -04006741 S;
6742 W;
6743 /* NOTREACHED */
6744 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006745}
6746
Dave Barach72d72232016-08-04 10:15:08 -04006747static int
6748api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006749{
Dave Barach72d72232016-08-04 10:15:08 -04006750 unformat_input_t *i = vam->input;
6751 vl_api_create_vlan_subif_t *mp;
6752 f64 timeout;
6753 u32 sw_if_index;
6754 u8 sw_if_index_set = 0;
6755 u32 vlan_id;
6756 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006757
Dave Barach72d72232016-08-04 10:15:08 -04006758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6759 {
6760 if (unformat (i, "sw_if_index %d", &sw_if_index))
6761 sw_if_index_set = 1;
6762 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6763 sw_if_index_set = 1;
6764 else if (unformat (i, "vlan %d", &vlan_id))
6765 vlan_id_set = 1;
6766 else
6767 {
6768 clib_warning ("parse error '%U'", format_unformat_error, i);
6769 return -99;
6770 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006771 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006772
Dave Barach72d72232016-08-04 10:15:08 -04006773 if (sw_if_index_set == 0)
6774 {
6775 errmsg ("missing interface name or sw_if_index\n");
6776 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006777 }
6778
Dave Barach72d72232016-08-04 10:15:08 -04006779 if (vlan_id_set == 0)
6780 {
6781 errmsg ("missing vlan_id\n");
6782 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006783 }
Dave Barach72d72232016-08-04 10:15:08 -04006784 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006785
Dave Barach72d72232016-08-04 10:15:08 -04006786 mp->sw_if_index = ntohl (sw_if_index);
6787 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006788
Dave Barach72d72232016-08-04 10:15:08 -04006789 S;
6790 W;
6791 /* NOTREACHED */
6792 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006793}
6794
6795#define foreach_create_subif_bit \
6796_(no_tags) \
6797_(one_tag) \
6798_(two_tags) \
6799_(dot1ad) \
6800_(exact_match) \
6801_(default_sub) \
6802_(outer_vlan_id_any) \
6803_(inner_vlan_id_any)
6804
Dave Barach72d72232016-08-04 10:15:08 -04006805static int
6806api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006807{
Dave Barach72d72232016-08-04 10:15:08 -04006808 unformat_input_t *i = vam->input;
6809 vl_api_create_subif_t *mp;
6810 f64 timeout;
6811 u32 sw_if_index;
6812 u8 sw_if_index_set = 0;
6813 u32 sub_id;
6814 u8 sub_id_set = 0;
6815 u32 no_tags = 0;
6816 u32 one_tag = 0;
6817 u32 two_tags = 0;
6818 u32 dot1ad = 0;
6819 u32 exact_match = 0;
6820 u32 default_sub = 0;
6821 u32 outer_vlan_id_any = 0;
6822 u32 inner_vlan_id_any = 0;
6823 u32 tmp;
6824 u16 outer_vlan_id = 0;
6825 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006826
Dave Barach72d72232016-08-04 10:15:08 -04006827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6828 {
6829 if (unformat (i, "sw_if_index %d", &sw_if_index))
6830 sw_if_index_set = 1;
6831 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6832 sw_if_index_set = 1;
6833 else if (unformat (i, "sub_id %d", &sub_id))
6834 sub_id_set = 1;
6835 else if (unformat (i, "outer_vlan_id %d", &tmp))
6836 outer_vlan_id = tmp;
6837 else if (unformat (i, "inner_vlan_id %d", &tmp))
6838 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006839
6840#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04006841 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07006842#undef _
Dave Barach72d72232016-08-04 10:15:08 -04006843 else
6844 {
6845 clib_warning ("parse error '%U'", format_unformat_error, i);
6846 return -99;
6847 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006848 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006849
Dave Barach72d72232016-08-04 10:15:08 -04006850 if (sw_if_index_set == 0)
6851 {
6852 errmsg ("missing interface name or sw_if_index\n");
6853 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006854 }
6855
Dave Barach72d72232016-08-04 10:15:08 -04006856 if (sub_id_set == 0)
6857 {
6858 errmsg ("missing sub_id\n");
6859 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006860 }
Dave Barach72d72232016-08-04 10:15:08 -04006861 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006862
Dave Barach72d72232016-08-04 10:15:08 -04006863 mp->sw_if_index = ntohl (sw_if_index);
6864 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006865
Ed Warnickecb9cada2015-12-08 15:45:58 -07006866#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04006867 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006868#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006869
Dave Barach72d72232016-08-04 10:15:08 -04006870 mp->outer_vlan_id = ntohs (outer_vlan_id);
6871 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006872
Dave Barach72d72232016-08-04 10:15:08 -04006873 S;
6874 W;
6875 /* NOTREACHED */
6876 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006877}
6878
Dave Barach72d72232016-08-04 10:15:08 -04006879static int
6880api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006881{
Dave Barach72d72232016-08-04 10:15:08 -04006882 unformat_input_t *i = vam->input;
6883 vl_api_oam_add_del_t *mp;
6884 f64 timeout;
6885 u32 vrf_id = 0;
6886 u8 is_add = 1;
6887 ip4_address_t src, dst;
6888 u8 src_set = 0;
6889 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006890
Dave Barach72d72232016-08-04 10:15:08 -04006891 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6892 {
6893 if (unformat (i, "vrf %d", &vrf_id))
6894 ;
6895 else if (unformat (i, "src %U", unformat_ip4_address, &src))
6896 src_set = 1;
6897 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
6898 dst_set = 1;
6899 else if (unformat (i, "del"))
6900 is_add = 0;
6901 else
6902 {
6903 clib_warning ("parse error '%U'", format_unformat_error, i);
6904 return -99;
6905 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006907
Dave Barach72d72232016-08-04 10:15:08 -04006908 if (src_set == 0)
6909 {
6910 errmsg ("missing src addr\n");
6911 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006912 }
6913
Dave Barach72d72232016-08-04 10:15:08 -04006914 if (dst_set == 0)
6915 {
6916 errmsg ("missing dst addr\n");
6917 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006918 }
6919
Dave Barach72d72232016-08-04 10:15:08 -04006920 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006921
Dave Barach72d72232016-08-04 10:15:08 -04006922 mp->vrf_id = ntohl (vrf_id);
6923 mp->is_add = is_add;
6924 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
6925 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006926
Dave Barach72d72232016-08-04 10:15:08 -04006927 S;
6928 W;
6929 /* NOTREACHED */
6930 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006931}
6932
Dave Barach72d72232016-08-04 10:15:08 -04006933static int
6934api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006935{
Dave Barach72d72232016-08-04 10:15:08 -04006936 unformat_input_t *i = vam->input;
6937 vl_api_reset_fib_t *mp;
6938 f64 timeout;
6939 u32 vrf_id = 0;
6940 u8 is_ipv6 = 0;
6941 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006942
Dave Barach72d72232016-08-04 10:15:08 -04006943 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6944 {
6945 if (unformat (i, "vrf %d", &vrf_id))
6946 vrf_id_set = 1;
6947 else if (unformat (i, "ipv6"))
6948 is_ipv6 = 1;
6949 else
6950 {
6951 clib_warning ("parse error '%U'", format_unformat_error, i);
6952 return -99;
6953 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006954 }
6955
Dave Barach72d72232016-08-04 10:15:08 -04006956 if (vrf_id_set == 0)
6957 {
6958 errmsg ("missing vrf id\n");
6959 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006960 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006961
Dave Barach72d72232016-08-04 10:15:08 -04006962 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006963
Dave Barach72d72232016-08-04 10:15:08 -04006964 mp->vrf_id = ntohl (vrf_id);
6965 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006966
Dave Barach72d72232016-08-04 10:15:08 -04006967 S;
6968 W;
6969 /* NOTREACHED */
6970 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006971}
6972
Dave Barach72d72232016-08-04 10:15:08 -04006973static int
6974api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006975{
Dave Barach72d72232016-08-04 10:15:08 -04006976 unformat_input_t *i = vam->input;
6977 vl_api_dhcp_proxy_config_t *mp;
6978 f64 timeout;
6979 u32 vrf_id = 0;
6980 u8 is_add = 1;
6981 u8 insert_cid = 1;
6982 u8 v4_address_set = 0;
6983 u8 v6_address_set = 0;
6984 ip4_address_t v4address;
6985 ip6_address_t v6address;
6986 u8 v4_src_address_set = 0;
6987 u8 v6_src_address_set = 0;
6988 ip4_address_t v4srcaddress;
6989 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006990
Dave Barach72d72232016-08-04 10:15:08 -04006991 /* Parse args required to build the message */
6992 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6993 {
6994 if (unformat (i, "del"))
6995 is_add = 0;
6996 else if (unformat (i, "vrf %d", &vrf_id))
6997 ;
6998 else if (unformat (i, "insert-cid %d", &insert_cid))
6999 ;
7000 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7001 v4_address_set = 1;
7002 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7003 v6_address_set = 1;
7004 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7005 v4_src_address_set = 1;
7006 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7007 v6_src_address_set = 1;
7008 else
7009 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007010 }
7011
Dave Barach72d72232016-08-04 10:15:08 -04007012 if (v4_address_set && v6_address_set)
7013 {
7014 errmsg ("both v4 and v6 server addresses set\n");
7015 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007016 }
Dave Barach72d72232016-08-04 10:15:08 -04007017 if (!v4_address_set && !v6_address_set)
7018 {
7019 errmsg ("no server addresses set\n");
7020 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007021 }
7022
Dave Barach72d72232016-08-04 10:15:08 -04007023 if (v4_src_address_set && v6_src_address_set)
7024 {
7025 errmsg ("both v4 and v6 src addresses set\n");
7026 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007027 }
Dave Barach72d72232016-08-04 10:15:08 -04007028 if (!v4_src_address_set && !v6_src_address_set)
7029 {
7030 errmsg ("no src addresses set\n");
7031 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007032 }
7033
Dave Barach72d72232016-08-04 10:15:08 -04007034 if (!(v4_src_address_set && v4_address_set) &&
7035 !(v6_src_address_set && v6_address_set))
7036 {
7037 errmsg ("no matching server and src addresses set\n");
7038 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007039 }
7040
Dave Barach72d72232016-08-04 10:15:08 -04007041 /* Construct the API message */
7042 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007043
Dave Barach72d72232016-08-04 10:15:08 -04007044 mp->insert_circuit_id = insert_cid;
7045 mp->is_add = is_add;
7046 mp->vrf_id = ntohl (vrf_id);
7047 if (v6_address_set)
7048 {
7049 mp->is_ipv6 = 1;
7050 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7051 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7052 }
7053 else
7054 {
7055 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7056 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007057 }
7058
Dave Barach72d72232016-08-04 10:15:08 -04007059 /* send it... */
7060 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007061
Dave Barach72d72232016-08-04 10:15:08 -04007062 /* Wait for a reply, return good/bad news */
7063 W;
7064 /* NOTREACHED */
7065 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007066}
7067
Dave Barach72d72232016-08-04 10:15:08 -04007068static int
7069api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007070{
Dave Barach72d72232016-08-04 10:15:08 -04007071 unformat_input_t *i = vam->input;
7072 vl_api_dhcp_proxy_config_2_t *mp;
7073 f64 timeout;
7074 u32 rx_vrf_id = 0;
7075 u32 server_vrf_id = 0;
7076 u8 is_add = 1;
7077 u8 insert_cid = 1;
7078 u8 v4_address_set = 0;
7079 u8 v6_address_set = 0;
7080 ip4_address_t v4address;
7081 ip6_address_t v6address;
7082 u8 v4_src_address_set = 0;
7083 u8 v6_src_address_set = 0;
7084 ip4_address_t v4srcaddress;
7085 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007086
Dave Barach72d72232016-08-04 10:15:08 -04007087 /* Parse args required to build the message */
7088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7089 {
7090 if (unformat (i, "del"))
7091 is_add = 0;
7092 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7093 ;
7094 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7095 ;
7096 else if (unformat (i, "insert-cid %d", &insert_cid))
7097 ;
7098 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7099 v4_address_set = 1;
7100 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7101 v6_address_set = 1;
7102 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7103 v4_src_address_set = 1;
7104 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7105 v6_src_address_set = 1;
7106 else
7107 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007108 }
7109
Dave Barach72d72232016-08-04 10:15:08 -04007110 if (v4_address_set && v6_address_set)
7111 {
7112 errmsg ("both v4 and v6 server addresses set\n");
7113 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007114 }
Dave Barach72d72232016-08-04 10:15:08 -04007115 if (!v4_address_set && !v6_address_set)
7116 {
7117 errmsg ("no server addresses set\n");
7118 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007119 }
7120
Dave Barach72d72232016-08-04 10:15:08 -04007121 if (v4_src_address_set && v6_src_address_set)
7122 {
7123 errmsg ("both v4 and v6 src addresses set\n");
7124 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007125 }
Dave Barach72d72232016-08-04 10:15:08 -04007126 if (!v4_src_address_set && !v6_src_address_set)
7127 {
7128 errmsg ("no src addresses set\n");
7129 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007130 }
7131
Dave Barach72d72232016-08-04 10:15:08 -04007132 if (!(v4_src_address_set && v4_address_set) &&
7133 !(v6_src_address_set && v6_address_set))
7134 {
7135 errmsg ("no matching server and src addresses set\n");
7136 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007137 }
7138
Dave Barach72d72232016-08-04 10:15:08 -04007139 /* Construct the API message */
7140 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007141
Dave Barach72d72232016-08-04 10:15:08 -04007142 mp->insert_circuit_id = insert_cid;
7143 mp->is_add = is_add;
7144 mp->rx_vrf_id = ntohl (rx_vrf_id);
7145 mp->server_vrf_id = ntohl (server_vrf_id);
7146 if (v6_address_set)
7147 {
7148 mp->is_ipv6 = 1;
7149 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7150 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7151 }
7152 else
7153 {
7154 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7155 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007156 }
7157
Dave Barach72d72232016-08-04 10:15:08 -04007158 /* send it... */
7159 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007160
Dave Barach72d72232016-08-04 10:15:08 -04007161 /* Wait for a reply, return good/bad news */
7162 W;
7163 /* NOTREACHED */
7164 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007165}
7166
Dave Barach72d72232016-08-04 10:15:08 -04007167static int
7168api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007169{
Dave Barach72d72232016-08-04 10:15:08 -04007170 unformat_input_t *i = vam->input;
7171 vl_api_dhcp_proxy_set_vss_t *mp;
7172 f64 timeout;
7173 u8 is_ipv6 = 0;
7174 u8 is_add = 1;
7175 u32 tbl_id;
7176 u8 tbl_id_set = 0;
7177 u32 oui;
7178 u8 oui_set = 0;
7179 u32 fib_id;
7180 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007181
Dave Barach72d72232016-08-04 10:15:08 -04007182 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7183 {
7184 if (unformat (i, "tbl_id %d", &tbl_id))
7185 tbl_id_set = 1;
7186 if (unformat (i, "fib_id %d", &fib_id))
7187 fib_id_set = 1;
7188 if (unformat (i, "oui %d", &oui))
7189 oui_set = 1;
7190 else if (unformat (i, "ipv6"))
7191 is_ipv6 = 1;
7192 else if (unformat (i, "del"))
7193 is_add = 0;
7194 else
7195 {
7196 clib_warning ("parse error '%U'", format_unformat_error, i);
7197 return -99;
7198 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007199 }
7200
Dave Barach72d72232016-08-04 10:15:08 -04007201 if (tbl_id_set == 0)
7202 {
7203 errmsg ("missing tbl id\n");
7204 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007205 }
7206
Dave Barach72d72232016-08-04 10:15:08 -04007207 if (fib_id_set == 0)
7208 {
7209 errmsg ("missing fib id\n");
7210 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007211 }
Dave Barach72d72232016-08-04 10:15:08 -04007212 if (oui_set == 0)
7213 {
7214 errmsg ("missing oui\n");
7215 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007216 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007217
Dave Barach72d72232016-08-04 10:15:08 -04007218 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7219 mp->tbl_id = ntohl (tbl_id);
7220 mp->fib_id = ntohl (fib_id);
7221 mp->oui = ntohl (oui);
7222 mp->is_ipv6 = is_ipv6;
7223 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007224
Dave Barach72d72232016-08-04 10:15:08 -04007225 S;
7226 W;
7227 /* NOTREACHED */
7228 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007229}
7230
Dave Barach72d72232016-08-04 10:15:08 -04007231static int
7232api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007233{
Dave Barach72d72232016-08-04 10:15:08 -04007234 unformat_input_t *i = vam->input;
7235 vl_api_dhcp_client_config_t *mp;
7236 f64 timeout;
7237 u32 sw_if_index;
7238 u8 sw_if_index_set = 0;
7239 u8 is_add = 1;
7240 u8 *hostname = 0;
7241 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007242
Dave Barach72d72232016-08-04 10:15:08 -04007243 /* Parse args required to build the message */
7244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7245 {
7246 if (unformat (i, "del"))
7247 is_add = 0;
7248 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7249 sw_if_index_set = 1;
7250 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7251 sw_if_index_set = 1;
7252 else if (unformat (i, "hostname %s", &hostname))
7253 ;
7254 else if (unformat (i, "disable_event"))
7255 disable_event = 1;
7256 else
7257 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007258 }
7259
Dave Barach72d72232016-08-04 10:15:08 -04007260 if (sw_if_index_set == 0)
7261 {
7262 errmsg ("missing interface name or sw_if_index\n");
7263 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007264 }
7265
Dave Barach72d72232016-08-04 10:15:08 -04007266 if (vec_len (hostname) > 63)
7267 {
7268 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007269 }
Dave Barach72d72232016-08-04 10:15:08 -04007270 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007271
Dave Barach72d72232016-08-04 10:15:08 -04007272 /* Construct the API message */
7273 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007274
Dave Barach72d72232016-08-04 10:15:08 -04007275 mp->sw_if_index = ntohl (sw_if_index);
7276 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7277 vec_free (hostname);
7278 mp->is_add = is_add;
7279 mp->want_dhcp_event = disable_event ? 0 : 1;
7280 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007281
Dave Barach72d72232016-08-04 10:15:08 -04007282 /* send it... */
7283 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007284
Dave Barach72d72232016-08-04 10:15:08 -04007285 /* Wait for a reply, return good/bad news */
7286 W;
7287 /* NOTREACHED */
7288 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007289}
7290
Dave Barach72d72232016-08-04 10:15:08 -04007291static int
7292api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007293{
Dave Barach72d72232016-08-04 10:15:08 -04007294 unformat_input_t *i = vam->input;
7295 vl_api_set_ip_flow_hash_t *mp;
7296 f64 timeout;
7297 u32 vrf_id = 0;
7298 u8 is_ipv6 = 0;
7299 u8 vrf_id_set = 0;
7300 u8 src = 0;
7301 u8 dst = 0;
7302 u8 sport = 0;
7303 u8 dport = 0;
7304 u8 proto = 0;
7305 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007306
Dave Barach72d72232016-08-04 10:15:08 -04007307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7308 {
7309 if (unformat (i, "vrf %d", &vrf_id))
7310 vrf_id_set = 1;
7311 else if (unformat (i, "ipv6"))
7312 is_ipv6 = 1;
7313 else if (unformat (i, "src"))
7314 src = 1;
7315 else if (unformat (i, "dst"))
7316 dst = 1;
7317 else if (unformat (i, "sport"))
7318 sport = 1;
7319 else if (unformat (i, "dport"))
7320 dport = 1;
7321 else if (unformat (i, "proto"))
7322 proto = 1;
7323 else if (unformat (i, "reverse"))
7324 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007325
Dave Barach72d72232016-08-04 10:15:08 -04007326 else
7327 {
7328 clib_warning ("parse error '%U'", format_unformat_error, i);
7329 return -99;
7330 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007331 }
7332
Dave Barach72d72232016-08-04 10:15:08 -04007333 if (vrf_id_set == 0)
7334 {
7335 errmsg ("missing vrf id\n");
7336 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007337 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007338
Dave Barach72d72232016-08-04 10:15:08 -04007339 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7340 mp->src = src;
7341 mp->dst = dst;
7342 mp->sport = sport;
7343 mp->dport = dport;
7344 mp->proto = proto;
7345 mp->reverse = reverse;
7346 mp->vrf_id = ntohl (vrf_id);
7347 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007348
Dave Barach72d72232016-08-04 10:15:08 -04007349 S;
7350 W;
7351 /* NOTREACHED */
7352 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007353}
7354
Dave Barach72d72232016-08-04 10:15:08 -04007355static int
7356api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007357{
Dave Barach72d72232016-08-04 10:15:08 -04007358 unformat_input_t *i = vam->input;
7359 vl_api_sw_interface_ip6_enable_disable_t *mp;
7360 f64 timeout;
7361 u32 sw_if_index;
7362 u8 sw_if_index_set = 0;
7363 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007364
Dave Barach72d72232016-08-04 10:15:08 -04007365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7366 {
7367 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7368 sw_if_index_set = 1;
7369 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7370 sw_if_index_set = 1;
7371 else if (unformat (i, "enable"))
7372 enable = 1;
7373 else if (unformat (i, "disable"))
7374 enable = 0;
7375 else
7376 {
7377 clib_warning ("parse error '%U'", format_unformat_error, i);
7378 return -99;
7379 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007380 }
7381
Dave Barach72d72232016-08-04 10:15:08 -04007382 if (sw_if_index_set == 0)
7383 {
7384 errmsg ("missing interface name or sw_if_index\n");
7385 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007386 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007387
Dave Barach72d72232016-08-04 10:15:08 -04007388 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007389
Dave Barach72d72232016-08-04 10:15:08 -04007390 mp->sw_if_index = ntohl (sw_if_index);
7391 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007392
Dave Barach72d72232016-08-04 10:15:08 -04007393 S;
7394 W;
7395 /* NOTREACHED */
7396 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007397}
7398
Dave Barach72d72232016-08-04 10:15:08 -04007399static int
7400api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007401{
Dave Barach72d72232016-08-04 10:15:08 -04007402 unformat_input_t *i = vam->input;
7403 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7404 f64 timeout;
7405 u32 sw_if_index;
7406 u8 sw_if_index_set = 0;
7407 u32 address_length = 0;
7408 u8 v6_address_set = 0;
7409 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007410
Dave Barach72d72232016-08-04 10:15:08 -04007411 /* Parse args required to build the message */
7412 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7413 {
7414 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7415 sw_if_index_set = 1;
7416 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7417 sw_if_index_set = 1;
7418 else if (unformat (i, "%U/%d",
7419 unformat_ip6_address, &v6address, &address_length))
7420 v6_address_set = 1;
7421 else
7422 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007423 }
7424
Dave Barach72d72232016-08-04 10:15:08 -04007425 if (sw_if_index_set == 0)
7426 {
7427 errmsg ("missing interface name or sw_if_index\n");
7428 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007429 }
Dave Barach72d72232016-08-04 10:15:08 -04007430 if (!v6_address_set)
7431 {
7432 errmsg ("no address set\n");
7433 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007434 }
7435
Dave Barach72d72232016-08-04 10:15:08 -04007436 /* Construct the API message */
7437 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7438 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007439
Dave Barach72d72232016-08-04 10:15:08 -04007440 mp->sw_if_index = ntohl (sw_if_index);
7441 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7442 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007443
Dave Barach72d72232016-08-04 10:15:08 -04007444 /* send it... */
7445 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007446
Dave Barach72d72232016-08-04 10:15:08 -04007447 /* Wait for a reply, return good/bad news */
7448 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007449
Dave Barach72d72232016-08-04 10:15:08 -04007450 /* NOTREACHED */
7451 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007452}
7453
7454
Dave Barach72d72232016-08-04 10:15:08 -04007455static int
7456api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007457{
Dave Barach72d72232016-08-04 10:15:08 -04007458 unformat_input_t *i = vam->input;
7459 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7460 f64 timeout;
7461 u32 sw_if_index;
7462 u8 sw_if_index_set = 0;
7463 u32 address_length = 0;
7464 u8 v6_address_set = 0;
7465 ip6_address_t v6address;
7466 u8 use_default = 0;
7467 u8 no_advertise = 0;
7468 u8 off_link = 0;
7469 u8 no_autoconfig = 0;
7470 u8 no_onlink = 0;
7471 u8 is_no = 0;
7472 u32 val_lifetime = 0;
7473 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007474
Dave Barach72d72232016-08-04 10:15:08 -04007475 /* Parse args required to build the message */
7476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7477 {
7478 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7479 sw_if_index_set = 1;
7480 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7481 sw_if_index_set = 1;
7482 else if (unformat (i, "%U/%d",
7483 unformat_ip6_address, &v6address, &address_length))
7484 v6_address_set = 1;
7485 else if (unformat (i, "val_life %d", &val_lifetime))
7486 ;
7487 else if (unformat (i, "pref_life %d", &pref_lifetime))
7488 ;
7489 else if (unformat (i, "def"))
7490 use_default = 1;
7491 else if (unformat (i, "noadv"))
7492 no_advertise = 1;
7493 else if (unformat (i, "offl"))
7494 off_link = 1;
7495 else if (unformat (i, "noauto"))
7496 no_autoconfig = 1;
7497 else if (unformat (i, "nolink"))
7498 no_onlink = 1;
7499 else if (unformat (i, "isno"))
7500 is_no = 1;
7501 else
7502 {
7503 clib_warning ("parse error '%U'", format_unformat_error, i);
7504 return -99;
7505 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007506 }
7507
Dave Barach72d72232016-08-04 10:15:08 -04007508 if (sw_if_index_set == 0)
7509 {
7510 errmsg ("missing interface name or sw_if_index\n");
7511 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007512 }
Dave Barach72d72232016-08-04 10:15:08 -04007513 if (!v6_address_set)
7514 {
7515 errmsg ("no address set\n");
7516 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007517 }
7518
Dave Barach72d72232016-08-04 10:15:08 -04007519 /* Construct the API message */
7520 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007521
Dave Barach72d72232016-08-04 10:15:08 -04007522 mp->sw_if_index = ntohl (sw_if_index);
7523 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7524 mp->address_length = address_length;
7525 mp->use_default = use_default;
7526 mp->no_advertise = no_advertise;
7527 mp->off_link = off_link;
7528 mp->no_autoconfig = no_autoconfig;
7529 mp->no_onlink = no_onlink;
7530 mp->is_no = is_no;
7531 mp->val_lifetime = ntohl (val_lifetime);
7532 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007533
Dave Barach72d72232016-08-04 10:15:08 -04007534 /* send it... */
7535 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007536
Dave Barach72d72232016-08-04 10:15:08 -04007537 /* Wait for a reply, return good/bad news */
7538 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007539
Dave Barach72d72232016-08-04 10:15:08 -04007540 /* NOTREACHED */
7541 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007542}
7543
Dave Barach72d72232016-08-04 10:15:08 -04007544static int
7545api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007546{
Dave Barach72d72232016-08-04 10:15:08 -04007547 unformat_input_t *i = vam->input;
7548 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7549 f64 timeout;
7550 u32 sw_if_index;
7551 u8 sw_if_index_set = 0;
7552 u8 suppress = 0;
7553 u8 managed = 0;
7554 u8 other = 0;
7555 u8 ll_option = 0;
7556 u8 send_unicast = 0;
7557 u8 cease = 0;
7558 u8 is_no = 0;
7559 u8 default_router = 0;
7560 u32 max_interval = 0;
7561 u32 min_interval = 0;
7562 u32 lifetime = 0;
7563 u32 initial_count = 0;
7564 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007566
Dave Barach72d72232016-08-04 10:15:08 -04007567 /* Parse args required to build the message */
7568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7569 {
7570 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7571 sw_if_index_set = 1;
7572 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7573 sw_if_index_set = 1;
7574 else if (unformat (i, "maxint %d", &max_interval))
7575 ;
7576 else if (unformat (i, "minint %d", &min_interval))
7577 ;
7578 else if (unformat (i, "life %d", &lifetime))
7579 ;
7580 else if (unformat (i, "count %d", &initial_count))
7581 ;
7582 else if (unformat (i, "interval %d", &initial_interval))
7583 ;
7584 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7585 suppress = 1;
7586 else if (unformat (i, "managed"))
7587 managed = 1;
7588 else if (unformat (i, "other"))
7589 other = 1;
7590 else if (unformat (i, "ll"))
7591 ll_option = 1;
7592 else if (unformat (i, "send"))
7593 send_unicast = 1;
7594 else if (unformat (i, "cease"))
7595 cease = 1;
7596 else if (unformat (i, "isno"))
7597 is_no = 1;
7598 else if (unformat (i, "def"))
7599 default_router = 1;
7600 else
7601 {
7602 clib_warning ("parse error '%U'", format_unformat_error, i);
7603 return -99;
7604 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007605 }
7606
Dave Barach72d72232016-08-04 10:15:08 -04007607 if (sw_if_index_set == 0)
7608 {
7609 errmsg ("missing interface name or sw_if_index\n");
7610 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007611 }
7612
Dave Barach72d72232016-08-04 10:15:08 -04007613 /* Construct the API message */
7614 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007615
Dave Barach72d72232016-08-04 10:15:08 -04007616 mp->sw_if_index = ntohl (sw_if_index);
7617 mp->max_interval = ntohl (max_interval);
7618 mp->min_interval = ntohl (min_interval);
7619 mp->lifetime = ntohl (lifetime);
7620 mp->initial_count = ntohl (initial_count);
7621 mp->initial_interval = ntohl (initial_interval);
7622 mp->suppress = suppress;
7623 mp->managed = managed;
7624 mp->other = other;
7625 mp->ll_option = ll_option;
7626 mp->send_unicast = send_unicast;
7627 mp->cease = cease;
7628 mp->is_no = is_no;
7629 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007630
Dave Barach72d72232016-08-04 10:15:08 -04007631 /* send it... */
7632 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007633
Dave Barach72d72232016-08-04 10:15:08 -04007634 /* Wait for a reply, return good/bad news */
7635 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007636
Dave Barach72d72232016-08-04 10:15:08 -04007637 /* NOTREACHED */
7638 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007639}
7640
Dave Barach72d72232016-08-04 10:15:08 -04007641static int
7642api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007643{
Dave Barach72d72232016-08-04 10:15:08 -04007644 unformat_input_t *i = vam->input;
7645 vl_api_set_arp_neighbor_limit_t *mp;
7646 f64 timeout;
7647 u32 arp_nbr_limit;
7648 u8 limit_set = 0;
7649 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007650
Dave Barach72d72232016-08-04 10:15:08 -04007651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7652 {
7653 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7654 limit_set = 1;
7655 else if (unformat (i, "ipv6"))
7656 is_ipv6 = 1;
7657 else
7658 {
7659 clib_warning ("parse error '%U'", format_unformat_error, i);
7660 return -99;
7661 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007662 }
7663
Dave Barach72d72232016-08-04 10:15:08 -04007664 if (limit_set == 0)
7665 {
7666 errmsg ("missing limit value\n");
7667 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007668 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007669
Dave Barach72d72232016-08-04 10:15:08 -04007670 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007671
Dave Barach72d72232016-08-04 10:15:08 -04007672 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7673 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007674
Dave Barach72d72232016-08-04 10:15:08 -04007675 S;
7676 W;
7677 /* NOTREACHED */
7678 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007679}
7680
Dave Barach72d72232016-08-04 10:15:08 -04007681static int
7682api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007683{
Dave Barach72d72232016-08-04 10:15:08 -04007684 unformat_input_t *i = vam->input;
7685 vl_api_l2_patch_add_del_t *mp;
7686 f64 timeout;
7687 u32 rx_sw_if_index;
7688 u8 rx_sw_if_index_set = 0;
7689 u32 tx_sw_if_index;
7690 u8 tx_sw_if_index_set = 0;
7691 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007692
Dave Barach72d72232016-08-04 10:15:08 -04007693 /* Parse args required to build the message */
7694 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7695 {
7696 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7697 rx_sw_if_index_set = 1;
7698 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7699 tx_sw_if_index_set = 1;
7700 else if (unformat (i, "rx"))
7701 {
7702 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7703 {
7704 if (unformat (i, "%U", unformat_sw_if_index, vam,
7705 &rx_sw_if_index))
7706 rx_sw_if_index_set = 1;
7707 }
7708 else
7709 break;
7710 }
7711 else if (unformat (i, "tx"))
7712 {
7713 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7714 {
7715 if (unformat (i, "%U", unformat_sw_if_index, vam,
7716 &tx_sw_if_index))
7717 tx_sw_if_index_set = 1;
7718 }
7719 else
7720 break;
7721 }
7722 else if (unformat (i, "del"))
7723 is_add = 0;
7724 else
7725 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007726 }
7727
Dave Barach72d72232016-08-04 10:15:08 -04007728 if (rx_sw_if_index_set == 0)
7729 {
7730 errmsg ("missing rx interface name or rx_sw_if_index\n");
7731 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007732 }
7733
Dave Barach72d72232016-08-04 10:15:08 -04007734 if (tx_sw_if_index_set == 0)
7735 {
7736 errmsg ("missing tx interface name or tx_sw_if_index\n");
7737 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007738 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007739
Dave Barach72d72232016-08-04 10:15:08 -04007740 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007741
Dave Barach72d72232016-08-04 10:15:08 -04007742 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7743 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7744 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007745
Dave Barach72d72232016-08-04 10:15:08 -04007746 S;
7747 W;
7748 /* NOTREACHED */
7749 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007750}
Dave Barach72d72232016-08-04 10:15:08 -04007751
7752static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007753api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007754{
Dave Barach72d72232016-08-04 10:15:08 -04007755 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007756 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007757 f64 timeout;
7758 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007759 int has_trace_option = 0;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307760 int has_pot_option = 0;
7761 int has_seqno_option = 0;
7762 int has_analyse_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007763
Shwetha20a64f52016-03-25 10:55:01 +00007764 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7765 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007766 if (unformat (input, "trace"))
7767 has_trace_option = 1;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307768 else if (unformat (input, "pot"))
7769 has_pot_option = 1;
7770 else if (unformat (input, "seqno"))
7771 has_seqno_option = 1;
7772 else if (unformat (input, "analyse"))
7773 has_analyse_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007774 else
Dave Barach72d72232016-08-04 10:15:08 -04007775 break;
Shwetha20a64f52016-03-25 10:55:01 +00007776 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007777 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007778 mp->id = htons (id);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307779 mp->seqno = has_seqno_option;
7780 mp->analyse = has_analyse_option;
7781 mp->pot_enable = has_pot_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007782 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007783
Dave Barach72d72232016-08-04 10:15:08 -04007784 S;
7785 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007786
Dave Barach72d72232016-08-04 10:15:08 -04007787 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007788
Shwetha20a64f52016-03-25 10:55:01 +00007789}
Dave Barach72d72232016-08-04 10:15:08 -04007790
Shwetha20a64f52016-03-25 10:55:01 +00007791
Dave Barach72d72232016-08-04 10:15:08 -04007792static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007793api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007794{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007795 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007796 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007797
Vengada Govindan07d2f842016-08-25 10:34:34 -07007798 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04007799 S;
7800 W;
7801 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00007802}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007803
Dave Barach72d72232016-08-04 10:15:08 -04007804static int
7805api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806{
Dave Barach72d72232016-08-04 10:15:08 -04007807 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007808 vl_api_sr_tunnel_add_del_t *mp;
7809 f64 timeout;
7810 int is_del = 0;
7811 int pl_index;
7812 ip6_address_t src_address;
7813 int src_address_set = 0;
7814 ip6_address_t dst_address;
7815 u32 dst_mask_width;
7816 int dst_address_set = 0;
7817 u16 flags = 0;
7818 u32 rx_table_id = 0;
7819 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007820 ip6_address_t *segments = 0;
7821 ip6_address_t *this_seg;
7822 ip6_address_t *tags = 0;
7823 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007824 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04007825 u8 *name = 0;
7826 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007827
7828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7829 {
7830 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007831 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007832 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04007833 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007834 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04007835 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007836 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007837 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007838 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04007839 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007840 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04007841 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007842 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04007843 unformat_ip6_address, &dst_address, &dst_mask_width))
7844 dst_address_set = 1;
7845 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
7846 {
7847 vec_add2 (segments, this_seg, 1);
7848 clib_memcpy (this_seg->as_u8, next_address.as_u8,
7849 sizeof (*this_seg));
7850 }
7851 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
7852 {
7853 vec_add2 (tags, this_tag, 1);
7854 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
7855 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007856 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04007857 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007858 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04007859 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007860 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007861 {
7862 if (pl_index <= 0 || pl_index > 4)
7863 {
7864 pl_index_range_error:
7865 errmsg ("pl index %d out of range\n", pl_index);
7866 return -99;
7867 }
7868 flags |=
7869 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
7870 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007871 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007872 {
7873 if (pl_index <= 0 || pl_index > 4)
7874 goto pl_index_range_error;
7875 flags |=
7876 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
7877 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007878 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04007879 {
7880 if (pl_index <= 0 || pl_index > 4)
7881 goto pl_index_range_error;
7882 flags |=
7883 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
7884 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007885 else
Dave Barach72d72232016-08-04 10:15:08 -04007886 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007887 }
7888
7889 if (!src_address_set)
7890 {
7891 errmsg ("src address required\n");
7892 return -99;
7893 }
7894
7895 if (!dst_address_set)
7896 {
7897 errmsg ("dst address required\n");
7898 return -99;
7899 }
7900
7901 if (!segments)
7902 {
7903 errmsg ("at least one sr segment required\n");
7904 return -99;
7905 }
7906
Dave Barach72d72232016-08-04 10:15:08 -04007907 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
7908 vec_len (segments) * sizeof (ip6_address_t)
7909 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007910
Damjan Marionf1213b82016-03-13 02:22:06 +01007911 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
7912 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007913 mp->dst_mask_width = dst_mask_width;
7914 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
7915 mp->n_segments = vec_len (segments);
7916 mp->n_tags = vec_len (tags);
7917 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007918 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04007919 vec_len (segments) * sizeof (ip6_address_t));
7920 clib_memcpy (mp->segs_and_tags +
7921 vec_len (segments) * sizeof (ip6_address_t), tags,
7922 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007923
7924 mp->outer_vrf_id = ntohl (rx_table_id);
7925 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04007926 memcpy (mp->name, name, vec_len (name));
7927 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007928
7929 vec_free (segments);
7930 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007931
Dave Barach72d72232016-08-04 10:15:08 -04007932 S;
7933 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007934 /* NOTREACHED */
7935}
7936
Dave Barach72d72232016-08-04 10:15:08 -04007937static int
7938api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007939{
Dave Barach72d72232016-08-04 10:15:08 -04007940 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007941 vl_api_sr_policy_add_del_t *mp;
7942 f64 timeout;
7943 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007944 u8 *name = 0;
7945 u8 *tunnel_name = 0;
7946 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007947
Dave Barach72d72232016-08-04 10:15:08 -04007948 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007949 int tunnel_set = 0;
7950 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04007951 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
7952 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 -07007953
7954 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7955 {
7956 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04007957 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007958 else if (unformat (input, "name %s", &name))
7959 name_set = 1;
7960 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04007961 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007962 if (tunnel_name)
7963 {
7964 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007965 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04007966 - length = #bytes to store in serial vector
7967 - +1 = byte to store that length
7968 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007969 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007970 tunnel_set = 1;
7971 tunnel_name = 0;
7972 }
Dave Barach72d72232016-08-04 10:15:08 -04007973 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007974 else
Dave Barach72d72232016-08-04 10:15:08 -04007975 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007976 }
7977
7978 if (!name_set)
7979 {
7980 errmsg ("policy name required\n");
7981 return -99;
7982 }
7983
7984 if ((!tunnel_set) && (!is_del))
7985 {
7986 errmsg ("tunnel name required\n");
7987 return -99;
7988 }
7989
Dave Barach72d72232016-08-04 10:15:08 -04007990 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007991
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007992
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007993
7994 mp->is_add = !is_del;
7995
Dave Barach72d72232016-08-04 10:15:08 -04007996 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007997 // 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 -04007998 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07007999 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008000 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8001 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008002
Dave Barach72d72232016-08-04 10:15:08 -04008003 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008004 {
8005 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008006 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8007 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008008 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008009 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008010 }
Dave Barach72d72232016-08-04 10:15:08 -04008011 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 -07008012
8013 vec_free (tunnel_names);
8014 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008015
Dave Barach72d72232016-08-04 10:15:08 -04008016 S;
8017 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008018 /* NOTREACHED */
8019}
8020
Dave Barach72d72232016-08-04 10:15:08 -04008021static int
8022api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008023{
Dave Barach72d72232016-08-04 10:15:08 -04008024 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008025 vl_api_sr_multicast_map_add_del_t *mp;
8026 f64 timeout;
8027 int is_del = 0;
8028 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008029 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008030 int multicast_address_set = 0;
8031
8032 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8033 {
8034 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008035 is_del = 1;
8036 else
8037 if (unformat
8038 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008039 multicast_address_set = 1;
8040 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008041 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008042 else
Dave Barach72d72232016-08-04 10:15:08 -04008043 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008044 }
8045
8046 if (!is_del && !policy_name)
8047 {
8048 errmsg ("sr-policy name required\n");
8049 return -99;
8050 }
8051
8052
8053 if (!multicast_address_set)
8054 {
8055 errmsg ("address required\n");
8056 return -99;
8057 }
8058
Dave Barach72d72232016-08-04 10:15:08 -04008059 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008060
8061 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008062 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8063 clib_memcpy (mp->multicast_address, &multicast_address,
8064 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008065
8066
8067 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008068
Dave Barach72d72232016-08-04 10:15:08 -04008069 S;
8070 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008071 /* NOTREACHED */
8072}
8073
Ed Warnickecb9cada2015-12-08 15:45:58 -07008074
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008075#define foreach_tcp_proto_field \
8076_(src_port) \
8077_(dst_port)
8078
8079#define foreach_udp_proto_field \
8080_(src_port) \
8081_(dst_port)
8082
Ed Warnickecb9cada2015-12-08 15:45:58 -07008083#define foreach_ip4_proto_field \
8084_(src_address) \
8085_(dst_address) \
8086_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008087_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008088_(fragment_id) \
8089_(ttl) \
8090_(protocol) \
8091_(checksum)
8092
Dave Barach72d72232016-08-04 10:15:08 -04008093uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008094unformat_tcp_mask (unformat_input_t * input, va_list * args)
8095{
8096 u8 **maskp = va_arg (*args, u8 **);
8097 u8 *mask = 0;
8098 u8 found_something = 0;
8099 tcp_header_t *tcp;
8100
8101#define _(a) u8 a=0;
8102 foreach_tcp_proto_field;
8103#undef _
8104
8105 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8106 {
8107 if (0);
8108#define _(a) else if (unformat (input, #a)) a=1;
8109 foreach_tcp_proto_field
8110#undef _
8111 else
8112 break;
8113 }
8114
8115#define _(a) found_something += a;
8116 foreach_tcp_proto_field;
8117#undef _
8118
8119 if (found_something == 0)
8120 return 0;
8121
8122 vec_validate (mask, sizeof (*tcp) - 1);
8123
8124 tcp = (tcp_header_t *) mask;
8125
8126#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8127 foreach_tcp_proto_field;
8128#undef _
8129
8130 *maskp = mask;
8131 return 1;
8132}
8133
8134uword
8135unformat_udp_mask (unformat_input_t * input, va_list * args)
8136{
8137 u8 **maskp = va_arg (*args, u8 **);
8138 u8 *mask = 0;
8139 u8 found_something = 0;
8140 udp_header_t *udp;
8141
8142#define _(a) u8 a=0;
8143 foreach_udp_proto_field;
8144#undef _
8145
8146 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8147 {
8148 if (0);
8149#define _(a) else if (unformat (input, #a)) a=1;
8150 foreach_udp_proto_field
8151#undef _
8152 else
8153 break;
8154 }
8155
8156#define _(a) found_something += a;
8157 foreach_udp_proto_field;
8158#undef _
8159
8160 if (found_something == 0)
8161 return 0;
8162
8163 vec_validate (mask, sizeof (*udp) - 1);
8164
8165 udp = (udp_header_t *) mask;
8166
8167#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8168 foreach_udp_proto_field;
8169#undef _
8170
8171 *maskp = mask;
8172 return 1;
8173}
8174
8175typedef struct
8176{
8177 u16 src_port, dst_port;
8178} tcpudp_header_t;
8179
8180uword
8181unformat_l4_mask (unformat_input_t * input, va_list * args)
8182{
8183 u8 **maskp = va_arg (*args, u8 **);
8184 u16 src_port = 0, dst_port = 0;
8185 tcpudp_header_t *tcpudp;
8186
8187 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8188 {
8189 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8190 return 1;
8191 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8192 return 1;
8193 else if (unformat (input, "src_port"))
8194 src_port = 0xFFFF;
8195 else if (unformat (input, "dst_port"))
8196 dst_port = 0xFFFF;
8197 else
8198 return 0;
8199 }
8200
8201 if (!src_port && !dst_port)
8202 return 0;
8203
8204 u8 *mask = 0;
8205 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8206
8207 tcpudp = (tcpudp_header_t *) mask;
8208 tcpudp->src_port = src_port;
8209 tcpudp->dst_port = dst_port;
8210
8211 *maskp = mask;
8212
8213 return 1;
8214}
8215
8216uword
Dave Barach72d72232016-08-04 10:15:08 -04008217unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008218{
Dave Barach72d72232016-08-04 10:15:08 -04008219 u8 **maskp = va_arg (*args, u8 **);
8220 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008221 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008222 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008223
Ed Warnickecb9cada2015-12-08 15:45:58 -07008224#define _(a) u8 a=0;
8225 foreach_ip4_proto_field;
8226#undef _
8227 u8 version = 0;
8228 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008229
8230
8231 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008232 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008233 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008234 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008235 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008236 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008237 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008238 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008239 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008240 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008241 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008242 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008243
Ed Warnickecb9cada2015-12-08 15:45:58 -07008244#define _(a) else if (unformat (input, #a)) a=1;
8245 foreach_ip4_proto_field
8246#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008247 else
8248 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008249 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008250
Ed Warnickecb9cada2015-12-08 15:45:58 -07008251#define _(a) found_something += a;
8252 foreach_ip4_proto_field;
8253#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008254
Ed Warnickecb9cada2015-12-08 15:45:58 -07008255 if (found_something == 0)
8256 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008257
Ed Warnickecb9cada2015-12-08 15:45:58 -07008258 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008259
Ed Warnickecb9cada2015-12-08 15:45:58 -07008260 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008261
Ed Warnickecb9cada2015-12-08 15:45:58 -07008262#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8263 foreach_ip4_proto_field;
8264#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008265
Ed Warnickecb9cada2015-12-08 15:45:58 -07008266 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008267
Ed Warnickecb9cada2015-12-08 15:45:58 -07008268 if (version)
8269 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008270
Ed Warnickecb9cada2015-12-08 15:45:58 -07008271 if (hdr_length)
8272 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008273
Ed Warnickecb9cada2015-12-08 15:45:58 -07008274 *maskp = mask;
8275 return 1;
8276}
8277
8278#define foreach_ip6_proto_field \
8279_(src_address) \
8280_(dst_address) \
8281_(payload_length) \
8282_(hop_limit) \
8283_(protocol)
8284
Dave Barach72d72232016-08-04 10:15:08 -04008285uword
8286unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008287{
Dave Barach72d72232016-08-04 10:15:08 -04008288 u8 **maskp = va_arg (*args, u8 **);
8289 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008290 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008291 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008292 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008293
Ed Warnickecb9cada2015-12-08 15:45:58 -07008294#define _(a) u8 a=0;
8295 foreach_ip6_proto_field;
8296#undef _
8297 u8 version = 0;
8298 u8 traffic_class = 0;
8299 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008300
8301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008302 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008303 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008304 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008305 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008306 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008307 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008308 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008309 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008310 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008311 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008312 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008313 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008314 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008315
Ed Warnickecb9cada2015-12-08 15:45:58 -07008316#define _(a) else if (unformat (input, #a)) a=1;
8317 foreach_ip6_proto_field
8318#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008319 else
8320 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008321 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008322
Ed Warnickecb9cada2015-12-08 15:45:58 -07008323#define _(a) found_something += a;
8324 foreach_ip6_proto_field;
8325#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008326
Ed Warnickecb9cada2015-12-08 15:45:58 -07008327 if (found_something == 0)
8328 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008329
Ed Warnickecb9cada2015-12-08 15:45:58 -07008330 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008331
Ed Warnickecb9cada2015-12-08 15:45:58 -07008332 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008333
Ed Warnickecb9cada2015-12-08 15:45:58 -07008334#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8335 foreach_ip6_proto_field;
8336#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008337
Ed Warnickecb9cada2015-12-08 15:45:58 -07008338 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008339
Ed Warnickecb9cada2015-12-08 15:45:58 -07008340 if (version)
8341 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8342
8343 if (traffic_class)
8344 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8345
8346 if (flow_label)
8347 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8348
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008349 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008350 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008351
Ed Warnickecb9cada2015-12-08 15:45:58 -07008352 *maskp = mask;
8353 return 1;
8354}
8355
Dave Barach72d72232016-08-04 10:15:08 -04008356uword
8357unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008358{
Dave Barach72d72232016-08-04 10:15:08 -04008359 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008360
Dave Barach72d72232016-08-04 10:15:08 -04008361 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8362 {
8363 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8364 return 1;
8365 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8366 return 1;
8367 else
8368 break;
8369 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008370 return 0;
8371}
8372
Dave Barach72d72232016-08-04 10:15:08 -04008373uword
8374unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008375{
Dave Barach72d72232016-08-04 10:15:08 -04008376 u8 **maskp = va_arg (*args, u8 **);
8377 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008378 u8 src = 0;
8379 u8 dst = 0;
8380 u8 proto = 0;
8381 u8 tag1 = 0;
8382 u8 tag2 = 0;
8383 u8 ignore_tag1 = 0;
8384 u8 ignore_tag2 = 0;
8385 u8 cos1 = 0;
8386 u8 cos2 = 0;
8387 u8 dot1q = 0;
8388 u8 dot1ad = 0;
8389 int len = 14;
8390
Dave Barach72d72232016-08-04 10:15:08 -04008391 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8392 {
8393 if (unformat (input, "src"))
8394 src = 1;
8395 else if (unformat (input, "dst"))
8396 dst = 1;
8397 else if (unformat (input, "proto"))
8398 proto = 1;
8399 else if (unformat (input, "tag1"))
8400 tag1 = 1;
8401 else if (unformat (input, "tag2"))
8402 tag2 = 1;
8403 else if (unformat (input, "ignore-tag1"))
8404 ignore_tag1 = 1;
8405 else if (unformat (input, "ignore-tag2"))
8406 ignore_tag2 = 1;
8407 else if (unformat (input, "cos1"))
8408 cos1 = 1;
8409 else if (unformat (input, "cos2"))
8410 cos2 = 1;
8411 else if (unformat (input, "dot1q"))
8412 dot1q = 1;
8413 else if (unformat (input, "dot1ad"))
8414 dot1ad = 1;
8415 else
8416 break;
8417 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008418 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008419 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008420 return 0;
8421
8422 if (tag1 || ignore_tag1 || cos1 || dot1q)
8423 len = 18;
8424 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8425 len = 22;
8426
Dave Barach72d72232016-08-04 10:15:08 -04008427 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008428
8429 if (dst)
8430 memset (mask, 0xff, 6);
8431
8432 if (src)
8433 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008434
Ed Warnickecb9cada2015-12-08 15:45:58 -07008435 if (tag2 || dot1ad)
8436 {
8437 /* inner vlan tag */
8438 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008439 {
8440 mask[19] = 0xff;
8441 mask[18] = 0x0f;
8442 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008443 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008444 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008445 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008446 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008447 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008448 {
8449 mask[15] = 0xff;
8450 mask[14] = 0x0f;
8451 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008452 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008453 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008454 *maskp = mask;
8455 return 1;
8456 }
8457 if (tag1 | dot1q)
8458 {
8459 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008460 {
8461 mask[15] = 0xff;
8462 mask[14] = 0x0f;
8463 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008464 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008465 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008466 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008467 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008468
8469 *maskp = mask;
8470 return 1;
8471 }
8472 if (cos2)
8473 mask[18] |= 0xe0;
8474 if (cos1)
8475 mask[14] |= 0xe0;
8476 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008477 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008478
Ed Warnickecb9cada2015-12-08 15:45:58 -07008479 *maskp = mask;
8480 return 1;
8481}
8482
Dave Barach72d72232016-08-04 10:15:08 -04008483uword
8484unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008485{
Dave Barach72d72232016-08-04 10:15:08 -04008486 u8 **maskp = va_arg (*args, u8 **);
8487 u32 *skipp = va_arg (*args, u32 *);
8488 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008489 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008490 u8 *mask = 0;
8491 u8 *l2 = 0;
8492 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008493 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008494 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008495
Dave Barach72d72232016-08-04 10:15:08 -04008496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8497 {
8498 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8499 ;
8500 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8501 ;
8502 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8503 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008504 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8505 ;
Dave Barach72d72232016-08-04 10:15:08 -04008506 else
8507 break;
8508 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008509
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008510 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008511 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008512 vec_free (mask);
8513 vec_free (l2);
8514 vec_free (l4);
8515 return 0;
8516 }
8517
8518 if (mask || l2 || l3 || l4)
8519 {
8520 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008521 {
8522 /* "With a free Ethernet header in every package" */
8523 if (l2 == 0)
8524 vec_validate (l2, 13);
8525 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008526 if (vec_len (l3))
8527 {
8528 vec_append (mask, l3);
8529 vec_free (l3);
8530 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008531 if (vec_len (l4))
8532 {
8533 vec_append (mask, l4);
8534 vec_free (l4);
8535 }
Dave Barach72d72232016-08-04 10:15:08 -04008536 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008537
8538 /* Scan forward looking for the first significant mask octet */
8539 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008540 if (mask[i])
8541 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008542
8543 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008544 *skipp = i / sizeof (u32x4);
8545 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008546
8547 /* Pad mask to an even multiple of the vector size */
8548 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008549 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008550
8551 match = vec_len (mask) / sizeof (u32x4);
8552
Dave Barach72d72232016-08-04 10:15:08 -04008553 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8554 {
8555 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8556 if (*tmp || *(tmp + 1))
8557 break;
8558 match--;
8559 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008560 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008561 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008562
Dave Barach72d72232016-08-04 10:15:08 -04008563 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008564
8565 *matchp = match;
8566 *maskp = mask;
8567
8568 return 1;
8569 }
8570
8571 return 0;
8572}
8573
8574#define foreach_l2_next \
8575_(drop, DROP) \
8576_(ethernet, ETHERNET_INPUT) \
8577_(ip4, IP4_INPUT) \
8578_(ip6, IP6_INPUT)
8579
Dave Barach72d72232016-08-04 10:15:08 -04008580uword
8581unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008582{
Dave Barach72d72232016-08-04 10:15:08 -04008583 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008584 u32 next_index = 0;
8585 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008586
Ed Warnickecb9cada2015-12-08 15:45:58 -07008587#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008588 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008589 foreach_l2_next;
8590#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008591
Ed Warnickecb9cada2015-12-08 15:45:58 -07008592 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008593 {
8594 next_index = tmp;
8595 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008596 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008597
Ed Warnickecb9cada2015-12-08 15:45:58 -07008598 return 0;
8599
Dave Barach72d72232016-08-04 10:15:08 -04008600out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008601 *miss_next_indexp = next_index;
8602 return 1;
8603}
8604
8605#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008606_(drop, DROP) \
8607_(local, LOCAL) \
8608_(rewrite, REWRITE)
8609
Dave Barach72d72232016-08-04 10:15:08 -04008610uword
8611unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008612{
Dave Barach72d72232016-08-04 10:15:08 -04008613 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008614 u32 next_index = 0;
8615 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008616
Ed Warnickecb9cada2015-12-08 15:45:58 -07008617#define _(n,N) \
8618 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8619 foreach_ip_next;
8620#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008621
Ed Warnickecb9cada2015-12-08 15:45:58 -07008622 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008623 {
8624 next_index = tmp;
8625 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008626 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008627
Ed Warnickecb9cada2015-12-08 15:45:58 -07008628 return 0;
8629
Dave Barach72d72232016-08-04 10:15:08 -04008630out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008631 *miss_next_indexp = next_index;
8632 return 1;
8633}
8634
8635#define foreach_acl_next \
8636_(deny, DENY)
8637
Dave Barach72d72232016-08-04 10:15:08 -04008638uword
8639unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008640{
Dave Barach72d72232016-08-04 10:15:08 -04008641 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008642 u32 next_index = 0;
8643 u32 tmp;
8644
8645#define _(n,N) \
8646 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8647 foreach_acl_next;
8648#undef _
8649
8650 if (unformat (input, "permit"))
8651 {
8652 next_index = ~0;
8653 goto out;
8654 }
8655 else if (unformat (input, "%d", &tmp))
8656 {
8657 next_index = tmp;
8658 goto out;
8659 }
8660
8661 return 0;
8662
Dave Barach72d72232016-08-04 10:15:08 -04008663out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008664 *miss_next_indexp = next_index;
8665 return 1;
8666}
8667
Dave Barach72d72232016-08-04 10:15:08 -04008668uword
8669unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008670{
Dave Barach72d72232016-08-04 10:15:08 -04008671 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008672
8673 if (unformat (input, "conform-color"))
8674 *r = POLICE_CONFORM;
8675 else if (unformat (input, "exceed-color"))
8676 *r = POLICE_EXCEED;
8677 else
8678 return 0;
8679
8680 return 1;
8681}
8682
Dave Barach72d72232016-08-04 10:15:08 -04008683static int
8684api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008685{
Dave Barach72d72232016-08-04 10:15:08 -04008686 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008687 vl_api_classify_add_del_table_t *mp;
8688
8689 u32 nbuckets = 2;
8690 u32 skip = ~0;
8691 u32 match = ~0;
8692 int is_add = 1;
8693 u32 table_index = ~0;
8694 u32 next_table_index = ~0;
8695 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008696 u32 memory_size = 32 << 20;
8697 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008698 f64 timeout;
Steve Shin25e26dc2016-11-08 10:47:10 -08008699 u32 current_data_flag = 0;
8700 int current_data_offset = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008701
Dave Barach72d72232016-08-04 10:15:08 -04008702 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8703 {
8704 if (unformat (i, "del"))
8705 is_add = 0;
8706 else if (unformat (i, "buckets %d", &nbuckets))
8707 ;
8708 else if (unformat (i, "memory_size %d", &memory_size))
8709 ;
8710 else if (unformat (i, "skip %d", &skip))
8711 ;
8712 else if (unformat (i, "match %d", &match))
8713 ;
8714 else if (unformat (i, "table %d", &table_index))
8715 ;
8716 else if (unformat (i, "mask %U", unformat_classify_mask,
8717 &mask, &skip, &match))
8718 ;
8719 else if (unformat (i, "next-table %d", &next_table_index))
8720 ;
8721 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8722 &miss_next_index))
8723 ;
8724 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8725 &miss_next_index))
8726 ;
8727 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8728 &miss_next_index))
8729 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08008730 else if (unformat (i, "current-data-flag %d", &current_data_flag))
8731 ;
8732 else if (unformat (i, "current-data-offset %d", &current_data_offset))
8733 ;
Dave Barach72d72232016-08-04 10:15:08 -04008734 else
8735 break;
8736 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008737
Dave Barach72d72232016-08-04 10:15:08 -04008738 if (is_add && mask == 0)
8739 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008740 errmsg ("Mask required\n");
8741 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008742 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008743
Dave Barach72d72232016-08-04 10:15:08 -04008744 if (is_add && skip == ~0)
8745 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008746 errmsg ("skip count required\n");
8747 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008748 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008749
Dave Barach72d72232016-08-04 10:15:08 -04008750 if (is_add && match == ~0)
8751 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008752 errmsg ("match count required\n");
8753 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008754 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008755
Dave Barach72d72232016-08-04 10:15:08 -04008756 if (!is_add && table_index == ~0)
8757 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008758 errmsg ("table index required for delete\n");
8759 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008760 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008761
Dave Barach72d72232016-08-04 10:15:08 -04008762 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008763
8764 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -04008765 mp->table_index = ntohl (table_index);
8766 mp->nbuckets = ntohl (nbuckets);
8767 mp->memory_size = ntohl (memory_size);
8768 mp->skip_n_vectors = ntohl (skip);
8769 mp->match_n_vectors = ntohl (match);
8770 mp->next_table_index = ntohl (next_table_index);
8771 mp->miss_next_index = ntohl (miss_next_index);
Steve Shin25e26dc2016-11-08 10:47:10 -08008772 mp->current_data_flag = ntohl (current_data_flag);
8773 mp->current_data_offset = ntohl (current_data_offset);
Dave Barach72d72232016-08-04 10:15:08 -04008774 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008775
Dave Barach72d72232016-08-04 10:15:08 -04008776 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008777
Dave Barach72d72232016-08-04 10:15:08 -04008778 S;
8779 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008780 /* NOTREACHED */
8781}
8782
Dave Barach72d72232016-08-04 10:15:08 -04008783uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008784unformat_l4_match (unformat_input_t * input, va_list * args)
8785{
8786 u8 **matchp = va_arg (*args, u8 **);
8787
8788 u8 *proto_header = 0;
8789 int src_port = 0;
8790 int dst_port = 0;
8791
8792 tcpudp_header_t h;
8793
8794 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8795 {
8796 if (unformat (input, "src_port %d", &src_port))
8797 ;
8798 else if (unformat (input, "dst_port %d", &dst_port))
8799 ;
8800 else
8801 return 0;
8802 }
8803
8804 h.src_port = clib_host_to_net_u16 (src_port);
8805 h.dst_port = clib_host_to_net_u16 (dst_port);
8806 vec_validate (proto_header, sizeof (h) - 1);
8807 memcpy (proto_header, &h, sizeof (h));
8808
8809 *matchp = proto_header;
8810
8811 return 1;
8812}
8813
8814uword
Dave Barach72d72232016-08-04 10:15:08 -04008815unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008816{
Dave Barach72d72232016-08-04 10:15:08 -04008817 u8 **matchp = va_arg (*args, u8 **);
8818 u8 *match = 0;
8819 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008820 int version = 0;
8821 u32 version_val;
8822 int hdr_length = 0;
8823 u32 hdr_length_val;
8824 int src = 0, dst = 0;
8825 ip4_address_t src_val, dst_val;
8826 int proto = 0;
8827 u32 proto_val;
8828 int tos = 0;
8829 u32 tos_val;
8830 int length = 0;
8831 u32 length_val;
8832 int fragment_id = 0;
8833 u32 fragment_id_val;
8834 int ttl = 0;
8835 int ttl_val;
8836 int checksum = 0;
8837 u32 checksum_val;
8838
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008839 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008840 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008841 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008842 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008843 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008844 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008845 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008846 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008847 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008848 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008849 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008850 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008851 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04008852 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008853 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008854 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008855 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04008856 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008857 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04008858 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008859 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04008860 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008861 else
Dave Barach72d72232016-08-04 10:15:08 -04008862 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008863 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008864
Ed Warnickecb9cada2015-12-08 15:45:58 -07008865 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8866 + ttl + checksum == 0)
8867 return 0;
8868
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008869 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008870 * Aligned because we use the real comparison functions
8871 */
Dave Barach72d72232016-08-04 10:15:08 -04008872 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008873
Ed Warnickecb9cada2015-12-08 15:45:58 -07008874 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008875
Ed Warnickecb9cada2015-12-08 15:45:58 -07008876 /* These are realistically matched in practice */
8877 if (src)
8878 ip->src_address.as_u32 = src_val.as_u32;
8879
8880 if (dst)
8881 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008882
Ed Warnickecb9cada2015-12-08 15:45:58 -07008883 if (proto)
8884 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008885
Ed Warnickecb9cada2015-12-08 15:45:58 -07008886
8887 /* These are not, but they're included for completeness */
8888 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04008889 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008890
8891 if (hdr_length)
8892 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008893
Ed Warnickecb9cada2015-12-08 15:45:58 -07008894 if (tos)
8895 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008896
Ed Warnickecb9cada2015-12-08 15:45:58 -07008897 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008898 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008899
Ed Warnickecb9cada2015-12-08 15:45:58 -07008900 if (ttl)
8901 ip->ttl = ttl_val;
8902
8903 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008904 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008905
8906 *matchp = match;
8907 return 1;
8908}
8909
Dave Barach72d72232016-08-04 10:15:08 -04008910uword
8911unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008912{
Dave Barach72d72232016-08-04 10:15:08 -04008913 u8 **matchp = va_arg (*args, u8 **);
8914 u8 *match = 0;
8915 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008916 int version = 0;
8917 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04008918 u8 traffic_class = 0;
8919 u32 traffic_class_val = 0;
8920 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008921 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008922 int src = 0, dst = 0;
8923 ip6_address_t src_val, dst_val;
8924 int proto = 0;
8925 u32 proto_val;
8926 int payload_length = 0;
8927 u32 payload_length_val;
8928 int hop_limit = 0;
8929 int hop_limit_val;
8930 u32 ip_version_traffic_class_and_flow_label;
8931
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008932 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008933 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008934 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04008935 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008936 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04008937 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008938 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04008939 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008940 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04008941 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008942 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04008943 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008944 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04008945 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008946 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04008947 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008948 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04008949 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008950 else
Dave Barach72d72232016-08-04 10:15:08 -04008951 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008952 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008953
Ed Warnickecb9cada2015-12-08 15:45:58 -07008954 if (version + traffic_class + flow_label + src + dst + proto +
8955 payload_length + hop_limit == 0)
8956 return 0;
8957
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008958 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07008959 * Aligned because we use the real comparison functions
8960 */
Dave Barach72d72232016-08-04 10:15:08 -04008961 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008962
Ed Warnickecb9cada2015-12-08 15:45:58 -07008963 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008964
Ed Warnickecb9cada2015-12-08 15:45:58 -07008965 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01008966 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008967
8968 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01008969 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008970
Ed Warnickecb9cada2015-12-08 15:45:58 -07008971 if (proto)
8972 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008973
Ed Warnickecb9cada2015-12-08 15:45:58 -07008974 ip_version_traffic_class_and_flow_label = 0;
8975
8976 if (version)
8977 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8978
8979 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04008980 ip_version_traffic_class_and_flow_label |=
8981 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008982
8983 if (flow_label)
8984 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008985
8986 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008987 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8988
8989 if (payload_length)
8990 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008991
Ed Warnickecb9cada2015-12-08 15:45:58 -07008992 if (hop_limit)
8993 ip->hop_limit = hop_limit_val;
8994
8995 *matchp = match;
8996 return 1;
8997}
8998
Dave Barach72d72232016-08-04 10:15:08 -04008999uword
9000unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009001{
Dave Barach72d72232016-08-04 10:15:08 -04009002 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009003
Dave Barach72d72232016-08-04 10:15:08 -04009004 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9005 {
9006 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9007 return 1;
9008 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9009 return 1;
9010 else
9011 break;
9012 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009013 return 0;
9014}
9015
Dave Barach72d72232016-08-04 10:15:08 -04009016uword
9017unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009018{
Dave Barach72d72232016-08-04 10:15:08 -04009019 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009020 u32 tag;
9021
Dave Barach72d72232016-08-04 10:15:08 -04009022 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009023 {
Dave Barach72d72232016-08-04 10:15:08 -04009024 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009025 tagp[1] = tag & 0xFF;
9026 return 1;
9027 }
9028
9029 return 0;
9030}
9031
Dave Barach72d72232016-08-04 10:15:08 -04009032uword
9033unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009034{
Dave Barach72d72232016-08-04 10:15:08 -04009035 u8 **matchp = va_arg (*args, u8 **);
9036 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009037 u8 src = 0;
9038 u8 src_val[6];
9039 u8 dst = 0;
9040 u8 dst_val[6];
9041 u8 proto = 0;
9042 u16 proto_val;
9043 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009044 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009045 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009046 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009047 int len = 14;
9048 u8 ignore_tag1 = 0;
9049 u8 ignore_tag2 = 0;
9050 u8 cos1 = 0;
9051 u8 cos2 = 0;
9052 u32 cos1_val = 0;
9053 u32 cos2_val = 0;
9054
Dave Barach72d72232016-08-04 10:15:08 -04009055 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9056 {
9057 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9058 src = 1;
9059 else
9060 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9061 dst = 1;
9062 else if (unformat (input, "proto %U",
9063 unformat_ethernet_type_host_byte_order, &proto_val))
9064 proto = 1;
9065 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9066 tag1 = 1;
9067 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9068 tag2 = 1;
9069 else if (unformat (input, "ignore-tag1"))
9070 ignore_tag1 = 1;
9071 else if (unformat (input, "ignore-tag2"))
9072 ignore_tag2 = 1;
9073 else if (unformat (input, "cos1 %d", &cos1_val))
9074 cos1 = 1;
9075 else if (unformat (input, "cos2 %d", &cos2_val))
9076 cos2 = 1;
9077 else
9078 break;
9079 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009080 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009081 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009082 return 0;
9083
9084 if (tag1 || ignore_tag1 || cos1)
9085 len = 18;
9086 if (tag2 || ignore_tag2 || cos2)
9087 len = 22;
9088
Dave Barach72d72232016-08-04 10:15:08 -04009089 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009090
9091 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009092 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009093
9094 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009095 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009096
Ed Warnickecb9cada2015-12-08 15:45:58 -07009097 if (tag2)
9098 {
9099 /* inner vlan tag */
9100 match[19] = tag2_val[1];
9101 match[18] = tag2_val[0];
9102 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009103 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009104 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009105 {
9106 match[21] = proto_val & 0xff;
9107 match[20] = proto_val >> 8;
9108 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009109 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009110 {
9111 match[15] = tag1_val[1];
9112 match[14] = tag1_val[0];
9113 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009114 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009115 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009116 *matchp = match;
9117 return 1;
9118 }
9119 if (tag1)
9120 {
Dave Barach72d72232016-08-04 10:15:08 -04009121 match[15] = tag1_val[1];
9122 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009123 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009124 {
9125 match[17] = proto_val & 0xff;
9126 match[16] = proto_val >> 8;
9127 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009128 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009129 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009130
9131 *matchp = match;
9132 return 1;
9133 }
9134 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009135 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009136 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009137 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009138 if (proto)
9139 {
9140 match[13] = proto_val & 0xff;
9141 match[12] = proto_val >> 8;
9142 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009143
Ed Warnickecb9cada2015-12-08 15:45:58 -07009144 *matchp = match;
9145 return 1;
9146}
9147
9148
Dave Barach72d72232016-08-04 10:15:08 -04009149uword
9150unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009151{
Dave Barach72d72232016-08-04 10:15:08 -04009152 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009153 u32 skip_n_vectors = va_arg (*args, u32);
9154 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009155
Dave Barach72d72232016-08-04 10:15:08 -04009156 u8 *match = 0;
9157 u8 *l2 = 0;
9158 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009159 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160
Dave Barach72d72232016-08-04 10:15:08 -04009161 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9162 {
9163 if (unformat (input, "hex %U", unformat_hex_string, &match))
9164 ;
9165 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9166 ;
9167 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9168 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009169 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9170 ;
Dave Barach72d72232016-08-04 10:15:08 -04009171 else
9172 break;
9173 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009174
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009175 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009176 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009177 vec_free (match);
9178 vec_free (l2);
9179 vec_free (l4);
9180 return 0;
9181 }
9182
9183 if (match || l2 || l3 || l4)
9184 {
9185 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009186 {
9187 /* "Win a free Ethernet header in every packet" */
9188 if (l2 == 0)
9189 vec_validate_aligned (l2, 13, sizeof (u32x4));
9190 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009191 if (vec_len (l3))
9192 {
9193 vec_append_aligned (match, l3, sizeof (u32x4));
9194 vec_free (l3);
9195 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009196 if (vec_len (l4))
9197 {
9198 vec_append_aligned (match, l4, sizeof (u32x4));
9199 vec_free (l4);
9200 }
Dave Barach72d72232016-08-04 10:15:08 -04009201 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009202
9203 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009204 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009205 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9206 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009207
Dave Barach72d72232016-08-04 10:15:08 -04009208 /* Set size, include skipped vectors */
9209 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009210
9211 *matchp = match;
9212
9213 return 1;
9214 }
9215
9216 return 0;
9217}
9218
Dave Barach72d72232016-08-04 10:15:08 -04009219static int
9220api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009221{
Dave Barach72d72232016-08-04 10:15:08 -04009222 unformat_input_t *i = vam->input;
9223 vl_api_classify_add_del_session_t *mp;
9224 int is_add = 1;
9225 u32 table_index = ~0;
9226 u32 hit_next_index = ~0;
9227 u32 opaque_index = ~0;
9228 u8 *match = 0;
9229 i32 advance = 0;
9230 f64 timeout;
9231 u32 skip_n_vectors = 0;
9232 u32 match_n_vectors = 0;
Steve Shin25e26dc2016-11-08 10:47:10 -08009233 u32 action = 0;
9234 u32 metadata = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009235
Dave Barach72d72232016-08-04 10:15:08 -04009236 /*
9237 * Warning: you have to supply skip_n and match_n
9238 * because the API client cant simply look at the classify
9239 * table object.
9240 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009241
Dave Barach72d72232016-08-04 10:15:08 -04009242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9243 {
9244 if (unformat (i, "del"))
9245 is_add = 0;
9246 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9247 &hit_next_index))
9248 ;
9249 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9250 &hit_next_index))
9251 ;
9252 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9253 &hit_next_index))
9254 ;
9255 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9256 ;
9257 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9258 ;
9259 else if (unformat (i, "opaque-index %d", &opaque_index))
9260 ;
9261 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9262 ;
9263 else if (unformat (i, "match_n %d", &match_n_vectors))
9264 ;
9265 else if (unformat (i, "match %U", unformat_classify_match,
9266 &match, skip_n_vectors, match_n_vectors))
9267 ;
9268 else if (unformat (i, "advance %d", &advance))
9269 ;
9270 else if (unformat (i, "table-index %d", &table_index))
9271 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08009272 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
9273 action = 1;
9274 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
9275 action = 2;
9276 else if (unformat (i, "action %d", &action))
9277 ;
9278 else if (unformat (i, "metadata %d", &metadata))
9279 ;
Dave Barach72d72232016-08-04 10:15:08 -04009280 else
9281 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009282 }
9283
Dave Barach72d72232016-08-04 10:15:08 -04009284 if (table_index == ~0)
9285 {
9286 errmsg ("Table index required\n");
9287 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009288 }
9289
Dave Barach72d72232016-08-04 10:15:08 -04009290 if (is_add && match == 0)
9291 {
9292 errmsg ("Match value required\n");
9293 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009294 }
9295
Dave Barach72d72232016-08-04 10:15:08 -04009296 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009297
Dave Barach72d72232016-08-04 10:15:08 -04009298 mp->is_add = is_add;
9299 mp->table_index = ntohl (table_index);
9300 mp->hit_next_index = ntohl (hit_next_index);
9301 mp->opaque_index = ntohl (opaque_index);
9302 mp->advance = ntohl (advance);
Steve Shin25e26dc2016-11-08 10:47:10 -08009303 mp->action = action;
9304 mp->metadata = ntohl (metadata);
Dave Barach72d72232016-08-04 10:15:08 -04009305 clib_memcpy (mp->match, match, vec_len (match));
9306 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009307
Dave Barach72d72232016-08-04 10:15:08 -04009308 S;
9309 W;
9310 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009311}
9312
Dave Barach72d72232016-08-04 10:15:08 -04009313static int
9314api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009315{
Dave Barach72d72232016-08-04 10:15:08 -04009316 unformat_input_t *i = vam->input;
9317 vl_api_classify_set_interface_ip_table_t *mp;
9318 f64 timeout;
9319 u32 sw_if_index;
9320 int sw_if_index_set;
9321 u32 table_index = ~0;
9322 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009323
Dave Barach72d72232016-08-04 10:15:08 -04009324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9325 {
9326 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9327 sw_if_index_set = 1;
9328 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9329 sw_if_index_set = 1;
9330 else if (unformat (i, "table %d", &table_index))
9331 ;
9332 else
9333 {
9334 clib_warning ("parse error '%U'", format_unformat_error, i);
9335 return -99;
9336 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009337 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009338
Dave Barach72d72232016-08-04 10:15:08 -04009339 if (sw_if_index_set == 0)
9340 {
9341 errmsg ("missing interface name or sw_if_index\n");
9342 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009343 }
9344
9345
Dave Barach72d72232016-08-04 10:15:08 -04009346 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009347
Dave Barach72d72232016-08-04 10:15:08 -04009348 mp->sw_if_index = ntohl (sw_if_index);
9349 mp->table_index = ntohl (table_index);
9350 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009351
Dave Barach72d72232016-08-04 10:15:08 -04009352 S;
9353 W;
9354 /* NOTREACHED */
9355 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009356}
9357
Dave Barach72d72232016-08-04 10:15:08 -04009358static int
9359api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009360{
Dave Barach72d72232016-08-04 10:15:08 -04009361 unformat_input_t *i = vam->input;
9362 vl_api_classify_set_interface_l2_tables_t *mp;
9363 f64 timeout;
9364 u32 sw_if_index;
9365 int sw_if_index_set;
9366 u32 ip4_table_index = ~0;
9367 u32 ip6_table_index = ~0;
9368 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009369 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009370
Dave Barach72d72232016-08-04 10:15:08 -04009371 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9372 {
9373 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9374 sw_if_index_set = 1;
9375 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9376 sw_if_index_set = 1;
9377 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9378 ;
9379 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9380 ;
9381 else if (unformat (i, "other-table %d", &other_table_index))
9382 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009383 else if (unformat (i, "is-input %d", &is_input))
9384 ;
Dave Barach72d72232016-08-04 10:15:08 -04009385 else
9386 {
9387 clib_warning ("parse error '%U'", format_unformat_error, i);
9388 return -99;
9389 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009390 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009391
Dave Barach72d72232016-08-04 10:15:08 -04009392 if (sw_if_index_set == 0)
9393 {
9394 errmsg ("missing interface name or sw_if_index\n");
9395 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009396 }
9397
9398
Dave Barach72d72232016-08-04 10:15:08 -04009399 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009400
Dave Barach72d72232016-08-04 10:15:08 -04009401 mp->sw_if_index = ntohl (sw_if_index);
9402 mp->ip4_table_index = ntohl (ip4_table_index);
9403 mp->ip6_table_index = ntohl (ip6_table_index);
9404 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009405 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009406
Dave Barach72d72232016-08-04 10:15:08 -04009407 S;
9408 W;
9409 /* NOTREACHED */
9410 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009411}
9412
Dave Barach72d72232016-08-04 10:15:08 -04009413static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009414api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009415{
Dave Barach72d72232016-08-04 10:15:08 -04009416 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009417 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009418 ip4_address_t collector_address;
9419 u8 collector_address_set = 0;
9420 u32 collector_port = ~0;
9421 ip4_address_t src_address;
9422 u8 src_address_set = 0;
9423 u32 vrf_id = ~0;
9424 u32 path_mtu = ~0;
9425 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009426 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009427 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009428
Dave Barach72d72232016-08-04 10:15:08 -04009429 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9430 {
9431 if (unformat (i, "collector_address %U", unformat_ip4_address,
9432 &collector_address))
9433 collector_address_set = 1;
9434 else if (unformat (i, "collector_port %d", &collector_port))
9435 ;
9436 else if (unformat (i, "src_address %U", unformat_ip4_address,
9437 &src_address))
9438 src_address_set = 1;
9439 else if (unformat (i, "vrf_id %d", &vrf_id))
9440 ;
9441 else if (unformat (i, "path_mtu %d", &path_mtu))
9442 ;
9443 else if (unformat (i, "template_interval %d", &template_interval))
9444 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009445 else if (unformat (i, "udp_checksum"))
9446 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009447 else
9448 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009449 }
9450
Dave Barach72d72232016-08-04 10:15:08 -04009451 if (collector_address_set == 0)
9452 {
9453 errmsg ("collector_address required\n");
9454 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009455 }
9456
Dave Barach72d72232016-08-04 10:15:08 -04009457 if (src_address_set == 0)
9458 {
9459 errmsg ("src_address required\n");
9460 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009461 }
9462
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009463 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009464
Dave Barach72d72232016-08-04 10:15:08 -04009465 memcpy (mp->collector_address, collector_address.data,
9466 sizeof (collector_address.data));
9467 mp->collector_port = htons ((u16) collector_port);
9468 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9469 mp->vrf_id = htonl (vrf_id);
9470 mp->path_mtu = htonl (path_mtu);
9471 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009472 mp->udp_checksum = udp_checksum;
9473
9474 S;
9475 W;
9476 /* NOTREACHED */
9477}
9478
9479static int
9480api_set_ipfix_classify_stream (vat_main_t * vam)
9481{
9482 unformat_input_t *i = vam->input;
9483 vl_api_set_ipfix_classify_stream_t *mp;
9484 u32 domain_id = 0;
9485 u32 src_port = UDP_DST_PORT_ipfix;
9486 f64 timeout;
9487
9488 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9489 {
9490 if (unformat (i, "domain %d", &domain_id))
9491 ;
9492 else if (unformat (i, "src_port %d", &src_port))
9493 ;
9494 else
9495 {
9496 errmsg ("unknown input `%U'", format_unformat_error, i);
9497 return -99;
9498 }
9499 }
9500
9501 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9502
9503 mp->domain_id = htonl (domain_id);
9504 mp->src_port = htons ((u16) src_port);
9505
9506 S;
9507 W;
9508 /* NOTREACHED */
9509}
9510
9511static int
9512api_ipfix_classify_table_add_del (vat_main_t * vam)
9513{
9514 unformat_input_t *i = vam->input;
9515 vl_api_ipfix_classify_table_add_del_t *mp;
9516 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009517 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009518 u8 ip_version = 0;
9519 u8 transport_protocol = 255;
9520 f64 timeout;
9521
9522 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9523 {
9524 if (unformat (i, "add"))
9525 is_add = 1;
9526 else if (unformat (i, "del"))
9527 is_add = 0;
9528 else if (unformat (i, "table %d", &classify_table_index))
9529 ;
9530 else if (unformat (i, "ip4"))
9531 ip_version = 4;
9532 else if (unformat (i, "ip6"))
9533 ip_version = 6;
9534 else if (unformat (i, "tcp"))
9535 transport_protocol = 6;
9536 else if (unformat (i, "udp"))
9537 transport_protocol = 17;
9538 else
9539 {
9540 errmsg ("unknown input `%U'", format_unformat_error, i);
9541 return -99;
9542 }
9543 }
9544
9545 if (is_add == -1)
9546 {
9547 errmsg ("expecting: add|del");
9548 return -99;
9549 }
9550 if (classify_table_index == ~0)
9551 {
9552 errmsg ("classifier table not specified");
9553 return -99;
9554 }
9555 if (ip_version == 0)
9556 {
9557 errmsg ("IP version not specified");
9558 return -99;
9559 }
9560
9561 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9562
9563 mp->is_add = is_add;
9564 mp->table_id = htonl (classify_table_index);
9565 mp->ip_version = ip_version;
9566 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009567
Dave Barach72d72232016-08-04 10:15:08 -04009568 S;
9569 W;
9570 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009571}
9572
Dave Barach72d72232016-08-04 10:15:08 -04009573static int
9574api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009575{
Dave Barach72d72232016-08-04 10:15:08 -04009576 unformat_input_t *i = vam->input;
9577 vl_api_get_node_index_t *mp;
9578 f64 timeout;
9579 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009580
Dave Barach72d72232016-08-04 10:15:08 -04009581 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9582 {
9583 if (unformat (i, "node %s", &name))
9584 ;
9585 else
9586 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009587 }
Dave Barach72d72232016-08-04 10:15:08 -04009588 if (name == 0)
9589 {
9590 errmsg ("node name required\n");
9591 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009592 }
Dave Barach72d72232016-08-04 10:15:08 -04009593 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9594 {
9595 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9596 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009597 }
9598
Dave Barach72d72232016-08-04 10:15:08 -04009599 M (GET_NODE_INDEX, get_node_index);
9600 clib_memcpy (mp->node_name, name, vec_len (name));
9601 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009602
Dave Barach72d72232016-08-04 10:15:08 -04009603 S;
9604 W;
9605 /* NOTREACHED */
9606 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009607}
9608
Dave Barach72d72232016-08-04 10:15:08 -04009609static int
9610api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009611{
Dave Barach72d72232016-08-04 10:15:08 -04009612 unformat_input_t *i = vam->input;
9613 vl_api_get_next_index_t *mp;
9614 f64 timeout;
9615 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009616
Dave Barach72d72232016-08-04 10:15:08 -04009617 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9618 {
9619 if (unformat (i, "node-name %s", &node_name))
9620 ;
9621 else if (unformat (i, "next-node-name %s", &next_node_name))
9622 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009623 }
9624
Dave Barach72d72232016-08-04 10:15:08 -04009625 if (node_name == 0)
9626 {
9627 errmsg ("node name required\n");
9628 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009629 }
Dave Barach72d72232016-08-04 10:15:08 -04009630 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9631 {
9632 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9633 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009634 }
9635
Dave Barach72d72232016-08-04 10:15:08 -04009636 if (next_node_name == 0)
9637 {
9638 errmsg ("next node name required\n");
9639 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009640 }
Dave Barach72d72232016-08-04 10:15:08 -04009641 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9642 {
9643 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9644 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009645 }
9646
Dave Barach72d72232016-08-04 10:15:08 -04009647 M (GET_NEXT_INDEX, get_next_index);
9648 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9649 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9650 vec_free (node_name);
9651 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009652
Dave Barach72d72232016-08-04 10:15:08 -04009653 S;
9654 W;
9655 /* NOTREACHED */
9656 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009657}
9658
Dave Barach72d72232016-08-04 10:15:08 -04009659static int
9660api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009661{
Dave Barach72d72232016-08-04 10:15:08 -04009662 unformat_input_t *i = vam->input;
9663 vl_api_add_node_next_t *mp;
9664 f64 timeout;
9665 u8 *name = 0;
9666 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009667
Dave Barach72d72232016-08-04 10:15:08 -04009668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9669 {
9670 if (unformat (i, "node %s", &name))
9671 ;
9672 else if (unformat (i, "next %s", &next))
9673 ;
9674 else
9675 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009676 }
Dave Barach72d72232016-08-04 10:15:08 -04009677 if (name == 0)
9678 {
9679 errmsg ("node name required\n");
9680 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009681 }
Dave Barach72d72232016-08-04 10:15:08 -04009682 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9683 {
9684 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9685 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009686 }
Dave Barach72d72232016-08-04 10:15:08 -04009687 if (next == 0)
9688 {
9689 errmsg ("next node required\n");
9690 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009691 }
Dave Barach72d72232016-08-04 10:15:08 -04009692 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9693 {
9694 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9695 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009696 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009697
Dave Barach72d72232016-08-04 10:15:08 -04009698 M (ADD_NODE_NEXT, add_node_next);
9699 clib_memcpy (mp->node_name, name, vec_len (name));
9700 clib_memcpy (mp->next_name, next, vec_len (next));
9701 vec_free (name);
9702 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009703
Dave Barach72d72232016-08-04 10:15:08 -04009704 S;
9705 W;
9706 /* NOTREACHED */
9707 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009708}
9709
Dave Barach72d72232016-08-04 10:15:08 -04009710static int
9711api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009712{
Dave Barach72d72232016-08-04 10:15:08 -04009713 unformat_input_t *i = vam->input;
9714 ip6_address_t client_address, our_address;
9715 int client_address_set = 0;
9716 int our_address_set = 0;
9717 u32 local_session_id = 0;
9718 u32 remote_session_id = 0;
9719 u64 local_cookie = 0;
9720 u64 remote_cookie = 0;
9721 u8 l2_sublayer_present = 0;
9722 vl_api_l2tpv3_create_tunnel_t *mp;
9723 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009724
Dave Barach72d72232016-08-04 10:15:08 -04009725 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9726 {
9727 if (unformat (i, "client_address %U", unformat_ip6_address,
9728 &client_address))
9729 client_address_set = 1;
9730 else if (unformat (i, "our_address %U", unformat_ip6_address,
9731 &our_address))
9732 our_address_set = 1;
9733 else if (unformat (i, "local_session_id %d", &local_session_id))
9734 ;
9735 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9736 ;
9737 else if (unformat (i, "local_cookie %lld", &local_cookie))
9738 ;
9739 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9740 ;
9741 else if (unformat (i, "l2-sublayer-present"))
9742 l2_sublayer_present = 1;
9743 else
9744 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009745 }
9746
Dave Barach72d72232016-08-04 10:15:08 -04009747 if (client_address_set == 0)
9748 {
9749 errmsg ("client_address required\n");
9750 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009751 }
9752
Dave Barach72d72232016-08-04 10:15:08 -04009753 if (our_address_set == 0)
9754 {
9755 errmsg ("our_address required\n");
9756 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009757 }
9758
Dave Barach72d72232016-08-04 10:15:08 -04009759 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009760
Dave Barach72d72232016-08-04 10:15:08 -04009761 clib_memcpy (mp->client_address, client_address.as_u8,
9762 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009763
Dave Barach72d72232016-08-04 10:15:08 -04009764 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009765
Dave Barach72d72232016-08-04 10:15:08 -04009766 mp->local_session_id = ntohl (local_session_id);
9767 mp->remote_session_id = ntohl (remote_session_id);
9768 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9769 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9770 mp->l2_sublayer_present = l2_sublayer_present;
9771 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009772
Dave Barach72d72232016-08-04 10:15:08 -04009773 S;
9774 W;
9775 /* NOTREACHED */
9776 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009777}
9778
Dave Barach72d72232016-08-04 10:15:08 -04009779static int
9780api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009781{
Dave Barach72d72232016-08-04 10:15:08 -04009782 unformat_input_t *i = vam->input;
9783 u32 sw_if_index;
9784 u8 sw_if_index_set = 0;
9785 u64 new_local_cookie = 0;
9786 u64 new_remote_cookie = 0;
9787 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9788 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009789
Dave Barach72d72232016-08-04 10:15:08 -04009790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9791 {
9792 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9793 sw_if_index_set = 1;
9794 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9795 sw_if_index_set = 1;
9796 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
9797 ;
9798 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
9799 ;
9800 else
9801 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009802 }
9803
Dave Barach72d72232016-08-04 10:15:08 -04009804 if (sw_if_index_set == 0)
9805 {
9806 errmsg ("missing interface name or sw_if_index\n");
9807 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009808 }
9809
Dave Barach72d72232016-08-04 10:15:08 -04009810 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009811
Dave Barach72d72232016-08-04 10:15:08 -04009812 mp->sw_if_index = ntohl (sw_if_index);
9813 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
9814 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009815
Dave Barach72d72232016-08-04 10:15:08 -04009816 S;
9817 W;
9818 /* NOTREACHED */
9819 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009820}
9821
Dave Barach72d72232016-08-04 10:15:08 -04009822static int
9823api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009824{
Dave Barach72d72232016-08-04 10:15:08 -04009825 unformat_input_t *i = vam->input;
9826 vl_api_l2tpv3_interface_enable_disable_t *mp;
9827 f64 timeout;
9828 u32 sw_if_index;
9829 u8 sw_if_index_set = 0;
9830 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009831
Dave Barach72d72232016-08-04 10:15:08 -04009832 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9833 {
9834 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9835 sw_if_index_set = 1;
9836 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9837 sw_if_index_set = 1;
9838 else if (unformat (i, "enable"))
9839 enable_disable = 1;
9840 else if (unformat (i, "disable"))
9841 enable_disable = 0;
9842 else
9843 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009844 }
9845
Dave Barach72d72232016-08-04 10:15:08 -04009846 if (sw_if_index_set == 0)
9847 {
9848 errmsg ("missing interface name or sw_if_index\n");
9849 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009850 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009851
Dave Barach72d72232016-08-04 10:15:08 -04009852 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009853
Dave Barach72d72232016-08-04 10:15:08 -04009854 mp->sw_if_index = ntohl (sw_if_index);
9855 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009856
Dave Barach72d72232016-08-04 10:15:08 -04009857 S;
9858 W;
9859 /* NOTREACHED */
9860 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009861}
9862
Dave Barach72d72232016-08-04 10:15:08 -04009863static int
9864api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009865{
Dave Barach72d72232016-08-04 10:15:08 -04009866 unformat_input_t *i = vam->input;
9867 vl_api_l2tpv3_set_lookup_key_t *mp;
9868 f64 timeout;
9869 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009870
Dave Barach72d72232016-08-04 10:15:08 -04009871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9872 {
9873 if (unformat (i, "lookup_v6_src"))
9874 key = L2T_LOOKUP_SRC_ADDRESS;
9875 else if (unformat (i, "lookup_v6_dst"))
9876 key = L2T_LOOKUP_DST_ADDRESS;
9877 else if (unformat (i, "lookup_session_id"))
9878 key = L2T_LOOKUP_SESSION_ID;
9879 else
9880 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009881 }
9882
Dave Barach72d72232016-08-04 10:15:08 -04009883 if (key == (u8) ~ 0)
9884 {
9885 errmsg ("l2tp session lookup key unset\n");
9886 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009887 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009888
Dave Barach72d72232016-08-04 10:15:08 -04009889 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009890
Dave Barach72d72232016-08-04 10:15:08 -04009891 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009892
Dave Barach72d72232016-08-04 10:15:08 -04009893 S;
9894 W;
9895 /* NOTREACHED */
9896 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009897}
9898
9899static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009900 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009901{
Dave Barach72d72232016-08-04 10:15:08 -04009902 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009903
Dave Barach72d72232016-08-04 10:15:08 -04009904 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
9905 format_ip6_address, mp->our_address,
9906 format_ip6_address, mp->client_address,
9907 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009908
Dave Barach72d72232016-08-04 10:15:08 -04009909 fformat (vam->ofp,
9910 " local cookies %016llx %016llx remote cookie %016llx\n",
9911 clib_net_to_host_u64 (mp->local_cookie[0]),
9912 clib_net_to_host_u64 (mp->local_cookie[1]),
9913 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009914
Dave Barach72d72232016-08-04 10:15:08 -04009915 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
9916 clib_net_to_host_u32 (mp->local_session_id),
9917 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009918
Dave Barach72d72232016-08-04 10:15:08 -04009919 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
9920 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009921
9922}
9923
9924static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009925 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009926{
Dave Barach72d72232016-08-04 10:15:08 -04009927 vat_main_t *vam = &vat_main;
9928 vat_json_node_t *node = NULL;
9929 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009930
Dave Barach72d72232016-08-04 10:15:08 -04009931 if (VAT_JSON_ARRAY != vam->json_tree.type)
9932 {
9933 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9934 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009935 }
Dave Barach72d72232016-08-04 10:15:08 -04009936 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009937
Dave Barach72d72232016-08-04 10:15:08 -04009938 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009939
Dave Barach72d72232016-08-04 10:15:08 -04009940 clib_memcpy (&addr, mp->our_address, sizeof (addr));
9941 vat_json_object_add_ip6 (node, "our_address", addr);
9942 clib_memcpy (&addr, mp->client_address, sizeof (addr));
9943 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009944
Dave Barach72d72232016-08-04 10:15:08 -04009945 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
9946 vat_json_init_array (lc);
9947 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
9948 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
9949 vat_json_object_add_uint (node, "remote_cookie",
9950 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009951
Dave Barach72d72232016-08-04 10:15:08 -04009952 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
9953 vat_json_object_add_uint (node, "local_session_id",
9954 clib_net_to_host_u32 (mp->local_session_id));
9955 vat_json_object_add_uint (node, "remote_session_id",
9956 clib_net_to_host_u32 (mp->remote_session_id));
9957 vat_json_object_add_string_copy (node, "l2_sublayer",
9958 mp->l2_sublayer_present ? (u8 *) "present"
9959 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -07009960}
9961
Dave Barach72d72232016-08-04 10:15:08 -04009962static int
9963api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009964{
Dave Barach72d72232016-08-04 10:15:08 -04009965 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
9966 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009967
Dave Barach72d72232016-08-04 10:15:08 -04009968 /* Get list of l2tpv3-tunnel interfaces */
9969 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
9970 S;
9971
9972 /* Use a control ping for synchronization */
9973 {
9974 vl_api_control_ping_t *mp;
9975 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009976 S;
Dave Barach72d72232016-08-04 10:15:08 -04009977 }
9978 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009979}
9980
9981
9982static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04009983 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009984{
Dave Barach72d72232016-08-04 10:15:08 -04009985 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009986
Dave Barach72d72232016-08-04 10:15:08 -04009987 fformat (vam->ofp, "%-16s %d\n",
9988 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009989}
9990
9991static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04009992 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009993{
Dave Barach72d72232016-08-04 10:15:08 -04009994 vat_main_t *vam = &vat_main;
9995 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009996
Dave Barach72d72232016-08-04 10:15:08 -04009997 if (VAT_JSON_ARRAY != vam->json_tree.type)
9998 {
9999 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10000 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010001 }
Dave Barach72d72232016-08-04 10:15:08 -040010002 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010003
Dave Barach72d72232016-08-04 10:15:08 -040010004 vat_json_init_object (node);
10005 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10006 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010007}
10008
Dave Barach72d72232016-08-04 10:15:08 -040010009static int
10010api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010011{
Dave Barach72d72232016-08-04 10:15:08 -040010012 vl_api_sw_interface_tap_dump_t *mp;
10013 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010014
Dave Barach72d72232016-08-04 10:15:08 -040010015 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10016 /* Get list of tap interfaces */
10017 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10018 S;
10019
10020 /* Use a control ping for synchronization */
10021 {
10022 vl_api_control_ping_t *mp;
10023 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010024 S;
Dave Barach72d72232016-08-04 10:15:08 -040010025 }
10026 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010027}
10028
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010029static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010030 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010031{
Dave Barach72d72232016-08-04 10:15:08 -040010032 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010033 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010034
John Loc42912d2016-11-07 18:30:47 -050010035 if (unformat (input, "l2"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070010036 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10037 else if (unformat (input, "%d", &tmp))
10038 *result = tmp;
10039 else
10040 return 0;
10041 return 1;
10042}
10043
Dave Barach72d72232016-08-04 10:15:08 -040010044static int
10045api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010046{
Dave Barach72d72232016-08-04 10:15:08 -040010047 unformat_input_t *line_input = vam->input;
10048 vl_api_vxlan_add_del_tunnel_t *mp;
10049 f64 timeout;
Eyal Baric5b13602016-11-24 19:42:43 +020010050 ip46_address_t src, dst;
Dave Barach72d72232016-08-04 10:15:08 -040010051 u8 is_add = 1;
10052 u8 ipv4_set = 0, ipv6_set = 0;
10053 u8 src_set = 0;
10054 u8 dst_set = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010055 u8 grp_set = 0;
10056 u32 mcast_sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040010057 u32 encap_vrf_id = 0;
10058 u32 decap_next_index = ~0;
10059 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010060
Eyal Baric5b13602016-11-24 19:42:43 +020010061 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
10062 memset (&src, 0, sizeof src);
10063 memset (&dst, 0, sizeof dst);
10064
Dave Barach72d72232016-08-04 10:15:08 -040010065 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10066 {
10067 if (unformat (line_input, "del"))
10068 is_add = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010069 else
10070 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010071 {
10072 ipv4_set = 1;
10073 src_set = 1;
10074 }
Eyal Baric5b13602016-11-24 19:42:43 +020010075 else
10076 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010077 {
10078 ipv4_set = 1;
10079 dst_set = 1;
10080 }
Eyal Baric5b13602016-11-24 19:42:43 +020010081 else
10082 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010083 {
10084 ipv6_set = 1;
10085 src_set = 1;
10086 }
Eyal Baric5b13602016-11-24 19:42:43 +020010087 else
10088 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010089 {
10090 ipv6_set = 1;
10091 dst_set = 1;
10092 }
Eyal Baric5b13602016-11-24 19:42:43 +020010093 else if (unformat (line_input, "group %U %U",
10094 unformat_ip4_address, &dst.ip4,
10095 unformat_sw_if_index, vam, &mcast_sw_if_index))
10096 {
10097 grp_set = dst_set = 1;
10098 ipv4_set = 1;
10099 }
10100 else if (unformat (line_input, "group %U",
10101 unformat_ip4_address, &dst.ip4))
10102 {
10103 grp_set = dst_set = 1;
10104 ipv4_set = 1;
10105 }
10106 else if (unformat (line_input, "group %U %U",
10107 unformat_ip6_address, &dst.ip6,
10108 unformat_sw_if_index, vam, &mcast_sw_if_index))
10109 {
10110 grp_set = dst_set = 1;
10111 ipv6_set = 1;
10112 }
10113 else if (unformat (line_input, "group %U",
10114 unformat_ip6_address, &dst.ip6))
10115 {
10116 grp_set = dst_set = 1;
10117 ipv6_set = 1;
10118 }
10119 else
10120 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10121 ;
Dave Barach72d72232016-08-04 10:15:08 -040010122 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10123 ;
10124 else if (unformat (line_input, "decap-next %U",
10125 unformat_vxlan_decap_next, &decap_next_index))
10126 ;
10127 else if (unformat (line_input, "vni %d", &vni))
10128 ;
10129 else
10130 {
10131 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10132 return -99;
10133 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010134 }
10135
Dave Barach72d72232016-08-04 10:15:08 -040010136 if (src_set == 0)
10137 {
10138 errmsg ("tunnel src address not specified\n");
10139 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010140 }
Dave Barach72d72232016-08-04 10:15:08 -040010141 if (dst_set == 0)
10142 {
10143 errmsg ("tunnel dst address not specified\n");
10144 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010145 }
10146
Eyal Baric5b13602016-11-24 19:42:43 +020010147 if (grp_set && !ip46_address_is_multicast (&dst))
10148 {
10149 errmsg ("tunnel group address not multicast\n");
10150 return -99;
10151 }
10152 if (grp_set && mcast_sw_if_index == ~0)
10153 {
10154 errmsg ("tunnel nonexistent multicast device\n");
10155 return -99;
10156 }
10157
10158
Dave Barach72d72232016-08-04 10:15:08 -040010159 if (ipv4_set && ipv6_set)
10160 {
10161 errmsg ("both IPv4 and IPv6 addresses specified");
10162 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010163 }
10164
Dave Barach72d72232016-08-04 10:15:08 -040010165 if ((vni == 0) || (vni >> 24))
10166 {
10167 errmsg ("vni not specified or out of range\n");
10168 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010169 }
10170
Dave Barach72d72232016-08-04 10:15:08 -040010171 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010172
Dave Barach72d72232016-08-04 10:15:08 -040010173 if (ipv6_set)
10174 {
Eyal Baric5b13602016-11-24 19:42:43 +020010175 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
10176 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
Chris Luke99cb3352016-04-26 10:49:53 -040010177 }
Dave Barach72d72232016-08-04 10:15:08 -040010178 else
10179 {
Eyal Baric5b13602016-11-24 19:42:43 +020010180 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
10181 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010182 }
10183 mp->encap_vrf_id = ntohl (encap_vrf_id);
10184 mp->decap_next_index = ntohl (decap_next_index);
Eyal Baric5b13602016-11-24 19:42:43 +020010185 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Dave Barach72d72232016-08-04 10:15:08 -040010186 mp->vni = ntohl (vni);
10187 mp->is_add = is_add;
10188 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010189
Dave Barach72d72232016-08-04 10:15:08 -040010190 S;
10191 W;
10192 /* NOTREACHED */
10193 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010194}
10195
Dave Wallace60231f32015-12-17 21:04:30 -050010196static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010197 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010198{
Dave Barach72d72232016-08-04 10:15:08 -040010199 vat_main_t *vam = &vat_main;
Eyal Baric5b13602016-11-24 19:42:43 +020010200 ip46_address_t src, dst;
Dave Wallace60231f32015-12-17 21:04:30 -050010201
Eyal Baric5b13602016-11-24 19:42:43 +020010202 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src);
10203 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst);
10204
10205 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010206 ntohl (mp->sw_if_index),
Eyal Baric5b13602016-11-24 19:42:43 +020010207 format_ip46_address, &src, IP46_TYPE_ANY,
10208 format_ip46_address, &dst, IP46_TYPE_ANY,
Dave Barach72d72232016-08-04 10:15:08 -040010209 ntohl (mp->encap_vrf_id),
Eyal Baric5b13602016-11-24 19:42:43 +020010210 ntohl (mp->decap_next_index), ntohl (mp->vni),
10211 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010212}
10213
10214static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010215 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010216{
Dave Barach72d72232016-08-04 10:15:08 -040010217 vat_main_t *vam = &vat_main;
10218 vat_json_node_t *node = NULL;
Dave Wallace60231f32015-12-17 21:04:30 -050010219
Dave Barach72d72232016-08-04 10:15:08 -040010220 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010221 {
Dave Barach72d72232016-08-04 10:15:08 -040010222 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10223 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010224 }
Dave Barach72d72232016-08-04 10:15:08 -040010225 node = vat_json_array_add (&vam->json_tree);
10226
10227 vat_json_init_object (node);
10228 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10229 if (mp->is_ipv6)
10230 {
Eyal Baric5b13602016-11-24 19:42:43 +020010231 struct in6_addr ip6;
10232
10233 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010234 vat_json_object_add_ip6 (node, "src_address", ip6);
Eyal Baric5b13602016-11-24 19:42:43 +020010235 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010236 vat_json_object_add_ip6 (node, "dst_address", ip6);
10237 }
10238 else
10239 {
Eyal Baric5b13602016-11-24 19:42:43 +020010240 struct in_addr ip4;
10241
10242 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010243 vat_json_object_add_ip4 (node, "src_address", ip4);
Eyal Baric5b13602016-11-24 19:42:43 +020010244 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010245 vat_json_object_add_ip4 (node, "dst_address", ip4);
10246 }
10247 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10248 vat_json_object_add_uint (node, "decap_next_index",
10249 ntohl (mp->decap_next_index));
10250 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10251 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Eyal Baric5b13602016-11-24 19:42:43 +020010252 vat_json_object_add_uint (node, "mcast_sw_if_index",
10253 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010254}
10255
Dave Barach72d72232016-08-04 10:15:08 -040010256static int
10257api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010258{
Dave Barach72d72232016-08-04 10:15:08 -040010259 unformat_input_t *i = vam->input;
10260 vl_api_vxlan_tunnel_dump_t *mp;
10261 f64 timeout;
10262 u32 sw_if_index;
10263 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010264
Dave Barach72d72232016-08-04 10:15:08 -040010265 /* Parse args required to build the message */
10266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10267 {
10268 if (unformat (i, "sw_if_index %d", &sw_if_index))
10269 sw_if_index_set = 1;
10270 else
10271 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010272 }
10273
Dave Barach72d72232016-08-04 10:15:08 -040010274 if (sw_if_index_set == 0)
10275 {
10276 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010277 }
Dave Barach72d72232016-08-04 10:15:08 -040010278
10279 if (!vam->json_output)
10280 {
Eyal Baric5b13602016-11-24 19:42:43 +020010281 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s\n",
Dave Barach72d72232016-08-04 10:15:08 -040010282 "sw_if_index", "src_address", "dst_address",
Eyal Baric5b13602016-11-24 19:42:43 +020010283 "encap_vrf_id", "decap_next_index", "vni",
10284 "mcast_sw_if_index");
Dave Barach72d72232016-08-04 10:15:08 -040010285 }
10286
10287 /* Get list of vxlan-tunnel interfaces */
10288 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10289
10290 mp->sw_if_index = htonl (sw_if_index);
10291
10292 S;
10293
10294 /* Use a control ping for synchronization */
10295 {
10296 vl_api_control_ping_t *mp;
10297 M (CONTROL_PING, control_ping);
10298 S;
10299 }
10300 W;
10301}
10302
10303static int
10304api_gre_add_del_tunnel (vat_main_t * vam)
10305{
10306 unformat_input_t *line_input = vam->input;
10307 vl_api_gre_add_del_tunnel_t *mp;
10308 f64 timeout;
10309 ip4_address_t src4, dst4;
10310 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010311 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010312 u8 src_set = 0;
10313 u8 dst_set = 0;
10314 u32 outer_fib_id = 0;
10315
10316 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10317 {
10318 if (unformat (line_input, "del"))
10319 is_add = 0;
10320 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10321 src_set = 1;
10322 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10323 dst_set = 1;
10324 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10325 ;
David Hothama8cd3092016-09-19 09:55:07 -070010326 else if (unformat (line_input, "teb"))
10327 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010328 else
10329 {
10330 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10331 return -99;
10332 }
10333 }
10334
10335 if (src_set == 0)
10336 {
10337 errmsg ("tunnel src address not specified\n");
10338 return -99;
10339 }
10340 if (dst_set == 0)
10341 {
10342 errmsg ("tunnel dst address not specified\n");
10343 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010344 }
10345
10346
Dave Barach72d72232016-08-04 10:15:08 -040010347 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010348
Dave Barach72d72232016-08-04 10:15:08 -040010349 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10350 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10351 mp->outer_fib_id = ntohl (outer_fib_id);
10352 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010353 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010354
Dave Barach72d72232016-08-04 10:15:08 -040010355 S;
10356 W;
10357 /* NOTREACHED */
10358 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010359}
10360
10361static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010362 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010363{
Dave Barach72d72232016-08-04 10:15:08 -040010364 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010365
David Hothama8cd3092016-09-19 09:55:07 -070010366 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010367 ntohl (mp->sw_if_index),
10368 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010369 format_ip4_address, &mp->dst_address,
10370 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010371}
10372
10373static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010374 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010375{
Dave Barach72d72232016-08-04 10:15:08 -040010376 vat_main_t *vam = &vat_main;
10377 vat_json_node_t *node = NULL;
10378 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010379
Dave Barach72d72232016-08-04 10:15:08 -040010380 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010381 {
Dave Barach72d72232016-08-04 10:15:08 -040010382 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10383 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010384 }
Dave Barach72d72232016-08-04 10:15:08 -040010385 node = vat_json_array_add (&vam->json_tree);
10386
10387 vat_json_init_object (node);
10388 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10389 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10390 vat_json_object_add_ip4 (node, "src_address", ip4);
10391 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10392 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010393 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010394 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010395}
10396
Dave Barach72d72232016-08-04 10:15:08 -040010397static int
10398api_gre_tunnel_dump (vat_main_t * vam)
10399{
10400 unformat_input_t *i = vam->input;
10401 vl_api_gre_tunnel_dump_t *mp;
10402 f64 timeout;
10403 u32 sw_if_index;
10404 u8 sw_if_index_set = 0;
10405
10406 /* Parse args required to build the message */
10407 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10408 {
10409 if (unformat (i, "sw_if_index %d", &sw_if_index))
10410 sw_if_index_set = 1;
10411 else
10412 break;
10413 }
10414
10415 if (sw_if_index_set == 0)
10416 {
10417 sw_if_index = ~0;
10418 }
10419
10420 if (!vam->json_output)
10421 {
David Hothama8cd3092016-09-19 09:55:07 -070010422 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10423 "sw_if_index", "src_address", "dst_address", "teb",
10424 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010425 }
10426
10427 /* Get list of gre-tunnel interfaces */
10428 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10429
10430 mp->sw_if_index = htonl (sw_if_index);
10431
10432 S;
10433
10434 /* Use a control ping for synchronization */
10435 {
10436 vl_api_control_ping_t *mp;
10437 M (CONTROL_PING, control_ping);
10438 S;
10439 }
10440 W;
10441}
10442
10443static int
10444api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010445{
10446// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010447 vl_api_l2_fib_clear_table_t *mp;
10448 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010449
Dave Barach72d72232016-08-04 10:15:08 -040010450 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010451
Dave Barach72d72232016-08-04 10:15:08 -040010452 S;
10453 W;
10454 /* NOTREACHED */
10455 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010456}
10457
Dave Barach72d72232016-08-04 10:15:08 -040010458static int
10459api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010460{
Dave Barach72d72232016-08-04 10:15:08 -040010461 unformat_input_t *i = vam->input;
10462 vl_api_l2_interface_efp_filter_t *mp;
10463 f64 timeout;
10464 u32 sw_if_index;
10465 u8 enable = 1;
10466 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010467
Dave Barach72d72232016-08-04 10:15:08 -040010468 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10469 {
10470 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10471 sw_if_index_set = 1;
10472 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10473 sw_if_index_set = 1;
10474 else if (unformat (i, "enable"))
10475 enable = 1;
10476 else if (unformat (i, "disable"))
10477 enable = 0;
10478 else
10479 {
10480 clib_warning ("parse error '%U'", format_unformat_error, i);
10481 return -99;
10482 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010483 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010484
Dave Barach72d72232016-08-04 10:15:08 -040010485 if (sw_if_index_set == 0)
10486 {
10487 errmsg ("missing sw_if_index\n");
10488 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010489 }
10490
Dave Barach72d72232016-08-04 10:15:08 -040010491 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010492
Dave Barach72d72232016-08-04 10:15:08 -040010493 mp->sw_if_index = ntohl (sw_if_index);
10494 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010495
Dave Barach72d72232016-08-04 10:15:08 -040010496 S;
10497 W;
10498 /* NOTREACHED */
10499 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010500}
10501
10502#define foreach_vtr_op \
10503_("disable", L2_VTR_DISABLED) \
10504_("push-1", L2_VTR_PUSH_1) \
10505_("push-2", L2_VTR_PUSH_2) \
10506_("pop-1", L2_VTR_POP_1) \
10507_("pop-2", L2_VTR_POP_2) \
10508_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10509_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10510_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10511_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10512
Dave Barach72d72232016-08-04 10:15:08 -040010513static int
10514api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010515{
Dave Barach72d72232016-08-04 10:15:08 -040010516 unformat_input_t *i = vam->input;
10517 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10518 f64 timeout;
10519 u32 sw_if_index;
10520 u8 sw_if_index_set = 0;
10521 u8 vtr_op_set = 0;
10522 u32 vtr_op = 0;
10523 u32 push_dot1q = 1;
10524 u32 tag1 = ~0;
10525 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010526
Dave Barach72d72232016-08-04 10:15:08 -040010527 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10528 {
10529 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10530 sw_if_index_set = 1;
10531 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10532 sw_if_index_set = 1;
10533 else if (unformat (i, "vtr_op %d", &vtr_op))
10534 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010535#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010536 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010537#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010538 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10539 ;
10540 else if (unformat (i, "tag1 %d", &tag1))
10541 ;
10542 else if (unformat (i, "tag2 %d", &tag2))
10543 ;
10544 else
10545 {
10546 clib_warning ("parse error '%U'", format_unformat_error, i);
10547 return -99;
10548 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010549 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010550
Dave Barach72d72232016-08-04 10:15:08 -040010551 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
10552 {
10553 errmsg ("missing vtr operation or sw_if_index\n");
10554 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010555 }
10556
Dave Barach72d72232016-08-04 10:15:08 -040010557 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10558 mp->sw_if_index = ntohl (sw_if_index);
10559 mp->vtr_op = ntohl (vtr_op);
10560 mp->push_dot1q = ntohl (push_dot1q);
10561 mp->tag1 = ntohl (tag1);
10562 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010563
Dave Barach72d72232016-08-04 10:15:08 -040010564 S;
10565 W;
10566 /* NOTREACHED */
10567 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010568}
10569
Dave Barach72d72232016-08-04 10:15:08 -040010570static int
10571api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010572{
Dave Barach72d72232016-08-04 10:15:08 -040010573 unformat_input_t *i = vam->input;
10574 vl_api_create_vhost_user_if_t *mp;
10575 f64 timeout;
10576 u8 *file_name;
10577 u8 is_server = 0;
10578 u8 file_name_set = 0;
10579 u32 custom_dev_instance = ~0;
10580 u8 hwaddr[6];
10581 u8 use_custom_mac = 0;
Dave Barach7be864a2016-11-28 11:41:35 -050010582 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010583
Dave Barach75665d32016-11-17 11:36:59 -050010584 /* Shut up coverity */
10585 memset (hwaddr, 0, sizeof (hwaddr));
10586
Dave Barach72d72232016-08-04 10:15:08 -040010587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10588 {
10589 if (unformat (i, "socket %s", &file_name))
10590 {
10591 file_name_set = 1;
10592 }
10593 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10594 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010595 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010596 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010597 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010598 is_server = 1;
Dave Barach7be864a2016-11-28 11:41:35 -050010599 else if (unformat (i, "tag %s", &tag))
10600 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010601 else
Dave Barach72d72232016-08-04 10:15:08 -040010602 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010603 }
10604
Dave Barach72d72232016-08-04 10:15:08 -040010605 if (file_name_set == 0)
10606 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010607 errmsg ("missing socket file name\n");
10608 return -99;
10609 }
10610
Dave Barach72d72232016-08-04 10:15:08 -040010611 if (vec_len (file_name) > 255)
10612 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010613 errmsg ("socket file name too long\n");
10614 return -99;
10615 }
Dave Barach72d72232016-08-04 10:15:08 -040010616 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010617
Dave Barach72d72232016-08-04 10:15:08 -040010618 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010619
Dave Barach72d72232016-08-04 10:15:08 -040010620 mp->is_server = is_server;
10621 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10622 vec_free (file_name);
10623 if (custom_dev_instance != ~0)
10624 {
10625 mp->renumber = 1;
10626 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010627 }
Dave Barach72d72232016-08-04 10:15:08 -040010628 mp->use_custom_mac = use_custom_mac;
10629 clib_memcpy (mp->mac_address, hwaddr, 6);
Dave Barach7be864a2016-11-28 11:41:35 -050010630 if (tag)
10631 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10632 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010633
Dave Barach72d72232016-08-04 10:15:08 -040010634 S;
10635 W;
10636 /* NOTREACHED */
10637 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010638}
10639
Dave Barach72d72232016-08-04 10:15:08 -040010640static int
10641api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010642{
Dave Barach72d72232016-08-04 10:15:08 -040010643 unformat_input_t *i = vam->input;
10644 vl_api_modify_vhost_user_if_t *mp;
10645 f64 timeout;
10646 u8 *file_name;
10647 u8 is_server = 0;
10648 u8 file_name_set = 0;
10649 u32 custom_dev_instance = ~0;
10650 u8 sw_if_index_set = 0;
10651 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010652
Dave Barach72d72232016-08-04 10:15:08 -040010653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10654 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010655 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010656 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010657 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010658 sw_if_index_set = 1;
10659 else if (unformat (i, "socket %s", &file_name))
10660 {
10661 file_name_set = 1;
10662 }
10663 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10664 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010665 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010666 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010667 else
Dave Barach72d72232016-08-04 10:15:08 -040010668 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010669 }
10670
Dave Barach72d72232016-08-04 10:15:08 -040010671 if (sw_if_index_set == 0)
10672 {
10673 errmsg ("missing sw_if_index or interface name\n");
10674 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010675 }
10676
Dave Barach72d72232016-08-04 10:15:08 -040010677 if (file_name_set == 0)
10678 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010679 errmsg ("missing socket file name\n");
10680 return -99;
10681 }
10682
Dave Barach72d72232016-08-04 10:15:08 -040010683 if (vec_len (file_name) > 255)
10684 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010685 errmsg ("socket file name too long\n");
10686 return -99;
10687 }
Dave Barach72d72232016-08-04 10:15:08 -040010688 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010689
Dave Barach72d72232016-08-04 10:15:08 -040010690 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010691
Dave Barach72d72232016-08-04 10:15:08 -040010692 mp->sw_if_index = ntohl (sw_if_index);
10693 mp->is_server = is_server;
10694 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10695 vec_free (file_name);
10696 if (custom_dev_instance != ~0)
10697 {
10698 mp->renumber = 1;
10699 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010700 }
10701
Dave Barach72d72232016-08-04 10:15:08 -040010702 S;
10703 W;
10704 /* NOTREACHED */
10705 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010706}
10707
Dave Barach72d72232016-08-04 10:15:08 -040010708static int
10709api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010710{
Dave Barach72d72232016-08-04 10:15:08 -040010711 unformat_input_t *i = vam->input;
10712 vl_api_delete_vhost_user_if_t *mp;
10713 f64 timeout;
10714 u32 sw_if_index = ~0;
10715 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010716
Dave Barach72d72232016-08-04 10:15:08 -040010717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10718 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010719 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010720 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010721 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010722 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010723 else
Dave Barach72d72232016-08-04 10:15:08 -040010724 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010725 }
10726
Dave Barach72d72232016-08-04 10:15:08 -040010727 if (sw_if_index_set == 0)
10728 {
10729 errmsg ("missing sw_if_index or interface name\n");
10730 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010731 }
10732
10733
Dave Barach72d72232016-08-04 10:15:08 -040010734 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010735
Dave Barach72d72232016-08-04 10:15:08 -040010736 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010737
Dave Barach72d72232016-08-04 10:15:08 -040010738 S;
10739 W;
10740 /* NOTREACHED */
10741 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010742}
10743
10744static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010745 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010746{
Dave Barach72d72232016-08-04 10:15:08 -040010747 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010748
Dave Barach72d72232016-08-04 10:15:08 -040010749 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10750 (char *) mp->interface_name,
10751 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10752 clib_net_to_host_u64 (mp->features), mp->is_server,
10753 ntohl (mp->num_regions), (char *) mp->sock_filename);
10754 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010755}
10756
10757static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010758 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010759{
Dave Barach72d72232016-08-04 10:15:08 -040010760 vat_main_t *vam = &vat_main;
10761 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010762
Dave Barach72d72232016-08-04 10:15:08 -040010763 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010764 {
Dave Barach72d72232016-08-04 10:15:08 -040010765 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10766 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010767 }
Dave Barach72d72232016-08-04 10:15:08 -040010768 node = vat_json_array_add (&vam->json_tree);
10769
10770 vat_json_init_object (node);
10771 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10772 vat_json_object_add_string_copy (node, "interface_name",
10773 mp->interface_name);
10774 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10775 ntohl (mp->virtio_net_hdr_sz));
10776 vat_json_object_add_uint (node, "features",
10777 clib_net_to_host_u64 (mp->features));
10778 vat_json_object_add_uint (node, "is_server", mp->is_server);
10779 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10780 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10781 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010782}
10783
Dave Barach72d72232016-08-04 10:15:08 -040010784static int
10785api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010786{
Dave Barach72d72232016-08-04 10:15:08 -040010787 vl_api_sw_interface_vhost_user_dump_t *mp;
10788 f64 timeout;
10789 fformat (vam->ofp,
10790 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010791
Dave Barach72d72232016-08-04 10:15:08 -040010792 /* Get list of vhost-user interfaces */
10793 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
10794 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010795
Dave Barach72d72232016-08-04 10:15:08 -040010796 /* Use a control ping for synchronization */
10797 {
10798 vl_api_control_ping_t *mp;
10799 M (CONTROL_PING, control_ping);
10800 S;
10801 }
10802 W;
10803}
10804
10805static int
10806api_show_version (vat_main_t * vam)
10807{
10808 vl_api_show_version_t *mp;
10809 f64 timeout;
10810
10811 M (SHOW_VERSION, show_version);
10812
10813 S;
10814 W;
10815 /* NOTREACHED */
10816 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010817}
10818
Ed Warnickecb9cada2015-12-08 15:45:58 -070010819
Dave Barach72d72232016-08-04 10:15:08 -040010820static int
10821api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010822{
Dave Barach72d72232016-08-04 10:15:08 -040010823 unformat_input_t *line_input = vam->input;
10824 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10825 f64 timeout;
10826 ip4_address_t local4, remote4;
10827 ip6_address_t local6, remote6;
10828 u8 is_add = 1;
10829 u8 ipv4_set = 0, ipv6_set = 0;
10830 u8 local_set = 0;
10831 u8 remote_set = 0;
10832 u32 encap_vrf_id = 0;
10833 u32 decap_vrf_id = 0;
10834 u8 protocol = ~0;
10835 u32 vni;
10836 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010837
Dave Barach72d72232016-08-04 10:15:08 -040010838 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10839 {
10840 if (unformat (line_input, "del"))
10841 is_add = 0;
10842 else if (unformat (line_input, "local %U",
10843 unformat_ip4_address, &local4))
10844 {
10845 local_set = 1;
10846 ipv4_set = 1;
10847 }
10848 else if (unformat (line_input, "remote %U",
10849 unformat_ip4_address, &remote4))
10850 {
10851 remote_set = 1;
10852 ipv4_set = 1;
10853 }
10854 else if (unformat (line_input, "local %U",
10855 unformat_ip6_address, &local6))
10856 {
10857 local_set = 1;
10858 ipv6_set = 1;
10859 }
10860 else if (unformat (line_input, "remote %U",
10861 unformat_ip6_address, &remote6))
10862 {
10863 remote_set = 1;
10864 ipv6_set = 1;
10865 }
10866 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10867 ;
10868 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10869 ;
10870 else if (unformat (line_input, "vni %d", &vni))
10871 vni_set = 1;
10872 else if (unformat (line_input, "next-ip4"))
10873 protocol = 1;
10874 else if (unformat (line_input, "next-ip6"))
10875 protocol = 2;
10876 else if (unformat (line_input, "next-ethernet"))
10877 protocol = 3;
10878 else if (unformat (line_input, "next-nsh"))
10879 protocol = 4;
10880 else
10881 {
10882 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10883 return -99;
10884 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010885 }
10886
Dave Barach72d72232016-08-04 10:15:08 -040010887 if (local_set == 0)
10888 {
10889 errmsg ("tunnel local address not specified\n");
10890 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010891 }
Dave Barach72d72232016-08-04 10:15:08 -040010892 if (remote_set == 0)
10893 {
10894 errmsg ("tunnel remote address not specified\n");
10895 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010896 }
Dave Barach72d72232016-08-04 10:15:08 -040010897 if (ipv4_set && ipv6_set)
10898 {
10899 errmsg ("both IPv4 and IPv6 addresses specified");
10900 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080010901 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010902
Dave Barach72d72232016-08-04 10:15:08 -040010903 if (vni_set == 0)
10904 {
10905 errmsg ("vni not specified\n");
10906 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010907 }
10908
Dave Barach72d72232016-08-04 10:15:08 -040010909 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010910
Hongjun Nidf921cc2016-05-25 01:16:19 +080010911
Dave Barach72d72232016-08-04 10:15:08 -040010912 if (ipv6_set)
10913 {
10914 clib_memcpy (&mp->local, &local6, sizeof (local6));
10915 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
10916 }
10917 else
10918 {
10919 clib_memcpy (&mp->local, &local4, sizeof (local4));
10920 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080010921 }
10922
Dave Barach72d72232016-08-04 10:15:08 -040010923 mp->encap_vrf_id = ntohl (encap_vrf_id);
10924 mp->decap_vrf_id = ntohl (decap_vrf_id);
10925 mp->protocol = ntohl (protocol);
10926 mp->vni = ntohl (vni);
10927 mp->is_add = is_add;
10928 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010929
Dave Barach72d72232016-08-04 10:15:08 -040010930 S;
10931 W;
10932 /* NOTREACHED */
10933 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010934}
10935
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010936static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010937 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010938{
Dave Barach72d72232016-08-04 10:15:08 -040010939 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010940
Dave Barach72d72232016-08-04 10:15:08 -040010941 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
10942 ntohl (mp->sw_if_index),
10943 format_ip46_address, &(mp->local[0]),
10944 format_ip46_address, &(mp->remote[0]),
10945 ntohl (mp->vni),
10946 ntohl (mp->protocol),
10947 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010948}
10949
10950static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010951 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010952{
Dave Barach72d72232016-08-04 10:15:08 -040010953 vat_main_t *vam = &vat_main;
10954 vat_json_node_t *node = NULL;
10955 struct in_addr ip4;
10956 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010957
Dave Barach72d72232016-08-04 10:15:08 -040010958 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010959 {
Dave Barach72d72232016-08-04 10:15:08 -040010960 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10961 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010962 }
Dave Barach72d72232016-08-04 10:15:08 -040010963 node = vat_json_array_add (&vam->json_tree);
10964
10965 vat_json_init_object (node);
10966 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10967 if (mp->is_ipv6)
10968 {
10969 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
10970 vat_json_object_add_ip6 (node, "local", ip6);
10971 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
10972 vat_json_object_add_ip6 (node, "remote", ip6);
10973 }
10974 else
10975 {
10976 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
10977 vat_json_object_add_ip4 (node, "local", ip4);
10978 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
10979 vat_json_object_add_ip4 (node, "remote", ip4);
10980 }
10981 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10982 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10983 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10984 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10985 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080010986}
10987
Dave Barach72d72232016-08-04 10:15:08 -040010988static int
10989api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010990{
Dave Barach72d72232016-08-04 10:15:08 -040010991 unformat_input_t *i = vam->input;
10992 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10993 f64 timeout;
10994 u32 sw_if_index;
10995 u8 sw_if_index_set = 0;
10996
10997 /* Parse args required to build the message */
10998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10999 {
11000 if (unformat (i, "sw_if_index %d", &sw_if_index))
11001 sw_if_index_set = 1;
11002 else
11003 break;
11004 }
11005
11006 if (sw_if_index_set == 0)
11007 {
11008 sw_if_index = ~0;
11009 }
11010
11011 if (!vam->json_output)
11012 {
11013 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
11014 "sw_if_index", "local", "remote", "vni",
11015 "protocol", "encap_vrf_id", "decap_vrf_id");
11016 }
11017
11018 /* Get list of vxlan-tunnel interfaces */
11019 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
11020
11021 mp->sw_if_index = htonl (sw_if_index);
11022
11023 S;
11024
11025 /* Use a control ping for synchronization */
11026 {
11027 vl_api_control_ping_t *mp;
11028 M (CONTROL_PING, control_ping);
11029 S;
11030 }
11031 W;
11032}
11033
11034u8 *
11035format_l2_fib_mac_address (u8 * s, va_list * args)
11036{
11037 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011038
11039 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011040 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011041}
11042
11043static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011044 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011045{
Dave Barach72d72232016-08-04 10:15:08 -040011046 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011047
Dave Barach72d72232016-08-04 10:15:08 -040011048 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11049 " %d %d %d\n",
11050 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11051 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11052 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011053}
11054
11055static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011056 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011057{
Dave Barach72d72232016-08-04 10:15:08 -040011058 vat_main_t *vam = &vat_main;
11059 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011060
Dave Barach72d72232016-08-04 10:15:08 -040011061 if (VAT_JSON_ARRAY != vam->json_tree.type)
11062 {
11063 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11064 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011065 }
Dave Barach72d72232016-08-04 10:15:08 -040011066 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011067
Dave Barach72d72232016-08-04 10:15:08 -040011068 vat_json_init_object (node);
11069 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11070 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11071 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11072 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11073 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11074 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011075}
11076
Dave Barach72d72232016-08-04 10:15:08 -040011077static int
11078api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011079{
Dave Barach72d72232016-08-04 10:15:08 -040011080 unformat_input_t *i = vam->input;
11081 vl_api_l2_fib_table_dump_t *mp;
11082 f64 timeout;
11083 u32 bd_id;
11084 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011085
Dave Barach72d72232016-08-04 10:15:08 -040011086 /* Parse args required to build the message */
11087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011088 {
Dave Barach72d72232016-08-04 10:15:08 -040011089 if (unformat (i, "bd_id %d", &bd_id))
11090 bd_id_set = 1;
11091 else
11092 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011093 }
Dave Barach72d72232016-08-04 10:15:08 -040011094
11095 if (bd_id_set == 0)
11096 {
11097 errmsg ("missing bridge domain\n");
11098 return -99;
11099 }
11100
11101 fformat (vam->ofp,
11102 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11103
11104 /* Get list of l2 fib entries */
11105 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11106
11107 mp->bd_id = ntohl (bd_id);
11108 S;
11109
11110 /* Use a control ping for synchronization */
11111 {
11112 vl_api_control_ping_t *mp;
11113 M (CONTROL_PING, control_ping);
11114 S;
11115 }
11116 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011117}
11118
11119
11120static int
11121api_interface_name_renumber (vat_main_t * vam)
11122{
Dave Barach72d72232016-08-04 10:15:08 -040011123 unformat_input_t *line_input = vam->input;
11124 vl_api_interface_name_renumber_t *mp;
11125 u32 sw_if_index = ~0;
11126 f64 timeout;
11127 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011128
Dave Barach72d72232016-08-04 10:15:08 -040011129 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11130 {
11131 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11132 &sw_if_index))
11133 ;
11134 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11135 ;
11136 else if (unformat (line_input, "new_show_dev_instance %d",
11137 &new_show_dev_instance))
11138 ;
11139 else
11140 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011141 }
11142
Dave Barach72d72232016-08-04 10:15:08 -040011143 if (sw_if_index == ~0)
11144 {
11145 errmsg ("missing interface name or sw_if_index\n");
11146 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011147 }
11148
Dave Barach72d72232016-08-04 10:15:08 -040011149 if (new_show_dev_instance == ~0)
11150 {
11151 errmsg ("missing new_show_dev_instance\n");
11152 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011153 }
11154
Dave Barach72d72232016-08-04 10:15:08 -040011155 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011156
Dave Barach72d72232016-08-04 10:15:08 -040011157 mp->sw_if_index = ntohl (sw_if_index);
11158 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011159
Dave Barach72d72232016-08-04 10:15:08 -040011160 S;
11161 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011162}
11163
11164static int
11165api_want_ip4_arp_events (vat_main_t * vam)
11166{
Dave Barach72d72232016-08-04 10:15:08 -040011167 unformat_input_t *line_input = vam->input;
11168 vl_api_want_ip4_arp_events_t *mp;
11169 f64 timeout;
11170 ip4_address_t address;
11171 int address_set = 0;
11172 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011173
Dave Barach72d72232016-08-04 10:15:08 -040011174 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11175 {
11176 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11177 address_set = 1;
11178 else if (unformat (line_input, "del"))
11179 enable_disable = 0;
11180 else
11181 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011182 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011183
Dave Barach72d72232016-08-04 10:15:08 -040011184 if (address_set == 0)
11185 {
11186 errmsg ("missing addresses\n");
11187 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011188 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011189
Dave Barach72d72232016-08-04 10:15:08 -040011190 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11191 mp->enable_disable = enable_disable;
11192 mp->pid = getpid ();
11193 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011194
Dave Barach72d72232016-08-04 10:15:08 -040011195 S;
11196 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011197}
11198
Dave Barach72d72232016-08-04 10:15:08 -040011199static int
John Lo1edfba92016-08-27 01:11:57 -040011200api_want_ip6_nd_events (vat_main_t * vam)
11201{
11202 unformat_input_t *line_input = vam->input;
11203 vl_api_want_ip6_nd_events_t *mp;
11204 f64 timeout;
11205 ip6_address_t address;
11206 int address_set = 0;
11207 u32 enable_disable = 1;
11208
11209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11210 {
11211 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11212 address_set = 1;
11213 else if (unformat (line_input, "del"))
11214 enable_disable = 0;
11215 else
11216 break;
11217 }
11218
11219 if (address_set == 0)
11220 {
11221 errmsg ("missing addresses\n");
11222 return -99;
11223 }
11224
11225 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11226 mp->enable_disable = enable_disable;
11227 mp->pid = getpid ();
11228 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11229
11230 S;
11231 W;
11232}
11233
11234static int
Dave Barach72d72232016-08-04 10:15:08 -040011235api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011236{
Dave Barach72d72232016-08-04 10:15:08 -040011237 unformat_input_t *i = vam->input;
11238 vl_api_input_acl_set_interface_t *mp;
11239 f64 timeout;
11240 u32 sw_if_index;
11241 int sw_if_index_set;
11242 u32 ip4_table_index = ~0;
11243 u32 ip6_table_index = ~0;
11244 u32 l2_table_index = ~0;
11245 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011246
Dave Barach72d72232016-08-04 10:15:08 -040011247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11248 {
11249 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11250 sw_if_index_set = 1;
11251 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11252 sw_if_index_set = 1;
11253 else if (unformat (i, "del"))
11254 is_add = 0;
11255 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11256 ;
11257 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11258 ;
11259 else if (unformat (i, "l2-table %d", &l2_table_index))
11260 ;
11261 else
11262 {
11263 clib_warning ("parse error '%U'", format_unformat_error, i);
11264 return -99;
11265 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011266 }
11267
Dave Barach72d72232016-08-04 10:15:08 -040011268 if (sw_if_index_set == 0)
11269 {
11270 errmsg ("missing interface name or sw_if_index\n");
11271 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011272 }
11273
Dave Barach72d72232016-08-04 10:15:08 -040011274 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011275
Dave Barach72d72232016-08-04 10:15:08 -040011276 mp->sw_if_index = ntohl (sw_if_index);
11277 mp->ip4_table_index = ntohl (ip4_table_index);
11278 mp->ip6_table_index = ntohl (ip6_table_index);
11279 mp->l2_table_index = ntohl (l2_table_index);
11280 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011281
Dave Barach72d72232016-08-04 10:15:08 -040011282 S;
11283 W;
11284 /* NOTREACHED */
11285 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011286}
11287
11288static int
11289api_ip_address_dump (vat_main_t * vam)
11290{
Dave Barach72d72232016-08-04 10:15:08 -040011291 unformat_input_t *i = vam->input;
11292 vl_api_ip_address_dump_t *mp;
11293 u32 sw_if_index = ~0;
11294 u8 sw_if_index_set = 0;
11295 u8 ipv4_set = 0;
11296 u8 ipv6_set = 0;
11297 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011298
Dave Barach72d72232016-08-04 10:15:08 -040011299 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011300 {
Dave Barach72d72232016-08-04 10:15:08 -040011301 if (unformat (i, "sw_if_index %d", &sw_if_index))
11302 sw_if_index_set = 1;
11303 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11304 sw_if_index_set = 1;
11305 else if (unformat (i, "ipv4"))
11306 ipv4_set = 1;
11307 else if (unformat (i, "ipv6"))
11308 ipv6_set = 1;
11309 else
11310 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011311 }
Dave Barach72d72232016-08-04 10:15:08 -040011312
11313 if (ipv4_set && ipv6_set)
11314 {
11315 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11316 return -99;
11317 }
11318
11319 if ((!ipv4_set) && (!ipv6_set))
11320 {
11321 errmsg ("no ipv4 nor ipv6 flag set\n");
11322 return -99;
11323 }
11324
11325 if (sw_if_index_set == 0)
11326 {
11327 errmsg ("missing interface name or sw_if_index\n");
11328 return -99;
11329 }
11330
11331 vam->current_sw_if_index = sw_if_index;
11332 vam->is_ipv6 = ipv6_set;
11333
11334 M (IP_ADDRESS_DUMP, ip_address_dump);
11335 mp->sw_if_index = ntohl (sw_if_index);
11336 mp->is_ipv6 = ipv6_set;
11337 S;
11338
11339 /* Use a control ping for synchronization */
11340 {
11341 vl_api_control_ping_t *mp;
11342 M (CONTROL_PING, control_ping);
11343 S;
11344 }
11345 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011346}
11347
11348static int
11349api_ip_dump (vat_main_t * vam)
11350{
Dave Barach72d72232016-08-04 10:15:08 -040011351 vl_api_ip_dump_t *mp;
11352 unformat_input_t *in = vam->input;
11353 int ipv4_set = 0;
11354 int ipv6_set = 0;
11355 int is_ipv6;
11356 f64 timeout;
11357 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011358
Dave Barach72d72232016-08-04 10:15:08 -040011359 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011360 {
Dave Barach72d72232016-08-04 10:15:08 -040011361 if (unformat (in, "ipv4"))
11362 ipv4_set = 1;
11363 else if (unformat (in, "ipv6"))
11364 ipv6_set = 1;
11365 else
11366 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011367 }
Dave Barach72d72232016-08-04 10:15:08 -040011368
11369 if (ipv4_set && ipv6_set)
11370 {
11371 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11372 return -99;
11373 }
11374
11375 if ((!ipv4_set) && (!ipv6_set))
11376 {
11377 errmsg ("no ipv4 nor ipv6 flag set\n");
11378 return -99;
11379 }
11380
11381 is_ipv6 = ipv6_set;
11382 vam->is_ipv6 = is_ipv6;
11383
11384 /* free old data */
11385 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11386 {
11387 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11388 }
11389 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11390
11391 M (IP_DUMP, ip_dump);
11392 mp->is_ipv6 = ipv6_set;
11393 S;
11394
11395 /* Use a control ping for synchronization */
11396 {
11397 vl_api_control_ping_t *mp;
11398 M (CONTROL_PING, control_ping);
11399 S;
11400 }
11401 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011402}
11403
11404static int
11405api_ipsec_spd_add_del (vat_main_t * vam)
11406{
Dave Barach72d72232016-08-04 10:15:08 -040011407 unformat_input_t *i = vam->input;
11408 vl_api_ipsec_spd_add_del_t *mp;
11409 f64 timeout;
11410 u32 spd_id = ~0;
11411 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011412
Dave Barach72d72232016-08-04 10:15:08 -040011413 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11414 {
11415 if (unformat (i, "spd_id %d", &spd_id))
11416 ;
11417 else if (unformat (i, "del"))
11418 is_add = 0;
11419 else
11420 {
11421 clib_warning ("parse error '%U'", format_unformat_error, i);
11422 return -99;
11423 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011424 }
Dave Barach72d72232016-08-04 10:15:08 -040011425 if (spd_id == ~0)
11426 {
11427 errmsg ("spd_id must be set\n");
11428 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011429 }
11430
Dave Barach72d72232016-08-04 10:15:08 -040011431 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011432
Dave Barach72d72232016-08-04 10:15:08 -040011433 mp->spd_id = ntohl (spd_id);
11434 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011435
Dave Barach72d72232016-08-04 10:15:08 -040011436 S;
11437 W;
11438 /* NOTREACHED */
11439 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011440}
11441
11442static int
11443api_ipsec_interface_add_del_spd (vat_main_t * vam)
11444{
Dave Barach72d72232016-08-04 10:15:08 -040011445 unformat_input_t *i = vam->input;
11446 vl_api_ipsec_interface_add_del_spd_t *mp;
11447 f64 timeout;
11448 u32 sw_if_index;
11449 u8 sw_if_index_set = 0;
11450 u32 spd_id = (u32) ~ 0;
11451 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011452
Dave Barach72d72232016-08-04 10:15:08 -040011453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11454 {
11455 if (unformat (i, "del"))
11456 is_add = 0;
11457 else if (unformat (i, "spd_id %d", &spd_id))
11458 ;
11459 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11460 sw_if_index_set = 1;
11461 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11462 sw_if_index_set = 1;
11463 else
11464 {
11465 clib_warning ("parse error '%U'", format_unformat_error, i);
11466 return -99;
11467 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011468
11469 }
11470
Dave Barach72d72232016-08-04 10:15:08 -040011471 if (spd_id == (u32) ~ 0)
11472 {
11473 errmsg ("spd_id must be set\n");
11474 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011475 }
11476
Dave Barach72d72232016-08-04 10:15:08 -040011477 if (sw_if_index_set == 0)
11478 {
11479 errmsg ("missing interface name or sw_if_index\n");
11480 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011481 }
11482
Dave Barach72d72232016-08-04 10:15:08 -040011483 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011484
Dave Barach72d72232016-08-04 10:15:08 -040011485 mp->spd_id = ntohl (spd_id);
11486 mp->sw_if_index = ntohl (sw_if_index);
11487 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011488
Dave Barach72d72232016-08-04 10:15:08 -040011489 S;
11490 W;
11491 /* NOTREACHED */
11492 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011493}
11494
11495static int
11496api_ipsec_spd_add_del_entry (vat_main_t * vam)
11497{
Dave Barach72d72232016-08-04 10:15:08 -040011498 unformat_input_t *i = vam->input;
11499 vl_api_ipsec_spd_add_del_entry_t *mp;
11500 f64 timeout;
11501 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011502 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011503 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011504 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11505 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11506 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11507 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011508
Dave Barach72d72232016-08-04 10:15:08 -040011509 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11510 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11511 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11512 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11513 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11514 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011515
Dave Barach72d72232016-08-04 10:15:08 -040011516 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11517 {
11518 if (unformat (i, "del"))
11519 is_add = 0;
11520 if (unformat (i, "outbound"))
11521 is_outbound = 1;
11522 if (unformat (i, "inbound"))
11523 is_outbound = 0;
11524 else if (unformat (i, "spd_id %d", &spd_id))
11525 ;
11526 else if (unformat (i, "sa_id %d", &sa_id))
11527 ;
11528 else if (unformat (i, "priority %d", &priority))
11529 ;
11530 else if (unformat (i, "protocol %d", &protocol))
11531 ;
11532 else if (unformat (i, "lport_start %d", &lport_start))
11533 ;
11534 else if (unformat (i, "lport_stop %d", &lport_stop))
11535 ;
11536 else if (unformat (i, "rport_start %d", &rport_start))
11537 ;
11538 else if (unformat (i, "rport_stop %d", &rport_stop))
11539 ;
11540 else
11541 if (unformat
11542 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11543 {
11544 is_ipv6 = 0;
11545 is_ip_any = 0;
11546 }
11547 else
11548 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11549 {
11550 is_ipv6 = 0;
11551 is_ip_any = 0;
11552 }
11553 else
11554 if (unformat
11555 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11556 {
11557 is_ipv6 = 0;
11558 is_ip_any = 0;
11559 }
11560 else
11561 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11562 {
11563 is_ipv6 = 0;
11564 is_ip_any = 0;
11565 }
11566 else
11567 if (unformat
11568 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11569 {
11570 is_ipv6 = 1;
11571 is_ip_any = 0;
11572 }
11573 else
11574 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11575 {
11576 is_ipv6 = 1;
11577 is_ip_any = 0;
11578 }
11579 else
11580 if (unformat
11581 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11582 {
11583 is_ipv6 = 1;
11584 is_ip_any = 0;
11585 }
11586 else
11587 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11588 {
11589 is_ipv6 = 1;
11590 is_ip_any = 0;
11591 }
11592 else
11593 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11594 {
11595 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11596 {
11597 clib_warning ("unsupported action: 'resolve'");
11598 return -99;
11599 }
11600 }
11601 else
11602 {
11603 clib_warning ("parse error '%U'", format_unformat_error, i);
11604 return -99;
11605 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011606
11607 }
11608
Dave Barach72d72232016-08-04 10:15:08 -040011609 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011610
Dave Barach72d72232016-08-04 10:15:08 -040011611 mp->spd_id = ntohl (spd_id);
11612 mp->priority = ntohl (priority);
11613 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011614
Dave Barach72d72232016-08-04 10:15:08 -040011615 mp->is_ipv6 = is_ipv6;
11616 if (is_ipv6 || is_ip_any)
11617 {
11618 clib_memcpy (mp->remote_address_start, &raddr6_start,
11619 sizeof (ip6_address_t));
11620 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11621 sizeof (ip6_address_t));
11622 clib_memcpy (mp->local_address_start, &laddr6_start,
11623 sizeof (ip6_address_t));
11624 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11625 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011626 }
Dave Barach72d72232016-08-04 10:15:08 -040011627 else
11628 {
11629 clib_memcpy (mp->remote_address_start, &raddr4_start,
11630 sizeof (ip4_address_t));
11631 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11632 sizeof (ip4_address_t));
11633 clib_memcpy (mp->local_address_start, &laddr4_start,
11634 sizeof (ip4_address_t));
11635 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11636 sizeof (ip4_address_t));
11637 }
11638 mp->protocol = (u8) protocol;
11639 mp->local_port_start = ntohs ((u16) lport_start);
11640 mp->local_port_stop = ntohs ((u16) lport_stop);
11641 mp->remote_port_start = ntohs ((u16) rport_start);
11642 mp->remote_port_stop = ntohs ((u16) rport_stop);
11643 mp->policy = (u8) policy;
11644 mp->sa_id = ntohl (sa_id);
11645 mp->is_add = is_add;
11646 mp->is_ip_any = is_ip_any;
11647 S;
11648 W;
11649 /* NOTREACHED */
11650 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011651}
11652
11653static int
11654api_ipsec_sad_add_del_entry (vat_main_t * vam)
11655{
Dave Barach72d72232016-08-04 10:15:08 -040011656 unformat_input_t *i = vam->input;
11657 vl_api_ipsec_sad_add_del_entry_t *mp;
11658 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011659 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011660 u8 *ck = 0, *ik = 0;
11661 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011662
Dave Barach72d72232016-08-04 10:15:08 -040011663 u8 protocol = IPSEC_PROTOCOL_AH;
11664 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11665 u32 crypto_alg = 0, integ_alg = 0;
11666 ip4_address_t tun_src4;
11667 ip4_address_t tun_dst4;
11668 ip6_address_t tun_src6;
11669 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011670
Dave Barach72d72232016-08-04 10:15:08 -040011671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11672 {
11673 if (unformat (i, "del"))
11674 is_add = 0;
11675 else if (unformat (i, "sad_id %d", &sad_id))
11676 ;
11677 else if (unformat (i, "spi %d", &spi))
11678 ;
11679 else if (unformat (i, "esp"))
11680 protocol = IPSEC_PROTOCOL_ESP;
11681 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11682 {
11683 is_tunnel = 1;
11684 is_tunnel_ipv6 = 0;
11685 }
11686 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11687 {
11688 is_tunnel = 1;
11689 is_tunnel_ipv6 = 0;
11690 }
11691 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11692 {
11693 is_tunnel = 1;
11694 is_tunnel_ipv6 = 1;
11695 }
11696 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11697 {
11698 is_tunnel = 1;
11699 is_tunnel_ipv6 = 1;
11700 }
11701 else
11702 if (unformat
11703 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11704 {
11705 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011706 crypto_alg >= IPSEC_CRYPTO_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011707 {
11708 clib_warning ("unsupported crypto-alg: '%U'",
11709 format_ipsec_crypto_alg, crypto_alg);
11710 return -99;
11711 }
11712 }
11713 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11714 ;
11715 else
11716 if (unformat
11717 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11718 {
Radu Nicolau6929ea92016-11-29 11:00:30 +000011719#if DPDK_CRYPTO==1
11720 if (integ_alg < IPSEC_INTEG_ALG_NONE ||
11721#else
Dave Barach72d72232016-08-04 10:15:08 -040011722 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011723#endif
11724 integ_alg >= IPSEC_INTEG_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011725 {
11726 clib_warning ("unsupported integ-alg: '%U'",
11727 format_ipsec_integ_alg, integ_alg);
11728 return -99;
11729 }
11730 }
11731 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11732 ;
11733 else
11734 {
11735 clib_warning ("parse error '%U'", format_unformat_error, i);
11736 return -99;
11737 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011738
11739 }
11740
Radu Nicolau6929ea92016-11-29 11:00:30 +000011741#if DPDK_CRYPTO==1
11742 /*Special cases, aes-gcm-128 encryption */
11743 if (crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
11744 {
11745 if (integ_alg != IPSEC_INTEG_ALG_NONE
11746 && integ_alg != IPSEC_INTEG_ALG_AES_GCM_128)
11747 {
11748 clib_warning
11749 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
11750 return -99;
11751 }
11752 else /*set integ-alg internally to aes-gcm-128 */
11753 integ_alg = IPSEC_INTEG_ALG_AES_GCM_128;
11754 }
11755 else if (integ_alg == IPSEC_INTEG_ALG_AES_GCM_128)
11756 {
11757 clib_warning ("unsupported integ-alg: aes-gcm-128");
11758 return -99;
11759 }
11760 else if (integ_alg == IPSEC_INTEG_ALG_NONE)
11761 {
11762 clib_warning ("unsupported integ-alg: none");
11763 return -99;
11764 }
11765#endif
11766
11767
Dave Barach72d72232016-08-04 10:15:08 -040011768 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011769
Dave Barach72d72232016-08-04 10:15:08 -040011770 mp->sad_id = ntohl (sad_id);
11771 mp->is_add = is_add;
11772 mp->protocol = protocol;
11773 mp->spi = ntohl (spi);
11774 mp->is_tunnel = is_tunnel;
11775 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11776 mp->crypto_algorithm = crypto_alg;
11777 mp->integrity_algorithm = integ_alg;
11778 mp->crypto_key_length = vec_len (ck);
11779 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011780
Dave Barach72d72232016-08-04 10:15:08 -040011781 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11782 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011783
Dave Barach72d72232016-08-04 10:15:08 -040011784 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11785 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011786
Dave Barach839fe3e2016-08-10 11:35:54 -040011787 if (ck)
11788 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11789 if (ik)
11790 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011791
Dave Barach72d72232016-08-04 10:15:08 -040011792 if (is_tunnel)
11793 {
11794 if (is_tunnel_ipv6)
11795 {
11796 clib_memcpy (mp->tunnel_src_address, &tun_src6,
11797 sizeof (ip6_address_t));
11798 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
11799 sizeof (ip6_address_t));
11800 }
11801 else
11802 {
11803 clib_memcpy (mp->tunnel_src_address, &tun_src4,
11804 sizeof (ip4_address_t));
11805 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
11806 sizeof (ip4_address_t));
11807 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011808 }
11809
Dave Barach72d72232016-08-04 10:15:08 -040011810 S;
11811 W;
11812 /* NOTREACHED */
11813 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011814}
11815
11816static int
11817api_ipsec_sa_set_key (vat_main_t * vam)
11818{
Dave Barach72d72232016-08-04 10:15:08 -040011819 unformat_input_t *i = vam->input;
11820 vl_api_ipsec_sa_set_key_t *mp;
11821 f64 timeout;
11822 u32 sa_id;
11823 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011824
Dave Barach72d72232016-08-04 10:15:08 -040011825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11826 {
11827 if (unformat (i, "sa_id %d", &sa_id))
11828 ;
11829 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11830 ;
11831 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11832 ;
11833 else
11834 {
11835 clib_warning ("parse error '%U'", format_unformat_error, i);
11836 return -99;
11837 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011838 }
11839
Dave Barach72d72232016-08-04 10:15:08 -040011840 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011841
Dave Barach72d72232016-08-04 10:15:08 -040011842 mp->sa_id = ntohl (sa_id);
11843 mp->crypto_key_length = vec_len (ck);
11844 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011845
Dave Barach72d72232016-08-04 10:15:08 -040011846 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11847 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011848
Dave Barach72d72232016-08-04 10:15:08 -040011849 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11850 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011851
Dave Barach839fe3e2016-08-10 11:35:54 -040011852 if (ck)
11853 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11854 if (ik)
11855 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011856
Dave Barach72d72232016-08-04 10:15:08 -040011857 S;
11858 W;
11859 /* NOTREACHED */
11860 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011861}
11862
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011863static int
11864api_ikev2_profile_add_del (vat_main_t * vam)
11865{
Dave Barach72d72232016-08-04 10:15:08 -040011866 unformat_input_t *i = vam->input;
11867 vl_api_ikev2_profile_add_del_t *mp;
11868 f64 timeout;
11869 u8 is_add = 1;
11870 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011871
Dave Barach72d72232016-08-04 10:15:08 -040011872 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011873
Dave Barach72d72232016-08-04 10:15:08 -040011874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11875 {
11876 if (unformat (i, "del"))
11877 is_add = 0;
11878 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11879 vec_add1 (name, 0);
11880 else
11881 {
11882 errmsg ("parse error '%U'", format_unformat_error, i);
11883 return -99;
11884 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011885 }
11886
Dave Barach72d72232016-08-04 10:15:08 -040011887 if (!vec_len (name))
11888 {
11889 errmsg ("profile name must be specified");
11890 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011891 }
11892
Dave Barach72d72232016-08-04 10:15:08 -040011893 if (vec_len (name) > 64)
11894 {
11895 errmsg ("profile name too long");
11896 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011897 }
11898
Dave Barach72d72232016-08-04 10:15:08 -040011899 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011900
Dave Barach72d72232016-08-04 10:15:08 -040011901 clib_memcpy (mp->name, name, vec_len (name));
11902 mp->is_add = is_add;
11903 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011904
Dave Barach72d72232016-08-04 10:15:08 -040011905 S;
11906 W;
11907 /* NOTREACHED */
11908 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011909}
11910
11911static int
11912api_ikev2_profile_set_auth (vat_main_t * vam)
11913{
Dave Barach72d72232016-08-04 10:15:08 -040011914 unformat_input_t *i = vam->input;
11915 vl_api_ikev2_profile_set_auth_t *mp;
11916 f64 timeout;
11917 u8 *name = 0;
11918 u8 *data = 0;
11919 u32 auth_method = 0;
11920 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011921
Dave Barach72d72232016-08-04 10:15:08 -040011922 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011923
Dave Barach72d72232016-08-04 10:15:08 -040011924 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11925 {
11926 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11927 vec_add1 (name, 0);
11928 else if (unformat (i, "auth_method %U",
11929 unformat_ikev2_auth_method, &auth_method))
11930 ;
11931 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
11932 is_hex = 1;
11933 else if (unformat (i, "auth_data %v", &data))
11934 ;
11935 else
11936 {
11937 errmsg ("parse error '%U'", format_unformat_error, i);
11938 return -99;
11939 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011940 }
11941
Dave Barach72d72232016-08-04 10:15:08 -040011942 if (!vec_len (name))
11943 {
11944 errmsg ("profile name must be specified");
11945 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011946 }
11947
Dave Barach72d72232016-08-04 10:15:08 -040011948 if (vec_len (name) > 64)
11949 {
11950 errmsg ("profile name too long");
11951 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011952 }
11953
Dave Barach72d72232016-08-04 10:15:08 -040011954 if (!vec_len (data))
11955 {
11956 errmsg ("auth_data must be specified");
11957 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011958 }
11959
Dave Barach72d72232016-08-04 10:15:08 -040011960 if (!auth_method)
11961 {
11962 errmsg ("auth_method must be specified");
11963 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011964 }
11965
Dave Barach72d72232016-08-04 10:15:08 -040011966 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011967
Dave Barach72d72232016-08-04 10:15:08 -040011968 mp->is_hex = is_hex;
11969 mp->auth_method = (u8) auth_method;
11970 mp->data_len = vec_len (data);
11971 clib_memcpy (mp->name, name, vec_len (name));
11972 clib_memcpy (mp->data, data, vec_len (data));
11973 vec_free (name);
11974 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011975
Dave Barach72d72232016-08-04 10:15:08 -040011976 S;
11977 W;
11978 /* NOTREACHED */
11979 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011980}
11981
11982static int
11983api_ikev2_profile_set_id (vat_main_t * vam)
11984{
Dave Barach72d72232016-08-04 10:15:08 -040011985 unformat_input_t *i = vam->input;
11986 vl_api_ikev2_profile_set_id_t *mp;
11987 f64 timeout;
11988 u8 *name = 0;
11989 u8 *data = 0;
11990 u8 is_local = 0;
11991 u32 id_type = 0;
11992 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011993
Dave Barach72d72232016-08-04 10:15:08 -040011994 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020011995
Dave Barach72d72232016-08-04 10:15:08 -040011996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11997 {
11998 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
11999 vec_add1 (name, 0);
12000 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
12001 ;
12002 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
12003 {
12004 data = vec_new (u8, 4);
12005 clib_memcpy (data, ip4.as_u8, 4);
12006 }
12007 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
12008 ;
12009 else if (unformat (i, "id_data %v", &data))
12010 ;
12011 else if (unformat (i, "local"))
12012 is_local = 1;
12013 else if (unformat (i, "remote"))
12014 is_local = 0;
12015 else
12016 {
12017 errmsg ("parse error '%U'", format_unformat_error, i);
12018 return -99;
12019 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012020 }
12021
Dave Barach72d72232016-08-04 10:15:08 -040012022 if (!vec_len (name))
12023 {
12024 errmsg ("profile name must be specified");
12025 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012026 }
12027
Dave Barach72d72232016-08-04 10:15:08 -040012028 if (vec_len (name) > 64)
12029 {
12030 errmsg ("profile name too long");
12031 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012032 }
12033
Dave Barach72d72232016-08-04 10:15:08 -040012034 if (!vec_len (data))
12035 {
12036 errmsg ("id_data must be specified");
12037 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012038 }
12039
Dave Barach72d72232016-08-04 10:15:08 -040012040 if (!id_type)
12041 {
12042 errmsg ("id_type must be specified");
12043 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012044 }
12045
Dave Barach72d72232016-08-04 10:15:08 -040012046 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012047
Dave Barach72d72232016-08-04 10:15:08 -040012048 mp->is_local = is_local;
12049 mp->id_type = (u8) id_type;
12050 mp->data_len = vec_len (data);
12051 clib_memcpy (mp->name, name, vec_len (name));
12052 clib_memcpy (mp->data, data, vec_len (data));
12053 vec_free (name);
12054 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012055
Dave Barach72d72232016-08-04 10:15:08 -040012056 S;
12057 W;
12058 /* NOTREACHED */
12059 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012060}
12061
12062static int
12063api_ikev2_profile_set_ts (vat_main_t * vam)
12064{
Dave Barach72d72232016-08-04 10:15:08 -040012065 unformat_input_t *i = vam->input;
12066 vl_api_ikev2_profile_set_ts_t *mp;
12067 f64 timeout;
12068 u8 *name = 0;
12069 u8 is_local = 0;
12070 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12071 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012072
Dave Barach72d72232016-08-04 10:15:08 -040012073 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012074
Dave Barach72d72232016-08-04 10:15:08 -040012075 start_addr.as_u32 = 0;
12076 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012077
Dave Barach72d72232016-08-04 10:15:08 -040012078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12079 {
12080 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12081 vec_add1 (name, 0);
12082 else if (unformat (i, "protocol %d", &proto))
12083 ;
12084 else if (unformat (i, "start_port %d", &start_port))
12085 ;
12086 else if (unformat (i, "end_port %d", &end_port))
12087 ;
12088 else
12089 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12090 ;
12091 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12092 ;
12093 else if (unformat (i, "local"))
12094 is_local = 1;
12095 else if (unformat (i, "remote"))
12096 is_local = 0;
12097 else
12098 {
12099 errmsg ("parse error '%U'", format_unformat_error, i);
12100 return -99;
12101 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012102 }
12103
Dave Barach72d72232016-08-04 10:15:08 -040012104 if (!vec_len (name))
12105 {
12106 errmsg ("profile name must be specified");
12107 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012108 }
12109
Dave Barach72d72232016-08-04 10:15:08 -040012110 if (vec_len (name) > 64)
12111 {
12112 errmsg ("profile name too long");
12113 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012114 }
12115
Dave Barach72d72232016-08-04 10:15:08 -040012116 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012117
Dave Barach72d72232016-08-04 10:15:08 -040012118 mp->is_local = is_local;
12119 mp->proto = (u8) proto;
12120 mp->start_port = (u16) start_port;
12121 mp->end_port = (u16) end_port;
12122 mp->start_addr = start_addr.as_u32;
12123 mp->end_addr = end_addr.as_u32;
12124 clib_memcpy (mp->name, name, vec_len (name));
12125 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012126
Dave Barach72d72232016-08-04 10:15:08 -040012127 S;
12128 W;
12129 /* NOTREACHED */
12130 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012131}
12132
12133static int
12134api_ikev2_set_local_key (vat_main_t * vam)
12135{
Dave Barach72d72232016-08-04 10:15:08 -040012136 unformat_input_t *i = vam->input;
12137 vl_api_ikev2_set_local_key_t *mp;
12138 f64 timeout;
12139 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012140
Dave Barach72d72232016-08-04 10:15:08 -040012141 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12142 {
12143 if (unformat (i, "file %v", &file))
12144 vec_add1 (file, 0);
12145 else
12146 {
12147 errmsg ("parse error '%U'", format_unformat_error, i);
12148 return -99;
12149 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012150 }
12151
Dave Barach72d72232016-08-04 10:15:08 -040012152 if (!vec_len (file))
12153 {
12154 errmsg ("RSA key file must be specified");
12155 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012156 }
12157
Dave Barach72d72232016-08-04 10:15:08 -040012158 if (vec_len (file) > 256)
12159 {
12160 errmsg ("file name too long");
12161 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012162 }
12163
Dave Barach72d72232016-08-04 10:15:08 -040012164 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012165
Dave Barach72d72232016-08-04 10:15:08 -040012166 clib_memcpy (mp->key_file, file, vec_len (file));
12167 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012168
Dave Barach72d72232016-08-04 10:15:08 -040012169 S;
12170 W;
12171 /* NOTREACHED */
12172 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012173}
12174
Ed Warnickecb9cada2015-12-08 15:45:58 -070012175/*
12176 * MAP
12177 */
Dave Barach72d72232016-08-04 10:15:08 -040012178static int
12179api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012180{
12181 unformat_input_t *i = vam->input;
12182 vl_api_map_add_domain_t *mp;
12183 f64 timeout;
12184
12185 ip4_address_t ip4_prefix;
12186 ip6_address_t ip6_prefix;
12187 ip6_address_t ip6_src;
12188 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012189 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12190 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012191 u8 is_translation = 0;
12192 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012193 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012194
Dave Barach72d72232016-08-04 10:15:08 -040012195 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12196 {
12197 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12198 &ip4_prefix, &ip4_prefix_len))
12199 num_m_args++;
12200 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12201 &ip6_prefix, &ip6_prefix_len))
12202 num_m_args++;
12203 else
12204 if (unformat
12205 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12206 &ip6_src_len))
12207 num_m_args++;
12208 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12209 num_m_args++;
12210 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12211 num_m_args++;
12212 else if (unformat (i, "psid-offset %d", &psid_offset))
12213 num_m_args++;
12214 else if (unformat (i, "psid-len %d", &psid_length))
12215 num_m_args++;
12216 else if (unformat (i, "mtu %d", &mtu))
12217 num_m_args++;
12218 else if (unformat (i, "map-t"))
12219 is_translation = 1;
12220 else
12221 {
12222 clib_warning ("parse error '%U'", format_unformat_error, i);
12223 return -99;
12224 }
12225 }
12226
Ole Troan07e7eab2016-08-25 00:24:08 +020012227 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012228 {
12229 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012230 return -99;
12231 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012232
12233 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012234 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012235
Dave Barach72d72232016-08-04 10:15:08 -040012236 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012237 mp->ip4_prefix_len = ip4_prefix_len;
12238
Dave Barach72d72232016-08-04 10:15:08 -040012239 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012240 mp->ip6_prefix_len = ip6_prefix_len;
12241
Dave Barach72d72232016-08-04 10:15:08 -040012242 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012243 mp->ip6_src_prefix_len = ip6_src_len;
12244
12245 mp->ea_bits_len = ea_bits_len;
12246 mp->psid_offset = psid_offset;
12247 mp->psid_length = psid_length;
12248 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012249 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012250
12251 /* send it... */
12252 S;
12253
12254 /* Wait for a reply, return good/bad news */
12255 W;
12256}
12257
Dave Barach72d72232016-08-04 10:15:08 -040012258static int
12259api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012260{
12261 unformat_input_t *i = vam->input;
12262 vl_api_map_del_domain_t *mp;
12263 f64 timeout;
12264
12265 u32 num_m_args = 0;
12266 u32 index;
12267
Dave Barach72d72232016-08-04 10:15:08 -040012268 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12269 {
12270 if (unformat (i, "index %d", &index))
12271 num_m_args++;
12272 else
12273 {
12274 clib_warning ("parse error '%U'", format_unformat_error, i);
12275 return -99;
12276 }
12277 }
12278
12279 if (num_m_args != 1)
12280 {
12281 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012282 return -99;
12283 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012284
12285 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012286 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012287
Dave Barach72d72232016-08-04 10:15:08 -040012288 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012289
12290 /* send it... */
12291 S;
12292
12293 /* Wait for a reply, return good/bad news */
12294 W;
12295}
12296
Dave Barach72d72232016-08-04 10:15:08 -040012297static int
12298api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012299{
12300 unformat_input_t *i = vam->input;
12301 vl_api_map_add_del_rule_t *mp;
12302 f64 timeout;
12303 u8 is_add = 1;
12304 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012305 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012306
Dave Barach72d72232016-08-04 10:15:08 -040012307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12308 {
12309 if (unformat (i, "index %d", &index))
12310 num_m_args++;
12311 else if (unformat (i, "psid %d", &psid))
12312 num_m_args++;
12313 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12314 num_m_args++;
12315 else if (unformat (i, "del"))
12316 {
12317 is_add = 0;
12318 }
12319 else
12320 {
12321 clib_warning ("parse error '%U'", format_unformat_error, i);
12322 return -99;
12323 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012324 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012325
12326 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012327 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012328
Dave Barach72d72232016-08-04 10:15:08 -040012329 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012330 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012331 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12332 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012333
12334 /* send it... */
12335 S;
12336
12337 /* Wait for a reply, return good/bad news */
12338 W;
12339}
12340
Dave Barach72d72232016-08-04 10:15:08 -040012341static int
12342api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012343{
Dave Barach72d72232016-08-04 10:15:08 -040012344 vl_api_map_domain_dump_t *mp;
12345 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012346
Dave Barach72d72232016-08-04 10:15:08 -040012347 /* Construct the API message */
12348 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012349
Dave Barach72d72232016-08-04 10:15:08 -040012350 /* send it... */
12351 S;
12352
12353 /* Use a control ping for synchronization */
12354 {
12355 vl_api_control_ping_t *mp;
12356 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012357 S;
Dave Barach72d72232016-08-04 10:15:08 -040012358 }
12359 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012360}
12361
Dave Barach72d72232016-08-04 10:15:08 -040012362static int
12363api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012364{
Dave Barach72d72232016-08-04 10:15:08 -040012365 unformat_input_t *i = vam->input;
12366 vl_api_map_rule_dump_t *mp;
12367 f64 timeout;
12368 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012369
Dave Barach72d72232016-08-04 10:15:08 -040012370 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012371 {
Dave Barach72d72232016-08-04 10:15:08 -040012372 if (unformat (i, "index %u", &domain_index))
12373 ;
12374 else
12375 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012376 }
Dave Barach72d72232016-08-04 10:15:08 -040012377
12378 if (domain_index == ~0)
12379 {
12380 clib_warning ("parse error: domain index expected");
12381 return -99;
12382 }
12383
12384 /* Construct the API message */
12385 M (MAP_RULE_DUMP, map_rule_dump);
12386
12387 mp->domain_index = htonl (domain_index);
12388
12389 /* send it... */
12390 S;
12391
12392 /* Use a control ping for synchronization */
12393 {
12394 vl_api_control_ping_t *mp;
12395 M (CONTROL_PING, control_ping);
12396 S;
12397 }
12398 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012399}
12400
12401static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012402 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012403{
Dave Barach72d72232016-08-04 10:15:08 -040012404 vat_main_t *vam = &vat_main;
12405 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012406
Dave Barach72d72232016-08-04 10:15:08 -040012407 if (vam->async_mode)
12408 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012409 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012410 }
12411 else
12412 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012413 vam->retval = retval;
12414 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012415 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012416}
12417
12418static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012419 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012420{
Dave Barach72d72232016-08-04 10:15:08 -040012421 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012422 vat_json_node_t node;
12423
Dave Barach72d72232016-08-04 10:15:08 -040012424 vat_json_init_object (&node);
12425 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12426 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012427
Dave Barach72d72232016-08-04 10:15:08 -040012428 vat_json_print (vam->ofp, &node);
12429 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012430
Dave Barach72d72232016-08-04 10:15:08 -040012431 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012432 vam->result_ready = 1;
12433}
12434
12435static int
12436api_get_first_msg_id (vat_main_t * vam)
12437{
Dave Barach72d72232016-08-04 10:15:08 -040012438 vl_api_get_first_msg_id_t *mp;
12439 f64 timeout;
12440 unformat_input_t *i = vam->input;
12441 u8 *name;
12442 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012443
Dave Barach72d72232016-08-04 10:15:08 -040012444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12445 {
12446 if (unformat (i, "client %s", &name))
12447 name_set = 1;
12448 else
12449 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012450 }
12451
Dave Barach72d72232016-08-04 10:15:08 -040012452 if (name_set == 0)
12453 {
12454 errmsg ("missing client name\n");
12455 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012456 }
Dave Barach72d72232016-08-04 10:15:08 -040012457 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012458
Dave Barach72d72232016-08-04 10:15:08 -040012459 if (vec_len (name) > 63)
12460 {
12461 errmsg ("client name too long\n");
12462 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012463 }
12464
Dave Barach72d72232016-08-04 10:15:08 -040012465 M (GET_FIRST_MSG_ID, get_first_msg_id);
12466 clib_memcpy (mp->name, name, vec_len (name));
12467 S;
12468 W;
12469 /* NOTREACHED */
12470 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012471}
12472
Dave Barach72d72232016-08-04 10:15:08 -040012473static int
12474api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012475{
Dave Barach72d72232016-08-04 10:15:08 -040012476 unformat_input_t *line_input = vam->input;
12477 vl_api_cop_interface_enable_disable_t *mp;
12478 f64 timeout;
12479 u32 sw_if_index = ~0;
12480 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012481
Dave Barach72d72232016-08-04 10:15:08 -040012482 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12483 {
12484 if (unformat (line_input, "disable"))
12485 enable_disable = 0;
12486 if (unformat (line_input, "enable"))
12487 enable_disable = 1;
12488 else if (unformat (line_input, "%U", unformat_sw_if_index,
12489 vam, &sw_if_index))
12490 ;
12491 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12492 ;
12493 else
12494 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012495 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012496
Dave Barach72d72232016-08-04 10:15:08 -040012497 if (sw_if_index == ~0)
12498 {
12499 errmsg ("missing interface name or sw_if_index\n");
12500 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012501 }
12502
Dave Barach72d72232016-08-04 10:15:08 -040012503 /* Construct the API message */
12504 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12505 mp->sw_if_index = ntohl (sw_if_index);
12506 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012507
Dave Barach72d72232016-08-04 10:15:08 -040012508 /* send it... */
12509 S;
12510 /* Wait for the reply */
12511 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012512}
12513
Dave Barach72d72232016-08-04 10:15:08 -040012514static int
12515api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012516{
Dave Barach72d72232016-08-04 10:15:08 -040012517 unformat_input_t *line_input = vam->input;
12518 vl_api_cop_whitelist_enable_disable_t *mp;
12519 f64 timeout;
12520 u32 sw_if_index = ~0;
12521 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012522 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012523
Dave Barach72d72232016-08-04 10:15:08 -040012524 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12525 {
12526 if (unformat (line_input, "ip4"))
12527 ip4 = 1;
12528 else if (unformat (line_input, "ip6"))
12529 ip6 = 1;
12530 else if (unformat (line_input, "default"))
12531 default_cop = 1;
12532 else if (unformat (line_input, "%U", unformat_sw_if_index,
12533 vam, &sw_if_index))
12534 ;
12535 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12536 ;
12537 else if (unformat (line_input, "fib-id %d", &fib_id))
12538 ;
12539 else
12540 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012541 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012542
Dave Barach72d72232016-08-04 10:15:08 -040012543 if (sw_if_index == ~0)
12544 {
12545 errmsg ("missing interface name or sw_if_index\n");
12546 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012547 }
12548
Dave Barach72d72232016-08-04 10:15:08 -040012549 /* Construct the API message */
12550 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12551 mp->sw_if_index = ntohl (sw_if_index);
12552 mp->fib_id = ntohl (fib_id);
12553 mp->ip4 = ip4;
12554 mp->ip6 = ip6;
12555 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012556
Dave Barach72d72232016-08-04 10:15:08 -040012557 /* send it... */
12558 S;
12559 /* Wait for the reply */
12560 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012561}
12562
Dave Barach72d72232016-08-04 10:15:08 -040012563static int
12564api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012565{
Dave Barach72d72232016-08-04 10:15:08 -040012566 vl_api_get_node_graph_t *mp;
12567 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012568
Dave Barach72d72232016-08-04 10:15:08 -040012569 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012570
Dave Barach72d72232016-08-04 10:15:08 -040012571 /* send it... */
12572 S;
12573 /* Wait for the reply */
12574 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012575}
12576
Dave Barach72d72232016-08-04 10:15:08 -040012577/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012578/** Used for parsing LISP eids */
12579typedef CLIB_PACKED(struct{
12580 u8 addr[16]; /**< eid address */
12581 u32 len; /**< prefix length if IP */
12582 u8 type; /**< type of eid */
12583}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012584/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012585
12586static uword
12587unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12588{
Dave Barach72d72232016-08-04 10:15:08 -040012589 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012590
Dave Barach72d72232016-08-04 10:15:08 -040012591 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012592
Dave Barach72d72232016-08-04 10:15:08 -040012593 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12594 {
12595 a->type = 0; /* ipv4 type */
12596 }
12597 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12598 {
12599 a->type = 1; /* ipv6 type */
12600 }
12601 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12602 {
12603 a->type = 2; /* mac type */
12604 }
12605 else
12606 {
Florin Coras429e7952016-08-02 02:31:03 +020012607 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012608 }
Florin Coras429e7952016-08-02 02:31:03 +020012609
Dave Barach72d72232016-08-04 10:15:08 -040012610 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12611 {
Florin Coras429e7952016-08-02 02:31:03 +020012612 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012613 }
Florin Coras429e7952016-08-02 02:31:03 +020012614
12615 return 1;
12616}
12617
12618static int
12619lisp_eid_size_vat (u8 type)
12620{
Dave Barach72d72232016-08-04 10:15:08 -040012621 switch (type)
12622 {
Florin Coras429e7952016-08-02 02:31:03 +020012623 case 0:
12624 return 4;
12625 case 1:
12626 return 16;
12627 case 2:
12628 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012629 }
Florin Coras429e7952016-08-02 02:31:03 +020012630 return 0;
12631}
12632
12633static void
12634lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12635{
Dave Barach72d72232016-08-04 10:15:08 -040012636 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012637}
12638
Dave Barach72d72232016-08-04 10:15:08 -040012639/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012640/** Used for transferring locators via VPP API */
12641typedef CLIB_PACKED(struct
12642{
Dave Barach72d72232016-08-04 10:15:08 -040012643 u32 sw_if_index; /**< locator sw_if_index */
12644 u8 priority; /**< locator priority */
12645 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012646}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012647/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012648
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012649static int
Dave Barach72d72232016-08-04 10:15:08 -040012650api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012651{
Dave Barach72d72232016-08-04 10:15:08 -040012652 unformat_input_t *input = vam->input;
12653 vl_api_lisp_add_del_locator_set_t *mp;
12654 f64 timeout = ~0;
12655 u8 is_add = 1;
12656 u8 *locator_set_name = NULL;
12657 u8 locator_set_name_set = 0;
12658 ls_locator_t locator, *locators = 0;
12659 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012660 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012661
Dave Barach72d72232016-08-04 10:15:08 -040012662 /* Parse args required to build the message */
12663 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12664 {
12665 if (unformat (input, "del"))
12666 {
12667 is_add = 0;
12668 }
12669 else if (unformat (input, "locator-set %s", &locator_set_name))
12670 {
12671 locator_set_name_set = 1;
12672 }
12673 else if (unformat (input, "sw_if_index %u p %u w %u",
12674 &sw_if_index, &priority, &weight))
12675 {
12676 locator.sw_if_index = htonl (sw_if_index);
12677 locator.priority = priority;
12678 locator.weight = weight;
12679 vec_add1 (locators, locator);
12680 }
12681 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12682 vam, &sw_if_index, &priority, &weight))
12683 {
12684 locator.sw_if_index = htonl (sw_if_index);
12685 locator.priority = priority;
12686 locator.weight = weight;
12687 vec_add1 (locators, locator);
12688 }
12689 else
12690 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012691 }
12692
Dave Barach72d72232016-08-04 10:15:08 -040012693 if (locator_set_name_set == 0)
12694 {
12695 errmsg ("missing locator-set name");
12696 vec_free (locators);
12697 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012698 }
12699
Dave Barach72d72232016-08-04 10:15:08 -040012700 if (vec_len (locator_set_name) > 64)
12701 {
12702 errmsg ("locator-set name too long\n");
12703 vec_free (locator_set_name);
12704 vec_free (locators);
12705 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012706 }
Dave Barach72d72232016-08-04 10:15:08 -040012707 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012708
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012709 data_len = sizeof (ls_locator_t) * vec_len (locators);
12710
Dave Barach72d72232016-08-04 10:15:08 -040012711 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012712 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012713
Dave Barach72d72232016-08-04 10:15:08 -040012714 mp->is_add = is_add;
12715 clib_memcpy (mp->locator_set_name, locator_set_name,
12716 vec_len (locator_set_name));
12717 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012718
Filip Tehlare3552c42016-08-26 12:44:38 +020012719 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012720 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012721 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012722 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012723
Dave Barach72d72232016-08-04 10:15:08 -040012724 /* send it... */
12725 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012726
Dave Barach72d72232016-08-04 10:15:08 -040012727 /* Wait for a reply... */
12728 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012729
Dave Barach72d72232016-08-04 10:15:08 -040012730 /* NOTREACHED */
12731 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012732}
12733
12734static int
Dave Barach72d72232016-08-04 10:15:08 -040012735api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012736{
Dave Barach72d72232016-08-04 10:15:08 -040012737 unformat_input_t *input = vam->input;
12738 vl_api_lisp_add_del_locator_t *mp;
12739 f64 timeout = ~0;
12740 u32 tmp_if_index = ~0;
12741 u32 sw_if_index = ~0;
12742 u8 sw_if_index_set = 0;
12743 u8 sw_if_index_if_name_set = 0;
12744 u32 priority = ~0;
12745 u8 priority_set = 0;
12746 u32 weight = ~0;
12747 u8 weight_set = 0;
12748 u8 is_add = 1;
12749 u8 *locator_set_name = NULL;
12750 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012751
Dave Barach72d72232016-08-04 10:15:08 -040012752 /* Parse args required to build the message */
12753 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12754 {
12755 if (unformat (input, "del"))
12756 {
12757 is_add = 0;
12758 }
12759 else if (unformat (input, "locator-set %s", &locator_set_name))
12760 {
12761 locator_set_name_set = 1;
12762 }
12763 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12764 &tmp_if_index))
12765 {
12766 sw_if_index_if_name_set = 1;
12767 sw_if_index = tmp_if_index;
12768 }
12769 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12770 {
12771 sw_if_index_set = 1;
12772 sw_if_index = tmp_if_index;
12773 }
12774 else if (unformat (input, "p %d", &priority))
12775 {
12776 priority_set = 1;
12777 }
12778 else if (unformat (input, "w %d", &weight))
12779 {
12780 weight_set = 1;
12781 }
12782 else
12783 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012784 }
12785
Dave Barach72d72232016-08-04 10:15:08 -040012786 if (locator_set_name_set == 0)
12787 {
12788 errmsg ("missing locator-set name");
12789 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012790 }
12791
Dave Barach72d72232016-08-04 10:15:08 -040012792 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
12793 {
12794 errmsg ("missing sw_if_index");
12795 vec_free (locator_set_name);
12796 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012797 }
12798
Dave Barach72d72232016-08-04 10:15:08 -040012799 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
12800 {
12801 errmsg ("cannot use both params interface name and sw_if_index");
12802 vec_free (locator_set_name);
12803 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012804 }
12805
Dave Barach72d72232016-08-04 10:15:08 -040012806 if (priority_set == 0)
12807 {
12808 errmsg ("missing locator-set priority\n");
12809 vec_free (locator_set_name);
12810 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012811 }
12812
Dave Barach72d72232016-08-04 10:15:08 -040012813 if (weight_set == 0)
12814 {
12815 errmsg ("missing locator-set weight\n");
12816 vec_free (locator_set_name);
12817 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012818 }
12819
Dave Barach72d72232016-08-04 10:15:08 -040012820 if (vec_len (locator_set_name) > 64)
12821 {
12822 errmsg ("locator-set name too long\n");
12823 vec_free (locator_set_name);
12824 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012825 }
Dave Barach72d72232016-08-04 10:15:08 -040012826 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012827
Dave Barach72d72232016-08-04 10:15:08 -040012828 /* Construct the API message */
12829 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012830
Dave Barach72d72232016-08-04 10:15:08 -040012831 mp->is_add = is_add;
12832 mp->sw_if_index = ntohl (sw_if_index);
12833 mp->priority = priority;
12834 mp->weight = weight;
12835 clib_memcpy (mp->locator_set_name, locator_set_name,
12836 vec_len (locator_set_name));
12837 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012838
Dave Barach72d72232016-08-04 10:15:08 -040012839 /* send it... */
12840 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012841
Dave Barach72d72232016-08-04 10:15:08 -040012842 /* Wait for a reply... */
12843 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012844
Dave Barach72d72232016-08-04 10:15:08 -040012845 /* NOTREACHED */
12846 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012847}
12848
12849static int
Dave Barach72d72232016-08-04 10:15:08 -040012850api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012851{
Dave Barach72d72232016-08-04 10:15:08 -040012852 unformat_input_t *input = vam->input;
12853 vl_api_lisp_add_del_local_eid_t *mp;
12854 f64 timeout = ~0;
12855 u8 is_add = 1;
12856 u8 eid_set = 0;
12857 lisp_eid_vat_t _eid, *eid = &_eid;
12858 u8 *locator_set_name = 0;
12859 u8 locator_set_name_set = 0;
12860 u32 vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012861
Dave Barach72d72232016-08-04 10:15:08 -040012862 /* Parse args required to build the message */
12863 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12864 {
12865 if (unformat (input, "del"))
12866 {
12867 is_add = 0;
12868 }
12869 else if (unformat (input, "vni %d", &vni))
12870 {
12871 ;
12872 }
12873 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
12874 {
12875 eid_set = 1;
12876 }
12877 else if (unformat (input, "locator-set %s", &locator_set_name))
12878 {
12879 locator_set_name_set = 1;
12880 }
12881 else
12882 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012883 }
12884
Dave Barach72d72232016-08-04 10:15:08 -040012885 if (locator_set_name_set == 0)
12886 {
12887 errmsg ("missing locator-set name\n");
12888 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012889 }
12890
Dave Barach72d72232016-08-04 10:15:08 -040012891 if (0 == eid_set)
12892 {
12893 errmsg ("EID address not set!");
12894 vec_free (locator_set_name);
12895 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020012896 }
12897
Dave Barach72d72232016-08-04 10:15:08 -040012898 if (vec_len (locator_set_name) > 64)
12899 {
12900 errmsg ("locator-set name too long\n");
12901 vec_free (locator_set_name);
12902 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012903 }
Dave Barach72d72232016-08-04 10:15:08 -040012904 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012905
Dave Barach72d72232016-08-04 10:15:08 -040012906 /* Construct the API message */
12907 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012908
Dave Barach72d72232016-08-04 10:15:08 -040012909 mp->is_add = is_add;
12910 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
12911 mp->eid_type = eid->type;
12912 mp->prefix_len = eid->len;
12913 mp->vni = clib_host_to_net_u32 (vni);
12914 clib_memcpy (mp->locator_set_name, locator_set_name,
12915 vec_len (locator_set_name));
Florin Coras429e7952016-08-02 02:31:03 +020012916
Dave Barach72d72232016-08-04 10:15:08 -040012917 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012918
Dave Barach72d72232016-08-04 10:15:08 -040012919 /* send it... */
12920 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012921
Dave Barach72d72232016-08-04 10:15:08 -040012922 /* Wait for a reply... */
12923 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012924
Dave Barach72d72232016-08-04 10:15:08 -040012925 /* NOTREACHED */
12926 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012927}
12928
Dave Barach72d72232016-08-04 10:15:08 -040012929/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012930/** Used for transferring locators via VPP API */
12931typedef CLIB_PACKED(struct
12932{
Dave Barach72d72232016-08-04 10:15:08 -040012933 u8 is_ip4; /**< is locator an IPv4 address? */
12934 u8 priority; /**< locator priority */
12935 u8 weight; /**< locator weight */
12936 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020012937}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040012938/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012939
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012940static int
Dave Barach72d72232016-08-04 10:15:08 -040012941api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012942{
Dave Barach72d72232016-08-04 10:15:08 -040012943 unformat_input_t *input = vam->input;
12944 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
12945 f64 timeout = ~0;
12946 u8 is_add = 1;
12947 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
12948 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
12949 u8 rmt_eid_set = 0, lcl_eid_set = 0;
12950 u32 action = ~0, p, w;
12951 ip4_address_t rmt_rloc4, lcl_rloc4;
12952 ip6_address_t rmt_rloc6, lcl_rloc6;
12953 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012954
Dave Barach839fe3e2016-08-10 11:35:54 -040012955 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020012956
Dave Barach72d72232016-08-04 10:15:08 -040012957 /* Parse args required to build the message */
12958 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12959 {
12960 if (unformat (input, "del"))
12961 {
12962 is_add = 0;
12963 }
12964 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
12965 {
12966 rmt_eid_set = 1;
12967 }
12968 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
12969 {
12970 lcl_eid_set = 1;
12971 }
12972 else if (unformat (input, "p %d w %d", &p, &w))
12973 {
12974 if (!curr_rloc)
12975 {
12976 errmsg ("No RLOC configured for setting priority/weight!");
12977 return -99;
12978 }
12979 curr_rloc->priority = p;
12980 curr_rloc->weight = w;
12981 }
12982 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
12983 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
12984 {
12985 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020012986
Dave Barach72d72232016-08-04 10:15:08 -040012987 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020012988 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040012989 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012990
Dave Barach72d72232016-08-04 10:15:08 -040012991 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
12992 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020012993 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040012994 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
12995 }
Florin Coras7fbfad32016-08-05 16:57:33 +020012996 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040012997 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
12998 {
12999 rloc.is_ip4 = 0;
13000 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020013001 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013002 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013003
Dave Barach72d72232016-08-04 10:15:08 -040013004 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
13005 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013006 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013007 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13008 }
13009 else if (unformat (input, "action %d", &action))
13010 {
13011 ;
13012 }
13013 else
13014 {
13015 clib_warning ("parse error '%U'", format_unformat_error, input);
13016 return -99;
13017 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013018 }
13019
Dave Barach72d72232016-08-04 10:15:08 -040013020 if (!rmt_eid_set)
13021 {
13022 errmsg ("remote eid addresses not set\n");
13023 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013024 }
13025
Dave Barach72d72232016-08-04 10:15:08 -040013026 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
13027 {
13028 errmsg ("eid types don't match\n");
13029 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013030 }
13031
Dave Barach839fe3e2016-08-10 11:35:54 -040013032 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020013033 {
13034 errmsg ("action not set for negative mapping\n");
13035 return -99;
13036 }
13037
Dave Barach72d72232016-08-04 10:15:08 -040013038 /* Construct the API message */
13039 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013040
Dave Barach72d72232016-08-04 10:15:08 -040013041 mp->is_add = is_add;
13042 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
13043 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
13044 mp->eid_type = rmt_eid->type;
13045 mp->rmt_len = rmt_eid->len;
13046 mp->lcl_len = lcl_eid->len;
13047 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020013048
Florin Coras7fbfad32016-08-05 16:57:33 +020013049 if (0 != rmt_locs && 0 != lcl_locs)
13050 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013051 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020013052 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013053 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013054 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013055 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013056 }
Dave Barach72d72232016-08-04 10:15:08 -040013057 vec_free (lcl_locs);
13058 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013059
Dave Barach72d72232016-08-04 10:15:08 -040013060 /* send it... */
13061 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013062
Dave Barach72d72232016-08-04 10:15:08 -040013063 /* Wait for a reply... */
13064 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013065
Dave Barach72d72232016-08-04 10:15:08 -040013066 /* NOTREACHED */
13067 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013068}
13069
13070static int
Dave Barach72d72232016-08-04 10:15:08 -040013071api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013072{
Dave Barach72d72232016-08-04 10:15:08 -040013073 unformat_input_t *input = vam->input;
13074 vl_api_lisp_add_del_map_resolver_t *mp;
13075 f64 timeout = ~0;
13076 u8 is_add = 1;
13077 u8 ipv4_set = 0;
13078 u8 ipv6_set = 0;
13079 ip4_address_t ipv4;
13080 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013081
Dave Barach72d72232016-08-04 10:15:08 -040013082 /* Parse args required to build the message */
13083 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13084 {
13085 if (unformat (input, "del"))
13086 {
13087 is_add = 0;
13088 }
13089 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13090 {
13091 ipv4_set = 1;
13092 }
13093 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13094 {
13095 ipv6_set = 1;
13096 }
13097 else
13098 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013099 }
13100
Dave Barach72d72232016-08-04 10:15:08 -040013101 if (ipv4_set && ipv6_set)
13102 {
13103 errmsg ("both eid v4 and v6 addresses set\n");
13104 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013105 }
13106
Dave Barach72d72232016-08-04 10:15:08 -040013107 if (!ipv4_set && !ipv6_set)
13108 {
13109 errmsg ("eid addresses not set\n");
13110 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013111 }
13112
Dave Barach72d72232016-08-04 10:15:08 -040013113 /* Construct the API message */
13114 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013115
Dave Barach72d72232016-08-04 10:15:08 -040013116 mp->is_add = is_add;
13117 if (ipv6_set)
13118 {
13119 mp->is_ipv6 = 1;
13120 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13121 }
13122 else
13123 {
13124 mp->is_ipv6 = 0;
13125 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013126 }
13127
Dave Barach72d72232016-08-04 10:15:08 -040013128 /* send it... */
13129 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013130
Dave Barach72d72232016-08-04 10:15:08 -040013131 /* Wait for a reply... */
13132 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013133
Dave Barach72d72232016-08-04 10:15:08 -040013134 /* NOTREACHED */
13135 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013136}
13137
13138static int
Florin Coras577c3552016-04-21 00:45:40 +020013139api_lisp_gpe_enable_disable (vat_main_t * vam)
13140{
Dave Barach72d72232016-08-04 10:15:08 -040013141 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013142 vl_api_lisp_gpe_enable_disable_t *mp;
13143 f64 timeout = ~0;
13144 u8 is_set = 0;
13145 u8 is_en = 1;
13146
13147 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013148 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13149 {
13150 if (unformat (input, "enable"))
13151 {
13152 is_set = 1;
13153 is_en = 1;
13154 }
13155 else if (unformat (input, "disable"))
13156 {
13157 is_set = 1;
13158 is_en = 0;
13159 }
13160 else
13161 break;
13162 }
Florin Coras577c3552016-04-21 00:45:40 +020013163
Dave Barach72d72232016-08-04 10:15:08 -040013164 if (is_set == 0)
13165 {
13166 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013167 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013168 }
Florin Coras577c3552016-04-21 00:45:40 +020013169
13170 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013171 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013172
13173 mp->is_en = is_en;
13174
13175 /* send it... */
13176 S;
13177
13178 /* Wait for a reply... */
13179 W;
13180
13181 /* NOTREACHED */
13182 return 0;
13183}
13184
13185static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013186api_lisp_enable_disable (vat_main_t * vam)
13187{
Dave Barach72d72232016-08-04 10:15:08 -040013188 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013189 vl_api_lisp_enable_disable_t *mp;
13190 f64 timeout = ~0;
13191 u8 is_set = 0;
13192 u8 is_en = 0;
13193
13194 /* Parse args required to build the message */
13195 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13196 {
13197 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013198 {
13199 is_set = 1;
13200 is_en = 1;
13201 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013202 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013203 {
13204 is_set = 1;
13205 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013206 else
Dave Barach72d72232016-08-04 10:15:08 -040013207 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013208 }
13209
13210 if (!is_set)
13211 {
13212 errmsg ("Value not set\n");
13213 return -99;
13214 }
13215
13216 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013217 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013218
13219 mp->is_en = is_en;
13220
13221 /* send it... */
13222 S;
13223
13224 /* Wait for a reply... */
13225 W;
13226
13227 /* NOTREACHED */
13228 return 0;
13229}
13230
Florin Corasdca88042016-09-14 16:01:38 +020013231static int
13232api_show_lisp_map_request_mode (vat_main_t * vam)
13233{
13234 f64 timeout = ~0;
13235 vl_api_show_lisp_map_request_mode_t *mp;
13236
13237 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13238
13239 /* send */
13240 S;
13241
13242 /* wait for reply */
13243 W;
13244
13245 return 0;
13246}
13247
13248static int
13249api_lisp_map_request_mode (vat_main_t * vam)
13250{
13251 f64 timeout = ~0;
13252 unformat_input_t *input = vam->input;
13253 vl_api_lisp_map_request_mode_t *mp;
13254 u8 mode = 0;
13255
13256 /* Parse args required to build the message */
13257 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13258 {
13259 if (unformat (input, "dst-only"))
13260 mode = 0;
13261 else if (unformat (input, "src-dst"))
13262 mode = 1;
13263 else
13264 {
13265 errmsg ("parse error '%U'", format_unformat_error, input);
13266 return -99;
13267 }
13268 }
13269
13270 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13271
13272 mp->mode = mode;
13273
13274 /* send */
13275 S;
13276
13277 /* wait for reply */
13278 W;
13279
13280 /* notreached */
13281 return 0;
13282}
13283
Filip Tehlar195bcee2016-05-13 17:37:35 +020013284/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013285 * Enable/disable LISP proxy ITR.
13286 *
13287 * @param vam vpp API test context
13288 * @return return code
13289 */
13290static int
13291api_lisp_pitr_set_locator_set (vat_main_t * vam)
13292{
13293 f64 timeout = ~0;
13294 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013295 unformat_input_t *input = vam->input;
13296 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013297 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013298 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013299
13300 /* Parse args required to build the message */
13301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13302 {
13303 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013304 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013305 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013306 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013307 else
Dave Barach72d72232016-08-04 10:15:08 -040013308 {
13309 errmsg ("parse error '%U'", format_unformat_error, input);
13310 return -99;
13311 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013312 }
13313
13314 if (!ls_name_set)
13315 {
13316 errmsg ("locator-set name not set!");
13317 return -99;
13318 }
13319
Dave Barach72d72232016-08-04 10:15:08 -040013320 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013321
13322 mp->is_add = is_add;
13323 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13324 vec_free (ls_name);
13325
13326 /* send */
13327 S;
13328
13329 /* wait for reply */
13330 W;
13331
Dave Barach72d72232016-08-04 10:15:08 -040013332 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013333 return 0;
13334}
13335
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013336static int
13337api_show_lisp_pitr (vat_main_t * vam)
13338{
Dave Barach72d72232016-08-04 10:15:08 -040013339 vl_api_show_lisp_pitr_t *mp;
13340 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013341
Dave Barach72d72232016-08-04 10:15:08 -040013342 if (!vam->json_output)
13343 {
13344 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013345 }
13346
Dave Barach72d72232016-08-04 10:15:08 -040013347 M (SHOW_LISP_PITR, show_lisp_pitr);
13348 /* send it... */
13349 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013350
Dave Barach72d72232016-08-04 10:15:08 -040013351 /* Wait for a reply... */
13352 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013353
Dave Barach72d72232016-08-04 10:15:08 -040013354 /* NOTREACHED */
13355 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013356}
13357
Filip Tehlar53f09e32016-05-19 14:25:44 +020013358/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013359 * Add/delete mapping between vni and vrf
13360 */
13361static int
13362api_lisp_eid_table_add_del_map (vat_main_t * vam)
13363{
13364 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013365 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013366 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013367 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13368 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013369
13370 /* Parse args required to build the message */
13371 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13372 {
13373 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013374 is_add = 0;
13375 else if (unformat (input, "vrf %d", &vrf))
13376 vrf_set = 1;
13377 else if (unformat (input, "bd_index %d", &bd_index))
13378 bd_index_set = 1;
13379 else if (unformat (input, "vni %d", &vni))
13380 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013381 else
Dave Barach72d72232016-08-04 10:15:08 -040013382 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013383 }
13384
Florin Coras1a1adc72016-07-22 01:45:30 +020013385 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013386 {
13387 errmsg ("missing arguments!");
13388 return -99;
13389 }
13390
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013391 if (vrf_set && bd_index_set)
13392 {
13393 errmsg ("error: both vrf and bd entered!");
13394 return -99;
13395 }
13396
Dave Barach72d72232016-08-04 10:15:08 -040013397 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013398
13399 mp->is_add = is_add;
13400 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013401 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013402 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013403
13404 /* send */
13405 S;
13406
13407 /* wait for reply */
13408 W;
13409
Dave Barach72d72232016-08-04 10:15:08 -040013410 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013411 return 0;
13412}
13413
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013414uword
13415unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13416{
13417 u32 *action = va_arg (*args, u32 *);
13418 u8 *s = 0;
13419
13420 if (unformat (input, "%s", &s))
13421 {
13422 if (!strcmp ((char *) s, "no-action"))
13423 action[0] = 0;
13424 else if (!strcmp ((char *) s, "natively-forward"))
13425 action[0] = 1;
13426 else if (!strcmp ((char *) s, "send-map-request"))
13427 action[0] = 2;
13428 else if (!strcmp ((char *) s, "drop"))
13429 action[0] = 3;
13430 else
13431 {
13432 clib_warning ("invalid action: '%s'", s);
13433 action[0] = 3;
13434 }
13435 }
13436 else
13437 return 0;
13438
13439 vec_free (s);
13440 return 1;
13441}
13442
Filip Tehlar324112f2016-06-02 16:07:38 +020013443/**
Florin Corasf727db92016-06-23 15:01:58 +020013444 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013445 *
13446 * @param vam vpp API test context
13447 * @return return code
13448 */
13449static int
13450api_lisp_add_del_remote_mapping (vat_main_t * vam)
13451{
Dave Barach72d72232016-08-04 10:15:08 -040013452 unformat_input_t *input = vam->input;
13453 vl_api_lisp_add_del_remote_mapping_t *mp;
13454 f64 timeout = ~0;
13455 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013456 lisp_eid_vat_t _eid, *eid = &_eid;
13457 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013458 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013459 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013460 ip4_address_t rloc4;
13461 ip6_address_t rloc6;
13462 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013463
Dave Barach839fe3e2016-08-10 11:35:54 -040013464 memset (&rloc, 0, sizeof (rloc));
13465
Dave Barach72d72232016-08-04 10:15:08 -040013466 /* Parse args required to build the message */
13467 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13468 {
13469 if (unformat (input, "del-all"))
13470 {
13471 del_all = 1;
13472 }
13473 else if (unformat (input, "del"))
13474 {
13475 is_add = 0;
13476 }
13477 else if (unformat (input, "add"))
13478 {
13479 is_add = 1;
13480 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013481 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013482 {
13483 eid_set = 1;
13484 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013485 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013486 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013487 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013488 }
13489 else if (unformat (input, "vni %d", &vni))
13490 {
13491 ;
13492 }
13493 else if (unformat (input, "p %d w %d", &p, &w))
13494 {
13495 if (!curr_rloc)
13496 {
13497 errmsg ("No RLOC configured for setting priority/weight!");
13498 return -99;
13499 }
13500 curr_rloc->priority = p;
13501 curr_rloc->weight = w;
13502 }
13503 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13504 {
13505 rloc.is_ip4 = 1;
13506 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13507 vec_add1 (rlocs, rloc);
13508 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13509 }
13510 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13511 {
13512 rloc.is_ip4 = 0;
13513 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13514 vec_add1 (rlocs, rloc);
13515 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13516 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013517 else if (unformat (input, "action %U",
13518 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013519 {
13520 ;
13521 }
13522 else
13523 {
13524 clib_warning ("parse error '%U'", format_unformat_error, input);
13525 return -99;
13526 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013527 }
13528
Dave Barach72d72232016-08-04 10:15:08 -040013529 if (0 == eid_set)
13530 {
13531 errmsg ("missing params!");
13532 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013533 }
13534
Dave Barach72d72232016-08-04 10:15:08 -040013535 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13536 {
13537 errmsg ("no action set for negative map-reply!");
13538 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013539 }
13540
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013541 data_len = vec_len (rlocs) * sizeof (rloc_t);
13542
13543 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013544 mp->is_add = is_add;
13545 mp->vni = htonl (vni);
13546 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013547 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013548 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013549 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013550 mp->del_all = del_all;
13551 mp->eid_type = eid->type;
13552 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013553 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013554
Filip Tehlare3552c42016-08-26 12:44:38 +020013555 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013556 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013557 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013558
Dave Barach72d72232016-08-04 10:15:08 -040013559 /* send it... */
13560 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013561
Dave Barach72d72232016-08-04 10:15:08 -040013562 /* Wait for a reply... */
13563 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013564
Dave Barach72d72232016-08-04 10:15:08 -040013565 /* NOTREACHED */
13566 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013567}
13568
Florin Corasf727db92016-06-23 15:01:58 +020013569/**
13570 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
13571 * forwarding entries in data-plane accordingly.
13572 *
13573 * @param vam vpp API test context
13574 * @return return code
13575 */
13576static int
13577api_lisp_add_del_adjacency (vat_main_t * vam)
13578{
Dave Barach72d72232016-08-04 10:15:08 -040013579 unformat_input_t *input = vam->input;
13580 vl_api_lisp_add_del_adjacency_t *mp;
13581 f64 timeout = ~0;
13582 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013583 ip4_address_t leid4, reid4;
13584 ip6_address_t leid6, reid6;
13585 u8 reid_mac[6] = { 0 };
13586 u8 leid_mac[6] = { 0 };
13587 u8 reid_type, leid_type;
13588 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040013589 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020013590
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013591 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020013592
Dave Barach72d72232016-08-04 10:15:08 -040013593 /* Parse args required to build the message */
13594 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13595 {
13596 if (unformat (input, "del"))
13597 {
13598 is_add = 0;
13599 }
13600 else if (unformat (input, "add"))
13601 {
13602 is_add = 1;
13603 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013604 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
13605 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013606 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013607 reid_type = 0; /* ipv4 */
13608 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013609 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013610 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
13611 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013612 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013613 reid_type = 1; /* ipv6 */
13614 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013615 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013616 else if (unformat (input, "reid %U", unformat_ethernet_address,
13617 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013618 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013619 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013620 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013621 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
13622 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013623 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013624 leid_type = 0; /* ipv4 */
13625 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013626 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013627 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
13628 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040013629 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013630 leid_type = 1; /* ipv6 */
13631 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040013632 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013633 else if (unformat (input, "leid %U", unformat_ethernet_address,
13634 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040013635 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013636 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040013637 }
13638 else if (unformat (input, "vni %d", &vni))
13639 {
13640 ;
13641 }
13642 else
13643 {
13644 errmsg ("parse error '%U'", format_unformat_error, input);
13645 return -99;
13646 }
Florin Corasf727db92016-06-23 15:01:58 +020013647 }
13648
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013649 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013650 {
13651 errmsg ("missing params!");
13652 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013653 }
13654
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013655 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040013656 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013657 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040013658 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020013659 }
13660
Dave Barach72d72232016-08-04 10:15:08 -040013661 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
13662 mp->is_add = is_add;
13663 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013664 mp->leid_len = leid_len;
13665 mp->reid_len = reid_len;
13666 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020013667
Dave Barach72d72232016-08-04 10:15:08 -040013668 switch (mp->eid_type)
13669 {
Florin Corasf727db92016-06-23 15:01:58 +020013670 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013671 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
13672 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040013673 break;
Florin Corasf727db92016-06-23 15:01:58 +020013674 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013675 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
13676 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040013677 break;
Florin Corasf727db92016-06-23 15:01:58 +020013678 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020013679 clib_memcpy (mp->leid, leid_mac, 6);
13680 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040013681 break;
Florin Corasf727db92016-06-23 15:01:58 +020013682 default:
Dave Barach72d72232016-08-04 10:15:08 -040013683 errmsg ("unknown EID type %d!", mp->eid_type);
13684 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013685 }
13686
Dave Barach72d72232016-08-04 10:15:08 -040013687 /* send it... */
13688 S;
Florin Corasf727db92016-06-23 15:01:58 +020013689
Dave Barach72d72232016-08-04 10:15:08 -040013690 /* Wait for a reply... */
13691 W;
Florin Corasf727db92016-06-23 15:01:58 +020013692
Dave Barach72d72232016-08-04 10:15:08 -040013693 /* NOTREACHED */
13694 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020013695}
13696
Filip Tehlar46d4e362016-05-09 09:39:26 +020013697static int
Dave Barach72d72232016-08-04 10:15:08 -040013698api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013699{
Dave Barach72d72232016-08-04 10:15:08 -040013700 unformat_input_t *input = vam->input;
13701 vl_api_lisp_gpe_add_del_iface_t *mp;
13702 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020013703 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040013704 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013705
Dave Barach72d72232016-08-04 10:15:08 -040013706 /* Parse args required to build the message */
13707 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13708 {
13709 if (unformat (input, "up"))
13710 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013711 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013712 is_add = 1;
13713 }
13714 else if (unformat (input, "down"))
13715 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013716 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013717 is_add = 0;
13718 }
13719 else if (unformat (input, "table_id %d", &dp_table))
13720 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013721 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013722 }
13723 else if (unformat (input, "bd_id %d", &dp_table))
13724 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013725 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013726 is_l2 = 1;
13727 }
13728 else if (unformat (input, "vni %d", &vni))
13729 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013730 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013731 }
13732 else
13733 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013734 }
13735
Florin Coras7fbfad32016-08-05 16:57:33 +020013736 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040013737 {
Florin Coras7fbfad32016-08-05 16:57:33 +020013738 errmsg ("Action not set\n");
13739 return -99;
13740 }
13741 if (dp_table_set == 0 || vni_set == 0)
13742 {
13743 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040013744 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013745 }
13746
Dave Barach72d72232016-08-04 10:15:08 -040013747 /* Construct the API message */
13748 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013749
Dave Barach72d72232016-08-04 10:15:08 -040013750 mp->is_add = is_add;
13751 mp->dp_table = dp_table;
13752 mp->is_l2 = is_l2;
13753 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013754
Dave Barach72d72232016-08-04 10:15:08 -040013755 /* send it... */
13756 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013757
Dave Barach72d72232016-08-04 10:15:08 -040013758 /* Wait for a reply... */
13759 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013760
Dave Barach72d72232016-08-04 10:15:08 -040013761 /* NOTREACHED */
13762 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013763}
13764
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013765/**
13766 * Add/del map request itr rlocs from LISP control plane and updates
13767 *
13768 * @param vam vpp API test context
13769 * @return return code
13770 */
13771static int
Dave Barach72d72232016-08-04 10:15:08 -040013772api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013773{
Dave Barach72d72232016-08-04 10:15:08 -040013774 unformat_input_t *input = vam->input;
13775 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
13776 f64 timeout = ~0;
13777 u8 *locator_set_name = 0;
13778 u8 locator_set_name_set = 0;
13779 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020013780
Dave Barach72d72232016-08-04 10:15:08 -040013781 /* Parse args required to build the message */
13782 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013783 {
Dave Barach72d72232016-08-04 10:15:08 -040013784 if (unformat (input, "del"))
13785 {
13786 is_add = 0;
13787 }
13788 else if (unformat (input, "%_%v%_", &locator_set_name))
13789 {
13790 locator_set_name_set = 1;
13791 }
13792 else
13793 {
13794 clib_warning ("parse error '%U'", format_unformat_error, input);
13795 return -99;
13796 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013797 }
13798
Dave Barach72d72232016-08-04 10:15:08 -040013799 if (is_add && !locator_set_name_set)
13800 {
13801 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020013802 return -99;
13803 }
13804
Dave Barach72d72232016-08-04 10:15:08 -040013805 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020013806 {
Dave Barach72d72232016-08-04 10:15:08 -040013807 errmsg ("itr-rloc locator-set name too long\n");
13808 vec_free (locator_set_name);
13809 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013810 }
13811
Dave Barach72d72232016-08-04 10:15:08 -040013812 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
13813 mp->is_add = is_add;
13814 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013815 {
Dave Barach72d72232016-08-04 10:15:08 -040013816 clib_memcpy (mp->locator_set_name, locator_set_name,
13817 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013818 }
Dave Barach72d72232016-08-04 10:15:08 -040013819 else
13820 {
13821 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013822 }
Dave Barach72d72232016-08-04 10:15:08 -040013823 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013824
Dave Barach72d72232016-08-04 10:15:08 -040013825 /* send it... */
13826 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013827
Dave Barach72d72232016-08-04 10:15:08 -040013828 /* Wait for a reply... */
13829 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013830
Dave Barach72d72232016-08-04 10:15:08 -040013831 /* NOTREACHED */
13832 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013833}
13834
13835static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013836api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013837{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013838 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013839 vl_api_lisp_locator_dump_t *mp;
13840 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013841 u8 is_index_set = 0, is_name_set = 0;
13842 u8 *ls_name = 0;
13843 u32 ls_index = ~0;
13844
13845 /* Parse args required to build the message */
13846 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13847 {
13848 if (unformat (input, "ls_name %_%v%_", &ls_name))
13849 {
13850 is_name_set = 1;
13851 }
13852 else if (unformat (input, "ls_index %d", &ls_index))
13853 {
13854 is_index_set = 1;
13855 }
13856 else
13857 {
13858 errmsg ("parse error '%U'", format_unformat_error, input);
13859 return -99;
13860 }
13861 }
13862
13863 if (!is_index_set && !is_name_set)
13864 {
13865 errmsg ("error: expected one of index or name!\n");
13866 return -99;
13867 }
13868
13869 if (is_index_set && is_name_set)
13870 {
13871 errmsg ("error: only one param expected!\n");
13872 return -99;
13873 }
13874
Florin Coras042d2122016-09-21 16:38:19 +020013875 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020013876 {
13877 errmsg ("error: locator set name too long!");
13878 return -99;
13879 }
13880
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013881 if (!vam->json_output)
13882 {
13883 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
13884 "weight");
13885 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013886
Dave Barach72d72232016-08-04 10:15:08 -040013887 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013888 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013889
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013890 if (is_index_set)
13891 mp->ls_index = clib_host_to_net_u32 (ls_index);
13892 else
13893 {
13894 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020013895 strncpy ((char *) mp->ls_name, (char *) ls_name,
13896 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013897 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013898
Dave Barach72d72232016-08-04 10:15:08 -040013899 /* send it... */
13900 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020013901
Dave Barach72d72232016-08-04 10:15:08 -040013902 /* Use a control ping for synchronization */
13903 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013904 vl_api_control_ping_t *mp;
13905 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040013906 S;
13907 }
13908 /* Wait for a reply... */
13909 W;
Dave Barach72d72232016-08-04 10:15:08 -040013910
13911 /* NOTREACHED */
13912 return 0;
13913}
13914
13915static int
13916api_lisp_locator_set_dump (vat_main_t * vam)
13917{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013918 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040013919 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013920 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013921 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013922
13923 /* Parse args required to build the message */
13924 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13925 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013926 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040013927 {
13928 filter = 1;
13929 }
13930 else if (unformat (input, "remote"))
13931 {
13932 filter = 2;
13933 }
13934 else
13935 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013936 errmsg ("parse error '%U'", format_unformat_error, input);
13937 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013938 }
13939 }
13940
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013941 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040013942 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013943 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040013944 }
13945
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013946 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040013947
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013948 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040013949
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013950 /* send it... */
13951 S;
13952
13953 /* Use a control ping for synchronization */
13954 {
13955 vl_api_control_ping_t *mp;
13956 M (CONTROL_PING, control_ping);
13957 S;
13958 }
13959 /* Wait for a reply... */
13960 W;
13961
13962 /* NOTREACHED */
13963 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040013964}
13965
13966static int
13967api_lisp_eid_table_map_dump (vat_main_t * vam)
13968{
Filip Tehlarc0681792016-08-24 14:11:07 +020013969 u8 is_l2 = 0;
13970 u8 mode_set = 0;
13971 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040013972 vl_api_lisp_eid_table_map_dump_t *mp;
13973 f64 timeout = ~0;
13974
Filip Tehlarc0681792016-08-24 14:11:07 +020013975 /* Parse args required to build the message */
13976 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13977 {
13978 if (unformat (input, "l2"))
13979 {
13980 is_l2 = 1;
13981 mode_set = 1;
13982 }
13983 else if (unformat (input, "l3"))
13984 {
13985 is_l2 = 0;
13986 mode_set = 1;
13987 }
13988 else
13989 {
13990 errmsg ("parse error '%U'", format_unformat_error, input);
13991 return -99;
13992 }
13993 }
13994
13995 if (!mode_set)
13996 {
13997 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
13998 return -99;
13999 }
14000
Dave Barach72d72232016-08-04 10:15:08 -040014001 if (!vam->json_output)
14002 {
Filip Tehlarc0681792016-08-24 14:11:07 +020014003 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040014004 }
14005
14006 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020014007 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040014008
14009 /* send it... */
14010 S;
14011
14012 /* Use a control ping for synchronization */
14013 {
14014 vl_api_control_ping_t *mp;
14015 M (CONTROL_PING, control_ping);
14016 S;
14017 }
14018 /* Wait for a reply... */
14019 W;
14020
14021 /* NOTREACHED */
14022 return 0;
14023}
14024
14025static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020014026api_lisp_eid_table_vni_dump (vat_main_t * vam)
14027{
14028 vl_api_lisp_eid_table_vni_dump_t *mp;
14029 f64 timeout = ~0;
14030
14031 if (!vam->json_output)
14032 {
14033 fformat (vam->ofp, "VNI\n");
14034 }
14035
14036 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
14037
14038 /* send it... */
14039 S;
14040
14041 /* Use a control ping for synchronization */
14042 {
14043 vl_api_control_ping_t *mp;
14044 M (CONTROL_PING, control_ping);
14045 S;
14046 }
14047 /* Wait for a reply... */
14048 W;
14049
14050 /* NOTREACHED */
14051 return 0;
14052}
14053
14054static int
Dave Barach72d72232016-08-04 10:15:08 -040014055api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014056{
Dave Barach72d72232016-08-04 10:15:08 -040014057 unformat_input_t *i = vam->input;
14058 vl_api_lisp_eid_table_dump_t *mp;
14059 f64 timeout = ~0;
14060 struct in_addr ip4;
14061 struct in6_addr ip6;
14062 u8 mac[6];
14063 u8 eid_type = ~0, eid_set = 0;
14064 u32 prefix_length = ~0, t, vni = 0;
14065 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014066
Dave Barach72d72232016-08-04 10:15:08 -040014067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014068 {
Dave Barach72d72232016-08-04 10:15:08 -040014069 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14070 {
14071 eid_set = 1;
14072 eid_type = 0;
14073 prefix_length = t;
14074 }
14075 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14076 {
14077 eid_set = 1;
14078 eid_type = 1;
14079 prefix_length = t;
14080 }
14081 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14082 {
14083 eid_set = 1;
14084 eid_type = 2;
14085 }
14086 else if (unformat (i, "vni %d", &t))
14087 {
14088 vni = t;
14089 }
14090 else if (unformat (i, "local"))
14091 {
14092 filter = 1;
14093 }
14094 else if (unformat (i, "remote"))
14095 {
14096 filter = 2;
14097 }
14098 else
14099 {
14100 errmsg ("parse error '%U'", format_unformat_error, i);
14101 return -99;
14102 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014103 }
14104
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014105 if (!vam->json_output)
14106 {
14107 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type",
14108 "ls_index", "ttl", "authoritative");
14109 }
14110
Dave Barach72d72232016-08-04 10:15:08 -040014111 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014112
Dave Barach72d72232016-08-04 10:15:08 -040014113 mp->filter = filter;
14114 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014115 {
Dave Barach72d72232016-08-04 10:15:08 -040014116 mp->eid_set = 1;
14117 mp->vni = htonl (vni);
14118 mp->eid_type = eid_type;
14119 switch (eid_type)
14120 {
14121 case 0:
14122 mp->prefix_length = prefix_length;
14123 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14124 break;
14125 case 1:
14126 mp->prefix_length = prefix_length;
14127 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14128 break;
14129 case 2:
14130 clib_memcpy (mp->eid, mac, sizeof (mac));
14131 break;
14132 default:
14133 errmsg ("unknown EID type %d!", eid_type);
14134 return -99;
14135 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014136 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014137
Dave Barach72d72232016-08-04 10:15:08 -040014138 /* send it... */
14139 S;
14140
14141 /* Use a control ping for synchronization */
14142 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014143 vl_api_control_ping_t *mp;
14144 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014145 S;
14146 }
14147
14148 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014149 W;
Dave Barach72d72232016-08-04 10:15:08 -040014150
14151 /* NOTREACHED */
14152 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014153}
14154
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014155static int
Dave Barach72d72232016-08-04 10:15:08 -040014156api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014157{
Dave Barach72d72232016-08-04 10:15:08 -040014158 vl_api_lisp_gpe_tunnel_dump_t *mp;
14159 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014160
Dave Barach72d72232016-08-04 10:15:08 -040014161 if (!vam->json_output)
14162 {
14163 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14164 "%=16s%=16s%=16s%=16s%=16s\n",
14165 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14166 "Decap next", "Lisp version", "Flags", "Next protocol",
14167 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014168 }
14169
Dave Barach72d72232016-08-04 10:15:08 -040014170 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14171 /* send it... */
14172 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014173
Dave Barach72d72232016-08-04 10:15:08 -040014174 /* Use a control ping for synchronization */
14175 {
14176 vl_api_control_ping_t *mp;
14177 M (CONTROL_PING, control_ping);
14178 S;
14179 }
14180 /* Wait for a reply... */
14181 W;
14182
14183 /* NOTREACHED */
14184 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014185}
14186
Matus Fabian8a95a482016-05-06 15:14:13 +020014187static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014188api_lisp_adjacencies_get (vat_main_t * vam)
14189{
14190 unformat_input_t *i = vam->input;
14191 vl_api_lisp_adjacencies_get_t *mp;
14192 f64 timeout = ~0;
14193 u8 vni_set = 0;
14194 u32 vni = ~0;
14195
14196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14197 {
14198 if (unformat (i, "vni %d", &vni))
14199 {
14200 vni_set = 1;
14201 }
14202 else
14203 {
14204 errmsg ("parse error '%U'\n", format_unformat_error, i);
14205 return -99;
14206 }
14207 }
14208
14209 if (!vni_set)
14210 {
14211 errmsg ("vni not set!\n");
14212 return -99;
14213 }
14214
14215 if (!vam->json_output)
14216 {
14217 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14218 }
14219
14220 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14221 mp->vni = clib_host_to_net_u32 (vni);
14222
14223 /* send it... */
14224 S;
14225
14226 /* Wait for a reply... */
14227 W;
14228
14229 /* NOTREACHED */
14230 return 0;
14231}
14232
14233static int
Dave Barach72d72232016-08-04 10:15:08 -040014234api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014235{
Dave Barach72d72232016-08-04 10:15:08 -040014236 vl_api_lisp_map_resolver_dump_t *mp;
14237 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014238
Dave Barach72d72232016-08-04 10:15:08 -040014239 if (!vam->json_output)
14240 {
14241 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014242 }
14243
Dave Barach72d72232016-08-04 10:15:08 -040014244 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14245 /* send it... */
14246 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014247
Dave Barach72d72232016-08-04 10:15:08 -040014248 /* Use a control ping for synchronization */
14249 {
14250 vl_api_control_ping_t *mp;
14251 M (CONTROL_PING, control_ping);
14252 S;
14253 }
14254 /* Wait for a reply... */
14255 W;
14256
14257 /* NOTREACHED */
14258 return 0;
14259}
14260
14261static int
14262api_show_lisp_status (vat_main_t * vam)
14263{
14264 vl_api_show_lisp_status_t *mp;
14265 f64 timeout = ~0;
14266
14267 if (!vam->json_output)
14268 {
14269 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14270 }
14271
14272 M (SHOW_LISP_STATUS, show_lisp_status);
14273 /* send it... */
14274 S;
14275 /* Wait for a reply... */
14276 W;
14277
14278 /* NOTREACHED */
14279 return 0;
14280}
14281
14282static int
14283api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14284{
14285 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14286 f64 timeout = ~0;
14287
14288 if (!vam->json_output)
14289 {
14290 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14291 }
14292
14293 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14294 /* send it... */
14295 S;
14296 /* Wait for a reply... */
14297 W;
14298
14299 /* NOTREACHED */
14300 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014301}
14302
14303static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014304api_af_packet_create (vat_main_t * vam)
14305{
Dave Barach72d72232016-08-04 10:15:08 -040014306 unformat_input_t *i = vam->input;
14307 vl_api_af_packet_create_t *mp;
14308 f64 timeout;
14309 u8 *host_if_name = 0;
14310 u8 hw_addr[6];
14311 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014312
Dave Barach72d72232016-08-04 10:15:08 -040014313 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014314
Dave Barach72d72232016-08-04 10:15:08 -040014315 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14316 {
14317 if (unformat (i, "name %s", &host_if_name))
14318 vec_add1 (host_if_name, 0);
14319 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14320 random_hw_addr = 0;
14321 else
14322 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014323 }
14324
Dave Barach72d72232016-08-04 10:15:08 -040014325 if (!vec_len (host_if_name))
14326 {
14327 errmsg ("host-interface name must be specified");
14328 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014329 }
14330
Dave Barach72d72232016-08-04 10:15:08 -040014331 if (vec_len (host_if_name) > 64)
14332 {
14333 errmsg ("host-interface name too long");
14334 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014335 }
14336
Dave Barach72d72232016-08-04 10:15:08 -040014337 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014338
Dave Barach72d72232016-08-04 10:15:08 -040014339 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14340 clib_memcpy (mp->hw_addr, hw_addr, 6);
14341 mp->use_random_hw_addr = random_hw_addr;
14342 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014343
Dave Barach72d72232016-08-04 10:15:08 -040014344 S;
14345 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14346 /* NOTREACHED */
14347 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014348}
14349
14350static int
14351api_af_packet_delete (vat_main_t * vam)
14352{
Dave Barach72d72232016-08-04 10:15:08 -040014353 unformat_input_t *i = vam->input;
14354 vl_api_af_packet_delete_t *mp;
14355 f64 timeout;
14356 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014357
Dave Barach72d72232016-08-04 10:15:08 -040014358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14359 {
14360 if (unformat (i, "name %s", &host_if_name))
14361 vec_add1 (host_if_name, 0);
14362 else
14363 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014364 }
14365
Dave Barach72d72232016-08-04 10:15:08 -040014366 if (!vec_len (host_if_name))
14367 {
14368 errmsg ("host-interface name must be specified");
14369 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014370 }
14371
Dave Barach72d72232016-08-04 10:15:08 -040014372 if (vec_len (host_if_name) > 64)
14373 {
14374 errmsg ("host-interface name too long");
14375 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014376 }
14377
Dave Barach72d72232016-08-04 10:15:08 -040014378 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014379
Dave Barach72d72232016-08-04 10:15:08 -040014380 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14381 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014382
Dave Barach72d72232016-08-04 10:15:08 -040014383 S;
14384 W;
14385 /* NOTREACHED */
14386 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014387}
14388
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014389static int
14390api_policer_add_del (vat_main_t * vam)
14391{
Dave Barach72d72232016-08-04 10:15:08 -040014392 unformat_input_t *i = vam->input;
14393 vl_api_policer_add_del_t *mp;
14394 f64 timeout;
14395 u8 is_add = 1;
14396 u8 *name = 0;
14397 u32 cir = 0;
14398 u32 eir = 0;
14399 u64 cb = 0;
14400 u64 eb = 0;
14401 u8 rate_type = 0;
14402 u8 round_type = 0;
14403 u8 type = 0;
14404 u8 color_aware = 0;
14405 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014406
Dave Barach839fe3e2016-08-10 11:35:54 -040014407 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14408 conform_action.dscp = 0;
14409 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14410 exceed_action.dscp = 0;
14411 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14412 violate_action.dscp = 0;
14413
Dave Barach72d72232016-08-04 10:15:08 -040014414 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14415 {
14416 if (unformat (i, "del"))
14417 is_add = 0;
14418 else if (unformat (i, "name %s", &name))
14419 vec_add1 (name, 0);
14420 else if (unformat (i, "cir %u", &cir))
14421 ;
14422 else if (unformat (i, "eir %u", &eir))
14423 ;
14424 else if (unformat (i, "cb %u", &cb))
14425 ;
14426 else if (unformat (i, "eb %u", &eb))
14427 ;
14428 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14429 &rate_type))
14430 ;
14431 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14432 &round_type))
14433 ;
14434 else if (unformat (i, "type %U", unformat_policer_type, &type))
14435 ;
14436 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14437 &conform_action))
14438 ;
14439 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14440 &exceed_action))
14441 ;
14442 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14443 &violate_action))
14444 ;
14445 else if (unformat (i, "color-aware"))
14446 color_aware = 1;
14447 else
14448 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014449 }
14450
Dave Barach72d72232016-08-04 10:15:08 -040014451 if (!vec_len (name))
14452 {
14453 errmsg ("policer name must be specified");
14454 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014455 }
14456
Dave Barach72d72232016-08-04 10:15:08 -040014457 if (vec_len (name) > 64)
14458 {
14459 errmsg ("policer name too long");
14460 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014461 }
14462
Dave Barach72d72232016-08-04 10:15:08 -040014463 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014464
Dave Barach72d72232016-08-04 10:15:08 -040014465 clib_memcpy (mp->name, name, vec_len (name));
14466 vec_free (name);
14467 mp->is_add = is_add;
14468 mp->cir = cir;
14469 mp->eir = eir;
14470 mp->cb = cb;
14471 mp->eb = eb;
14472 mp->rate_type = rate_type;
14473 mp->round_type = round_type;
14474 mp->type = type;
14475 mp->conform_action_type = conform_action.action_type;
14476 mp->conform_dscp = conform_action.dscp;
14477 mp->exceed_action_type = exceed_action.action_type;
14478 mp->exceed_dscp = exceed_action.dscp;
14479 mp->violate_action_type = violate_action.action_type;
14480 mp->violate_dscp = violate_action.dscp;
14481 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014482
Dave Barach72d72232016-08-04 10:15:08 -040014483 S;
14484 W;
14485 /* NOTREACHED */
14486 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014487}
14488
Matus Fabian82e29c42016-05-11 04:49:46 -070014489static int
Dave Barach72d72232016-08-04 10:15:08 -040014490api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014491{
Dave Barach72d72232016-08-04 10:15:08 -040014492 unformat_input_t *i = vam->input;
14493 vl_api_policer_dump_t *mp;
14494 f64 timeout = ~0;
14495 u8 *match_name = 0;
14496 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014497
Dave Barach72d72232016-08-04 10:15:08 -040014498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014499 {
Dave Barach72d72232016-08-04 10:15:08 -040014500 if (unformat (i, "name %s", &match_name))
14501 {
14502 vec_add1 (match_name, 0);
14503 match_name_valid = 1;
14504 }
14505 else
14506 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014507 }
Matus Fabiane8554802016-05-18 23:40:37 -070014508
Dave Barach72d72232016-08-04 10:15:08 -040014509 M (POLICER_DUMP, policer_dump);
14510 mp->match_name_valid = match_name_valid;
14511 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14512 vec_free (match_name);
14513 /* send it... */
14514 S;
14515
14516 /* Use a control ping for synchronization */
14517 {
14518 vl_api_control_ping_t *mp;
14519 M (CONTROL_PING, control_ping);
14520 S;
14521 }
14522 /* Wait for a reply... */
14523 W;
14524
14525 /* NOTREACHED */
14526 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014527}
14528
14529static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014530api_policer_classify_set_interface (vat_main_t * vam)
14531{
Dave Barach72d72232016-08-04 10:15:08 -040014532 unformat_input_t *i = vam->input;
14533 vl_api_policer_classify_set_interface_t *mp;
14534 f64 timeout;
14535 u32 sw_if_index;
14536 int sw_if_index_set;
14537 u32 ip4_table_index = ~0;
14538 u32 ip6_table_index = ~0;
14539 u32 l2_table_index = ~0;
14540 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014541
Dave Barach72d72232016-08-04 10:15:08 -040014542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14543 {
14544 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
14545 sw_if_index_set = 1;
14546 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14547 sw_if_index_set = 1;
14548 else if (unformat (i, "del"))
14549 is_add = 0;
14550 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14551 ;
14552 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14553 ;
14554 else if (unformat (i, "l2-table %d", &l2_table_index))
14555 ;
14556 else
14557 {
14558 clib_warning ("parse error '%U'", format_unformat_error, i);
14559 return -99;
14560 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014561 }
14562
Dave Barach72d72232016-08-04 10:15:08 -040014563 if (sw_if_index_set == 0)
14564 {
14565 errmsg ("missing interface name or sw_if_index\n");
14566 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014567 }
14568
Dave Barach72d72232016-08-04 10:15:08 -040014569 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014570
Dave Barach72d72232016-08-04 10:15:08 -040014571 mp->sw_if_index = ntohl (sw_if_index);
14572 mp->ip4_table_index = ntohl (ip4_table_index);
14573 mp->ip6_table_index = ntohl (ip6_table_index);
14574 mp->l2_table_index = ntohl (l2_table_index);
14575 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014576
Dave Barach72d72232016-08-04 10:15:08 -040014577 S;
14578 W;
14579 /* NOTREACHED */
14580 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014581}
14582
14583static int
Dave Barach72d72232016-08-04 10:15:08 -040014584api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014585{
Dave Barach72d72232016-08-04 10:15:08 -040014586 unformat_input_t *i = vam->input;
14587 vl_api_policer_classify_dump_t *mp;
14588 f64 timeout = ~0;
14589 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014590
Juraj Sloboda506b2452016-08-07 23:45:24 -070014591 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040014592 ;
14593 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014594 {
Dave Barach72d72232016-08-04 10:15:08 -040014595 errmsg ("classify table type must be specified\n");
14596 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014597 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014598
Dave Barach72d72232016-08-04 10:15:08 -040014599 if (!vam->json_output)
14600 {
14601 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
14602 }
14603
14604 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
14605 mp->type = type;
14606 /* send it... */
14607 S;
14608
14609 /* Use a control ping for synchronization */
14610 {
14611 vl_api_control_ping_t *mp;
14612 M (CONTROL_PING, control_ping);
14613 S;
14614 }
14615 /* Wait for a reply... */
14616 W;
14617
14618 /* NOTREACHED */
14619 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070014620}
14621
14622static int
Matus Fabian82e29c42016-05-11 04:49:46 -070014623api_netmap_create (vat_main_t * vam)
14624{
Dave Barach72d72232016-08-04 10:15:08 -040014625 unformat_input_t *i = vam->input;
14626 vl_api_netmap_create_t *mp;
14627 f64 timeout;
14628 u8 *if_name = 0;
14629 u8 hw_addr[6];
14630 u8 random_hw_addr = 1;
14631 u8 is_pipe = 0;
14632 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014633
Dave Barach72d72232016-08-04 10:15:08 -040014634 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070014635
Dave Barach72d72232016-08-04 10:15:08 -040014636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14637 {
14638 if (unformat (i, "name %s", &if_name))
14639 vec_add1 (if_name, 0);
14640 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14641 random_hw_addr = 0;
14642 else if (unformat (i, "pipe"))
14643 is_pipe = 1;
14644 else if (unformat (i, "master"))
14645 is_master = 1;
14646 else if (unformat (i, "slave"))
14647 is_master = 0;
14648 else
14649 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014650 }
14651
Dave Barach72d72232016-08-04 10:15:08 -040014652 if (!vec_len (if_name))
14653 {
14654 errmsg ("interface name must be specified");
14655 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014656 }
14657
Dave Barach72d72232016-08-04 10:15:08 -040014658 if (vec_len (if_name) > 64)
14659 {
14660 errmsg ("interface name too long");
14661 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014662 }
14663
Dave Barach72d72232016-08-04 10:15:08 -040014664 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070014665
Dave Barach72d72232016-08-04 10:15:08 -040014666 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14667 clib_memcpy (mp->hw_addr, hw_addr, 6);
14668 mp->use_random_hw_addr = random_hw_addr;
14669 mp->is_pipe = is_pipe;
14670 mp->is_master = is_master;
14671 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014672
Dave Barach72d72232016-08-04 10:15:08 -040014673 S;
14674 W;
14675 /* NOTREACHED */
14676 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014677}
14678
14679static int
14680api_netmap_delete (vat_main_t * vam)
14681{
Dave Barach72d72232016-08-04 10:15:08 -040014682 unformat_input_t *i = vam->input;
14683 vl_api_netmap_delete_t *mp;
14684 f64 timeout;
14685 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014686
Dave Barach72d72232016-08-04 10:15:08 -040014687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14688 {
14689 if (unformat (i, "name %s", &if_name))
14690 vec_add1 (if_name, 0);
14691 else
14692 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070014693 }
14694
Dave Barach72d72232016-08-04 10:15:08 -040014695 if (!vec_len (if_name))
14696 {
14697 errmsg ("interface name must be specified");
14698 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014699 }
14700
Dave Barach72d72232016-08-04 10:15:08 -040014701 if (vec_len (if_name) > 64)
14702 {
14703 errmsg ("interface name too long");
14704 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070014705 }
14706
Dave Barach72d72232016-08-04 10:15:08 -040014707 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070014708
Dave Barach72d72232016-08-04 10:15:08 -040014709 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
14710 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070014711
Dave Barach72d72232016-08-04 10:15:08 -040014712 S;
14713 W;
14714 /* NOTREACHED */
14715 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070014716}
14717
Neale Rannsad422ed2016-11-02 14:20:04 +000014718static void vl_api_mpls_tunnel_details_t_handler
14719 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014720{
Dave Barach72d72232016-08-04 10:15:08 -040014721 vat_main_t *vam = &vat_main;
Neale Rannsad422ed2016-11-02 14:20:04 +000014722 i32 len = mp->mt_next_hop_n_labels;
Dave Barach72d72232016-08-04 10:15:08 -040014723 i32 i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014724
Neale Rannsad422ed2016-11-02 14:20:04 +000014725 fformat (vam->ofp, "[%d]: via %U %d labels ",
14726 mp->tunnel_index,
14727 format_ip4_address, mp->mt_next_hop,
14728 ntohl (mp->mt_next_hop_sw_if_index));
Dave Barach72d72232016-08-04 10:15:08 -040014729 for (i = 0; i < len; i++)
14730 {
Neale Rannsad422ed2016-11-02 14:20:04 +000014731 fformat (vam->ofp, "%u ", ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014732 }
Dave Barach72d72232016-08-04 10:15:08 -040014733 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014734}
14735
Neale Rannsad422ed2016-11-02 14:20:04 +000014736static void vl_api_mpls_tunnel_details_t_handler_json
14737 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014738{
Dave Barach72d72232016-08-04 10:15:08 -040014739 vat_main_t *vam = &vat_main;
14740 vat_json_node_t *node = NULL;
14741 struct in_addr ip4;
14742 i32 i;
Neale Rannsad422ed2016-11-02 14:20:04 +000014743 i32 len = mp->mt_next_hop_n_labels;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014744
Dave Barach72d72232016-08-04 10:15:08 -040014745 if (VAT_JSON_ARRAY != vam->json_tree.type)
14746 {
14747 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14748 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014749 }
Dave Barach72d72232016-08-04 10:15:08 -040014750 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014751
Dave Barach72d72232016-08-04 10:15:08 -040014752 vat_json_init_object (node);
14753 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
Neale Rannsad422ed2016-11-02 14:20:04 +000014754 clib_memcpy (&ip4, &(mp->mt_next_hop), sizeof (ip4));
14755 vat_json_object_add_ip4 (node, "next_hop", ip4);
14756 vat_json_object_add_uint (node, "next_hop_sw_if_index",
14757 ntohl (mp->mt_next_hop_sw_if_index));
14758 vat_json_object_add_uint (node, "l2_only", ntohl (mp->mt_l2_only));
Dave Barach72d72232016-08-04 10:15:08 -040014759 vat_json_object_add_uint (node, "label_count", len);
14760 for (i = 0; i < len; i++)
14761 {
Neale Rannsad422ed2016-11-02 14:20:04 +000014762 vat_json_object_add_uint (node, "label",
14763 ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014764 }
14765}
14766
Dave Barach72d72232016-08-04 10:15:08 -040014767static int
Neale Rannsad422ed2016-11-02 14:20:04 +000014768api_mpls_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014769{
Neale Rannsad422ed2016-11-02 14:20:04 +000014770 vl_api_mpls_tunnel_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014771 f64 timeout;
14772 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014773
Dave Barach72d72232016-08-04 10:15:08 -040014774 /* Parse args required to build the message */
14775 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014776 {
Dave Barach72d72232016-08-04 10:15:08 -040014777 if (!unformat (vam->input, "tunnel_index %d", &index))
14778 {
14779 index = -1;
14780 break;
14781 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014782 }
Dave Barach72d72232016-08-04 10:15:08 -040014783
14784 fformat (vam->ofp, " tunnel_index %d\n", index);
14785
Neale Rannsad422ed2016-11-02 14:20:04 +000014786 M (MPLS_TUNNEL_DUMP, mpls_tunnel_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014787 mp->tunnel_index = htonl (index);
14788 S;
14789
14790 /* Use a control ping for synchronization */
14791 {
14792 vl_api_control_ping_t *mp;
14793 M (CONTROL_PING, control_ping);
14794 S;
14795 }
14796 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014797}
14798
Steven01b07122016-11-02 10:40:09 -070014799#define vl_api_mpls_fib_details_t_endian vl_noop_handler
14800#define vl_api_mpls_fib_details_t_print vl_noop_handler
14801
Neale Ranns1357f3b2016-10-16 12:01:42 -070014802static void
14803vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014804{
Dave Barach72d72232016-08-04 10:15:08 -040014805 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070014806 int count = ntohl (mp->count);
14807 vl_api_fib_path_t *fp;
14808 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014809
Dave Barach72d72232016-08-04 10:15:08 -040014810 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070014811 "table-id %d, label %u, ess_bit %u\n",
14812 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
Steven01b07122016-11-02 10:40:09 -070014813 fp = mp->path;
14814 for (i = 0; i < count; i++)
14815 {
Steven5858a822016-11-16 13:26:27 -080014816 if (fp->afi == IP46_TYPE_IP6)
14817 fformat (vam->ofp,
14818 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14819 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14820 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14821 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14822 format_ip6_address, fp->next_hop);
14823 else if (fp->afi == IP46_TYPE_IP4)
14824 fformat (vam->ofp,
14825 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14826 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14827 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14828 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14829 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070014830 fp++;
14831 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014832}
14833
Neale Ranns1357f3b2016-10-16 12:01:42 -070014834static void vl_api_mpls_fib_details_t_handler_json
14835 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014836{
Dave Barach72d72232016-08-04 10:15:08 -040014837 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070014838 int count = ntohl (mp->count);
Dave Barach72d72232016-08-04 10:15:08 -040014839 vat_json_node_t *node = NULL;
Steven01b07122016-11-02 10:40:09 -070014840 struct in_addr ip4;
14841 struct in6_addr ip6;
14842 vl_api_fib_path_t *fp;
14843 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014844
Dave Barach72d72232016-08-04 10:15:08 -040014845 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014846 {
Dave Barach72d72232016-08-04 10:15:08 -040014847 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14848 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014849 }
Dave Barach72d72232016-08-04 10:15:08 -040014850 node = vat_json_array_add (&vam->json_tree);
14851
14852 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070014853 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
14854 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040014855 vat_json_object_add_uint (node, "label", ntohl (mp->label));
Steven01b07122016-11-02 10:40:09 -070014856 vat_json_object_add_uint (node, "path_count", count);
14857 fp = mp->path;
14858 for (i = 0; i < count; i++)
14859 {
14860 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
14861 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
14862 vat_json_object_add_uint (node, "is_local", fp->is_local);
14863 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
14864 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
14865 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
14866 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
14867 if (fp->afi == IP46_TYPE_IP4)
14868 {
14869 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
14870 vat_json_object_add_ip4 (node, "next_hop", ip4);
14871 }
14872 else if (fp->afi == IP46_TYPE_IP6)
14873 {
14874 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
14875 vat_json_object_add_ip6 (node, "next_hop", ip6);
14876 }
14877 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020014878}
14879
Dave Barach72d72232016-08-04 10:15:08 -040014880static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070014881api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014882{
Neale Ranns1357f3b2016-10-16 12:01:42 -070014883 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014884 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014885
Neale Ranns1357f3b2016-10-16 12:01:42 -070014886 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014887 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014888
Dave Barach72d72232016-08-04 10:15:08 -040014889 /* Use a control ping for synchronization */
14890 {
14891 vl_api_control_ping_t *mp;
14892 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014893 S;
Dave Barach72d72232016-08-04 10:15:08 -040014894 }
14895 W;
14896}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020014897
Steven01b07122016-11-02 10:40:09 -070014898#define vl_api_ip_fib_details_t_endian vl_noop_handler
14899#define vl_api_ip_fib_details_t_print vl_noop_handler
14900
14901static void
14902vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
14903{
14904 vat_main_t *vam = &vat_main;
14905 int count = ntohl (mp->count);
14906 vl_api_fib_path_t *fp;
14907 int i;
14908
14909 fformat (vam->ofp,
14910 "table-id %d, prefix %U/%d\n",
14911 ntohl (mp->table_id), format_ip4_address, mp->address,
14912 mp->address_length);
14913 fp = mp->path;
14914 for (i = 0; i < count; i++)
14915 {
Steven5858a822016-11-16 13:26:27 -080014916 if (fp->afi == IP46_TYPE_IP6)
14917 fformat (vam->ofp,
14918 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14919 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14920 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14921 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14922 format_ip6_address, fp->next_hop);
14923 else if (fp->afi == IP46_TYPE_IP4)
14924 fformat (vam->ofp,
14925 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
14926 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
14927 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
14928 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
14929 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070014930 fp++;
14931 }
14932}
14933
14934static void vl_api_ip_fib_details_t_handler_json
14935 (vl_api_ip_fib_details_t * mp)
14936{
14937 vat_main_t *vam = &vat_main;
14938 int count = ntohl (mp->count);
14939 vat_json_node_t *node = NULL;
14940 struct in_addr ip4;
14941 struct in6_addr ip6;
14942 vl_api_fib_path_t *fp;
14943 int i;
14944
14945 if (VAT_JSON_ARRAY != vam->json_tree.type)
14946 {
14947 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14948 vat_json_init_array (&vam->json_tree);
14949 }
14950 node = vat_json_array_add (&vam->json_tree);
14951
14952 vat_json_init_object (node);
14953 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
14954 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
14955 vat_json_object_add_ip4 (node, "prefix", ip4);
14956 vat_json_object_add_uint (node, "mask_length", mp->address_length);
14957 vat_json_object_add_uint (node, "path_count", count);
14958 fp = mp->path;
14959 for (i = 0; i < count; i++)
14960 {
14961 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
14962 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
14963 vat_json_object_add_uint (node, "is_local", fp->is_local);
14964 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
14965 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
14966 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
14967 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
14968 if (fp->afi == IP46_TYPE_IP4)
14969 {
14970 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
14971 vat_json_object_add_ip4 (node, "next_hop", ip4);
14972 }
14973 else if (fp->afi == IP46_TYPE_IP6)
14974 {
14975 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
14976 vat_json_object_add_ip6 (node, "next_hop", ip6);
14977 }
14978 }
14979}
14980
14981static int
14982api_ip_fib_dump (vat_main_t * vam)
14983{
14984 vl_api_ip_fib_dump_t *mp;
14985 f64 timeout;
14986
14987 M (IP_FIB_DUMP, ip_fib_dump);
14988 S;
14989
14990 /* Use a control ping for synchronization */
14991 {
14992 vl_api_control_ping_t *mp;
14993 M (CONTROL_PING, control_ping);
14994 S;
14995 }
14996 W;
14997}
14998
14999#define vl_api_ip6_fib_details_t_endian vl_noop_handler
15000#define vl_api_ip6_fib_details_t_print vl_noop_handler
15001
15002static void
15003vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
15004{
15005 vat_main_t *vam = &vat_main;
15006 int count = ntohl (mp->count);
15007 vl_api_fib_path_t *fp;
15008 int i;
15009
15010 fformat (vam->ofp,
15011 "table-id %d, prefix %U/%d\n",
15012 ntohl (mp->table_id), format_ip6_address, mp->address,
15013 mp->address_length);
15014 fp = mp->path;
15015 for (i = 0; i < count; i++)
15016 {
Steven5858a822016-11-16 13:26:27 -080015017 if (fp->afi == IP46_TYPE_IP6)
15018 fformat (vam->ofp,
15019 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15020 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15021 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15022 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15023 format_ip6_address, fp->next_hop);
15024 else if (fp->afi == IP46_TYPE_IP4)
15025 fformat (vam->ofp,
15026 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15027 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15028 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15029 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15030 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015031 fp++;
15032 }
15033}
15034
15035static void vl_api_ip6_fib_details_t_handler_json
15036 (vl_api_ip6_fib_details_t * mp)
15037{
15038 vat_main_t *vam = &vat_main;
15039 int count = ntohl (mp->count);
15040 vat_json_node_t *node = NULL;
15041 struct in_addr ip4;
15042 struct in6_addr ip6;
15043 vl_api_fib_path_t *fp;
15044 int i;
15045
15046 if (VAT_JSON_ARRAY != vam->json_tree.type)
15047 {
15048 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15049 vat_json_init_array (&vam->json_tree);
15050 }
15051 node = vat_json_array_add (&vam->json_tree);
15052
15053 vat_json_init_object (node);
15054 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15055 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
15056 vat_json_object_add_ip6 (node, "prefix", ip6);
15057 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15058 vat_json_object_add_uint (node, "path_count", count);
15059 fp = mp->path;
15060 for (i = 0; i < count; i++)
15061 {
15062 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15063 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15064 vat_json_object_add_uint (node, "is_local", fp->is_local);
15065 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15066 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15067 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15068 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15069 if (fp->afi == IP46_TYPE_IP4)
15070 {
15071 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15072 vat_json_object_add_ip4 (node, "next_hop", ip4);
15073 }
15074 else if (fp->afi == IP46_TYPE_IP6)
15075 {
15076 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15077 vat_json_object_add_ip6 (node, "next_hop", ip6);
15078 }
15079 }
15080}
15081
15082static int
15083api_ip6_fib_dump (vat_main_t * vam)
15084{
15085 vl_api_ip6_fib_dump_t *mp;
15086 f64 timeout;
15087
15088 M (IP6_FIB_DUMP, ip6_fib_dump);
15089 S;
15090
15091 /* Use a control ping for synchronization */
15092 {
15093 vl_api_control_ping_t *mp;
15094 M (CONTROL_PING, control_ping);
15095 S;
15096 }
15097 W;
15098}
15099
Dave Barach72d72232016-08-04 10:15:08 -040015100int
15101api_classify_table_ids (vat_main_t * vam)
15102{
15103 vl_api_classify_table_ids_t *mp;
15104 f64 timeout;
15105
15106 /* Construct the API message */
15107 M (CLASSIFY_TABLE_IDS, classify_table_ids);
15108 mp->context = 0;
15109
15110 S;
15111 W;
15112 /* NOTREACHED */
15113 return 0;
15114}
15115
15116int
15117api_classify_table_by_interface (vat_main_t * vam)
15118{
15119 unformat_input_t *input = vam->input;
15120 vl_api_classify_table_by_interface_t *mp;
15121 f64 timeout;
15122
15123 u32 sw_if_index = ~0;
15124 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015125 {
Dave Barach72d72232016-08-04 10:15:08 -040015126 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15127 ;
15128 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15129 ;
15130 else
15131 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015132 }
Dave Barach72d72232016-08-04 10:15:08 -040015133 if (sw_if_index == ~0)
15134 {
15135 errmsg ("missing interface name or sw_if_index\n");
15136 return -99;
15137 }
15138
15139 /* Construct the API message */
15140 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
15141 mp->context = 0;
15142 mp->sw_if_index = ntohl (sw_if_index);
15143
15144 S;
15145 W;
15146 /* NOTREACHED */
15147 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015148}
15149
Dave Barach72d72232016-08-04 10:15:08 -040015150int
15151api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015152{
Dave Barach72d72232016-08-04 10:15:08 -040015153 unformat_input_t *input = vam->input;
15154 vl_api_classify_table_info_t *mp;
15155 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015156
Dave Barach72d72232016-08-04 10:15:08 -040015157 u32 table_id = ~0;
15158 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15159 {
15160 if (unformat (input, "table_id %d", &table_id))
15161 ;
15162 else
15163 break;
15164 }
15165 if (table_id == ~0)
15166 {
15167 errmsg ("missing table id\n");
15168 return -99;
15169 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015170
Dave Barach72d72232016-08-04 10:15:08 -040015171 /* Construct the API message */
15172 M (CLASSIFY_TABLE_INFO, classify_table_info);
15173 mp->context = 0;
15174 mp->table_id = ntohl (table_id);
15175
15176 S;
15177 W;
15178 /* NOTREACHED */
15179 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015180}
15181
Dave Barach72d72232016-08-04 10:15:08 -040015182int
15183api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015184{
Dave Barach72d72232016-08-04 10:15:08 -040015185 unformat_input_t *input = vam->input;
15186 vl_api_classify_session_dump_t *mp;
15187 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015188
Dave Barach72d72232016-08-04 10:15:08 -040015189 u32 table_id = ~0;
15190 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15191 {
15192 if (unformat (input, "table_id %d", &table_id))
15193 ;
15194 else
15195 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015196 }
Dave Barach72d72232016-08-04 10:15:08 -040015197 if (table_id == ~0)
15198 {
15199 errmsg ("missing table id\n");
15200 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015201 }
15202
Dave Barach72d72232016-08-04 10:15:08 -040015203 /* Construct the API message */
15204 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15205 mp->context = 0;
15206 mp->table_id = ntohl (table_id);
15207 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015208
Dave Barach72d72232016-08-04 10:15:08 -040015209 /* Use a control ping for synchronization */
15210 {
15211 vl_api_control_ping_t *mp;
15212 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015213 S;
Dave Barach72d72232016-08-04 10:15:08 -040015214 }
15215 W;
15216 /* NOTREACHED */
15217 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015218}
15219
Dave Barach72d72232016-08-04 10:15:08 -040015220static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015221vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015222{
Dave Barach72d72232016-08-04 10:15:08 -040015223 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015224
Dave Barach72d72232016-08-04 10:15:08 -040015225 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015226 "src_address %U, vrf_id %d, path_mtu %u, "
15227 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015228 format_ip4_address, mp->collector_address,
15229 ntohs (mp->collector_port),
15230 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015231 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15232 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015233
15234 vam->retval = 0;
15235 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015236}
15237
Dave Barach72d72232016-08-04 10:15:08 -040015238static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015239 vl_api_ipfix_exporter_details_t_handler_json
15240 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015241{
Dave Barach72d72232016-08-04 10:15:08 -040015242 vat_main_t *vam = &vat_main;
15243 vat_json_node_t node;
15244 struct in_addr collector_address;
15245 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015246
Dave Barach72d72232016-08-04 10:15:08 -040015247 vat_json_init_object (&node);
15248 clib_memcpy (&collector_address, &mp->collector_address,
15249 sizeof (collector_address));
15250 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15251 vat_json_object_add_uint (&node, "collector_port",
15252 ntohs (mp->collector_port));
15253 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15254 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015255 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015256 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15257 vat_json_object_add_uint (&node, "template_interval",
15258 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015259 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015260
15261 vat_json_print (vam->ofp, &node);
15262 vat_json_free (&node);
15263 vam->retval = 0;
15264 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015265}
15266
Dave Barach72d72232016-08-04 10:15:08 -040015267int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015268api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015269{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015270 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015271 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015272
Dave Barach72d72232016-08-04 10:15:08 -040015273 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015274 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015275 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015276
Dave Barach72d72232016-08-04 10:15:08 -040015277 S;
15278 W;
15279 /* NOTREACHED */
15280 return 0;
15281}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015282
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015283static int
15284api_ipfix_classify_stream_dump (vat_main_t * vam)
15285{
15286 vl_api_ipfix_classify_stream_dump_t *mp;
15287 f64 timeout;
15288
15289 /* Construct the API message */
15290 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15291 mp->context = 0;
15292
15293 S;
15294 W;
15295 /* NOTREACHED */
15296 return 0;
15297}
15298
15299static void
15300 vl_api_ipfix_classify_stream_details_t_handler
15301 (vl_api_ipfix_classify_stream_details_t * mp)
15302{
15303 vat_main_t *vam = &vat_main;
15304 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15305 ntohl (mp->domain_id), ntohs (mp->src_port));
15306 vam->retval = 0;
15307 vam->result_ready = 1;
15308}
15309
15310static void
15311 vl_api_ipfix_classify_stream_details_t_handler_json
15312 (vl_api_ipfix_classify_stream_details_t * mp)
15313{
15314 vat_main_t *vam = &vat_main;
15315 vat_json_node_t node;
15316
15317 vat_json_init_object (&node);
15318 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15319 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15320
15321 vat_json_print (vam->ofp, &node);
15322 vat_json_free (&node);
15323 vam->retval = 0;
15324 vam->result_ready = 1;
15325}
15326
15327static int
15328api_ipfix_classify_table_dump (vat_main_t * vam)
15329{
15330 vl_api_ipfix_classify_table_dump_t *mp;
15331 f64 timeout;
15332
15333 if (!vam->json_output)
15334 {
15335 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15336 "transport_protocol");
15337 }
15338
15339 /* Construct the API message */
15340 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15341
15342 /* send it... */
15343 S;
15344
15345 /* Use a control ping for synchronization */
15346 {
15347 vl_api_control_ping_t *mp;
15348 M (CONTROL_PING, control_ping);
15349 S;
15350 }
15351 W;
15352}
15353
15354static void
15355 vl_api_ipfix_classify_table_details_t_handler
15356 (vl_api_ipfix_classify_table_details_t * mp)
15357{
15358 vat_main_t *vam = &vat_main;
15359 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15360 mp->transport_protocol);
15361}
15362
15363static void
15364 vl_api_ipfix_classify_table_details_t_handler_json
15365 (vl_api_ipfix_classify_table_details_t * mp)
15366{
15367 vat_json_node_t *node = NULL;
15368 vat_main_t *vam = &vat_main;
15369
15370 if (VAT_JSON_ARRAY != vam->json_tree.type)
15371 {
15372 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15373 vat_json_init_array (&vam->json_tree);
15374 }
15375
15376 node = vat_json_array_add (&vam->json_tree);
15377 vat_json_init_object (node);
15378
15379 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15380 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15381 vat_json_object_add_uint (node, "transport_protocol",
15382 mp->transport_protocol);
15383}
15384
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015385static int
15386api_sw_interface_span_enable_disable (vat_main_t * vam)
15387{
15388 unformat_input_t *i = vam->input;
15389 vl_api_sw_interface_span_enable_disable_t *mp;
15390 f64 timeout;
15391 u32 src_sw_if_index = ~0;
15392 u32 dst_sw_if_index = ~0;
15393 u8 enable = 1;
15394
15395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15396 {
15397 if (unformat (i, "src %U", unformat_sw_if_index, vam, &src_sw_if_index))
15398 ;
15399 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
15400 ;
15401 else
15402 if (unformat
15403 (i, "dst %U", unformat_sw_if_index, vam, &dst_sw_if_index))
15404 ;
15405 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
15406 ;
15407 else if (unformat (i, "disable"))
15408 enable = 0;
15409 else
15410 break;
15411 }
15412
15413 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable);
15414
15415 mp->sw_if_index_from = htonl (src_sw_if_index);
15416 mp->sw_if_index_to = htonl (dst_sw_if_index);
15417 mp->enable = enable;
15418
15419 S;
15420 W;
15421 /* NOTREACHED */
15422 return 0;
15423}
15424
15425static void
15426vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
15427 * mp)
15428{
15429 vat_main_t *vam = &vat_main;
15430
15431 fformat (vam->ofp, "%u => %u\n",
15432 ntohl (mp->sw_if_index_from), ntohl (mp->sw_if_index_to));
15433}
15434
15435static void
15436 vl_api_sw_interface_span_details_t_handler_json
15437 (vl_api_sw_interface_span_details_t * mp)
15438{
15439 vat_main_t *vam = &vat_main;
15440 vat_json_node_t *node = NULL;
15441
15442 if (VAT_JSON_ARRAY != vam->json_tree.type)
15443 {
15444 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15445 vat_json_init_array (&vam->json_tree);
15446 }
15447 node = vat_json_array_add (&vam->json_tree);
15448
15449 vat_json_init_object (node);
15450 vat_json_object_add_uint (node, "src-if-index",
15451 ntohl (mp->sw_if_index_from));
15452 vat_json_object_add_uint (node, "dst-if-index", ntohl (mp->sw_if_index_to));
15453}
15454
15455static int
15456api_sw_interface_span_dump (vat_main_t * vam)
15457{
15458 vl_api_sw_interface_span_dump_t *mp;
15459 f64 timeout;
15460
15461 M (SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump);
15462 S;
15463
15464 /* Use a control ping for synchronization */
15465 {
15466 vl_api_control_ping_t *mp;
15467 M (CONTROL_PING, control_ping);
15468 S;
15469 }
15470 W;
15471}
15472
Dave Barach72d72232016-08-04 10:15:08 -040015473int
15474api_pg_create_interface (vat_main_t * vam)
15475{
15476 unformat_input_t *input = vam->input;
15477 vl_api_pg_create_interface_t *mp;
15478 f64 timeout;
15479
15480 u32 if_id = ~0;
15481 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15482 {
15483 if (unformat (input, "if_id %d", &if_id))
15484 ;
15485 else
15486 break;
15487 }
15488 if (if_id == ~0)
15489 {
15490 errmsg ("missing pg interface index\n");
15491 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015492 }
15493
Dave Barach72d72232016-08-04 10:15:08 -040015494 /* Construct the API message */
15495 M (PG_CREATE_INTERFACE, pg_create_interface);
15496 mp->context = 0;
15497 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070015498
Dave Barach72d72232016-08-04 10:15:08 -040015499 S;
15500 W;
15501 /* NOTREACHED */
15502 return 0;
15503}
15504
15505int
15506api_pg_capture (vat_main_t * vam)
15507{
15508 unformat_input_t *input = vam->input;
15509 vl_api_pg_capture_t *mp;
15510 f64 timeout;
15511
15512 u32 if_id = ~0;
15513 u8 enable = 1;
15514 u32 count = 1;
15515 u8 pcap_file_set = 0;
15516 u8 *pcap_file = 0;
15517 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15518 {
15519 if (unformat (input, "if_id %d", &if_id))
15520 ;
15521 else if (unformat (input, "pcap %s", &pcap_file))
15522 pcap_file_set = 1;
15523 else if (unformat (input, "count %d", &count))
15524 ;
15525 else if (unformat (input, "disable"))
15526 enable = 0;
15527 else
15528 break;
15529 }
15530 if (if_id == ~0)
15531 {
15532 errmsg ("missing pg interface index\n");
15533 return -99;
15534 }
15535 if (pcap_file_set > 0)
15536 {
15537 if (vec_len (pcap_file) > 255)
15538 {
15539 errmsg ("pcap file name is too long\n");
15540 return -99;
15541 }
15542 }
15543
15544 u32 name_len = vec_len (pcap_file);
15545 /* Construct the API message */
15546 M (PG_CAPTURE, pg_capture);
15547 mp->context = 0;
15548 mp->interface_id = ntohl (if_id);
15549 mp->is_enabled = enable;
15550 mp->count = ntohl (count);
15551 mp->pcap_name_length = ntohl (name_len);
15552 if (pcap_file_set != 0)
15553 {
15554 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
15555 }
15556 vec_free (pcap_file);
15557
15558 S;
15559 W;
15560 /* NOTREACHED */
15561 return 0;
15562}
15563
15564int
15565api_pg_enable_disable (vat_main_t * vam)
15566{
15567 unformat_input_t *input = vam->input;
15568 vl_api_pg_enable_disable_t *mp;
15569 f64 timeout;
15570
15571 u8 enable = 1;
15572 u8 stream_name_set = 0;
15573 u8 *stream_name = 0;
15574 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15575 {
15576 if (unformat (input, "stream %s", &stream_name))
15577 stream_name_set = 1;
15578 else if (unformat (input, "disable"))
15579 enable = 0;
15580 else
15581 break;
15582 }
15583
15584 if (stream_name_set > 0)
15585 {
15586 if (vec_len (stream_name) > 255)
15587 {
15588 errmsg ("stream name too long\n");
15589 return -99;
15590 }
15591 }
15592
15593 u32 name_len = vec_len (stream_name);
15594 /* Construct the API message */
15595 M (PG_ENABLE_DISABLE, pg_enable_disable);
15596 mp->context = 0;
15597 mp->is_enabled = enable;
15598 if (stream_name_set != 0)
15599 {
15600 mp->stream_name_length = ntohl (name_len);
15601 clib_memcpy (mp->stream_name, stream_name, name_len);
15602 }
15603 vec_free (stream_name);
15604
15605 S;
15606 W;
15607 /* NOTREACHED */
15608 return 0;
15609}
15610
15611int
15612api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
15613{
15614 unformat_input_t *input = vam->input;
15615 vl_api_ip_source_and_port_range_check_add_del_t *mp;
15616 f64 timeout;
15617
15618 u16 *low_ports = 0;
15619 u16 *high_ports = 0;
15620 u16 this_low;
15621 u16 this_hi;
15622 ip4_address_t ip4_addr;
15623 ip6_address_t ip6_addr;
15624 u32 length;
15625 u32 tmp, tmp2;
15626 u8 prefix_set = 0;
15627 u32 vrf_id = ~0;
15628 u8 is_add = 1;
15629 u8 is_ipv6 = 0;
15630
15631 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15632 {
15633 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
15634 {
15635 prefix_set = 1;
15636 }
15637 else
15638 if (unformat
15639 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
15640 {
15641 prefix_set = 1;
15642 is_ipv6 = 1;
15643 }
15644 else if (unformat (input, "vrf %d", &vrf_id))
15645 ;
15646 else if (unformat (input, "del"))
15647 is_add = 0;
15648 else if (unformat (input, "port %d", &tmp))
15649 {
15650 if (tmp == 0 || tmp > 65535)
15651 {
15652 errmsg ("port %d out of range", tmp);
15653 return -99;
15654 }
15655 this_low = tmp;
15656 this_hi = this_low + 1;
15657 vec_add1 (low_ports, this_low);
15658 vec_add1 (high_ports, this_hi);
15659 }
15660 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
15661 {
15662 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
15663 {
15664 errmsg ("incorrect range parameters\n");
15665 return -99;
15666 }
15667 this_low = tmp;
15668 /* Note: in debug CLI +1 is added to high before
15669 passing to real fn that does "the work"
15670 (ip_source_and_port_range_check_add_del).
15671 This fn is a wrapper around the binary API fn a
15672 control plane will call, which expects this increment
15673 to have occurred. Hence letting the binary API control
15674 plane fn do the increment for consistency between VAT
15675 and other control planes.
15676 */
15677 this_hi = tmp2;
15678 vec_add1 (low_ports, this_low);
15679 vec_add1 (high_ports, this_hi);
15680 }
15681 else
15682 break;
15683 }
15684
15685 if (prefix_set == 0)
15686 {
15687 errmsg ("<address>/<mask> not specified\n");
15688 return -99;
15689 }
15690
15691 if (vrf_id == ~0)
15692 {
15693 errmsg ("VRF ID required, not specified\n");
15694 return -99;
15695 }
15696
15697 if (vrf_id == 0)
15698 {
15699 errmsg
15700 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15701 return -99;
15702 }
15703
15704 if (vec_len (low_ports) == 0)
15705 {
15706 errmsg ("At least one port or port range required\n");
15707 return -99;
15708 }
15709
15710 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
15711 ip_source_and_port_range_check_add_del);
15712
15713 mp->is_add = is_add;
15714
15715 if (is_ipv6)
15716 {
15717 mp->is_ipv6 = 1;
15718 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
15719 }
15720 else
15721 {
15722 mp->is_ipv6 = 0;
15723 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
15724 }
15725
15726 mp->mask_length = length;
15727 mp->number_of_ranges = vec_len (low_ports);
15728
15729 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
15730 vec_free (low_ports);
15731
15732 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
15733 vec_free (high_ports);
15734
15735 mp->vrf_id = ntohl (vrf_id);
15736
15737 S;
15738 W;
15739 /* NOTREACHED */
15740 return 0;
15741}
15742
15743int
15744api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
15745{
15746 unformat_input_t *input = vam->input;
15747 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
15748 f64 timeout;
15749 u32 sw_if_index = ~0;
15750 int vrf_set = 0;
15751 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
15752 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
15753 u8 is_add = 1;
15754
15755 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15756 {
15757 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15758 ;
15759 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15760 ;
15761 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
15762 vrf_set = 1;
15763 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
15764 vrf_set = 1;
15765 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
15766 vrf_set = 1;
15767 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
15768 vrf_set = 1;
15769 else if (unformat (input, "del"))
15770 is_add = 0;
15771 else
15772 break;
15773 }
15774
15775 if (sw_if_index == ~0)
15776 {
15777 errmsg ("Interface required but not specified\n");
15778 return -99;
15779 }
15780
15781 if (vrf_set == 0)
15782 {
15783 errmsg ("VRF ID required but not specified\n");
15784 return -99;
15785 }
15786
15787 if (tcp_out_vrf_id == 0
15788 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
15789 {
15790 errmsg
15791 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
15792 return -99;
15793 }
15794
15795 /* Construct the API message */
15796 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
15797 ip_source_and_port_range_check_interface_add_del);
15798
15799 mp->sw_if_index = ntohl (sw_if_index);
15800 mp->is_add = is_add;
15801 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
15802 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
15803 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
15804 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
15805
15806 /* send it... */
15807 S;
15808
15809 /* Wait for a reply... */
15810 W;
15811}
15812
15813static int
Matus Fabian694265d2016-08-10 01:55:36 -070015814api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
15815{
15816 unformat_input_t *i = vam->input;
15817 vl_api_ipsec_gre_add_del_tunnel_t *mp;
15818 f64 timeout;
15819 u32 local_sa_id = 0;
15820 u32 remote_sa_id = 0;
15821 ip4_address_t src_address;
15822 ip4_address_t dst_address;
15823 u8 is_add = 1;
15824
15825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15826 {
15827 if (unformat (i, "local_sa %d", &local_sa_id))
15828 ;
15829 else if (unformat (i, "remote_sa %d", &remote_sa_id))
15830 ;
15831 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
15832 ;
15833 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
15834 ;
15835 else if (unformat (i, "del"))
15836 is_add = 0;
15837 else
15838 {
15839 clib_warning ("parse error '%U'", format_unformat_error, i);
15840 return -99;
15841 }
15842 }
15843
15844 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
15845
15846 mp->local_sa_id = ntohl (local_sa_id);
15847 mp->remote_sa_id = ntohl (remote_sa_id);
15848 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
15849 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
15850 mp->is_add = is_add;
15851
15852 S;
15853 W;
15854 /* NOTREACHED */
15855 return 0;
15856}
15857
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070015858static int
15859api_punt (vat_main_t * vam)
15860{
15861 unformat_input_t *i = vam->input;
15862 vl_api_punt_t *mp;
15863 f64 timeout;
15864 u32 ipv = ~0;
15865 u32 protocol = ~0;
15866 u32 port = ~0;
15867 int is_add = 1;
15868
15869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15870 {
15871 if (unformat (i, "ip %d", &ipv))
15872 ;
15873 else if (unformat (i, "protocol %d", &protocol))
15874 ;
15875 else if (unformat (i, "port %d", &port))
15876 ;
15877 else if (unformat (i, "del"))
15878 is_add = 0;
15879 else
15880 {
15881 clib_warning ("parse error '%U'", format_unformat_error, i);
15882 return -99;
15883 }
15884 }
15885
15886 M (PUNT, punt);
15887
15888 mp->is_add = (u8) is_add;
15889 mp->ipv = (u8) ipv;
15890 mp->l4_protocol = (u8) protocol;
15891 mp->l4_port = htons ((u16) port);
15892
15893 S;
15894 W;
15895 /* NOTREACHED */
15896 return 0;
15897}
15898
Matus Fabian694265d2016-08-10 01:55:36 -070015899static void vl_api_ipsec_gre_tunnel_details_t_handler
15900 (vl_api_ipsec_gre_tunnel_details_t * mp)
15901{
15902 vat_main_t *vam = &vat_main;
15903
15904 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
15905 ntohl (mp->sw_if_index),
15906 format_ip4_address, &mp->src_address,
15907 format_ip4_address, &mp->dst_address,
15908 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
15909}
15910
15911static void vl_api_ipsec_gre_tunnel_details_t_handler_json
15912 (vl_api_ipsec_gre_tunnel_details_t * mp)
15913{
15914 vat_main_t *vam = &vat_main;
15915 vat_json_node_t *node = NULL;
15916 struct in_addr ip4;
15917
15918 if (VAT_JSON_ARRAY != vam->json_tree.type)
15919 {
15920 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15921 vat_json_init_array (&vam->json_tree);
15922 }
15923 node = vat_json_array_add (&vam->json_tree);
15924
15925 vat_json_init_object (node);
15926 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
15927 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
15928 vat_json_object_add_ip4 (node, "src_address", ip4);
15929 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
15930 vat_json_object_add_ip4 (node, "dst_address", ip4);
15931 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
15932 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
15933}
15934
15935static int
15936api_ipsec_gre_tunnel_dump (vat_main_t * vam)
15937{
15938 unformat_input_t *i = vam->input;
15939 vl_api_ipsec_gre_tunnel_dump_t *mp;
15940 f64 timeout;
15941 u32 sw_if_index;
15942 u8 sw_if_index_set = 0;
15943
15944 /* Parse args required to build the message */
15945 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15946 {
15947 if (unformat (i, "sw_if_index %d", &sw_if_index))
15948 sw_if_index_set = 1;
15949 else
15950 break;
15951 }
15952
15953 if (sw_if_index_set == 0)
15954 {
15955 sw_if_index = ~0;
15956 }
15957
15958 if (!vam->json_output)
15959 {
15960 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
15961 "sw_if_index", "src_address", "dst_address",
15962 "local_sa_id", "remote_sa_id");
15963 }
15964
15965 /* Get list of gre-tunnel interfaces */
15966 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
15967
15968 mp->sw_if_index = htonl (sw_if_index);
15969
15970 S;
15971
15972 /* Use a control ping for synchronization */
15973 {
15974 vl_api_control_ping_t *mp;
15975 M (CONTROL_PING, control_ping);
15976 S;
15977 }
15978 W;
15979}
15980
15981static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015982api_delete_subif (vat_main_t * vam)
15983{
15984 unformat_input_t *i = vam->input;
15985 vl_api_delete_subif_t *mp;
15986 f64 timeout;
15987 u32 sw_if_index = ~0;
15988
15989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15990 {
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020015991 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15992 ;
Pavel Kotucekd85590a2016-08-26 13:35:40 +020015993 if (unformat (i, "sw_if_index %d", &sw_if_index))
15994 ;
15995 else
15996 break;
15997 }
15998
15999 if (sw_if_index == ~0)
16000 {
16001 errmsg ("missing sw_if_index\n");
16002 return -99;
16003 }
16004
16005 /* Construct the API message */
16006 M (DELETE_SUBIF, delete_subif);
16007 mp->sw_if_index = ntohl (sw_if_index);
16008
16009 S;
16010 W;
16011}
16012
Pavel Kotucek95300d12016-08-26 16:11:36 +020016013#define foreach_pbb_vtr_op \
16014_("disable", L2_VTR_DISABLED) \
16015_("pop", L2_VTR_POP_2) \
16016_("push", L2_VTR_PUSH_2)
16017
16018static int
16019api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
16020{
16021 unformat_input_t *i = vam->input;
16022 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
16023 f64 timeout;
16024 u32 sw_if_index = ~0, vtr_op = ~0;
16025 u16 outer_tag = ~0;
16026 u8 dmac[6], smac[6];
16027 u8 dmac_set = 0, smac_set = 0;
16028 u16 vlanid = 0;
16029 u32 sid = ~0;
16030 u32 tmp;
16031
Dave Barach75665d32016-11-17 11:36:59 -050016032 /* Shut up coverity */
16033 memset (dmac, 0, sizeof (dmac));
16034 memset (smac, 0, sizeof (smac));
16035
Pavel Kotucek95300d12016-08-26 16:11:36 +020016036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16037 {
16038 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16039 ;
16040 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16041 ;
16042 else if (unformat (i, "vtr_op %d", &vtr_op))
16043 ;
16044#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
16045 foreach_pbb_vtr_op
16046#undef _
16047 else if (unformat (i, "translate_pbb_stag"))
16048 {
16049 if (unformat (i, "%d", &tmp))
16050 {
16051 vtr_op = L2_VTR_TRANSLATE_2_1;
16052 outer_tag = tmp;
16053 }
16054 else
16055 {
16056 errmsg
16057 ("translate_pbb_stag operation requires outer tag definition\n");
16058 return -99;
16059 }
16060 }
16061 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
16062 dmac_set++;
16063 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
16064 smac_set++;
16065 else if (unformat (i, "sid %d", &sid))
16066 ;
16067 else if (unformat (i, "vlanid %d", &tmp))
16068 vlanid = tmp;
16069 else
16070 {
16071 clib_warning ("parse error '%U'", format_unformat_error, i);
16072 return -99;
16073 }
16074 }
16075
16076 if ((sw_if_index == ~0) || (vtr_op == ~0))
16077 {
16078 errmsg ("missing sw_if_index or vtr operation\n");
16079 return -99;
16080 }
16081 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
16082 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
16083 {
16084 errmsg
16085 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
16086 return -99;
16087 }
16088
16089 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
16090 mp->sw_if_index = ntohl (sw_if_index);
16091 mp->vtr_op = ntohl (vtr_op);
16092 mp->outer_tag = ntohs (outer_tag);
16093 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
16094 clib_memcpy (mp->b_smac, smac, sizeof (smac));
16095 mp->b_vlanid = ntohs (vlanid);
16096 mp->i_sid = ntohl (sid);
16097
16098 S;
16099 W;
16100 /* NOTREACHED */
16101 return 0;
16102}
16103
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016104static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070016105api_flow_classify_set_interface (vat_main_t * vam)
16106{
16107 unformat_input_t *i = vam->input;
16108 vl_api_flow_classify_set_interface_t *mp;
16109 f64 timeout;
16110 u32 sw_if_index;
16111 int sw_if_index_set;
16112 u32 ip4_table_index = ~0;
16113 u32 ip6_table_index = ~0;
16114 u8 is_add = 1;
16115
16116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16117 {
16118 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16119 sw_if_index_set = 1;
16120 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16121 sw_if_index_set = 1;
16122 else if (unformat (i, "del"))
16123 is_add = 0;
16124 else if (unformat (i, "ip4-table %d", &ip4_table_index))
16125 ;
16126 else if (unformat (i, "ip6-table %d", &ip6_table_index))
16127 ;
16128 else
16129 {
16130 clib_warning ("parse error '%U'", format_unformat_error, i);
16131 return -99;
16132 }
16133 }
16134
16135 if (sw_if_index_set == 0)
16136 {
16137 errmsg ("missing interface name or sw_if_index\n");
16138 return -99;
16139 }
16140
16141 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
16142
16143 mp->sw_if_index = ntohl (sw_if_index);
16144 mp->ip4_table_index = ntohl (ip4_table_index);
16145 mp->ip6_table_index = ntohl (ip6_table_index);
16146 mp->is_add = is_add;
16147
16148 S;
16149 W;
16150 /* NOTREACHED */
16151 return 0;
16152}
16153
16154static int
16155api_flow_classify_dump (vat_main_t * vam)
16156{
16157 unformat_input_t *i = vam->input;
16158 vl_api_flow_classify_dump_t *mp;
16159 f64 timeout = ~0;
16160 u8 type = FLOW_CLASSIFY_N_TABLES;
16161
16162 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
16163 ;
16164 else
16165 {
16166 errmsg ("classify table type must be specified\n");
16167 return -99;
16168 }
16169
16170 if (!vam->json_output)
16171 {
16172 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
16173 }
16174
16175 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
16176 mp->type = type;
16177 /* send it... */
16178 S;
16179
16180 /* Use a control ping for synchronization */
16181 {
16182 vl_api_control_ping_t *mp;
16183 M (CONTROL_PING, control_ping);
16184 S;
16185 }
16186 /* Wait for a reply... */
16187 W;
16188
16189 /* NOTREACHED */
16190 return 0;
16191}
16192
16193static int
Pavel Kotucek7490a752016-11-15 09:19:11 +010016194api_feature_enable_disable (vat_main_t * vam)
16195{
16196 unformat_input_t *i = vam->input;
16197 vl_api_feature_enable_disable_t *mp;
16198 f64 timeout;
16199 u8 *arc_name = 0;
16200 u8 *feature_name = 0;
16201 u32 sw_if_index = ~0;
16202 u8 enable = 1;
16203
16204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16205 {
16206 if (unformat (i, "arc_name %s", &arc_name))
16207 ;
16208 else if (unformat (i, "feature_name %s", &feature_name))
16209 ;
16210 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16211 ;
16212 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16213 ;
16214 else if (unformat (i, "disable"))
16215 enable = 0;
16216 else
16217 break;
16218 }
16219
16220 if (arc_name == 0)
16221 {
16222 errmsg ("missing arc name\n");
16223 return -99;
16224 }
16225 if (vec_len (arc_name) > 63)
16226 {
16227 errmsg ("arc name too long\n");
16228 }
16229
16230 if (feature_name == 0)
16231 {
16232 errmsg ("missing feature name\n");
16233 return -99;
16234 }
16235 if (vec_len (feature_name) > 63)
16236 {
16237 errmsg ("feature name too long\n");
16238 }
16239
16240 if (sw_if_index == ~0)
16241 {
16242 errmsg ("missing interface name or sw_if_index\n");
16243 return -99;
16244 }
16245
16246 /* Construct the API message */
16247 M (FEATURE_ENABLE_DISABLE, feature_enable_disable);
16248 mp->sw_if_index = ntohl (sw_if_index);
16249 mp->enable = enable;
16250 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
16251 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
16252 vec_free (arc_name);
16253 vec_free (feature_name);
16254
16255 S;
16256 W;
16257}
16258
16259static int
Dave Barach7be864a2016-11-28 11:41:35 -050016260api_sw_interface_tag_add_del (vat_main_t * vam)
16261{
16262 unformat_input_t *i = vam->input;
16263 vl_api_sw_interface_tag_add_del_t *mp;
16264 f64 timeout;
16265 u32 sw_if_index = ~0;
16266 u8 *tag = 0;
16267 u8 enable = 1;
16268
16269 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16270 {
16271 if (unformat (i, "tag %s", &tag))
16272 ;
16273 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16274 ;
16275 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16276 ;
16277 else if (unformat (i, "del"))
16278 enable = 0;
16279 else
16280 break;
16281 }
16282
16283 if (sw_if_index == ~0)
16284 {
16285 errmsg ("missing interface name or sw_if_index\n");
16286 return -99;
16287 }
16288
16289 if (enable && (tag == 0))
16290 {
16291 errmsg ("no tag specified\n");
16292 return -99;
16293 }
16294
16295 /* Construct the API message */
16296 M (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del);
16297 mp->sw_if_index = ntohl (sw_if_index);
16298 mp->is_add = enable;
16299 if (enable)
16300 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
16301 vec_free (tag);
16302
16303 S;
16304 W;
16305}
16306
16307static int
Dave Barach72d72232016-08-04 10:15:08 -040016308q_or_quit (vat_main_t * vam)
16309{
16310 longjmp (vam->jump_buf, 1);
16311 return 0; /* not so much */
16312}
16313
16314static int
16315q (vat_main_t * vam)
16316{
16317 return q_or_quit (vam);
16318}
16319
16320static int
16321quit (vat_main_t * vam)
16322{
16323 return q_or_quit (vam);
16324}
16325
16326static int
16327comment (vat_main_t * vam)
16328{
16329 return 0;
16330}
16331
16332static int
16333cmd_cmp (void *a1, void *a2)
16334{
16335 u8 **c1 = a1;
16336 u8 **c2 = a2;
16337
16338 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
16339}
16340
16341static int
16342help (vat_main_t * vam)
16343{
16344 u8 **cmds = 0;
16345 u8 *name = 0;
16346 hash_pair_t *p;
16347 unformat_input_t *i = vam->input;
16348 int j;
16349
16350 if (unformat (i, "%s", &name))
16351 {
16352 uword *hs;
16353
16354 vec_add1 (name, 0);
16355
16356 hs = hash_get_mem (vam->help_by_name, name);
16357 if (hs)
16358 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
16359 else
16360 fformat (vam->ofp, "No such msg / command '%s'\n", name);
16361 vec_free (name);
16362 return 0;
16363 }
16364
16365 fformat (vam->ofp, "Help is available for the following:\n");
16366
16367 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016368 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070016369 ({
Dave Barach72d72232016-08-04 10:15:08 -040016370 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070016371 }));
Dave Barach72d72232016-08-04 10:15:08 -040016372 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070016373
Dave Barach72d72232016-08-04 10:15:08 -040016374 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016375
Dave Barach72d72232016-08-04 10:15:08 -040016376 for (j = 0; j < vec_len (cmds); j++)
16377 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016378
Dave Barach72d72232016-08-04 10:15:08 -040016379 vec_free (cmds);
16380 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016381}
16382
Dave Barach72d72232016-08-04 10:15:08 -040016383static int
16384set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016385{
Dave Barach72d72232016-08-04 10:15:08 -040016386 u8 *name = 0, *value = 0;
16387 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016388
Dave Barach72d72232016-08-04 10:15:08 -040016389 if (unformat (i, "%s", &name))
16390 {
16391 /* The input buffer is a vector, not a string. */
16392 value = vec_dup (i->buffer);
16393 vec_delete (value, i->index, 0);
16394 /* Almost certainly has a trailing newline */
16395 if (value[vec_len (value) - 1] == '\n')
16396 value[vec_len (value) - 1] = 0;
16397 /* Make sure it's a proper string, one way or the other */
16398 vec_add1 (value, 0);
16399 (void) clib_macro_set_value (&vam->macro_main,
16400 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016401 }
Dave Barach72d72232016-08-04 10:15:08 -040016402 else
16403 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070016404
Dave Barach72d72232016-08-04 10:15:08 -040016405 vec_free (name);
16406 vec_free (value);
16407 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016408}
16409
Dave Barach72d72232016-08-04 10:15:08 -040016410static int
16411unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016412{
Dave Barach72d72232016-08-04 10:15:08 -040016413 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016414
Dave Barach72d72232016-08-04 10:15:08 -040016415 if (unformat (vam->input, "%s", &name))
16416 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
16417 errmsg ("unset: %s wasn't set\n", name);
16418 vec_free (name);
16419 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016420}
16421
Dave Barach72d72232016-08-04 10:15:08 -040016422typedef struct
16423{
16424 u8 *name;
16425 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016426} macro_sort_t;
16427
16428
Dave Barach72d72232016-08-04 10:15:08 -040016429static int
16430macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016431{
Dave Barach72d72232016-08-04 10:15:08 -040016432 macro_sort_t *s1 = a1;
16433 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016434
Dave Barach72d72232016-08-04 10:15:08 -040016435 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050016436}
16437
Dave Barach72d72232016-08-04 10:15:08 -040016438static int
16439dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016440{
Dave Barach72d72232016-08-04 10:15:08 -040016441 macro_sort_t *sort_me = 0, *sm;
16442 int i;
16443 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016444
Dave Barach72d72232016-08-04 10:15:08 -040016445 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016446 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070016447 ({
Dave Barach72d72232016-08-04 10:15:08 -040016448 vec_add2 (sort_me, sm, 1);
16449 sm->name = (u8 *)(p->key);
16450 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016451 }));
Dave Barach72d72232016-08-04 10:15:08 -040016452 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016453
Dave Barach72d72232016-08-04 10:15:08 -040016454 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016455
Dave Barach72d72232016-08-04 10:15:08 -040016456 if (vec_len (sort_me))
16457 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
16458 else
16459 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070016460
Dave Barach72d72232016-08-04 10:15:08 -040016461 for (i = 0; i < vec_len (sort_me); i++)
16462 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
16463 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016464}
16465
Dave Barach72d72232016-08-04 10:15:08 -040016466static int
16467dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016468{
Dave Barach72d72232016-08-04 10:15:08 -040016469 int i, j;
16470 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016471
Dave Barach72d72232016-08-04 10:15:08 -040016472 if (vec_len (vam->graph_nodes) == 0)
16473 {
16474 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16475 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016476 }
16477
Dave Barach72d72232016-08-04 10:15:08 -040016478 for (i = 0; i < vec_len (vam->graph_nodes); i++)
16479 {
16480 node = vam->graph_nodes[i];
16481 fformat (vam->ofp, "[%d] %s\n", i, node->name);
16482 for (j = 0; j < vec_len (node->next_nodes); j++)
16483 {
16484 if (node->next_nodes[j] != ~0)
16485 {
16486 next_node = vam->graph_nodes[node->next_nodes[j]];
16487 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16488 }
16489 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016490 }
Dave Barach72d72232016-08-04 10:15:08 -040016491 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016492}
16493
Dave Barach72d72232016-08-04 10:15:08 -040016494static int
Dave Barach557d1282016-11-10 14:22:49 -050016495value_sort_cmp (void *a1, void *a2)
16496{
16497 name_sort_t *n1 = a1;
16498 name_sort_t *n2 = a2;
16499
16500 if (n1->value < n2->value)
16501 return -1;
16502 if (n1->value > n2->value)
16503 return 1;
16504 return 0;
16505}
16506
16507
16508static int
16509dump_msg_api_table (vat_main_t * vam)
16510{
16511 api_main_t *am = &api_main;
16512 name_sort_t *nses = 0, *ns;
16513 hash_pair_t *hp;
16514 int i;
16515
16516 /* *INDENT-OFF* */
16517 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
16518 ({
16519 vec_add2 (nses, ns, 1);
16520 ns->name = (u8 *)(hp->key);
16521 ns->value = (u32) hp->value[0];
16522 }));
16523 /* *INDENT-ON* */
16524
16525 vec_sort_with_function (nses, value_sort_cmp);
16526
16527 for (i = 0; i < vec_len (nses); i++)
16528 fformat (vam->ofp, " [%d]: %s\n", nses[i].value, nses[i].name);
16529 vec_free (nses);
16530 return 0;
16531}
16532
16533static int
16534get_msg_id (vat_main_t * vam)
16535{
16536 u8 *name_and_crc;
16537 u32 message_index;
16538
16539 if (unformat (vam->input, "%s", &name_and_crc))
16540 {
16541 message_index = vl_api_get_msg_index (name_and_crc);
16542 if (message_index == ~0)
16543 {
16544 fformat (vam->ofp, " '%s' not found\n", name_and_crc);
16545 return 0;
16546 }
16547 fformat (vam->ofp, " '%s' has message index %d\n",
16548 name_and_crc, message_index);
16549 return 0;
16550 }
16551 errmsg ("name_and_crc required...\n");
16552 return 0;
16553}
16554
16555static int
Dave Barach72d72232016-08-04 10:15:08 -040016556search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050016557{
Dave Barach72d72232016-08-04 10:15:08 -040016558 unformat_input_t *line_input = vam->input;
16559 u8 *node_to_find;
16560 int j;
16561 vlib_node_t *node, *next_node;
16562 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016563
Dave Barach72d72232016-08-04 10:15:08 -040016564 if (vam->graph_node_index_by_name == 0)
16565 {
16566 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
16567 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016568 }
16569
Dave Barach72d72232016-08-04 10:15:08 -040016570 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
16571 {
16572 if (unformat (line_input, "%s", &node_to_find))
16573 {
16574 vec_add1 (node_to_find, 0);
16575 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
16576 if (p == 0)
16577 {
16578 fformat (vam->ofp, "%s not found...\n", node_to_find);
16579 goto out;
16580 }
16581 node = vam->graph_nodes[p[0]];
16582 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
16583 for (j = 0; j < vec_len (node->next_nodes); j++)
16584 {
16585 if (node->next_nodes[j] != ~0)
16586 {
16587 next_node = vam->graph_nodes[node->next_nodes[j]];
16588 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
16589 }
16590 }
16591 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016592
Dave Barach72d72232016-08-04 10:15:08 -040016593 else
16594 {
16595 clib_warning ("parse error '%U'", format_unformat_error,
16596 line_input);
16597 return -99;
16598 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050016599
16600 out:
Dave Barach72d72232016-08-04 10:15:08 -040016601 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016602
Dave Barachb44e9bc2016-02-19 09:06:23 -050016603 }
16604
Dave Barach72d72232016-08-04 10:15:08 -040016605 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050016606}
16607
16608
Dave Barach72d72232016-08-04 10:15:08 -040016609static int
16610script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016611{
Dave Barach72d72232016-08-04 10:15:08 -040016612 u8 *s = 0;
16613 char *save_current_file;
16614 unformat_input_t save_input;
16615 jmp_buf save_jump_buf;
16616 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016617
Dave Barach72d72232016-08-04 10:15:08 -040016618 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016619
Dave Barach72d72232016-08-04 10:15:08 -040016620 if (unformat (vam->input, "%s", &s))
16621 {
16622 new_fp = fopen ((char *) s, "r");
16623 if (new_fp == 0)
16624 {
16625 errmsg ("Couldn't open script file %s\n", s);
16626 vec_free (s);
16627 return -99;
16628 }
16629 }
16630 else
16631 {
16632 errmsg ("Missing script name\n");
16633 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016634 }
16635
Dave Barach72d72232016-08-04 10:15:08 -040016636 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
16637 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
16638 save_ifp = vam->ifp;
16639 save_line_number = vam->input_line_number;
16640 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016641
Dave Barach72d72232016-08-04 10:15:08 -040016642 vam->input_line_number = 0;
16643 vam->ifp = new_fp;
16644 vam->current_file = s;
16645 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016646
Dave Barach72d72232016-08-04 10:15:08 -040016647 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
16648 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
16649 vam->ifp = save_ifp;
16650 vam->input_line_number = save_line_number;
16651 vam->current_file = (u8 *) save_current_file;
16652 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016653
Dave Barach72d72232016-08-04 10:15:08 -040016654 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016655}
16656
Dave Barach72d72232016-08-04 10:15:08 -040016657static int
16658echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070016659{
Dave Barach72d72232016-08-04 10:15:08 -040016660 fformat (vam->ofp, "%v", vam->input->buffer);
16661 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016662}
16663
16664/* List of API message constructors, CLI names map to api_xxx */
16665#define foreach_vpe_api_msg \
16666_(create_loopback,"[mac <mac-addr>]") \
16667_(sw_interface_dump,"") \
16668_(sw_interface_set_flags, \
16669 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
16670_(sw_interface_add_del_address, \
16671 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
16672_(sw_interface_set_table, \
16673 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040016674_(sw_interface_set_mpls_enable, \
16675 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016676_(sw_interface_set_vpath, \
16677 "<intfc> | sw_if_index <id> enable | disable") \
John Lo37682e12016-11-30 12:51:39 -050016678_(sw_interface_set_vxlan_bypass, \
16679 "<intfc> | sw_if_index <id> [ip4 | ip6] enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016680_(sw_interface_set_l2_xconnect, \
16681 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16682 "enable | disable") \
16683_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040016684 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016685 "[shg <split-horizon-group>] [bvi]\n" \
16686 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010016687_(sw_interface_set_dpdk_hqos_pipe, \
16688 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
16689 "profile <profile-id>\n") \
16690_(sw_interface_set_dpdk_hqos_subport, \
16691 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
16692 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
16693_(sw_interface_set_dpdk_hqos_tctbl, \
16694 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016695_(bridge_domain_add_del, \
16696 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
16697_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
16698_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070016699 "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 -070016700_(l2_flags, \
16701 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
16702_(bridge_flags, \
16703 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
16704_(tap_connect, \
Dave Barach7be864a2016-11-28 11:41:35 -050016705 "tapname <name> mac <mac-addr> | random-mac [tag <string>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016706_(tap_modify, \
16707 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
16708_(tap_delete, \
16709 "<vpp-if-name> | sw_if_index <id>") \
16710_(sw_interface_tap_dump, "") \
16711_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016712 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016713 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16714 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16715 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016716_(mpls_route_add_del, \
16717 "<label> <eos> via <addr> [table-id <n>]\n" \
16718 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
16719 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
16720 "[multipath] [count <n>]") \
16721_(mpls_ip_bind_unbind, \
16722 "<label> <addr/len>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000016723_(mpls_tunnel_add_del, \
16724 " via <addr> [table-id <n>]\n" \
16725 "sw_if_index <id>] [l2] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016726_(proxy_arp_add_del, \
16727 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
16728_(proxy_arp_intfc_enable_disable, \
16729 "<intfc> | sw_if_index <id> enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016730_(sw_interface_set_unnumbered, \
16731 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
16732_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040016733 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
16734 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016735_(reset_vrf, "vrf <id> [ipv6]") \
16736_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
16737_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
16738 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
16739 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
16740 "[outer_vlan_id_any][inner_vlan_id_any]") \
16741_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
16742_(reset_fib, "vrf <n> [ipv6]") \
16743_(dhcp_proxy_config, \
16744 "svr <v46-address> src <v46-address>\n" \
16745 "insert-cid <n> [del]") \
16746_(dhcp_proxy_config_2, \
16747 "svr <v46-address> src <v46-address>\n" \
16748 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
16749_(dhcp_proxy_set_vss, \
16750 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
16751_(dhcp_client_config, \
16752 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
16753_(set_ip_flow_hash, \
16754 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
16755_(sw_interface_ip6_enable_disable, \
16756 "<intfc> | sw_if_index <id> enable | disable") \
16757_(sw_interface_ip6_set_link_local_address, \
16758 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
16759_(sw_interface_ip6nd_ra_prefix, \
16760 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
16761 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
16762 "[nolink] [isno]") \
16763_(sw_interface_ip6nd_ra_config, \
16764 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040016765 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016766 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
16767_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
16768_(l2_patch_add_del, \
16769 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
16770 "enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016771_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070016772 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
16773 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
16774 "[policy <policy_name>]") \
16775_(sr_policy_add_del, \
16776 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
16777_(sr_multicast_map_add_del, \
16778 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016779_(classify_add_del_table, \
16780 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080016781 " [del] mask <mask-value>\n" \
16782 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
16783 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016784_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016785 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
16786 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080016787 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
16788 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016789_(classify_set_interface_ip_table, \
16790 "<intfc> | sw_if_index <nn> table <nn>") \
16791_(classify_set_interface_l2_tables, \
16792 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16793 " [other-table <nn>]") \
16794_(get_node_index, "node <node-name") \
16795_(add_node_next, "node <node-name> next <next-node-name>") \
16796_(l2tpv3_create_tunnel, \
16797 "client_address <ip6-addr> our_address <ip6-addr>\n" \
16798 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
16799 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
16800_(l2tpv3_set_tunnel_cookies, \
16801 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
16802 "[new_remote_cookie <nn>]\n") \
16803_(l2tpv3_interface_enable_disable, \
16804 "<intfc> | sw_if_index <nn> enable | disable") \
16805_(l2tpv3_set_lookup_key, \
16806 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
16807_(sw_if_l2tpv3_tunnel_dump, "") \
16808_(vxlan_add_del_tunnel, \
Eyal Baric5b13602016-11-24 19:42:43 +020016809 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
16810 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
16811 "vni <vni> [encap-vrf-id <nn>] [decap-next l2|ip4|ip6] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050016812_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016813_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070016814 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040016815_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016816_(l2_fib_clear_table, "") \
16817_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
16818_(l2_interface_vlan_tag_rewrite, \
16819 "<intfc> | sw_if_index <nn> \n" \
16820 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
16821 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
16822_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000016823 "socket <filename> [server] [renumber <dev_instance>] " \
16824 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016825_(modify_vhost_user_if, \
16826 "<intfc> | sw_if_index <nn> socket <filename>\n" \
16827 "[server] [renumber <dev_instance>]") \
16828_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
16829_(sw_interface_vhost_user_dump, "") \
16830_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080016831_(vxlan_gpe_add_del_tunnel, \
16832 "local <addr> remote <addr> vni <nn>\n" \
16833 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
16834 "[next-ethernet] [next-nsh]\n") \
16835_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016836_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016837_(interface_name_renumber, \
16838 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
16839_(input_acl_set_interface, \
16840 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16841 " [l2-table <nn>] [del]") \
16842_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040016843_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016844_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
16845_(ip_dump, "ipv4 | ipv6") \
16846_(ipsec_spd_add_del, "spd_id <n> [del]") \
16847_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
16848 " spid_id <n> ") \
16849_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
16850 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
16851 " integ_alg <alg> integ_key <hex>") \
16852_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
16853 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
16854 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
16855 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
16856_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020016857_(ikev2_profile_add_del, "name <profile_name> [del]") \
16858_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
16859 "(auth_data 0x<data> | auth_data <data>)") \
16860_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
16861 "(id_data 0x<data> | id_data <data>) (local|remote)") \
16862_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
16863 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
16864 "(local|remote)") \
16865_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016866_(delete_loopback,"sw_if_index <nn>") \
16867_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
16868_(map_add_domain, \
16869 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
16870 "ip6-src <ip6addr> " \
16871 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
16872_(map_del_domain, "index <n>") \
16873_(map_add_del_rule, \
16874 "index <n> psid <n> dst <ip6addr> [del]") \
16875_(map_domain_dump, "") \
16876_(map_rule_dump, "index <map-domain>") \
16877_(want_interface_events, "enable|disable") \
16878_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050016879_(get_first_msg_id, "client <name>") \
16880_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
16881_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016882 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010016883_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000016884_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070016885_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
16886_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020016887_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
16888 " sw_if_index <sw_if_index> p <priority> " \
16889 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016890_(lisp_add_del_locator, "locator-set <locator_name> " \
16891 "iface <intf> | sw_if_index <sw_if_index> " \
16892 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016893_(lisp_add_del_local_eid,"vni <vni> eid " \
16894 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016895 "locator-set <locator_name> [del]") \
Florin Coras429e7952016-08-02 02:31:03 +020016896_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
16897 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016898_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020016899_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020016900_(lisp_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016901_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016902_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
16903 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016904 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020016905 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020016906 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020016907_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
16908 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020016909_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020016910_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016911_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020016912_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020016913_(lisp_locator_set_dump, "[local | remote]") \
16914_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020016915_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
16916 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020016917_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020016918_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020016919_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020016920_(lisp_map_resolver_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020016921_(lisp_adjacencies_get, "vni <vni>") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020016922_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020016923_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020016924_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020016925_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020016926_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070016927_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016928_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070016929_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070016930_(policer_classify_set_interface, \
16931 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
16932 " [l2-table <nn>] [del]") \
16933_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070016934_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
16935 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020016936_(netmap_delete, "name <interface name>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000016937_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070016938_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020016939_(classify_table_ids, "") \
16940_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
16941_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070016942_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070016943_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
16944 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
16945 "[template_interval <nn>] [udp_checksum]") \
16946_(ipfix_exporter_dump, "") \
16947_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
16948_(ipfix_classify_stream_dump, "") \
16949_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
16950_(ipfix_classify_table_dump, "") \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016951_(sw_interface_span_enable_disable, "[src <intfc> | src_sw_if_index <id>] [[dst <intfc> | dst_sw_if_index <id>] | disable]") \
16952_(sw_interface_span_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020016953_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
16954_(pg_create_interface, "if_id <nn>") \
16955_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040016956_(pg_enable_disable, "[stream <id>] disable") \
16957_(ip_source_and_port_range_check_add_del, \
16958 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
16959_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070016960 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070016961 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
16962_(ipsec_gre_add_del_tunnel, \
16963 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016964_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016965_(delete_subif,"<intfc> | sw_if_index <nn>") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020016966_(l2_interface_pbb_tag_rewrite, \
16967 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016968 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
16969 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070016970_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
16971_(flow_classify_set_interface, \
16972 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
Steven01b07122016-11-02 10:40:09 -070016973_(flow_classify_dump, "type [ip4|ip6]") \
16974_(ip_fib_dump, "") \
Pavel Kotucek7490a752016-11-15 09:19:11 +010016975_(ip6_fib_dump, "") \
16976_(feature_enable_disable, "arc_name <arc_name> " \
Dave Barach7be864a2016-11-28 11:41:35 -050016977 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
16978_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
16979"[disable]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070016980
16981/* List of command functions, CLI names map directly to functions */
16982#define foreach_cli_function \
16983_(comment, "usage: comment <ignore-rest-of-line>") \
16984_(dump_interface_table, "usage: dump_interface_table") \
16985_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
16986_(dump_ipv4_table, "usage: dump_ipv4_table") \
16987_(dump_ipv6_table, "usage: dump_ipv6_table") \
16988_(dump_stats_table, "usage: dump_stats_table") \
16989_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016990_(dump_node_table, "usage: dump_node_table") \
Dave Barach557d1282016-11-10 14:22:49 -050016991_(dump_msg_api_table, "usage: dump_msg_api_table") \
16992_(get_msg_id, "usage: get_msg_id name_and_crc") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016993_(echo, "usage: echo <message>") \
16994_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020016995_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070016996_(help, "usage: help") \
16997_(q, "usage: quit") \
16998_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050016999_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017000_(set, "usage: set <variable-name> <value>") \
17001_(script, "usage: script <file-name>") \
17002_(unset, "usage: unset <variable-name>")
17003
17004#define _(N,n) \
17005 static void vl_api_##n##_t_handler_uni \
17006 (vl_api_##n##_t * mp) \
17007 { \
17008 vat_main_t * vam = &vat_main; \
17009 if (vam->json_output) { \
17010 vl_api_##n##_t_handler_json(mp); \
17011 } else { \
17012 vl_api_##n##_t_handler(mp); \
17013 } \
17014 }
17015foreach_vpe_api_reply_msg;
17016#undef _
17017
Dave Barach72d72232016-08-04 10:15:08 -040017018void
17019vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017020{
17021#define _(N,n) \
17022 vl_msg_api_set_handlers(VL_API_##N, #n, \
17023 vl_api_##n##_t_handler_uni, \
17024 vl_noop_handler, \
17025 vl_api_##n##_t_endian, \
17026 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017027 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040017028 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017029#undef _
17030
Dave Barach72d72232016-08-04 10:15:08 -040017031 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017032
Dave Barach72d72232016-08-04 10:15:08 -040017033 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017034
Dave Barach72d72232016-08-04 10:15:08 -040017035 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017036
Dave Barach72d72232016-08-04 10:15:08 -040017037 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017038
Dave Barach72d72232016-08-04 10:15:08 -040017039 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017040#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040017041 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017042#undef _
17043
Dave Barach72d72232016-08-04 10:15:08 -040017044 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017045#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017046 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017047#undef _
17048
Dave Barach72d72232016-08-04 10:15:08 -040017049 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017050#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040017051 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017052#undef _
17053
Dave Barach72d72232016-08-04 10:15:08 -040017054 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017055#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017056 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017057#undef _
17058}
17059
17060#undef vl_api_version
Dave Barachaff70772016-10-31 11:59:07 -040017061#define vl_api_version(n,v) static u32 memory_api_version = v;
17062#include <vlibmemory/vl_memory_api_h.h>
17063#undef vl_api_version
17064
17065#undef vl_api_version
17066#define vl_api_version(n,v) static u32 vnet_interface_api_version = v;
17067#include <vnet/interface.api.h>
17068#undef vl_api_version
17069
17070#undef vl_api_version
17071#define vl_api_version(n,v) static u32 vpp_api_version = v;
Dave Barachaa6920e2016-06-27 09:25:13 -040017072#include <vpp-api/vpe.api.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070017073#undef vl_api_version
17074
Dave Barachaff70772016-10-31 11:59:07 -040017075static u32 *api_versions[] = {
17076 &memory_api_version,
17077 &vnet_interface_api_version,
17078 &vpp_api_version,
17079};
17080
Dave Barach72d72232016-08-04 10:15:08 -040017081void
17082vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017083{
Dave Barachaff70772016-10-31 11:59:07 -040017084 int i;
17085
17086 ASSERT (ARRAY_LEN (mp->api_versions) >= ARRAY_LEN (api_versions));
17087
Dave Barach72d72232016-08-04 10:15:08 -040017088 /*
Dave Barachaff70772016-10-31 11:59:07 -040017089 * Send the API signatures. This bit of code must
Dave Barach72d72232016-08-04 10:15:08 -040017090 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
17091 */
Dave Barachaff70772016-10-31 11:59:07 -040017092
17093 for (i = 0; i < ARRAY_LEN (api_versions); i++)
17094 mp->api_versions[i] = clib_host_to_net_u32 (*api_versions[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017095}
Dave Barach72d72232016-08-04 10:15:08 -040017096
17097/*
17098 * fd.io coding-style-patch-verification: ON
17099 *
17100 * Local Variables:
17101 * eval: (c-set-style "gnu")
17102 * End:
17103 */