blob: c6e5ac8d1daa166624cb1e7e2ef75d4e634d9fa0 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 *------------------------------------------------------------------
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003 * api_format.c
4 *
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07005 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080016 * limitations under the License.
Ed Warnickecb9cada2015-12-08 15:45:58 -070017 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlibapi/api.h>
22#include <vlibmemory/api.h>
23#include <vlibsocket/api.h>
24#include <vnet/ip/ip.h>
25#include <vnet/sr/sr_packet.h>
26#include <vnet/l2/l2_input.h>
27#include <vnet/l2tp/l2tp.h>
28#include <vnet/vxlan/vxlan.h>
Chris Luke27fe48f2016-04-28 13:44:38 -040029#include <vnet/gre/gre.h>
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070030#include <vnet/vxlan-gpe/vxlan_gpe.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031#include <vnet/lisp-gpe/lisp_gpe.h>
32
Dave Barachaa6920e2016-06-27 09:25:13 -040033#include <vpp-api/vpe_msg_enum.h>
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080034#include <vnet/l2/l2_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#include <vnet/l2/l2_vtr.h>
36#include <vnet/classify/input_acl.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070037#include <vnet/classify/policer_classify.h>
Juraj Sloboda506b2452016-08-07 23:45:24 -070038#include <vnet/classify/flow_classify.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039#include <vnet/mpls/mpls.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#include <vnet/ipsec/ipsec.h>
Matus Fabiane5f42fe2016-04-08 11:18:08 +020041#include <vnet/ipsec/ikev2.h>
Dave Barachbfdedbd2016-01-20 09:11:55 -050042#include <inttypes.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070043#include <vnet/map/map.h>
Dave Barachc07bf5d2016-02-17 17:52:26 -050044#include <vnet/cop/cop.h>
Shwetha20a64f52016-03-25 10:55:01 +000045#include <vnet/ip/ip6_hop_by_hop.h>
Dave Barach6f9bca22016-04-30 10:25:32 -040046#include <vnet/ip/ip_source_and_port_range_check.h>
Matus Fabian65fcd4d2016-05-13 05:44:48 -070047#include <vnet/policer/xlate.h>
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010048#include <vnet/span/span.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070049#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070050#include <vnet/policer/police.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
52#include "vat/json_format.h"
53
Damjan Marion67655492016-11-15 12:50:28 +010054#include <inttypes.h>
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020055#include <sys/stat.h>
56
Dave Barach72d72232016-08-04 10:15:08 -040057#define vl_typedefs /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080058#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070059#undef vl_typedefs
60
61/* declare message handlers for each api */
62
Dave Barach72d72232016-08-04 10:15:08 -040063#define vl_endianfun /* define message structures */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080064#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070065#undef vl_endianfun
66
67/* instantiate all the print functions we know about */
68#define vl_print(handle, ...)
69#define vl_printfun
Dave Barachaa6920e2016-06-27 09:25:13 -040070#include <vpp-api/vpe_all_api_h.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#undef vl_printfun
72
Dave Barach72d72232016-08-04 10:15:08 -040073uword
74unformat_sw_if_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
Dave Barach72d72232016-08-04 10:15:08 -040076 vat_main_t *vam = va_arg (*args, vat_main_t *);
77 u32 *result = va_arg (*args, u32 *);
78 u8 *if_name;
79 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 if (!unformat (input, "%s", &if_name))
Dave Barach72d72232016-08-04 10:15:08 -040082 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
84 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
85 if (p == 0)
Dave Barach72d72232016-08-04 10:15:08 -040086 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 *result = p[0];
88 return 1;
89}
90
91/* Parse an IP4 address %d.%d.%d.%d. */
Dave Barach72d72232016-08-04 10:15:08 -040092uword
93unformat_ip4_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070094{
Dave Barach72d72232016-08-04 10:15:08 -040095 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 unsigned a[4];
97
Dave Barach72d72232016-08-04 10:15:08 -040098 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 return 0;
100
101 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 return 0;
103
104 result[0] = a[0];
105 result[1] = a[1];
106 result[2] = a[2];
107 result[3] = a[3];
108
109 return 1;
110}
111
112
113uword
114unformat_ethernet_address (unformat_input_t * input, va_list * args)
115{
Dave Barach72d72232016-08-04 10:15:08 -0400116 u8 *result = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u32 i, a[6];
118
Dave Barach72d72232016-08-04 10:15:08 -0400119 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
120 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 return 0;
122
123 /* Check range. */
124 for (i = 0; i < 6; i++)
125 if (a[i] >= (1 << 8))
126 return 0;
127
128 for (i = 0; i < 6; i++)
129 result[i] = a[i];
130
131 return 1;
132}
133
134/* Returns ethernet type as an int in host byte order. */
135uword
136unformat_ethernet_type_host_byte_order (unformat_input_t * input,
137 va_list * args)
138{
Dave Barach72d72232016-08-04 10:15:08 -0400139 u16 *result = va_arg (*args, u16 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140 int type;
141
142 /* Numeric type. */
Dave Barach72d72232016-08-04 10:15:08 -0400143 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 {
145 if (type >= (1 << 16))
146 return 0;
147 *result = type;
148 return 1;
149 }
150 return 0;
151}
152
153/* Parse an IP6 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400154uword
155unformat_ip6_address (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156{
Dave Barach72d72232016-08-04 10:15:08 -0400157 ip6_address_t *result = va_arg (*args, ip6_address_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 u16 hex_quads[8];
159 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
160 uword c, n_colon, double_colon_index;
161
162 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
163 double_colon_index = ARRAY_LEN (hex_quads);
164 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
165 {
166 hex_digit = 16;
167 if (c >= '0' && c <= '9')
168 hex_digit = c - '0';
169 else if (c >= 'a' && c <= 'f')
170 hex_digit = c + 10 - 'a';
171 else if (c >= 'A' && c <= 'F')
172 hex_digit = c + 10 - 'A';
173 else if (c == ':' && n_colon < 2)
174 n_colon++;
175 else
176 {
177 unformat_put_input (input);
178 break;
179 }
180
181 /* Too many hex quads. */
182 if (n_hex_quads >= ARRAY_LEN (hex_quads))
183 return 0;
184
185 if (hex_digit < 16)
186 {
187 hex_quad = (hex_quad << 4) | hex_digit;
188
189 /* Hex quad must fit in 16 bits. */
190 if (n_hex_digits >= 4)
191 return 0;
192
193 n_colon = 0;
194 n_hex_digits++;
195 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800196
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197 /* Save position of :: */
198 if (n_colon == 2)
199 {
200 /* More than one :: ? */
201 if (double_colon_index < ARRAY_LEN (hex_quads))
202 return 0;
203 double_colon_index = n_hex_quads;
204 }
205
206 if (n_colon > 0 && n_hex_digits > 0)
207 {
208 hex_quads[n_hex_quads++] = hex_quad;
209 hex_quad = 0;
210 n_hex_digits = 0;
211 }
212 }
213
214 if (n_hex_digits > 0)
215 hex_quads[n_hex_quads++] = hex_quad;
216
217 {
218 word i;
219
220 /* Expand :: to appropriate number of zero hex quads. */
221 if (double_colon_index < ARRAY_LEN (hex_quads))
222 {
223 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
224
225 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
226 hex_quads[n_zero + i] = hex_quads[i];
227
228 for (i = 0; i < n_zero; i++)
229 hex_quads[double_colon_index + i] = 0;
230
231 n_hex_quads = ARRAY_LEN (hex_quads);
232 }
233
234 /* Too few hex quads given. */
235 if (n_hex_quads < ARRAY_LEN (hex_quads))
236 return 0;
237
238 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
239 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
240
241 return 1;
242 }
243}
244
245uword
246unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
247{
Dave Barach72d72232016-08-04 10:15:08 -0400248 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249
Dave Barach72d72232016-08-04 10:15:08 -0400250 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
252 foreach_ipsec_policy_action
253#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400254 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255 return 0;
256 return 1;
257}
258
259uword
260unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
261{
Dave Barach72d72232016-08-04 10:15:08 -0400262 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263
Dave Barach72d72232016-08-04 10:15:08 -0400264 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
266 foreach_ipsec_crypto_alg
267#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400268 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269 return 0;
270 return 1;
271}
272
273u8 *
274format_ipsec_crypto_alg (u8 * s, va_list * args)
275{
276 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400277 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
279 switch (i)
280 {
281#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400282 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400284 default:
285 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286 }
287 return format (s, "%s", t);
288}
289
290uword
291unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
292{
Dave Barach72d72232016-08-04 10:15:08 -0400293 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
Dave Barach72d72232016-08-04 10:15:08 -0400295 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
297 foreach_ipsec_integ_alg
298#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400299 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300 return 0;
301 return 1;
302}
303
304u8 *
305format_ipsec_integ_alg (u8 * s, va_list * args)
306{
307 u32 i = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -0400308 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309
310 switch (i)
311 {
312#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Dave Barach72d72232016-08-04 10:15:08 -0400313 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400315 default:
316 return format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317 }
318 return format (s, "%s", t);
319}
320
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200321uword
322unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
323{
Dave Barach72d72232016-08-04 10:15:08 -0400324 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200325
Dave Barach72d72232016-08-04 10:15:08 -0400326 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200327#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
328 foreach_ikev2_auth_method
329#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400330 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200331 return 0;
332 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200333}
334
335uword
336unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
337{
Dave Barach72d72232016-08-04 10:15:08 -0400338 u32 *r = va_arg (*args, u32 *);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200339
Dave Barach72d72232016-08-04 10:15:08 -0400340 if (0);
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200341#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
342 foreach_ikev2_id_type
343#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400344 else
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200345 return 0;
346 return 1;
Matus Fabiane5f42fe2016-04-08 11:18:08 +0200347}
348
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700349uword
350unformat_policer_rate_type (unformat_input_t * input, va_list * args)
351{
Dave Barach72d72232016-08-04 10:15:08 -0400352 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700353
354 if (unformat (input, "kbps"))
355 *r = SSE2_QOS_RATE_KBPS;
Dave Barach72d72232016-08-04 10:15:08 -0400356 else if (unformat (input, "pps"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700357 *r = SSE2_QOS_RATE_PPS;
358 else
359 return 0;
360 return 1;
361}
362
363uword
364unformat_policer_round_type (unformat_input_t * input, va_list * args)
365{
Dave Barach72d72232016-08-04 10:15:08 -0400366 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700367
Dave Barach72d72232016-08-04 10:15:08 -0400368 if (unformat (input, "closest"))
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700369 *r = SSE2_QOS_ROUND_TO_CLOSEST;
370 else if (unformat (input, "up"))
371 *r = SSE2_QOS_ROUND_TO_UP;
372 else if (unformat (input, "down"))
373 *r = SSE2_QOS_ROUND_TO_DOWN;
374 else
375 return 0;
376 return 1;
377}
378
379uword
380unformat_policer_type (unformat_input_t * input, va_list * args)
381{
Dave Barach72d72232016-08-04 10:15:08 -0400382 u8 *r = va_arg (*args, u8 *);
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700383
384 if (unformat (input, "1r2c"))
385 *r = SSE2_QOS_POLICER_TYPE_1R2C;
386 else if (unformat (input, "1r3c"))
387 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
388 else if (unformat (input, "2r3c-2698"))
389 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
390 else if (unformat (input, "2r3c-4115"))
391 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
392 else if (unformat (input, "2r3c-mef5cf1"))
393 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
394 else
395 return 0;
396 return 1;
397}
398
Matus Fabian4ac74c92016-05-31 07:33:29 -0700399uword
400unformat_dscp (unformat_input_t * input, va_list * va)
401{
Dave Barach72d72232016-08-04 10:15:08 -0400402 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700403
Dave Barach72d72232016-08-04 10:15:08 -0400404 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700405#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Dave Barach72d72232016-08-04 10:15:08 -0400406 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700407#undef _
Dave Barach72d72232016-08-04 10:15:08 -0400408 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700409 return 0;
410 return 1;
411}
412
413uword
414unformat_policer_action_type (unformat_input_t * input, va_list * va)
415{
Dave Barach72d72232016-08-04 10:15:08 -0400416 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700417 = va_arg (*va, sse2_qos_pol_action_params_st *);
418
419 if (unformat (input, "drop"))
420 a->action_type = SSE2_QOS_ACTION_DROP;
421 else if (unformat (input, "transmit"))
422 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
423 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
424 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
425 else
426 return 0;
427 return 1;
428}
429
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700430uword
Juraj Sloboda506b2452016-08-07 23:45:24 -0700431unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700432{
Dave Barach72d72232016-08-04 10:15:08 -0400433 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700434 u32 tid;
435
436 if (unformat (input, "ip4"))
437 tid = POLICER_CLASSIFY_TABLE_IP4;
438 else if (unformat (input, "ip6"))
439 tid = POLICER_CLASSIFY_TABLE_IP6;
440 else if (unformat (input, "l2"))
441 tid = POLICER_CLASSIFY_TABLE_L2;
442 else
443 return 0;
444
445 *r = tid;
446 return 1;
447}
448
Juraj Sloboda506b2452016-08-07 23:45:24 -0700449uword
450unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
451{
452 u32 *r = va_arg (*va, u32 *);
453 u32 tid;
454
455 if (unformat (input, "ip4"))
456 tid = FLOW_CLASSIFY_TABLE_IP4;
457 else if (unformat (input, "ip6"))
458 tid = FLOW_CLASSIFY_TABLE_IP6;
459 else
460 return 0;
461
462 *r = tid;
463 return 1;
464}
465
Dave Barach72d72232016-08-04 10:15:08 -0400466u8 *
467format_ip4_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468{
Dave Barach72d72232016-08-04 10:15:08 -0400469 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
471}
472
Dave Barach72d72232016-08-04 10:15:08 -0400473u8 *
474format_ip6_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475{
Dave Barach72d72232016-08-04 10:15:08 -0400476 ip6_address_t *a = va_arg (*args, ip6_address_t *);
477 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478
Dave Barach72d72232016-08-04 10:15:08 -0400479 i_max_n_zero = ARRAY_LEN (a->as_u16);
480 max_n_zeros = 0;
481 i_first_zero = i_max_n_zero;
482 n_zeros = 0;
483 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
484 {
485 u32 is_zero = a->as_u16[i] == 0;
486 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
487 {
488 i_first_zero = i;
489 n_zeros = 0;
490 }
491 n_zeros += is_zero;
492 if ((!is_zero && n_zeros > max_n_zeros)
493 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
494 {
495 i_max_n_zero = i_first_zero;
496 max_n_zeros = n_zeros;
497 i_first_zero = ARRAY_LEN (a->as_u16);
498 n_zeros = 0;
499 }
500 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501
Dave Barach72d72232016-08-04 10:15:08 -0400502 last_double_colon = 0;
503 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
504 {
505 if (i == i_max_n_zero && max_n_zeros > 1)
506 {
507 s = format (s, "::");
508 i += max_n_zeros - 1;
509 last_double_colon = 1;
510 }
511 else
512 {
513 s = format (s, "%s%x",
514 (last_double_colon || i == 0) ? "" : ":",
515 clib_net_to_host_u16 (a->as_u16[i]));
516 last_double_colon = 0;
517 }
518 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519
Dave Barach72d72232016-08-04 10:15:08 -0400520 return s;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521}
522
Chris Luke99cb3352016-04-26 10:49:53 -0400523/* Format an IP46 address. */
Dave Barach72d72232016-08-04 10:15:08 -0400524u8 *
525format_ip46_address (u8 * s, va_list * args)
Chris Luke99cb3352016-04-26 10:49:53 -0400526{
527 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
Damjan Marion86be4872016-05-24 23:19:11 +0200528 ip46_type_t type = va_arg (*args, ip46_type_t);
529 int is_ip4 = 1;
530
531 switch (type)
532 {
Dave Barach72d72232016-08-04 10:15:08 -0400533 case IP46_TYPE_ANY:
534 is_ip4 = ip46_address_is_ip4 (ip46);
535 break;
536 case IP46_TYPE_IP4:
537 is_ip4 = 1;
538 break;
539 case IP46_TYPE_IP6:
540 is_ip4 = 0;
541 break;
Damjan Marion86be4872016-05-24 23:19:11 +0200542 }
543
544 return is_ip4 ?
Dave Barach72d72232016-08-04 10:15:08 -0400545 format (s, "%U", format_ip4_address, &ip46->ip4) :
546 format (s, "%U", format_ip6_address, &ip46->ip6);
Chris Luke99cb3352016-04-26 10:49:53 -0400547}
548
Dave Barach72d72232016-08-04 10:15:08 -0400549u8 *
550format_ethernet_address (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700551{
Dave Barach72d72232016-08-04 10:15:08 -0400552 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553
554 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -0400555 a[0], a[1], a[2], a[3], a[4], a[5]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700556}
557
Dave Barach72d72232016-08-04 10:15:08 -0400558void
559increment_v4_address (ip4_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700560{
Dave Barach72d72232016-08-04 10:15:08 -0400561 u32 v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562
Dave Barach72d72232016-08-04 10:15:08 -0400563 v = ntohl (a->as_u32) + 1;
564 a->as_u32 = ntohl (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565}
566
Dave Barach72d72232016-08-04 10:15:08 -0400567void
568increment_v6_address (ip6_address_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569{
Dave Barach72d72232016-08-04 10:15:08 -0400570 u64 v0, v1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571
Dave Barach72d72232016-08-04 10:15:08 -0400572 v0 = clib_net_to_host_u64 (a->as_u64[0]);
573 v1 = clib_net_to_host_u64 (a->as_u64[1]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700574
Dave Barach72d72232016-08-04 10:15:08 -0400575 v1 += 1;
576 if (v1 == 0)
577 v0 += 1;
578 a->as_u64[0] = clib_net_to_host_u64 (v0);
579 a->as_u64[1] = clib_net_to_host_u64 (v1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580}
581
Dave Barach72d72232016-08-04 10:15:08 -0400582void
583increment_mac_address (u64 * mac)
Dave Barach41da02d2016-07-11 16:48:42 -0700584{
Dave Barach72d72232016-08-04 10:15:08 -0400585 u64 tmp = *mac;
Dave Barach41da02d2016-07-11 16:48:42 -0700586
Dave Barach72d72232016-08-04 10:15:08 -0400587 tmp = clib_net_to_host_u64 (tmp);
588 tmp += 1 << 16; /* skip unused (least significant) octets */
589 tmp = clib_host_to_net_u64 (tmp);
590 *mac = tmp;
Dave Barach41da02d2016-07-11 16:48:42 -0700591}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800593static void vl_api_create_loopback_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400594 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700595{
Dave Barach72d72232016-08-04 10:15:08 -0400596 vat_main_t *vam = &vat_main;
597 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598
Dave Barach72d72232016-08-04 10:15:08 -0400599 vam->retval = retval;
600 vam->regenerate_interface_table = 1;
601 vam->sw_if_index = ntohl (mp->sw_if_index);
602 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603}
604
605static void vl_api_create_loopback_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400606 (vl_api_create_loopback_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700607{
Dave Barach72d72232016-08-04 10:15:08 -0400608 vat_main_t *vam = &vat_main;
609 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610
Dave Barach72d72232016-08-04 10:15:08 -0400611 vat_json_init_object (&node);
612 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
613 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
Dave Barach72d72232016-08-04 10:15:08 -0400615 vat_json_print (vam->ofp, &node);
616 vat_json_free (&node);
617 vam->retval = ntohl (mp->retval);
618 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700619}
620
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800621static void vl_api_af_packet_create_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400622 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700623{
Dave Barach72d72232016-08-04 10:15:08 -0400624 vat_main_t *vam = &vat_main;
625 i32 retval = ntohl (mp->retval);
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700626
Dave Barach72d72232016-08-04 10:15:08 -0400627 vam->retval = retval;
628 vam->regenerate_interface_table = 1;
629 vam->sw_if_index = ntohl (mp->sw_if_index);
630 vam->result_ready = 1;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700631}
632
633static void vl_api_af_packet_create_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400634 (vl_api_af_packet_create_reply_t * mp)
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700635{
Dave Barach72d72232016-08-04 10:15:08 -0400636 vat_main_t *vam = &vat_main;
637 vat_json_node_t node;
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700638
Dave Barach72d72232016-08-04 10:15:08 -0400639 vat_json_init_object (&node);
640 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
641 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -0700642
Dave Barach72d72232016-08-04 10:15:08 -0400643 vat_json_print (vam->ofp, &node);
644 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700645
Dave Barach72d72232016-08-04 10:15:08 -0400646 vam->retval = ntohl (mp->retval);
647 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700648}
649
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800650static void vl_api_create_vlan_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400651 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700652{
Dave Barach72d72232016-08-04 10:15:08 -0400653 vat_main_t *vam = &vat_main;
654 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700655
Dave Barach72d72232016-08-04 10:15:08 -0400656 vam->retval = retval;
657 vam->regenerate_interface_table = 1;
658 vam->sw_if_index = ntohl (mp->sw_if_index);
659 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700660}
661
662static void vl_api_create_vlan_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400663 (vl_api_create_vlan_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700664{
Dave Barach72d72232016-08-04 10:15:08 -0400665 vat_main_t *vam = &vat_main;
666 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700667
Dave Barach72d72232016-08-04 10:15:08 -0400668 vat_json_init_object (&node);
669 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
670 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671
Dave Barach72d72232016-08-04 10:15:08 -0400672 vat_json_print (vam->ofp, &node);
673 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674
Dave Barach72d72232016-08-04 10:15:08 -0400675 vam->retval = ntohl (mp->retval);
676 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700677}
678
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800679static void vl_api_create_subif_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400680 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681{
Dave Barach72d72232016-08-04 10:15:08 -0400682 vat_main_t *vam = &vat_main;
683 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700684
Dave Barach72d72232016-08-04 10:15:08 -0400685 vam->retval = retval;
686 vam->regenerate_interface_table = 1;
687 vam->sw_if_index = ntohl (mp->sw_if_index);
688 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700689}
690
691static void vl_api_create_subif_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400692 (vl_api_create_subif_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693{
Dave Barach72d72232016-08-04 10:15:08 -0400694 vat_main_t *vam = &vat_main;
695 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
Dave Barach72d72232016-08-04 10:15:08 -0400697 vat_json_init_object (&node);
698 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
699 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700
Dave Barach72d72232016-08-04 10:15:08 -0400701 vat_json_print (vam->ofp, &node);
702 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703
Dave Barach72d72232016-08-04 10:15:08 -0400704 vam->retval = ntohl (mp->retval);
705 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706}
707
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800708static void vl_api_interface_name_renumber_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400709 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710{
Dave Barach72d72232016-08-04 10:15:08 -0400711 vat_main_t *vam = &vat_main;
712 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713
Dave Barach72d72232016-08-04 10:15:08 -0400714 vam->retval = retval;
715 vam->regenerate_interface_table = 1;
716 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717}
718
719static void vl_api_interface_name_renumber_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400720 (vl_api_interface_name_renumber_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700721{
Dave Barach72d72232016-08-04 10:15:08 -0400722 vat_main_t *vam = &vat_main;
723 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
Dave Barach72d72232016-08-04 10:15:08 -0400725 vat_json_init_object (&node);
726 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700727
Dave Barach72d72232016-08-04 10:15:08 -0400728 vat_json_print (vam->ofp, &node);
729 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700730
Dave Barach72d72232016-08-04 10:15:08 -0400731 vam->retval = ntohl (mp->retval);
732 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700733}
734
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800735/*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736 * Special-case: build the interface table, maintain
737 * the next loopback sw_if_index vbl.
738 */
739static void vl_api_sw_interface_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400740 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741{
Dave Barach72d72232016-08-04 10:15:08 -0400742 vat_main_t *vam = &vat_main;
743 u8 *s = format (0, "%s%c", mp->interface_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744
Dave Barach72d72232016-08-04 10:15:08 -0400745 hash_set_mem (vam->sw_if_index_by_interface_name, s,
746 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747
Dave Barach72d72232016-08-04 10:15:08 -0400748 /* In sub interface case, fill the sub interface table entry */
749 if (mp->sw_if_index != mp->sup_sw_if_index)
750 {
751 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700752
Dave Barach72d72232016-08-04 10:15:08 -0400753 vec_add2 (vam->sw_if_subif_table, sub, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700754
Dave Barach72d72232016-08-04 10:15:08 -0400755 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
756 strncpy ((char *) sub->interface_name, (char *) s,
757 vec_len (sub->interface_name));
758 sub->sw_if_index = ntohl (mp->sw_if_index);
759 sub->sub_id = ntohl (mp->sub_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760
Dave Barach72d72232016-08-04 10:15:08 -0400761 sub->sub_dot1ad = mp->sub_dot1ad;
762 sub->sub_number_of_tags = mp->sub_number_of_tags;
763 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
764 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
765 sub->sub_exact_match = mp->sub_exact_match;
766 sub->sub_default = mp->sub_default;
767 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
768 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769
Dave Barach72d72232016-08-04 10:15:08 -0400770 /* vlan tag rewrite */
771 sub->vtr_op = ntohl (mp->vtr_op);
772 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
773 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
774 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775 }
776}
777
778static void vl_api_sw_interface_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400779 (vl_api_sw_interface_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780{
Dave Barach72d72232016-08-04 10:15:08 -0400781 vat_main_t *vam = &vat_main;
782 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783
Dave Barach72d72232016-08-04 10:15:08 -0400784 if (VAT_JSON_ARRAY != vam->json_tree.type)
785 {
786 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
787 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 }
Dave Barach72d72232016-08-04 10:15:08 -0400789 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700790
Dave Barach72d72232016-08-04 10:15:08 -0400791 vat_json_init_object (node);
792 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
793 vat_json_object_add_uint (node, "sup_sw_if_index",
794 ntohl (mp->sup_sw_if_index));
795 vat_json_object_add_uint (node, "l2_address_length",
796 ntohl (mp->l2_address_length));
797 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
798 sizeof (mp->l2_address));
799 vat_json_object_add_string_copy (node, "interface_name",
800 mp->interface_name);
801 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
802 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
803 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
804 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
805 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
806 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
807 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
808 vat_json_object_add_uint (node, "sub_number_of_tags",
809 mp->sub_number_of_tags);
810 vat_json_object_add_uint (node, "sub_outer_vlan_id",
811 ntohs (mp->sub_outer_vlan_id));
812 vat_json_object_add_uint (node, "sub_inner_vlan_id",
813 ntohs (mp->sub_inner_vlan_id));
814 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
815 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
816 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
817 mp->sub_outer_vlan_id_any);
818 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
819 mp->sub_inner_vlan_id_any);
820 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
821 vat_json_object_add_uint (node, "vtr_push_dot1q",
822 ntohl (mp->vtr_push_dot1q));
823 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
824 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700825}
826
827static void vl_api_sw_interface_set_flags_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400828 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700829{
Dave Barach72d72232016-08-04 10:15:08 -0400830 vat_main_t *vam = &vat_main;
831 if (vam->interface_event_display)
832 errmsg ("interface flags: sw_if_index %d %s %s\n",
833 ntohl (mp->sw_if_index),
834 mp->admin_up_down ? "admin-up" : "admin-down",
835 mp->link_up_down ? "link-up" : "link-down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836}
837
838static void vl_api_sw_interface_set_flags_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400839 (vl_api_sw_interface_set_flags_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840{
Dave Barach72d72232016-08-04 10:15:08 -0400841 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700842}
843
Dave Barach72d72232016-08-04 10:15:08 -0400844static void
845vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700846{
Dave Barach72d72232016-08-04 10:15:08 -0400847 vat_main_t *vam = &vat_main;
848 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700849
Dave Barach72d72232016-08-04 10:15:08 -0400850 vam->retval = retval;
851 vam->shmem_result = (u8 *) mp->reply_in_shmem;
852 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853}
854
Dave Barach72d72232016-08-04 10:15:08 -0400855static void
856vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700857{
Dave Barach72d72232016-08-04 10:15:08 -0400858 vat_main_t *vam = &vat_main;
859 vat_json_node_t node;
860 api_main_t *am = &api_main;
861 void *oldheap;
862 u8 *reply;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700863
Dave Barach72d72232016-08-04 10:15:08 -0400864 vat_json_init_object (&node);
865 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
866 vat_json_object_add_uint (&node, "reply_in_shmem",
867 ntohl (mp->reply_in_shmem));
868 /* Toss the shared-memory original... */
869 pthread_mutex_lock (&am->vlib_rp->mutex);
870 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -0500871
Dave Barach72d72232016-08-04 10:15:08 -0400872 reply = (u8 *) (mp->reply_in_shmem);
873 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +0800874
Dave Barach72d72232016-08-04 10:15:08 -0400875 svm_pop_heap (oldheap);
876 pthread_mutex_unlock (&am->vlib_rp->mutex);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877
Dave Barach72d72232016-08-04 10:15:08 -0400878 vat_json_print (vam->ofp, &node);
879 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700880
Dave Barach72d72232016-08-04 10:15:08 -0400881 vam->retval = ntohl (mp->retval);
882 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883}
884
Ole Troanc27213a2016-08-31 14:50:49 +0200885static void
886vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
887{
888 vat_main_t *vam = &vat_main;
889 i32 retval = ntohl (mp->retval);
890
891 vam->retval = retval;
892 vam->cmd_reply = mp->reply;
893 vam->result_ready = 1;
894}
895
896static void
897vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
898{
899 vat_main_t *vam = &vat_main;
900 vat_json_node_t node;
901
902 vat_json_init_object (&node);
903 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
904 vat_json_object_add_string_copy (&node, "reply", mp->reply);
905
906 vat_json_print (vam->ofp, &node);
907 vat_json_free (&node);
908
909 vam->retval = ntohl (mp->retval);
910 vam->result_ready = 1;
911}
912
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913static void vl_api_classify_add_del_table_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400914 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700915{
Dave Barach72d72232016-08-04 10:15:08 -0400916 vat_main_t *vam = &vat_main;
917 i32 retval = ntohl (mp->retval);
918 if (vam->async_mode)
919 {
920 vam->async_errors += (retval < 0);
921 }
922 else
923 {
924 vam->retval = retval;
925 if (retval == 0 &&
926 ((mp->new_table_index != 0xFFFFFFFF) ||
927 (mp->skip_n_vectors != 0xFFFFFFFF) ||
928 (mp->match_n_vectors != 0xFFFFFFFF)))
929 /*
930 * Note: this is just barely thread-safe, depends on
931 * the main thread spinning waiting for an answer...
932 */
933 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
934 ntohl (mp->new_table_index),
935 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
936 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937 }
938}
939
940static void vl_api_classify_add_del_table_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400941 (vl_api_classify_add_del_table_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942{
Dave Barach72d72232016-08-04 10:15:08 -0400943 vat_main_t *vam = &vat_main;
944 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700945
Dave Barach72d72232016-08-04 10:15:08 -0400946 vat_json_init_object (&node);
947 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
948 vat_json_object_add_uint (&node, "new_table_index",
949 ntohl (mp->new_table_index));
950 vat_json_object_add_uint (&node, "skip_n_vectors",
951 ntohl (mp->skip_n_vectors));
952 vat_json_object_add_uint (&node, "match_n_vectors",
953 ntohl (mp->match_n_vectors));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700954
Dave Barach72d72232016-08-04 10:15:08 -0400955 vat_json_print (vam->ofp, &node);
956 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700957
Dave Barach72d72232016-08-04 10:15:08 -0400958 vam->retval = ntohl (mp->retval);
959 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960}
961
962static void vl_api_get_node_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400963 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964{
Dave Barach72d72232016-08-04 10:15:08 -0400965 vat_main_t *vam = &vat_main;
966 i32 retval = ntohl (mp->retval);
967 if (vam->async_mode)
968 {
969 vam->async_errors += (retval < 0);
970 }
971 else
972 {
973 vam->retval = retval;
974 if (retval == 0)
975 errmsg ("node index %d\n", ntohl (mp->node_index));
976 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977 }
978}
979
980static void vl_api_get_node_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -0400981 (vl_api_get_node_index_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982{
Dave Barach72d72232016-08-04 10:15:08 -0400983 vat_main_t *vam = &vat_main;
984 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985
Dave Barach72d72232016-08-04 10:15:08 -0400986 vat_json_init_object (&node);
987 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
988 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989
Dave Barach72d72232016-08-04 10:15:08 -0400990 vat_json_print (vam->ofp, &node);
991 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992
Dave Barach72d72232016-08-04 10:15:08 -0400993 vam->retval = ntohl (mp->retval);
994 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995}
996
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700997static void vl_api_get_next_index_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -0400998 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -0700999{
Dave Barach72d72232016-08-04 10:15:08 -04001000 vat_main_t *vam = &vat_main;
1001 i32 retval = ntohl (mp->retval);
1002 if (vam->async_mode)
1003 {
1004 vam->async_errors += (retval < 0);
1005 }
1006 else
1007 {
1008 vam->retval = retval;
1009 if (retval == 0)
1010 errmsg ("next node index %d\n", ntohl (mp->next_index));
1011 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001012 }
1013}
1014
1015static void vl_api_get_next_index_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001016 (vl_api_get_next_index_reply_t * mp)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001017{
Dave Barach72d72232016-08-04 10:15:08 -04001018 vat_main_t *vam = &vat_main;
1019 vat_json_node_t node;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001020
Dave Barach72d72232016-08-04 10:15:08 -04001021 vat_json_init_object (&node);
1022 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1023 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001024
Dave Barach72d72232016-08-04 10:15:08 -04001025 vat_json_print (vam->ofp, &node);
1026 vat_json_free (&node);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001027
Dave Barach72d72232016-08-04 10:15:08 -04001028 vam->retval = ntohl (mp->retval);
1029 vam->result_ready = 1;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07001030}
1031
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032static void vl_api_add_node_next_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001033 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034{
Dave Barach72d72232016-08-04 10:15:08 -04001035 vat_main_t *vam = &vat_main;
1036 i32 retval = ntohl (mp->retval);
1037 if (vam->async_mode)
1038 {
1039 vam->async_errors += (retval < 0);
1040 }
1041 else
1042 {
1043 vam->retval = retval;
1044 if (retval == 0)
1045 errmsg ("next index %d\n", ntohl (mp->next_index));
1046 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001047 }
1048}
1049
1050static void vl_api_add_node_next_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001051 (vl_api_add_node_next_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052{
Dave Barach72d72232016-08-04 10:15:08 -04001053 vat_main_t *vam = &vat_main;
1054 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001055
Dave Barach72d72232016-08-04 10:15:08 -04001056 vat_json_init_object (&node);
1057 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1058 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001059
Dave Barach72d72232016-08-04 10:15:08 -04001060 vat_json_print (vam->ofp, &node);
1061 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001062
Dave Barach72d72232016-08-04 10:15:08 -04001063 vam->retval = ntohl (mp->retval);
1064 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001065}
1066
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001067static void vl_api_show_version_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001068 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069{
Dave Barach72d72232016-08-04 10:15:08 -04001070 vat_main_t *vam = &vat_main;
1071 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072
Dave Barach72d72232016-08-04 10:15:08 -04001073 if (retval >= 0)
1074 {
1075 errmsg (" program: %s\n", mp->program);
1076 errmsg (" version: %s\n", mp->version);
1077 errmsg (" build date: %s\n", mp->build_date);
1078 errmsg ("build directory: %s\n", mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001079 }
Dave Barach72d72232016-08-04 10:15:08 -04001080 vam->retval = retval;
1081 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001082}
1083
1084static void vl_api_show_version_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001085 (vl_api_show_version_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001086{
Dave Barach72d72232016-08-04 10:15:08 -04001087 vat_main_t *vam = &vat_main;
1088 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089
Dave Barach72d72232016-08-04 10:15:08 -04001090 vat_json_init_object (&node);
1091 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1092 vat_json_object_add_string_copy (&node, "program", mp->program);
1093 vat_json_object_add_string_copy (&node, "version", mp->version);
1094 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1095 vat_json_object_add_string_copy (&node, "build_directory",
1096 mp->build_directory);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001097
Dave Barach72d72232016-08-04 10:15:08 -04001098 vat_json_print (vam->ofp, &node);
1099 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100
Dave Barach72d72232016-08-04 10:15:08 -04001101 vam->retval = ntohl (mp->retval);
1102 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103}
1104
Dave Barach72d72232016-08-04 10:15:08 -04001105static void
1106vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001107{
Dave Barach72d72232016-08-04 10:15:08 -04001108 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001109 errmsg ("arp %s event: address %U new mac %U sw_if_index %d\n",
1110 mp->mac_ip ? "mac/ip binding" : "address resolution",
Dave Barach72d72232016-08-04 10:15:08 -04001111 format_ip4_address, &mp->address,
1112 format_ethernet_address, mp->new_mac, mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001113}
1114
Dave Barach72d72232016-08-04 10:15:08 -04001115static void
1116vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117{
Dave Barach72d72232016-08-04 10:15:08 -04001118 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001119}
1120
John Lo1edfba92016-08-27 01:11:57 -04001121static void
1122vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1123{
1124 vat_main_t *vam = &vat_main;
John Loe016b5e2016-09-02 00:13:41 -04001125 errmsg ("ip6 nd %s event: address %U new mac %U sw_if_index %d\n",
1126 mp->mac_ip ? "mac/ip binding" : "address resolution",
John Lo1edfba92016-08-27 01:11:57 -04001127 format_ip6_address, mp->address,
1128 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1129}
1130
1131static void
1132vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1133{
1134 /* JSON output not supported */
1135}
1136
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001137/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001138 * Special-case: build the bridge domain table, maintain
1139 * the next bd id vbl.
1140 */
1141static void vl_api_bridge_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001142 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001143{
Dave Barach72d72232016-08-04 10:15:08 -04001144 vat_main_t *vam = &vat_main;
1145 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146
Dave Barach72d72232016-08-04 10:15:08 -04001147 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1148 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149
Dave Barach72d72232016-08-04 10:15:08 -04001150 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1151 ntohl (mp->bd_id), mp->learn, mp->forward,
1152 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153
Dave Barach72d72232016-08-04 10:15:08 -04001154 if (n_sw_ifs)
1155 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1156 "Interface Name");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001157}
1158
1159static void vl_api_bridge_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001160 (vl_api_bridge_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001161{
Dave Barach72d72232016-08-04 10:15:08 -04001162 vat_main_t *vam = &vat_main;
1163 vat_json_node_t *node, *array = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001164
Dave Barach72d72232016-08-04 10:15:08 -04001165 if (VAT_JSON_ARRAY != vam->json_tree.type)
1166 {
1167 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1168 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001169 }
Dave Barach72d72232016-08-04 10:15:08 -04001170 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001171
Dave Barach72d72232016-08-04 10:15:08 -04001172 vat_json_init_object (node);
1173 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1174 vat_json_object_add_uint (node, "flood", mp->flood);
1175 vat_json_object_add_uint (node, "forward", mp->forward);
1176 vat_json_object_add_uint (node, "learn", mp->learn);
1177 vat_json_object_add_uint (node, "bvi_sw_if_index",
1178 ntohl (mp->bvi_sw_if_index));
1179 vat_json_object_add_uint (node, "n_sw_ifs", ntohl (mp->n_sw_ifs));
1180 array = vat_json_object_add (node, "sw_if");
1181 vat_json_init_array (array);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001182}
1183
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001184/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07001185 * Special-case: build the bridge domain sw if table.
1186 */
1187static void vl_api_bridge_domain_sw_if_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001188 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001189{
Dave Barach72d72232016-08-04 10:15:08 -04001190 vat_main_t *vam = &vat_main;
1191 hash_pair_t *p;
1192 u8 *sw_if_name = 0;
1193 u32 sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
Dave Barach72d72232016-08-04 10:15:08 -04001195 sw_if_index = ntohl (mp->sw_if_index);
1196 /* *INDENT-OFF* */
1197 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1198 ({
1199 if ((u32) p->value[0] == sw_if_index)
1200 {
1201 sw_if_name = (u8 *)(p->key);
1202 break;
1203 }
1204 }));
1205 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001206
Dave Barach72d72232016-08-04 10:15:08 -04001207 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1208 mp->shg, sw_if_name ? (char *) sw_if_name :
1209 "sw_if_index not found!");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001210}
1211
1212static void vl_api_bridge_domain_sw_if_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001213 (vl_api_bridge_domain_sw_if_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214{
Dave Barach72d72232016-08-04 10:15:08 -04001215 vat_main_t *vam = &vat_main;
1216 vat_json_node_t *node = NULL;
1217 uword last_index = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218
Dave Barach72d72232016-08-04 10:15:08 -04001219 ASSERT (VAT_JSON_ARRAY == vam->json_tree.type);
1220 ASSERT (vec_len (vam->json_tree.array) >= 1);
1221 last_index = vec_len (vam->json_tree.array) - 1;
1222 node = &vam->json_tree.array[last_index];
1223 node = vat_json_object_get_element (node, "sw_if");
1224 ASSERT (NULL != node);
1225 node = vat_json_array_add (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001226
Dave Barach72d72232016-08-04 10:15:08 -04001227 vat_json_init_object (node);
1228 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1229 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1230 vat_json_object_add_uint (node, "shg", mp->shg);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001231}
1232
1233static void vl_api_control_ping_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001234 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001235{
Dave Barach72d72232016-08-04 10:15:08 -04001236 vat_main_t *vam = &vat_main;
1237 i32 retval = ntohl (mp->retval);
1238 if (vam->async_mode)
1239 {
1240 vam->async_errors += (retval < 0);
1241 }
1242 else
1243 {
1244 vam->retval = retval;
1245 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001246 }
1247}
1248
1249static void vl_api_control_ping_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001250 (vl_api_control_ping_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001251{
Dave Barach72d72232016-08-04 10:15:08 -04001252 vat_main_t *vam = &vat_main;
1253 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001254
Dave Barach72d72232016-08-04 10:15:08 -04001255 if (VAT_JSON_NONE != vam->json_tree.type)
1256 {
1257 vat_json_print (vam->ofp, &vam->json_tree);
1258 vat_json_free (&vam->json_tree);
1259 vam->json_tree.type = VAT_JSON_NONE;
1260 }
1261 else
1262 {
1263 /* just print [] */
1264 vat_json_init_array (&vam->json_tree);
1265 vat_json_print (vam->ofp, &vam->json_tree);
1266 vam->json_tree.type = VAT_JSON_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001267 }
1268
Dave Barach72d72232016-08-04 10:15:08 -04001269 vam->retval = retval;
1270 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271}
1272
Dave Barach72d72232016-08-04 10:15:08 -04001273static void
1274vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001275{
Dave Barach72d72232016-08-04 10:15:08 -04001276 vat_main_t *vam = &vat_main;
1277 i32 retval = ntohl (mp->retval);
1278 if (vam->async_mode)
1279 {
1280 vam->async_errors += (retval < 0);
1281 }
1282 else
1283 {
1284 vam->retval = retval;
1285 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001286 }
1287}
1288
1289static void vl_api_l2_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001290 (vl_api_l2_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001291{
Dave Barach72d72232016-08-04 10:15:08 -04001292 vat_main_t *vam = &vat_main;
1293 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001294
Dave Barach72d72232016-08-04 10:15:08 -04001295 vat_json_init_object (&node);
1296 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1297 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1298 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299
Dave Barach72d72232016-08-04 10:15:08 -04001300 vat_json_print (vam->ofp, &node);
1301 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001302
Dave Barach72d72232016-08-04 10:15:08 -04001303 vam->retval = ntohl (mp->retval);
1304 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001305}
1306
1307static void vl_api_bridge_flags_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001308 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001309{
Dave Barach72d72232016-08-04 10:15:08 -04001310 vat_main_t *vam = &vat_main;
1311 i32 retval = ntohl (mp->retval);
1312 if (vam->async_mode)
1313 {
1314 vam->async_errors += (retval < 0);
1315 }
1316 else
1317 {
1318 vam->retval = retval;
1319 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001320 }
1321}
1322
1323static void vl_api_bridge_flags_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001324 (vl_api_bridge_flags_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001325{
Dave Barach72d72232016-08-04 10:15:08 -04001326 vat_main_t *vam = &vat_main;
1327 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328
Dave Barach72d72232016-08-04 10:15:08 -04001329 vat_json_init_object (&node);
1330 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1331 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1332 ntohl (mp->resulting_feature_bitmap));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001333
Dave Barach72d72232016-08-04 10:15:08 -04001334 vat_json_print (vam->ofp, &node);
1335 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336
Dave Barach72d72232016-08-04 10:15:08 -04001337 vam->retval = ntohl (mp->retval);
1338 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339}
1340
1341static void vl_api_tap_connect_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001342 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001343{
Dave Barach72d72232016-08-04 10:15:08 -04001344 vat_main_t *vam = &vat_main;
1345 i32 retval = ntohl (mp->retval);
1346 if (vam->async_mode)
1347 {
1348 vam->async_errors += (retval < 0);
1349 }
1350 else
1351 {
1352 vam->retval = retval;
1353 vam->sw_if_index = ntohl (mp->sw_if_index);
1354 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001355 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001356
Ed Warnickecb9cada2015-12-08 15:45:58 -07001357}
1358
1359static void vl_api_tap_connect_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001360 (vl_api_tap_connect_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001361{
Dave Barach72d72232016-08-04 10:15:08 -04001362 vat_main_t *vam = &vat_main;
1363 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001364
Dave Barach72d72232016-08-04 10:15:08 -04001365 vat_json_init_object (&node);
1366 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1367 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001368
Dave Barach72d72232016-08-04 10:15:08 -04001369 vat_json_print (vam->ofp, &node);
1370 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001371
Dave Barach72d72232016-08-04 10:15:08 -04001372 vam->retval = ntohl (mp->retval);
1373 vam->result_ready = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08001374
Ed Warnickecb9cada2015-12-08 15:45:58 -07001375}
1376
Dave Barach72d72232016-08-04 10:15:08 -04001377static void
1378vl_api_tap_modify_reply_t_handler (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001379{
Dave Barach72d72232016-08-04 10:15:08 -04001380 vat_main_t *vam = &vat_main;
1381 i32 retval = ntohl (mp->retval);
1382 if (vam->async_mode)
1383 {
1384 vam->async_errors += (retval < 0);
1385 }
1386 else
1387 {
1388 vam->retval = retval;
1389 vam->sw_if_index = ntohl (mp->sw_if_index);
1390 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001391 }
1392}
1393
1394static void vl_api_tap_modify_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001395 (vl_api_tap_modify_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001396{
Dave Barach72d72232016-08-04 10:15:08 -04001397 vat_main_t *vam = &vat_main;
1398 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001399
Dave Barach72d72232016-08-04 10:15:08 -04001400 vat_json_init_object (&node);
1401 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1402 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001403
Dave Barach72d72232016-08-04 10:15:08 -04001404 vat_json_print (vam->ofp, &node);
1405 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001406
Dave Barach72d72232016-08-04 10:15:08 -04001407 vam->retval = ntohl (mp->retval);
1408 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409}
1410
Dave Barach72d72232016-08-04 10:15:08 -04001411static void
1412vl_api_tap_delete_reply_t_handler (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413{
Dave Barach72d72232016-08-04 10:15:08 -04001414 vat_main_t *vam = &vat_main;
1415 i32 retval = ntohl (mp->retval);
1416 if (vam->async_mode)
1417 {
1418 vam->async_errors += (retval < 0);
1419 }
1420 else
1421 {
1422 vam->retval = retval;
1423 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424 }
1425}
1426
1427static void vl_api_tap_delete_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001428 (vl_api_tap_delete_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001429{
Dave Barach72d72232016-08-04 10:15:08 -04001430 vat_main_t *vam = &vat_main;
1431 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432
Dave Barach72d72232016-08-04 10:15:08 -04001433 vat_json_init_object (&node);
1434 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001435
Dave Barach72d72232016-08-04 10:15:08 -04001436 vat_json_print (vam->ofp, &node);
1437 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438
Dave Barach72d72232016-08-04 10:15:08 -04001439 vam->retval = ntohl (mp->retval);
1440 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001441}
1442
Neale Rannsad422ed2016-11-02 14:20:04 +00001443static void vl_api_mpls_tunnel_add_del_reply_t_handler
1444 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001445{
Dave Barach72d72232016-08-04 10:15:08 -04001446 vat_main_t *vam = &vat_main;
1447 i32 retval = ntohl (mp->retval);
1448 if (vam->async_mode)
1449 {
1450 vam->async_errors += (retval < 0);
1451 }
1452 else
1453 {
1454 vam->retval = retval;
1455 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001456 }
1457}
1458
Neale Rannsad422ed2016-11-02 14:20:04 +00001459static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
1460 (vl_api_mpls_tunnel_add_del_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001461{
Dave Barach72d72232016-08-04 10:15:08 -04001462 vat_main_t *vam = &vat_main;
1463 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464
Dave Barach72d72232016-08-04 10:15:08 -04001465 vat_json_init_object (&node);
1466 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1467 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
Neale Rannsad422ed2016-11-02 14:20:04 +00001468 ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469
Dave Barach72d72232016-08-04 10:15:08 -04001470 vat_json_print (vam->ofp, &node);
1471 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001472
Dave Barach72d72232016-08-04 10:15:08 -04001473 vam->retval = ntohl (mp->retval);
1474 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001475}
1476
1477static void vl_api_l2tpv3_create_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001478 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001479{
Dave Barach72d72232016-08-04 10:15:08 -04001480 vat_main_t *vam = &vat_main;
1481 i32 retval = ntohl (mp->retval);
1482 if (vam->async_mode)
1483 {
1484 vam->async_errors += (retval < 0);
1485 }
1486 else
1487 {
1488 vam->retval = retval;
1489 vam->sw_if_index = ntohl (mp->sw_if_index);
1490 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001491 }
1492}
1493
1494static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001495 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001496{
Dave Barach72d72232016-08-04 10:15:08 -04001497 vat_main_t *vam = &vat_main;
1498 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001499
Dave Barach72d72232016-08-04 10:15:08 -04001500 vat_json_init_object (&node);
1501 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1502 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001503
Dave Barach72d72232016-08-04 10:15:08 -04001504 vat_json_print (vam->ofp, &node);
1505 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001506
Dave Barach72d72232016-08-04 10:15:08 -04001507 vam->retval = ntohl (mp->retval);
1508 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001509}
1510
Filip Tehlar3a834602016-08-11 12:21:37 +02001511
1512static void vl_api_lisp_add_del_locator_set_reply_t_handler
1513 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1514{
1515 vat_main_t *vam = &vat_main;
1516 i32 retval = ntohl (mp->retval);
1517 if (vam->async_mode)
1518 {
1519 vam->async_errors += (retval < 0);
1520 }
1521 else
1522 {
1523 vam->retval = retval;
1524 vam->result_ready = 1;
1525 }
1526}
1527
1528static void vl_api_lisp_add_del_locator_set_reply_t_handler_json
1529 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1530{
1531 vat_main_t *vam = &vat_main;
1532 vat_json_node_t node;
1533
1534 vat_json_init_object (&node);
1535 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1536 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
1537
1538 vat_json_print (vam->ofp, &node);
1539 vat_json_free (&node);
1540
1541 vam->retval = ntohl (mp->retval);
1542 vam->result_ready = 1;
1543}
1544
Ed Warnickecb9cada2015-12-08 15:45:58 -07001545static void vl_api_vxlan_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001546 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001547{
Dave Barach72d72232016-08-04 10:15:08 -04001548 vat_main_t *vam = &vat_main;
1549 i32 retval = ntohl (mp->retval);
1550 if (vam->async_mode)
1551 {
1552 vam->async_errors += (retval < 0);
1553 }
1554 else
1555 {
1556 vam->retval = retval;
1557 vam->sw_if_index = ntohl (mp->sw_if_index);
1558 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001559 }
1560}
1561
1562static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001563 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001564{
Dave Barach72d72232016-08-04 10:15:08 -04001565 vat_main_t *vam = &vat_main;
1566 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001567
Dave Barach72d72232016-08-04 10:15:08 -04001568 vat_json_init_object (&node);
1569 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1570 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001571
Dave Barach72d72232016-08-04 10:15:08 -04001572 vat_json_print (vam->ofp, &node);
1573 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001574
Dave Barach72d72232016-08-04 10:15:08 -04001575 vam->retval = ntohl (mp->retval);
1576 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001577}
1578
Chris Luke27fe48f2016-04-28 13:44:38 -04001579static void vl_api_gre_add_del_tunnel_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001580 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001581{
Dave Barach72d72232016-08-04 10:15:08 -04001582 vat_main_t *vam = &vat_main;
1583 i32 retval = ntohl (mp->retval);
1584 if (vam->async_mode)
1585 {
1586 vam->async_errors += (retval < 0);
1587 }
1588 else
1589 {
1590 vam->retval = retval;
1591 vam->sw_if_index = ntohl (mp->sw_if_index);
1592 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001593 }
1594}
1595
1596static void vl_api_gre_add_del_tunnel_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001597 (vl_api_gre_add_del_tunnel_reply_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -04001598{
Dave Barach72d72232016-08-04 10:15:08 -04001599 vat_main_t *vam = &vat_main;
1600 vat_json_node_t node;
Chris Luke27fe48f2016-04-28 13:44:38 -04001601
Dave Barach72d72232016-08-04 10:15:08 -04001602 vat_json_init_object (&node);
1603 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1604 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Chris Luke27fe48f2016-04-28 13:44:38 -04001605
Dave Barach72d72232016-08-04 10:15:08 -04001606 vat_json_print (vam->ofp, &node);
1607 vat_json_free (&node);
Chris Luke27fe48f2016-04-28 13:44:38 -04001608
Dave Barach72d72232016-08-04 10:15:08 -04001609 vam->retval = ntohl (mp->retval);
1610 vam->result_ready = 1;
Chris Luke27fe48f2016-04-28 13:44:38 -04001611}
1612
Ed Warnickecb9cada2015-12-08 15:45:58 -07001613static void vl_api_create_vhost_user_if_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001614 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001615{
Dave Barach72d72232016-08-04 10:15:08 -04001616 vat_main_t *vam = &vat_main;
1617 i32 retval = ntohl (mp->retval);
1618 if (vam->async_mode)
1619 {
1620 vam->async_errors += (retval < 0);
1621 }
1622 else
1623 {
1624 vam->retval = retval;
1625 vam->sw_if_index = ntohl (mp->sw_if_index);
1626 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001627 }
1628}
1629
1630static void vl_api_create_vhost_user_if_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001631 (vl_api_create_vhost_user_if_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001632{
Dave Barach72d72232016-08-04 10:15:08 -04001633 vat_main_t *vam = &vat_main;
1634 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001635
Dave Barach72d72232016-08-04 10:15:08 -04001636 vat_json_init_object (&node);
1637 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1638 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639
Dave Barach72d72232016-08-04 10:15:08 -04001640 vat_json_print (vam->ofp, &node);
1641 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001642
Dave Barach72d72232016-08-04 10:15:08 -04001643 vam->retval = ntohl (mp->retval);
1644 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001645}
1646
1647static void vl_api_ip_address_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001648 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001649{
Dave Barach72d72232016-08-04 10:15:08 -04001650 vat_main_t *vam = &vat_main;
1651 static ip_address_details_t empty_ip_address_details = { {0} };
1652 ip_address_details_t *address = NULL;
1653 ip_details_t *current_ip_details = NULL;
1654 ip_details_t *details = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001655
Dave Barach72d72232016-08-04 10:15:08 -04001656 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001657
Dave Barach72d72232016-08-04 10:15:08 -04001658 if (!details || vam->current_sw_if_index >= vec_len (details)
1659 || !details[vam->current_sw_if_index].present)
1660 {
1661 errmsg ("ip address details arrived but not stored\n");
1662 errmsg ("ip_dump should be called first\n");
1663 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664 }
1665
Dave Barach72d72232016-08-04 10:15:08 -04001666 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001667
1668#define addresses (current_ip_details->addr)
1669
Dave Barach72d72232016-08-04 10:15:08 -04001670 vec_validate_init_empty (addresses, vec_len (addresses),
1671 empty_ip_address_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672
Dave Barach72d72232016-08-04 10:15:08 -04001673 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001674
Dave Barach72d72232016-08-04 10:15:08 -04001675 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
1676 address->prefix_length = mp->prefix_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677#undef addresses
1678}
1679
1680static void vl_api_ip_address_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001681 (vl_api_ip_address_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001682{
Dave Barach72d72232016-08-04 10:15:08 -04001683 vat_main_t *vam = &vat_main;
1684 vat_json_node_t *node = NULL;
1685 struct in6_addr ip6;
1686 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barach72d72232016-08-04 10:15:08 -04001688 if (VAT_JSON_ARRAY != vam->json_tree.type)
1689 {
1690 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1691 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001692 }
Dave Barach72d72232016-08-04 10:15:08 -04001693 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001694
Dave Barach72d72232016-08-04 10:15:08 -04001695 vat_json_init_object (node);
1696 if (vam->is_ipv6)
1697 {
1698 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
1699 vat_json_object_add_ip6 (node, "ip", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700 }
Dave Barach72d72232016-08-04 10:15:08 -04001701 else
1702 {
1703 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
1704 vat_json_object_add_ip4 (node, "ip", ip4);
1705 }
1706 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001707}
1708
Dave Barach72d72232016-08-04 10:15:08 -04001709static void
1710vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001711{
Dave Barach72d72232016-08-04 10:15:08 -04001712 vat_main_t *vam = &vat_main;
1713 static ip_details_t empty_ip_details = { 0 };
1714 ip_details_t *ip = NULL;
1715 u32 sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001716
Dave Barach72d72232016-08-04 10:15:08 -04001717 sw_if_index = ntohl (mp->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001718
Dave Barach72d72232016-08-04 10:15:08 -04001719 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1720 sw_if_index, empty_ip_details);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001721
Dave Barach72d72232016-08-04 10:15:08 -04001722 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1723 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001724
Dave Barach72d72232016-08-04 10:15:08 -04001725 ip->present = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001726}
1727
Dave Barach72d72232016-08-04 10:15:08 -04001728static void
1729vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001730{
Dave Barach72d72232016-08-04 10:15:08 -04001731 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001732
Dave Barach72d72232016-08-04 10:15:08 -04001733 if (VAT_JSON_ARRAY != vam->json_tree.type)
1734 {
1735 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1736 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001737 }
Dave Barach72d72232016-08-04 10:15:08 -04001738 vat_json_array_add_uint (&vam->json_tree,
1739 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001740}
1741
1742static void vl_api_map_domain_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001743 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001744{
Dave Barach72d72232016-08-04 10:15:08 -04001745 vat_json_node_t *node = NULL;
1746 vat_main_t *vam = &vat_main;
1747 struct in6_addr ip6;
1748 struct in_addr ip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001749
Dave Barach72d72232016-08-04 10:15:08 -04001750 if (VAT_JSON_ARRAY != vam->json_tree.type)
1751 {
1752 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1753 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001754 }
1755
Dave Barach72d72232016-08-04 10:15:08 -04001756 node = vat_json_array_add (&vam->json_tree);
1757 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001758
Dave Barach72d72232016-08-04 10:15:08 -04001759 vat_json_object_add_uint (node, "domain_index",
1760 clib_net_to_host_u32 (mp->domain_index));
1761 clib_memcpy (&ip6, mp->ip6_prefix, sizeof (ip6));
1762 vat_json_object_add_ip6 (node, "ip6_prefix", ip6);
1763 clib_memcpy (&ip4, mp->ip4_prefix, sizeof (ip4));
1764 vat_json_object_add_ip4 (node, "ip4_prefix", ip4);
1765 clib_memcpy (&ip6, mp->ip6_src, sizeof (ip6));
1766 vat_json_object_add_ip6 (node, "ip6_src", ip6);
1767 vat_json_object_add_int (node, "ip6_prefix_len", mp->ip6_prefix_len);
1768 vat_json_object_add_int (node, "ip4_prefix_len", mp->ip4_prefix_len);
1769 vat_json_object_add_int (node, "ip6_src_len", mp->ip6_src_len);
1770 vat_json_object_add_int (node, "ea_bits_len", mp->ea_bits_len);
1771 vat_json_object_add_int (node, "psid_offset", mp->psid_offset);
1772 vat_json_object_add_int (node, "psid_length", mp->psid_length);
1773 vat_json_object_add_uint (node, "flags", mp->flags);
1774 vat_json_object_add_uint (node, "mtu", clib_net_to_host_u16 (mp->mtu));
1775 vat_json_object_add_int (node, "is_translation", mp->is_translation);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001776}
1777
1778static void vl_api_map_domain_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001779 (vl_api_map_domain_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001780{
Dave Barach72d72232016-08-04 10:15:08 -04001781 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001782
Dave Barach72d72232016-08-04 10:15:08 -04001783 if (mp->is_translation)
1784 {
1785 fformat (vam->ofp,
1786 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1787 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1788 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1789 format_ip6_address, mp->ip6_src, mp->ip6_src_len,
1790 clib_net_to_host_u32 (mp->domain_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001791 }
Dave Barach72d72232016-08-04 10:15:08 -04001792 else
1793 {
1794 fformat (vam->ofp,
1795 "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1796 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1797 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1798 format_ip6_address, mp->ip6_src,
1799 clib_net_to_host_u32 (mp->domain_index));
1800 }
1801 fformat (vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1802 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu,
1803 mp->is_translation ? "map-t" : "");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001804}
1805
1806static void vl_api_map_rule_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001807 (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001808{
Dave Barach72d72232016-08-04 10:15:08 -04001809 struct in6_addr ip6;
1810 vat_json_node_t *node = NULL;
1811 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001812
Dave Barach72d72232016-08-04 10:15:08 -04001813 if (VAT_JSON_ARRAY != vam->json_tree.type)
1814 {
1815 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1816 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001817 }
1818
Dave Barach72d72232016-08-04 10:15:08 -04001819 node = vat_json_array_add (&vam->json_tree);
1820 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001821
Dave Barach72d72232016-08-04 10:15:08 -04001822 vat_json_object_add_uint (node, "psid", clib_net_to_host_u16 (mp->psid));
1823 clib_memcpy (&ip6, mp->ip6_dst, sizeof (ip6));
1824 vat_json_object_add_ip6 (node, "ip6_dst", ip6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825}
1826
Dave Barach72d72232016-08-04 10:15:08 -04001827static void
1828vl_api_map_rule_details_t_handler (vl_api_map_rule_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001829{
Dave Barach72d72232016-08-04 10:15:08 -04001830 vat_main_t *vam = &vat_main;
1831 fformat (vam->ofp, " %d (psid) %U (ip6-dst)\n",
1832 clib_net_to_host_u16 (mp->psid), format_ip6_address, mp->ip6_dst);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833}
1834
Dave Barach72d72232016-08-04 10:15:08 -04001835static void
1836vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001837{
Dave Barach72d72232016-08-04 10:15:08 -04001838 vat_main_t *vam = &vat_main;
1839 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1840 "router_addr %U host_mac %U\n",
1841 mp->pid, mp->is_ipv6 ? "ipv6" : "ipv4", mp->hostname,
1842 format_ip4_address, &mp->host_address,
1843 format_ip4_address, &mp->router_address,
1844 format_ethernet_address, mp->host_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845}
1846
1847static void vl_api_dhcp_compl_event_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001848 (vl_api_dhcp_compl_event_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849{
Dave Barach72d72232016-08-04 10:15:08 -04001850 /* JSON output not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001851}
1852
Dave Barach72d72232016-08-04 10:15:08 -04001853static void
1854set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1855 u32 counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001856{
Dave Barach72d72232016-08-04 10:15:08 -04001857 vat_main_t *vam = &vat_main;
1858 static u64 default_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001859
Dave Barach72d72232016-08-04 10:15:08 -04001860 vec_validate_init_empty (vam->simple_interface_counters, vnet_counter_type,
1861 NULL);
1862 vec_validate_init_empty (vam->simple_interface_counters[vnet_counter_type],
1863 sw_if_index, default_counter);
1864 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001865}
1866
Dave Barach72d72232016-08-04 10:15:08 -04001867static void
1868set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1869 interface_counter_t counter)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870{
Dave Barach72d72232016-08-04 10:15:08 -04001871 vat_main_t *vam = &vat_main;
1872 static interface_counter_t default_counter = { 0, };
Ed Warnickecb9cada2015-12-08 15:45:58 -07001873
Dave Barach72d72232016-08-04 10:15:08 -04001874 vec_validate_init_empty (vam->combined_interface_counters,
1875 vnet_counter_type, NULL);
1876 vec_validate_init_empty (vam->combined_interface_counters
1877 [vnet_counter_type], sw_if_index, default_counter);
1878 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001879}
1880
1881static void vl_api_vnet_interface_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001882 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001883{
Dave Barach72d72232016-08-04 10:15:08 -04001884 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001885}
1886
1887static void vl_api_vnet_interface_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001888 (vl_api_vnet_interface_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001889{
Dave Barach72d72232016-08-04 10:15:08 -04001890 interface_counter_t counter;
1891 vlib_counter_t *v;
1892 u64 *v_packets;
1893 u64 packets;
1894 u32 count;
1895 u32 first_sw_if_index;
1896 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001897
Dave Barach72d72232016-08-04 10:15:08 -04001898 count = ntohl (mp->count);
1899 first_sw_if_index = ntohl (mp->first_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900
Dave Barach72d72232016-08-04 10:15:08 -04001901 if (!mp->is_combined)
1902 {
1903 v_packets = (u64 *) & mp->data;
1904 for (i = 0; i < count; i++)
1905 {
1906 packets =
1907 clib_net_to_host_u64 (clib_mem_unaligned (v_packets, u64));
1908 set_simple_interface_counter (mp->vnet_counter_type,
1909 first_sw_if_index + i, packets);
1910 v_packets++;
1911 }
1912 }
1913 else
1914 {
1915 v = (vlib_counter_t *) & mp->data;
1916 for (i = 0; i < count; i++)
1917 {
1918 counter.packets =
1919 clib_net_to_host_u64 (clib_mem_unaligned (&v->packets, u64));
1920 counter.bytes =
1921 clib_net_to_host_u64 (clib_mem_unaligned (&v->bytes, u64));
1922 set_combined_interface_counter (mp->vnet_counter_type,
1923 first_sw_if_index + i, counter);
1924 v++;
1925 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001926 }
1927}
1928
Dave Barach72d72232016-08-04 10:15:08 -04001929static u32
1930ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001931{
Dave Barach72d72232016-08-04 10:15:08 -04001932 vat_main_t *vam = &vat_main;
1933 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001934
Dave Barach72d72232016-08-04 10:15:08 -04001935 for (i = 0; i < vec_len (vam->ip4_fib_counters_vrf_id_by_index); i++)
1936 {
1937 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id)
1938 {
1939 return i;
1940 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001941 }
Dave Barach72d72232016-08-04 10:15:08 -04001942 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001943}
1944
Dave Barach72d72232016-08-04 10:15:08 -04001945static u32
1946ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001947{
Dave Barach72d72232016-08-04 10:15:08 -04001948 vat_main_t *vam = &vat_main;
1949 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001950
Dave Barach72d72232016-08-04 10:15:08 -04001951 for (i = 0; i < vec_len (vam->ip6_fib_counters_vrf_id_by_index); i++)
1952 {
1953 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id)
1954 {
1955 return i;
1956 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001957 }
Dave Barach72d72232016-08-04 10:15:08 -04001958 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959}
1960
1961static void vl_api_vnet_ip4_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04001962 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001963{
Dave Barach72d72232016-08-04 10:15:08 -04001964 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001965}
1966
1967static void vl_api_vnet_ip4_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04001968 (vl_api_vnet_ip4_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001969{
Dave Barach72d72232016-08-04 10:15:08 -04001970 vat_main_t *vam = &vat_main;
1971 vl_api_ip4_fib_counter_t *v;
1972 ip4_fib_counter_t *counter;
1973 struct in_addr ip4;
1974 u32 vrf_id;
1975 u32 vrf_index;
1976 u32 count;
1977 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001978
Dave Barach72d72232016-08-04 10:15:08 -04001979 vrf_id = ntohl (mp->vrf_id);
1980 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
1981 if (~0 == vrf_index)
1982 {
1983 vrf_index = vec_len (vam->ip4_fib_counters_vrf_id_by_index);
1984 vec_validate (vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1985 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1986 vec_validate (vam->ip4_fib_counters, vrf_index);
1987 vam->ip4_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001988 }
1989
Dave Barach72d72232016-08-04 10:15:08 -04001990 vec_free (vam->ip4_fib_counters[vrf_index]);
1991 v = (vl_api_ip4_fib_counter_t *) & mp->c;
1992 count = ntohl (mp->count);
1993 for (i = 0; i < count; i++)
1994 {
1995 vec_validate (vam->ip4_fib_counters[vrf_index], i);
1996 counter = &vam->ip4_fib_counters[vrf_index][i];
1997 clib_memcpy (&ip4, &v->address, sizeof (ip4));
1998 counter->address = ip4;
1999 counter->address_length = v->address_length;
2000 counter->packets = clib_net_to_host_u64 (v->packets);
2001 counter->bytes = clib_net_to_host_u64 (v->bytes);
2002 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002003 }
2004}
2005
2006static void vl_api_vnet_ip6_fib_counters_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002007 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002008{
Dave Barach72d72232016-08-04 10:15:08 -04002009 /* not supported */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010}
2011
2012static void vl_api_vnet_ip6_fib_counters_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002013 (vl_api_vnet_ip6_fib_counters_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014{
Dave Barach72d72232016-08-04 10:15:08 -04002015 vat_main_t *vam = &vat_main;
2016 vl_api_ip6_fib_counter_t *v;
2017 ip6_fib_counter_t *counter;
2018 struct in6_addr ip6;
2019 u32 vrf_id;
2020 u32 vrf_index;
2021 u32 count;
2022 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002023
Dave Barach72d72232016-08-04 10:15:08 -04002024 vrf_id = ntohl (mp->vrf_id);
2025 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id (vrf_id);
2026 if (~0 == vrf_index)
2027 {
2028 vrf_index = vec_len (vam->ip6_fib_counters_vrf_id_by_index);
2029 vec_validate (vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
2030 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
2031 vec_validate (vam->ip6_fib_counters, vrf_index);
2032 vam->ip6_fib_counters[vrf_index] = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002033 }
2034
Dave Barach72d72232016-08-04 10:15:08 -04002035 vec_free (vam->ip6_fib_counters[vrf_index]);
2036 v = (vl_api_ip6_fib_counter_t *) & mp->c;
2037 count = ntohl (mp->count);
2038 for (i = 0; i < count; i++)
2039 {
2040 vec_validate (vam->ip6_fib_counters[vrf_index], i);
2041 counter = &vam->ip6_fib_counters[vrf_index][i];
2042 clib_memcpy (&ip6, &v->address, sizeof (ip6));
2043 counter->address = ip6;
2044 counter->address_length = v->address_length;
2045 counter->packets = clib_net_to_host_u64 (v->packets);
2046 counter->bytes = clib_net_to_host_u64 (v->bytes);
2047 v++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002048 }
2049}
2050
2051static void vl_api_get_first_msg_id_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002052 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053{
Dave Barach72d72232016-08-04 10:15:08 -04002054 vat_main_t *vam = &vat_main;
2055 i32 retval = ntohl (mp->retval);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002056
Dave Barach72d72232016-08-04 10:15:08 -04002057 if (vam->async_mode)
2058 {
2059 vam->async_errors += (retval < 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002060 }
Dave Barach72d72232016-08-04 10:15:08 -04002061 else
2062 {
2063 vam->retval = retval;
2064 vam->result_ready = 1;
2065 }
2066 if (retval >= 0)
2067 {
2068 errmsg ("first message id %d\n", ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002069 }
2070}
2071
2072static void vl_api_get_first_msg_id_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002073 (vl_api_get_first_msg_id_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002074{
Dave Barach72d72232016-08-04 10:15:08 -04002075 vat_main_t *vam = &vat_main;
2076 vat_json_node_t node;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002077
Dave Barach72d72232016-08-04 10:15:08 -04002078 vat_json_init_object (&node);
2079 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2080 vat_json_object_add_uint (&node, "first_msg_id",
2081 (uint) ntohs (mp->first_msg_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002082
Dave Barach72d72232016-08-04 10:15:08 -04002083 vat_json_print (vam->ofp, &node);
2084 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002085
Dave Barach72d72232016-08-04 10:15:08 -04002086 vam->retval = ntohl (mp->retval);
2087 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002088}
2089
Dave Barachb44e9bc2016-02-19 09:06:23 -05002090static void vl_api_get_node_graph_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04002091 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002092{
Dave Barach72d72232016-08-04 10:15:08 -04002093 vat_main_t *vam = &vat_main;
2094 api_main_t *am = &api_main;
2095 i32 retval = ntohl (mp->retval);
2096 u8 *pvt_copy, *reply;
2097 void *oldheap;
2098 vlib_node_t *node;
2099 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002100
Dave Barach72d72232016-08-04 10:15:08 -04002101 if (vam->async_mode)
2102 {
2103 vam->async_errors += (retval < 0);
2104 }
2105 else
2106 {
2107 vam->retval = retval;
2108 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002109 }
2110
Dave Barach72d72232016-08-04 10:15:08 -04002111 /* "Should never happen..." */
2112 if (retval != 0)
2113 return;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002114
Dave Barach72d72232016-08-04 10:15:08 -04002115 reply = (u8 *) (mp->reply_in_shmem);
2116 pvt_copy = vec_dup (reply);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002117
Dave Barach72d72232016-08-04 10:15:08 -04002118 /* Toss the shared-memory original... */
2119 pthread_mutex_lock (&am->vlib_rp->mutex);
2120 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002121
Dave Barach72d72232016-08-04 10:15:08 -04002122 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002123
Dave Barach72d72232016-08-04 10:15:08 -04002124 svm_pop_heap (oldheap);
2125 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002126
Dave Barach72d72232016-08-04 10:15:08 -04002127 if (vam->graph_nodes)
2128 {
2129 hash_free (vam->graph_node_index_by_name);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002130
Dave Barach72d72232016-08-04 10:15:08 -04002131 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2132 {
2133 node = vam->graph_nodes[i];
2134 vec_free (node->name);
2135 vec_free (node->next_nodes);
2136 vec_free (node);
2137 }
2138 vec_free (vam->graph_nodes);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002139 }
2140
Dave Barach72d72232016-08-04 10:15:08 -04002141 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2142 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2143 vec_free (pvt_copy);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002144
Dave Barach72d72232016-08-04 10:15:08 -04002145 for (i = 0; i < vec_len (vam->graph_nodes); i++)
2146 {
2147 node = vam->graph_nodes[i];
2148 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002149 }
2150}
2151
2152static void vl_api_get_node_graph_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04002153 (vl_api_get_node_graph_reply_t * mp)
Dave Barachb44e9bc2016-02-19 09:06:23 -05002154{
Dave Barach72d72232016-08-04 10:15:08 -04002155 vat_main_t *vam = &vat_main;
2156 api_main_t *am = &api_main;
2157 void *oldheap;
2158 vat_json_node_t node;
2159 u8 *reply;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002160
Dave Barach72d72232016-08-04 10:15:08 -04002161 /* $$$$ make this real? */
2162 vat_json_init_object (&node);
2163 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2164 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002165
Dave Barach72d72232016-08-04 10:15:08 -04002166 reply = (u8 *) (mp->reply_in_shmem);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002167
Dave Barach72d72232016-08-04 10:15:08 -04002168 /* Toss the shared-memory original... */
2169 pthread_mutex_lock (&am->vlib_rp->mutex);
2170 oldheap = svm_push_data_heap (am->vlib_rp);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002171
Dave Barach72d72232016-08-04 10:15:08 -04002172 vec_free (reply);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08002173
Dave Barach72d72232016-08-04 10:15:08 -04002174 svm_pop_heap (oldheap);
2175 pthread_mutex_unlock (&am->vlib_rp->mutex);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002176
Dave Barach72d72232016-08-04 10:15:08 -04002177 vat_json_print (vam->ofp, &node);
2178 vat_json_free (&node);
Dave Barachb44e9bc2016-02-19 09:06:23 -05002179
Dave Barach72d72232016-08-04 10:15:08 -04002180 vam->retval = ntohl (mp->retval);
2181 vam->result_ready = 1;
Dave Barachb44e9bc2016-02-19 09:06:23 -05002182}
2183
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002184static void
Dave Barach72d72232016-08-04 10:15:08 -04002185vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002186{
Dave Barach72d72232016-08-04 10:15:08 -04002187 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002188 u8 *s = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002189
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002190 if (mp->local)
Dave Barach72d72232016-08-04 10:15:08 -04002191 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002192 s = format (s, "%=16d%=16d%=16d\n",
2193 ntohl (mp->sw_if_index), mp->priority, mp->weight);
Dave Barach72d72232016-08-04 10:15:08 -04002194 }
2195 else
2196 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002197 s = format (s, "%=16U%=16d%=16d\n",
2198 mp->is_ipv6 ? format_ip6_address :
2199 format_ip4_address,
2200 mp->ip_address, mp->priority, mp->weight);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002201 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002202
2203 fformat (vam->ofp, "%v", s);
2204 vec_free (s);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002205}
2206
2207static void
Dave Barach72d72232016-08-04 10:15:08 -04002208vl_api_lisp_locator_details_t_handler_json (vl_api_lisp_locator_details_t *
2209 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002210{
Dave Barach72d72232016-08-04 10:15:08 -04002211 vat_main_t *vam = &vat_main;
2212 vat_json_node_t *node = NULL;
Dave Barach72d72232016-08-04 10:15:08 -04002213 struct in6_addr ip6;
2214 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002215
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002216 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Barach72d72232016-08-04 10:15:08 -04002217 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002218 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2219 vat_json_init_array (&vam->json_tree);
2220 }
2221 node = vat_json_array_add (&vam->json_tree);
2222 vat_json_init_object (node);
2223
2224 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2225 vat_json_object_add_uint (node, "priority", mp->priority);
2226 vat_json_object_add_uint (node, "weight", mp->weight);
2227
2228 if (mp->local)
2229 vat_json_object_add_uint (node, "sw_if_index",
2230 clib_net_to_host_u32 (mp->sw_if_index));
2231 else
2232 {
2233 if (mp->is_ipv6)
Dave Barach72d72232016-08-04 10:15:08 -04002234 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002235 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2236 vat_json_object_add_ip6 (node, "address", ip6);
Dave Barach72d72232016-08-04 10:15:08 -04002237 }
2238 else
2239 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002240 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2241 vat_json_object_add_ip4 (node, "address", ip4);
Dave Barach72d72232016-08-04 10:15:08 -04002242 }
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002243 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002244}
2245
2246static void
2247vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
2248 mp)
2249{
2250 vat_main_t *vam = &vat_main;
2251 u8 *ls_name = 0;
2252
2253 ls_name = format (0, "%s", mp->ls_name);
2254
2255 fformat (vam->ofp, "%=10d%=15v\n", clib_net_to_host_u32 (mp->ls_index),
2256 ls_name);
2257 vec_free (ls_name);
2258}
2259
2260static void
2261 vl_api_lisp_locator_set_details_t_handler_json
2262 (vl_api_lisp_locator_set_details_t * mp)
2263{
2264 vat_main_t *vam = &vat_main;
2265 vat_json_node_t *node = 0;
2266 u8 *ls_name = 0;
2267
2268 ls_name = format (0, "%s", mp->ls_name);
2269 vec_add1 (ls_name, 0);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002270
Dave Barach72d72232016-08-04 10:15:08 -04002271 if (VAT_JSON_ARRAY != vam->json_tree.type)
2272 {
2273 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2274 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002275 }
Dave Barach72d72232016-08-04 10:15:08 -04002276 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002277
Dave Barach72d72232016-08-04 10:15:08 -04002278 vat_json_init_object (node);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002279 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2280 vat_json_object_add_uint (node, "ls_index",
2281 clib_net_to_host_u32 (mp->ls_index));
2282 vec_free (ls_name);
2283}
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002284
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002285static u8 *
2286format_lisp_flat_eid (u8 * s, va_list * args)
2287{
2288 u32 type = va_arg (*args, u32);
2289 u8 *eid = va_arg (*args, u8 *);
2290 u32 eid_len = va_arg (*args, u32);
2291
2292 switch (type)
Dave Barach72d72232016-08-04 10:15:08 -04002293 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002294 case 0:
2295 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2296 case 1:
2297 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2298 case 2:
2299 return format (s, "%U", format_ethernet_address, eid);
Andrej Kozemcak3e53fc52016-05-09 10:52:16 +02002300 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002301 return 0;
Dave Barach72d72232016-08-04 10:15:08 -04002302}
2303
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002304static u8 *
2305format_lisp_eid_vat (u8 * s, va_list * args)
Dave Barach72d72232016-08-04 10:15:08 -04002306{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002307 u32 type = va_arg (*args, u32);
2308 u8 *eid = va_arg (*args, u8 *);
2309 u32 eid_len = va_arg (*args, u32);
2310 u8 *seid = va_arg (*args, u8 *);
2311 u32 seid_len = va_arg (*args, u32);
2312 u32 is_src_dst = va_arg (*args, u32);
Dave Barach72d72232016-08-04 10:15:08 -04002313
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002314 if (is_src_dst)
2315 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002316
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002317 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
Dave Barach72d72232016-08-04 10:15:08 -04002318
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002319 return s;
Dave Barach72d72232016-08-04 10:15:08 -04002320}
2321
2322static void
Filip Tehlarc00617b2016-08-27 08:40:26 +02002323vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
2324{
2325 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002326 u8 *s = 0, *eid = 0;
2327
2328 if (~0 == mp->locator_set_index)
2329 s = format (0, "action: %d", mp->action);
2330 else
2331 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2332
2333 eid = format (0, "%U", format_lisp_eid_vat,
2334 mp->eid_type,
2335 mp->eid,
2336 mp->eid_prefix_len,
2337 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2338 vec_add1 (eid, 0);
2339
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002340 fformat (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s\n",
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002341 clib_net_to_host_u32 (mp->vni),
2342 eid,
2343 mp->is_local ? "local" : "remote",
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002344 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
2345 clib_net_to_host_u16 (mp->key_id), mp->key);
2346
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002347 vec_free (s);
2348 vec_free (eid);
Filip Tehlarc00617b2016-08-27 08:40:26 +02002349}
2350
2351static void
Dave Barach72d72232016-08-04 10:15:08 -04002352vl_api_lisp_eid_table_details_t_handler_json (vl_api_lisp_eid_table_details_t
2353 * mp)
2354{
2355 vat_main_t *vam = &vat_main;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002356 vat_json_node_t *node = 0;
2357 u8 *eid = 0;
2358
2359 if (VAT_JSON_ARRAY != vam->json_tree.type)
2360 {
2361 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2362 vat_json_init_array (&vam->json_tree);
2363 }
2364 node = vat_json_array_add (&vam->json_tree);
2365
2366 vat_json_init_object (node);
2367 if (~0 == mp->locator_set_index)
2368 vat_json_object_add_uint (node, "action", mp->action);
2369 else
2370 vat_json_object_add_uint (node, "locator_set_index",
2371 clib_net_to_host_u32 (mp->locator_set_index));
2372
2373 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2374 eid = format (0, "%U", format_lisp_eid_vat,
2375 mp->eid_type,
2376 mp->eid,
2377 mp->eid_prefix_len,
2378 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2379 vec_add1 (eid, 0);
2380 vat_json_object_add_string_copy (node, "eid", eid);
2381 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2382 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2383 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002384
2385 if (mp->key_id)
2386 {
2387 vat_json_object_add_uint (node, "key_id",
2388 clib_net_to_host_u16 (mp->key_id));
2389 vat_json_object_add_string_copy (node, "key", mp->key);
2390 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +02002391 vec_free (eid);
Dave Barach72d72232016-08-04 10:15:08 -04002392}
2393
2394static void
2395 vl_api_lisp_eid_table_map_details_t_handler
2396 (vl_api_lisp_eid_table_map_details_t * mp)
2397{
2398 vat_main_t *vam = &vat_main;
2399
2400 u8 *line = format (0, "%=10d%=10d",
2401 clib_net_to_host_u32 (mp->vni),
Filip Tehlarc0681792016-08-24 14:11:07 +02002402 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002403 fformat (vam->ofp, "%v\n", line);
2404 vec_free (line);
2405}
2406
2407static void
2408 vl_api_lisp_eid_table_map_details_t_handler_json
2409 (vl_api_lisp_eid_table_map_details_t * mp)
2410{
2411 vat_main_t *vam = &vat_main;
2412 vat_json_node_t *node = NULL;
2413
2414 if (VAT_JSON_ARRAY != vam->json_tree.type)
2415 {
2416 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2417 vat_json_init_array (&vam->json_tree);
2418 }
2419 node = vat_json_array_add (&vam->json_tree);
2420 vat_json_init_object (node);
Filip Tehlarc0681792016-08-24 14:11:07 +02002421 vat_json_object_add_uint (node, "dp_table",
2422 clib_net_to_host_u32 (mp->dp_table));
Dave Barach72d72232016-08-04 10:15:08 -04002423 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
Filip Tehlar2f653d02016-07-13 13:17:15 +02002424}
2425
Filip Tehlar50a4e142016-08-24 11:28:02 +02002426static void
2427 vl_api_lisp_eid_table_vni_details_t_handler
2428 (vl_api_lisp_eid_table_vni_details_t * mp)
2429{
2430 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002431
Filip Tehlar50a4e142016-08-24 11:28:02 +02002432 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
2433 fformat (vam->ofp, "%v\n", line);
2434 vec_free (line);
2435}
2436
2437static void
2438 vl_api_lisp_eid_table_vni_details_t_handler_json
2439 (vl_api_lisp_eid_table_vni_details_t * mp)
2440{
2441 vat_main_t *vam = &vat_main;
2442 vat_json_node_t *node = NULL;
2443
2444 if (VAT_JSON_ARRAY != vam->json_tree.type)
2445 {
2446 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2447 vat_json_init_array (&vam->json_tree);
2448 }
2449 node = vat_json_array_add (&vam->json_tree);
2450 vat_json_init_object (node);
2451 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2452}
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002453
2454static u8 *
2455format_decap_next (u8 * s, va_list * args)
2456{
2457 u32 next_index = va_arg (*args, u32);
2458
2459 switch (next_index)
2460 {
2461 case LISP_GPE_INPUT_NEXT_DROP:
2462 return format (s, "drop");
2463 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2464 return format (s, "ip4");
2465 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2466 return format (s, "ip6");
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002467 default:
2468 return format (s, "unknown %d", next_index);
2469 }
2470 return s;
2471}
2472
2473static void
Dave Barach72d72232016-08-04 10:15:08 -04002474vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *
2475 mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002476{
Dave Barach72d72232016-08-04 10:15:08 -04002477 vat_main_t *vam = &vat_main;
2478 u8 *iid_str;
2479 u8 *flag_str = NULL;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002480
Dave Barach72d72232016-08-04 10:15:08 -04002481 iid_str = format (0, "%d (0x%x)", ntohl (mp->iid), ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002482
2483#define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2484 foreach_lisp_gpe_flag_bit;
2485#undef _
2486
Dave Barach72d72232016-08-04 10:15:08 -04002487 fformat (vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2488 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2489 mp->tunnels,
2490 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2491 mp->source_ip,
2492 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2493 mp->destination_ip,
2494 ntohl (mp->encap_fib_id),
2495 ntohl (mp->decap_fib_id),
2496 format_decap_next, ntohl (mp->dcap_next),
2497 mp->ver_res >> 6,
2498 flag_str, mp->next_protocol, mp->ver_res, mp->res, iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002499
Dave Barach72d72232016-08-04 10:15:08 -04002500 vec_free (iid_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002501}
2502
2503static void
Dave Barach72d72232016-08-04 10:15:08 -04002504 vl_api_lisp_gpe_tunnel_details_t_handler_json
2505 (vl_api_lisp_gpe_tunnel_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002506{
Dave Barach72d72232016-08-04 10:15:08 -04002507 vat_main_t *vam = &vat_main;
2508 vat_json_node_t *node = NULL;
2509 struct in6_addr ip6;
2510 struct in_addr ip4;
2511 u8 *next_decap_str;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002512
Dave Barach72d72232016-08-04 10:15:08 -04002513 next_decap_str = format (0, "%U", format_decap_next, htonl (mp->dcap_next));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002514
Dave Barach72d72232016-08-04 10:15:08 -04002515 if (VAT_JSON_ARRAY != vam->json_tree.type)
2516 {
2517 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2518 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002519 }
Dave Barach72d72232016-08-04 10:15:08 -04002520 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002521
Dave Barach72d72232016-08-04 10:15:08 -04002522 vat_json_init_object (node);
2523 vat_json_object_add_uint (node, "tunel", mp->tunnels);
2524 if (mp->is_ipv6)
2525 {
2526 clib_memcpy (&ip6, mp->source_ip, sizeof (ip6));
2527 vat_json_object_add_ip6 (node, "source address", ip6);
2528 clib_memcpy (&ip6, mp->destination_ip, sizeof (ip6));
2529 vat_json_object_add_ip6 (node, "destination address", ip6);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002530 }
Dave Barach72d72232016-08-04 10:15:08 -04002531 else
2532 {
2533 clib_memcpy (&ip4, mp->source_ip, sizeof (ip4));
2534 vat_json_object_add_ip4 (node, "source address", ip4);
2535 clib_memcpy (&ip4, mp->destination_ip, sizeof (ip4));
2536 vat_json_object_add_ip4 (node, "destination address", ip4);
2537 }
2538 vat_json_object_add_uint (node, "fib encap", ntohl (mp->encap_fib_id));
2539 vat_json_object_add_uint (node, "fib decap", ntohl (mp->decap_fib_id));
2540 vat_json_object_add_string_copy (node, "decap next", next_decap_str);
2541 vat_json_object_add_uint (node, "lisp version", mp->ver_res >> 6);
2542 vat_json_object_add_uint (node, "flags", mp->flags);
2543 vat_json_object_add_uint (node, "next protocol", mp->next_protocol);
2544 vat_json_object_add_uint (node, "ver_res", mp->ver_res);
2545 vat_json_object_add_uint (node, "res", mp->res);
2546 vat_json_object_add_uint (node, "iid", ntohl (mp->iid));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002547
Dave Barach72d72232016-08-04 10:15:08 -04002548 vec_free (next_decap_str);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002549}
2550
2551static void
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002552 vl_api_show_lisp_map_register_state_reply_t_handler
2553 (vl_api_show_lisp_map_register_state_reply_t * mp)
2554{
2555 vat_main_t *vam = &vat_main;
2556 int retval = clib_net_to_host_u32 (mp->retval);
2557
2558 fformat (vam->ofp, "%s\n", mp->is_enabled ? "enabled" : "disabled");
2559
2560 vam->retval = retval;
2561 vam->result_ready = 1;
2562}
2563
2564static void
2565 vl_api_show_lisp_map_register_state_reply_t_handler_json
2566 (vl_api_show_lisp_map_register_state_reply_t * mp)
2567{
2568 vat_main_t *vam = &vat_main;
2569 vat_json_node_t _node, *node = &_node;
2570 int retval = clib_net_to_host_u32 (mp->retval);
2571
2572 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
2573
2574 vat_json_init_object (node);
2575 vat_json_object_add_string_copy (node, "state", s);
2576
2577 vat_json_print (vam->ofp, node);
2578 vat_json_free (node);
2579
2580 vam->retval = retval;
2581 vam->result_ready = 1;
2582 vec_free (s);
2583}
2584
2585static void
2586 vl_api_show_lisp_rloc_probe_state_reply_t_handler
2587 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
2588{
2589 vat_main_t *vam = &vat_main;
2590 int retval = clib_net_to_host_u32 (mp->retval);
2591
2592 if (retval)
2593 goto end;
2594
2595 fformat (vam->ofp, "%s\n", mp->is_enabled ? "enabled" : "disabled");
2596end:
2597 vam->retval = retval;
2598 vam->result_ready = 1;
2599}
2600
2601static void
2602 vl_api_show_lisp_rloc_probe_state_reply_t_handler_json
2603 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
2604{
2605 vat_main_t *vam = &vat_main;
2606 vat_json_node_t _node, *node = &_node;
2607 int retval = clib_net_to_host_u32 (mp->retval);
2608
2609 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
2610 vat_json_init_object (node);
2611 vat_json_object_add_string_copy (node, "state", s);
2612
2613 vat_json_print (vam->ofp, node);
2614 vat_json_free (node);
2615
2616 vam->retval = retval;
2617 vam->result_ready = 1;
2618 vec_free (s);
2619}
2620
2621static void
Filip Tehlar69a9b762016-09-23 10:00:52 +02002622 vl_api_lisp_adjacencies_get_reply_t_handler
2623 (vl_api_lisp_adjacencies_get_reply_t * mp)
2624{
2625 vat_main_t *vam = &vat_main;
2626 u32 i, n;
2627 int retval = clib_net_to_host_u32 (mp->retval);
2628 vl_api_lisp_adjacency_t *a;
2629
2630 if (retval)
2631 goto end;
2632
2633 n = clib_net_to_host_u32 (mp->count);
2634
2635 for (i = 0; i < n; i++)
2636 {
2637 a = &mp->adjacencies[i];
2638 fformat (vam->ofp, "%U %40U\n",
2639 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
2640 format_lisp_flat_eid, a->eid_type, a->reid,
2641 a->reid_prefix_len);
2642 }
2643
2644end:
2645 vam->retval = retval;
2646 vam->result_ready = 1;
2647}
2648
2649static void
2650 vl_api_lisp_adjacencies_get_reply_t_handler_json
2651 (vl_api_lisp_adjacencies_get_reply_t * mp)
2652{
2653 u8 *s = 0;
2654 vat_main_t *vam = &vat_main;
2655 vat_json_node_t *e = 0, root;
2656 u32 i, n;
2657 int retval = clib_net_to_host_u32 (mp->retval);
2658 vl_api_lisp_adjacency_t *a;
2659
2660 if (retval)
2661 goto end;
2662
2663 n = clib_net_to_host_u32 (mp->count);
2664 vat_json_init_array (&root);
2665
2666 for (i = 0; i < n; i++)
2667 {
2668 e = vat_json_array_add (&root);
2669 a = &mp->adjacencies[i];
2670
2671 vat_json_init_object (e);
2672 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
2673 a->leid_prefix_len);
2674 vec_add1 (s, 0);
2675 vat_json_object_add_string_copy (e, "leid", s);
2676 vec_free (s);
2677
2678 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
2679 a->reid_prefix_len);
2680 vec_add1 (s, 0);
2681 vat_json_object_add_string_copy (e, "reid", s);
2682 vec_free (s);
2683 }
2684
2685 vat_json_print (vam->ofp, &root);
2686 vat_json_free (&root);
2687
2688end:
2689 vam->retval = retval;
2690 vam->result_ready = 1;
2691}
2692
2693static void
Filip Tehlar397fd7d2016-10-26 14:31:24 +02002694vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t
2695 * mp)
2696{
2697 vat_main_t *vam = &vat_main;
2698
2699 fformat (vam->ofp, "%=20U\n",
2700 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2701 mp->ip_address);
2702}
2703
2704static void
2705 vl_api_lisp_map_server_details_t_handler_json
2706 (vl_api_lisp_map_server_details_t * mp)
2707{
2708 vat_main_t *vam = &vat_main;
2709 vat_json_node_t *node = NULL;
2710 struct in6_addr ip6;
2711 struct in_addr ip4;
2712
2713 if (VAT_JSON_ARRAY != vam->json_tree.type)
2714 {
2715 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2716 vat_json_init_array (&vam->json_tree);
2717 }
2718 node = vat_json_array_add (&vam->json_tree);
2719
2720 vat_json_init_object (node);
2721 if (mp->is_ipv6)
2722 {
2723 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2724 vat_json_object_add_ip6 (node, "map-server", ip6);
2725 }
2726 else
2727 {
2728 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2729 vat_json_object_add_ip4 (node, "map-server", ip4);
2730 }
2731}
2732
2733static void
Dave Barach72d72232016-08-04 10:15:08 -04002734vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
2735 * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002736{
Dave Barach72d72232016-08-04 10:15:08 -04002737 vat_main_t *vam = &vat_main;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002738
Dave Barach72d72232016-08-04 10:15:08 -04002739 fformat (vam->ofp, "%=20U\n",
2740 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2741 mp->ip_address);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002742}
2743
2744static void
Dave Barach72d72232016-08-04 10:15:08 -04002745 vl_api_lisp_map_resolver_details_t_handler_json
2746 (vl_api_lisp_map_resolver_details_t * mp)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002747{
Dave Barach72d72232016-08-04 10:15:08 -04002748 vat_main_t *vam = &vat_main;
2749 vat_json_node_t *node = NULL;
2750 struct in6_addr ip6;
2751 struct in_addr ip4;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002752
Dave Barach72d72232016-08-04 10:15:08 -04002753 if (VAT_JSON_ARRAY != vam->json_tree.type)
2754 {
2755 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2756 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002757 }
Dave Barach72d72232016-08-04 10:15:08 -04002758 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002759
Dave Barach72d72232016-08-04 10:15:08 -04002760 vat_json_init_object (node);
2761 if (mp->is_ipv6)
2762 {
2763 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2764 vat_json_object_add_ip6 (node, "map resolver", ip6);
2765 }
2766 else
2767 {
2768 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2769 vat_json_object_add_ip4 (node, "map resolver", ip4);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02002770 }
2771}
2772
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002773static void
Dave Barach72d72232016-08-04 10:15:08 -04002774 vl_api_show_lisp_status_reply_t_handler
2775 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002776{
Dave Barach72d72232016-08-04 10:15:08 -04002777 vat_main_t *vam = &vat_main;
2778 i32 retval = ntohl (mp->retval);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002779
Dave Barach72d72232016-08-04 10:15:08 -04002780 if (0 <= retval)
2781 {
2782 fformat (vam->ofp, "feature: %s\ngpe: %s\n",
2783 mp->feature_status ? "enabled" : "disabled",
2784 mp->gpe_status ? "enabled" : "disabled");
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002785 }
2786
Dave Barach72d72232016-08-04 10:15:08 -04002787 vam->retval = retval;
2788 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002789}
2790
2791static void
Dave Barach72d72232016-08-04 10:15:08 -04002792 vl_api_show_lisp_status_reply_t_handler_json
2793 (vl_api_show_lisp_status_reply_t * mp)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002794{
Dave Barach72d72232016-08-04 10:15:08 -04002795 vat_main_t *vam = &vat_main;
2796 vat_json_node_t node;
2797 u8 *gpe_status = NULL;
2798 u8 *feature_status = NULL;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002799
Dave Barach72d72232016-08-04 10:15:08 -04002800 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2801 feature_status = format (0, "%s",
2802 mp->feature_status ? "enabled" : "disabled");
2803 vec_add1 (gpe_status, 0);
2804 vec_add1 (feature_status, 0);
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002805
Dave Barach72d72232016-08-04 10:15:08 -04002806 vat_json_init_object (&node);
2807 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
2808 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
Filip Tehlar46d4e362016-05-09 09:39:26 +02002809
Dave Barach72d72232016-08-04 10:15:08 -04002810 vec_free (gpe_status);
2811 vec_free (feature_status);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002812
Dave Barach72d72232016-08-04 10:15:08 -04002813 vat_json_print (vam->ofp, &node);
2814 vat_json_free (&node);
Andrej Kozemcakd9831182016-06-20 08:47:57 +02002815
Dave Barach72d72232016-08-04 10:15:08 -04002816 vam->retval = ntohl (mp->retval);
2817 vam->result_ready = 1;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02002818}
2819
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002820static void
Dave Barach72d72232016-08-04 10:15:08 -04002821 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
2822 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002823{
Dave Barach72d72232016-08-04 10:15:08 -04002824 vat_main_t *vam = &vat_main;
2825 i32 retval = ntohl (mp->retval);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002826
Dave Barach72d72232016-08-04 10:15:08 -04002827 if (retval >= 0)
2828 {
2829 fformat (vam->ofp, "%=20s\n", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002830 }
2831
Dave Barach72d72232016-08-04 10:15:08 -04002832 vam->retval = retval;
2833 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002834}
2835
2836static void
Dave Barach72d72232016-08-04 10:15:08 -04002837 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json
2838 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002839{
Dave Barach72d72232016-08-04 10:15:08 -04002840 vat_main_t *vam = &vat_main;
2841 vat_json_node_t *node = NULL;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002842
Dave Barach72d72232016-08-04 10:15:08 -04002843 if (VAT_JSON_ARRAY != vam->json_tree.type)
2844 {
2845 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2846 vat_json_init_array (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002847 }
Dave Barach72d72232016-08-04 10:15:08 -04002848 node = vat_json_array_add (&vam->json_tree);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002849
Dave Barach72d72232016-08-04 10:15:08 -04002850 vat_json_init_object (node);
2851 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002852
Dave Barach72d72232016-08-04 10:15:08 -04002853 vat_json_print (vam->ofp, node);
2854 vat_json_free (node);
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002855
Dave Barach72d72232016-08-04 10:15:08 -04002856 vam->retval = ntohl (mp->retval);
2857 vam->result_ready = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02002858}
2859
Florin Corasdca88042016-09-14 16:01:38 +02002860static u8 *
2861format_lisp_map_request_mode (u8 * s, va_list * args)
2862{
2863 u32 mode = va_arg (*args, u32);
2864
2865 switch (mode)
2866 {
2867 case 0:
2868 return format (0, "dst-only");
2869 case 1:
2870 return format (0, "src-dst");
2871 }
2872 return 0;
2873}
2874
2875static void
2876 vl_api_show_lisp_map_request_mode_reply_t_handler
2877 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2878{
2879 vat_main_t *vam = &vat_main;
2880 i32 retval = ntohl (mp->retval);
2881
2882 if (0 <= retval)
2883 {
2884 u32 mode = mp->mode;
2885 fformat (vam->ofp, "map_request_mode: %U\n",
2886 format_lisp_map_request_mode, mode);
2887 }
2888
2889 vam->retval = retval;
2890 vam->result_ready = 1;
2891}
2892
2893static void
2894 vl_api_show_lisp_map_request_mode_reply_t_handler_json
2895 (vl_api_show_lisp_map_request_mode_reply_t * mp)
2896{
2897 vat_main_t *vam = &vat_main;
2898 vat_json_node_t node;
2899 u8 *s = 0;
2900 u32 mode;
2901
2902 mode = mp->mode;
2903 s = format (0, "%U", format_lisp_map_request_mode, mode);
2904 vec_add1 (s, 0);
2905
2906 vat_json_init_object (&node);
2907 vat_json_object_add_string_copy (&node, "map_request_mode", s);
2908 vat_json_print (vam->ofp, &node);
2909 vat_json_free (&node);
2910
2911 vec_free (s);
2912 vam->retval = ntohl (mp->retval);
2913 vam->result_ready = 1;
2914}
2915
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002916static void
2917vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2918{
Dave Barach72d72232016-08-04 10:15:08 -04002919 vat_main_t *vam = &vat_main;
2920 i32 retval = ntohl (mp->retval);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002921
Dave Barach72d72232016-08-04 10:15:08 -04002922 if (0 <= retval)
2923 {
2924 fformat (vam->ofp, "%-20s%-16s\n",
2925 mp->status ? "enabled" : "disabled",
2926 mp->status ? (char *) mp->locator_set_name : "");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002927 }
2928
Dave Barach72d72232016-08-04 10:15:08 -04002929 vam->retval = retval;
2930 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002931}
2932
2933static void
Dave Barach72d72232016-08-04 10:15:08 -04002934vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t *
2935 mp)
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002936{
Dave Barach72d72232016-08-04 10:15:08 -04002937 vat_main_t *vam = &vat_main;
2938 vat_json_node_t node;
2939 u8 *status = 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002940
Dave Barach72d72232016-08-04 10:15:08 -04002941 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2942 vec_add1 (status, 0);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002943
Dave Barach72d72232016-08-04 10:15:08 -04002944 vat_json_init_object (&node);
2945 vat_json_object_add_string_copy (&node, "status", status);
2946 if (mp->status)
2947 {
2948 vat_json_object_add_string_copy (&node, "locator_set",
2949 mp->locator_set_name);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002950 }
2951
Dave Barach72d72232016-08-04 10:15:08 -04002952 vec_free (status);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002953
Dave Barach72d72232016-08-04 10:15:08 -04002954 vat_json_print (vam->ofp, &node);
2955 vat_json_free (&node);
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002956
Dave Barach72d72232016-08-04 10:15:08 -04002957 vam->retval = ntohl (mp->retval);
2958 vam->result_ready = 1;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02002959}
2960
Dave Barach72d72232016-08-04 10:15:08 -04002961static u8 *
2962format_policer_type (u8 * s, va_list * va)
Matus Fabiane8554802016-05-18 23:40:37 -07002963{
Dave Barach72d72232016-08-04 10:15:08 -04002964 u32 i = va_arg (*va, u32);
Matus Fabiane8554802016-05-18 23:40:37 -07002965
Dave Barach72d72232016-08-04 10:15:08 -04002966 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2967 s = format (s, "1r2c");
2968 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2969 s = format (s, "1r3c");
2970 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2971 s = format (s, "2r3c-2698");
2972 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2973 s = format (s, "2r3c-4115");
2974 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2975 s = format (s, "2r3c-mef5cf1");
2976 else
2977 s = format (s, "ILLEGAL");
Matus Fabiane8554802016-05-18 23:40:37 -07002978 return s;
2979}
2980
Dave Barach72d72232016-08-04 10:15:08 -04002981static u8 *
2982format_policer_rate_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -07002983{
2984 u32 i = va_arg (*va, u32);
Matus Fabian4ac74c92016-05-31 07:33:29 -07002985
Dave Barach72d72232016-08-04 10:15:08 -04002986 if (i == SSE2_QOS_RATE_KBPS)
2987 s = format (s, "kbps");
2988 else if (i == SSE2_QOS_RATE_PPS)
2989 s = format (s, "pps");
2990 else
2991 s = format (s, "ILLEGAL");
2992 return s;
2993}
2994
2995static u8 *
2996format_policer_round_type (u8 * s, va_list * va)
2997{
2998 u32 i = va_arg (*va, u32);
2999
3000 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
3001 s = format (s, "closest");
3002 else if (i == SSE2_QOS_ROUND_TO_UP)
3003 s = format (s, "up");
3004 else if (i == SSE2_QOS_ROUND_TO_DOWN)
3005 s = format (s, "down");
3006 else
3007 s = format (s, "ILLEGAL");
3008 return s;
3009}
3010
3011static u8 *
3012format_policer_action_type (u8 * s, va_list * va)
3013{
3014 u32 i = va_arg (*va, u32);
3015
3016 if (i == SSE2_QOS_ACTION_DROP)
3017 s = format (s, "drop");
3018 else if (i == SSE2_QOS_ACTION_TRANSMIT)
3019 s = format (s, "transmit");
3020 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3021 s = format (s, "mark-and-transmit");
3022 else
3023 s = format (s, "ILLEGAL");
3024 return s;
3025}
3026
3027static u8 *
3028format_dscp (u8 * s, va_list * va)
3029{
3030 u32 i = va_arg (*va, u32);
3031 char *t = 0;
3032
3033 switch (i)
3034 {
3035#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
3036 foreach_vnet_dscp
3037#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -07003038 default:
3039 return format (s, "ILLEGAL");
Dave Barach72d72232016-08-04 10:15:08 -04003040 }
Matus Fabian4ac74c92016-05-31 07:33:29 -07003041 s = format (s, "%s", t);
3042 return s;
3043}
3044
Dave Barach72d72232016-08-04 10:15:08 -04003045static void
3046vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07003047{
Dave Barach72d72232016-08-04 10:15:08 -04003048 vat_main_t *vam = &vat_main;
3049 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
Matus Fabian4ac74c92016-05-31 07:33:29 -07003050
Dave Barach72d72232016-08-04 10:15:08 -04003051 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3052 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3053 else
3054 conform_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07003055
Dave Barach72d72232016-08-04 10:15:08 -04003056 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3057 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3058 else
3059 exceed_dscp_str = format (0, "");
Matus Fabian4ac74c92016-05-31 07:33:29 -07003060
Dave Barach72d72232016-08-04 10:15:08 -04003061 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3062 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3063 else
3064 violate_dscp_str = format (0, "");
Matus Fabiane8554802016-05-18 23:40:37 -07003065
Dave Barach72d72232016-08-04 10:15:08 -04003066 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
3067 "rate type %U, round type %U, %s rate, %s color-aware, "
3068 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
3069 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
3070 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
3071 mp->name,
3072 format_policer_type, mp->type,
3073 ntohl (mp->cir),
3074 ntohl (mp->eir),
3075 clib_net_to_host_u64 (mp->cb),
3076 clib_net_to_host_u64 (mp->eb),
3077 format_policer_rate_type, mp->rate_type,
3078 format_policer_round_type, mp->round_type,
3079 mp->single_rate ? "single" : "dual",
3080 mp->color_aware ? "is" : "not",
3081 ntohl (mp->cir_tokens_per_period),
3082 ntohl (mp->pir_tokens_per_period),
3083 ntohl (mp->scale),
3084 ntohl (mp->current_limit),
3085 ntohl (mp->current_bucket),
3086 ntohl (mp->extended_limit),
3087 ntohl (mp->extended_bucket),
3088 clib_net_to_host_u64 (mp->last_update_time),
3089 format_policer_action_type, mp->conform_action_type,
3090 conform_dscp_str,
3091 format_policer_action_type, mp->exceed_action_type,
3092 exceed_dscp_str,
3093 format_policer_action_type, mp->violate_action_type,
3094 violate_dscp_str);
Matus Fabian4ac74c92016-05-31 07:33:29 -07003095
Dave Barach72d72232016-08-04 10:15:08 -04003096 vec_free (conform_dscp_str);
3097 vec_free (exceed_dscp_str);
3098 vec_free (violate_dscp_str);
Matus Fabiane8554802016-05-18 23:40:37 -07003099}
3100
3101static void vl_api_policer_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003102 (vl_api_policer_details_t * mp)
Matus Fabiane8554802016-05-18 23:40:37 -07003103{
Dave Barach72d72232016-08-04 10:15:08 -04003104 vat_main_t *vam = &vat_main;
3105 vat_json_node_t *node;
3106 u8 *rate_type_str, *round_type_str, *type_str;
3107 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
Matus Fabiane8554802016-05-18 23:40:37 -07003108
Dave Barach72d72232016-08-04 10:15:08 -04003109 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
3110 round_type_str =
3111 format (0, "%U", format_policer_round_type, mp->round_type);
3112 type_str = format (0, "%U", format_policer_type, mp->type);
3113 conform_action_str = format (0, "%U", format_policer_action_type,
3114 mp->conform_action_type);
3115 exceed_action_str = format (0, "%U", format_policer_action_type,
3116 mp->exceed_action_type);
3117 violate_action_str = format (0, "%U", format_policer_action_type,
3118 mp->violate_action_type);
Matus Fabiane8554802016-05-18 23:40:37 -07003119
Dave Barach72d72232016-08-04 10:15:08 -04003120 if (VAT_JSON_ARRAY != vam->json_tree.type)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003121 {
Dave Barach72d72232016-08-04 10:15:08 -04003122 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3123 vat_json_init_array (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003124 }
Dave Barach72d72232016-08-04 10:15:08 -04003125 node = vat_json_array_add (&vam->json_tree);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003126
Dave Barach72d72232016-08-04 10:15:08 -04003127 vat_json_init_object (node);
3128 vat_json_object_add_string_copy (node, "name", mp->name);
3129 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
3130 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
3131 vat_json_object_add_uint (node, "cb", ntohl (mp->cb));
3132 vat_json_object_add_uint (node, "eb", ntohl (mp->eb));
3133 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
3134 vat_json_object_add_string_copy (node, "round_type", round_type_str);
3135 vat_json_object_add_string_copy (node, "type", type_str);
3136 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
3137 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
3138 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
3139 vat_json_object_add_uint (node, "cir_tokens_per_period",
3140 ntohl (mp->cir_tokens_per_period));
3141 vat_json_object_add_uint (node, "eir_tokens_per_period",
3142 ntohl (mp->pir_tokens_per_period));
3143 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
3144 vat_json_object_add_uint (node, "current_bucket",
3145 ntohl (mp->current_bucket));
3146 vat_json_object_add_uint (node, "extended_limit",
3147 ntohl (mp->extended_limit));
3148 vat_json_object_add_uint (node, "extended_bucket",
3149 ntohl (mp->extended_bucket));
3150 vat_json_object_add_uint (node, "last_update_time",
3151 ntohl (mp->last_update_time));
3152 vat_json_object_add_string_copy (node, "conform_action",
3153 conform_action_str);
3154 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3155 {
3156 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
3157 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
3158 vec_free (dscp_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003159 }
Dave Barach72d72232016-08-04 10:15:08 -04003160 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
3161 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3162 {
3163 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
3164 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
3165 vec_free (dscp_str);
3166 }
3167 vat_json_object_add_string_copy (node, "violate_action",
3168 violate_action_str);
3169 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
3170 {
3171 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
3172 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
3173 vec_free (dscp_str);
3174 }
3175
3176 vec_free (rate_type_str);
3177 vec_free (round_type_str);
3178 vec_free (type_str);
3179 vec_free (conform_action_str);
3180 vec_free (exceed_action_str);
3181 vec_free (violate_action_str);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003182}
3183
Dave Barach72d72232016-08-04 10:15:08 -04003184static void
3185vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
3186 mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003187{
Dave Barach72d72232016-08-04 10:15:08 -04003188 vat_main_t *vam = &vat_main;
3189 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003190
Dave Barach72d72232016-08-04 10:15:08 -04003191 if (count > 0)
3192 fformat (vam->ofp, "classify table ids (%d) : ", count);
3193 for (i = 0; i < count; i++)
3194 {
3195 fformat (vam->ofp, "%d", ntohl (mp->ids[i]));
3196 fformat (vam->ofp, (i < count - 1) ? "," : "\n");
3197 }
3198 vam->retval = ntohl (mp->retval);
3199 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003200}
3201
Dave Barach72d72232016-08-04 10:15:08 -04003202static void
3203 vl_api_classify_table_ids_reply_t_handler_json
3204 (vl_api_classify_table_ids_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003205{
Dave Barach72d72232016-08-04 10:15:08 -04003206 vat_main_t *vam = &vat_main;
3207 int i, count = ntohl (mp->count);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003208
Dave Barach72d72232016-08-04 10:15:08 -04003209 if (count > 0)
3210 {
3211 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003212
Dave Barach72d72232016-08-04 10:15:08 -04003213 vat_json_init_object (&node);
3214 for (i = 0; i < count; i++)
3215 {
3216 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
3217 }
3218 vat_json_print (vam->ofp, &node);
3219 vat_json_free (&node);
3220 }
3221 vam->retval = ntohl (mp->retval);
3222 vam->result_ready = 1;
3223}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003224
Dave Barach72d72232016-08-04 10:15:08 -04003225static void
3226 vl_api_classify_table_by_interface_reply_t_handler
3227 (vl_api_classify_table_by_interface_reply_t * mp)
3228{
3229 vat_main_t *vam = &vat_main;
3230 u32 table_id;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003231
Dave Barach72d72232016-08-04 10:15:08 -04003232 table_id = ntohl (mp->l2_table_id);
3233 if (table_id != ~0)
3234 fformat (vam->ofp, "l2 table id : %d\n", table_id);
3235 else
3236 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
3237 table_id = ntohl (mp->ip4_table_id);
3238 if (table_id != ~0)
3239 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
3240 else
3241 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
3242 table_id = ntohl (mp->ip6_table_id);
3243 if (table_id != ~0)
3244 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
3245 else
3246 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
3247 vam->retval = ntohl (mp->retval);
3248 vam->result_ready = 1;
3249}
3250
3251static void
3252 vl_api_classify_table_by_interface_reply_t_handler_json
3253 (vl_api_classify_table_by_interface_reply_t * mp)
3254{
3255 vat_main_t *vam = &vat_main;
3256 vat_json_node_t node;
3257
3258 vat_json_init_object (&node);
3259
3260 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
3261 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
3262 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
3263
3264 vat_json_print (vam->ofp, &node);
3265 vat_json_free (&node);
3266
3267 vam->retval = ntohl (mp->retval);
3268 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003269}
3270
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003271static void vl_api_policer_add_del_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003272 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003273{
Dave Barach72d72232016-08-04 10:15:08 -04003274 vat_main_t *vam = &vat_main;
3275 i32 retval = ntohl (mp->retval);
3276 if (vam->async_mode)
3277 {
3278 vam->async_errors += (retval < 0);
3279 }
3280 else
3281 {
3282 vam->retval = retval;
3283 vam->result_ready = 1;
3284 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3285 /*
3286 * Note: this is just barely thread-safe, depends on
3287 * the main thread spinning waiting for an answer...
3288 */
3289 errmsg ("policer index %d\n", ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003290 }
3291}
3292
3293static void vl_api_policer_add_del_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003294 (vl_api_policer_add_del_reply_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003295{
Dave Barach72d72232016-08-04 10:15:08 -04003296 vat_main_t *vam = &vat_main;
3297 vat_json_node_t node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003298
Dave Barach72d72232016-08-04 10:15:08 -04003299 vat_json_init_object (&node);
3300 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3301 vat_json_object_add_uint (&node, "policer_index",
3302 ntohl (mp->policer_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003303
Dave Barach72d72232016-08-04 10:15:08 -04003304 vat_json_print (vam->ofp, &node);
3305 vat_json_free (&node);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003306
Dave Barach72d72232016-08-04 10:15:08 -04003307 vam->retval = ntohl (mp->retval);
3308 vam->result_ready = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003309}
3310
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003311/* Format hex dump. */
Dave Barach72d72232016-08-04 10:15:08 -04003312u8 *
3313format_hex_bytes (u8 * s, va_list * va)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003314{
Dave Barach72d72232016-08-04 10:15:08 -04003315 u8 *bytes = va_arg (*va, u8 *);
3316 int n_bytes = va_arg (*va, int);
3317 uword i;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003318
Dave Barach72d72232016-08-04 10:15:08 -04003319 /* Print short or long form depending on byte count. */
3320 uword short_form = n_bytes <= 32;
3321 uword indent = format_get_indent (s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003322
Dave Barach72d72232016-08-04 10:15:08 -04003323 if (n_bytes == 0)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003324 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003325
Dave Barach72d72232016-08-04 10:15:08 -04003326 for (i = 0; i < n_bytes; i++)
3327 {
3328 if (!short_form && (i % 32) == 0)
3329 s = format (s, "%08x: ", i);
3330 s = format (s, "%02x", bytes[i]);
3331 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3332 s = format (s, "\n%U", format_white_space, indent);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003333 }
Dave Barach72d72232016-08-04 10:15:08 -04003334
3335 return s;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003336}
3337
Dave Barach72d72232016-08-04 10:15:08 -04003338static void
3339vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3340 * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003341{
Dave Barach72d72232016-08-04 10:15:08 -04003342 vat_main_t *vam = &vat_main;
3343 i32 retval = ntohl (mp->retval);
3344 if (retval == 0)
3345 {
3346 fformat (vam->ofp, "classify table info :\n");
3347 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n",
3348 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3349 ntohl (mp->miss_next_index));
3350 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n",
3351 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3352 ntohl (mp->match_n_vectors));
3353 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask,
3354 ntohl (mp->mask_length));
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003355 }
Dave Barach72d72232016-08-04 10:15:08 -04003356 vam->retval = retval;
3357 vam->result_ready = 1;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003358}
3359
Dave Barach72d72232016-08-04 10:15:08 -04003360static void
3361 vl_api_classify_table_info_reply_t_handler_json
3362 (vl_api_classify_table_info_reply_t * mp)
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003363{
Dave Barach72d72232016-08-04 10:15:08 -04003364 vat_main_t *vam = &vat_main;
3365 vat_json_node_t node;
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003366
Dave Barach72d72232016-08-04 10:15:08 -04003367 i32 retval = ntohl (mp->retval);
3368 if (retval == 0)
3369 {
3370 vat_json_init_object (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003371
Dave Barach72d72232016-08-04 10:15:08 -04003372 vat_json_object_add_int (&node, "sessions",
3373 ntohl (mp->active_sessions));
3374 vat_json_object_add_int (&node, "nexttbl",
3375 ntohl (mp->next_table_index));
3376 vat_json_object_add_int (&node, "nextnode",
3377 ntohl (mp->miss_next_index));
3378 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3379 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3380 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3381 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3382 ntohl (mp->mask_length), 0);
3383 vat_json_object_add_string_copy (&node, "mask", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003384
Dave Barach72d72232016-08-04 10:15:08 -04003385 vat_json_print (vam->ofp, &node);
3386 vat_json_free (&node);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003387 }
Dave Barach72d72232016-08-04 10:15:08 -04003388 vam->retval = ntohl (mp->retval);
3389 vam->result_ready = 1;
3390}
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003391
Dave Barach72d72232016-08-04 10:15:08 -04003392static void
3393vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3394 mp)
3395{
3396 vat_main_t *vam = &vat_main;
3397
3398 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3399 ntohl (mp->hit_next_index), ntohl (mp->advance),
3400 ntohl (mp->opaque_index));
3401 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match,
3402 ntohl (mp->match_length));
3403}
3404
3405static void
3406 vl_api_classify_session_details_t_handler_json
3407 (vl_api_classify_session_details_t * mp)
3408{
3409 vat_main_t *vam = &vat_main;
3410 vat_json_node_t *node = NULL;
3411
3412 if (VAT_JSON_ARRAY != vam->json_tree.type)
3413 {
3414 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3415 vat_json_init_array (&vam->json_tree);
3416 }
3417 node = vat_json_array_add (&vam->json_tree);
3418
3419 vat_json_init_object (node);
3420 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3421 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3422 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3423 u8 *s =
3424 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3425 0);
3426 vat_json_object_add_string_copy (node, "match", s);
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003427}
Matus Fabiane8554802016-05-18 23:40:37 -07003428
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003429static void vl_api_pg_create_interface_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003430 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003431{
Dave Barach72d72232016-08-04 10:15:08 -04003432 vat_main_t *vam = &vat_main;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003433
Dave Barach72d72232016-08-04 10:15:08 -04003434 vam->retval = ntohl (mp->retval);
3435 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003436}
3437
3438static void vl_api_pg_create_interface_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003439 (vl_api_pg_create_interface_reply_t * mp)
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003440{
Dave Barach72d72232016-08-04 10:15:08 -04003441 vat_main_t *vam = &vat_main;
3442 vat_json_node_t node;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003443
Dave Barach72d72232016-08-04 10:15:08 -04003444 i32 retval = ntohl (mp->retval);
3445 if (retval == 0)
3446 {
3447 vat_json_init_object (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003448
Dave Barach72d72232016-08-04 10:15:08 -04003449 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003450
Dave Barach72d72232016-08-04 10:15:08 -04003451 vat_json_print (vam->ofp, &node);
3452 vat_json_free (&node);
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003453 }
Dave Barach72d72232016-08-04 10:15:08 -04003454 vam->retval = ntohl (mp->retval);
3455 vam->result_ready = 1;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003456}
3457
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003458static void vl_api_policer_classify_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -04003459 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003460{
Dave Barach72d72232016-08-04 10:15:08 -04003461 vat_main_t *vam = &vat_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003462
Dave Barach72d72232016-08-04 10:15:08 -04003463 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3464 ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003465}
3466
3467static void vl_api_policer_classify_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -04003468 (vl_api_policer_classify_details_t * mp)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003469{
Dave Barach72d72232016-08-04 10:15:08 -04003470 vat_main_t *vam = &vat_main;
3471 vat_json_node_t *node;
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003472
Dave Barach72d72232016-08-04 10:15:08 -04003473 if (VAT_JSON_ARRAY != vam->json_tree.type)
3474 {
3475 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3476 vat_json_init_array (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003477 }
Dave Barach72d72232016-08-04 10:15:08 -04003478 node = vat_json_array_add (&vam->json_tree);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003479
Dave Barach72d72232016-08-04 10:15:08 -04003480 vat_json_init_object (node);
3481 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3482 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003483}
3484
Matus Fabian694265d2016-08-10 01:55:36 -07003485static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
3486 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3487{
3488 vat_main_t *vam = &vat_main;
3489 i32 retval = ntohl (mp->retval);
3490 if (vam->async_mode)
3491 {
3492 vam->async_errors += (retval < 0);
3493 }
3494 else
3495 {
3496 vam->retval = retval;
3497 vam->sw_if_index = ntohl (mp->sw_if_index);
3498 vam->result_ready = 1;
3499 }
3500}
3501
3502static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
3503 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
3504{
3505 vat_main_t *vam = &vat_main;
3506 vat_json_node_t node;
3507
3508 vat_json_init_object (&node);
3509 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3510 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
3511
3512 vat_json_print (vam->ofp, &node);
3513 vat_json_free (&node);
3514
3515 vam->retval = ntohl (mp->retval);
3516 vam->result_ready = 1;
3517}
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003518
Juraj Sloboda506b2452016-08-07 23:45:24 -07003519static void vl_api_flow_classify_details_t_handler
3520 (vl_api_flow_classify_details_t * mp)
3521{
3522 vat_main_t *vam = &vat_main;
3523
3524 fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index),
3525 ntohl (mp->table_index));
3526}
3527
3528static void vl_api_flow_classify_details_t_handler_json
3529 (vl_api_flow_classify_details_t * mp)
3530{
3531 vat_main_t *vam = &vat_main;
3532 vat_json_node_t *node;
3533
3534 if (VAT_JSON_ARRAY != vam->json_tree.type)
3535 {
3536 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3537 vat_json_init_array (&vam->json_tree);
3538 }
3539 node = vat_json_array_add (&vam->json_tree);
3540
3541 vat_json_init_object (node);
3542 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3543 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3544}
3545
3546
3547
Ed Warnickecb9cada2015-12-08 15:45:58 -07003548#define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
3549#define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
3550#define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3551#define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
Filip Tehlar69a9b762016-09-23 10:00:52 +02003552#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler
3553#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler
Ed Warnickecb9cada2015-12-08 15:45:58 -07003554
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003555/*
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003556 * Generate boilerplate reply handlers, which
Ed Warnickecb9cada2015-12-08 15:45:58 -07003557 * dig the return value out of the xxx_reply_t API message,
3558 * stick it into vam->retval, and set vam->result_ready
3559 *
3560 * Could also do this by pointing N message decode slots at
3561 * a single function, but that could break in subtle ways.
3562 */
3563
3564#define foreach_standard_reply_retval_handler \
3565_(sw_interface_set_flags_reply) \
3566_(sw_interface_add_del_address_reply) \
3567_(sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003568_(sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003569_(sw_interface_set_vpath_reply) \
John Lo37682e12016-11-30 12:51:39 -05003570_(sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003571_(sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003572_(sw_interface_set_dpdk_hqos_pipe_reply) \
3573_(sw_interface_set_dpdk_hqos_subport_reply) \
3574_(sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003575_(bridge_domain_add_del_reply) \
3576_(sw_interface_set_l2_xconnect_reply) \
3577_(l2fib_add_del_reply) \
3578_(ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003579_(mpls_route_add_del_reply) \
3580_(mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003581_(proxy_arp_add_del_reply) \
3582_(proxy_arp_intfc_enable_disable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003583_(sw_interface_set_unnumbered_reply) \
3584_(ip_neighbor_add_del_reply) \
3585_(reset_vrf_reply) \
3586_(oam_add_del_reply) \
3587_(reset_fib_reply) \
3588_(dhcp_proxy_config_reply) \
3589_(dhcp_proxy_config_2_reply) \
3590_(dhcp_proxy_set_vss_reply) \
3591_(dhcp_client_config_reply) \
3592_(set_ip_flow_hash_reply) \
3593_(sw_interface_ip6_enable_disable_reply) \
3594_(sw_interface_ip6_set_link_local_address_reply) \
3595_(sw_interface_ip6nd_ra_prefix_reply) \
3596_(sw_interface_ip6nd_ra_config_reply) \
3597_(set_arp_neighbor_limit_reply) \
3598_(l2_patch_add_del_reply) \
3599_(sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003600_(sr_policy_add_del_reply) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07003601_(sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003602_(classify_add_del_session_reply) \
3603_(classify_set_interface_ip_table_reply) \
3604_(classify_set_interface_l2_tables_reply) \
3605_(l2tpv3_set_tunnel_cookies_reply) \
3606_(l2tpv3_interface_enable_disable_reply) \
3607_(l2tpv3_set_lookup_key_reply) \
3608_(l2_fib_clear_table_reply) \
3609_(l2_interface_efp_filter_reply) \
3610_(l2_interface_vlan_tag_rewrite_reply) \
3611_(modify_vhost_user_if_reply) \
3612_(delete_vhost_user_if_reply) \
3613_(want_ip4_arp_events_reply) \
John Lo1edfba92016-08-27 01:11:57 -04003614_(want_ip6_nd_events_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003615_(input_acl_set_interface_reply) \
3616_(ipsec_spd_add_del_reply) \
3617_(ipsec_interface_add_del_spd_reply) \
3618_(ipsec_spd_add_del_entry_reply) \
3619_(ipsec_sad_add_del_entry_reply) \
3620_(ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003621_(ikev2_profile_add_del_reply) \
3622_(ikev2_profile_set_auth_reply) \
3623_(ikev2_profile_set_id_reply) \
3624_(ikev2_profile_set_ts_reply) \
3625_(ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003626_(delete_loopback_reply) \
3627_(bd_ip_mac_add_del_reply) \
3628_(map_del_domain_reply) \
3629_(map_add_del_rule_reply) \
3630_(want_interface_events_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003631_(want_stats_reply) \
3632_(cop_interface_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003633_(cop_whitelist_enable_disable_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003634_(sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003635_(ioam_enable_reply) \
3636_(ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003637_(lisp_add_del_locator_reply) \
3638_(lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003639_(lisp_add_del_remote_mapping_reply) \
3640_(lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003641_(lisp_gpe_add_del_fwd_entry_reply) \
3642_(lisp_add_del_map_resolver_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003643_(lisp_add_del_map_server_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003644_(lisp_gpe_enable_disable_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003645_(lisp_gpe_add_del_iface_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003646_(lisp_enable_disable_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003647_(lisp_rloc_probe_enable_disable_reply) \
3648_(lisp_map_register_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003649_(lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003650_(lisp_map_request_mode_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003651_(lisp_add_del_map_request_itr_rlocs_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003652_(lisp_eid_table_add_del_map_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003653_(vxlan_gpe_add_del_tunnel_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003654_(af_packet_delete_reply) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003655_(policer_classify_set_interface_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003656_(netmap_create_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003657_(netmap_delete_reply) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003658_(set_ipfix_exporter_reply) \
3659_(set_ipfix_classify_stream_reply) \
3660_(ipfix_classify_table_add_del_reply) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003661_(flow_classify_set_interface_reply) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003662_(sw_interface_span_enable_disable_reply) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003663_(pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003664_(pg_enable_disable_reply) \
3665_(ip_source_and_port_range_check_add_del_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003666_(ip_source_and_port_range_check_interface_add_del_reply)\
Pavel Kotucek95300d12016-08-26 16:11:36 +02003667_(delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003668_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003669_(punt_reply) \
Dave Barach7be864a2016-11-28 11:41:35 -05003670_(feature_enable_disable_reply) \
Matus Fabiand162f3d2016-12-05 01:05:35 -08003671_(sw_interface_tag_add_del_reply) \
3672_(sw_interface_set_mtu_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003673
3674#define _(n) \
3675 static void vl_api_##n##_t_handler \
3676 (vl_api_##n##_t * mp) \
3677 { \
3678 vat_main_t * vam = &vat_main; \
3679 i32 retval = ntohl(mp->retval); \
3680 if (vam->async_mode) { \
3681 vam->async_errors += (retval < 0); \
3682 } else { \
3683 vam->retval = retval; \
3684 vam->result_ready = 1; \
3685 } \
3686 }
3687foreach_standard_reply_retval_handler;
3688#undef _
3689
3690#define _(n) \
3691 static void vl_api_##n##_t_handler_json \
3692 (vl_api_##n##_t * mp) \
3693 { \
3694 vat_main_t * vam = &vat_main; \
3695 vat_json_node_t node; \
3696 vat_json_init_object(&node); \
3697 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3698 vat_json_print(vam->ofp, &node); \
3699 vam->retval = ntohl(mp->retval); \
3700 vam->result_ready = 1; \
3701 }
3702foreach_standard_reply_retval_handler;
3703#undef _
3704
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08003705/*
Ed Warnickecb9cada2015-12-08 15:45:58 -07003706 * Table of message reply handlers, must include boilerplate handlers
3707 * we just generated
3708 */
3709
3710#define foreach_vpe_api_reply_msg \
3711_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3712_(SW_INTERFACE_DETAILS, sw_interface_details) \
3713_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3714_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3715_(CONTROL_PING_REPLY, control_ping_reply) \
3716_(CLI_REPLY, cli_reply) \
Ole Troanc27213a2016-08-31 14:50:49 +02003717_(CLI_INBAND_REPLY, cli_inband_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003718_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3719 sw_interface_add_del_address_reply) \
3720_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
John Lo06b14b92016-10-24 20:20:11 -04003721_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003722_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
John Lo37682e12016-11-30 12:51:39 -05003723_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003724_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3725 sw_interface_set_l2_xconnect_reply) \
3726_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3727 sw_interface_set_l2_bridge_reply) \
Jasvinder Singh85ecc812016-07-21 17:02:19 +01003728_(SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY, \
3729 sw_interface_set_dpdk_hqos_pipe_reply) \
3730_(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY, \
3731 sw_interface_set_dpdk_hqos_subport_reply) \
3732_(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
3733 sw_interface_set_dpdk_hqos_tctbl_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003734_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3735_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3736_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3737_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3738_(L2_FLAGS_REPLY, l2_flags_reply) \
3739_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3740_(TAP_CONNECT_REPLY, tap_connect_reply) \
3741_(TAP_MODIFY_REPLY, tap_modify_reply) \
3742_(TAP_DELETE_REPLY, tap_delete_reply) \
3743_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3744_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003745_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3746_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003747_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3748_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3749 proxy_arp_intfc_enable_disable_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003750_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003751_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3752 sw_interface_set_unnumbered_reply) \
3753_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3754_(RESET_VRF_REPLY, reset_vrf_reply) \
3755_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3756_(CREATE_SUBIF_REPLY, create_subif_reply) \
3757_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3758_(RESET_FIB_REPLY, reset_fib_reply) \
3759_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3760_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3761_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3762_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3763_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3764_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3765 sw_interface_ip6_enable_disable_reply) \
3766_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3767 sw_interface_ip6_set_link_local_address_reply) \
3768_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3769 sw_interface_ip6nd_ra_prefix_reply) \
3770_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3771 sw_interface_ip6nd_ra_config_reply) \
3772_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3773_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3774_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07003775_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3776_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003777_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3778_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3779_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3780classify_set_interface_ip_table_reply) \
3781_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3782 classify_set_interface_l2_tables_reply) \
3783_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3784_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3785_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3786_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3787_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3788 l2tpv3_interface_enable_disable_reply) \
3789_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3790_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3791_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
Dave Wallace60231f32015-12-17 21:04:30 -05003792_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Chris Luke27fe48f2016-04-28 13:44:38 -04003793_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3794_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003795_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3796_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3797_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3798_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3799_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3800_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3801_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3802_(SHOW_VERSION_REPLY, show_version_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003803_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +08003804_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3805_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003806_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3807_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3808_(IP4_ARP_EVENT, ip4_arp_event) \
John Lo1edfba92016-08-27 01:11:57 -04003809_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
3810_(IP6_ND_EVENT, ip6_nd_event) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003811_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3812_(IP_ADDRESS_DETAILS, ip_address_details) \
3813_(IP_DETAILS, ip_details) \
3814_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3815_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3816_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3817_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3818_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matus Fabiane5f42fe2016-04-08 11:18:08 +02003819_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3820_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3821_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3822_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3823_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003824_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3825_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3826_(DHCP_COMPL_EVENT, dhcp_compl_event) \
3827_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3828_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3829_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3830_(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3831_(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003832_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07003833_(MAP_DOMAIN_DETAILS, map_domain_details) \
3834_(MAP_RULE_DETAILS, map_rule_details) \
3835_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3836_(WANT_STATS_REPLY, want_stats_reply) \
Dave Barachc07bf5d2016-02-17 17:52:26 -05003837_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3838_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
Dave Barachb44e9bc2016-02-19 09:06:23 -05003839_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
Pavel Kotucek00bbf272016-03-03 13:27:11 +01003840_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
Shwetha20a64f52016-03-25 10:55:01 +00003841_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
Vengada Govindan07d2f842016-08-25 10:34:34 -07003842_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3843_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003844_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3845_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3846_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
Florin Corasf727db92016-06-23 15:01:58 +02003847_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3848_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003849_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3850_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003851_(LISP_ADD_DEL_MAP_SERVER_REPLY, lisp_add_del_map_server_reply) \
Florin Coras577c3552016-04-21 00:45:40 +02003852_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
Filip Tehlar46d4e362016-05-09 09:39:26 +02003853_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003854_(LISP_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
3855 lisp_map_register_enable_disable_reply) \
3856_(LISP_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
3857 lisp_rloc_probe_enable_disable_reply) \
Filip Tehlar53f09e32016-05-19 14:25:44 +02003858_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003859_(LISP_MAP_REQUEST_MODE_REPLY, lisp_map_request_mode_reply) \
Filip Tehlar324112f2016-06-02 16:07:38 +02003860_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003861_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3862_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003863_(LISP_LOCATOR_DETAILS, lisp_locator_details) \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +02003864_(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
Filip Tehlar2f653d02016-07-13 13:17:15 +02003865_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
Filip Tehlar50a4e142016-08-24 11:28:02 +02003866_(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +02003867_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +02003868_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003869_(LISP_MAP_SERVER_DETAILS, lisp_map_server_details) \
Filip Tehlar69a9b762016-09-23 10:00:52 +02003870_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \
Andrej Kozemcakd9831182016-06-20 08:47:57 +02003871_(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +02003872_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3873 lisp_add_del_map_request_itr_rlocs_reply) \
3874_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3875 lisp_get_map_request_itr_rlocs_reply) \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +02003876_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
Florin Corasdca88042016-09-14 16:01:38 +02003877_(SHOW_LISP_MAP_REQUEST_MODE_REPLY, show_lisp_map_request_mode_reply) \
Filip Tehlar397fd7d2016-10-26 14:31:24 +02003878_(SHOW_LISP_RLOC_PROBE_STATE_REPLY, show_lisp_rloc_probe_state_reply) \
3879_(SHOW_LISP_MAP_REGISTER_STATE_REPLY, \
3880 show_lisp_map_register_state_reply) \
Matus Fabian8a95a482016-05-06 15:14:13 +02003881_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
Matus Fabian65fcd4d2016-05-13 05:44:48 -07003882_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003883_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
Matus Fabiane8554802016-05-18 23:40:37 -07003884_(POLICER_DETAILS, policer_details) \
Matus Fabian70e6a8d2016-06-20 08:10:42 -07003885_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3886_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
Matus Fabian82e29c42016-05-11 04:49:46 -07003887_(NETMAP_CREATE_REPLY, netmap_create_reply) \
marek zavodsky2c21a9a2016-06-21 05:35:16 +02003888_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
Neale Rannsad422ed2016-11-02 14:20:04 +00003889_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
Neale Ranns1357f3b2016-10-16 12:01:42 -07003890_(MPLS_FIB_DETAILS, mpls_fib_details) \
Pavel Kotucek20c90f72016-06-07 14:44:26 +02003891_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3892_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3893_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
Juraj Slobodaac645ad2016-07-07 00:18:57 -07003894_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
Juraj Slobodaffa652a2016-08-07 23:43:42 -07003895_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3896_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3897_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3898_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3899_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3900_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
Juraj Sloboda506b2452016-08-07 23:45:24 -07003901_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3902_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01003903_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3904_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +02003905_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3906_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3907_(PG_CAPTURE_REPLY, pg_capture_reply) \
Dave Barach6f9bca22016-04-30 10:25:32 -04003908_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3909_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3910 ip_source_and_port_range_check_add_del_reply) \
3911_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
Matus Fabian694265d2016-08-10 01:55:36 -07003912 ip_source_and_port_range_check_interface_add_del_reply) \
3913_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
Pavel Kotucekd85590a2016-08-26 13:35:40 +02003914_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
Pavel Kotucek95300d12016-08-26 16:11:36 +02003915_(DELETE_SUBIF_REPLY, delete_subif_reply) \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -07003916_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Steven01b07122016-11-02 10:40:09 -07003917_(PUNT_REPLY, punt_reply) \
3918_(IP_FIB_DETAILS, ip_fib_details) \
Pavel Kotucek7490a752016-11-15 09:19:11 +01003919_(IP6_FIB_DETAILS, ip6_fib_details) \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +01003920_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
Matus Fabianf468e232016-12-02 06:00:53 -08003921_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +01003922_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3923_(SW_INTERFACE_SET_MTU_REPLY, sw_interface_set_mtu_reply) \
Juraj Slobodadfc19232016-12-05 13:20:37 +01003924_(IP_NEIGHBOR_DETAILS, ip_neighbor_details) \
3925_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003926
3927/* M: construct, but don't yet send a message */
3928
3929#define M(T,t) \
3930do { \
3931 vam->result_ready = 0; \
3932 mp = vl_msg_api_alloc(sizeof(*mp)); \
3933 memset (mp, 0, sizeof (*mp)); \
3934 mp->_vl_msg_id = ntohs (VL_API_##T); \
3935 mp->client_index = vam->my_client_index; \
3936} while(0);
3937
3938#define M2(T,t,n) \
3939do { \
3940 vam->result_ready = 0; \
3941 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3942 memset (mp, 0, sizeof (*mp)); \
3943 mp->_vl_msg_id = ntohs (VL_API_##T); \
3944 mp->client_index = vam->my_client_index; \
3945} while(0);
3946
3947
3948/* S: send a message */
3949#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3950
3951/* W: wait for results, with timeout */
3952#define W \
3953do { \
3954 timeout = vat_time_now (vam) + 1.0; \
3955 \
3956 while (vat_time_now (vam) < timeout) { \
3957 if (vam->result_ready == 1) { \
3958 return (vam->retval); \
3959 } \
3960 } \
3961 return -99; \
3962} while(0);
3963
Keith Burns (alagalah)802255c2016-06-13 16:56:04 -07003964/* W2: wait for results, with timeout */
3965#define W2(body) \
3966do { \
3967 timeout = vat_time_now (vam) + 1.0; \
3968 \
3969 while (vat_time_now (vam) < timeout) { \
3970 if (vam->result_ready == 1) { \
3971 (body); \
3972 return (vam->retval); \
3973 } \
3974 } \
3975 return -99; \
3976} while(0);
3977
Dave Barach72d72232016-08-04 10:15:08 -04003978typedef struct
3979{
3980 u8 *name;
3981 u32 value;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003982} name_sort_t;
3983
3984
3985#define STR_VTR_OP_CASE(op) \
3986 case L2_VTR_ ## op: \
3987 return "" # op;
3988
Dave Barach72d72232016-08-04 10:15:08 -04003989static const char *
3990str_vtr_op (u32 vtr_op)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003991{
Dave Barach72d72232016-08-04 10:15:08 -04003992 switch (vtr_op)
3993 {
3994 STR_VTR_OP_CASE (DISABLED);
3995 STR_VTR_OP_CASE (PUSH_1);
3996 STR_VTR_OP_CASE (PUSH_2);
3997 STR_VTR_OP_CASE (POP_1);
3998 STR_VTR_OP_CASE (POP_2);
3999 STR_VTR_OP_CASE (TRANSLATE_1_1);
4000 STR_VTR_OP_CASE (TRANSLATE_1_2);
4001 STR_VTR_OP_CASE (TRANSLATE_2_1);
4002 STR_VTR_OP_CASE (TRANSLATE_2_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004003 }
4004
Dave Barach72d72232016-08-04 10:15:08 -04004005 return "UNKNOWN";
Ed Warnickecb9cada2015-12-08 15:45:58 -07004006}
4007
Dave Barach72d72232016-08-04 10:15:08 -04004008static int
4009dump_sub_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004010{
Dave Barach72d72232016-08-04 10:15:08 -04004011 const sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004012
Dave Barach72d72232016-08-04 10:15:08 -04004013 if (vam->json_output)
4014 {
4015 clib_warning
4016 ("JSON output supported only for VPE API calls and dump_stats_table");
4017 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004018 }
4019
Dave Barach72d72232016-08-04 10:15:08 -04004020 fformat (vam->ofp,
4021 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
4022 "Interface", "sw_if_index",
4023 "sub id", "dot1ad", "tags", "outer id",
4024 "inner id", "exact", "default", "outer any", "inner any");
4025
4026 vec_foreach (sub, vam->sw_if_subif_table)
4027 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07004028 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004029 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
4030 sub->interface_name,
4031 sub->sw_if_index,
4032 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
4033 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
4034 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
4035 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
4036 if (sub->vtr_op != L2_VTR_DISABLED)
4037 {
4038 fformat (vam->ofp,
4039 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
4040 "tag1: %d tag2: %d ]\n",
4041 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
4042 sub->vtr_tag1, sub->vtr_tag2);
4043 }
4044 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004045
Dave Barach72d72232016-08-04 10:15:08 -04004046 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004047}
4048
Dave Barach72d72232016-08-04 10:15:08 -04004049static int
4050name_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004051{
Dave Barach72d72232016-08-04 10:15:08 -04004052 name_sort_t *n1 = a1;
4053 name_sort_t *n2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004054
Dave Barach72d72232016-08-04 10:15:08 -04004055 return strcmp ((char *) n1->name, (char *) n2->name);
Matus Fabiand2dc3df2015-12-14 10:31:33 -05004056}
4057
Dave Barach72d72232016-08-04 10:15:08 -04004058static int
4059dump_interface_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004060{
Dave Barach72d72232016-08-04 10:15:08 -04004061 hash_pair_t *p;
4062 name_sort_t *nses = 0, *ns;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004063
Dave Barach72d72232016-08-04 10:15:08 -04004064 if (vam->json_output)
4065 {
4066 clib_warning
4067 ("JSON output supported only for VPE API calls and dump_stats_table");
4068 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004069 }
4070
Dave Barach72d72232016-08-04 10:15:08 -04004071 /* *INDENT-OFF* */
4072 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4073 ({
4074 vec_add2 (nses, ns, 1);
4075 ns->name = (u8 *)(p->key);
4076 ns->value = (u32) p->value[0];
4077 }));
4078 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004079
Dave Barach72d72232016-08-04 10:15:08 -04004080 vec_sort_with_function (nses, name_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004081
Dave Barach72d72232016-08-04 10:15:08 -04004082 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
4083 vec_foreach (ns, nses)
4084 {
4085 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
4086 }
4087 vec_free (nses);
4088 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004089}
4090
Dave Barach72d72232016-08-04 10:15:08 -04004091static int
4092dump_ip_table (vat_main_t * vam, int is_ipv6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004093{
Dave Barach72d72232016-08-04 10:15:08 -04004094 const ip_details_t *det = NULL;
4095 const ip_address_details_t *address = NULL;
4096 u32 i = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004097
Dave Barach72d72232016-08-04 10:15:08 -04004098 fformat (vam->ofp, "%-12s\n", "sw_if_index");
4099
Dave Barach72d72232016-08-04 10:15:08 -04004100 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
4101 {
4102 i++;
4103 if (!det->present)
4104 {
4105 continue;
4106 }
4107 fformat (vam->ofp, "%-12d\n", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004108 fformat (vam->ofp,
Dave Barach72d72232016-08-04 10:15:08 -04004109 " %-30s%-13s\n", "Address", "Prefix length");
4110 if (!det->addr)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004111 {
Dave Barach72d72232016-08-04 10:15:08 -04004112 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004113 }
Dave Barach72d72232016-08-04 10:15:08 -04004114 vec_foreach (address, det->addr)
4115 {
4116 fformat (vam->ofp,
4117 " %-30U%-13d\n",
4118 is_ipv6 ? format_ip6_address : format_ip4_address,
4119 address->ip, address->prefix_length);
4120 }
4121 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004122
Dave Barach72d72232016-08-04 10:15:08 -04004123 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004124}
4125
Dave Barach72d72232016-08-04 10:15:08 -04004126static int
4127dump_ipv4_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004128{
Dave Barach72d72232016-08-04 10:15:08 -04004129 if (vam->json_output)
4130 {
4131 clib_warning
4132 ("JSON output supported only for VPE API calls and dump_stats_table");
4133 return -99;
4134 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004135
Dave Barach72d72232016-08-04 10:15:08 -04004136 return dump_ip_table (vam, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004137}
4138
Dave Barach72d72232016-08-04 10:15:08 -04004139static int
4140dump_ipv6_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004141{
Dave Barach72d72232016-08-04 10:15:08 -04004142 if (vam->json_output)
4143 {
4144 clib_warning
4145 ("JSON output supported only for VPE API calls and dump_stats_table");
4146 return -99;
4147 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004148
Dave Barach72d72232016-08-04 10:15:08 -04004149 return dump_ip_table (vam, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004150}
4151
Dave Barach72d72232016-08-04 10:15:08 -04004152static char *
4153counter_type_to_str (u8 counter_type, u8 is_combined)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004154{
Dave Barach72d72232016-08-04 10:15:08 -04004155 if (!is_combined)
4156 {
4157 switch (counter_type)
4158 {
4159 case VNET_INTERFACE_COUNTER_DROP:
4160 return "drop";
4161 case VNET_INTERFACE_COUNTER_PUNT:
4162 return "punt";
4163 case VNET_INTERFACE_COUNTER_IP4:
4164 return "ip4";
4165 case VNET_INTERFACE_COUNTER_IP6:
4166 return "ip6";
4167 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
4168 return "rx-no-buf";
4169 case VNET_INTERFACE_COUNTER_RX_MISS:
4170 return "rx-miss";
4171 case VNET_INTERFACE_COUNTER_RX_ERROR:
4172 return "rx-error";
4173 case VNET_INTERFACE_COUNTER_TX_ERROR:
4174 return "tx-error";
4175 default:
4176 return "INVALID-COUNTER-TYPE";
4177 }
4178 }
4179 else
4180 {
4181 switch (counter_type)
4182 {
4183 case VNET_INTERFACE_COUNTER_RX:
4184 return "rx";
4185 case VNET_INTERFACE_COUNTER_TX:
4186 return "tx";
4187 default:
4188 return "INVALID-COUNTER-TYPE";
4189 }
4190 }
4191}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004192
Dave Barach72d72232016-08-04 10:15:08 -04004193static int
4194dump_stats_table (vat_main_t * vam)
4195{
4196 vat_json_node_t node;
4197 vat_json_node_t *msg_array;
4198 vat_json_node_t *msg;
4199 vat_json_node_t *counter_array;
4200 vat_json_node_t *counter;
4201 interface_counter_t c;
4202 u64 packets;
4203 ip4_fib_counter_t *c4;
4204 ip6_fib_counter_t *c6;
4205 int i, j;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004206
Dave Barach72d72232016-08-04 10:15:08 -04004207 if (!vam->json_output)
4208 {
4209 clib_warning ("dump_stats_table supported only in JSON format");
4210 return -99;
4211 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004212
Dave Barach72d72232016-08-04 10:15:08 -04004213 vat_json_init_object (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004214
Dave Barach72d72232016-08-04 10:15:08 -04004215 /* interface counters */
4216 msg_array = vat_json_object_add (&node, "interface_counters");
4217 vat_json_init_array (msg_array);
4218 for (i = 0; i < vec_len (vam->simple_interface_counters); i++)
4219 {
4220 msg = vat_json_array_add (msg_array);
4221 vat_json_init_object (msg);
4222 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4223 (u8 *) counter_type_to_str (i, 0));
4224 vat_json_object_add_int (msg, "is_combined", 0);
4225 counter_array = vat_json_object_add (msg, "data");
4226 vat_json_init_array (counter_array);
4227 for (j = 0; j < vec_len (vam->simple_interface_counters[i]); j++)
4228 {
4229 packets = vam->simple_interface_counters[i][j];
4230 vat_json_array_add_uint (counter_array, packets);
4231 }
4232 }
4233 for (i = 0; i < vec_len (vam->combined_interface_counters); i++)
4234 {
4235 msg = vat_json_array_add (msg_array);
4236 vat_json_init_object (msg);
4237 vat_json_object_add_string_copy (msg, "vnet_counter_type",
4238 (u8 *) counter_type_to_str (i, 1));
4239 vat_json_object_add_int (msg, "is_combined", 1);
4240 counter_array = vat_json_object_add (msg, "data");
4241 vat_json_init_array (counter_array);
4242 for (j = 0; j < vec_len (vam->combined_interface_counters[i]); j++)
4243 {
4244 c = vam->combined_interface_counters[i][j];
4245 counter = vat_json_array_add (counter_array);
4246 vat_json_init_object (counter);
4247 vat_json_object_add_uint (counter, "packets", c.packets);
4248 vat_json_object_add_uint (counter, "bytes", c.bytes);
4249 }
4250 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004251
Dave Barach72d72232016-08-04 10:15:08 -04004252 /* ip4 fib counters */
4253 msg_array = vat_json_object_add (&node, "ip4_fib_counters");
4254 vat_json_init_array (msg_array);
4255 for (i = 0; i < vec_len (vam->ip4_fib_counters); i++)
4256 {
4257 msg = vat_json_array_add (msg_array);
4258 vat_json_init_object (msg);
4259 vat_json_object_add_uint (msg, "vrf_id",
4260 vam->ip4_fib_counters_vrf_id_by_index[i]);
4261 counter_array = vat_json_object_add (msg, "c");
4262 vat_json_init_array (counter_array);
4263 for (j = 0; j < vec_len (vam->ip4_fib_counters[i]); j++)
4264 {
4265 counter = vat_json_array_add (counter_array);
4266 vat_json_init_object (counter);
4267 c4 = &vam->ip4_fib_counters[i][j];
4268 vat_json_object_add_ip4 (counter, "address", c4->address);
4269 vat_json_object_add_uint (counter, "address_length",
4270 c4->address_length);
4271 vat_json_object_add_uint (counter, "packets", c4->packets);
4272 vat_json_object_add_uint (counter, "bytes", c4->bytes);
4273 }
4274 }
4275
4276 /* ip6 fib counters */
4277 msg_array = vat_json_object_add (&node, "ip6_fib_counters");
4278 vat_json_init_array (msg_array);
4279 for (i = 0; i < vec_len (vam->ip6_fib_counters); i++)
4280 {
4281 msg = vat_json_array_add (msg_array);
4282 vat_json_init_object (msg);
4283 vat_json_object_add_uint (msg, "vrf_id",
4284 vam->ip6_fib_counters_vrf_id_by_index[i]);
4285 counter_array = vat_json_object_add (msg, "c");
4286 vat_json_init_array (counter_array);
4287 for (j = 0; j < vec_len (vam->ip6_fib_counters[i]); j++)
4288 {
4289 counter = vat_json_array_add (counter_array);
4290 vat_json_init_object (counter);
4291 c6 = &vam->ip6_fib_counters[i][j];
4292 vat_json_object_add_ip6 (counter, "address", c6->address);
4293 vat_json_object_add_uint (counter, "address_length",
4294 c6->address_length);
4295 vat_json_object_add_uint (counter, "packets", c6->packets);
4296 vat_json_object_add_uint (counter, "bytes", c6->bytes);
4297 }
4298 }
4299
4300 vat_json_print (vam->ofp, &node);
4301 vat_json_free (&node);
4302
4303 return 0;
4304}
4305
4306int
4307exec (vat_main_t * vam)
4308{
4309 api_main_t *am = &api_main;
4310 vl_api_cli_request_t *mp;
4311 f64 timeout;
4312 void *oldheap;
4313 u8 *cmd = 0;
4314 unformat_input_t *i = vam->input;
4315
4316 if (vec_len (i->buffer) == 0)
4317 return -1;
4318
4319 if (vam->exec_mode == 0 && unformat (i, "mode"))
4320 {
4321 vam->exec_mode = 1;
4322 return 0;
4323 }
4324 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4325 {
4326 vam->exec_mode = 0;
4327 return 0;
4328 }
4329
4330
4331 M (CLI_REQUEST, cli_request);
4332
4333 /*
4334 * Copy cmd into shared memory.
4335 * In order for the CLI command to work, it
4336 * must be a vector ending in \n, not a C-string ending
4337 * in \n\0.
4338 */
4339 pthread_mutex_lock (&am->vlib_rp->mutex);
4340 oldheap = svm_push_data_heap (am->vlib_rp);
4341
4342 vec_validate (cmd, vec_len (vam->input->buffer) - 1);
4343 clib_memcpy (cmd, vam->input->buffer, vec_len (vam->input->buffer));
4344
4345 svm_pop_heap (oldheap);
4346 pthread_mutex_unlock (&am->vlib_rp->mutex);
4347
4348 mp->cmd_in_shmem = (u64) cmd;
4349 S;
4350 timeout = vat_time_now (vam) + 10.0;
4351
4352 while (vat_time_now (vam) < timeout)
4353 {
4354 if (vam->result_ready == 1)
4355 {
4356 u8 *free_me;
4357 if (vam->shmem_result != NULL)
4358 fformat (vam->ofp, "%s", vam->shmem_result);
4359 pthread_mutex_lock (&am->vlib_rp->mutex);
4360 oldheap = svm_push_data_heap (am->vlib_rp);
4361
4362 free_me = (u8 *) vam->shmem_result;
4363 vec_free (free_me);
4364
4365 svm_pop_heap (oldheap);
4366 pthread_mutex_unlock (&am->vlib_rp->mutex);
4367 return 0;
4368 }
4369 }
4370 return -99;
4371}
4372
Ole Troanc27213a2016-08-31 14:50:49 +02004373/*
4374 * Future replacement of exec() that passes CLI buffers directly in
4375 * the API messages instead of an additional shared memory area.
4376 */
4377static int
4378exec_inband (vat_main_t * vam)
4379{
4380 vl_api_cli_inband_t *mp;
4381 f64 timeout;
4382 unformat_input_t *i = vam->input;
4383
4384 if (vec_len (i->buffer) == 0)
4385 return -1;
4386
4387 if (vam->exec_mode == 0 && unformat (i, "mode"))
4388 {
4389 vam->exec_mode = 1;
4390 return 0;
4391 }
4392 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
4393 {
4394 vam->exec_mode = 0;
4395 return 0;
4396 }
4397
4398 /*
4399 * In order for the CLI command to work, it
4400 * must be a vector ending in \n, not a C-string ending
4401 * in \n\0.
4402 */
4403 u32 len = vec_len (vam->input->buffer);
4404 M2 (CLI_INBAND, cli_inband, len);
4405 clib_memcpy (mp->cmd, vam->input->buffer, len);
4406 mp->length = htonl (len);
4407
4408 S;
4409 W2 (fformat (vam->ofp, "%s", vam->cmd_reply));
4410}
4411
Dave Barach72d72232016-08-04 10:15:08 -04004412static int
4413api_create_loopback (vat_main_t * vam)
4414{
4415 unformat_input_t *i = vam->input;
4416 vl_api_create_loopback_t *mp;
4417 f64 timeout;
4418 u8 mac_address[6];
4419 u8 mac_set = 0;
4420
4421 memset (mac_address, 0, sizeof (mac_address));
4422
4423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4424 {
4425 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
4426 mac_set = 1;
4427 else
4428 break;
4429 }
4430
4431 /* Construct the API message */
4432 M (CREATE_LOOPBACK, create_loopback);
4433 if (mac_set)
4434 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
4435
4436 S;
4437 W;
4438}
4439
4440static int
4441api_delete_loopback (vat_main_t * vam)
4442{
4443 unformat_input_t *i = vam->input;
4444 vl_api_delete_loopback_t *mp;
4445 f64 timeout;
4446 u32 sw_if_index = ~0;
4447
4448 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4449 {
4450 if (unformat (i, "sw_if_index %d", &sw_if_index))
4451 ;
4452 else
4453 break;
4454 }
4455
4456 if (sw_if_index == ~0)
4457 {
4458 errmsg ("missing sw_if_index\n");
4459 return -99;
4460 }
4461
4462 /* Construct the API message */
4463 M (DELETE_LOOPBACK, delete_loopback);
4464 mp->sw_if_index = ntohl (sw_if_index);
4465
4466 S;
4467 W;
4468}
4469
4470static int
4471api_want_stats (vat_main_t * vam)
4472{
4473 unformat_input_t *i = vam->input;
4474 vl_api_want_stats_t *mp;
4475 f64 timeout;
4476 int enable = -1;
4477
4478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4479 {
4480 if (unformat (i, "enable"))
4481 enable = 1;
4482 else if (unformat (i, "disable"))
4483 enable = 0;
4484 else
4485 break;
4486 }
4487
4488 if (enable == -1)
4489 {
4490 errmsg ("missing enable|disable\n");
4491 return -99;
4492 }
4493
4494 M (WANT_STATS, want_stats);
4495 mp->enable_disable = enable;
4496
4497 S;
4498 W;
4499}
4500
4501static int
4502api_want_interface_events (vat_main_t * vam)
4503{
4504 unformat_input_t *i = vam->input;
4505 vl_api_want_interface_events_t *mp;
4506 f64 timeout;
4507 int enable = -1;
4508
4509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4510 {
4511 if (unformat (i, "enable"))
4512 enable = 1;
4513 else if (unformat (i, "disable"))
4514 enable = 0;
4515 else
4516 break;
4517 }
4518
4519 if (enable == -1)
4520 {
4521 errmsg ("missing enable|disable\n");
4522 return -99;
4523 }
4524
4525 M (WANT_INTERFACE_EVENTS, want_interface_events);
4526 mp->enable_disable = enable;
4527
4528 vam->interface_event_display = enable;
4529
4530 S;
4531 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004532}
4533
4534
4535/* Note: non-static, called once to set up the initial intfc table */
Dave Barach72d72232016-08-04 10:15:08 -04004536int
4537api_sw_interface_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004538{
Dave Barach72d72232016-08-04 10:15:08 -04004539 vl_api_sw_interface_dump_t *mp;
4540 f64 timeout;
4541 hash_pair_t *p;
4542 name_sort_t *nses = 0, *ns;
4543 sw_interface_subif_t *sub = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004544
Dave Barach72d72232016-08-04 10:15:08 -04004545 /* Toss the old name table */
4546 /* *INDENT-OFF* */
4547 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
4548 ({
4549 vec_add2 (nses, ns, 1);
4550 ns->name = (u8 *)(p->key);
4551 ns->value = (u32) p->value[0];
4552 }));
4553 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004554
Dave Barach72d72232016-08-04 10:15:08 -04004555 hash_free (vam->sw_if_index_by_interface_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004556
Dave Barach72d72232016-08-04 10:15:08 -04004557 vec_foreach (ns, nses) vec_free (ns->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004558
Dave Barach72d72232016-08-04 10:15:08 -04004559 vec_free (nses);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004560
Dave Barach72d72232016-08-04 10:15:08 -04004561 vec_foreach (sub, vam->sw_if_subif_table)
4562 {
4563 vec_free (sub->interface_name);
4564 }
4565 vec_free (vam->sw_if_subif_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004566
Dave Barach72d72232016-08-04 10:15:08 -04004567 /* recreate the interface name hash table */
4568 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004569
Dave Barach72d72232016-08-04 10:15:08 -04004570 /* Get list of ethernets */
4571 M (SW_INTERFACE_DUMP, sw_interface_dump);
4572 mp->name_filter_valid = 1;
4573 strncpy ((char *) mp->name_filter, "Ether", sizeof (mp->name_filter) - 1);
4574 S;
4575
4576 /* and local / loopback interfaces */
4577 M (SW_INTERFACE_DUMP, sw_interface_dump);
4578 mp->name_filter_valid = 1;
4579 strncpy ((char *) mp->name_filter, "lo", sizeof (mp->name_filter) - 1);
4580 S;
4581
Damjan Marionf2c6ed12016-09-30 10:53:30 +02004582 /* and packet-generator interfaces */
4583 M (SW_INTERFACE_DUMP, sw_interface_dump);
4584 mp->name_filter_valid = 1;
4585 strncpy ((char *) mp->name_filter, "pg", sizeof (mp->name_filter) - 1);
4586 S;
Dave Barach72d72232016-08-04 10:15:08 -04004587
4588 /* and vxlan-gpe tunnel interfaces */
4589 M (SW_INTERFACE_DUMP, sw_interface_dump);
4590 mp->name_filter_valid = 1;
4591 strncpy ((char *) mp->name_filter, "vxlan_gpe",
4592 sizeof (mp->name_filter) - 1);
4593 S;
4594
4595 /* and vxlan tunnel interfaces */
4596 M (SW_INTERFACE_DUMP, sw_interface_dump);
4597 mp->name_filter_valid = 1;
4598 strncpy ((char *) mp->name_filter, "vxlan", sizeof (mp->name_filter) - 1);
4599 S;
4600
4601 /* and host (af_packet) interfaces */
4602 M (SW_INTERFACE_DUMP, sw_interface_dump);
4603 mp->name_filter_valid = 1;
4604 strncpy ((char *) mp->name_filter, "host", sizeof (mp->name_filter) - 1);
4605 S;
4606
4607 /* and l2tpv3 tunnel interfaces */
4608 M (SW_INTERFACE_DUMP, sw_interface_dump);
4609 mp->name_filter_valid = 1;
4610 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel",
4611 sizeof (mp->name_filter) - 1);
4612 S;
4613
4614 /* and GRE tunnel interfaces */
4615 M (SW_INTERFACE_DUMP, sw_interface_dump);
4616 mp->name_filter_valid = 1;
4617 strncpy ((char *) mp->name_filter, "gre", sizeof (mp->name_filter) - 1);
4618 S;
4619
Florin Corasce982752016-09-06 13:36:11 +02004620 /* and LISP-GPE interfaces */
4621 M (SW_INTERFACE_DUMP, sw_interface_dump);
4622 mp->name_filter_valid = 1;
4623 strncpy ((char *) mp->name_filter, "lisp_gpe",
4624 sizeof (mp->name_filter) - 1);
4625 S;
4626
Matus Fabian8fce3e32016-09-06 23:19:43 -07004627 /* and IPSEC tunnel interfaces */
4628 M (SW_INTERFACE_DUMP, sw_interface_dump);
4629 mp->name_filter_valid = 1;
4630 strncpy ((char *) mp->name_filter, "ipsec", sizeof (mp->name_filter) - 1);
4631 S;
4632
Dave Barach72d72232016-08-04 10:15:08 -04004633 /* Use a control ping for synchronization */
4634 {
4635 vl_api_control_ping_t *mp;
4636 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004637 S;
Dave Barach72d72232016-08-04 10:15:08 -04004638 }
4639 W;
4640}
Ed Warnickecb9cada2015-12-08 15:45:58 -07004641
Dave Barach72d72232016-08-04 10:15:08 -04004642static int
4643api_sw_interface_set_flags (vat_main_t * vam)
4644{
4645 unformat_input_t *i = vam->input;
4646 vl_api_sw_interface_set_flags_t *mp;
4647 f64 timeout;
4648 u32 sw_if_index;
4649 u8 sw_if_index_set = 0;
4650 u8 admin_up = 0, link_up = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004651
Dave Barach72d72232016-08-04 10:15:08 -04004652 /* Parse args required to build the message */
4653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004654 {
Dave Barach72d72232016-08-04 10:15:08 -04004655 if (unformat (i, "admin-up"))
4656 admin_up = 1;
4657 else if (unformat (i, "admin-down"))
4658 admin_up = 0;
4659 else if (unformat (i, "link-up"))
4660 link_up = 1;
4661 else if (unformat (i, "link-down"))
4662 link_up = 0;
4663 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4664 sw_if_index_set = 1;
4665 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4666 sw_if_index_set = 1;
4667 else
4668 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004669 }
4670
Dave Barach72d72232016-08-04 10:15:08 -04004671 if (sw_if_index_set == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004672 {
Dave Barach72d72232016-08-04 10:15:08 -04004673 errmsg ("missing interface name or sw_if_index\n");
4674 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004675 }
4676
Dave Barach72d72232016-08-04 10:15:08 -04004677 /* Construct the API message */
4678 M (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
4679 mp->sw_if_index = ntohl (sw_if_index);
4680 mp->admin_up_down = admin_up;
4681 mp->link_up_down = link_up;
4682
4683 /* send it... */
4684 S;
4685
4686 /* Wait for a reply, return the good/bad news... */
4687 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004688}
4689
Dave Barach72d72232016-08-04 10:15:08 -04004690static int
4691api_sw_interface_clear_stats (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004692{
Dave Barach72d72232016-08-04 10:15:08 -04004693 unformat_input_t *i = vam->input;
4694 vl_api_sw_interface_clear_stats_t *mp;
4695 f64 timeout;
4696 u32 sw_if_index;
4697 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004698
Dave Barach72d72232016-08-04 10:15:08 -04004699 /* Parse args required to build the message */
4700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4701 {
4702 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4703 sw_if_index_set = 1;
4704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4705 sw_if_index_set = 1;
4706 else
4707 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004708 }
4709
Dave Barach72d72232016-08-04 10:15:08 -04004710 /* Construct the API message */
4711 M (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004712
Dave Barach72d72232016-08-04 10:15:08 -04004713 if (sw_if_index_set == 1)
4714 mp->sw_if_index = ntohl (sw_if_index);
4715 else
4716 mp->sw_if_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004717
Dave Barach72d72232016-08-04 10:15:08 -04004718 /* send it... */
4719 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004720
Dave Barach72d72232016-08-04 10:15:08 -04004721 /* Wait for a reply, return the good/bad news... */
4722 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004723}
4724
Dave Barach72d72232016-08-04 10:15:08 -04004725static int
Jasvinder Singh85ecc812016-07-21 17:02:19 +01004726api_sw_interface_set_dpdk_hqos_pipe (vat_main_t * vam)
4727{
4728 unformat_input_t *i = vam->input;
4729 vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp;
4730 f64 timeout;
4731 u32 sw_if_index;
4732 u8 sw_if_index_set = 0;
4733 u32 subport;
4734 u8 subport_set = 0;
4735 u32 pipe;
4736 u8 pipe_set = 0;
4737 u32 profile;
4738 u8 profile_set = 0;
4739
4740 /* Parse args required to build the message */
4741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4742 {
4743 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4744 sw_if_index_set = 1;
4745 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4746 sw_if_index_set = 1;
4747 else if (unformat (i, "subport %u", &subport))
4748 subport_set = 1;
4749 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4750 sw_if_index_set = 1;
4751 else if (unformat (i, "pipe %u", &pipe))
4752 pipe_set = 1;
4753 else if (unformat (i, "profile %u", &profile))
4754 profile_set = 1;
4755 else
4756 break;
4757 }
4758
4759 if (sw_if_index_set == 0)
4760 {
4761 errmsg ("missing interface name or sw_if_index\n");
4762 return -99;
4763 }
4764
4765 if (subport_set == 0)
4766 {
4767 errmsg ("missing subport \n");
4768 return -99;
4769 }
4770
4771 if (pipe_set == 0)
4772 {
4773 errmsg ("missing pipe\n");
4774 return -99;
4775 }
4776
4777 if (profile_set == 0)
4778 {
4779 errmsg ("missing profile\n");
4780 return -99;
4781 }
4782
4783 M (SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe);
4784
4785 mp->sw_if_index = ntohl (sw_if_index);
4786 mp->subport = ntohl (subport);
4787 mp->pipe = ntohl (pipe);
4788 mp->profile = ntohl (profile);
4789
4790
4791 S;
4792 W;
4793 /* NOTREACHED */
4794 return 0;
4795}
4796
4797static int
4798api_sw_interface_set_dpdk_hqos_subport (vat_main_t * vam)
4799{
4800 unformat_input_t *i = vam->input;
4801 vl_api_sw_interface_set_dpdk_hqos_subport_t *mp;
4802 f64 timeout;
4803 u32 sw_if_index;
4804 u8 sw_if_index_set = 0;
4805 u32 subport;
4806 u8 subport_set = 0;
4807 u32 tb_rate = 1250000000; /* 10GbE */
4808 u32 tb_size = 1000000;
4809 u32 tc_rate[] = { 1250000000, 1250000000, 1250000000, 1250000000 };
4810 u32 tc_period = 10;
4811
4812 /* Parse args required to build the message */
4813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4814 {
4815 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4816 sw_if_index_set = 1;
4817 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4818 sw_if_index_set = 1;
4819 else if (unformat (i, "subport %u", &subport))
4820 subport_set = 1;
4821 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4822 sw_if_index_set = 1;
4823 else if (unformat (i, "rate %u", &tb_rate))
4824 {
4825 u32 tc_id;
4826
4827 for (tc_id = 0; tc_id < (sizeof (tc_rate) / sizeof (tc_rate[0]));
4828 tc_id++)
4829 tc_rate[tc_id] = tb_rate;
4830 }
4831 else if (unformat (i, "bktsize %u", &tb_size))
4832 ;
4833 else if (unformat (i, "tc0 %u", &tc_rate[0]))
4834 ;
4835 else if (unformat (i, "tc1 %u", &tc_rate[1]))
4836 ;
4837 else if (unformat (i, "tc2 %u", &tc_rate[2]))
4838 ;
4839 else if (unformat (i, "tc3 %u", &tc_rate[3]))
4840 ;
4841 else if (unformat (i, "period %u", &tc_period))
4842 ;
4843 else
4844 break;
4845 }
4846
4847 if (sw_if_index_set == 0)
4848 {
4849 errmsg ("missing interface name or sw_if_index\n");
4850 return -99;
4851 }
4852
4853 if (subport_set == 0)
4854 {
4855 errmsg ("missing subport \n");
4856 return -99;
4857 }
4858
4859 M (SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport);
4860
4861 mp->sw_if_index = ntohl (sw_if_index);
4862 mp->subport = ntohl (subport);
4863 mp->tb_rate = ntohl (tb_rate);
4864 mp->tb_size = ntohl (tb_size);
4865 mp->tc_rate[0] = ntohl (tc_rate[0]);
4866 mp->tc_rate[1] = ntohl (tc_rate[1]);
4867 mp->tc_rate[2] = ntohl (tc_rate[2]);
4868 mp->tc_rate[3] = ntohl (tc_rate[3]);
4869 mp->tc_period = ntohl (tc_period);
4870
4871 S;
4872 W;
4873 /* NOTREACHED */
4874 return 0;
4875}
4876
4877static int
4878api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
4879{
4880 unformat_input_t *i = vam->input;
4881 vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp;
4882 f64 timeout;
4883 u32 sw_if_index;
4884 u8 sw_if_index_set = 0;
4885 u8 entry_set = 0;
4886 u8 tc_set = 0;
4887 u8 queue_set = 0;
4888 u32 entry, tc, queue;
4889
4890 /* Parse args required to build the message */
4891 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4892 {
4893 if (unformat (i, "rx %U", unformat_sw_if_index, vam, &sw_if_index))
4894 sw_if_index_set = 1;
4895 else if (unformat (i, "sw_if_index %u", &sw_if_index))
4896 sw_if_index_set = 1;
4897 else if (unformat (i, "entry %d", &entry))
4898 entry_set = 1;
4899 else if (unformat (i, "tc %d", &tc))
4900 tc_set = 1;
4901 else if (unformat (i, "queue %d", &queue))
4902 queue_set = 1;
4903 else
4904 break;
4905 }
4906
4907 if (sw_if_index_set == 0)
4908 {
4909 errmsg ("missing interface name or sw_if_index\n");
4910 return -99;
4911 }
4912
4913 if (entry_set == 0)
4914 {
4915 errmsg ("missing entry \n");
4916 return -99;
4917 }
4918
4919 if (tc_set == 0)
4920 {
4921 errmsg ("missing traffic class \n");
4922 return -99;
4923 }
4924
4925 if (queue_set == 0)
4926 {
4927 errmsg ("missing queue \n");
4928 return -99;
4929 }
4930
4931 M (SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl);
4932
4933 mp->sw_if_index = ntohl (sw_if_index);
4934 mp->entry = ntohl (entry);
4935 mp->tc = ntohl (tc);
4936 mp->queue = ntohl (queue);
4937
4938 S;
4939 W;
4940 /* NOTREACHED */
4941 return 0;
4942}
4943
4944static int
Dave Barach72d72232016-08-04 10:15:08 -04004945api_sw_interface_add_del_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004946{
Dave Barach72d72232016-08-04 10:15:08 -04004947 unformat_input_t *i = vam->input;
4948 vl_api_sw_interface_add_del_address_t *mp;
4949 f64 timeout;
4950 u32 sw_if_index;
4951 u8 sw_if_index_set = 0;
4952 u8 is_add = 1, del_all = 0;
4953 u32 address_length = 0;
4954 u8 v4_address_set = 0;
4955 u8 v6_address_set = 0;
4956 ip4_address_t v4address;
4957 ip6_address_t v6address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004958
Dave Barach72d72232016-08-04 10:15:08 -04004959 /* Parse args required to build the message */
4960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4961 {
4962 if (unformat (i, "del-all"))
4963 del_all = 1;
4964 else if (unformat (i, "del"))
4965 is_add = 0;
4966 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4967 sw_if_index_set = 1;
4968 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4969 sw_if_index_set = 1;
4970 else if (unformat (i, "%U/%d",
4971 unformat_ip4_address, &v4address, &address_length))
4972 v4_address_set = 1;
4973 else if (unformat (i, "%U/%d",
4974 unformat_ip6_address, &v6address, &address_length))
4975 v6_address_set = 1;
4976 else
4977 break;
4978 }
4979
4980 if (sw_if_index_set == 0)
4981 {
4982 errmsg ("missing interface name or sw_if_index\n");
4983 return -99;
4984 }
4985 if (v4_address_set && v6_address_set)
4986 {
4987 errmsg ("both v4 and v6 addresses set\n");
4988 return -99;
4989 }
4990 if (!v4_address_set && !v6_address_set && !del_all)
4991 {
4992 errmsg ("no addresses set\n");
4993 return -99;
4994 }
4995
4996 /* Construct the API message */
4997 M (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4998
4999 mp->sw_if_index = ntohl (sw_if_index);
5000 mp->is_add = is_add;
5001 mp->del_all = del_all;
5002 if (v6_address_set)
5003 {
5004 mp->is_ipv6 = 1;
5005 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5006 }
5007 else
5008 {
5009 clib_memcpy (mp->address, &v4address, sizeof (v4address));
5010 }
5011 mp->address_length = address_length;
5012
5013 /* send it... */
5014 S;
5015
5016 /* Wait for a reply, return good/bad news */
5017 W;
5018}
5019
5020static int
John Lo06b14b92016-10-24 20:20:11 -04005021api_sw_interface_set_mpls_enable (vat_main_t * vam)
5022{
5023 unformat_input_t *i = vam->input;
5024 vl_api_sw_interface_set_mpls_enable_t *mp;
5025 f64 timeout;
5026 u32 sw_if_index;
5027 u8 sw_if_index_set = 0;
5028 u8 enable = 1;
5029
5030 /* Parse args required to build the message */
5031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5032 {
5033 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5034 sw_if_index_set = 1;
5035 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5036 sw_if_index_set = 1;
5037 else if (unformat (i, "disable"))
5038 enable = 0;
5039 else if (unformat (i, "dis"))
5040 enable = 0;
5041 else
5042 break;
5043 }
5044
5045 if (sw_if_index_set == 0)
5046 {
5047 errmsg ("missing interface name or sw_if_index\n");
5048 return -99;
5049 }
5050
5051 /* Construct the API message */
5052 M (SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable);
5053
5054 mp->sw_if_index = ntohl (sw_if_index);
5055 mp->enable = enable;
5056
5057 /* send it... */
5058 S;
5059
5060 /* Wait for a reply... */
5061 W;
5062}
5063
5064static int
Dave Barach72d72232016-08-04 10:15:08 -04005065api_sw_interface_set_table (vat_main_t * vam)
5066{
5067 unformat_input_t *i = vam->input;
5068 vl_api_sw_interface_set_table_t *mp;
5069 f64 timeout;
5070 u32 sw_if_index, vrf_id = 0;
5071 u8 sw_if_index_set = 0;
5072 u8 is_ipv6 = 0;
5073
5074 /* Parse args required to build the message */
5075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5076 {
5077 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5078 sw_if_index_set = 1;
5079 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5080 sw_if_index_set = 1;
5081 else if (unformat (i, "vrf %d", &vrf_id))
5082 ;
5083 else if (unformat (i, "ipv6"))
5084 is_ipv6 = 1;
5085 else
5086 break;
5087 }
5088
5089 if (sw_if_index_set == 0)
5090 {
5091 errmsg ("missing interface name or sw_if_index\n");
5092 return -99;
5093 }
5094
5095 /* Construct the API message */
5096 M (SW_INTERFACE_SET_TABLE, sw_interface_set_table);
5097
5098 mp->sw_if_index = ntohl (sw_if_index);
5099 mp->is_ipv6 = is_ipv6;
5100 mp->vrf_id = ntohl (vrf_id);
5101
5102 /* send it... */
5103 S;
5104
5105 /* Wait for a reply... */
5106 W;
5107}
5108
Juraj Slobodadfc19232016-12-05 13:20:37 +01005109static void vl_api_sw_interface_get_table_reply_t_handler
5110 (vl_api_sw_interface_get_table_reply_t * mp)
5111{
5112 vat_main_t *vam = &vat_main;
5113
5114 fformat (vam->ofp, "%d\n", ntohl (mp->vrf_id));
5115
5116 vam->retval = ntohl (mp->retval);
5117 vam->result_ready = 1;
5118
5119}
5120
5121static void vl_api_sw_interface_get_table_reply_t_handler_json
5122 (vl_api_sw_interface_get_table_reply_t * mp)
5123{
5124 vat_main_t *vam = &vat_main;
5125 vat_json_node_t node;
5126
5127 vat_json_init_object (&node);
5128 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
5129 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
5130
5131 vat_json_print (vam->ofp, &node);
5132 vat_json_free (&node);
5133
5134 vam->retval = ntohl (mp->retval);
5135 vam->result_ready = 1;
5136}
5137
5138static int
5139api_sw_interface_get_table (vat_main_t * vam)
5140{
5141 unformat_input_t *i = vam->input;
5142 vl_api_sw_interface_get_table_t *mp;
5143 u32 sw_if_index;
5144 u8 sw_if_index_set = 0;
5145 u8 is_ipv6 = 0;
5146 f64 timeout;
5147
5148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5149 {
5150 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5151 sw_if_index_set = 1;
5152 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5153 sw_if_index_set = 1;
5154 else if (unformat (i, "ipv6"))
5155 is_ipv6 = 1;
5156 else
5157 break;
5158 }
5159
5160 if (sw_if_index_set == 0)
5161 {
5162 errmsg ("missing interface name or sw_if_index\n");
5163 return -99;
5164 }
5165
5166 M (SW_INTERFACE_GET_TABLE, sw_interface_get_table);
5167 mp->sw_if_index = htonl (sw_if_index);
5168 mp->is_ipv6 = is_ipv6;
5169
5170 S;
5171 W;
5172}
5173
Dave Barach72d72232016-08-04 10:15:08 -04005174static int
5175api_sw_interface_set_vpath (vat_main_t * vam)
5176{
5177 unformat_input_t *i = vam->input;
5178 vl_api_sw_interface_set_vpath_t *mp;
5179 f64 timeout;
5180 u32 sw_if_index = 0;
5181 u8 sw_if_index_set = 0;
5182 u8 is_enable = 0;
5183
5184 /* Parse args required to build the message */
5185 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5186 {
5187 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5188 sw_if_index_set = 1;
5189 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5190 sw_if_index_set = 1;
5191 else if (unformat (i, "enable"))
5192 is_enable = 1;
5193 else if (unformat (i, "disable"))
5194 is_enable = 0;
5195 else
5196 break;
5197 }
5198
5199 if (sw_if_index_set == 0)
5200 {
5201 errmsg ("missing interface name or sw_if_index\n");
5202 return -99;
5203 }
5204
5205 /* Construct the API message */
5206 M (SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
5207
5208 mp->sw_if_index = ntohl (sw_if_index);
5209 mp->enable = is_enable;
5210
5211 /* send it... */
5212 S;
5213
5214 /* Wait for a reply... */
5215 W;
5216}
5217
5218static int
John Lo37682e12016-11-30 12:51:39 -05005219api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
5220{
5221 unformat_input_t *i = vam->input;
5222 vl_api_sw_interface_set_vxlan_bypass_t *mp;
5223 f64 timeout;
5224 u32 sw_if_index = 0;
5225 u8 sw_if_index_set = 0;
5226 u8 is_enable = 0;
5227 u8 is_ipv6 = 0;
5228
5229 /* Parse args required to build the message */
5230 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5231 {
5232 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5233 sw_if_index_set = 1;
5234 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5235 sw_if_index_set = 1;
5236 else if (unformat (i, "enable"))
5237 is_enable = 1;
5238 else if (unformat (i, "disable"))
5239 is_enable = 0;
5240 else if (unformat (i, "ip4"))
5241 is_ipv6 = 0;
5242 else if (unformat (i, "ip6"))
5243 is_ipv6 = 1;
5244 else
5245 break;
5246 }
5247
5248 if (sw_if_index_set == 0)
5249 {
5250 errmsg ("missing interface name or sw_if_index\n");
5251 return -99;
5252 }
5253
5254 /* Construct the API message */
5255 M (SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass);
5256
5257 mp->sw_if_index = ntohl (sw_if_index);
5258 mp->enable = is_enable;
5259 mp->is_ipv6 = is_ipv6;
5260
5261 /* send it... */
5262 S;
5263
5264 /* Wait for a reply... */
5265 W;
5266}
5267
5268static int
Dave Barach72d72232016-08-04 10:15:08 -04005269api_sw_interface_set_l2_xconnect (vat_main_t * vam)
5270{
5271 unformat_input_t *i = vam->input;
5272 vl_api_sw_interface_set_l2_xconnect_t *mp;
5273 f64 timeout;
5274 u32 rx_sw_if_index;
5275 u8 rx_sw_if_index_set = 0;
5276 u32 tx_sw_if_index;
5277 u8 tx_sw_if_index_set = 0;
5278 u8 enable = 1;
5279
5280 /* Parse args required to build the message */
5281 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5282 {
5283 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5284 rx_sw_if_index_set = 1;
5285 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5286 tx_sw_if_index_set = 1;
5287 else if (unformat (i, "rx"))
5288 {
5289 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5290 {
5291 if (unformat (i, "%U", unformat_sw_if_index, vam,
5292 &rx_sw_if_index))
5293 rx_sw_if_index_set = 1;
5294 }
5295 else
Dave Barach41da02d2016-07-11 16:48:42 -07005296 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005297 }
Dave Barach72d72232016-08-04 10:15:08 -04005298 else if (unformat (i, "tx"))
5299 {
5300 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5301 {
5302 if (unformat (i, "%U", unformat_sw_if_index, vam,
5303 &tx_sw_if_index))
5304 tx_sw_if_index_set = 1;
5305 }
5306 else
5307 break;
5308 }
5309 else if (unformat (i, "enable"))
5310 enable = 1;
5311 else if (unformat (i, "disable"))
5312 enable = 0;
5313 else
5314 break;
Dave Barach41da02d2016-07-11 16:48:42 -07005315 }
5316
Dave Barach72d72232016-08-04 10:15:08 -04005317 if (rx_sw_if_index_set == 0)
5318 {
5319 errmsg ("missing rx interface name or rx_sw_if_index\n");
5320 return -99;
5321 }
Dave Barach41da02d2016-07-11 16:48:42 -07005322
Dave Barach72d72232016-08-04 10:15:08 -04005323 if (enable && (tx_sw_if_index_set == 0))
5324 {
5325 errmsg ("missing tx interface name or tx_sw_if_index\n");
5326 return -99;
5327 }
Dave Barach41da02d2016-07-11 16:48:42 -07005328
Dave Barach72d72232016-08-04 10:15:08 -04005329 M (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
Dave Barach41da02d2016-07-11 16:48:42 -07005330
Dave Barach72d72232016-08-04 10:15:08 -04005331 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5332 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5333 mp->enable = enable;
5334
5335 S;
5336 W;
5337 /* NOTREACHED */
5338 return 0;
5339}
5340
5341static int
5342api_sw_interface_set_l2_bridge (vat_main_t * vam)
5343{
5344 unformat_input_t *i = vam->input;
5345 vl_api_sw_interface_set_l2_bridge_t *mp;
5346 f64 timeout;
5347 u32 rx_sw_if_index;
5348 u8 rx_sw_if_index_set = 0;
5349 u32 bd_id;
5350 u8 bd_id_set = 0;
5351 u8 bvi = 0;
5352 u32 shg = 0;
5353 u8 enable = 1;
5354
5355 /* Parse args required to build the message */
5356 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5357 {
5358 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
5359 rx_sw_if_index_set = 1;
5360 else if (unformat (i, "bd_id %d", &bd_id))
5361 bd_id_set = 1;
5362 else if (unformat (i, "%U", unformat_sw_if_index, vam, &rx_sw_if_index))
5363 rx_sw_if_index_set = 1;
5364 else if (unformat (i, "shg %d", &shg))
5365 ;
5366 else if (unformat (i, "bvi"))
5367 bvi = 1;
5368 else if (unformat (i, "enable"))
5369 enable = 1;
5370 else if (unformat (i, "disable"))
5371 enable = 0;
5372 else
5373 break;
5374 }
5375
5376 if (rx_sw_if_index_set == 0)
5377 {
5378 errmsg ("missing rx interface name or sw_if_index\n");
5379 return -99;
5380 }
5381
5382 if (enable && (bd_id_set == 0))
5383 {
5384 errmsg ("missing bridge domain\n");
5385 return -99;
5386 }
5387
5388 M (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
5389
5390 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5391 mp->bd_id = ntohl (bd_id);
5392 mp->shg = (u8) shg;
5393 mp->bvi = bvi;
5394 mp->enable = enable;
5395
5396 S;
5397 W;
5398 /* NOTREACHED */
5399 return 0;
5400}
5401
5402static int
5403api_bridge_domain_dump (vat_main_t * vam)
5404{
5405 unformat_input_t *i = vam->input;
5406 vl_api_bridge_domain_dump_t *mp;
5407 f64 timeout;
5408 u32 bd_id = ~0;
5409
5410 /* Parse args required to build the message */
5411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5412 {
5413 if (unformat (i, "bd_id %d", &bd_id))
5414 ;
5415 else
5416 break;
5417 }
5418
5419 M (BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
5420 mp->bd_id = ntohl (bd_id);
5421 S;
5422
5423 /* Use a control ping for synchronization */
5424 {
5425 vl_api_control_ping_t *mp;
5426 M (CONTROL_PING, control_ping);
5427 S;
5428 }
5429
5430 W;
5431 /* NOTREACHED */
5432 return 0;
5433}
5434
5435static int
5436api_bridge_domain_add_del (vat_main_t * vam)
5437{
5438 unformat_input_t *i = vam->input;
5439 vl_api_bridge_domain_add_del_t *mp;
5440 f64 timeout;
5441 u32 bd_id = ~0;
5442 u8 is_add = 1;
5443 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
5444
5445 /* Parse args required to build the message */
5446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5447 {
5448 if (unformat (i, "bd_id %d", &bd_id))
5449 ;
5450 else if (unformat (i, "flood %d", &flood))
5451 ;
5452 else if (unformat (i, "uu-flood %d", &uu_flood))
5453 ;
5454 else if (unformat (i, "forward %d", &forward))
5455 ;
5456 else if (unformat (i, "learn %d", &learn))
5457 ;
5458 else if (unformat (i, "arp-term %d", &arp_term))
5459 ;
5460 else if (unformat (i, "del"))
5461 {
5462 is_add = 0;
5463 flood = uu_flood = forward = learn = 0;
5464 }
5465 else
5466 break;
5467 }
5468
5469 if (bd_id == ~0)
5470 {
5471 errmsg ("missing bridge domain\n");
5472 return -99;
5473 }
5474
5475 M (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
5476
5477 mp->bd_id = ntohl (bd_id);
5478 mp->flood = flood;
5479 mp->uu_flood = uu_flood;
5480 mp->forward = forward;
5481 mp->learn = learn;
5482 mp->arp_term = arp_term;
5483 mp->is_add = is_add;
5484
5485 S;
5486 W;
5487 /* NOTREACHED */
5488 return 0;
5489}
5490
5491static int
5492api_l2fib_add_del (vat_main_t * vam)
5493{
5494 unformat_input_t *i = vam->input;
5495 vl_api_l2fib_add_del_t *mp;
5496 f64 timeout;
5497 u64 mac = 0;
5498 u8 mac_set = 0;
5499 u32 bd_id;
5500 u8 bd_id_set = 0;
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005501 u32 sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04005502 u8 sw_if_index_set = 0;
5503 u8 is_add = 1;
5504 u8 static_mac = 0;
5505 u8 filter_mac = 0;
5506 u8 bvi_mac = 0;
5507 int count = 1;
5508 f64 before = 0;
5509 int j;
5510
5511 /* Parse args required to build the message */
5512 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5513 {
5514 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
5515 mac_set = 1;
5516 else if (unformat (i, "bd_id %d", &bd_id))
5517 bd_id_set = 1;
5518 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5519 sw_if_index_set = 1;
5520 else if (unformat (i, "sw_if"))
5521 {
5522 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5523 {
5524 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5525 sw_if_index_set = 1;
5526 }
5527 else
5528 break;
5529 }
5530 else if (unformat (i, "static"))
5531 static_mac = 1;
5532 else if (unformat (i, "filter"))
5533 {
5534 filter_mac = 1;
5535 static_mac = 1;
5536 }
5537 else if (unformat (i, "bvi"))
5538 {
5539 bvi_mac = 1;
5540 static_mac = 1;
5541 }
5542 else if (unformat (i, "del"))
5543 is_add = 0;
5544 else if (unformat (i, "count %d", &count))
5545 ;
5546 else
5547 break;
5548 }
5549
5550 if (mac_set == 0)
5551 {
5552 errmsg ("missing mac address\n");
5553 return -99;
5554 }
5555
5556 if (bd_id_set == 0)
5557 {
5558 errmsg ("missing bridge domain\n");
5559 return -99;
5560 }
5561
Pavel Kotucek9dd34e02016-12-02 08:18:55 +01005562 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
Dave Barach72d72232016-08-04 10:15:08 -04005563 {
5564 errmsg ("missing interface name or sw_if_index\n");
5565 return -99;
5566 }
5567
5568 if (count > 1)
5569 {
5570 /* Turn on async mode */
5571 vam->async_mode = 1;
5572 vam->async_errors = 0;
5573 before = vat_time_now (vam);
5574 }
5575
5576 for (j = 0; j < count; j++)
5577 {
5578 M (L2FIB_ADD_DEL, l2fib_add_del);
5579
5580 mp->mac = mac;
5581 mp->bd_id = ntohl (bd_id);
5582 mp->is_add = is_add;
5583
5584 if (is_add)
5585 {
5586 mp->sw_if_index = ntohl (sw_if_index);
5587 mp->static_mac = static_mac;
5588 mp->filter_mac = filter_mac;
5589 mp->bvi_mac = bvi_mac;
5590 }
5591 increment_mac_address (&mac);
5592 /* send it... */
5593 S;
5594 }
5595
5596 if (count > 1)
5597 {
5598 vl_api_control_ping_t *mp;
5599 f64 after;
5600
5601 /* Shut off async mode */
5602 vam->async_mode = 0;
5603
5604 M (CONTROL_PING, control_ping);
5605 S;
5606
5607 timeout = vat_time_now (vam) + 1.0;
5608 while (vat_time_now (vam) < timeout)
5609 if (vam->result_ready == 1)
5610 goto out;
5611 vam->retval = -99;
Dave Barach41da02d2016-07-11 16:48:42 -07005612
5613 out:
Dave Barach72d72232016-08-04 10:15:08 -04005614 if (vam->retval == -99)
5615 errmsg ("timeout\n");
Dave Barach41da02d2016-07-11 16:48:42 -07005616
Dave Barach72d72232016-08-04 10:15:08 -04005617 if (vam->async_errors > 0)
5618 {
5619 errmsg ("%d asynchronous errors\n", vam->async_errors);
5620 vam->retval = -98;
5621 }
5622 vam->async_errors = 0;
5623 after = vat_time_now (vam);
Dave Barach41da02d2016-07-11 16:48:42 -07005624
Dave Barach72d72232016-08-04 10:15:08 -04005625 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5626 count, after - before, count / (after - before));
Dave Barach41da02d2016-07-11 16:48:42 -07005627 }
Dave Barach72d72232016-08-04 10:15:08 -04005628 else
5629 {
5630 /* Wait for a reply... */
5631 W;
5632 }
5633 /* Return the good/bad news */
5634 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005635}
5636
Dave Barach72d72232016-08-04 10:15:08 -04005637static int
5638api_l2_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005639{
Dave Barach72d72232016-08-04 10:15:08 -04005640 unformat_input_t *i = vam->input;
5641 vl_api_l2_flags_t *mp;
5642 f64 timeout;
5643 u32 sw_if_index;
5644 u32 feature_bitmap = 0;
5645 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005646
Dave Barach72d72232016-08-04 10:15:08 -04005647 /* Parse args required to build the message */
5648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5649 {
5650 if (unformat (i, "sw_if_index %d", &sw_if_index))
5651 sw_if_index_set = 1;
5652 else if (unformat (i, "sw_if"))
5653 {
5654 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5655 {
5656 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5657 sw_if_index_set = 1;
5658 }
5659 else
5660 break;
5661 }
5662 else if (unformat (i, "learn"))
5663 feature_bitmap |= L2INPUT_FEAT_LEARN;
5664 else if (unformat (i, "forward"))
5665 feature_bitmap |= L2INPUT_FEAT_FWD;
5666 else if (unformat (i, "flood"))
5667 feature_bitmap |= L2INPUT_FEAT_FLOOD;
5668 else if (unformat (i, "uu-flood"))
5669 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
5670 else
5671 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005672 }
5673
Dave Barach72d72232016-08-04 10:15:08 -04005674 if (sw_if_index_set == 0)
5675 {
5676 errmsg ("missing interface name or sw_if_index\n");
5677 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005678 }
5679
Dave Barach72d72232016-08-04 10:15:08 -04005680 M (L2_FLAGS, l2_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005681
Dave Barach72d72232016-08-04 10:15:08 -04005682 mp->sw_if_index = ntohl (sw_if_index);
5683 mp->feature_bitmap = ntohl (feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005684
Dave Barach72d72232016-08-04 10:15:08 -04005685 S;
5686 W;
5687 /* NOTREACHED */
5688 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005689}
5690
Dave Barach72d72232016-08-04 10:15:08 -04005691static int
5692api_bridge_flags (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005693{
Dave Barach72d72232016-08-04 10:15:08 -04005694 unformat_input_t *i = vam->input;
5695 vl_api_bridge_flags_t *mp;
5696 f64 timeout;
5697 u32 bd_id;
5698 u8 bd_id_set = 0;
5699 u8 is_set = 1;
5700 u32 flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005701
Dave Barach72d72232016-08-04 10:15:08 -04005702 /* Parse args required to build the message */
5703 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5704 {
5705 if (unformat (i, "bd_id %d", &bd_id))
5706 bd_id_set = 1;
5707 else if (unformat (i, "learn"))
5708 flags |= L2_LEARN;
5709 else if (unformat (i, "forward"))
5710 flags |= L2_FWD;
5711 else if (unformat (i, "flood"))
5712 flags |= L2_FLOOD;
5713 else if (unformat (i, "uu-flood"))
5714 flags |= L2_UU_FLOOD;
5715 else if (unformat (i, "arp-term"))
5716 flags |= L2_ARP_TERM;
5717 else if (unformat (i, "off"))
5718 is_set = 0;
5719 else if (unformat (i, "disable"))
5720 is_set = 0;
5721 else
5722 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005723 }
5724
Dave Barach72d72232016-08-04 10:15:08 -04005725 if (bd_id_set == 0)
5726 {
5727 errmsg ("missing bridge domain\n");
5728 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005729 }
5730
Dave Barach72d72232016-08-04 10:15:08 -04005731 M (BRIDGE_FLAGS, bridge_flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005732
Dave Barach72d72232016-08-04 10:15:08 -04005733 mp->bd_id = ntohl (bd_id);
5734 mp->feature_bitmap = ntohl (flags);
5735 mp->is_set = is_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005736
Dave Barach72d72232016-08-04 10:15:08 -04005737 S;
5738 W;
5739 /* NOTREACHED */
5740 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005741}
5742
Dave Barach72d72232016-08-04 10:15:08 -04005743static int
5744api_bd_ip_mac_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005745{
Dave Barach72d72232016-08-04 10:15:08 -04005746 unformat_input_t *i = vam->input;
5747 vl_api_bd_ip_mac_add_del_t *mp;
5748 f64 timeout;
5749 u32 bd_id;
5750 u8 is_ipv6 = 0;
5751 u8 is_add = 1;
5752 u8 bd_id_set = 0;
5753 u8 ip_set = 0;
5754 u8 mac_set = 0;
5755 ip4_address_t v4addr;
5756 ip6_address_t v6addr;
5757 u8 macaddr[6];
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005758
Ed Warnickecb9cada2015-12-08 15:45:58 -07005759
Dave Barach72d72232016-08-04 10:15:08 -04005760 /* Parse args required to build the message */
5761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5762 {
5763 if (unformat (i, "bd_id %d", &bd_id))
5764 {
5765 bd_id_set++;
5766 }
5767 else if (unformat (i, "%U", unformat_ip4_address, &v4addr))
5768 {
5769 ip_set++;
5770 }
5771 else if (unformat (i, "%U", unformat_ip6_address, &v6addr))
5772 {
5773 ip_set++;
5774 is_ipv6++;
5775 }
5776 else if (unformat (i, "%U", unformat_ethernet_address, macaddr))
5777 {
5778 mac_set++;
5779 }
5780 else if (unformat (i, "del"))
5781 is_add = 0;
5782 else
5783 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005784 }
5785
Dave Barach72d72232016-08-04 10:15:08 -04005786 if (bd_id_set == 0)
5787 {
5788 errmsg ("missing bridge domain\n");
5789 return -99;
5790 }
5791 else if (ip_set == 0)
5792 {
5793 errmsg ("missing IP address\n");
5794 return -99;
5795 }
5796 else if (mac_set == 0)
5797 {
5798 errmsg ("missing MAC address\n");
5799 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005800 }
5801
Dave Barach72d72232016-08-04 10:15:08 -04005802 M (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005803
Dave Barach72d72232016-08-04 10:15:08 -04005804 mp->bd_id = ntohl (bd_id);
5805 mp->is_ipv6 = is_ipv6;
5806 mp->is_add = is_add;
5807 if (is_ipv6)
5808 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
5809 else
5810 clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
5811 clib_memcpy (mp->mac_address, macaddr, 6);
5812 S;
5813 W;
5814 /* NOTREACHED */
5815 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005816}
5817
Dave Barach72d72232016-08-04 10:15:08 -04005818static int
5819api_tap_connect (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005820{
Dave Barach72d72232016-08-04 10:15:08 -04005821 unformat_input_t *i = vam->input;
5822 vl_api_tap_connect_t *mp;
5823 f64 timeout;
5824 u8 mac_address[6];
5825 u8 random_mac = 1;
5826 u8 name_set = 0;
5827 u8 *tap_name;
Dave Barach7be864a2016-11-28 11:41:35 -05005828 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005829
Dave Barach72d72232016-08-04 10:15:08 -04005830 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005831
Dave Barach72d72232016-08-04 10:15:08 -04005832 /* Parse args required to build the message */
5833 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5834 {
5835 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5836 {
5837 random_mac = 0;
5838 }
5839 else if (unformat (i, "random-mac"))
5840 random_mac = 1;
5841 else if (unformat (i, "tapname %s", &tap_name))
5842 name_set = 1;
Dave Barach143faaa2016-12-02 08:43:40 -05005843 else if (unformat (i, "tag %s", &tag))
5844 ;
Dave Barach72d72232016-08-04 10:15:08 -04005845 else
5846 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005847 }
5848
Dave Barach72d72232016-08-04 10:15:08 -04005849 if (name_set == 0)
5850 {
5851 errmsg ("missing tap name\n");
5852 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005853 }
Dave Barach72d72232016-08-04 10:15:08 -04005854 if (vec_len (tap_name) > 63)
5855 {
5856 errmsg ("tap name too long\n");
Dave Barach7be864a2016-11-28 11:41:35 -05005857 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005858 }
Dave Barach72d72232016-08-04 10:15:08 -04005859 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005860
Dave Barach7be864a2016-11-28 11:41:35 -05005861 if (vec_len (tag) > 63)
5862 {
5863 errmsg ("tag too long\n");
5864 return -99;
5865 }
Dave Barach7be864a2016-11-28 11:41:35 -05005866
Dave Barach72d72232016-08-04 10:15:08 -04005867 /* Construct the API message */
5868 M (TAP_CONNECT, tap_connect);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005869
Dave Barach72d72232016-08-04 10:15:08 -04005870 mp->use_random_mac = random_mac;
5871 clib_memcpy (mp->mac_address, mac_address, 6);
5872 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
Dave Barach7be864a2016-11-28 11:41:35 -05005873 if (tag)
5874 clib_memcpy (mp->tag, tag, vec_len (tag));
5875
Dave Barach72d72232016-08-04 10:15:08 -04005876 vec_free (tap_name);
Dave Barach7be864a2016-11-28 11:41:35 -05005877 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005878
Dave Barach72d72232016-08-04 10:15:08 -04005879 /* send it... */
5880 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005881
Dave Barach72d72232016-08-04 10:15:08 -04005882 /* Wait for a reply... */
5883 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005884}
5885
Dave Barach72d72232016-08-04 10:15:08 -04005886static int
5887api_tap_modify (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005888{
Dave Barach72d72232016-08-04 10:15:08 -04005889 unformat_input_t *i = vam->input;
5890 vl_api_tap_modify_t *mp;
5891 f64 timeout;
5892 u8 mac_address[6];
5893 u8 random_mac = 1;
5894 u8 name_set = 0;
5895 u8 *tap_name;
5896 u32 sw_if_index = ~0;
5897 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005898
Dave Barach72d72232016-08-04 10:15:08 -04005899 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005900
Dave Barach72d72232016-08-04 10:15:08 -04005901 /* Parse args required to build the message */
5902 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5903 {
5904 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5905 sw_if_index_set = 1;
5906 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5907 sw_if_index_set = 1;
5908 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5909 {
5910 random_mac = 0;
5911 }
5912 else if (unformat (i, "random-mac"))
5913 random_mac = 1;
5914 else if (unformat (i, "tapname %s", &tap_name))
5915 name_set = 1;
5916 else
5917 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005918 }
5919
Dave Barach72d72232016-08-04 10:15:08 -04005920 if (sw_if_index_set == 0)
5921 {
5922 errmsg ("missing vpp interface name");
5923 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005924 }
Dave Barach72d72232016-08-04 10:15:08 -04005925 if (name_set == 0)
5926 {
5927 errmsg ("missing tap name\n");
5928 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005929 }
Dave Barach72d72232016-08-04 10:15:08 -04005930 if (vec_len (tap_name) > 63)
5931 {
5932 errmsg ("tap name too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07005933 }
Dave Barach72d72232016-08-04 10:15:08 -04005934 vec_add1 (tap_name, 0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005935
Dave Barach72d72232016-08-04 10:15:08 -04005936 /* Construct the API message */
5937 M (TAP_MODIFY, tap_modify);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005938
Dave Barach72d72232016-08-04 10:15:08 -04005939 mp->use_random_mac = random_mac;
5940 mp->sw_if_index = ntohl (sw_if_index);
5941 clib_memcpy (mp->mac_address, mac_address, 6);
5942 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
5943 vec_free (tap_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005944
Dave Barach72d72232016-08-04 10:15:08 -04005945 /* send it... */
5946 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005947
Dave Barach72d72232016-08-04 10:15:08 -04005948 /* Wait for a reply... */
5949 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005950}
5951
Dave Barach72d72232016-08-04 10:15:08 -04005952static int
5953api_tap_delete (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005954{
Dave Barach72d72232016-08-04 10:15:08 -04005955 unformat_input_t *i = vam->input;
5956 vl_api_tap_delete_t *mp;
5957 f64 timeout;
5958 u32 sw_if_index = ~0;
5959 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005960
Dave Barach72d72232016-08-04 10:15:08 -04005961 /* Parse args required to build the message */
5962 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5963 {
5964 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5965 sw_if_index_set = 1;
5966 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5967 sw_if_index_set = 1;
5968 else
5969 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005970 }
5971
Dave Barach72d72232016-08-04 10:15:08 -04005972 if (sw_if_index_set == 0)
5973 {
5974 errmsg ("missing vpp interface name");
5975 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005976 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08005977
Dave Barach72d72232016-08-04 10:15:08 -04005978 /* Construct the API message */
5979 M (TAP_DELETE, tap_delete);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005980
Dave Barach72d72232016-08-04 10:15:08 -04005981 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07005982
Dave Barach72d72232016-08-04 10:15:08 -04005983 /* send it... */
5984 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005985
Dave Barach72d72232016-08-04 10:15:08 -04005986 /* Wait for a reply... */
5987 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07005988}
5989
Dave Barach72d72232016-08-04 10:15:08 -04005990static int
5991api_ip_add_del_route (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07005992{
Dave Barach72d72232016-08-04 10:15:08 -04005993 unformat_input_t *i = vam->input;
5994 vl_api_ip_add_del_route_t *mp;
5995 f64 timeout;
5996 u32 sw_if_index = ~0, vrf_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04005997 u8 is_ipv6 = 0;
5998 u8 is_local = 0, is_drop = 0;
Neale Ranns948e00f2016-10-20 13:39:34 +01005999 u8 is_unreach = 0, is_prohibit = 0;
Dave Barach72d72232016-08-04 10:15:08 -04006000 u8 create_vrf_if_needed = 0;
6001 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006002 u32 next_hop_weight = 1;
Dave Barach72d72232016-08-04 10:15:08 -04006003 u8 not_last = 0;
6004 u8 is_multipath = 0;
6005 u8 address_set = 0;
6006 u8 address_length_set = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006007 u32 next_hop_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04006008 u32 resolve_attempts = 0;
6009 u32 dst_address_length = 0;
6010 u8 next_hop_set = 0;
6011 ip4_address_t v4_dst_address, v4_next_hop_address;
6012 ip6_address_t v6_dst_address, v6_next_hop_address;
6013 int count = 1;
6014 int j;
6015 f64 before = 0;
6016 u32 random_add_del = 0;
6017 u32 *random_vector = 0;
6018 uword *random_hash;
6019 u32 random_seed = 0xdeaddabe;
6020 u32 classify_table_index = ~0;
6021 u8 is_classify = 0;
Neale Ranns33a7dd52016-10-07 15:14:33 +01006022 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006023 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006024 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006025 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006026
Dave Barach72d72232016-08-04 10:15:08 -04006027 /* Parse args required to build the message */
6028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6029 {
6030 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00006031 ;
Dave Barach72d72232016-08-04 10:15:08 -04006032 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Neale Rannsad422ed2016-11-02 14:20:04 +00006033 ;
Dave Barach72d72232016-08-04 10:15:08 -04006034 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
6035 {
6036 address_set = 1;
6037 is_ipv6 = 0;
6038 }
6039 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
6040 {
6041 address_set = 1;
6042 is_ipv6 = 1;
6043 }
6044 else if (unformat (i, "/%d", &dst_address_length))
6045 {
6046 address_length_set = 1;
6047 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006048
Dave Barach72d72232016-08-04 10:15:08 -04006049 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
6050 &v4_next_hop_address))
6051 {
6052 next_hop_set = 1;
6053 }
6054 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
6055 &v6_next_hop_address))
6056 {
6057 next_hop_set = 1;
6058 }
6059 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
6060 ;
6061 else if (unformat (i, "weight %d", &next_hop_weight))
6062 ;
6063 else if (unformat (i, "drop"))
6064 {
6065 is_drop = 1;
6066 }
Neale Ranns948e00f2016-10-20 13:39:34 +01006067 else if (unformat (i, "null-send-unreach"))
6068 {
6069 is_unreach = 1;
6070 }
6071 else if (unformat (i, "null-send-prohibit"))
6072 {
6073 is_prohibit = 1;
6074 }
Dave Barach72d72232016-08-04 10:15:08 -04006075 else if (unformat (i, "local"))
6076 {
6077 is_local = 1;
6078 }
6079 else if (unformat (i, "classify %d", &classify_table_index))
6080 {
6081 is_classify = 1;
6082 }
6083 else if (unformat (i, "del"))
6084 is_add = 0;
6085 else if (unformat (i, "add"))
6086 is_add = 1;
6087 else if (unformat (i, "not-last"))
6088 not_last = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006089 else if (unformat (i, "resolve-via-host"))
6090 resolve_host = 1;
6091 else if (unformat (i, "resolve-via-attached"))
6092 resolve_attached = 1;
Dave Barach72d72232016-08-04 10:15:08 -04006093 else if (unformat (i, "multipath"))
6094 is_multipath = 1;
6095 else if (unformat (i, "vrf %d", &vrf_id))
6096 ;
6097 else if (unformat (i, "create-vrf"))
6098 create_vrf_if_needed = 1;
6099 else if (unformat (i, "count %d", &count))
6100 ;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006101 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
6102 ;
6103 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6104 ;
6105 else if (unformat (i, "out-label %d", &next_hop_out_label))
Neale Rannsad422ed2016-11-02 14:20:04 +00006106 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
6107 else if (unformat (i, "via-label %d", &next_hop_via_label))
Dave Barach72d72232016-08-04 10:15:08 -04006108 ;
6109 else if (unformat (i, "random"))
6110 random_add_del = 1;
6111 else if (unformat (i, "seed %d", &random_seed))
6112 ;
6113 else
6114 {
6115 clib_warning ("parse error '%U'", format_unformat_error, i);
6116 return -99;
6117 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006118 }
6119
Neale Ranns948e00f2016-10-20 13:39:34 +01006120 if (!next_hop_set && !is_drop && !is_local &&
Neale Rannsad422ed2016-11-02 14:20:04 +00006121 !is_classify && !is_unreach && !is_prohibit &&
6122 MPLS_LABEL_INVALID == next_hop_via_label)
Dave Barach72d72232016-08-04 10:15:08 -04006123 {
Neale Ranns948e00f2016-10-20 13:39:34 +01006124 errmsg
6125 ("next hop / local / drop / unreach / prohibit / classify not set\n");
Dave Barach72d72232016-08-04 10:15:08 -04006126 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006127 }
6128
Neale Rannsad422ed2016-11-02 14:20:04 +00006129 if (next_hop_set && MPLS_LABEL_INVALID != next_hop_via_label)
6130 {
6131 errmsg ("next hop and next-hop via label set\n");
6132 return -99;
6133 }
Dave Barach72d72232016-08-04 10:15:08 -04006134 if (address_set == 0)
6135 {
6136 errmsg ("missing addresses\n");
6137 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006138 }
6139
Dave Barach72d72232016-08-04 10:15:08 -04006140 if (address_length_set == 0)
6141 {
6142 errmsg ("missing address length\n");
6143 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006144 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006145
Dave Barach72d72232016-08-04 10:15:08 -04006146 /* Generate a pile of unique, random routes */
6147 if (random_add_del)
6148 {
6149 u32 this_random_address;
6150 random_hash = hash_create (count, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006151
Dave Barach72d72232016-08-04 10:15:08 -04006152 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
6153 for (j = 0; j <= count; j++)
6154 {
6155 do
6156 {
6157 this_random_address = random_u32 (&random_seed);
6158 this_random_address =
6159 clib_host_to_net_u32 (this_random_address);
6160 }
6161 while (hash_get (random_hash, this_random_address));
6162 vec_add1 (random_vector, this_random_address);
6163 hash_set (random_hash, this_random_address, 1);
6164 }
6165 hash_free (random_hash);
6166 v4_dst_address.as_u32 = random_vector[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07006167 }
6168
Dave Barach72d72232016-08-04 10:15:08 -04006169 if (count > 1)
6170 {
6171 /* Turn on async mode */
6172 vam->async_mode = 1;
6173 vam->async_errors = 0;
6174 before = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006175 }
6176
Dave Barach72d72232016-08-04 10:15:08 -04006177 for (j = 0; j < count; j++)
6178 {
6179 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006180 M2 (IP_ADD_DEL_ROUTE, ip_add_del_route,
6181 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006182
Dave Barach72d72232016-08-04 10:15:08 -04006183 mp->next_hop_sw_if_index = ntohl (sw_if_index);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006184 mp->table_id = ntohl (vrf_id);
Dave Barach72d72232016-08-04 10:15:08 -04006185 mp->create_vrf_if_needed = create_vrf_if_needed;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006186
Dave Barach72d72232016-08-04 10:15:08 -04006187 mp->is_add = is_add;
6188 mp->is_drop = is_drop;
Neale Ranns948e00f2016-10-20 13:39:34 +01006189 mp->is_unreach = is_unreach;
6190 mp->is_prohibit = is_prohibit;
Dave Barach72d72232016-08-04 10:15:08 -04006191 mp->is_ipv6 = is_ipv6;
6192 mp->is_local = is_local;
6193 mp->is_classify = is_classify;
6194 mp->is_multipath = is_multipath;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01006195 mp->is_resolve_host = resolve_host;
6196 mp->is_resolve_attached = resolve_attached;
Dave Barach72d72232016-08-04 10:15:08 -04006197 mp->not_last = not_last;
6198 mp->next_hop_weight = next_hop_weight;
6199 mp->dst_address_length = dst_address_length;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006200 mp->next_hop_table_id = ntohl (next_hop_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04006201 mp->classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006202 mp->next_hop_via_label = ntohl (next_hop_via_label);
6203 mp->next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6204 if (0 != mp->next_hop_n_out_labels)
6205 {
6206 memcpy (mp->next_hop_out_label_stack,
6207 next_hop_out_label_stack,
6208 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6209 vec_free (next_hop_out_label_stack);
6210 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006211
Dave Barach72d72232016-08-04 10:15:08 -04006212 if (is_ipv6)
6213 {
6214 clib_memcpy (mp->dst_address, &v6_dst_address,
6215 sizeof (v6_dst_address));
6216 if (next_hop_set)
6217 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
6218 sizeof (v6_next_hop_address));
6219 increment_v6_address (&v6_dst_address);
6220 }
6221 else
6222 {
6223 clib_memcpy (mp->dst_address, &v4_dst_address,
6224 sizeof (v4_dst_address));
6225 if (next_hop_set)
6226 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
6227 sizeof (v4_next_hop_address));
6228 if (random_add_del)
6229 v4_dst_address.as_u32 = random_vector[j + 1];
6230 else
6231 increment_v4_address (&v4_dst_address);
6232 }
6233 /* send it... */
6234 S;
Dave Barach477570e2016-10-09 17:43:22 -04006235 /* If we receive SIGTERM, stop now... */
6236 if (vam->do_exit)
6237 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006238 }
6239
Dave Barach72d72232016-08-04 10:15:08 -04006240 /* When testing multiple add/del ops, use a control-ping to sync */
6241 if (count > 1)
6242 {
6243 vl_api_control_ping_t *mp;
6244 f64 after;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006245
Dave Barach72d72232016-08-04 10:15:08 -04006246 /* Shut off async mode */
6247 vam->async_mode = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006248
Dave Barach72d72232016-08-04 10:15:08 -04006249 M (CONTROL_PING, control_ping);
6250 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006251
Dave Barach72d72232016-08-04 10:15:08 -04006252 timeout = vat_time_now (vam) + 1.0;
6253 while (vat_time_now (vam) < timeout)
6254 if (vam->result_ready == 1)
6255 goto out;
6256 vam->retval = -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006257
6258 out:
Dave Barach72d72232016-08-04 10:15:08 -04006259 if (vam->retval == -99)
6260 errmsg ("timeout\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07006261
Dave Barach72d72232016-08-04 10:15:08 -04006262 if (vam->async_errors > 0)
6263 {
6264 errmsg ("%d asynchronous errors\n", vam->async_errors);
6265 vam->retval = -98;
6266 }
6267 vam->async_errors = 0;
6268 after = vat_time_now (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006269
Dave Barach477570e2016-10-09 17:43:22 -04006270 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6271 if (j > 0)
6272 count = j;
6273
Dave Barach72d72232016-08-04 10:15:08 -04006274 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6275 count, after - before, count / (after - before));
6276 }
6277 else
6278 {
6279 /* Wait for a reply... */
6280 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006281 }
6282
Dave Barach72d72232016-08-04 10:15:08 -04006283 /* Return the good/bad news */
6284 return (vam->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006285}
6286
Dave Barach72d72232016-08-04 10:15:08 -04006287static int
Neale Ranns1357f3b2016-10-16 12:01:42 -07006288api_mpls_route_add_del (vat_main_t * vam)
6289{
6290 unformat_input_t *i = vam->input;
6291 vl_api_mpls_route_add_del_t *mp;
6292 f64 timeout;
6293 u32 sw_if_index = ~0, table_id = 0;
6294 u8 create_table_if_needed = 0;
6295 u8 is_add = 1;
Neale Ranns72c39092016-11-22 12:16:59 +00006296 u32 next_hop_weight = 1;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006297 u8 is_multipath = 0;
6298 u32 next_hop_table_id = 0;
6299 u8 next_hop_set = 0;
6300 ip4_address_t v4_next_hop_address = {
6301 .as_u32 = 0,
6302 };
6303 ip6_address_t v6_next_hop_address = { {0} };
6304 int count = 1;
6305 int j;
6306 f64 before = 0;
6307 u32 classify_table_index = ~0;
6308 u8 is_classify = 0;
6309 u8 resolve_host = 0, resolve_attached = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006310 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006311 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006312 mpls_label_t *next_hop_out_label_stack = NULL;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006313 mpls_label_t local_label = MPLS_LABEL_INVALID;
Neale Rannsad422ed2016-11-02 14:20:04 +00006314 u8 is_eos = 0;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006315 u8 next_hop_proto_is_ip4 = 1;
6316
6317 /* Parse args required to build the message */
6318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6319 {
6320 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6321 ;
6322 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6323 ;
6324 else if (unformat (i, "%d", &local_label))
6325 ;
6326 else if (unformat (i, "eos"))
6327 is_eos = 1;
6328 else if (unformat (i, "non-eos"))
6329 is_eos = 0;
6330 else if (unformat (i, "via %U", unformat_ip4_address,
6331 &v4_next_hop_address))
6332 {
6333 next_hop_set = 1;
6334 next_hop_proto_is_ip4 = 1;
6335 }
6336 else if (unformat (i, "via %U", unformat_ip6_address,
6337 &v6_next_hop_address))
6338 {
6339 next_hop_set = 1;
6340 next_hop_proto_is_ip4 = 0;
6341 }
6342 else if (unformat (i, "weight %d", &next_hop_weight))
6343 ;
6344 else if (unformat (i, "create-table"))
6345 create_table_if_needed = 1;
6346 else if (unformat (i, "classify %d", &classify_table_index))
6347 {
6348 is_classify = 1;
6349 }
6350 else if (unformat (i, "del"))
6351 is_add = 0;
6352 else if (unformat (i, "add"))
6353 is_add = 1;
6354 else if (unformat (i, "resolve-via-host"))
6355 resolve_host = 1;
6356 else if (unformat (i, "resolve-via-attached"))
6357 resolve_attached = 1;
6358 else if (unformat (i, "multipath"))
6359 is_multipath = 1;
6360 else if (unformat (i, "count %d", &count))
6361 ;
6362 else if (unformat (i, "lookup-in-ip4-table %d", &next_hop_table_id))
6363 {
6364 next_hop_set = 1;
6365 next_hop_proto_is_ip4 = 1;
6366 }
6367 else if (unformat (i, "lookup-in-ip6-table %d", &next_hop_table_id))
6368 {
6369 next_hop_set = 1;
6370 next_hop_proto_is_ip4 = 0;
6371 }
6372 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6373 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006374 else if (unformat (i, "via-label %d", &next_hop_via_label))
Neale Ranns1357f3b2016-10-16 12:01:42 -07006375 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006376 else if (unformat (i, "out-label %d", &next_hop_out_label))
6377 vec_add1 (next_hop_out_label_stack, ntohl (next_hop_out_label));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006378 else
6379 {
6380 clib_warning ("parse error '%U'", format_unformat_error, i);
6381 return -99;
6382 }
6383 }
6384
6385 if (!next_hop_set && !is_classify)
6386 {
6387 errmsg ("next hop / classify not set\n");
6388 return -99;
6389 }
6390
6391 if (MPLS_LABEL_INVALID == local_label)
6392 {
6393 errmsg ("missing label\n");
6394 return -99;
6395 }
6396
6397 if (count > 1)
6398 {
6399 /* Turn on async mode */
6400 vam->async_mode = 1;
6401 vam->async_errors = 0;
6402 before = vat_time_now (vam);
6403 }
6404
6405 for (j = 0; j < count; j++)
6406 {
6407 /* Construct the API message */
Neale Rannsad422ed2016-11-02 14:20:04 +00006408 M2 (MPLS_ROUTE_ADD_DEL, mpls_route_add_del,
6409 sizeof (mpls_label_t) * vec_len (next_hop_out_label_stack));
Neale Ranns1357f3b2016-10-16 12:01:42 -07006410
6411 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
6412 mp->mr_table_id = ntohl (table_id);
6413 mp->mr_create_table_if_needed = create_table_if_needed;
6414
6415 mp->mr_is_add = is_add;
6416 mp->mr_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6417 mp->mr_is_classify = is_classify;
6418 mp->mr_is_multipath = is_multipath;
6419 mp->mr_is_resolve_host = resolve_host;
6420 mp->mr_is_resolve_attached = resolve_attached;
6421 mp->mr_next_hop_weight = next_hop_weight;
6422 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
6423 mp->mr_classify_table_index = ntohl (classify_table_index);
Neale Rannsad422ed2016-11-02 14:20:04 +00006424 mp->mr_next_hop_via_label = ntohl (next_hop_via_label);
Neale Ranns1357f3b2016-10-16 12:01:42 -07006425 mp->mr_label = ntohl (local_label);
6426 mp->mr_eos = is_eos;
6427
Neale Rannsad422ed2016-11-02 14:20:04 +00006428 mp->mr_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
6429 if (0 != mp->mr_next_hop_n_out_labels)
6430 {
6431 memcpy (mp->mr_next_hop_out_label_stack,
6432 next_hop_out_label_stack,
6433 vec_len (next_hop_out_label_stack) * sizeof (mpls_label_t));
6434 vec_free (next_hop_out_label_stack);
6435 }
6436
Neale Ranns1357f3b2016-10-16 12:01:42 -07006437 if (next_hop_set)
6438 {
6439 if (next_hop_proto_is_ip4)
6440 {
6441 clib_memcpy (mp->mr_next_hop,
6442 &v4_next_hop_address,
6443 sizeof (v4_next_hop_address));
6444 }
6445 else
6446 {
6447 clib_memcpy (mp->mr_next_hop,
6448 &v6_next_hop_address,
6449 sizeof (v6_next_hop_address));
6450 }
6451 }
6452 local_label++;
6453
6454 /* send it... */
6455 S;
6456 /* If we receive SIGTERM, stop now... */
6457 if (vam->do_exit)
6458 break;
6459 }
6460
6461 /* When testing multiple add/del ops, use a control-ping to sync */
6462 if (count > 1)
6463 {
6464 vl_api_control_ping_t *mp;
6465 f64 after;
6466
6467 /* Shut off async mode */
6468 vam->async_mode = 0;
6469
6470 M (CONTROL_PING, control_ping);
6471 S;
6472
6473 timeout = vat_time_now (vam) + 1.0;
6474 while (vat_time_now (vam) < timeout)
6475 if (vam->result_ready == 1)
6476 goto out;
6477 vam->retval = -99;
6478
6479 out:
6480 if (vam->retval == -99)
6481 errmsg ("timeout\n");
6482
6483 if (vam->async_errors > 0)
6484 {
6485 errmsg ("%d asynchronous errors\n", vam->async_errors);
6486 vam->retval = -98;
6487 }
6488 vam->async_errors = 0;
6489 after = vat_time_now (vam);
6490
6491 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6492 if (j > 0)
6493 count = j;
6494
6495 fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
6496 count, after - before, count / (after - before));
6497 }
6498 else
6499 {
6500 /* Wait for a reply... */
6501 W;
6502 }
6503
6504 /* Return the good/bad news */
6505 return (vam->retval);
6506}
6507
6508static int
6509api_mpls_ip_bind_unbind (vat_main_t * vam)
6510{
6511 unformat_input_t *i = vam->input;
6512 vl_api_mpls_ip_bind_unbind_t *mp;
6513 f64 timeout;
6514 u32 ip_table_id = 0;
6515 u8 create_table_if_needed = 0;
6516 u8 is_bind = 1;
6517 u8 is_ip4 = 1;
6518 ip4_address_t v4_address;
6519 ip6_address_t v6_address;
6520 u32 address_length;
6521 u8 address_set = 0;
6522 mpls_label_t local_label = MPLS_LABEL_INVALID;
6523
6524 /* Parse args required to build the message */
6525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6526 {
6527 if (unformat (i, "%U/%d", unformat_ip4_address,
6528 &v4_address, &address_length))
6529 {
6530 is_ip4 = 1;
6531 address_set = 1;
6532 }
6533 else if (unformat (i, "%U/%d", unformat_ip6_address,
6534 &v6_address, &address_length))
6535 {
6536 is_ip4 = 0;
6537 address_set = 1;
6538 }
6539 else if (unformat (i, "%d", &local_label))
6540 ;
6541 else if (unformat (i, "create-table"))
6542 create_table_if_needed = 1;
6543 else if (unformat (i, "table-id %d", &ip_table_id))
6544 ;
6545 else if (unformat (i, "unbind"))
6546 is_bind = 0;
6547 else if (unformat (i, "bind"))
6548 is_bind = 1;
6549 else
6550 {
6551 clib_warning ("parse error '%U'", format_unformat_error, i);
6552 return -99;
6553 }
6554 }
6555
6556 if (!address_set)
6557 {
6558 errmsg ("IP addres not set\n");
6559 return -99;
6560 }
6561
6562 if (MPLS_LABEL_INVALID == local_label)
6563 {
6564 errmsg ("missing label\n");
6565 return -99;
6566 }
6567
6568 /* Construct the API message */
6569 M (MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind);
6570
6571 mp->mb_create_table_if_needed = create_table_if_needed;
6572 mp->mb_is_bind = is_bind;
6573 mp->mb_is_ip4 = is_ip4;
6574 mp->mb_ip_table_id = ntohl (ip_table_id);
6575 mp->mb_mpls_table_id = 0;
6576 mp->mb_label = ntohl (local_label);
6577 mp->mb_address_length = address_length;
6578
6579 if (is_ip4)
6580 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
6581 else
6582 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
6583
6584 /* send it... */
6585 S;
6586
6587 /* Wait for a reply... */
6588 W;
Neale Ranns1357f3b2016-10-16 12:01:42 -07006589}
6590
6591static int
Dave Barach72d72232016-08-04 10:15:08 -04006592api_proxy_arp_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006593{
Dave Barach72d72232016-08-04 10:15:08 -04006594 unformat_input_t *i = vam->input;
6595 vl_api_proxy_arp_add_del_t *mp;
6596 f64 timeout;
6597 u32 vrf_id = 0;
6598 u8 is_add = 1;
6599 ip4_address_t lo, hi;
6600 u8 range_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006601
Dave Barach72d72232016-08-04 10:15:08 -04006602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6603 {
6604 if (unformat (i, "vrf %d", &vrf_id))
6605 ;
6606 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
6607 unformat_ip4_address, &hi))
6608 range_set = 1;
6609 else if (unformat (i, "del"))
6610 is_add = 0;
6611 else
6612 {
6613 clib_warning ("parse error '%U'", format_unformat_error, i);
6614 return -99;
6615 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006616 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006617
Dave Barach72d72232016-08-04 10:15:08 -04006618 if (range_set == 0)
6619 {
6620 errmsg ("address range not set\n");
6621 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006622 }
6623
Dave Barach72d72232016-08-04 10:15:08 -04006624 M (PROXY_ARP_ADD_DEL, proxy_arp_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006625
Dave Barach72d72232016-08-04 10:15:08 -04006626 mp->vrf_id = ntohl (vrf_id);
6627 mp->is_add = is_add;
6628 clib_memcpy (mp->low_address, &lo, sizeof (mp->low_address));
6629 clib_memcpy (mp->hi_address, &hi, sizeof (mp->hi_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006630
Dave Barach72d72232016-08-04 10:15:08 -04006631 S;
6632 W;
6633 /* NOTREACHED */
6634 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006635}
6636
Dave Barach72d72232016-08-04 10:15:08 -04006637static int
6638api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006639{
Dave Barach72d72232016-08-04 10:15:08 -04006640 unformat_input_t *i = vam->input;
6641 vl_api_proxy_arp_intfc_enable_disable_t *mp;
6642 f64 timeout;
6643 u32 sw_if_index;
6644 u8 enable = 1;
6645 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006646
Dave Barach72d72232016-08-04 10:15:08 -04006647 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6648 {
6649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6650 sw_if_index_set = 1;
6651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6652 sw_if_index_set = 1;
6653 else if (unformat (i, "enable"))
6654 enable = 1;
6655 else if (unformat (i, "disable"))
6656 enable = 0;
6657 else
6658 {
6659 clib_warning ("parse error '%U'", format_unformat_error, i);
6660 return -99;
6661 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006662 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006663
Dave Barach72d72232016-08-04 10:15:08 -04006664 if (sw_if_index_set == 0)
6665 {
6666 errmsg ("missing interface name or sw_if_index\n");
6667 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006668 }
6669
Dave Barach72d72232016-08-04 10:15:08 -04006670 M (PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006671
Dave Barach72d72232016-08-04 10:15:08 -04006672 mp->sw_if_index = ntohl (sw_if_index);
6673 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006674
Dave Barach72d72232016-08-04 10:15:08 -04006675 S;
6676 W;
6677 /* NOTREACHED */
6678 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006679}
6680
Dave Barach72d72232016-08-04 10:15:08 -04006681static int
Neale Rannsad422ed2016-11-02 14:20:04 +00006682api_mpls_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006683{
Dave Barach72d72232016-08-04 10:15:08 -04006684 unformat_input_t *i = vam->input;
Neale Rannsad422ed2016-11-02 14:20:04 +00006685 vl_api_mpls_tunnel_add_del_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04006686 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006687
Dave Barach72d72232016-08-04 10:15:08 -04006688 u8 is_add = 1;
6689 u8 l2_only = 0;
Neale Rannsad422ed2016-11-02 14:20:04 +00006690 u32 sw_if_index = ~0;
6691 u32 next_hop_sw_if_index = ~0;
6692 u32 next_hop_proto_is_ip4 = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006693
Neale Rannsad422ed2016-11-02 14:20:04 +00006694 u32 next_hop_table_id = 0;
6695 ip4_address_t v4_next_hop_address = {
6696 .as_u32 = 0,
6697 };
6698 ip6_address_t v6_next_hop_address = { {0} };
6699 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID, *labels = NULL;
Dave Barach75665d32016-11-17 11:36:59 -05006700
Dave Barach72d72232016-08-04 10:15:08 -04006701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6702 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006703 if (unformat (i, "add"))
6704 is_add = 1;
6705 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6706 is_add = 0;
6707 else if (unformat (i, "sw_if_index %d", &next_hop_sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -04006708 ;
Neale Rannsad422ed2016-11-02 14:20:04 +00006709 else if (unformat (i, "via %U",
6710 unformat_ip4_address, &v4_next_hop_address))
6711 {
6712 next_hop_proto_is_ip4 = 1;
6713 }
6714 else if (unformat (i, "via %U",
6715 unformat_ip6_address, &v6_next_hop_address))
6716 {
6717 next_hop_proto_is_ip4 = 0;
6718 }
Dave Barach72d72232016-08-04 10:15:08 -04006719 else if (unformat (i, "l2-only"))
6720 l2_only = 1;
Neale Rannsad422ed2016-11-02 14:20:04 +00006721 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
6722 ;
6723 else if (unformat (i, "out-label %d", &next_hop_out_label))
6724 vec_add1 (labels, ntohl (next_hop_out_label));
Dave Barach72d72232016-08-04 10:15:08 -04006725 else
6726 {
6727 clib_warning ("parse error '%U'", format_unformat_error, i);
6728 return -99;
6729 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006730 }
6731
Neale Rannsad422ed2016-11-02 14:20:04 +00006732 M2 (MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del,
6733 sizeof (mpls_label_t) * vec_len (labels));
6734
6735 mp->mt_next_hop_sw_if_index = ntohl (next_hop_sw_if_index);
6736 mp->mt_sw_if_index = ntohl (sw_if_index);
6737 mp->mt_is_add = is_add;
6738 mp->mt_l2_only = l2_only;
6739 mp->mt_next_hop_table_id = ntohl (next_hop_table_id);
6740 mp->mt_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
6741
6742 mp->mt_next_hop_n_out_labels = vec_len (labels);
6743
6744 if (0 != mp->mt_next_hop_n_out_labels)
Dave Barach72d72232016-08-04 10:15:08 -04006745 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006746 clib_memcpy (mp->mt_next_hop_out_label_stack, labels,
6747 sizeof (mpls_label_t) * mp->mt_next_hop_n_out_labels);
6748 vec_free (labels);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006749 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006750
Neale Rannsad422ed2016-11-02 14:20:04 +00006751 if (next_hop_proto_is_ip4)
Dave Barach72d72232016-08-04 10:15:08 -04006752 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006753 clib_memcpy (mp->mt_next_hop,
6754 &v4_next_hop_address, sizeof (v4_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006755 }
Neale Rannsad422ed2016-11-02 14:20:04 +00006756 else
Dave Barach72d72232016-08-04 10:15:08 -04006757 {
Neale Rannsad422ed2016-11-02 14:20:04 +00006758 clib_memcpy (mp->mt_next_hop,
6759 &v6_next_hop_address, sizeof (v6_next_hop_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006760 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006761
Dave Barach72d72232016-08-04 10:15:08 -04006762 S;
6763 W;
6764 /* NOTREACHED */
6765 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006766}
6767
Dave Barach72d72232016-08-04 10:15:08 -04006768static int
6769api_sw_interface_set_unnumbered (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006770{
Dave Barach72d72232016-08-04 10:15:08 -04006771 unformat_input_t *i = vam->input;
6772 vl_api_sw_interface_set_unnumbered_t *mp;
6773 f64 timeout;
6774 u32 sw_if_index;
Dave Barach839fe3e2016-08-10 11:35:54 -04006775 u32 unnum_sw_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04006776 u8 is_add = 1;
6777 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006778
Dave Barach72d72232016-08-04 10:15:08 -04006779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6780 {
6781 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6782 sw_if_index_set = 1;
6783 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6784 sw_if_index_set = 1;
6785 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6786 ;
6787 else if (unformat (i, "del"))
6788 is_add = 0;
6789 else
6790 {
6791 clib_warning ("parse error '%U'", format_unformat_error, i);
6792 return -99;
6793 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006794 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006795
Dave Barach72d72232016-08-04 10:15:08 -04006796 if (sw_if_index_set == 0)
6797 {
6798 errmsg ("missing interface name or sw_if_index\n");
6799 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006800 }
6801
Dave Barach72d72232016-08-04 10:15:08 -04006802 M (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006803
Dave Barach72d72232016-08-04 10:15:08 -04006804 mp->sw_if_index = ntohl (sw_if_index);
6805 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6806 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006807
Dave Barach72d72232016-08-04 10:15:08 -04006808 S;
6809 W;
6810 /* NOTREACHED */
6811 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006812}
6813
Dave Barach72d72232016-08-04 10:15:08 -04006814static int
6815api_ip_neighbor_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006816{
Dave Barach72d72232016-08-04 10:15:08 -04006817 unformat_input_t *i = vam->input;
6818 vl_api_ip_neighbor_add_del_t *mp;
6819 f64 timeout;
6820 u32 sw_if_index;
6821 u8 sw_if_index_set = 0;
6822 u32 vrf_id = 0;
6823 u8 is_add = 1;
6824 u8 is_static = 0;
6825 u8 mac_address[6];
6826 u8 mac_set = 0;
6827 u8 v4_address_set = 0;
6828 u8 v6_address_set = 0;
6829 ip4_address_t v4address;
6830 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006831
Dave Barach72d72232016-08-04 10:15:08 -04006832 memset (mac_address, 0, sizeof (mac_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006833
Dave Barach72d72232016-08-04 10:15:08 -04006834 /* Parse args required to build the message */
6835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6836 {
6837 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
6838 {
6839 mac_set = 1;
6840 }
6841 else if (unformat (i, "del"))
6842 is_add = 0;
6843 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6844 sw_if_index_set = 1;
6845 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6846 sw_if_index_set = 1;
6847 else if (unformat (i, "is_static"))
6848 is_static = 1;
6849 else if (unformat (i, "vrf %d", &vrf_id))
6850 ;
6851 else if (unformat (i, "dst %U", unformat_ip4_address, &v4address))
6852 v4_address_set = 1;
6853 else if (unformat (i, "dst %U", unformat_ip6_address, &v6address))
6854 v6_address_set = 1;
6855 else
6856 {
6857 clib_warning ("parse error '%U'", format_unformat_error, i);
6858 return -99;
6859 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006860 }
6861
Dave Barach72d72232016-08-04 10:15:08 -04006862 if (sw_if_index_set == 0)
6863 {
6864 errmsg ("missing interface name or sw_if_index\n");
6865 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006866 }
Dave Barach72d72232016-08-04 10:15:08 -04006867 if (v4_address_set && v6_address_set)
6868 {
6869 errmsg ("both v4 and v6 addresses set\n");
6870 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006871 }
Dave Barach72d72232016-08-04 10:15:08 -04006872 if (!v4_address_set && !v6_address_set)
6873 {
6874 errmsg ("no address set\n");
6875 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006876 }
6877
Dave Barach72d72232016-08-04 10:15:08 -04006878 /* Construct the API message */
6879 M (IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006880
Dave Barach72d72232016-08-04 10:15:08 -04006881 mp->sw_if_index = ntohl (sw_if_index);
6882 mp->is_add = is_add;
6883 mp->vrf_id = ntohl (vrf_id);
6884 mp->is_static = is_static;
6885 if (mac_set)
6886 clib_memcpy (mp->mac_address, mac_address, 6);
6887 if (v6_address_set)
6888 {
6889 mp->is_ipv6 = 1;
6890 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
6891 }
6892 else
6893 {
6894 /* mp->is_ipv6 = 0; via memset in M macro above */
6895 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07006896 }
6897
Dave Barach72d72232016-08-04 10:15:08 -04006898 /* send it... */
6899 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006900
Dave Barach72d72232016-08-04 10:15:08 -04006901 /* Wait for a reply, return good/bad news */
6902 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006903
Dave Barach72d72232016-08-04 10:15:08 -04006904 /* NOTREACHED */
6905 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006906}
6907
Dave Barach72d72232016-08-04 10:15:08 -04006908static int
6909api_reset_vrf (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006910{
Dave Barach72d72232016-08-04 10:15:08 -04006911 unformat_input_t *i = vam->input;
6912 vl_api_reset_vrf_t *mp;
6913 f64 timeout;
6914 u32 vrf_id = 0;
6915 u8 is_ipv6 = 0;
6916 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006917
Dave Barach72d72232016-08-04 10:15:08 -04006918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6919 {
6920 if (unformat (i, "vrf %d", &vrf_id))
6921 vrf_id_set = 1;
6922 else if (unformat (i, "ipv6"))
6923 is_ipv6 = 1;
6924 else
6925 {
6926 clib_warning ("parse error '%U'", format_unformat_error, i);
6927 return -99;
6928 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006929 }
6930
Dave Barach72d72232016-08-04 10:15:08 -04006931 if (vrf_id_set == 0)
6932 {
6933 errmsg ("missing vrf id\n");
6934 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006935 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006936
Dave Barach72d72232016-08-04 10:15:08 -04006937 M (RESET_VRF, reset_vrf);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006938
Dave Barach72d72232016-08-04 10:15:08 -04006939 mp->vrf_id = ntohl (vrf_id);
6940 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006941
Dave Barach72d72232016-08-04 10:15:08 -04006942 S;
6943 W;
6944 /* NOTREACHED */
6945 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006946}
6947
Dave Barach72d72232016-08-04 10:15:08 -04006948static int
6949api_create_vlan_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07006950{
Dave Barach72d72232016-08-04 10:15:08 -04006951 unformat_input_t *i = vam->input;
6952 vl_api_create_vlan_subif_t *mp;
6953 f64 timeout;
6954 u32 sw_if_index;
6955 u8 sw_if_index_set = 0;
6956 u32 vlan_id;
6957 u8 vlan_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006958
Dave Barach72d72232016-08-04 10:15:08 -04006959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6960 {
6961 if (unformat (i, "sw_if_index %d", &sw_if_index))
6962 sw_if_index_set = 1;
6963 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6964 sw_if_index_set = 1;
6965 else if (unformat (i, "vlan %d", &vlan_id))
6966 vlan_id_set = 1;
6967 else
6968 {
6969 clib_warning ("parse error '%U'", format_unformat_error, i);
6970 return -99;
6971 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07006972 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08006973
Dave Barach72d72232016-08-04 10:15:08 -04006974 if (sw_if_index_set == 0)
6975 {
6976 errmsg ("missing interface name or sw_if_index\n");
6977 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006978 }
6979
Dave Barach72d72232016-08-04 10:15:08 -04006980 if (vlan_id_set == 0)
6981 {
6982 errmsg ("missing vlan_id\n");
6983 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006984 }
Dave Barach72d72232016-08-04 10:15:08 -04006985 M (CREATE_VLAN_SUBIF, create_vlan_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006986
Dave Barach72d72232016-08-04 10:15:08 -04006987 mp->sw_if_index = ntohl (sw_if_index);
6988 mp->vlan_id = ntohl (vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07006989
Dave Barach72d72232016-08-04 10:15:08 -04006990 S;
6991 W;
6992 /* NOTREACHED */
6993 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07006994}
6995
6996#define foreach_create_subif_bit \
6997_(no_tags) \
6998_(one_tag) \
6999_(two_tags) \
7000_(dot1ad) \
7001_(exact_match) \
7002_(default_sub) \
7003_(outer_vlan_id_any) \
7004_(inner_vlan_id_any)
7005
Dave Barach72d72232016-08-04 10:15:08 -04007006static int
7007api_create_subif (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007008{
Dave Barach72d72232016-08-04 10:15:08 -04007009 unformat_input_t *i = vam->input;
7010 vl_api_create_subif_t *mp;
7011 f64 timeout;
7012 u32 sw_if_index;
7013 u8 sw_if_index_set = 0;
7014 u32 sub_id;
7015 u8 sub_id_set = 0;
7016 u32 no_tags = 0;
7017 u32 one_tag = 0;
7018 u32 two_tags = 0;
7019 u32 dot1ad = 0;
7020 u32 exact_match = 0;
7021 u32 default_sub = 0;
7022 u32 outer_vlan_id_any = 0;
7023 u32 inner_vlan_id_any = 0;
7024 u32 tmp;
7025 u16 outer_vlan_id = 0;
7026 u16 inner_vlan_id = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007027
Dave Barach72d72232016-08-04 10:15:08 -04007028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7029 {
7030 if (unformat (i, "sw_if_index %d", &sw_if_index))
7031 sw_if_index_set = 1;
7032 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7033 sw_if_index_set = 1;
7034 else if (unformat (i, "sub_id %d", &sub_id))
7035 sub_id_set = 1;
7036 else if (unformat (i, "outer_vlan_id %d", &tmp))
7037 outer_vlan_id = tmp;
7038 else if (unformat (i, "inner_vlan_id %d", &tmp))
7039 inner_vlan_id = tmp;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007040
7041#define _(a) else if (unformat (i, #a)) a = 1 ;
Dave Barach72d72232016-08-04 10:15:08 -04007042 foreach_create_subif_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07007043#undef _
Dave Barach72d72232016-08-04 10:15:08 -04007044 else
7045 {
7046 clib_warning ("parse error '%U'", format_unformat_error, i);
7047 return -99;
7048 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007049 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007050
Dave Barach72d72232016-08-04 10:15:08 -04007051 if (sw_if_index_set == 0)
7052 {
7053 errmsg ("missing interface name or sw_if_index\n");
7054 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007055 }
7056
Dave Barach72d72232016-08-04 10:15:08 -04007057 if (sub_id_set == 0)
7058 {
7059 errmsg ("missing sub_id\n");
7060 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007061 }
Dave Barach72d72232016-08-04 10:15:08 -04007062 M (CREATE_SUBIF, create_subif);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007063
Dave Barach72d72232016-08-04 10:15:08 -04007064 mp->sw_if_index = ntohl (sw_if_index);
7065 mp->sub_id = ntohl (sub_id);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007066
Ed Warnickecb9cada2015-12-08 15:45:58 -07007067#define _(a) mp->a = a;
Dave Barach72d72232016-08-04 10:15:08 -04007068 foreach_create_subif_bit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007069#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007070
Dave Barach72d72232016-08-04 10:15:08 -04007071 mp->outer_vlan_id = ntohs (outer_vlan_id);
7072 mp->inner_vlan_id = ntohs (inner_vlan_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007073
Dave Barach72d72232016-08-04 10:15:08 -04007074 S;
7075 W;
7076 /* NOTREACHED */
7077 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007078}
7079
Dave Barach72d72232016-08-04 10:15:08 -04007080static int
7081api_oam_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007082{
Dave Barach72d72232016-08-04 10:15:08 -04007083 unformat_input_t *i = vam->input;
7084 vl_api_oam_add_del_t *mp;
7085 f64 timeout;
7086 u32 vrf_id = 0;
7087 u8 is_add = 1;
7088 ip4_address_t src, dst;
7089 u8 src_set = 0;
7090 u8 dst_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007091
Dave Barach72d72232016-08-04 10:15:08 -04007092 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7093 {
7094 if (unformat (i, "vrf %d", &vrf_id))
7095 ;
7096 else if (unformat (i, "src %U", unformat_ip4_address, &src))
7097 src_set = 1;
7098 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
7099 dst_set = 1;
7100 else if (unformat (i, "del"))
7101 is_add = 0;
7102 else
7103 {
7104 clib_warning ("parse error '%U'", format_unformat_error, i);
7105 return -99;
7106 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007107 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007108
Dave Barach72d72232016-08-04 10:15:08 -04007109 if (src_set == 0)
7110 {
7111 errmsg ("missing src addr\n");
7112 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007113 }
7114
Dave Barach72d72232016-08-04 10:15:08 -04007115 if (dst_set == 0)
7116 {
7117 errmsg ("missing dst addr\n");
7118 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007119 }
7120
Dave Barach72d72232016-08-04 10:15:08 -04007121 M (OAM_ADD_DEL, oam_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007122
Dave Barach72d72232016-08-04 10:15:08 -04007123 mp->vrf_id = ntohl (vrf_id);
7124 mp->is_add = is_add;
7125 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
7126 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007127
Dave Barach72d72232016-08-04 10:15:08 -04007128 S;
7129 W;
7130 /* NOTREACHED */
7131 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007132}
7133
Dave Barach72d72232016-08-04 10:15:08 -04007134static int
7135api_reset_fib (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007136{
Dave Barach72d72232016-08-04 10:15:08 -04007137 unformat_input_t *i = vam->input;
7138 vl_api_reset_fib_t *mp;
7139 f64 timeout;
7140 u32 vrf_id = 0;
7141 u8 is_ipv6 = 0;
7142 u8 vrf_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007143
Dave Barach72d72232016-08-04 10:15:08 -04007144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7145 {
7146 if (unformat (i, "vrf %d", &vrf_id))
7147 vrf_id_set = 1;
7148 else if (unformat (i, "ipv6"))
7149 is_ipv6 = 1;
7150 else
7151 {
7152 clib_warning ("parse error '%U'", format_unformat_error, i);
7153 return -99;
7154 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007155 }
7156
Dave Barach72d72232016-08-04 10:15:08 -04007157 if (vrf_id_set == 0)
7158 {
7159 errmsg ("missing vrf id\n");
7160 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007161 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007162
Dave Barach72d72232016-08-04 10:15:08 -04007163 M (RESET_FIB, reset_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007164
Dave Barach72d72232016-08-04 10:15:08 -04007165 mp->vrf_id = ntohl (vrf_id);
7166 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007167
Dave Barach72d72232016-08-04 10:15:08 -04007168 S;
7169 W;
7170 /* NOTREACHED */
7171 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007172}
7173
Dave Barach72d72232016-08-04 10:15:08 -04007174static int
7175api_dhcp_proxy_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007176{
Dave Barach72d72232016-08-04 10:15:08 -04007177 unformat_input_t *i = vam->input;
7178 vl_api_dhcp_proxy_config_t *mp;
7179 f64 timeout;
7180 u32 vrf_id = 0;
7181 u8 is_add = 1;
7182 u8 insert_cid = 1;
7183 u8 v4_address_set = 0;
7184 u8 v6_address_set = 0;
7185 ip4_address_t v4address;
7186 ip6_address_t v6address;
7187 u8 v4_src_address_set = 0;
7188 u8 v6_src_address_set = 0;
7189 ip4_address_t v4srcaddress;
7190 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007191
Dave Barach72d72232016-08-04 10:15:08 -04007192 /* Parse args required to build the message */
7193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7194 {
7195 if (unformat (i, "del"))
7196 is_add = 0;
7197 else if (unformat (i, "vrf %d", &vrf_id))
7198 ;
7199 else if (unformat (i, "insert-cid %d", &insert_cid))
7200 ;
7201 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7202 v4_address_set = 1;
7203 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7204 v6_address_set = 1;
7205 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7206 v4_src_address_set = 1;
7207 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7208 v6_src_address_set = 1;
7209 else
7210 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007211 }
7212
Dave Barach72d72232016-08-04 10:15:08 -04007213 if (v4_address_set && v6_address_set)
7214 {
7215 errmsg ("both v4 and v6 server addresses set\n");
7216 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007217 }
Dave Barach72d72232016-08-04 10:15:08 -04007218 if (!v4_address_set && !v6_address_set)
7219 {
7220 errmsg ("no server addresses set\n");
7221 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007222 }
7223
Dave Barach72d72232016-08-04 10:15:08 -04007224 if (v4_src_address_set && v6_src_address_set)
7225 {
7226 errmsg ("both v4 and v6 src addresses set\n");
7227 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007228 }
Dave Barach72d72232016-08-04 10:15:08 -04007229 if (!v4_src_address_set && !v6_src_address_set)
7230 {
7231 errmsg ("no src addresses set\n");
7232 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007233 }
7234
Dave Barach72d72232016-08-04 10:15:08 -04007235 if (!(v4_src_address_set && v4_address_set) &&
7236 !(v6_src_address_set && v6_address_set))
7237 {
7238 errmsg ("no matching server and src addresses set\n");
7239 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007240 }
7241
Dave Barach72d72232016-08-04 10:15:08 -04007242 /* Construct the API message */
7243 M (DHCP_PROXY_CONFIG, dhcp_proxy_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007244
Dave Barach72d72232016-08-04 10:15:08 -04007245 mp->insert_circuit_id = insert_cid;
7246 mp->is_add = is_add;
7247 mp->vrf_id = ntohl (vrf_id);
7248 if (v6_address_set)
7249 {
7250 mp->is_ipv6 = 1;
7251 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7252 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7253 }
7254 else
7255 {
7256 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7257 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007258 }
7259
Dave Barach72d72232016-08-04 10:15:08 -04007260 /* send it... */
7261 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007262
Dave Barach72d72232016-08-04 10:15:08 -04007263 /* Wait for a reply, return good/bad news */
7264 W;
7265 /* NOTREACHED */
7266 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007267}
7268
Dave Barach72d72232016-08-04 10:15:08 -04007269static int
7270api_dhcp_proxy_config_2 (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007271{
Dave Barach72d72232016-08-04 10:15:08 -04007272 unformat_input_t *i = vam->input;
7273 vl_api_dhcp_proxy_config_2_t *mp;
7274 f64 timeout;
7275 u32 rx_vrf_id = 0;
7276 u32 server_vrf_id = 0;
7277 u8 is_add = 1;
7278 u8 insert_cid = 1;
7279 u8 v4_address_set = 0;
7280 u8 v6_address_set = 0;
7281 ip4_address_t v4address;
7282 ip6_address_t v6address;
7283 u8 v4_src_address_set = 0;
7284 u8 v6_src_address_set = 0;
7285 ip4_address_t v4srcaddress;
7286 ip6_address_t v6srcaddress;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007287
Dave Barach72d72232016-08-04 10:15:08 -04007288 /* Parse args required to build the message */
7289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7290 {
7291 if (unformat (i, "del"))
7292 is_add = 0;
7293 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
7294 ;
7295 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
7296 ;
7297 else if (unformat (i, "insert-cid %d", &insert_cid))
7298 ;
7299 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
7300 v4_address_set = 1;
7301 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
7302 v6_address_set = 1;
7303 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
7304 v4_src_address_set = 1;
7305 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
7306 v6_src_address_set = 1;
7307 else
7308 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007309 }
7310
Dave Barach72d72232016-08-04 10:15:08 -04007311 if (v4_address_set && v6_address_set)
7312 {
7313 errmsg ("both v4 and v6 server addresses set\n");
7314 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007315 }
Dave Barach72d72232016-08-04 10:15:08 -04007316 if (!v4_address_set && !v6_address_set)
7317 {
7318 errmsg ("no server addresses set\n");
7319 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007320 }
7321
Dave Barach72d72232016-08-04 10:15:08 -04007322 if (v4_src_address_set && v6_src_address_set)
7323 {
7324 errmsg ("both v4 and v6 src addresses set\n");
7325 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007326 }
Dave Barach72d72232016-08-04 10:15:08 -04007327 if (!v4_src_address_set && !v6_src_address_set)
7328 {
7329 errmsg ("no src addresses set\n");
7330 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007331 }
7332
Dave Barach72d72232016-08-04 10:15:08 -04007333 if (!(v4_src_address_set && v4_address_set) &&
7334 !(v6_src_address_set && v6_address_set))
7335 {
7336 errmsg ("no matching server and src addresses set\n");
7337 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007338 }
7339
Dave Barach72d72232016-08-04 10:15:08 -04007340 /* Construct the API message */
7341 M (DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007342
Dave Barach72d72232016-08-04 10:15:08 -04007343 mp->insert_circuit_id = insert_cid;
7344 mp->is_add = is_add;
7345 mp->rx_vrf_id = ntohl (rx_vrf_id);
7346 mp->server_vrf_id = ntohl (server_vrf_id);
7347 if (v6_address_set)
7348 {
7349 mp->is_ipv6 = 1;
7350 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
7351 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
7352 }
7353 else
7354 {
7355 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
7356 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07007357 }
7358
Dave Barach72d72232016-08-04 10:15:08 -04007359 /* send it... */
7360 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007361
Dave Barach72d72232016-08-04 10:15:08 -04007362 /* Wait for a reply, return good/bad news */
7363 W;
7364 /* NOTREACHED */
7365 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007366}
7367
Dave Barach72d72232016-08-04 10:15:08 -04007368static int
7369api_dhcp_proxy_set_vss (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007370{
Dave Barach72d72232016-08-04 10:15:08 -04007371 unformat_input_t *i = vam->input;
7372 vl_api_dhcp_proxy_set_vss_t *mp;
7373 f64 timeout;
7374 u8 is_ipv6 = 0;
7375 u8 is_add = 1;
7376 u32 tbl_id;
7377 u8 tbl_id_set = 0;
7378 u32 oui;
7379 u8 oui_set = 0;
7380 u32 fib_id;
7381 u8 fib_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007382
Dave Barach72d72232016-08-04 10:15:08 -04007383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7384 {
7385 if (unformat (i, "tbl_id %d", &tbl_id))
7386 tbl_id_set = 1;
7387 if (unformat (i, "fib_id %d", &fib_id))
7388 fib_id_set = 1;
7389 if (unformat (i, "oui %d", &oui))
7390 oui_set = 1;
7391 else if (unformat (i, "ipv6"))
7392 is_ipv6 = 1;
7393 else if (unformat (i, "del"))
7394 is_add = 0;
7395 else
7396 {
7397 clib_warning ("parse error '%U'", format_unformat_error, i);
7398 return -99;
7399 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007400 }
7401
Dave Barach72d72232016-08-04 10:15:08 -04007402 if (tbl_id_set == 0)
7403 {
7404 errmsg ("missing tbl id\n");
7405 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007406 }
7407
Dave Barach72d72232016-08-04 10:15:08 -04007408 if (fib_id_set == 0)
7409 {
7410 errmsg ("missing fib id\n");
7411 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007412 }
Dave Barach72d72232016-08-04 10:15:08 -04007413 if (oui_set == 0)
7414 {
7415 errmsg ("missing oui\n");
7416 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007417 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007418
Dave Barach72d72232016-08-04 10:15:08 -04007419 M (DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
7420 mp->tbl_id = ntohl (tbl_id);
7421 mp->fib_id = ntohl (fib_id);
7422 mp->oui = ntohl (oui);
7423 mp->is_ipv6 = is_ipv6;
7424 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007425
Dave Barach72d72232016-08-04 10:15:08 -04007426 S;
7427 W;
7428 /* NOTREACHED */
7429 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007430}
7431
Dave Barach72d72232016-08-04 10:15:08 -04007432static int
7433api_dhcp_client_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007434{
Dave Barach72d72232016-08-04 10:15:08 -04007435 unformat_input_t *i = vam->input;
7436 vl_api_dhcp_client_config_t *mp;
7437 f64 timeout;
7438 u32 sw_if_index;
7439 u8 sw_if_index_set = 0;
7440 u8 is_add = 1;
7441 u8 *hostname = 0;
7442 u8 disable_event = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007443
Dave Barach72d72232016-08-04 10:15:08 -04007444 /* Parse args required to build the message */
7445 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7446 {
7447 if (unformat (i, "del"))
7448 is_add = 0;
7449 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7450 sw_if_index_set = 1;
7451 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7452 sw_if_index_set = 1;
7453 else if (unformat (i, "hostname %s", &hostname))
7454 ;
7455 else if (unformat (i, "disable_event"))
7456 disable_event = 1;
7457 else
7458 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007459 }
7460
Dave Barach72d72232016-08-04 10:15:08 -04007461 if (sw_if_index_set == 0)
7462 {
7463 errmsg ("missing interface name or sw_if_index\n");
7464 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007465 }
7466
Dave Barach72d72232016-08-04 10:15:08 -04007467 if (vec_len (hostname) > 63)
7468 {
7469 errmsg ("hostname too long\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -07007470 }
Dave Barach72d72232016-08-04 10:15:08 -04007471 vec_add1 (hostname, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007472
Dave Barach72d72232016-08-04 10:15:08 -04007473 /* Construct the API message */
7474 M (DHCP_CLIENT_CONFIG, dhcp_client_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007475
Dave Barach72d72232016-08-04 10:15:08 -04007476 mp->sw_if_index = ntohl (sw_if_index);
7477 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
7478 vec_free (hostname);
7479 mp->is_add = is_add;
7480 mp->want_dhcp_event = disable_event ? 0 : 1;
7481 mp->pid = getpid ();
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007482
Dave Barach72d72232016-08-04 10:15:08 -04007483 /* send it... */
7484 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007485
Dave Barach72d72232016-08-04 10:15:08 -04007486 /* Wait for a reply, return good/bad news */
7487 W;
7488 /* NOTREACHED */
7489 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007490}
7491
Dave Barach72d72232016-08-04 10:15:08 -04007492static int
7493api_set_ip_flow_hash (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007494{
Dave Barach72d72232016-08-04 10:15:08 -04007495 unformat_input_t *i = vam->input;
7496 vl_api_set_ip_flow_hash_t *mp;
7497 f64 timeout;
7498 u32 vrf_id = 0;
7499 u8 is_ipv6 = 0;
7500 u8 vrf_id_set = 0;
7501 u8 src = 0;
7502 u8 dst = 0;
7503 u8 sport = 0;
7504 u8 dport = 0;
7505 u8 proto = 0;
7506 u8 reverse = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007507
Dave Barach72d72232016-08-04 10:15:08 -04007508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7509 {
7510 if (unformat (i, "vrf %d", &vrf_id))
7511 vrf_id_set = 1;
7512 else if (unformat (i, "ipv6"))
7513 is_ipv6 = 1;
7514 else if (unformat (i, "src"))
7515 src = 1;
7516 else if (unformat (i, "dst"))
7517 dst = 1;
7518 else if (unformat (i, "sport"))
7519 sport = 1;
7520 else if (unformat (i, "dport"))
7521 dport = 1;
7522 else if (unformat (i, "proto"))
7523 proto = 1;
7524 else if (unformat (i, "reverse"))
7525 reverse = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007526
Dave Barach72d72232016-08-04 10:15:08 -04007527 else
7528 {
7529 clib_warning ("parse error '%U'", format_unformat_error, i);
7530 return -99;
7531 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007532 }
7533
Dave Barach72d72232016-08-04 10:15:08 -04007534 if (vrf_id_set == 0)
7535 {
7536 errmsg ("missing vrf id\n");
7537 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007538 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007539
Dave Barach72d72232016-08-04 10:15:08 -04007540 M (SET_IP_FLOW_HASH, set_ip_flow_hash);
7541 mp->src = src;
7542 mp->dst = dst;
7543 mp->sport = sport;
7544 mp->dport = dport;
7545 mp->proto = proto;
7546 mp->reverse = reverse;
7547 mp->vrf_id = ntohl (vrf_id);
7548 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007549
Dave Barach72d72232016-08-04 10:15:08 -04007550 S;
7551 W;
7552 /* NOTREACHED */
7553 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007554}
7555
Dave Barach72d72232016-08-04 10:15:08 -04007556static int
7557api_sw_interface_ip6_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007558{
Dave Barach72d72232016-08-04 10:15:08 -04007559 unformat_input_t *i = vam->input;
7560 vl_api_sw_interface_ip6_enable_disable_t *mp;
7561 f64 timeout;
7562 u32 sw_if_index;
7563 u8 sw_if_index_set = 0;
7564 u8 enable = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007565
Dave Barach72d72232016-08-04 10:15:08 -04007566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7567 {
7568 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7569 sw_if_index_set = 1;
7570 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7571 sw_if_index_set = 1;
7572 else if (unformat (i, "enable"))
7573 enable = 1;
7574 else if (unformat (i, "disable"))
7575 enable = 0;
7576 else
7577 {
7578 clib_warning ("parse error '%U'", format_unformat_error, i);
7579 return -99;
7580 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007581 }
7582
Dave Barach72d72232016-08-04 10:15:08 -04007583 if (sw_if_index_set == 0)
7584 {
7585 errmsg ("missing interface name or sw_if_index\n");
7586 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007587 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007588
Dave Barach72d72232016-08-04 10:15:08 -04007589 M (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007590
Dave Barach72d72232016-08-04 10:15:08 -04007591 mp->sw_if_index = ntohl (sw_if_index);
7592 mp->enable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007593
Dave Barach72d72232016-08-04 10:15:08 -04007594 S;
7595 W;
7596 /* NOTREACHED */
7597 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007598}
7599
Dave Barach72d72232016-08-04 10:15:08 -04007600static int
7601api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007602{
Dave Barach72d72232016-08-04 10:15:08 -04007603 unformat_input_t *i = vam->input;
7604 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
7605 f64 timeout;
7606 u32 sw_if_index;
7607 u8 sw_if_index_set = 0;
7608 u32 address_length = 0;
7609 u8 v6_address_set = 0;
7610 ip6_address_t v6address;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007611
Dave Barach72d72232016-08-04 10:15:08 -04007612 /* Parse args required to build the message */
7613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7614 {
7615 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7616 sw_if_index_set = 1;
7617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7618 sw_if_index_set = 1;
7619 else if (unformat (i, "%U/%d",
7620 unformat_ip6_address, &v6address, &address_length))
7621 v6_address_set = 1;
7622 else
7623 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007624 }
7625
Dave Barach72d72232016-08-04 10:15:08 -04007626 if (sw_if_index_set == 0)
7627 {
7628 errmsg ("missing interface name or sw_if_index\n");
7629 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007630 }
Dave Barach72d72232016-08-04 10:15:08 -04007631 if (!v6_address_set)
7632 {
7633 errmsg ("no address set\n");
7634 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007635 }
7636
Dave Barach72d72232016-08-04 10:15:08 -04007637 /* Construct the API message */
7638 M (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,
7639 sw_interface_ip6_set_link_local_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007640
Dave Barach72d72232016-08-04 10:15:08 -04007641 mp->sw_if_index = ntohl (sw_if_index);
7642 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7643 mp->address_length = address_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007644
Dave Barach72d72232016-08-04 10:15:08 -04007645 /* send it... */
7646 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007647
Dave Barach72d72232016-08-04 10:15:08 -04007648 /* Wait for a reply, return good/bad news */
7649 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007650
Dave Barach72d72232016-08-04 10:15:08 -04007651 /* NOTREACHED */
7652 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007653}
7654
7655
Dave Barach72d72232016-08-04 10:15:08 -04007656static int
7657api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007658{
Dave Barach72d72232016-08-04 10:15:08 -04007659 unformat_input_t *i = vam->input;
7660 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
7661 f64 timeout;
7662 u32 sw_if_index;
7663 u8 sw_if_index_set = 0;
7664 u32 address_length = 0;
7665 u8 v6_address_set = 0;
7666 ip6_address_t v6address;
7667 u8 use_default = 0;
7668 u8 no_advertise = 0;
7669 u8 off_link = 0;
7670 u8 no_autoconfig = 0;
7671 u8 no_onlink = 0;
7672 u8 is_no = 0;
7673 u32 val_lifetime = 0;
7674 u32 pref_lifetime = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007675
Dave Barach72d72232016-08-04 10:15:08 -04007676 /* Parse args required to build the message */
7677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7678 {
7679 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7680 sw_if_index_set = 1;
7681 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7682 sw_if_index_set = 1;
7683 else if (unformat (i, "%U/%d",
7684 unformat_ip6_address, &v6address, &address_length))
7685 v6_address_set = 1;
7686 else if (unformat (i, "val_life %d", &val_lifetime))
7687 ;
7688 else if (unformat (i, "pref_life %d", &pref_lifetime))
7689 ;
7690 else if (unformat (i, "def"))
7691 use_default = 1;
7692 else if (unformat (i, "noadv"))
7693 no_advertise = 1;
7694 else if (unformat (i, "offl"))
7695 off_link = 1;
7696 else if (unformat (i, "noauto"))
7697 no_autoconfig = 1;
7698 else if (unformat (i, "nolink"))
7699 no_onlink = 1;
7700 else if (unformat (i, "isno"))
7701 is_no = 1;
7702 else
7703 {
7704 clib_warning ("parse error '%U'", format_unformat_error, i);
7705 return -99;
7706 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007707 }
7708
Dave Barach72d72232016-08-04 10:15:08 -04007709 if (sw_if_index_set == 0)
7710 {
7711 errmsg ("missing interface name or sw_if_index\n");
7712 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007713 }
Dave Barach72d72232016-08-04 10:15:08 -04007714 if (!v6_address_set)
7715 {
7716 errmsg ("no address set\n");
7717 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007718 }
7719
Dave Barach72d72232016-08-04 10:15:08 -04007720 /* Construct the API message */
7721 M (SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007722
Dave Barach72d72232016-08-04 10:15:08 -04007723 mp->sw_if_index = ntohl (sw_if_index);
7724 clib_memcpy (mp->address, &v6address, sizeof (v6address));
7725 mp->address_length = address_length;
7726 mp->use_default = use_default;
7727 mp->no_advertise = no_advertise;
7728 mp->off_link = off_link;
7729 mp->no_autoconfig = no_autoconfig;
7730 mp->no_onlink = no_onlink;
7731 mp->is_no = is_no;
7732 mp->val_lifetime = ntohl (val_lifetime);
7733 mp->pref_lifetime = ntohl (pref_lifetime);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007734
Dave Barach72d72232016-08-04 10:15:08 -04007735 /* send it... */
7736 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007737
Dave Barach72d72232016-08-04 10:15:08 -04007738 /* Wait for a reply, return good/bad news */
7739 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007740
Dave Barach72d72232016-08-04 10:15:08 -04007741 /* NOTREACHED */
7742 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007743}
7744
Dave Barach72d72232016-08-04 10:15:08 -04007745static int
7746api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007747{
Dave Barach72d72232016-08-04 10:15:08 -04007748 unformat_input_t *i = vam->input;
7749 vl_api_sw_interface_ip6nd_ra_config_t *mp;
7750 f64 timeout;
7751 u32 sw_if_index;
7752 u8 sw_if_index_set = 0;
7753 u8 suppress = 0;
7754 u8 managed = 0;
7755 u8 other = 0;
7756 u8 ll_option = 0;
7757 u8 send_unicast = 0;
7758 u8 cease = 0;
7759 u8 is_no = 0;
7760 u8 default_router = 0;
7761 u32 max_interval = 0;
7762 u32 min_interval = 0;
7763 u32 lifetime = 0;
7764 u32 initial_count = 0;
7765 u32 initial_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007766
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007767
Dave Barach72d72232016-08-04 10:15:08 -04007768 /* Parse args required to build the message */
7769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7770 {
7771 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7772 sw_if_index_set = 1;
7773 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7774 sw_if_index_set = 1;
7775 else if (unformat (i, "maxint %d", &max_interval))
7776 ;
7777 else if (unformat (i, "minint %d", &min_interval))
7778 ;
7779 else if (unformat (i, "life %d", &lifetime))
7780 ;
7781 else if (unformat (i, "count %d", &initial_count))
7782 ;
7783 else if (unformat (i, "interval %d", &initial_interval))
7784 ;
7785 else if (unformat (i, "suppress") || unformat (i, "surpress"))
7786 suppress = 1;
7787 else if (unformat (i, "managed"))
7788 managed = 1;
7789 else if (unformat (i, "other"))
7790 other = 1;
7791 else if (unformat (i, "ll"))
7792 ll_option = 1;
7793 else if (unformat (i, "send"))
7794 send_unicast = 1;
7795 else if (unformat (i, "cease"))
7796 cease = 1;
7797 else if (unformat (i, "isno"))
7798 is_no = 1;
7799 else if (unformat (i, "def"))
7800 default_router = 1;
7801 else
7802 {
7803 clib_warning ("parse error '%U'", format_unformat_error, i);
7804 return -99;
7805 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007806 }
7807
Dave Barach72d72232016-08-04 10:15:08 -04007808 if (sw_if_index_set == 0)
7809 {
7810 errmsg ("missing interface name or sw_if_index\n");
7811 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007812 }
7813
Dave Barach72d72232016-08-04 10:15:08 -04007814 /* Construct the API message */
7815 M (SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007816
Dave Barach72d72232016-08-04 10:15:08 -04007817 mp->sw_if_index = ntohl (sw_if_index);
7818 mp->max_interval = ntohl (max_interval);
7819 mp->min_interval = ntohl (min_interval);
7820 mp->lifetime = ntohl (lifetime);
7821 mp->initial_count = ntohl (initial_count);
7822 mp->initial_interval = ntohl (initial_interval);
7823 mp->suppress = suppress;
7824 mp->managed = managed;
7825 mp->other = other;
7826 mp->ll_option = ll_option;
7827 mp->send_unicast = send_unicast;
7828 mp->cease = cease;
7829 mp->is_no = is_no;
7830 mp->default_router = default_router;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007831
Dave Barach72d72232016-08-04 10:15:08 -04007832 /* send it... */
7833 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007834
Dave Barach72d72232016-08-04 10:15:08 -04007835 /* Wait for a reply, return good/bad news */
7836 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007837
Dave Barach72d72232016-08-04 10:15:08 -04007838 /* NOTREACHED */
7839 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007840}
7841
Dave Barach72d72232016-08-04 10:15:08 -04007842static int
7843api_set_arp_neighbor_limit (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007844{
Dave Barach72d72232016-08-04 10:15:08 -04007845 unformat_input_t *i = vam->input;
7846 vl_api_set_arp_neighbor_limit_t *mp;
7847 f64 timeout;
7848 u32 arp_nbr_limit;
7849 u8 limit_set = 0;
7850 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007851
Dave Barach72d72232016-08-04 10:15:08 -04007852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7853 {
7854 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
7855 limit_set = 1;
7856 else if (unformat (i, "ipv6"))
7857 is_ipv6 = 1;
7858 else
7859 {
7860 clib_warning ("parse error '%U'", format_unformat_error, i);
7861 return -99;
7862 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07007863 }
7864
Dave Barach72d72232016-08-04 10:15:08 -04007865 if (limit_set == 0)
7866 {
7867 errmsg ("missing limit value\n");
7868 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007869 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007870
Dave Barach72d72232016-08-04 10:15:08 -04007871 M (SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007872
Dave Barach72d72232016-08-04 10:15:08 -04007873 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
7874 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007875
Dave Barach72d72232016-08-04 10:15:08 -04007876 S;
7877 W;
7878 /* NOTREACHED */
7879 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007880}
7881
Dave Barach72d72232016-08-04 10:15:08 -04007882static int
7883api_l2_patch_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07007884{
Dave Barach72d72232016-08-04 10:15:08 -04007885 unformat_input_t *i = vam->input;
7886 vl_api_l2_patch_add_del_t *mp;
7887 f64 timeout;
7888 u32 rx_sw_if_index;
7889 u8 rx_sw_if_index_set = 0;
7890 u32 tx_sw_if_index;
7891 u8 tx_sw_if_index_set = 0;
7892 u8 is_add = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007893
Dave Barach72d72232016-08-04 10:15:08 -04007894 /* Parse args required to build the message */
7895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7896 {
7897 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7898 rx_sw_if_index_set = 1;
7899 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7900 tx_sw_if_index_set = 1;
7901 else if (unformat (i, "rx"))
7902 {
7903 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7904 {
7905 if (unformat (i, "%U", unformat_sw_if_index, vam,
7906 &rx_sw_if_index))
7907 rx_sw_if_index_set = 1;
7908 }
7909 else
7910 break;
7911 }
7912 else if (unformat (i, "tx"))
7913 {
7914 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7915 {
7916 if (unformat (i, "%U", unformat_sw_if_index, vam,
7917 &tx_sw_if_index))
7918 tx_sw_if_index_set = 1;
7919 }
7920 else
7921 break;
7922 }
7923 else if (unformat (i, "del"))
7924 is_add = 0;
7925 else
7926 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007927 }
7928
Dave Barach72d72232016-08-04 10:15:08 -04007929 if (rx_sw_if_index_set == 0)
7930 {
7931 errmsg ("missing rx interface name or rx_sw_if_index\n");
7932 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007933 }
7934
Dave Barach72d72232016-08-04 10:15:08 -04007935 if (tx_sw_if_index_set == 0)
7936 {
7937 errmsg ("missing tx interface name or tx_sw_if_index\n");
7938 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007939 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007940
Dave Barach72d72232016-08-04 10:15:08 -04007941 M (L2_PATCH_ADD_DEL, l2_patch_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07007942
Dave Barach72d72232016-08-04 10:15:08 -04007943 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7944 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7945 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007946
Dave Barach72d72232016-08-04 10:15:08 -04007947 S;
7948 W;
7949 /* NOTREACHED */
7950 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07007951}
Dave Barach72d72232016-08-04 10:15:08 -04007952
7953static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007954api_ioam_enable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007955{
Dave Barach72d72232016-08-04 10:15:08 -04007956 unformat_input_t *input = vam->input;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007957 vl_api_ioam_enable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007958 f64 timeout;
7959 u32 id = 0;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007960 int has_trace_option = 0;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307961 int has_pot_option = 0;
7962 int has_seqno_option = 0;
7963 int has_analyse_option = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007964
Shwetha20a64f52016-03-25 10:55:01 +00007965 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7966 {
Vengada Govindan07d2f842016-08-25 10:34:34 -07007967 if (unformat (input, "trace"))
7968 has_trace_option = 1;
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307969 else if (unformat (input, "pot"))
7970 has_pot_option = 1;
7971 else if (unformat (input, "seqno"))
7972 has_seqno_option = 1;
7973 else if (unformat (input, "analyse"))
7974 has_analyse_option = 1;
Shwetha20a64f52016-03-25 10:55:01 +00007975 else
Dave Barach72d72232016-08-04 10:15:08 -04007976 break;
Shwetha20a64f52016-03-25 10:55:01 +00007977 }
Vengada Govindan07d2f842016-08-25 10:34:34 -07007978 M (IOAM_ENABLE, ioam_enable);
Dave Barach72d72232016-08-04 10:15:08 -04007979 mp->id = htons (id);
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05307980 mp->seqno = has_seqno_option;
7981 mp->analyse = has_analyse_option;
7982 mp->pot_enable = has_pot_option;
Vengada Govindan07d2f842016-08-25 10:34:34 -07007983 mp->trace_enable = has_trace_option;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007984
Dave Barach72d72232016-08-04 10:15:08 -04007985 S;
7986 W;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007987
Dave Barach72d72232016-08-04 10:15:08 -04007988 return (0);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007989
Shwetha20a64f52016-03-25 10:55:01 +00007990}
Dave Barach72d72232016-08-04 10:15:08 -04007991
Shwetha20a64f52016-03-25 10:55:01 +00007992
Dave Barach72d72232016-08-04 10:15:08 -04007993static int
Vengada Govindan07d2f842016-08-25 10:34:34 -07007994api_ioam_disable (vat_main_t * vam)
Shwetha20a64f52016-03-25 10:55:01 +00007995{
Vengada Govindan07d2f842016-08-25 10:34:34 -07007996 vl_api_ioam_disable_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04007997 f64 timeout;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08007998
Vengada Govindan07d2f842016-08-25 10:34:34 -07007999 M (IOAM_DISABLE, ioam_disable);
Dave Barach72d72232016-08-04 10:15:08 -04008000 S;
8001 W;
8002 return 0;
Shwetha20a64f52016-03-25 10:55:01 +00008003}
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008004
Dave Barach72d72232016-08-04 10:15:08 -04008005static int
8006api_sr_tunnel_add_del (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008007{
Dave Barach72d72232016-08-04 10:15:08 -04008008 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008009 vl_api_sr_tunnel_add_del_t *mp;
8010 f64 timeout;
8011 int is_del = 0;
8012 int pl_index;
8013 ip6_address_t src_address;
8014 int src_address_set = 0;
8015 ip6_address_t dst_address;
8016 u32 dst_mask_width;
8017 int dst_address_set = 0;
8018 u16 flags = 0;
8019 u32 rx_table_id = 0;
8020 u32 tx_table_id = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008021 ip6_address_t *segments = 0;
8022 ip6_address_t *this_seg;
8023 ip6_address_t *tags = 0;
8024 ip6_address_t *this_tag;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008025 ip6_address_t next_address, tag;
Dave Barach72d72232016-08-04 10:15:08 -04008026 u8 *name = 0;
8027 u8 *policy_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008028
8029 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8030 {
8031 if (unformat (i, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008032 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008033 else if (unformat (i, "name %s", &name))
Dave Barach72d72232016-08-04 10:15:08 -04008034 ;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008035 else if (unformat (i, "policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008036 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008037 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04008038 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008039 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
Dave Barach72d72232016-08-04 10:15:08 -04008040 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008041 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
Dave Barach72d72232016-08-04 10:15:08 -04008042 src_address_set = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008043 else if (unformat (i, "dst %U/%d",
Dave Barach72d72232016-08-04 10:15:08 -04008044 unformat_ip6_address, &dst_address, &dst_mask_width))
8045 dst_address_set = 1;
8046 else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
8047 {
8048 vec_add2 (segments, this_seg, 1);
8049 clib_memcpy (this_seg->as_u8, next_address.as_u8,
8050 sizeof (*this_seg));
8051 }
8052 else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
8053 {
8054 vec_add2 (tags, this_tag, 1);
8055 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
8056 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008057 else if (unformat (i, "clean"))
Dave Barach72d72232016-08-04 10:15:08 -04008058 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008059 else if (unformat (i, "protected"))
Dave Barach72d72232016-08-04 10:15:08 -04008060 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008061 else if (unformat (i, "InPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008062 {
8063 if (pl_index <= 0 || pl_index > 4)
8064 {
8065 pl_index_range_error:
8066 errmsg ("pl index %d out of range\n", pl_index);
8067 return -99;
8068 }
8069 flags |=
8070 IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
8071 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008072 else if (unformat (i, "EgPE %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008073 {
8074 if (pl_index <= 0 || pl_index > 4)
8075 goto pl_index_range_error;
8076 flags |=
8077 IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
8078 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008079 else if (unformat (i, "OrgSrc %d", &pl_index))
Dave Barach72d72232016-08-04 10:15:08 -04008080 {
8081 if (pl_index <= 0 || pl_index > 4)
8082 goto pl_index_range_error;
8083 flags |=
8084 IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
8085 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008086 else
Dave Barach72d72232016-08-04 10:15:08 -04008087 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008088 }
8089
8090 if (!src_address_set)
8091 {
8092 errmsg ("src address required\n");
8093 return -99;
8094 }
8095
8096 if (!dst_address_set)
8097 {
8098 errmsg ("dst address required\n");
8099 return -99;
8100 }
8101
8102 if (!segments)
8103 {
8104 errmsg ("at least one sr segment required\n");
8105 return -99;
8106 }
8107
Dave Barach72d72232016-08-04 10:15:08 -04008108 M2 (SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
8109 vec_len (segments) * sizeof (ip6_address_t)
8110 + vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008111
Damjan Marionf1213b82016-03-13 02:22:06 +01008112 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
8113 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008114 mp->dst_mask_width = dst_mask_width;
8115 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
8116 mp->n_segments = vec_len (segments);
8117 mp->n_tags = vec_len (tags);
8118 mp->is_add = is_del == 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008119 clib_memcpy (mp->segs_and_tags, segments,
Dave Barach72d72232016-08-04 10:15:08 -04008120 vec_len (segments) * sizeof (ip6_address_t));
8121 clib_memcpy (mp->segs_and_tags +
8122 vec_len (segments) * sizeof (ip6_address_t), tags,
8123 vec_len (tags) * sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008124
8125 mp->outer_vrf_id = ntohl (rx_table_id);
8126 mp->inner_vrf_id = ntohl (tx_table_id);
Dave Barach72d72232016-08-04 10:15:08 -04008127 memcpy (mp->name, name, vec_len (name));
8128 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008129
8130 vec_free (segments);
8131 vec_free (tags);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008132
Dave Barach72d72232016-08-04 10:15:08 -04008133 S;
8134 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008135 /* NOTREACHED */
8136}
8137
Dave Barach72d72232016-08-04 10:15:08 -04008138static int
8139api_sr_policy_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008140{
Dave Barach72d72232016-08-04 10:15:08 -04008141 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008142 vl_api_sr_policy_add_del_t *mp;
8143 f64 timeout;
8144 int is_del = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008145 u8 *name = 0;
8146 u8 *tunnel_name = 0;
8147 u8 **tunnel_names = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008148
Dave Barach72d72232016-08-04 10:15:08 -04008149 int name_set = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008150 int tunnel_set = 0;
8151 int j = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008152 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
8153 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008154
8155 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8156 {
8157 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008158 is_del = 1;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008159 else if (unformat (input, "name %s", &name))
8160 name_set = 1;
8161 else if (unformat (input, "tunnel %s", &tunnel_name))
Dave Barach72d72232016-08-04 10:15:08 -04008162 {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008163 if (tunnel_name)
8164 {
8165 vec_add1 (tunnel_names, tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008166 /* For serializer:
Dave Barach72d72232016-08-04 10:15:08 -04008167 - length = #bytes to store in serial vector
8168 - +1 = byte to store that length
8169 */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008170 tunnel_names_length += (vec_len (tunnel_name) + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008171 tunnel_set = 1;
8172 tunnel_name = 0;
8173 }
Dave Barach72d72232016-08-04 10:15:08 -04008174 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008175 else
Dave Barach72d72232016-08-04 10:15:08 -04008176 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008177 }
8178
8179 if (!name_set)
8180 {
8181 errmsg ("policy name required\n");
8182 return -99;
8183 }
8184
8185 if ((!tunnel_set) && (!is_del))
8186 {
8187 errmsg ("tunnel name required\n");
8188 return -99;
8189 }
8190
Dave Barach72d72232016-08-04 10:15:08 -04008191 M2 (SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008192
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008193
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008194
8195 mp->is_add = !is_del;
8196
Dave Barach72d72232016-08-04 10:15:08 -04008197 memcpy (mp->name, name, vec_len (name));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008198 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
Dave Barach72d72232016-08-04 10:15:08 -04008199 u8 *serial_orig = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008200 vec_validate (serial_orig, tunnel_names_length);
Dave Barach72d72232016-08-04 10:15:08 -04008201 *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
8202 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008203
Dave Barach72d72232016-08-04 10:15:08 -04008204 for (j = 0; j < vec_len (tunnel_names); j++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008205 {
8206 tun_name_len = vec_len (tunnel_names[j]);
Dave Barach72d72232016-08-04 10:15:08 -04008207 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
8208 serial_orig += 1; // Move along one byte to store the actual tunnel name
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008209 memcpy (serial_orig, tunnel_names[j], tun_name_len);
Dave Barach72d72232016-08-04 10:15:08 -04008210 serial_orig += tun_name_len; // Advance past the copy
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008211 }
Dave Barach72d72232016-08-04 10:15:08 -04008212 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008213
8214 vec_free (tunnel_names);
8215 vec_free (tunnel_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008216
Dave Barach72d72232016-08-04 10:15:08 -04008217 S;
8218 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008219 /* NOTREACHED */
8220}
8221
Dave Barach72d72232016-08-04 10:15:08 -04008222static int
8223api_sr_multicast_map_add_del (vat_main_t * vam)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008224{
Dave Barach72d72232016-08-04 10:15:08 -04008225 unformat_input_t *input = vam->input;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008226 vl_api_sr_multicast_map_add_del_t *mp;
8227 f64 timeout;
8228 int is_del = 0;
8229 ip6_address_t multicast_address;
Dave Barach72d72232016-08-04 10:15:08 -04008230 u8 *policy_name = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008231 int multicast_address_set = 0;
8232
8233 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8234 {
8235 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -04008236 is_del = 1;
8237 else
8238 if (unformat
8239 (input, "address %U", unformat_ip6_address, &multicast_address))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008240 multicast_address_set = 1;
8241 else if (unformat (input, "sr-policy %s", &policy_name))
Dave Barach72d72232016-08-04 10:15:08 -04008242 ;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008243 else
Dave Barach72d72232016-08-04 10:15:08 -04008244 break;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008245 }
8246
8247 if (!is_del && !policy_name)
8248 {
8249 errmsg ("sr-policy name required\n");
8250 return -99;
8251 }
8252
8253
8254 if (!multicast_address_set)
8255 {
8256 errmsg ("address required\n");
8257 return -99;
8258 }
8259
Dave Barach72d72232016-08-04 10:15:08 -04008260 M (SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008261
8262 mp->is_add = !is_del;
Dave Barach72d72232016-08-04 10:15:08 -04008263 memcpy (mp->policy_name, policy_name, vec_len (policy_name));
8264 clib_memcpy (mp->multicast_address, &multicast_address,
8265 sizeof (mp->multicast_address));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008266
8267
8268 vec_free (policy_name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008269
Dave Barach72d72232016-08-04 10:15:08 -04008270 S;
8271 W;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07008272 /* NOTREACHED */
8273}
8274
Ed Warnickecb9cada2015-12-08 15:45:58 -07008275
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008276#define foreach_tcp_proto_field \
8277_(src_port) \
8278_(dst_port)
8279
8280#define foreach_udp_proto_field \
8281_(src_port) \
8282_(dst_port)
8283
Ed Warnickecb9cada2015-12-08 15:45:58 -07008284#define foreach_ip4_proto_field \
8285_(src_address) \
8286_(dst_address) \
8287_(tos) \
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008288_(length) \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008289_(fragment_id) \
8290_(ttl) \
8291_(protocol) \
8292_(checksum)
8293
Dave Barach72d72232016-08-04 10:15:08 -04008294uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008295unformat_tcp_mask (unformat_input_t * input, va_list * args)
8296{
8297 u8 **maskp = va_arg (*args, u8 **);
8298 u8 *mask = 0;
8299 u8 found_something = 0;
8300 tcp_header_t *tcp;
8301
8302#define _(a) u8 a=0;
8303 foreach_tcp_proto_field;
8304#undef _
8305
8306 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8307 {
8308 if (0);
8309#define _(a) else if (unformat (input, #a)) a=1;
8310 foreach_tcp_proto_field
8311#undef _
8312 else
8313 break;
8314 }
8315
8316#define _(a) found_something += a;
8317 foreach_tcp_proto_field;
8318#undef _
8319
8320 if (found_something == 0)
8321 return 0;
8322
8323 vec_validate (mask, sizeof (*tcp) - 1);
8324
8325 tcp = (tcp_header_t *) mask;
8326
8327#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a));
8328 foreach_tcp_proto_field;
8329#undef _
8330
8331 *maskp = mask;
8332 return 1;
8333}
8334
8335uword
8336unformat_udp_mask (unformat_input_t * input, va_list * args)
8337{
8338 u8 **maskp = va_arg (*args, u8 **);
8339 u8 *mask = 0;
8340 u8 found_something = 0;
8341 udp_header_t *udp;
8342
8343#define _(a) u8 a=0;
8344 foreach_udp_proto_field;
8345#undef _
8346
8347 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8348 {
8349 if (0);
8350#define _(a) else if (unformat (input, #a)) a=1;
8351 foreach_udp_proto_field
8352#undef _
8353 else
8354 break;
8355 }
8356
8357#define _(a) found_something += a;
8358 foreach_udp_proto_field;
8359#undef _
8360
8361 if (found_something == 0)
8362 return 0;
8363
8364 vec_validate (mask, sizeof (*udp) - 1);
8365
8366 udp = (udp_header_t *) mask;
8367
8368#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a));
8369 foreach_udp_proto_field;
8370#undef _
8371
8372 *maskp = mask;
8373 return 1;
8374}
8375
8376typedef struct
8377{
8378 u16 src_port, dst_port;
8379} tcpudp_header_t;
8380
8381uword
8382unformat_l4_mask (unformat_input_t * input, va_list * args)
8383{
8384 u8 **maskp = va_arg (*args, u8 **);
8385 u16 src_port = 0, dst_port = 0;
8386 tcpudp_header_t *tcpudp;
8387
8388 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8389 {
8390 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
8391 return 1;
8392 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
8393 return 1;
8394 else if (unformat (input, "src_port"))
8395 src_port = 0xFFFF;
8396 else if (unformat (input, "dst_port"))
8397 dst_port = 0xFFFF;
8398 else
8399 return 0;
8400 }
8401
8402 if (!src_port && !dst_port)
8403 return 0;
8404
8405 u8 *mask = 0;
8406 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
8407
8408 tcpudp = (tcpudp_header_t *) mask;
8409 tcpudp->src_port = src_port;
8410 tcpudp->dst_port = dst_port;
8411
8412 *maskp = mask;
8413
8414 return 1;
8415}
8416
8417uword
Dave Barach72d72232016-08-04 10:15:08 -04008418unformat_ip4_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008419{
Dave Barach72d72232016-08-04 10:15:08 -04008420 u8 **maskp = va_arg (*args, u8 **);
8421 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008422 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008423 ip4_header_t *ip;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008424
Ed Warnickecb9cada2015-12-08 15:45:58 -07008425#define _(a) u8 a=0;
8426 foreach_ip4_proto_field;
8427#undef _
8428 u8 version = 0;
8429 u8 hdr_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008430
8431
8432 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008433 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008434 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008435 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008436 else if (unformat (input, "hdr_length"))
Dave Barach72d72232016-08-04 10:15:08 -04008437 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008438 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008439 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008440 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008441 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008442 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008443 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008444
Ed Warnickecb9cada2015-12-08 15:45:58 -07008445#define _(a) else if (unformat (input, #a)) a=1;
8446 foreach_ip4_proto_field
8447#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008448 else
8449 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008450 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008451
Ed Warnickecb9cada2015-12-08 15:45:58 -07008452#define _(a) found_something += a;
8453 foreach_ip4_proto_field;
8454#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008455
Ed Warnickecb9cada2015-12-08 15:45:58 -07008456 if (found_something == 0)
8457 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008458
Ed Warnickecb9cada2015-12-08 15:45:58 -07008459 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008460
Ed Warnickecb9cada2015-12-08 15:45:58 -07008461 ip = (ip4_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008462
Ed Warnickecb9cada2015-12-08 15:45:58 -07008463#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8464 foreach_ip4_proto_field;
8465#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008466
Ed Warnickecb9cada2015-12-08 15:45:58 -07008467 ip->ip_version_and_header_length = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008468
Ed Warnickecb9cada2015-12-08 15:45:58 -07008469 if (version)
8470 ip->ip_version_and_header_length |= 0xF0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008471
Ed Warnickecb9cada2015-12-08 15:45:58 -07008472 if (hdr_length)
8473 ip->ip_version_and_header_length |= 0x0F;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008474
Ed Warnickecb9cada2015-12-08 15:45:58 -07008475 *maskp = mask;
8476 return 1;
8477}
8478
8479#define foreach_ip6_proto_field \
8480_(src_address) \
8481_(dst_address) \
8482_(payload_length) \
8483_(hop_limit) \
8484_(protocol)
8485
Dave Barach72d72232016-08-04 10:15:08 -04008486uword
8487unformat_ip6_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008488{
Dave Barach72d72232016-08-04 10:15:08 -04008489 u8 **maskp = va_arg (*args, u8 **);
8490 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008491 u8 found_something = 0;
Dave Barach72d72232016-08-04 10:15:08 -04008492 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008493 u32 ip_version_traffic_class_and_flow_label;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008494
Ed Warnickecb9cada2015-12-08 15:45:58 -07008495#define _(a) u8 a=0;
8496 foreach_ip6_proto_field;
8497#undef _
8498 u8 version = 0;
8499 u8 traffic_class = 0;
8500 u8 flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008501
8502 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008503 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008504 if (unformat (input, "version"))
Dave Barach72d72232016-08-04 10:15:08 -04008505 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008506 else if (unformat (input, "traffic-class"))
Dave Barach72d72232016-08-04 10:15:08 -04008507 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008508 else if (unformat (input, "flow-label"))
Dave Barach72d72232016-08-04 10:15:08 -04008509 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008510 else if (unformat (input, "src"))
Dave Barach72d72232016-08-04 10:15:08 -04008511 src_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008512 else if (unformat (input, "dst"))
Dave Barach72d72232016-08-04 10:15:08 -04008513 dst_address = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008514 else if (unformat (input, "proto"))
Dave Barach72d72232016-08-04 10:15:08 -04008515 protocol = 1;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008516
Ed Warnickecb9cada2015-12-08 15:45:58 -07008517#define _(a) else if (unformat (input, #a)) a=1;
8518 foreach_ip6_proto_field
8519#undef _
Dave Barach72d72232016-08-04 10:15:08 -04008520 else
8521 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008522 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008523
Ed Warnickecb9cada2015-12-08 15:45:58 -07008524#define _(a) found_something += a;
8525 foreach_ip6_proto_field;
8526#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008527
Ed Warnickecb9cada2015-12-08 15:45:58 -07008528 if (found_something == 0)
8529 return 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008530
Ed Warnickecb9cada2015-12-08 15:45:58 -07008531 vec_validate (mask, sizeof (*ip) - 1);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008532
Ed Warnickecb9cada2015-12-08 15:45:58 -07008533 ip = (ip6_header_t *) mask;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008534
Ed Warnickecb9cada2015-12-08 15:45:58 -07008535#define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
8536 foreach_ip6_proto_field;
8537#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008538
Ed Warnickecb9cada2015-12-08 15:45:58 -07008539 ip_version_traffic_class_and_flow_label = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008540
Ed Warnickecb9cada2015-12-08 15:45:58 -07008541 if (version)
8542 ip_version_traffic_class_and_flow_label |= 0xF0000000;
8543
8544 if (traffic_class)
8545 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
8546
8547 if (flow_label)
8548 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
8549
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008550 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07008551 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008552
Ed Warnickecb9cada2015-12-08 15:45:58 -07008553 *maskp = mask;
8554 return 1;
8555}
8556
Dave Barach72d72232016-08-04 10:15:08 -04008557uword
8558unformat_l3_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008559{
Dave Barach72d72232016-08-04 10:15:08 -04008560 u8 **maskp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008561
Dave Barach72d72232016-08-04 10:15:08 -04008562 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8563 {
8564 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
8565 return 1;
8566 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
8567 return 1;
8568 else
8569 break;
8570 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008571 return 0;
8572}
8573
Dave Barach72d72232016-08-04 10:15:08 -04008574uword
8575unformat_l2_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008576{
Dave Barach72d72232016-08-04 10:15:08 -04008577 u8 **maskp = va_arg (*args, u8 **);
8578 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008579 u8 src = 0;
8580 u8 dst = 0;
8581 u8 proto = 0;
8582 u8 tag1 = 0;
8583 u8 tag2 = 0;
8584 u8 ignore_tag1 = 0;
8585 u8 ignore_tag2 = 0;
8586 u8 cos1 = 0;
8587 u8 cos2 = 0;
8588 u8 dot1q = 0;
8589 u8 dot1ad = 0;
8590 int len = 14;
8591
Dave Barach72d72232016-08-04 10:15:08 -04008592 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8593 {
8594 if (unformat (input, "src"))
8595 src = 1;
8596 else if (unformat (input, "dst"))
8597 dst = 1;
8598 else if (unformat (input, "proto"))
8599 proto = 1;
8600 else if (unformat (input, "tag1"))
8601 tag1 = 1;
8602 else if (unformat (input, "tag2"))
8603 tag2 = 1;
8604 else if (unformat (input, "ignore-tag1"))
8605 ignore_tag1 = 1;
8606 else if (unformat (input, "ignore-tag2"))
8607 ignore_tag2 = 1;
8608 else if (unformat (input, "cos1"))
8609 cos1 = 1;
8610 else if (unformat (input, "cos2"))
8611 cos2 = 1;
8612 else if (unformat (input, "dot1q"))
8613 dot1q = 1;
8614 else if (unformat (input, "dot1ad"))
8615 dot1ad = 1;
8616 else
8617 break;
8618 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008619 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
Dave Barach72d72232016-08-04 10:15:08 -04008620 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008621 return 0;
8622
8623 if (tag1 || ignore_tag1 || cos1 || dot1q)
8624 len = 18;
8625 if (tag2 || ignore_tag2 || cos2 || dot1ad)
8626 len = 22;
8627
Dave Barach72d72232016-08-04 10:15:08 -04008628 vec_validate (mask, len - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008629
8630 if (dst)
8631 memset (mask, 0xff, 6);
8632
8633 if (src)
8634 memset (mask + 6, 0xff, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008635
Ed Warnickecb9cada2015-12-08 15:45:58 -07008636 if (tag2 || dot1ad)
8637 {
8638 /* inner vlan tag */
8639 if (tag2)
Dave Barach72d72232016-08-04 10:15:08 -04008640 {
8641 mask[19] = 0xff;
8642 mask[18] = 0x0f;
8643 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008644 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04008645 mask[18] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008646 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008647 mask[21] = mask[20] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008648 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008649 {
8650 mask[15] = 0xff;
8651 mask[14] = 0x0f;
8652 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008653 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008654 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008655 *maskp = mask;
8656 return 1;
8657 }
8658 if (tag1 | dot1q)
8659 {
8660 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04008661 {
8662 mask[15] = 0xff;
8663 mask[14] = 0x0f;
8664 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008665 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04008666 mask[14] |= 0xe0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008667 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008668 mask[16] = mask[17] = 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008669
8670 *maskp = mask;
8671 return 1;
8672 }
8673 if (cos2)
8674 mask[18] |= 0xe0;
8675 if (cos1)
8676 mask[14] |= 0xe0;
8677 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04008678 mask[12] = mask[13] = 0xff;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008679
Ed Warnickecb9cada2015-12-08 15:45:58 -07008680 *maskp = mask;
8681 return 1;
8682}
8683
Dave Barach72d72232016-08-04 10:15:08 -04008684uword
8685unformat_classify_mask (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008686{
Dave Barach72d72232016-08-04 10:15:08 -04008687 u8 **maskp = va_arg (*args, u8 **);
8688 u32 *skipp = va_arg (*args, u32 *);
8689 u32 *matchp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008690 u32 match;
Dave Barach72d72232016-08-04 10:15:08 -04008691 u8 *mask = 0;
8692 u8 *l2 = 0;
8693 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008694 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008695 int i;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008696
Dave Barach72d72232016-08-04 10:15:08 -04008697 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8698 {
8699 if (unformat (input, "hex %U", unformat_hex_string, &mask))
8700 ;
8701 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
8702 ;
8703 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
8704 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008705 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
8706 ;
Dave Barach72d72232016-08-04 10:15:08 -04008707 else
8708 break;
8709 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008710
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008711 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008712 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008713 vec_free (mask);
8714 vec_free (l2);
8715 vec_free (l4);
8716 return 0;
8717 }
8718
8719 if (mask || l2 || l3 || l4)
8720 {
8721 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04008722 {
8723 /* "With a free Ethernet header in every package" */
8724 if (l2 == 0)
8725 vec_validate (l2, 13);
8726 mask = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04008727 if (vec_len (l3))
8728 {
8729 vec_append (mask, l3);
8730 vec_free (l3);
8731 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008732 if (vec_len (l4))
8733 {
8734 vec_append (mask, l4);
8735 vec_free (l4);
8736 }
Dave Barach72d72232016-08-04 10:15:08 -04008737 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008738
8739 /* Scan forward looking for the first significant mask octet */
8740 for (i = 0; i < vec_len (mask); i++)
Dave Barach72d72232016-08-04 10:15:08 -04008741 if (mask[i])
8742 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008743
8744 /* compute (skip, match) params */
Dave Barach72d72232016-08-04 10:15:08 -04008745 *skipp = i / sizeof (u32x4);
8746 vec_delete (mask, *skipp * sizeof (u32x4), 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008747
8748 /* Pad mask to an even multiple of the vector size */
8749 while (vec_len (mask) % sizeof (u32x4))
Dave Barach72d72232016-08-04 10:15:08 -04008750 vec_add1 (mask, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008751
8752 match = vec_len (mask) / sizeof (u32x4);
8753
Dave Barach72d72232016-08-04 10:15:08 -04008754 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8755 {
8756 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8757 if (*tmp || *(tmp + 1))
8758 break;
8759 match--;
8760 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008761 if (match == 0)
Dave Barach72d72232016-08-04 10:15:08 -04008762 clib_warning ("BUG: match 0");
Ed Warnickecb9cada2015-12-08 15:45:58 -07008763
Dave Barach72d72232016-08-04 10:15:08 -04008764 _vec_len (mask) = match * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008765
8766 *matchp = match;
8767 *maskp = mask;
8768
8769 return 1;
8770 }
8771
8772 return 0;
8773}
8774
8775#define foreach_l2_next \
8776_(drop, DROP) \
8777_(ethernet, ETHERNET_INPUT) \
8778_(ip4, IP4_INPUT) \
8779_(ip6, IP6_INPUT)
8780
Dave Barach72d72232016-08-04 10:15:08 -04008781uword
8782unformat_l2_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008783{
Dave Barach72d72232016-08-04 10:15:08 -04008784 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008785 u32 next_index = 0;
8786 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008787
Ed Warnickecb9cada2015-12-08 15:45:58 -07008788#define _(n,N) \
Dave Barachb84a3e52016-08-30 17:01:52 -04008789 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
Ed Warnickecb9cada2015-12-08 15:45:58 -07008790 foreach_l2_next;
8791#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008792
Ed Warnickecb9cada2015-12-08 15:45:58 -07008793 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008794 {
8795 next_index = tmp;
8796 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008797 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008798
Ed Warnickecb9cada2015-12-08 15:45:58 -07008799 return 0;
8800
Dave Barach72d72232016-08-04 10:15:08 -04008801out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008802 *miss_next_indexp = next_index;
8803 return 1;
8804}
8805
8806#define foreach_ip_next \
Ed Warnickecb9cada2015-12-08 15:45:58 -07008807_(drop, DROP) \
8808_(local, LOCAL) \
8809_(rewrite, REWRITE)
8810
Dave Barach72d72232016-08-04 10:15:08 -04008811uword
8812unformat_ip_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008813{
Dave Barach72d72232016-08-04 10:15:08 -04008814 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008815 u32 next_index = 0;
8816 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008817
Ed Warnickecb9cada2015-12-08 15:45:58 -07008818#define _(n,N) \
8819 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8820 foreach_ip_next;
8821#undef _
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008822
Ed Warnickecb9cada2015-12-08 15:45:58 -07008823 if (unformat (input, "%d", &tmp))
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008824 {
8825 next_index = tmp;
8826 goto out;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008827 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008828
Ed Warnickecb9cada2015-12-08 15:45:58 -07008829 return 0;
8830
Dave Barach72d72232016-08-04 10:15:08 -04008831out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008832 *miss_next_indexp = next_index;
8833 return 1;
8834}
8835
8836#define foreach_acl_next \
8837_(deny, DENY)
8838
Dave Barach72d72232016-08-04 10:15:08 -04008839uword
8840unformat_acl_next_index (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008841{
Dave Barach72d72232016-08-04 10:15:08 -04008842 u32 *miss_next_indexp = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008843 u32 next_index = 0;
8844 u32 tmp;
8845
8846#define _(n,N) \
8847 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8848 foreach_acl_next;
8849#undef _
8850
8851 if (unformat (input, "permit"))
8852 {
8853 next_index = ~0;
8854 goto out;
8855 }
8856 else if (unformat (input, "%d", &tmp))
8857 {
8858 next_index = tmp;
8859 goto out;
8860 }
8861
8862 return 0;
8863
Dave Barach72d72232016-08-04 10:15:08 -04008864out:
Ed Warnickecb9cada2015-12-08 15:45:58 -07008865 *miss_next_indexp = next_index;
8866 return 1;
8867}
8868
Dave Barach72d72232016-08-04 10:15:08 -04008869uword
8870unformat_policer_precolor (unformat_input_t * input, va_list * args)
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008871{
Dave Barach72d72232016-08-04 10:15:08 -04008872 u32 *r = va_arg (*args, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -07008873
8874 if (unformat (input, "conform-color"))
8875 *r = POLICE_CONFORM;
8876 else if (unformat (input, "exceed-color"))
8877 *r = POLICE_EXCEED;
8878 else
8879 return 0;
8880
8881 return 1;
8882}
8883
Dave Barach72d72232016-08-04 10:15:08 -04008884static int
8885api_classify_add_del_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07008886{
Dave Barach72d72232016-08-04 10:15:08 -04008887 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008888 vl_api_classify_add_del_table_t *mp;
8889
8890 u32 nbuckets = 2;
8891 u32 skip = ~0;
8892 u32 match = ~0;
8893 int is_add = 1;
Juraj Sloboda288e8932016-12-06 21:25:19 +01008894 int del_chain = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008895 u32 table_index = ~0;
8896 u32 next_table_index = ~0;
8897 u32 miss_next_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -04008898 u32 memory_size = 32 << 20;
8899 u8 *mask = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008900 f64 timeout;
Steve Shin25e26dc2016-11-08 10:47:10 -08008901 u32 current_data_flag = 0;
8902 int current_data_offset = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008903
Dave Barach72d72232016-08-04 10:15:08 -04008904 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8905 {
8906 if (unformat (i, "del"))
8907 is_add = 0;
Juraj Sloboda288e8932016-12-06 21:25:19 +01008908 else if (unformat (i, "del-chain"))
8909 {
8910 is_add = 0;
8911 del_chain = 1;
8912 }
Dave Barach72d72232016-08-04 10:15:08 -04008913 else if (unformat (i, "buckets %d", &nbuckets))
8914 ;
8915 else if (unformat (i, "memory_size %d", &memory_size))
8916 ;
8917 else if (unformat (i, "skip %d", &skip))
8918 ;
8919 else if (unformat (i, "match %d", &match))
8920 ;
8921 else if (unformat (i, "table %d", &table_index))
8922 ;
8923 else if (unformat (i, "mask %U", unformat_classify_mask,
8924 &mask, &skip, &match))
8925 ;
8926 else if (unformat (i, "next-table %d", &next_table_index))
8927 ;
8928 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
8929 &miss_next_index))
8930 ;
8931 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8932 &miss_next_index))
8933 ;
8934 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
8935 &miss_next_index))
8936 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08008937 else if (unformat (i, "current-data-flag %d", &current_data_flag))
8938 ;
8939 else if (unformat (i, "current-data-offset %d", &current_data_offset))
8940 ;
Dave Barach72d72232016-08-04 10:15:08 -04008941 else
8942 break;
8943 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008944
Dave Barach72d72232016-08-04 10:15:08 -04008945 if (is_add && mask == 0)
8946 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008947 errmsg ("Mask required\n");
8948 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008949 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008950
Dave Barach72d72232016-08-04 10:15:08 -04008951 if (is_add && skip == ~0)
8952 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008953 errmsg ("skip count required\n");
8954 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008955 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008956
Dave Barach72d72232016-08-04 10:15:08 -04008957 if (is_add && match == ~0)
8958 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008959 errmsg ("match count required\n");
8960 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008961 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08008962
Dave Barach72d72232016-08-04 10:15:08 -04008963 if (!is_add && table_index == ~0)
8964 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07008965 errmsg ("table index required for delete\n");
8966 return -99;
Dave Barach72d72232016-08-04 10:15:08 -04008967 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07008968
Dave Barach72d72232016-08-04 10:15:08 -04008969 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008970
8971 mp->is_add = is_add;
Juraj Sloboda288e8932016-12-06 21:25:19 +01008972 mp->del_chain = del_chain;
Dave Barach72d72232016-08-04 10:15:08 -04008973 mp->table_index = ntohl (table_index);
8974 mp->nbuckets = ntohl (nbuckets);
8975 mp->memory_size = ntohl (memory_size);
8976 mp->skip_n_vectors = ntohl (skip);
8977 mp->match_n_vectors = ntohl (match);
8978 mp->next_table_index = ntohl (next_table_index);
8979 mp->miss_next_index = ntohl (miss_next_index);
Steve Shin25e26dc2016-11-08 10:47:10 -08008980 mp->current_data_flag = ntohl (current_data_flag);
8981 mp->current_data_offset = ntohl (current_data_offset);
Dave Barach72d72232016-08-04 10:15:08 -04008982 clib_memcpy (mp->mask, mask, vec_len (mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -07008983
Dave Barach72d72232016-08-04 10:15:08 -04008984 vec_free (mask);
Ed Warnickecb9cada2015-12-08 15:45:58 -07008985
Dave Barach72d72232016-08-04 10:15:08 -04008986 S;
8987 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -07008988 /* NOTREACHED */
8989}
8990
Dave Barach72d72232016-08-04 10:15:08 -04008991uword
Juraj Sloboda51ffa812016-08-07 23:46:45 -07008992unformat_l4_match (unformat_input_t * input, va_list * args)
8993{
8994 u8 **matchp = va_arg (*args, u8 **);
8995
8996 u8 *proto_header = 0;
8997 int src_port = 0;
8998 int dst_port = 0;
8999
9000 tcpudp_header_t h;
9001
9002 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9003 {
9004 if (unformat (input, "src_port %d", &src_port))
9005 ;
9006 else if (unformat (input, "dst_port %d", &dst_port))
9007 ;
9008 else
9009 return 0;
9010 }
9011
9012 h.src_port = clib_host_to_net_u16 (src_port);
9013 h.dst_port = clib_host_to_net_u16 (dst_port);
9014 vec_validate (proto_header, sizeof (h) - 1);
9015 memcpy (proto_header, &h, sizeof (h));
9016
9017 *matchp = proto_header;
9018
9019 return 1;
9020}
9021
9022uword
Dave Barach72d72232016-08-04 10:15:08 -04009023unformat_ip4_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009024{
Dave Barach72d72232016-08-04 10:15:08 -04009025 u8 **matchp = va_arg (*args, u8 **);
9026 u8 *match = 0;
9027 ip4_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009028 int version = 0;
9029 u32 version_val;
9030 int hdr_length = 0;
9031 u32 hdr_length_val;
9032 int src = 0, dst = 0;
9033 ip4_address_t src_val, dst_val;
9034 int proto = 0;
9035 u32 proto_val;
9036 int tos = 0;
9037 u32 tos_val;
9038 int length = 0;
9039 u32 length_val;
9040 int fragment_id = 0;
9041 u32 fragment_id_val;
9042 int ttl = 0;
9043 int ttl_val;
9044 int checksum = 0;
9045 u32 checksum_val;
9046
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009047 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009048 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009049 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04009050 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009051 else if (unformat (input, "hdr_length %d", &hdr_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009052 hdr_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009053 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04009054 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009055 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04009056 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009057 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04009058 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009059 else if (unformat (input, "tos %d", &tos_val))
Dave Barach72d72232016-08-04 10:15:08 -04009060 tos = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009061 else if (unformat (input, "length %d", &length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009062 length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009063 else if (unformat (input, "fragment_id %d", &fragment_id_val))
Dave Barach72d72232016-08-04 10:15:08 -04009064 fragment_id = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009065 else if (unformat (input, "ttl %d", &ttl_val))
Dave Barach72d72232016-08-04 10:15:08 -04009066 ttl = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009067 else if (unformat (input, "checksum %d", &checksum_val))
Dave Barach72d72232016-08-04 10:15:08 -04009068 checksum = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009069 else
Dave Barach72d72232016-08-04 10:15:08 -04009070 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009071 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009072
Ed Warnickecb9cada2015-12-08 15:45:58 -07009073 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
9074 + ttl + checksum == 0)
9075 return 0;
9076
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009077 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009078 * Aligned because we use the real comparison functions
9079 */
Dave Barach72d72232016-08-04 10:15:08 -04009080 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009081
Ed Warnickecb9cada2015-12-08 15:45:58 -07009082 ip = (ip4_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009083
Ed Warnickecb9cada2015-12-08 15:45:58 -07009084 /* These are realistically matched in practice */
9085 if (src)
9086 ip->src_address.as_u32 = src_val.as_u32;
9087
9088 if (dst)
9089 ip->dst_address.as_u32 = dst_val.as_u32;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009090
Ed Warnickecb9cada2015-12-08 15:45:58 -07009091 if (proto)
9092 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009093
Ed Warnickecb9cada2015-12-08 15:45:58 -07009094
9095 /* These are not, but they're included for completeness */
9096 if (version)
Dave Barach72d72232016-08-04 10:15:08 -04009097 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009098
9099 if (hdr_length)
9100 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009101
Ed Warnickecb9cada2015-12-08 15:45:58 -07009102 if (tos)
9103 ip->tos = tos_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009104
Ed Warnickecb9cada2015-12-08 15:45:58 -07009105 if (length)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009106 ip->length = clib_host_to_net_u16 (length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009107
Ed Warnickecb9cada2015-12-08 15:45:58 -07009108 if (ttl)
9109 ip->ttl = ttl_val;
9110
9111 if (checksum)
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009112 ip->checksum = clib_host_to_net_u16 (checksum_val);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009113
9114 *matchp = match;
9115 return 1;
9116}
9117
Dave Barach72d72232016-08-04 10:15:08 -04009118uword
9119unformat_ip6_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009120{
Dave Barach72d72232016-08-04 10:15:08 -04009121 u8 **matchp = va_arg (*args, u8 **);
9122 u8 *match = 0;
9123 ip6_header_t *ip;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009124 int version = 0;
9125 u32 version_val;
Dave Barach839fe3e2016-08-10 11:35:54 -04009126 u8 traffic_class = 0;
9127 u32 traffic_class_val = 0;
9128 u8 flow_label = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009129 u8 flow_label_val;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009130 int src = 0, dst = 0;
9131 ip6_address_t src_val, dst_val;
9132 int proto = 0;
9133 u32 proto_val;
9134 int payload_length = 0;
9135 u32 payload_length_val;
9136 int hop_limit = 0;
9137 int hop_limit_val;
9138 u32 ip_version_traffic_class_and_flow_label;
9139
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009140 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009141 {
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009142 if (unformat (input, "version %d", &version_val))
Dave Barach72d72232016-08-04 10:15:08 -04009143 version = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009144 else if (unformat (input, "traffic_class %d", &traffic_class_val))
Dave Barach72d72232016-08-04 10:15:08 -04009145 traffic_class = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009146 else if (unformat (input, "flow_label %d", &flow_label_val))
Dave Barach72d72232016-08-04 10:15:08 -04009147 flow_label = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009148 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
Dave Barach72d72232016-08-04 10:15:08 -04009149 src = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009150 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
Dave Barach72d72232016-08-04 10:15:08 -04009151 dst = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009152 else if (unformat (input, "proto %d", &proto_val))
Dave Barach72d72232016-08-04 10:15:08 -04009153 proto = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009154 else if (unformat (input, "payload_length %d", &payload_length_val))
Dave Barach72d72232016-08-04 10:15:08 -04009155 payload_length = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009156 else if (unformat (input, "hop_limit %d", &hop_limit_val))
Dave Barach72d72232016-08-04 10:15:08 -04009157 hop_limit = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009158 else
Dave Barach72d72232016-08-04 10:15:08 -04009159 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009160 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009161
Ed Warnickecb9cada2015-12-08 15:45:58 -07009162 if (version + traffic_class + flow_label + src + dst + proto +
9163 payload_length + hop_limit == 0)
9164 return 0;
9165
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009166 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07009167 * Aligned because we use the real comparison functions
9168 */
Dave Barach72d72232016-08-04 10:15:08 -04009169 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009170
Ed Warnickecb9cada2015-12-08 15:45:58 -07009171 ip = (ip6_header_t *) match;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009172
Ed Warnickecb9cada2015-12-08 15:45:58 -07009173 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009174 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009175
9176 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009177 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009178
Ed Warnickecb9cada2015-12-08 15:45:58 -07009179 if (proto)
9180 ip->protocol = proto_val;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009181
Ed Warnickecb9cada2015-12-08 15:45:58 -07009182 ip_version_traffic_class_and_flow_label = 0;
9183
9184 if (version)
9185 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
9186
9187 if (traffic_class)
Dave Barach72d72232016-08-04 10:15:08 -04009188 ip_version_traffic_class_and_flow_label |=
9189 (traffic_class_val & 0xFF) << 20;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009190
9191 if (flow_label)
9192 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009193
9194 ip->ip_version_traffic_class_and_flow_label =
Ed Warnickecb9cada2015-12-08 15:45:58 -07009195 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
9196
9197 if (payload_length)
9198 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009199
Ed Warnickecb9cada2015-12-08 15:45:58 -07009200 if (hop_limit)
9201 ip->hop_limit = hop_limit_val;
9202
9203 *matchp = match;
9204 return 1;
9205}
9206
Dave Barach72d72232016-08-04 10:15:08 -04009207uword
9208unformat_l3_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009209{
Dave Barach72d72232016-08-04 10:15:08 -04009210 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009211
Dave Barach72d72232016-08-04 10:15:08 -04009212 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9213 {
9214 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
9215 return 1;
9216 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
9217 return 1;
9218 else
9219 break;
9220 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009221 return 0;
9222}
9223
Dave Barach72d72232016-08-04 10:15:08 -04009224uword
9225unformat_vlan_tag (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009226{
Dave Barach72d72232016-08-04 10:15:08 -04009227 u8 *tagp = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009228 u32 tag;
9229
Dave Barach72d72232016-08-04 10:15:08 -04009230 if (unformat (input, "%d", &tag))
Ed Warnickecb9cada2015-12-08 15:45:58 -07009231 {
Dave Barach72d72232016-08-04 10:15:08 -04009232 tagp[0] = (tag >> 8) & 0x0F;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009233 tagp[1] = tag & 0xFF;
9234 return 1;
9235 }
9236
9237 return 0;
9238}
9239
Dave Barach72d72232016-08-04 10:15:08 -04009240uword
9241unformat_l2_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009242{
Dave Barach72d72232016-08-04 10:15:08 -04009243 u8 **matchp = va_arg (*args, u8 **);
9244 u8 *match = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009245 u8 src = 0;
9246 u8 src_val[6];
9247 u8 dst = 0;
9248 u8 dst_val[6];
9249 u8 proto = 0;
9250 u16 proto_val;
9251 u8 tag1 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009252 u8 tag1_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009253 u8 tag2 = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009254 u8 tag2_val[2];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009255 int len = 14;
9256 u8 ignore_tag1 = 0;
9257 u8 ignore_tag2 = 0;
9258 u8 cos1 = 0;
9259 u8 cos2 = 0;
9260 u32 cos1_val = 0;
9261 u32 cos2_val = 0;
9262
Dave Barach72d72232016-08-04 10:15:08 -04009263 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9264 {
9265 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
9266 src = 1;
9267 else
9268 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
9269 dst = 1;
9270 else if (unformat (input, "proto %U",
9271 unformat_ethernet_type_host_byte_order, &proto_val))
9272 proto = 1;
9273 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
9274 tag1 = 1;
9275 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
9276 tag2 = 1;
9277 else if (unformat (input, "ignore-tag1"))
9278 ignore_tag1 = 1;
9279 else if (unformat (input, "ignore-tag2"))
9280 ignore_tag2 = 1;
9281 else if (unformat (input, "cos1 %d", &cos1_val))
9282 cos1 = 1;
9283 else if (unformat (input, "cos2 %d", &cos2_val))
9284 cos2 = 1;
9285 else
9286 break;
9287 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009288 if ((src + dst + proto + tag1 + tag2 +
Dave Barach72d72232016-08-04 10:15:08 -04009289 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009290 return 0;
9291
9292 if (tag1 || ignore_tag1 || cos1)
9293 len = 18;
9294 if (tag2 || ignore_tag2 || cos2)
9295 len = 22;
9296
Dave Barach72d72232016-08-04 10:15:08 -04009297 vec_validate_aligned (match, len - 1, sizeof (u32x4));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009298
9299 if (dst)
Damjan Marionf1213b82016-03-13 02:22:06 +01009300 clib_memcpy (match, dst_val, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009301
9302 if (src)
Damjan Marionf1213b82016-03-13 02:22:06 +01009303 clib_memcpy (match + 6, src_val, 6);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009304
Ed Warnickecb9cada2015-12-08 15:45:58 -07009305 if (tag2)
9306 {
9307 /* inner vlan tag */
9308 match[19] = tag2_val[1];
9309 match[18] = tag2_val[0];
9310 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009311 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009312 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009313 {
9314 match[21] = proto_val & 0xff;
9315 match[20] = proto_val >> 8;
9316 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009317 if (tag1)
Dave Barach72d72232016-08-04 10:15:08 -04009318 {
9319 match[15] = tag1_val[1];
9320 match[14] = tag1_val[0];
9321 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009322 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009323 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009324 *matchp = match;
9325 return 1;
9326 }
9327 if (tag1)
9328 {
Dave Barach72d72232016-08-04 10:15:08 -04009329 match[15] = tag1_val[1];
9330 match[14] = tag1_val[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07009331 if (proto)
Dave Barach72d72232016-08-04 10:15:08 -04009332 {
9333 match[17] = proto_val & 0xff;
9334 match[16] = proto_val >> 8;
9335 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009336 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009337 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009338
9339 *matchp = match;
9340 return 1;
9341 }
9342 if (cos2)
Dave Barach72d72232016-08-04 10:15:08 -04009343 match[18] |= (cos2_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009344 if (cos1)
Dave Barach72d72232016-08-04 10:15:08 -04009345 match[14] |= (cos1_val & 0x7) << 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009346 if (proto)
9347 {
9348 match[13] = proto_val & 0xff;
9349 match[12] = proto_val >> 8;
9350 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009351
Ed Warnickecb9cada2015-12-08 15:45:58 -07009352 *matchp = match;
9353 return 1;
9354}
9355
9356
Dave Barach72d72232016-08-04 10:15:08 -04009357uword
9358unformat_classify_match (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009359{
Dave Barach72d72232016-08-04 10:15:08 -04009360 u8 **matchp = va_arg (*args, u8 **);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009361 u32 skip_n_vectors = va_arg (*args, u32);
9362 u32 match_n_vectors = va_arg (*args, u32);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009363
Dave Barach72d72232016-08-04 10:15:08 -04009364 u8 *match = 0;
9365 u8 *l2 = 0;
9366 u8 *l3 = 0;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009367 u8 *l4 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009368
Dave Barach72d72232016-08-04 10:15:08 -04009369 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9370 {
9371 if (unformat (input, "hex %U", unformat_hex_string, &match))
9372 ;
9373 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
9374 ;
9375 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
9376 ;
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009377 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
9378 ;
Dave Barach72d72232016-08-04 10:15:08 -04009379 else
9380 break;
9381 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009382
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009383 if (l4 && !l3)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009384 {
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009385 vec_free (match);
9386 vec_free (l2);
9387 vec_free (l4);
9388 return 0;
9389 }
9390
9391 if (match || l2 || l3 || l4)
9392 {
9393 if (l2 || l3 || l4)
Dave Barach72d72232016-08-04 10:15:08 -04009394 {
9395 /* "Win a free Ethernet header in every packet" */
9396 if (l2 == 0)
9397 vec_validate_aligned (l2, 13, sizeof (u32x4));
9398 match = l2;
Dave Barach839fe3e2016-08-10 11:35:54 -04009399 if (vec_len (l3))
9400 {
9401 vec_append_aligned (match, l3, sizeof (u32x4));
9402 vec_free (l3);
9403 }
Juraj Sloboda51ffa812016-08-07 23:46:45 -07009404 if (vec_len (l4))
9405 {
9406 vec_append_aligned (match, l4, sizeof (u32x4));
9407 vec_free (l4);
9408 }
Dave Barach72d72232016-08-04 10:15:08 -04009409 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009410
9411 /* Make sure the vector is big enough even if key is all 0's */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009412 vec_validate_aligned
Dave Barach72d72232016-08-04 10:15:08 -04009413 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
9414 sizeof (u32x4));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009415
Dave Barach72d72232016-08-04 10:15:08 -04009416 /* Set size, include skipped vectors */
9417 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009418
9419 *matchp = match;
9420
9421 return 1;
9422 }
9423
9424 return 0;
9425}
9426
Dave Barach72d72232016-08-04 10:15:08 -04009427static int
9428api_classify_add_del_session (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009429{
Dave Barach72d72232016-08-04 10:15:08 -04009430 unformat_input_t *i = vam->input;
9431 vl_api_classify_add_del_session_t *mp;
9432 int is_add = 1;
9433 u32 table_index = ~0;
9434 u32 hit_next_index = ~0;
9435 u32 opaque_index = ~0;
9436 u8 *match = 0;
9437 i32 advance = 0;
9438 f64 timeout;
9439 u32 skip_n_vectors = 0;
9440 u32 match_n_vectors = 0;
Steve Shin25e26dc2016-11-08 10:47:10 -08009441 u32 action = 0;
9442 u32 metadata = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009443
Dave Barach72d72232016-08-04 10:15:08 -04009444 /*
9445 * Warning: you have to supply skip_n and match_n
9446 * because the API client cant simply look at the classify
9447 * table object.
9448 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009449
Dave Barach72d72232016-08-04 10:15:08 -04009450 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9451 {
9452 if (unformat (i, "del"))
9453 is_add = 0;
9454 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
9455 &hit_next_index))
9456 ;
9457 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
9458 &hit_next_index))
9459 ;
9460 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
9461 &hit_next_index))
9462 ;
9463 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
9464 ;
9465 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
9466 ;
9467 else if (unformat (i, "opaque-index %d", &opaque_index))
9468 ;
9469 else if (unformat (i, "skip_n %d", &skip_n_vectors))
9470 ;
9471 else if (unformat (i, "match_n %d", &match_n_vectors))
9472 ;
9473 else if (unformat (i, "match %U", unformat_classify_match,
9474 &match, skip_n_vectors, match_n_vectors))
9475 ;
9476 else if (unformat (i, "advance %d", &advance))
9477 ;
9478 else if (unformat (i, "table-index %d", &table_index))
9479 ;
Steve Shin25e26dc2016-11-08 10:47:10 -08009480 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
9481 action = 1;
9482 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
9483 action = 2;
9484 else if (unformat (i, "action %d", &action))
9485 ;
9486 else if (unformat (i, "metadata %d", &metadata))
9487 ;
Dave Barach72d72232016-08-04 10:15:08 -04009488 else
9489 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009490 }
9491
Dave Barach72d72232016-08-04 10:15:08 -04009492 if (table_index == ~0)
9493 {
9494 errmsg ("Table index required\n");
9495 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009496 }
9497
Dave Barach72d72232016-08-04 10:15:08 -04009498 if (is_add && match == 0)
9499 {
9500 errmsg ("Match value required\n");
9501 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009502 }
9503
Dave Barach72d72232016-08-04 10:15:08 -04009504 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session, vec_len (match));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009505
Dave Barach72d72232016-08-04 10:15:08 -04009506 mp->is_add = is_add;
9507 mp->table_index = ntohl (table_index);
9508 mp->hit_next_index = ntohl (hit_next_index);
9509 mp->opaque_index = ntohl (opaque_index);
9510 mp->advance = ntohl (advance);
Steve Shin25e26dc2016-11-08 10:47:10 -08009511 mp->action = action;
9512 mp->metadata = ntohl (metadata);
Dave Barach72d72232016-08-04 10:15:08 -04009513 clib_memcpy (mp->match, match, vec_len (match));
9514 vec_free (match);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009515
Dave Barach72d72232016-08-04 10:15:08 -04009516 S;
9517 W;
9518 /* NOTREACHED */
Ed Warnickecb9cada2015-12-08 15:45:58 -07009519}
9520
Dave Barach72d72232016-08-04 10:15:08 -04009521static int
9522api_classify_set_interface_ip_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009523{
Dave Barach72d72232016-08-04 10:15:08 -04009524 unformat_input_t *i = vam->input;
9525 vl_api_classify_set_interface_ip_table_t *mp;
9526 f64 timeout;
9527 u32 sw_if_index;
9528 int sw_if_index_set;
9529 u32 table_index = ~0;
9530 u8 is_ipv6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009531
Dave Barach72d72232016-08-04 10:15:08 -04009532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9533 {
9534 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9535 sw_if_index_set = 1;
9536 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9537 sw_if_index_set = 1;
9538 else if (unformat (i, "table %d", &table_index))
9539 ;
9540 else
9541 {
9542 clib_warning ("parse error '%U'", format_unformat_error, i);
9543 return -99;
9544 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009545 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009546
Dave Barach72d72232016-08-04 10:15:08 -04009547 if (sw_if_index_set == 0)
9548 {
9549 errmsg ("missing interface name or sw_if_index\n");
9550 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009551 }
9552
9553
Dave Barach72d72232016-08-04 10:15:08 -04009554 M (CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009555
Dave Barach72d72232016-08-04 10:15:08 -04009556 mp->sw_if_index = ntohl (sw_if_index);
9557 mp->table_index = ntohl (table_index);
9558 mp->is_ipv6 = is_ipv6;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009559
Dave Barach72d72232016-08-04 10:15:08 -04009560 S;
9561 W;
9562 /* NOTREACHED */
9563 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009564}
9565
Dave Barach72d72232016-08-04 10:15:08 -04009566static int
9567api_classify_set_interface_l2_tables (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009568{
Dave Barach72d72232016-08-04 10:15:08 -04009569 unformat_input_t *i = vam->input;
9570 vl_api_classify_set_interface_l2_tables_t *mp;
9571 f64 timeout;
9572 u32 sw_if_index;
9573 int sw_if_index_set;
9574 u32 ip4_table_index = ~0;
9575 u32 ip6_table_index = ~0;
9576 u32 other_table_index = ~0;
Dave Barachb84a3e52016-08-30 17:01:52 -04009577 u32 is_input = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009578
Dave Barach72d72232016-08-04 10:15:08 -04009579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9580 {
9581 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9582 sw_if_index_set = 1;
9583 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9584 sw_if_index_set = 1;
9585 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9586 ;
9587 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9588 ;
9589 else if (unformat (i, "other-table %d", &other_table_index))
9590 ;
Dave Barachb84a3e52016-08-30 17:01:52 -04009591 else if (unformat (i, "is-input %d", &is_input))
9592 ;
Dave Barach72d72232016-08-04 10:15:08 -04009593 else
9594 {
9595 clib_warning ("parse error '%U'", format_unformat_error, i);
9596 return -99;
9597 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07009598 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009599
Dave Barach72d72232016-08-04 10:15:08 -04009600 if (sw_if_index_set == 0)
9601 {
9602 errmsg ("missing interface name or sw_if_index\n");
9603 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009604 }
9605
9606
Dave Barach72d72232016-08-04 10:15:08 -04009607 M (CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009608
Dave Barach72d72232016-08-04 10:15:08 -04009609 mp->sw_if_index = ntohl (sw_if_index);
9610 mp->ip4_table_index = ntohl (ip4_table_index);
9611 mp->ip6_table_index = ntohl (ip6_table_index);
9612 mp->other_table_index = ntohl (other_table_index);
Dave Barachb84a3e52016-08-30 17:01:52 -04009613 mp->is_input = (u8) is_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009614
Dave Barach72d72232016-08-04 10:15:08 -04009615 S;
9616 W;
9617 /* NOTREACHED */
9618 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009619}
9620
Dave Barach72d72232016-08-04 10:15:08 -04009621static int
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009622api_set_ipfix_exporter (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009623{
Dave Barach72d72232016-08-04 10:15:08 -04009624 unformat_input_t *i = vam->input;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009625 vl_api_set_ipfix_exporter_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -04009626 ip4_address_t collector_address;
9627 u8 collector_address_set = 0;
9628 u32 collector_port = ~0;
9629 ip4_address_t src_address;
9630 u8 src_address_set = 0;
9631 u32 vrf_id = ~0;
9632 u32 path_mtu = ~0;
9633 u32 template_interval = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009634 u8 udp_checksum = 0;
Dave Barach72d72232016-08-04 10:15:08 -04009635 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009636
Dave Barach72d72232016-08-04 10:15:08 -04009637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9638 {
9639 if (unformat (i, "collector_address %U", unformat_ip4_address,
9640 &collector_address))
9641 collector_address_set = 1;
9642 else if (unformat (i, "collector_port %d", &collector_port))
9643 ;
9644 else if (unformat (i, "src_address %U", unformat_ip4_address,
9645 &src_address))
9646 src_address_set = 1;
9647 else if (unformat (i, "vrf_id %d", &vrf_id))
9648 ;
9649 else if (unformat (i, "path_mtu %d", &path_mtu))
9650 ;
9651 else if (unformat (i, "template_interval %d", &template_interval))
9652 ;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009653 else if (unformat (i, "udp_checksum"))
9654 udp_checksum = 1;
Dave Barach72d72232016-08-04 10:15:08 -04009655 else
9656 break;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009657 }
9658
Dave Barach72d72232016-08-04 10:15:08 -04009659 if (collector_address_set == 0)
9660 {
9661 errmsg ("collector_address required\n");
9662 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009663 }
9664
Dave Barach72d72232016-08-04 10:15:08 -04009665 if (src_address_set == 0)
9666 {
9667 errmsg ("src_address required\n");
9668 return -99;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009669 }
9670
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009671 M (SET_IPFIX_EXPORTER, set_ipfix_exporter);
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009672
Dave Barach72d72232016-08-04 10:15:08 -04009673 memcpy (mp->collector_address, collector_address.data,
9674 sizeof (collector_address.data));
9675 mp->collector_port = htons ((u16) collector_port);
9676 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
9677 mp->vrf_id = htonl (vrf_id);
9678 mp->path_mtu = htonl (path_mtu);
9679 mp->template_interval = htonl (template_interval);
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009680 mp->udp_checksum = udp_checksum;
9681
9682 S;
9683 W;
9684 /* NOTREACHED */
9685}
9686
9687static int
9688api_set_ipfix_classify_stream (vat_main_t * vam)
9689{
9690 unformat_input_t *i = vam->input;
9691 vl_api_set_ipfix_classify_stream_t *mp;
9692 u32 domain_id = 0;
9693 u32 src_port = UDP_DST_PORT_ipfix;
9694 f64 timeout;
9695
9696 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9697 {
9698 if (unformat (i, "domain %d", &domain_id))
9699 ;
9700 else if (unformat (i, "src_port %d", &src_port))
9701 ;
9702 else
9703 {
9704 errmsg ("unknown input `%U'", format_unformat_error, i);
9705 return -99;
9706 }
9707 }
9708
9709 M (SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream);
9710
9711 mp->domain_id = htonl (domain_id);
9712 mp->src_port = htons ((u16) src_port);
9713
9714 S;
9715 W;
9716 /* NOTREACHED */
9717}
9718
9719static int
9720api_ipfix_classify_table_add_del (vat_main_t * vam)
9721{
9722 unformat_input_t *i = vam->input;
9723 vl_api_ipfix_classify_table_add_del_t *mp;
9724 int is_add = -1;
Juraj Sloboda24648ad2016-09-06 04:43:52 -07009725 u32 classify_table_index = ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -07009726 u8 ip_version = 0;
9727 u8 transport_protocol = 255;
9728 f64 timeout;
9729
9730 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9731 {
9732 if (unformat (i, "add"))
9733 is_add = 1;
9734 else if (unformat (i, "del"))
9735 is_add = 0;
9736 else if (unformat (i, "table %d", &classify_table_index))
9737 ;
9738 else if (unformat (i, "ip4"))
9739 ip_version = 4;
9740 else if (unformat (i, "ip6"))
9741 ip_version = 6;
9742 else if (unformat (i, "tcp"))
9743 transport_protocol = 6;
9744 else if (unformat (i, "udp"))
9745 transport_protocol = 17;
9746 else
9747 {
9748 errmsg ("unknown input `%U'", format_unformat_error, i);
9749 return -99;
9750 }
9751 }
9752
9753 if (is_add == -1)
9754 {
9755 errmsg ("expecting: add|del");
9756 return -99;
9757 }
9758 if (classify_table_index == ~0)
9759 {
9760 errmsg ("classifier table not specified");
9761 return -99;
9762 }
9763 if (ip_version == 0)
9764 {
9765 errmsg ("IP version not specified");
9766 return -99;
9767 }
9768
9769 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del);
9770
9771 mp->is_add = is_add;
9772 mp->table_id = htonl (classify_table_index);
9773 mp->ip_version = ip_version;
9774 mp->transport_protocol = transport_protocol;
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009775
Dave Barach72d72232016-08-04 10:15:08 -04009776 S;
9777 W;
9778 /* NOTREACHED */
Juraj Slobodaac645ad2016-07-07 00:18:57 -07009779}
9780
Dave Barach72d72232016-08-04 10:15:08 -04009781static int
9782api_get_node_index (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009783{
Dave Barach72d72232016-08-04 10:15:08 -04009784 unformat_input_t *i = vam->input;
9785 vl_api_get_node_index_t *mp;
9786 f64 timeout;
9787 u8 *name = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009788
Dave Barach72d72232016-08-04 10:15:08 -04009789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9790 {
9791 if (unformat (i, "node %s", &name))
9792 ;
9793 else
9794 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009795 }
Dave Barach72d72232016-08-04 10:15:08 -04009796 if (name == 0)
9797 {
9798 errmsg ("node name required\n");
9799 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009800 }
Dave Barach72d72232016-08-04 10:15:08 -04009801 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9802 {
9803 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9804 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009805 }
9806
Dave Barach72d72232016-08-04 10:15:08 -04009807 M (GET_NODE_INDEX, get_node_index);
9808 clib_memcpy (mp->node_name, name, vec_len (name));
9809 vec_free (name);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009810
Dave Barach72d72232016-08-04 10:15:08 -04009811 S;
9812 W;
9813 /* NOTREACHED */
9814 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009815}
9816
Dave Barach72d72232016-08-04 10:15:08 -04009817static int
9818api_get_next_index (vat_main_t * vam)
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009819{
Dave Barach72d72232016-08-04 10:15:08 -04009820 unformat_input_t *i = vam->input;
9821 vl_api_get_next_index_t *mp;
9822 f64 timeout;
9823 u8 *node_name = 0, *next_node_name = 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009824
Dave Barach72d72232016-08-04 10:15:08 -04009825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9826 {
9827 if (unformat (i, "node-name %s", &node_name))
9828 ;
9829 else if (unformat (i, "next-node-name %s", &next_node_name))
9830 break;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009831 }
9832
Dave Barach72d72232016-08-04 10:15:08 -04009833 if (node_name == 0)
9834 {
9835 errmsg ("node name required\n");
9836 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009837 }
Dave Barach72d72232016-08-04 10:15:08 -04009838 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9839 {
9840 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9841 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009842 }
9843
Dave Barach72d72232016-08-04 10:15:08 -04009844 if (next_node_name == 0)
9845 {
9846 errmsg ("next node name required\n");
9847 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009848 }
Dave Barach72d72232016-08-04 10:15:08 -04009849 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9850 {
9851 errmsg ("next node name too long, max %d\n", ARRAY_LEN (mp->next_name));
9852 return -99;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009853 }
9854
Dave Barach72d72232016-08-04 10:15:08 -04009855 M (GET_NEXT_INDEX, get_next_index);
9856 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9857 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9858 vec_free (node_name);
9859 vec_free (next_node_name);
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009860
Dave Barach72d72232016-08-04 10:15:08 -04009861 S;
9862 W;
9863 /* NOTREACHED */
9864 return 0;
Keith Burns (alagalah)c61080e2016-07-19 14:47:43 -07009865}
9866
Dave Barach72d72232016-08-04 10:15:08 -04009867static int
9868api_add_node_next (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009869{
Dave Barach72d72232016-08-04 10:15:08 -04009870 unformat_input_t *i = vam->input;
9871 vl_api_add_node_next_t *mp;
9872 f64 timeout;
9873 u8 *name = 0;
9874 u8 *next = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009875
Dave Barach72d72232016-08-04 10:15:08 -04009876 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9877 {
9878 if (unformat (i, "node %s", &name))
9879 ;
9880 else if (unformat (i, "next %s", &next))
9881 ;
9882 else
9883 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009884 }
Dave Barach72d72232016-08-04 10:15:08 -04009885 if (name == 0)
9886 {
9887 errmsg ("node name required\n");
9888 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009889 }
Dave Barach72d72232016-08-04 10:15:08 -04009890 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9891 {
9892 errmsg ("node name too long, max %d\n", ARRAY_LEN (mp->node_name));
9893 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009894 }
Dave Barach72d72232016-08-04 10:15:08 -04009895 if (next == 0)
9896 {
9897 errmsg ("next node required\n");
9898 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009899 }
Dave Barach72d72232016-08-04 10:15:08 -04009900 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9901 {
9902 errmsg ("next name too long, max %d\n", ARRAY_LEN (mp->next_name));
9903 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009904 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009905
Dave Barach72d72232016-08-04 10:15:08 -04009906 M (ADD_NODE_NEXT, add_node_next);
9907 clib_memcpy (mp->node_name, name, vec_len (name));
9908 clib_memcpy (mp->next_name, next, vec_len (next));
9909 vec_free (name);
9910 vec_free (next);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009911
Dave Barach72d72232016-08-04 10:15:08 -04009912 S;
9913 W;
9914 /* NOTREACHED */
9915 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009916}
9917
Dave Barach72d72232016-08-04 10:15:08 -04009918static int
9919api_l2tpv3_create_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009920{
Dave Barach72d72232016-08-04 10:15:08 -04009921 unformat_input_t *i = vam->input;
9922 ip6_address_t client_address, our_address;
9923 int client_address_set = 0;
9924 int our_address_set = 0;
9925 u32 local_session_id = 0;
9926 u32 remote_session_id = 0;
9927 u64 local_cookie = 0;
9928 u64 remote_cookie = 0;
9929 u8 l2_sublayer_present = 0;
9930 vl_api_l2tpv3_create_tunnel_t *mp;
9931 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009932
Dave Barach72d72232016-08-04 10:15:08 -04009933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9934 {
9935 if (unformat (i, "client_address %U", unformat_ip6_address,
9936 &client_address))
9937 client_address_set = 1;
9938 else if (unformat (i, "our_address %U", unformat_ip6_address,
9939 &our_address))
9940 our_address_set = 1;
9941 else if (unformat (i, "local_session_id %d", &local_session_id))
9942 ;
9943 else if (unformat (i, "remote_session_id %d", &remote_session_id))
9944 ;
9945 else if (unformat (i, "local_cookie %lld", &local_cookie))
9946 ;
9947 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
9948 ;
9949 else if (unformat (i, "l2-sublayer-present"))
9950 l2_sublayer_present = 1;
9951 else
9952 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009953 }
9954
Dave Barach72d72232016-08-04 10:15:08 -04009955 if (client_address_set == 0)
9956 {
9957 errmsg ("client_address required\n");
9958 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009959 }
9960
Dave Barach72d72232016-08-04 10:15:08 -04009961 if (our_address_set == 0)
9962 {
9963 errmsg ("our_address required\n");
9964 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009965 }
9966
Dave Barach72d72232016-08-04 10:15:08 -04009967 M (L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07009968
Dave Barach72d72232016-08-04 10:15:08 -04009969 clib_memcpy (mp->client_address, client_address.as_u8,
9970 sizeof (mp->client_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07009971
Dave Barach72d72232016-08-04 10:15:08 -04009972 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
Hongjun Ni11bfc2f2016-07-22 18:19:19 +08009973
Dave Barach72d72232016-08-04 10:15:08 -04009974 mp->local_session_id = ntohl (local_session_id);
9975 mp->remote_session_id = ntohl (remote_session_id);
9976 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
9977 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
9978 mp->l2_sublayer_present = l2_sublayer_present;
9979 mp->is_ipv6 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009980
Dave Barach72d72232016-08-04 10:15:08 -04009981 S;
9982 W;
9983 /* NOTREACHED */
9984 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009985}
9986
Dave Barach72d72232016-08-04 10:15:08 -04009987static int
9988api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -07009989{
Dave Barach72d72232016-08-04 10:15:08 -04009990 unformat_input_t *i = vam->input;
9991 u32 sw_if_index;
9992 u8 sw_if_index_set = 0;
9993 u64 new_local_cookie = 0;
9994 u64 new_remote_cookie = 0;
9995 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
9996 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -07009997
Dave Barach72d72232016-08-04 10:15:08 -04009998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9999 {
10000 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10001 sw_if_index_set = 1;
10002 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10003 sw_if_index_set = 1;
10004 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
10005 ;
10006 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
10007 ;
10008 else
10009 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010010 }
10011
Dave Barach72d72232016-08-04 10:15:08 -040010012 if (sw_if_index_set == 0)
10013 {
10014 errmsg ("missing interface name or sw_if_index\n");
10015 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010016 }
10017
Dave Barach72d72232016-08-04 10:15:08 -040010018 M (L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010019
Dave Barach72d72232016-08-04 10:15:08 -040010020 mp->sw_if_index = ntohl (sw_if_index);
10021 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
10022 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010023
Dave Barach72d72232016-08-04 10:15:08 -040010024 S;
10025 W;
10026 /* NOTREACHED */
10027 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010028}
10029
Dave Barach72d72232016-08-04 10:15:08 -040010030static int
10031api_l2tpv3_interface_enable_disable (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010032{
Dave Barach72d72232016-08-04 10:15:08 -040010033 unformat_input_t *i = vam->input;
10034 vl_api_l2tpv3_interface_enable_disable_t *mp;
10035 f64 timeout;
10036 u32 sw_if_index;
10037 u8 sw_if_index_set = 0;
10038 u8 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010039
Dave Barach72d72232016-08-04 10:15:08 -040010040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10041 {
10042 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10043 sw_if_index_set = 1;
10044 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10045 sw_if_index_set = 1;
10046 else if (unformat (i, "enable"))
10047 enable_disable = 1;
10048 else if (unformat (i, "disable"))
10049 enable_disable = 0;
10050 else
10051 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010052 }
10053
Dave Barach72d72232016-08-04 10:15:08 -040010054 if (sw_if_index_set == 0)
10055 {
10056 errmsg ("missing interface name or sw_if_index\n");
10057 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010058 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010059
Dave Barach72d72232016-08-04 10:15:08 -040010060 M (L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010061
Dave Barach72d72232016-08-04 10:15:08 -040010062 mp->sw_if_index = ntohl (sw_if_index);
10063 mp->enable_disable = enable_disable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010064
Dave Barach72d72232016-08-04 10:15:08 -040010065 S;
10066 W;
10067 /* NOTREACHED */
10068 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010069}
10070
Dave Barach72d72232016-08-04 10:15:08 -040010071static int
10072api_l2tpv3_set_lookup_key (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010073{
Dave Barach72d72232016-08-04 10:15:08 -040010074 unformat_input_t *i = vam->input;
10075 vl_api_l2tpv3_set_lookup_key_t *mp;
10076 f64 timeout;
10077 u8 key = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010078
Dave Barach72d72232016-08-04 10:15:08 -040010079 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10080 {
10081 if (unformat (i, "lookup_v6_src"))
10082 key = L2T_LOOKUP_SRC_ADDRESS;
10083 else if (unformat (i, "lookup_v6_dst"))
10084 key = L2T_LOOKUP_DST_ADDRESS;
10085 else if (unformat (i, "lookup_session_id"))
10086 key = L2T_LOOKUP_SESSION_ID;
10087 else
10088 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010089 }
10090
Dave Barach72d72232016-08-04 10:15:08 -040010091 if (key == (u8) ~ 0)
10092 {
10093 errmsg ("l2tp session lookup key unset\n");
10094 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010095 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010096
Dave Barach72d72232016-08-04 10:15:08 -040010097 M (L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010098
Dave Barach72d72232016-08-04 10:15:08 -040010099 mp->key = key;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010100
Dave Barach72d72232016-08-04 10:15:08 -040010101 S;
10102 W;
10103 /* NOTREACHED */
10104 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010105}
10106
10107static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010108 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010109{
Dave Barach72d72232016-08-04 10:15:08 -040010110 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010111
Dave Barach72d72232016-08-04 10:15:08 -040010112 fformat (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
10113 format_ip6_address, mp->our_address,
10114 format_ip6_address, mp->client_address,
10115 clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010116
Dave Barach72d72232016-08-04 10:15:08 -040010117 fformat (vam->ofp,
10118 " local cookies %016llx %016llx remote cookie %016llx\n",
10119 clib_net_to_host_u64 (mp->local_cookie[0]),
10120 clib_net_to_host_u64 (mp->local_cookie[1]),
10121 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010122
Dave Barach72d72232016-08-04 10:15:08 -040010123 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
10124 clib_net_to_host_u32 (mp->local_session_id),
10125 clib_net_to_host_u32 (mp->remote_session_id));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010126
Dave Barach72d72232016-08-04 10:15:08 -040010127 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
10128 mp->l2_sublayer_present ? "preset" : "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010129
10130}
10131
10132static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010133 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010134{
Dave Barach72d72232016-08-04 10:15:08 -040010135 vat_main_t *vam = &vat_main;
10136 vat_json_node_t *node = NULL;
10137 struct in6_addr addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010138
Dave Barach72d72232016-08-04 10:15:08 -040010139 if (VAT_JSON_ARRAY != vam->json_tree.type)
10140 {
10141 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10142 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010143 }
Dave Barach72d72232016-08-04 10:15:08 -040010144 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010145
Dave Barach72d72232016-08-04 10:15:08 -040010146 vat_json_init_object (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010147
Dave Barach72d72232016-08-04 10:15:08 -040010148 clib_memcpy (&addr, mp->our_address, sizeof (addr));
10149 vat_json_object_add_ip6 (node, "our_address", addr);
10150 clib_memcpy (&addr, mp->client_address, sizeof (addr));
10151 vat_json_object_add_ip6 (node, "client_address", addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010152
Dave Barach72d72232016-08-04 10:15:08 -040010153 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
10154 vat_json_init_array (lc);
10155 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
10156 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
10157 vat_json_object_add_uint (node, "remote_cookie",
10158 clib_net_to_host_u64 (mp->remote_cookie));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010159
Dave Barach72d72232016-08-04 10:15:08 -040010160 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
10161 vat_json_object_add_uint (node, "local_session_id",
10162 clib_net_to_host_u32 (mp->local_session_id));
10163 vat_json_object_add_uint (node, "remote_session_id",
10164 clib_net_to_host_u32 (mp->remote_session_id));
10165 vat_json_object_add_string_copy (node, "l2_sublayer",
10166 mp->l2_sublayer_present ? (u8 *) "present"
10167 : (u8 *) "absent");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010168}
10169
Dave Barach72d72232016-08-04 10:15:08 -040010170static int
10171api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010172{
Dave Barach72d72232016-08-04 10:15:08 -040010173 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
10174 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010175
Dave Barach72d72232016-08-04 10:15:08 -040010176 /* Get list of l2tpv3-tunnel interfaces */
10177 M (SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
10178 S;
10179
10180 /* Use a control ping for synchronization */
10181 {
10182 vl_api_control_ping_t *mp;
10183 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010184 S;
Dave Barach72d72232016-08-04 10:15:08 -040010185 }
10186 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010187}
10188
10189
10190static void vl_api_sw_interface_tap_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010191 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010192{
Dave Barach72d72232016-08-04 10:15:08 -040010193 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010194
Dave Barach72d72232016-08-04 10:15:08 -040010195 fformat (vam->ofp, "%-16s %d\n",
10196 mp->dev_name, clib_net_to_host_u32 (mp->sw_if_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010197}
10198
10199static void vl_api_sw_interface_tap_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010200 (vl_api_sw_interface_tap_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010201{
Dave Barach72d72232016-08-04 10:15:08 -040010202 vat_main_t *vam = &vat_main;
10203 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010204
Dave Barach72d72232016-08-04 10:15:08 -040010205 if (VAT_JSON_ARRAY != vam->json_tree.type)
10206 {
10207 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10208 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010209 }
Dave Barach72d72232016-08-04 10:15:08 -040010210 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010211
Dave Barach72d72232016-08-04 10:15:08 -040010212 vat_json_init_object (node);
10213 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10214 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010215}
10216
Dave Barach72d72232016-08-04 10:15:08 -040010217static int
10218api_sw_interface_tap_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010219{
Dave Barach72d72232016-08-04 10:15:08 -040010220 vl_api_sw_interface_tap_dump_t *mp;
10221 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010222
Dave Barach72d72232016-08-04 10:15:08 -040010223 fformat (vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
10224 /* Get list of tap interfaces */
10225 M (SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
10226 S;
10227
10228 /* Use a control ping for synchronization */
10229 {
10230 vl_api_control_ping_t *mp;
10231 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010232 S;
Dave Barach72d72232016-08-04 10:15:08 -040010233 }
10234 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010235}
10236
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010237static uword unformat_vxlan_decap_next
Dave Barach72d72232016-08-04 10:15:08 -040010238 (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010239{
Dave Barach72d72232016-08-04 10:15:08 -040010240 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010241 u32 tmp;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010242
John Loc42912d2016-11-07 18:30:47 -050010243 if (unformat (input, "l2"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070010244 *result = VXLAN_INPUT_NEXT_L2_INPUT;
10245 else if (unformat (input, "%d", &tmp))
10246 *result = tmp;
10247 else
10248 return 0;
10249 return 1;
10250}
10251
Dave Barach72d72232016-08-04 10:15:08 -040010252static int
10253api_vxlan_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010254{
Dave Barach72d72232016-08-04 10:15:08 -040010255 unformat_input_t *line_input = vam->input;
10256 vl_api_vxlan_add_del_tunnel_t *mp;
10257 f64 timeout;
Eyal Baric5b13602016-11-24 19:42:43 +020010258 ip46_address_t src, dst;
Dave Barach72d72232016-08-04 10:15:08 -040010259 u8 is_add = 1;
10260 u8 ipv4_set = 0, ipv6_set = 0;
10261 u8 src_set = 0;
10262 u8 dst_set = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010263 u8 grp_set = 0;
10264 u32 mcast_sw_if_index = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040010265 u32 encap_vrf_id = 0;
10266 u32 decap_next_index = ~0;
10267 u32 vni = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010268
Eyal Baric5b13602016-11-24 19:42:43 +020010269 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
10270 memset (&src, 0, sizeof src);
10271 memset (&dst, 0, sizeof dst);
10272
Dave Barach72d72232016-08-04 10:15:08 -040010273 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10274 {
10275 if (unformat (line_input, "del"))
10276 is_add = 0;
Eyal Baric5b13602016-11-24 19:42:43 +020010277 else
10278 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010279 {
10280 ipv4_set = 1;
10281 src_set = 1;
10282 }
Eyal Baric5b13602016-11-24 19:42:43 +020010283 else
10284 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
Dave Barach72d72232016-08-04 10:15:08 -040010285 {
10286 ipv4_set = 1;
10287 dst_set = 1;
10288 }
Eyal Baric5b13602016-11-24 19:42:43 +020010289 else
10290 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010291 {
10292 ipv6_set = 1;
10293 src_set = 1;
10294 }
Eyal Baric5b13602016-11-24 19:42:43 +020010295 else
10296 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
Dave Barach72d72232016-08-04 10:15:08 -040010297 {
10298 ipv6_set = 1;
10299 dst_set = 1;
10300 }
Eyal Baric5b13602016-11-24 19:42:43 +020010301 else if (unformat (line_input, "group %U %U",
10302 unformat_ip4_address, &dst.ip4,
10303 unformat_sw_if_index, vam, &mcast_sw_if_index))
10304 {
10305 grp_set = dst_set = 1;
10306 ipv4_set = 1;
10307 }
10308 else if (unformat (line_input, "group %U",
10309 unformat_ip4_address, &dst.ip4))
10310 {
10311 grp_set = dst_set = 1;
10312 ipv4_set = 1;
10313 }
10314 else if (unformat (line_input, "group %U %U",
10315 unformat_ip6_address, &dst.ip6,
10316 unformat_sw_if_index, vam, &mcast_sw_if_index))
10317 {
10318 grp_set = dst_set = 1;
10319 ipv6_set = 1;
10320 }
10321 else if (unformat (line_input, "group %U",
10322 unformat_ip6_address, &dst.ip6))
10323 {
10324 grp_set = dst_set = 1;
10325 ipv6_set = 1;
10326 }
10327 else
10328 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10329 ;
Dave Barach72d72232016-08-04 10:15:08 -040010330 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10331 ;
10332 else if (unformat (line_input, "decap-next %U",
10333 unformat_vxlan_decap_next, &decap_next_index))
10334 ;
10335 else if (unformat (line_input, "vni %d", &vni))
10336 ;
10337 else
10338 {
10339 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10340 return -99;
10341 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010342 }
10343
Dave Barach72d72232016-08-04 10:15:08 -040010344 if (src_set == 0)
10345 {
10346 errmsg ("tunnel src address not specified\n");
10347 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010348 }
Dave Barach72d72232016-08-04 10:15:08 -040010349 if (dst_set == 0)
10350 {
10351 errmsg ("tunnel dst address not specified\n");
10352 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010353 }
10354
Eyal Baric5b13602016-11-24 19:42:43 +020010355 if (grp_set && !ip46_address_is_multicast (&dst))
10356 {
10357 errmsg ("tunnel group address not multicast\n");
10358 return -99;
10359 }
10360 if (grp_set && mcast_sw_if_index == ~0)
10361 {
10362 errmsg ("tunnel nonexistent multicast device\n");
10363 return -99;
10364 }
10365
10366
Dave Barach72d72232016-08-04 10:15:08 -040010367 if (ipv4_set && ipv6_set)
10368 {
10369 errmsg ("both IPv4 and IPv6 addresses specified");
10370 return -99;
Chris Luke99cb3352016-04-26 10:49:53 -040010371 }
10372
Dave Barach72d72232016-08-04 10:15:08 -040010373 if ((vni == 0) || (vni >> 24))
10374 {
10375 errmsg ("vni not specified or out of range\n");
10376 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010377 }
10378
Dave Barach72d72232016-08-04 10:15:08 -040010379 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
Chris Luke99cb3352016-04-26 10:49:53 -040010380
Dave Barach72d72232016-08-04 10:15:08 -040010381 if (ipv6_set)
10382 {
Eyal Baric5b13602016-11-24 19:42:43 +020010383 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
10384 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
Chris Luke99cb3352016-04-26 10:49:53 -040010385 }
Dave Barach72d72232016-08-04 10:15:08 -040010386 else
10387 {
Eyal Baric5b13602016-11-24 19:42:43 +020010388 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
10389 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010390 }
10391 mp->encap_vrf_id = ntohl (encap_vrf_id);
10392 mp->decap_next_index = ntohl (decap_next_index);
Eyal Baric5b13602016-11-24 19:42:43 +020010393 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Dave Barach72d72232016-08-04 10:15:08 -040010394 mp->vni = ntohl (vni);
10395 mp->is_add = is_add;
10396 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010397
Dave Barach72d72232016-08-04 10:15:08 -040010398 S;
10399 W;
10400 /* NOTREACHED */
10401 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010402}
10403
Dave Wallace60231f32015-12-17 21:04:30 -050010404static void vl_api_vxlan_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010405 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010406{
Dave Barach72d72232016-08-04 10:15:08 -040010407 vat_main_t *vam = &vat_main;
Eyal Baric5b13602016-11-24 19:42:43 +020010408 ip46_address_t src, dst;
Dave Wallace60231f32015-12-17 21:04:30 -050010409
Eyal Baric5b13602016-11-24 19:42:43 +020010410 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src);
10411 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst);
10412
10413 fformat (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010414 ntohl (mp->sw_if_index),
Eyal Baric5b13602016-11-24 19:42:43 +020010415 format_ip46_address, &src, IP46_TYPE_ANY,
10416 format_ip46_address, &dst, IP46_TYPE_ANY,
Dave Barach72d72232016-08-04 10:15:08 -040010417 ntohl (mp->encap_vrf_id),
Eyal Baric5b13602016-11-24 19:42:43 +020010418 ntohl (mp->decap_next_index), ntohl (mp->vni),
10419 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010420}
10421
10422static void vl_api_vxlan_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010423 (vl_api_vxlan_tunnel_details_t * mp)
Dave Wallace60231f32015-12-17 21:04:30 -050010424{
Dave Barach72d72232016-08-04 10:15:08 -040010425 vat_main_t *vam = &vat_main;
10426 vat_json_node_t *node = NULL;
Dave Wallace60231f32015-12-17 21:04:30 -050010427
Dave Barach72d72232016-08-04 10:15:08 -040010428 if (VAT_JSON_ARRAY != vam->json_tree.type)
Dave Wallace60231f32015-12-17 21:04:30 -050010429 {
Dave Barach72d72232016-08-04 10:15:08 -040010430 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10431 vat_json_init_array (&vam->json_tree);
Dave Wallace60231f32015-12-17 21:04:30 -050010432 }
Dave Barach72d72232016-08-04 10:15:08 -040010433 node = vat_json_array_add (&vam->json_tree);
10434
10435 vat_json_init_object (node);
10436 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10437 if (mp->is_ipv6)
10438 {
Eyal Baric5b13602016-11-24 19:42:43 +020010439 struct in6_addr ip6;
10440
10441 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010442 vat_json_object_add_ip6 (node, "src_address", ip6);
Eyal Baric5b13602016-11-24 19:42:43 +020010443 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
Dave Barach72d72232016-08-04 10:15:08 -040010444 vat_json_object_add_ip6 (node, "dst_address", ip6);
10445 }
10446 else
10447 {
Eyal Baric5b13602016-11-24 19:42:43 +020010448 struct in_addr ip4;
10449
10450 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010451 vat_json_object_add_ip4 (node, "src_address", ip4);
Eyal Baric5b13602016-11-24 19:42:43 +020010452 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
Dave Barach72d72232016-08-04 10:15:08 -040010453 vat_json_object_add_ip4 (node, "dst_address", ip4);
10454 }
10455 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10456 vat_json_object_add_uint (node, "decap_next_index",
10457 ntohl (mp->decap_next_index));
10458 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10459 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Eyal Baric5b13602016-11-24 19:42:43 +020010460 vat_json_object_add_uint (node, "mcast_sw_if_index",
10461 ntohl (mp->mcast_sw_if_index));
Dave Wallace60231f32015-12-17 21:04:30 -050010462}
10463
Dave Barach72d72232016-08-04 10:15:08 -040010464static int
10465api_vxlan_tunnel_dump (vat_main_t * vam)
Chris Luke27fe48f2016-04-28 13:44:38 -040010466{
Dave Barach72d72232016-08-04 10:15:08 -040010467 unformat_input_t *i = vam->input;
10468 vl_api_vxlan_tunnel_dump_t *mp;
10469 f64 timeout;
10470 u32 sw_if_index;
10471 u8 sw_if_index_set = 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010472
Dave Barach72d72232016-08-04 10:15:08 -040010473 /* Parse args required to build the message */
10474 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10475 {
10476 if (unformat (i, "sw_if_index %d", &sw_if_index))
10477 sw_if_index_set = 1;
10478 else
10479 break;
Chris Luke27fe48f2016-04-28 13:44:38 -040010480 }
10481
Dave Barach72d72232016-08-04 10:15:08 -040010482 if (sw_if_index_set == 0)
10483 {
10484 sw_if_index = ~0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010485 }
Dave Barach72d72232016-08-04 10:15:08 -040010486
10487 if (!vam->json_output)
10488 {
Eyal Baric5b13602016-11-24 19:42:43 +020010489 fformat (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s\n",
Dave Barach72d72232016-08-04 10:15:08 -040010490 "sw_if_index", "src_address", "dst_address",
Eyal Baric5b13602016-11-24 19:42:43 +020010491 "encap_vrf_id", "decap_next_index", "vni",
10492 "mcast_sw_if_index");
Dave Barach72d72232016-08-04 10:15:08 -040010493 }
10494
10495 /* Get list of vxlan-tunnel interfaces */
10496 M (VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
10497
10498 mp->sw_if_index = htonl (sw_if_index);
10499
10500 S;
10501
10502 /* Use a control ping for synchronization */
10503 {
10504 vl_api_control_ping_t *mp;
10505 M (CONTROL_PING, control_ping);
10506 S;
10507 }
10508 W;
10509}
10510
10511static int
10512api_gre_add_del_tunnel (vat_main_t * vam)
10513{
10514 unformat_input_t *line_input = vam->input;
10515 vl_api_gre_add_del_tunnel_t *mp;
10516 f64 timeout;
10517 ip4_address_t src4, dst4;
10518 u8 is_add = 1;
David Hothama8cd3092016-09-19 09:55:07 -070010519 u8 teb = 0;
Dave Barach72d72232016-08-04 10:15:08 -040010520 u8 src_set = 0;
10521 u8 dst_set = 0;
10522 u32 outer_fib_id = 0;
10523
10524 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10525 {
10526 if (unformat (line_input, "del"))
10527 is_add = 0;
10528 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
10529 src_set = 1;
10530 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
10531 dst_set = 1;
10532 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
10533 ;
David Hothama8cd3092016-09-19 09:55:07 -070010534 else if (unformat (line_input, "teb"))
10535 teb = 1;
Dave Barach72d72232016-08-04 10:15:08 -040010536 else
10537 {
10538 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
10539 return -99;
10540 }
10541 }
10542
10543 if (src_set == 0)
10544 {
10545 errmsg ("tunnel src address not specified\n");
10546 return -99;
10547 }
10548 if (dst_set == 0)
10549 {
10550 errmsg ("tunnel dst address not specified\n");
10551 return -99;
Chris Luke27fe48f2016-04-28 13:44:38 -040010552 }
10553
10554
Dave Barach72d72232016-08-04 10:15:08 -040010555 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
Chris Luke27fe48f2016-04-28 13:44:38 -040010556
Dave Barach72d72232016-08-04 10:15:08 -040010557 clib_memcpy (&mp->src_address, &src4, sizeof (src4));
10558 clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
10559 mp->outer_fib_id = ntohl (outer_fib_id);
10560 mp->is_add = is_add;
David Hothama8cd3092016-09-19 09:55:07 -070010561 mp->teb = teb;
Chris Luke27fe48f2016-04-28 13:44:38 -040010562
Dave Barach72d72232016-08-04 10:15:08 -040010563 S;
10564 W;
10565 /* NOTREACHED */
10566 return 0;
Chris Luke27fe48f2016-04-28 13:44:38 -040010567}
10568
10569static void vl_api_gre_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010570 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010571{
Dave Barach72d72232016-08-04 10:15:08 -040010572 vat_main_t *vam = &vat_main;
Chris Luke27fe48f2016-04-28 13:44:38 -040010573
David Hothama8cd3092016-09-19 09:55:07 -070010574 fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
Dave Barach72d72232016-08-04 10:15:08 -040010575 ntohl (mp->sw_if_index),
10576 format_ip4_address, &mp->src_address,
David Hothama8cd3092016-09-19 09:55:07 -070010577 format_ip4_address, &mp->dst_address,
10578 mp->teb, ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010579}
10580
10581static void vl_api_gre_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010582 (vl_api_gre_tunnel_details_t * mp)
Chris Luke27fe48f2016-04-28 13:44:38 -040010583{
Dave Barach72d72232016-08-04 10:15:08 -040010584 vat_main_t *vam = &vat_main;
10585 vat_json_node_t *node = NULL;
10586 struct in_addr ip4;
Chris Luke27fe48f2016-04-28 13:44:38 -040010587
Dave Barach72d72232016-08-04 10:15:08 -040010588 if (VAT_JSON_ARRAY != vam->json_tree.type)
Chris Luke27fe48f2016-04-28 13:44:38 -040010589 {
Dave Barach72d72232016-08-04 10:15:08 -040010590 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10591 vat_json_init_array (&vam->json_tree);
Chris Luke27fe48f2016-04-28 13:44:38 -040010592 }
Dave Barach72d72232016-08-04 10:15:08 -040010593 node = vat_json_array_add (&vam->json_tree);
10594
10595 vat_json_init_object (node);
10596 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10597 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
10598 vat_json_object_add_ip4 (node, "src_address", ip4);
10599 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
10600 vat_json_object_add_ip4 (node, "dst_address", ip4);
David Hothama8cd3092016-09-19 09:55:07 -070010601 vat_json_object_add_uint (node, "teb", mp->teb);
Dave Barach72d72232016-08-04 10:15:08 -040010602 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Chris Luke27fe48f2016-04-28 13:44:38 -040010603}
10604
Dave Barach72d72232016-08-04 10:15:08 -040010605static int
10606api_gre_tunnel_dump (vat_main_t * vam)
10607{
10608 unformat_input_t *i = vam->input;
10609 vl_api_gre_tunnel_dump_t *mp;
10610 f64 timeout;
10611 u32 sw_if_index;
10612 u8 sw_if_index_set = 0;
10613
10614 /* Parse args required to build the message */
10615 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10616 {
10617 if (unformat (i, "sw_if_index %d", &sw_if_index))
10618 sw_if_index_set = 1;
10619 else
10620 break;
10621 }
10622
10623 if (sw_if_index_set == 0)
10624 {
10625 sw_if_index = ~0;
10626 }
10627
10628 if (!vam->json_output)
10629 {
David Hothama8cd3092016-09-19 09:55:07 -070010630 fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
10631 "sw_if_index", "src_address", "dst_address", "teb",
10632 "outer_fib_id");
Dave Barach72d72232016-08-04 10:15:08 -040010633 }
10634
10635 /* Get list of gre-tunnel interfaces */
10636 M (GRE_TUNNEL_DUMP, gre_tunnel_dump);
10637
10638 mp->sw_if_index = htonl (sw_if_index);
10639
10640 S;
10641
10642 /* Use a control ping for synchronization */
10643 {
10644 vl_api_control_ping_t *mp;
10645 M (CONTROL_PING, control_ping);
10646 S;
10647 }
10648 W;
10649}
10650
10651static int
10652api_l2_fib_clear_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010653{
10654// unformat_input_t * i = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040010655 vl_api_l2_fib_clear_table_t *mp;
10656 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010657
Dave Barach72d72232016-08-04 10:15:08 -040010658 M (L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010659
Dave Barach72d72232016-08-04 10:15:08 -040010660 S;
10661 W;
10662 /* NOTREACHED */
10663 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010664}
10665
Dave Barach72d72232016-08-04 10:15:08 -040010666static int
10667api_l2_interface_efp_filter (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010668{
Dave Barach72d72232016-08-04 10:15:08 -040010669 unformat_input_t *i = vam->input;
10670 vl_api_l2_interface_efp_filter_t *mp;
10671 f64 timeout;
10672 u32 sw_if_index;
10673 u8 enable = 1;
10674 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010675
Dave Barach72d72232016-08-04 10:15:08 -040010676 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10677 {
10678 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10679 sw_if_index_set = 1;
10680 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10681 sw_if_index_set = 1;
10682 else if (unformat (i, "enable"))
10683 enable = 1;
10684 else if (unformat (i, "disable"))
10685 enable = 0;
10686 else
10687 {
10688 clib_warning ("parse error '%U'", format_unformat_error, i);
10689 return -99;
10690 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010691 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010692
Dave Barach72d72232016-08-04 10:15:08 -040010693 if (sw_if_index_set == 0)
10694 {
10695 errmsg ("missing sw_if_index\n");
10696 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010697 }
10698
Dave Barach72d72232016-08-04 10:15:08 -040010699 M (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010700
Dave Barach72d72232016-08-04 10:15:08 -040010701 mp->sw_if_index = ntohl (sw_if_index);
10702 mp->enable_disable = enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010703
Dave Barach72d72232016-08-04 10:15:08 -040010704 S;
10705 W;
10706 /* NOTREACHED */
10707 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010708}
10709
10710#define foreach_vtr_op \
10711_("disable", L2_VTR_DISABLED) \
10712_("push-1", L2_VTR_PUSH_1) \
10713_("push-2", L2_VTR_PUSH_2) \
10714_("pop-1", L2_VTR_POP_1) \
10715_("pop-2", L2_VTR_POP_2) \
10716_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
10717_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
10718_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
10719_("translate-2-2", L2_VTR_TRANSLATE_2_2)
10720
Dave Barach72d72232016-08-04 10:15:08 -040010721static int
10722api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010723{
Dave Barach72d72232016-08-04 10:15:08 -040010724 unformat_input_t *i = vam->input;
10725 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
10726 f64 timeout;
10727 u32 sw_if_index;
10728 u8 sw_if_index_set = 0;
10729 u8 vtr_op_set = 0;
10730 u32 vtr_op = 0;
10731 u32 push_dot1q = 1;
10732 u32 tag1 = ~0;
10733 u32 tag2 = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010734
Dave Barach72d72232016-08-04 10:15:08 -040010735 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10736 {
10737 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
10738 sw_if_index_set = 1;
10739 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10740 sw_if_index_set = 1;
10741 else if (unformat (i, "vtr_op %d", &vtr_op))
10742 vtr_op_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010743#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
Dave Barach72d72232016-08-04 10:15:08 -040010744 foreach_vtr_op
Ed Warnickecb9cada2015-12-08 15:45:58 -070010745#undef _
Dave Barach72d72232016-08-04 10:15:08 -040010746 else if (unformat (i, "push_dot1q %d", &push_dot1q))
10747 ;
10748 else if (unformat (i, "tag1 %d", &tag1))
10749 ;
10750 else if (unformat (i, "tag2 %d", &tag2))
10751 ;
10752 else
10753 {
10754 clib_warning ("parse error '%U'", format_unformat_error, i);
10755 return -99;
10756 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070010757 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080010758
Dave Barach72d72232016-08-04 10:15:08 -040010759 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
10760 {
10761 errmsg ("missing vtr operation or sw_if_index\n");
10762 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010763 }
10764
Dave Barach72d72232016-08-04 10:15:08 -040010765 M (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
10766 mp->sw_if_index = ntohl (sw_if_index);
10767 mp->vtr_op = ntohl (vtr_op);
10768 mp->push_dot1q = ntohl (push_dot1q);
10769 mp->tag1 = ntohl (tag1);
10770 mp->tag2 = ntohl (tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010771
Dave Barach72d72232016-08-04 10:15:08 -040010772 S;
10773 W;
10774 /* NOTREACHED */
10775 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010776}
10777
Dave Barach72d72232016-08-04 10:15:08 -040010778static int
10779api_create_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010780{
Dave Barach72d72232016-08-04 10:15:08 -040010781 unformat_input_t *i = vam->input;
10782 vl_api_create_vhost_user_if_t *mp;
10783 f64 timeout;
10784 u8 *file_name;
10785 u8 is_server = 0;
10786 u8 file_name_set = 0;
10787 u32 custom_dev_instance = ~0;
10788 u8 hwaddr[6];
10789 u8 use_custom_mac = 0;
Dave Barach7be864a2016-11-28 11:41:35 -050010790 u8 *tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010791
Dave Barach75665d32016-11-17 11:36:59 -050010792 /* Shut up coverity */
10793 memset (hwaddr, 0, sizeof (hwaddr));
10794
Dave Barach72d72232016-08-04 10:15:08 -040010795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10796 {
10797 if (unformat (i, "socket %s", &file_name))
10798 {
10799 file_name_set = 1;
10800 }
10801 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10802 ;
Pierre Pfisteref65cb02016-02-19 13:52:44 +000010803 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
Dave Barach72d72232016-08-04 10:15:08 -040010804 use_custom_mac = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010805 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010806 is_server = 1;
Dave Barach7be864a2016-11-28 11:41:35 -050010807 else if (unformat (i, "tag %s", &tag))
10808 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010809 else
Dave Barach72d72232016-08-04 10:15:08 -040010810 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010811 }
10812
Dave Barach72d72232016-08-04 10:15:08 -040010813 if (file_name_set == 0)
10814 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010815 errmsg ("missing socket file name\n");
10816 return -99;
10817 }
10818
Dave Barach72d72232016-08-04 10:15:08 -040010819 if (vec_len (file_name) > 255)
10820 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010821 errmsg ("socket file name too long\n");
10822 return -99;
10823 }
Dave Barach72d72232016-08-04 10:15:08 -040010824 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010825
Dave Barach72d72232016-08-04 10:15:08 -040010826 M (CREATE_VHOST_USER_IF, create_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010827
Dave Barach72d72232016-08-04 10:15:08 -040010828 mp->is_server = is_server;
10829 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10830 vec_free (file_name);
10831 if (custom_dev_instance != ~0)
10832 {
10833 mp->renumber = 1;
10834 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010835 }
Dave Barach72d72232016-08-04 10:15:08 -040010836 mp->use_custom_mac = use_custom_mac;
10837 clib_memcpy (mp->mac_address, hwaddr, 6);
Dave Barach7be864a2016-11-28 11:41:35 -050010838 if (tag)
10839 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10840 vec_free (tag);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010841
Dave Barach72d72232016-08-04 10:15:08 -040010842 S;
10843 W;
10844 /* NOTREACHED */
10845 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010846}
10847
Dave Barach72d72232016-08-04 10:15:08 -040010848static int
10849api_modify_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010850{
Dave Barach72d72232016-08-04 10:15:08 -040010851 unformat_input_t *i = vam->input;
10852 vl_api_modify_vhost_user_if_t *mp;
10853 f64 timeout;
10854 u8 *file_name;
10855 u8 is_server = 0;
10856 u8 file_name_set = 0;
10857 u32 custom_dev_instance = ~0;
10858 u8 sw_if_index_set = 0;
10859 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010860
Dave Barach72d72232016-08-04 10:15:08 -040010861 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10862 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010863 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010864 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010865 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010866 sw_if_index_set = 1;
10867 else if (unformat (i, "socket %s", &file_name))
10868 {
10869 file_name_set = 1;
10870 }
10871 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10872 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010873 else if (unformat (i, "server"))
Dave Barach72d72232016-08-04 10:15:08 -040010874 is_server = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010875 else
Dave Barach72d72232016-08-04 10:15:08 -040010876 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010877 }
10878
Dave Barach72d72232016-08-04 10:15:08 -040010879 if (sw_if_index_set == 0)
10880 {
10881 errmsg ("missing sw_if_index or interface name\n");
10882 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010883 }
10884
Dave Barach72d72232016-08-04 10:15:08 -040010885 if (file_name_set == 0)
10886 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010887 errmsg ("missing socket file name\n");
10888 return -99;
10889 }
10890
Dave Barach72d72232016-08-04 10:15:08 -040010891 if (vec_len (file_name) > 255)
10892 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010893 errmsg ("socket file name too long\n");
10894 return -99;
10895 }
Dave Barach72d72232016-08-04 10:15:08 -040010896 vec_add1 (file_name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010897
Dave Barach72d72232016-08-04 10:15:08 -040010898 M (MODIFY_VHOST_USER_IF, modify_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010899
Dave Barach72d72232016-08-04 10:15:08 -040010900 mp->sw_if_index = ntohl (sw_if_index);
10901 mp->is_server = is_server;
10902 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10903 vec_free (file_name);
10904 if (custom_dev_instance != ~0)
10905 {
10906 mp->renumber = 1;
10907 mp->custom_dev_instance = ntohl (custom_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010908 }
10909
Dave Barach72d72232016-08-04 10:15:08 -040010910 S;
10911 W;
10912 /* NOTREACHED */
10913 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010914}
10915
Dave Barach72d72232016-08-04 10:15:08 -040010916static int
10917api_delete_vhost_user_if (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010918{
Dave Barach72d72232016-08-04 10:15:08 -040010919 unformat_input_t *i = vam->input;
10920 vl_api_delete_vhost_user_if_t *mp;
10921 f64 timeout;
10922 u32 sw_if_index = ~0;
10923 u8 sw_if_index_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010924
Dave Barach72d72232016-08-04 10:15:08 -040010925 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10926 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070010927 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010928 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010929 else if (unformat (i, "sw_if_index %d", &sw_if_index))
Dave Barach72d72232016-08-04 10:15:08 -040010930 sw_if_index_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010931 else
Dave Barach72d72232016-08-04 10:15:08 -040010932 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010933 }
10934
Dave Barach72d72232016-08-04 10:15:08 -040010935 if (sw_if_index_set == 0)
10936 {
10937 errmsg ("missing sw_if_index or interface name\n");
10938 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010939 }
10940
10941
Dave Barach72d72232016-08-04 10:15:08 -040010942 M (DELETE_VHOST_USER_IF, delete_vhost_user_if);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010943
Dave Barach72d72232016-08-04 10:15:08 -040010944 mp->sw_if_index = ntohl (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010945
Dave Barach72d72232016-08-04 10:15:08 -040010946 S;
10947 W;
10948 /* NOTREACHED */
10949 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010950}
10951
10952static void vl_api_sw_interface_vhost_user_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040010953 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010954{
Dave Barach72d72232016-08-04 10:15:08 -040010955 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010956
Dave Barach72d72232016-08-04 10:15:08 -040010957 fformat (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
10958 (char *) mp->interface_name,
10959 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10960 clib_net_to_host_u64 (mp->features), mp->is_server,
10961 ntohl (mp->num_regions), (char *) mp->sock_filename);
10962 fformat (vam->ofp, " Status: '%s'\n", strerror (ntohl (mp->sock_errno)));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010963}
10964
10965static void vl_api_sw_interface_vhost_user_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040010966 (vl_api_sw_interface_vhost_user_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010967{
Dave Barach72d72232016-08-04 10:15:08 -040010968 vat_main_t *vam = &vat_main;
10969 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070010970
Dave Barach72d72232016-08-04 10:15:08 -040010971 if (VAT_JSON_ARRAY != vam->json_tree.type)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010972 {
Dave Barach72d72232016-08-04 10:15:08 -040010973 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10974 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070010975 }
Dave Barach72d72232016-08-04 10:15:08 -040010976 node = vat_json_array_add (&vam->json_tree);
10977
10978 vat_json_init_object (node);
10979 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10980 vat_json_object_add_string_copy (node, "interface_name",
10981 mp->interface_name);
10982 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10983 ntohl (mp->virtio_net_hdr_sz));
10984 vat_json_object_add_uint (node, "features",
10985 clib_net_to_host_u64 (mp->features));
10986 vat_json_object_add_uint (node, "is_server", mp->is_server);
10987 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10988 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10989 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
Ed Warnickecb9cada2015-12-08 15:45:58 -070010990}
10991
Dave Barach72d72232016-08-04 10:15:08 -040010992static int
10993api_sw_interface_vhost_user_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070010994{
Dave Barach72d72232016-08-04 10:15:08 -040010995 vl_api_sw_interface_vhost_user_dump_t *mp;
10996 f64 timeout;
10997 fformat (vam->ofp,
10998 "Interface name idx hdr_sz features server regions filename\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070010999
Dave Barach72d72232016-08-04 10:15:08 -040011000 /* Get list of vhost-user interfaces */
11001 M (SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
11002 S;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011003
Dave Barach72d72232016-08-04 10:15:08 -040011004 /* Use a control ping for synchronization */
11005 {
11006 vl_api_control_ping_t *mp;
11007 M (CONTROL_PING, control_ping);
11008 S;
11009 }
11010 W;
11011}
11012
11013static int
11014api_show_version (vat_main_t * vam)
11015{
11016 vl_api_show_version_t *mp;
11017 f64 timeout;
11018
11019 M (SHOW_VERSION, show_version);
11020
11021 S;
11022 W;
11023 /* NOTREACHED */
11024 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011025}
11026
Ed Warnickecb9cada2015-12-08 15:45:58 -070011027
Dave Barach72d72232016-08-04 10:15:08 -040011028static int
11029api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011030{
Dave Barach72d72232016-08-04 10:15:08 -040011031 unformat_input_t *line_input = vam->input;
11032 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
11033 f64 timeout;
11034 ip4_address_t local4, remote4;
11035 ip6_address_t local6, remote6;
11036 u8 is_add = 1;
11037 u8 ipv4_set = 0, ipv6_set = 0;
11038 u8 local_set = 0;
11039 u8 remote_set = 0;
11040 u32 encap_vrf_id = 0;
11041 u32 decap_vrf_id = 0;
11042 u8 protocol = ~0;
11043 u32 vni;
11044 u8 vni_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011045
Dave Barach72d72232016-08-04 10:15:08 -040011046 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11047 {
11048 if (unformat (line_input, "del"))
11049 is_add = 0;
11050 else if (unformat (line_input, "local %U",
11051 unformat_ip4_address, &local4))
11052 {
11053 local_set = 1;
11054 ipv4_set = 1;
11055 }
11056 else if (unformat (line_input, "remote %U",
11057 unformat_ip4_address, &remote4))
11058 {
11059 remote_set = 1;
11060 ipv4_set = 1;
11061 }
11062 else if (unformat (line_input, "local %U",
11063 unformat_ip6_address, &local6))
11064 {
11065 local_set = 1;
11066 ipv6_set = 1;
11067 }
11068 else if (unformat (line_input, "remote %U",
11069 unformat_ip6_address, &remote6))
11070 {
11071 remote_set = 1;
11072 ipv6_set = 1;
11073 }
11074 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
11075 ;
11076 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
11077 ;
11078 else if (unformat (line_input, "vni %d", &vni))
11079 vni_set = 1;
11080 else if (unformat (line_input, "next-ip4"))
11081 protocol = 1;
11082 else if (unformat (line_input, "next-ip6"))
11083 protocol = 2;
11084 else if (unformat (line_input, "next-ethernet"))
11085 protocol = 3;
11086 else if (unformat (line_input, "next-nsh"))
11087 protocol = 4;
11088 else
11089 {
11090 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
11091 return -99;
11092 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011093 }
11094
Dave Barach72d72232016-08-04 10:15:08 -040011095 if (local_set == 0)
11096 {
11097 errmsg ("tunnel local address not specified\n");
11098 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011099 }
Dave Barach72d72232016-08-04 10:15:08 -040011100 if (remote_set == 0)
11101 {
11102 errmsg ("tunnel remote address not specified\n");
11103 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011104 }
Dave Barach72d72232016-08-04 10:15:08 -040011105 if (ipv4_set && ipv6_set)
11106 {
11107 errmsg ("both IPv4 and IPv6 addresses specified");
11108 return -99;
Hongjun Nidf921cc2016-05-25 01:16:19 +080011109 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011110
Dave Barach72d72232016-08-04 10:15:08 -040011111 if (vni_set == 0)
11112 {
11113 errmsg ("vni not specified\n");
11114 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011115 }
11116
Dave Barach72d72232016-08-04 10:15:08 -040011117 M (VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011118
Hongjun Nidf921cc2016-05-25 01:16:19 +080011119
Dave Barach72d72232016-08-04 10:15:08 -040011120 if (ipv6_set)
11121 {
11122 clib_memcpy (&mp->local, &local6, sizeof (local6));
11123 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
11124 }
11125 else
11126 {
11127 clib_memcpy (&mp->local, &local4, sizeof (local4));
11128 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
Hongjun Nidf921cc2016-05-25 01:16:19 +080011129 }
11130
Dave Barach72d72232016-08-04 10:15:08 -040011131 mp->encap_vrf_id = ntohl (encap_vrf_id);
11132 mp->decap_vrf_id = ntohl (decap_vrf_id);
11133 mp->protocol = ntohl (protocol);
11134 mp->vni = ntohl (vni);
11135 mp->is_add = is_add;
11136 mp->is_ipv6 = ipv6_set;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011137
Dave Barach72d72232016-08-04 10:15:08 -040011138 S;
11139 W;
11140 /* NOTREACHED */
11141 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011142}
11143
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011144static void vl_api_vxlan_gpe_tunnel_details_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011145 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011146{
Dave Barach72d72232016-08-04 10:15:08 -040011147 vat_main_t *vam = &vat_main;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011148
Dave Barach72d72232016-08-04 10:15:08 -040011149 fformat (vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
11150 ntohl (mp->sw_if_index),
11151 format_ip46_address, &(mp->local[0]),
11152 format_ip46_address, &(mp->remote[0]),
11153 ntohl (mp->vni),
11154 ntohl (mp->protocol),
11155 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011156}
11157
11158static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011159 (vl_api_vxlan_gpe_tunnel_details_t * mp)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011160{
Dave Barach72d72232016-08-04 10:15:08 -040011161 vat_main_t *vam = &vat_main;
11162 vat_json_node_t *node = NULL;
11163 struct in_addr ip4;
11164 struct in6_addr ip6;
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011165
Dave Barach72d72232016-08-04 10:15:08 -040011166 if (VAT_JSON_ARRAY != vam->json_tree.type)
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011167 {
Dave Barach72d72232016-08-04 10:15:08 -040011168 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11169 vat_json_init_array (&vam->json_tree);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011170 }
Dave Barach72d72232016-08-04 10:15:08 -040011171 node = vat_json_array_add (&vam->json_tree);
11172
11173 vat_json_init_object (node);
11174 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11175 if (mp->is_ipv6)
11176 {
11177 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
11178 vat_json_object_add_ip6 (node, "local", ip6);
11179 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
11180 vat_json_object_add_ip6 (node, "remote", ip6);
11181 }
11182 else
11183 {
11184 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
11185 vat_json_object_add_ip4 (node, "local", ip4);
11186 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
11187 vat_json_object_add_ip4 (node, "remote", ip4);
11188 }
11189 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
11190 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
11191 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
11192 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
11193 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080011194}
11195
Dave Barach72d72232016-08-04 10:15:08 -040011196static int
11197api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011198{
Dave Barach72d72232016-08-04 10:15:08 -040011199 unformat_input_t *i = vam->input;
11200 vl_api_vxlan_gpe_tunnel_dump_t *mp;
11201 f64 timeout;
11202 u32 sw_if_index;
11203 u8 sw_if_index_set = 0;
11204
11205 /* Parse args required to build the message */
11206 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11207 {
11208 if (unformat (i, "sw_if_index %d", &sw_if_index))
11209 sw_if_index_set = 1;
11210 else
11211 break;
11212 }
11213
11214 if (sw_if_index_set == 0)
11215 {
11216 sw_if_index = ~0;
11217 }
11218
11219 if (!vam->json_output)
11220 {
11221 fformat (vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
11222 "sw_if_index", "local", "remote", "vni",
11223 "protocol", "encap_vrf_id", "decap_vrf_id");
11224 }
11225
11226 /* Get list of vxlan-tunnel interfaces */
11227 M (VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
11228
11229 mp->sw_if_index = htonl (sw_if_index);
11230
11231 S;
11232
11233 /* Use a control ping for synchronization */
11234 {
11235 vl_api_control_ping_t *mp;
11236 M (CONTROL_PING, control_ping);
11237 S;
11238 }
11239 W;
11240}
11241
11242u8 *
11243format_l2_fib_mac_address (u8 * s, va_list * args)
11244{
11245 u8 *a = va_arg (*args, u8 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011246
11247 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
Dave Barach72d72232016-08-04 10:15:08 -040011248 a[2], a[3], a[4], a[5], a[6], a[7]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011249}
11250
11251static void vl_api_l2_fib_table_entry_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040011252 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011253{
Dave Barach72d72232016-08-04 10:15:08 -040011254 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011255
Dave Barach72d72232016-08-04 10:15:08 -040011256 fformat (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
11257 " %d %d %d\n",
11258 ntohl (mp->bd_id), format_l2_fib_mac_address, &mp->mac,
11259 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
11260 mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011261}
11262
11263static void vl_api_l2_fib_table_entry_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040011264 (vl_api_l2_fib_table_entry_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011265{
Dave Barach72d72232016-08-04 10:15:08 -040011266 vat_main_t *vam = &vat_main;
11267 vat_json_node_t *node = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011268
Dave Barach72d72232016-08-04 10:15:08 -040011269 if (VAT_JSON_ARRAY != vam->json_tree.type)
11270 {
11271 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11272 vat_json_init_array (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011273 }
Dave Barach72d72232016-08-04 10:15:08 -040011274 node = vat_json_array_add (&vam->json_tree);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011275
Dave Barach72d72232016-08-04 10:15:08 -040011276 vat_json_init_object (node);
11277 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
11278 vat_json_object_add_uint (node, "mac", clib_net_to_host_u64 (mp->mac));
11279 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11280 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
11281 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
11282 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011283}
11284
Dave Barach72d72232016-08-04 10:15:08 -040011285static int
11286api_l2_fib_table_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011287{
Dave Barach72d72232016-08-04 10:15:08 -040011288 unformat_input_t *i = vam->input;
11289 vl_api_l2_fib_table_dump_t *mp;
11290 f64 timeout;
11291 u32 bd_id;
11292 u8 bd_id_set = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011293
Dave Barach72d72232016-08-04 10:15:08 -040011294 /* Parse args required to build the message */
11295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011296 {
Dave Barach72d72232016-08-04 10:15:08 -040011297 if (unformat (i, "bd_id %d", &bd_id))
11298 bd_id_set = 1;
11299 else
11300 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011301 }
Dave Barach72d72232016-08-04 10:15:08 -040011302
11303 if (bd_id_set == 0)
11304 {
11305 errmsg ("missing bridge domain\n");
11306 return -99;
11307 }
11308
11309 fformat (vam->ofp,
11310 "BD-ID Mac Address sw-ndx Static Filter BVI\n");
11311
11312 /* Get list of l2 fib entries */
11313 M (L2_FIB_TABLE_DUMP, l2_fib_table_dump);
11314
11315 mp->bd_id = ntohl (bd_id);
11316 S;
11317
11318 /* Use a control ping for synchronization */
11319 {
11320 vl_api_control_ping_t *mp;
11321 M (CONTROL_PING, control_ping);
11322 S;
11323 }
11324 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011325}
11326
11327
11328static int
11329api_interface_name_renumber (vat_main_t * vam)
11330{
Dave Barach72d72232016-08-04 10:15:08 -040011331 unformat_input_t *line_input = vam->input;
11332 vl_api_interface_name_renumber_t *mp;
11333 u32 sw_if_index = ~0;
11334 f64 timeout;
11335 u32 new_show_dev_instance = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011336
Dave Barach72d72232016-08-04 10:15:08 -040011337 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11338 {
11339 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
11340 &sw_if_index))
11341 ;
11342 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11343 ;
11344 else if (unformat (line_input, "new_show_dev_instance %d",
11345 &new_show_dev_instance))
11346 ;
11347 else
11348 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011349 }
11350
Dave Barach72d72232016-08-04 10:15:08 -040011351 if (sw_if_index == ~0)
11352 {
11353 errmsg ("missing interface name or sw_if_index\n");
11354 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011355 }
11356
Dave Barach72d72232016-08-04 10:15:08 -040011357 if (new_show_dev_instance == ~0)
11358 {
11359 errmsg ("missing new_show_dev_instance\n");
11360 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011361 }
11362
Dave Barach72d72232016-08-04 10:15:08 -040011363 M (INTERFACE_NAME_RENUMBER, interface_name_renumber);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011364
Dave Barach72d72232016-08-04 10:15:08 -040011365 mp->sw_if_index = ntohl (sw_if_index);
11366 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011367
Dave Barach72d72232016-08-04 10:15:08 -040011368 S;
11369 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011370}
11371
11372static int
11373api_want_ip4_arp_events (vat_main_t * vam)
11374{
Dave Barach72d72232016-08-04 10:15:08 -040011375 unformat_input_t *line_input = vam->input;
11376 vl_api_want_ip4_arp_events_t *mp;
11377 f64 timeout;
11378 ip4_address_t address;
11379 int address_set = 0;
11380 u32 enable_disable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011381
Dave Barach72d72232016-08-04 10:15:08 -040011382 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11383 {
11384 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
11385 address_set = 1;
11386 else if (unformat (line_input, "del"))
11387 enable_disable = 0;
11388 else
11389 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011390 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011391
Dave Barach72d72232016-08-04 10:15:08 -040011392 if (address_set == 0)
11393 {
11394 errmsg ("missing addresses\n");
11395 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011396 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080011397
Dave Barach72d72232016-08-04 10:15:08 -040011398 M (WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
11399 mp->enable_disable = enable_disable;
11400 mp->pid = getpid ();
11401 mp->address = address.as_u32;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011402
Dave Barach72d72232016-08-04 10:15:08 -040011403 S;
11404 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011405}
11406
Dave Barach72d72232016-08-04 10:15:08 -040011407static int
John Lo1edfba92016-08-27 01:11:57 -040011408api_want_ip6_nd_events (vat_main_t * vam)
11409{
11410 unformat_input_t *line_input = vam->input;
11411 vl_api_want_ip6_nd_events_t *mp;
11412 f64 timeout;
11413 ip6_address_t address;
11414 int address_set = 0;
11415 u32 enable_disable = 1;
11416
11417 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11418 {
11419 if (unformat (line_input, "address %U", unformat_ip6_address, &address))
11420 address_set = 1;
11421 else if (unformat (line_input, "del"))
11422 enable_disable = 0;
11423 else
11424 break;
11425 }
11426
11427 if (address_set == 0)
11428 {
11429 errmsg ("missing addresses\n");
11430 return -99;
11431 }
11432
11433 M (WANT_IP6_ND_EVENTS, want_ip6_nd_events);
11434 mp->enable_disable = enable_disable;
11435 mp->pid = getpid ();
11436 clib_memcpy (mp->address, &address, sizeof (ip6_address_t));
11437
11438 S;
11439 W;
11440}
11441
11442static int
Dave Barach72d72232016-08-04 10:15:08 -040011443api_input_acl_set_interface (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011444{
Dave Barach72d72232016-08-04 10:15:08 -040011445 unformat_input_t *i = vam->input;
11446 vl_api_input_acl_set_interface_t *mp;
11447 f64 timeout;
11448 u32 sw_if_index;
11449 int sw_if_index_set;
11450 u32 ip4_table_index = ~0;
11451 u32 ip6_table_index = ~0;
11452 u32 l2_table_index = ~0;
11453 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011454
Dave Barach72d72232016-08-04 10:15:08 -040011455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11456 {
11457 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11458 sw_if_index_set = 1;
11459 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11460 sw_if_index_set = 1;
11461 else if (unformat (i, "del"))
11462 is_add = 0;
11463 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11464 ;
11465 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11466 ;
11467 else if (unformat (i, "l2-table %d", &l2_table_index))
11468 ;
11469 else
11470 {
11471 clib_warning ("parse error '%U'", format_unformat_error, i);
11472 return -99;
11473 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011474 }
11475
Dave Barach72d72232016-08-04 10:15:08 -040011476 if (sw_if_index_set == 0)
11477 {
11478 errmsg ("missing interface name or sw_if_index\n");
11479 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011480 }
11481
Dave Barach72d72232016-08-04 10:15:08 -040011482 M (INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011483
Dave Barach72d72232016-08-04 10:15:08 -040011484 mp->sw_if_index = ntohl (sw_if_index);
11485 mp->ip4_table_index = ntohl (ip4_table_index);
11486 mp->ip6_table_index = ntohl (ip6_table_index);
11487 mp->l2_table_index = ntohl (l2_table_index);
11488 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011489
Dave Barach72d72232016-08-04 10:15:08 -040011490 S;
11491 W;
11492 /* NOTREACHED */
11493 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011494}
11495
11496static int
11497api_ip_address_dump (vat_main_t * vam)
11498{
Dave Barach72d72232016-08-04 10:15:08 -040011499 unformat_input_t *i = vam->input;
11500 vl_api_ip_address_dump_t *mp;
11501 u32 sw_if_index = ~0;
11502 u8 sw_if_index_set = 0;
11503 u8 ipv4_set = 0;
11504 u8 ipv6_set = 0;
11505 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011506
Dave Barach72d72232016-08-04 10:15:08 -040011507 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011508 {
Dave Barach72d72232016-08-04 10:15:08 -040011509 if (unformat (i, "sw_if_index %d", &sw_if_index))
11510 sw_if_index_set = 1;
11511 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11512 sw_if_index_set = 1;
11513 else if (unformat (i, "ipv4"))
11514 ipv4_set = 1;
11515 else if (unformat (i, "ipv6"))
11516 ipv6_set = 1;
11517 else
11518 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011519 }
Dave Barach72d72232016-08-04 10:15:08 -040011520
11521 if (ipv4_set && ipv6_set)
11522 {
11523 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11524 return -99;
11525 }
11526
11527 if ((!ipv4_set) && (!ipv6_set))
11528 {
11529 errmsg ("no ipv4 nor ipv6 flag set\n");
11530 return -99;
11531 }
11532
11533 if (sw_if_index_set == 0)
11534 {
11535 errmsg ("missing interface name or sw_if_index\n");
11536 return -99;
11537 }
11538
11539 vam->current_sw_if_index = sw_if_index;
11540 vam->is_ipv6 = ipv6_set;
11541
11542 M (IP_ADDRESS_DUMP, ip_address_dump);
11543 mp->sw_if_index = ntohl (sw_if_index);
11544 mp->is_ipv6 = ipv6_set;
11545 S;
11546
11547 /* Use a control ping for synchronization */
11548 {
11549 vl_api_control_ping_t *mp;
11550 M (CONTROL_PING, control_ping);
11551 S;
11552 }
11553 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011554}
11555
11556static int
11557api_ip_dump (vat_main_t * vam)
11558{
Dave Barach72d72232016-08-04 10:15:08 -040011559 vl_api_ip_dump_t *mp;
11560 unformat_input_t *in = vam->input;
11561 int ipv4_set = 0;
11562 int ipv6_set = 0;
11563 int is_ipv6;
11564 f64 timeout;
11565 int i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011566
Dave Barach72d72232016-08-04 10:15:08 -040011567 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070011568 {
Dave Barach72d72232016-08-04 10:15:08 -040011569 if (unformat (in, "ipv4"))
11570 ipv4_set = 1;
11571 else if (unformat (in, "ipv6"))
11572 ipv6_set = 1;
11573 else
11574 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011575 }
Dave Barach72d72232016-08-04 10:15:08 -040011576
11577 if (ipv4_set && ipv6_set)
11578 {
11579 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
11580 return -99;
11581 }
11582
11583 if ((!ipv4_set) && (!ipv6_set))
11584 {
11585 errmsg ("no ipv4 nor ipv6 flag set\n");
11586 return -99;
11587 }
11588
11589 is_ipv6 = ipv6_set;
11590 vam->is_ipv6 = is_ipv6;
11591
11592 /* free old data */
11593 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
11594 {
11595 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
11596 }
11597 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
11598
11599 M (IP_DUMP, ip_dump);
11600 mp->is_ipv6 = ipv6_set;
11601 S;
11602
11603 /* Use a control ping for synchronization */
11604 {
11605 vl_api_control_ping_t *mp;
11606 M (CONTROL_PING, control_ping);
11607 S;
11608 }
11609 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011610}
11611
11612static int
11613api_ipsec_spd_add_del (vat_main_t * vam)
11614{
Dave Barach72d72232016-08-04 10:15:08 -040011615 unformat_input_t *i = vam->input;
11616 vl_api_ipsec_spd_add_del_t *mp;
11617 f64 timeout;
11618 u32 spd_id = ~0;
11619 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011620
Dave Barach72d72232016-08-04 10:15:08 -040011621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11622 {
11623 if (unformat (i, "spd_id %d", &spd_id))
11624 ;
11625 else if (unformat (i, "del"))
11626 is_add = 0;
11627 else
11628 {
11629 clib_warning ("parse error '%U'", format_unformat_error, i);
11630 return -99;
11631 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011632 }
Dave Barach72d72232016-08-04 10:15:08 -040011633 if (spd_id == ~0)
11634 {
11635 errmsg ("spd_id must be set\n");
11636 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011637 }
11638
Dave Barach72d72232016-08-04 10:15:08 -040011639 M (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011640
Dave Barach72d72232016-08-04 10:15:08 -040011641 mp->spd_id = ntohl (spd_id);
11642 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011643
Dave Barach72d72232016-08-04 10:15:08 -040011644 S;
11645 W;
11646 /* NOTREACHED */
11647 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011648}
11649
11650static int
11651api_ipsec_interface_add_del_spd (vat_main_t * vam)
11652{
Dave Barach72d72232016-08-04 10:15:08 -040011653 unformat_input_t *i = vam->input;
11654 vl_api_ipsec_interface_add_del_spd_t *mp;
11655 f64 timeout;
11656 u32 sw_if_index;
11657 u8 sw_if_index_set = 0;
11658 u32 spd_id = (u32) ~ 0;
11659 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011660
Dave Barach72d72232016-08-04 10:15:08 -040011661 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11662 {
11663 if (unformat (i, "del"))
11664 is_add = 0;
11665 else if (unformat (i, "spd_id %d", &spd_id))
11666 ;
11667 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
11668 sw_if_index_set = 1;
11669 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11670 sw_if_index_set = 1;
11671 else
11672 {
11673 clib_warning ("parse error '%U'", format_unformat_error, i);
11674 return -99;
11675 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011676
11677 }
11678
Dave Barach72d72232016-08-04 10:15:08 -040011679 if (spd_id == (u32) ~ 0)
11680 {
11681 errmsg ("spd_id must be set\n");
11682 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011683 }
11684
Dave Barach72d72232016-08-04 10:15:08 -040011685 if (sw_if_index_set == 0)
11686 {
11687 errmsg ("missing interface name or sw_if_index\n");
11688 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011689 }
11690
Dave Barach72d72232016-08-04 10:15:08 -040011691 M (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011692
Dave Barach72d72232016-08-04 10:15:08 -040011693 mp->spd_id = ntohl (spd_id);
11694 mp->sw_if_index = ntohl (sw_if_index);
11695 mp->is_add = is_add;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011696
Dave Barach72d72232016-08-04 10:15:08 -040011697 S;
11698 W;
11699 /* NOTREACHED */
11700 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011701}
11702
11703static int
11704api_ipsec_spd_add_del_entry (vat_main_t * vam)
11705{
Dave Barach72d72232016-08-04 10:15:08 -040011706 unformat_input_t *i = vam->input;
11707 vl_api_ipsec_spd_add_del_entry_t *mp;
11708 f64 timeout;
11709 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
Dave Barach839fe3e2016-08-10 11:35:54 -040011710 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
Dave Barach042ffb42016-08-12 09:26:47 -040011711 i32 priority = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011712 u32 rport_start = 0, rport_stop = (u32) ~ 0;
11713 u32 lport_start = 0, lport_stop = (u32) ~ 0;
11714 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
11715 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011716
Dave Barach72d72232016-08-04 10:15:08 -040011717 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
11718 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~ 0;
11719 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
11720 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
11721 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~ 0;
11722 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011723
Dave Barach72d72232016-08-04 10:15:08 -040011724 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11725 {
11726 if (unformat (i, "del"))
11727 is_add = 0;
11728 if (unformat (i, "outbound"))
11729 is_outbound = 1;
11730 if (unformat (i, "inbound"))
11731 is_outbound = 0;
11732 else if (unformat (i, "spd_id %d", &spd_id))
11733 ;
11734 else if (unformat (i, "sa_id %d", &sa_id))
11735 ;
11736 else if (unformat (i, "priority %d", &priority))
11737 ;
11738 else if (unformat (i, "protocol %d", &protocol))
11739 ;
11740 else if (unformat (i, "lport_start %d", &lport_start))
11741 ;
11742 else if (unformat (i, "lport_stop %d", &lport_stop))
11743 ;
11744 else if (unformat (i, "rport_start %d", &rport_start))
11745 ;
11746 else if (unformat (i, "rport_stop %d", &rport_stop))
11747 ;
11748 else
11749 if (unformat
11750 (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
11751 {
11752 is_ipv6 = 0;
11753 is_ip_any = 0;
11754 }
11755 else
11756 if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
11757 {
11758 is_ipv6 = 0;
11759 is_ip_any = 0;
11760 }
11761 else
11762 if (unformat
11763 (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
11764 {
11765 is_ipv6 = 0;
11766 is_ip_any = 0;
11767 }
11768 else
11769 if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
11770 {
11771 is_ipv6 = 0;
11772 is_ip_any = 0;
11773 }
11774 else
11775 if (unformat
11776 (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
11777 {
11778 is_ipv6 = 1;
11779 is_ip_any = 0;
11780 }
11781 else
11782 if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
11783 {
11784 is_ipv6 = 1;
11785 is_ip_any = 0;
11786 }
11787 else
11788 if (unformat
11789 (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
11790 {
11791 is_ipv6 = 1;
11792 is_ip_any = 0;
11793 }
11794 else
11795 if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
11796 {
11797 is_ipv6 = 1;
11798 is_ip_any = 0;
11799 }
11800 else
11801 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11802 {
11803 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11804 {
11805 clib_warning ("unsupported action: 'resolve'");
11806 return -99;
11807 }
11808 }
11809 else
11810 {
11811 clib_warning ("parse error '%U'", format_unformat_error, i);
11812 return -99;
11813 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011814
11815 }
11816
Dave Barach72d72232016-08-04 10:15:08 -040011817 M (IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011818
Dave Barach72d72232016-08-04 10:15:08 -040011819 mp->spd_id = ntohl (spd_id);
11820 mp->priority = ntohl (priority);
11821 mp->is_outbound = is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011822
Dave Barach72d72232016-08-04 10:15:08 -040011823 mp->is_ipv6 = is_ipv6;
11824 if (is_ipv6 || is_ip_any)
11825 {
11826 clib_memcpy (mp->remote_address_start, &raddr6_start,
11827 sizeof (ip6_address_t));
11828 clib_memcpy (mp->remote_address_stop, &raddr6_stop,
11829 sizeof (ip6_address_t));
11830 clib_memcpy (mp->local_address_start, &laddr6_start,
11831 sizeof (ip6_address_t));
11832 clib_memcpy (mp->local_address_stop, &laddr6_stop,
11833 sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070011834 }
Dave Barach72d72232016-08-04 10:15:08 -040011835 else
11836 {
11837 clib_memcpy (mp->remote_address_start, &raddr4_start,
11838 sizeof (ip4_address_t));
11839 clib_memcpy (mp->remote_address_stop, &raddr4_stop,
11840 sizeof (ip4_address_t));
11841 clib_memcpy (mp->local_address_start, &laddr4_start,
11842 sizeof (ip4_address_t));
11843 clib_memcpy (mp->local_address_stop, &laddr4_stop,
11844 sizeof (ip4_address_t));
11845 }
11846 mp->protocol = (u8) protocol;
11847 mp->local_port_start = ntohs ((u16) lport_start);
11848 mp->local_port_stop = ntohs ((u16) lport_stop);
11849 mp->remote_port_start = ntohs ((u16) rport_start);
11850 mp->remote_port_stop = ntohs ((u16) rport_stop);
11851 mp->policy = (u8) policy;
11852 mp->sa_id = ntohl (sa_id);
11853 mp->is_add = is_add;
11854 mp->is_ip_any = is_ip_any;
11855 S;
11856 W;
11857 /* NOTREACHED */
11858 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011859}
11860
11861static int
11862api_ipsec_sad_add_del_entry (vat_main_t * vam)
11863{
Dave Barach72d72232016-08-04 10:15:08 -040011864 unformat_input_t *i = vam->input;
11865 vl_api_ipsec_sad_add_del_entry_t *mp;
11866 f64 timeout;
Dave Barach839fe3e2016-08-10 11:35:54 -040011867 u32 sad_id = 0, spi = 0;
Dave Barach72d72232016-08-04 10:15:08 -040011868 u8 *ck = 0, *ik = 0;
11869 u8 is_add = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011870
Dave Barach72d72232016-08-04 10:15:08 -040011871 u8 protocol = IPSEC_PROTOCOL_AH;
11872 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
11873 u32 crypto_alg = 0, integ_alg = 0;
11874 ip4_address_t tun_src4;
11875 ip4_address_t tun_dst4;
11876 ip6_address_t tun_src6;
11877 ip6_address_t tun_dst6;
Ed Warnickecb9cada2015-12-08 15:45:58 -070011878
Dave Barach72d72232016-08-04 10:15:08 -040011879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11880 {
11881 if (unformat (i, "del"))
11882 is_add = 0;
11883 else if (unformat (i, "sad_id %d", &sad_id))
11884 ;
11885 else if (unformat (i, "spi %d", &spi))
11886 ;
11887 else if (unformat (i, "esp"))
11888 protocol = IPSEC_PROTOCOL_ESP;
11889 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4))
11890 {
11891 is_tunnel = 1;
11892 is_tunnel_ipv6 = 0;
11893 }
11894 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4))
11895 {
11896 is_tunnel = 1;
11897 is_tunnel_ipv6 = 0;
11898 }
11899 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6))
11900 {
11901 is_tunnel = 1;
11902 is_tunnel_ipv6 = 1;
11903 }
11904 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6))
11905 {
11906 is_tunnel = 1;
11907 is_tunnel_ipv6 = 1;
11908 }
11909 else
11910 if (unformat
11911 (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg))
11912 {
11913 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011914 crypto_alg >= IPSEC_CRYPTO_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011915 {
11916 clib_warning ("unsupported crypto-alg: '%U'",
11917 format_ipsec_crypto_alg, crypto_alg);
11918 return -99;
11919 }
11920 }
11921 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11922 ;
11923 else
11924 if (unformat
11925 (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg))
11926 {
Radu Nicolau6929ea92016-11-29 11:00:30 +000011927#if DPDK_CRYPTO==1
11928 if (integ_alg < IPSEC_INTEG_ALG_NONE ||
11929#else
Dave Barach72d72232016-08-04 10:15:08 -040011930 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
Radu Nicolau6929ea92016-11-29 11:00:30 +000011931#endif
11932 integ_alg >= IPSEC_INTEG_N_ALG)
Dave Barach72d72232016-08-04 10:15:08 -040011933 {
11934 clib_warning ("unsupported integ-alg: '%U'",
11935 format_ipsec_integ_alg, integ_alg);
11936 return -99;
11937 }
11938 }
11939 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11940 ;
11941 else
11942 {
11943 clib_warning ("parse error '%U'", format_unformat_error, i);
11944 return -99;
11945 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070011946
11947 }
11948
Radu Nicolau6929ea92016-11-29 11:00:30 +000011949#if DPDK_CRYPTO==1
11950 /*Special cases, aes-gcm-128 encryption */
11951 if (crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
11952 {
11953 if (integ_alg != IPSEC_INTEG_ALG_NONE
11954 && integ_alg != IPSEC_INTEG_ALG_AES_GCM_128)
11955 {
11956 clib_warning
11957 ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
11958 return -99;
11959 }
11960 else /*set integ-alg internally to aes-gcm-128 */
11961 integ_alg = IPSEC_INTEG_ALG_AES_GCM_128;
11962 }
11963 else if (integ_alg == IPSEC_INTEG_ALG_AES_GCM_128)
11964 {
11965 clib_warning ("unsupported integ-alg: aes-gcm-128");
11966 return -99;
11967 }
11968 else if (integ_alg == IPSEC_INTEG_ALG_NONE)
11969 {
11970 clib_warning ("unsupported integ-alg: none");
11971 return -99;
11972 }
11973#endif
11974
11975
Dave Barach72d72232016-08-04 10:15:08 -040011976 M (IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011977
Dave Barach72d72232016-08-04 10:15:08 -040011978 mp->sad_id = ntohl (sad_id);
11979 mp->is_add = is_add;
11980 mp->protocol = protocol;
11981 mp->spi = ntohl (spi);
11982 mp->is_tunnel = is_tunnel;
11983 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
11984 mp->crypto_algorithm = crypto_alg;
11985 mp->integrity_algorithm = integ_alg;
11986 mp->crypto_key_length = vec_len (ck);
11987 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011988
Dave Barach72d72232016-08-04 10:15:08 -040011989 if (mp->crypto_key_length > sizeof (mp->crypto_key))
11990 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011991
Dave Barach72d72232016-08-04 10:15:08 -040011992 if (mp->integrity_key_length > sizeof (mp->integrity_key))
11993 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011994
Dave Barach839fe3e2016-08-10 11:35:54 -040011995 if (ck)
11996 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
11997 if (ik)
11998 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070011999
Dave Barach72d72232016-08-04 10:15:08 -040012000 if (is_tunnel)
12001 {
12002 if (is_tunnel_ipv6)
12003 {
12004 clib_memcpy (mp->tunnel_src_address, &tun_src6,
12005 sizeof (ip6_address_t));
12006 clib_memcpy (mp->tunnel_dst_address, &tun_dst6,
12007 sizeof (ip6_address_t));
12008 }
12009 else
12010 {
12011 clib_memcpy (mp->tunnel_src_address, &tun_src4,
12012 sizeof (ip4_address_t));
12013 clib_memcpy (mp->tunnel_dst_address, &tun_dst4,
12014 sizeof (ip4_address_t));
12015 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012016 }
12017
Dave Barach72d72232016-08-04 10:15:08 -040012018 S;
12019 W;
12020 /* NOTREACHED */
12021 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012022}
12023
12024static int
12025api_ipsec_sa_set_key (vat_main_t * vam)
12026{
Dave Barach72d72232016-08-04 10:15:08 -040012027 unformat_input_t *i = vam->input;
12028 vl_api_ipsec_sa_set_key_t *mp;
12029 f64 timeout;
12030 u32 sa_id;
12031 u8 *ck = 0, *ik = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012032
Dave Barach72d72232016-08-04 10:15:08 -040012033 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12034 {
12035 if (unformat (i, "sa_id %d", &sa_id))
12036 ;
12037 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
12038 ;
12039 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
12040 ;
12041 else
12042 {
12043 clib_warning ("parse error '%U'", format_unformat_error, i);
12044 return -99;
12045 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012046 }
12047
Dave Barach72d72232016-08-04 10:15:08 -040012048 M (IPSEC_SA_SET_KEY, ipsec_set_sa_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012049
Dave Barach72d72232016-08-04 10:15:08 -040012050 mp->sa_id = ntohl (sa_id);
12051 mp->crypto_key_length = vec_len (ck);
12052 mp->integrity_key_length = vec_len (ik);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012053
Dave Barach72d72232016-08-04 10:15:08 -040012054 if (mp->crypto_key_length > sizeof (mp->crypto_key))
12055 mp->crypto_key_length = sizeof (mp->crypto_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012056
Dave Barach72d72232016-08-04 10:15:08 -040012057 if (mp->integrity_key_length > sizeof (mp->integrity_key))
12058 mp->integrity_key_length = sizeof (mp->integrity_key);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012059
Dave Barach839fe3e2016-08-10 11:35:54 -040012060 if (ck)
12061 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
12062 if (ik)
12063 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012064
Dave Barach72d72232016-08-04 10:15:08 -040012065 S;
12066 W;
12067 /* NOTREACHED */
12068 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012069}
12070
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012071static int
12072api_ikev2_profile_add_del (vat_main_t * vam)
12073{
Dave Barach72d72232016-08-04 10:15:08 -040012074 unformat_input_t *i = vam->input;
12075 vl_api_ikev2_profile_add_del_t *mp;
12076 f64 timeout;
12077 u8 is_add = 1;
12078 u8 *name = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012079
Dave Barach72d72232016-08-04 10:15:08 -040012080 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012081
Dave Barach72d72232016-08-04 10:15:08 -040012082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12083 {
12084 if (unformat (i, "del"))
12085 is_add = 0;
12086 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12087 vec_add1 (name, 0);
12088 else
12089 {
12090 errmsg ("parse error '%U'", format_unformat_error, i);
12091 return -99;
12092 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012093 }
12094
Dave Barach72d72232016-08-04 10:15:08 -040012095 if (!vec_len (name))
12096 {
12097 errmsg ("profile name must be specified");
12098 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012099 }
12100
Dave Barach72d72232016-08-04 10:15:08 -040012101 if (vec_len (name) > 64)
12102 {
12103 errmsg ("profile name too long");
12104 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012105 }
12106
Dave Barach72d72232016-08-04 10:15:08 -040012107 M (IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012108
Dave Barach72d72232016-08-04 10:15:08 -040012109 clib_memcpy (mp->name, name, vec_len (name));
12110 mp->is_add = is_add;
12111 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012112
Dave Barach72d72232016-08-04 10:15:08 -040012113 S;
12114 W;
12115 /* NOTREACHED */
12116 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012117}
12118
12119static int
12120api_ikev2_profile_set_auth (vat_main_t * vam)
12121{
Dave Barach72d72232016-08-04 10:15:08 -040012122 unformat_input_t *i = vam->input;
12123 vl_api_ikev2_profile_set_auth_t *mp;
12124 f64 timeout;
12125 u8 *name = 0;
12126 u8 *data = 0;
12127 u32 auth_method = 0;
12128 u8 is_hex = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012129
Dave Barach72d72232016-08-04 10:15:08 -040012130 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012131
Dave Barach72d72232016-08-04 10:15:08 -040012132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12133 {
12134 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12135 vec_add1 (name, 0);
12136 else if (unformat (i, "auth_method %U",
12137 unformat_ikev2_auth_method, &auth_method))
12138 ;
12139 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
12140 is_hex = 1;
12141 else if (unformat (i, "auth_data %v", &data))
12142 ;
12143 else
12144 {
12145 errmsg ("parse error '%U'", format_unformat_error, i);
12146 return -99;
12147 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012148 }
12149
Dave Barach72d72232016-08-04 10:15:08 -040012150 if (!vec_len (name))
12151 {
12152 errmsg ("profile name must be specified");
12153 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012154 }
12155
Dave Barach72d72232016-08-04 10:15:08 -040012156 if (vec_len (name) > 64)
12157 {
12158 errmsg ("profile name too long");
12159 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012160 }
12161
Dave Barach72d72232016-08-04 10:15:08 -040012162 if (!vec_len (data))
12163 {
12164 errmsg ("auth_data must be specified");
12165 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012166 }
12167
Dave Barach72d72232016-08-04 10:15:08 -040012168 if (!auth_method)
12169 {
12170 errmsg ("auth_method must be specified");
12171 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012172 }
12173
Dave Barach72d72232016-08-04 10:15:08 -040012174 M (IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012175
Dave Barach72d72232016-08-04 10:15:08 -040012176 mp->is_hex = is_hex;
12177 mp->auth_method = (u8) auth_method;
12178 mp->data_len = vec_len (data);
12179 clib_memcpy (mp->name, name, vec_len (name));
12180 clib_memcpy (mp->data, data, vec_len (data));
12181 vec_free (name);
12182 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012183
Dave Barach72d72232016-08-04 10:15:08 -040012184 S;
12185 W;
12186 /* NOTREACHED */
12187 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012188}
12189
12190static int
12191api_ikev2_profile_set_id (vat_main_t * vam)
12192{
Dave Barach72d72232016-08-04 10:15:08 -040012193 unformat_input_t *i = vam->input;
12194 vl_api_ikev2_profile_set_id_t *mp;
12195 f64 timeout;
12196 u8 *name = 0;
12197 u8 *data = 0;
12198 u8 is_local = 0;
12199 u32 id_type = 0;
12200 ip4_address_t ip4;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012201
Dave Barach72d72232016-08-04 10:15:08 -040012202 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012203
Dave Barach72d72232016-08-04 10:15:08 -040012204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12205 {
12206 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12207 vec_add1 (name, 0);
12208 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
12209 ;
12210 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
12211 {
12212 data = vec_new (u8, 4);
12213 clib_memcpy (data, ip4.as_u8, 4);
12214 }
12215 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
12216 ;
12217 else if (unformat (i, "id_data %v", &data))
12218 ;
12219 else if (unformat (i, "local"))
12220 is_local = 1;
12221 else if (unformat (i, "remote"))
12222 is_local = 0;
12223 else
12224 {
12225 errmsg ("parse error '%U'", format_unformat_error, i);
12226 return -99;
12227 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012228 }
12229
Dave Barach72d72232016-08-04 10:15:08 -040012230 if (!vec_len (name))
12231 {
12232 errmsg ("profile name must be specified");
12233 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012234 }
12235
Dave Barach72d72232016-08-04 10:15:08 -040012236 if (vec_len (name) > 64)
12237 {
12238 errmsg ("profile name too long");
12239 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012240 }
12241
Dave Barach72d72232016-08-04 10:15:08 -040012242 if (!vec_len (data))
12243 {
12244 errmsg ("id_data must be specified");
12245 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012246 }
12247
Dave Barach72d72232016-08-04 10:15:08 -040012248 if (!id_type)
12249 {
12250 errmsg ("id_type must be specified");
12251 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012252 }
12253
Dave Barach72d72232016-08-04 10:15:08 -040012254 M (IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012255
Dave Barach72d72232016-08-04 10:15:08 -040012256 mp->is_local = is_local;
12257 mp->id_type = (u8) id_type;
12258 mp->data_len = vec_len (data);
12259 clib_memcpy (mp->name, name, vec_len (name));
12260 clib_memcpy (mp->data, data, vec_len (data));
12261 vec_free (name);
12262 vec_free (data);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012263
Dave Barach72d72232016-08-04 10:15:08 -040012264 S;
12265 W;
12266 /* NOTREACHED */
12267 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012268}
12269
12270static int
12271api_ikev2_profile_set_ts (vat_main_t * vam)
12272{
Dave Barach72d72232016-08-04 10:15:08 -040012273 unformat_input_t *i = vam->input;
12274 vl_api_ikev2_profile_set_ts_t *mp;
12275 f64 timeout;
12276 u8 *name = 0;
12277 u8 is_local = 0;
12278 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
12279 ip4_address_t start_addr, end_addr;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012280
Dave Barach72d72232016-08-04 10:15:08 -040012281 const char *valid_chars = "a-zA-Z0-9_";
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012282
Dave Barach72d72232016-08-04 10:15:08 -040012283 start_addr.as_u32 = 0;
12284 end_addr.as_u32 = (u32) ~ 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012285
Dave Barach72d72232016-08-04 10:15:08 -040012286 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12287 {
12288 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
12289 vec_add1 (name, 0);
12290 else if (unformat (i, "protocol %d", &proto))
12291 ;
12292 else if (unformat (i, "start_port %d", &start_port))
12293 ;
12294 else if (unformat (i, "end_port %d", &end_port))
12295 ;
12296 else
12297 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
12298 ;
12299 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
12300 ;
12301 else if (unformat (i, "local"))
12302 is_local = 1;
12303 else if (unformat (i, "remote"))
12304 is_local = 0;
12305 else
12306 {
12307 errmsg ("parse error '%U'", format_unformat_error, i);
12308 return -99;
12309 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012310 }
12311
Dave Barach72d72232016-08-04 10:15:08 -040012312 if (!vec_len (name))
12313 {
12314 errmsg ("profile name must be specified");
12315 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012316 }
12317
Dave Barach72d72232016-08-04 10:15:08 -040012318 if (vec_len (name) > 64)
12319 {
12320 errmsg ("profile name too long");
12321 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012322 }
12323
Dave Barach72d72232016-08-04 10:15:08 -040012324 M (IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012325
Dave Barach72d72232016-08-04 10:15:08 -040012326 mp->is_local = is_local;
12327 mp->proto = (u8) proto;
12328 mp->start_port = (u16) start_port;
12329 mp->end_port = (u16) end_port;
12330 mp->start_addr = start_addr.as_u32;
12331 mp->end_addr = end_addr.as_u32;
12332 clib_memcpy (mp->name, name, vec_len (name));
12333 vec_free (name);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012334
Dave Barach72d72232016-08-04 10:15:08 -040012335 S;
12336 W;
12337 /* NOTREACHED */
12338 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012339}
12340
12341static int
12342api_ikev2_set_local_key (vat_main_t * vam)
12343{
Dave Barach72d72232016-08-04 10:15:08 -040012344 unformat_input_t *i = vam->input;
12345 vl_api_ikev2_set_local_key_t *mp;
12346 f64 timeout;
12347 u8 *file = 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012348
Dave Barach72d72232016-08-04 10:15:08 -040012349 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12350 {
12351 if (unformat (i, "file %v", &file))
12352 vec_add1 (file, 0);
12353 else
12354 {
12355 errmsg ("parse error '%U'", format_unformat_error, i);
12356 return -99;
12357 }
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012358 }
12359
Dave Barach72d72232016-08-04 10:15:08 -040012360 if (!vec_len (file))
12361 {
12362 errmsg ("RSA key file must be specified");
12363 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012364 }
12365
Dave Barach72d72232016-08-04 10:15:08 -040012366 if (vec_len (file) > 256)
12367 {
12368 errmsg ("file name too long");
12369 return -99;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012370 }
12371
Dave Barach72d72232016-08-04 10:15:08 -040012372 M (IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012373
Dave Barach72d72232016-08-04 10:15:08 -040012374 clib_memcpy (mp->key_file, file, vec_len (file));
12375 vec_free (file);
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012376
Dave Barach72d72232016-08-04 10:15:08 -040012377 S;
12378 W;
12379 /* NOTREACHED */
12380 return 0;
Matus Fabiane5f42fe2016-04-08 11:18:08 +020012381}
12382
Ed Warnickecb9cada2015-12-08 15:45:58 -070012383/*
12384 * MAP
12385 */
Dave Barach72d72232016-08-04 10:15:08 -040012386static int
12387api_map_add_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012388{
12389 unformat_input_t *i = vam->input;
12390 vl_api_map_add_domain_t *mp;
12391 f64 timeout;
12392
12393 ip4_address_t ip4_prefix;
12394 ip6_address_t ip6_prefix;
12395 ip6_address_t ip6_src;
12396 u32 num_m_args = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012397 u32 ip6_prefix_len = 0, ip4_prefix_len = 0, ea_bits_len = 0, psid_offset =
12398 0, psid_length = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012399 u8 is_translation = 0;
12400 u32 mtu = 0;
Ole Troand847d1c2016-08-24 16:17:29 +020012401 u32 ip6_src_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012402
Dave Barach72d72232016-08-04 10:15:08 -040012403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12404 {
12405 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
12406 &ip4_prefix, &ip4_prefix_len))
12407 num_m_args++;
12408 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
12409 &ip6_prefix, &ip6_prefix_len))
12410 num_m_args++;
12411 else
12412 if (unformat
12413 (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src,
12414 &ip6_src_len))
12415 num_m_args++;
12416 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
12417 num_m_args++;
12418 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
12419 num_m_args++;
12420 else if (unformat (i, "psid-offset %d", &psid_offset))
12421 num_m_args++;
12422 else if (unformat (i, "psid-len %d", &psid_length))
12423 num_m_args++;
12424 else if (unformat (i, "mtu %d", &mtu))
12425 num_m_args++;
12426 else if (unformat (i, "map-t"))
12427 is_translation = 1;
12428 else
12429 {
12430 clib_warning ("parse error '%U'", format_unformat_error, i);
12431 return -99;
12432 }
12433 }
12434
Ole Troan07e7eab2016-08-25 00:24:08 +020012435 if (num_m_args < 3)
Dave Barach72d72232016-08-04 10:15:08 -040012436 {
12437 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012438 return -99;
12439 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012440
12441 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012442 M (MAP_ADD_DOMAIN, map_add_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012443
Dave Barach72d72232016-08-04 10:15:08 -040012444 clib_memcpy (mp->ip4_prefix, &ip4_prefix, sizeof (ip4_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012445 mp->ip4_prefix_len = ip4_prefix_len;
12446
Dave Barach72d72232016-08-04 10:15:08 -040012447 clib_memcpy (mp->ip6_prefix, &ip6_prefix, sizeof (ip6_prefix));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012448 mp->ip6_prefix_len = ip6_prefix_len;
12449
Dave Barach72d72232016-08-04 10:15:08 -040012450 clib_memcpy (mp->ip6_src, &ip6_src, sizeof (ip6_src));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012451 mp->ip6_src_prefix_len = ip6_src_len;
12452
12453 mp->ea_bits_len = ea_bits_len;
12454 mp->psid_offset = psid_offset;
12455 mp->psid_length = psid_length;
12456 mp->is_translation = is_translation;
Dave Barach72d72232016-08-04 10:15:08 -040012457 mp->mtu = htons (mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012458
12459 /* send it... */
12460 S;
12461
12462 /* Wait for a reply, return good/bad news */
12463 W;
12464}
12465
Dave Barach72d72232016-08-04 10:15:08 -040012466static int
12467api_map_del_domain (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012468{
12469 unformat_input_t *i = vam->input;
12470 vl_api_map_del_domain_t *mp;
12471 f64 timeout;
12472
12473 u32 num_m_args = 0;
12474 u32 index;
12475
Dave Barach72d72232016-08-04 10:15:08 -040012476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12477 {
12478 if (unformat (i, "index %d", &index))
12479 num_m_args++;
12480 else
12481 {
12482 clib_warning ("parse error '%U'", format_unformat_error, i);
12483 return -99;
12484 }
12485 }
12486
12487 if (num_m_args != 1)
12488 {
12489 errmsg ("mandatory argument(s) missing\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070012490 return -99;
12491 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012492
12493 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012494 M (MAP_DEL_DOMAIN, map_del_domain);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012495
Dave Barach72d72232016-08-04 10:15:08 -040012496 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012497
12498 /* send it... */
12499 S;
12500
12501 /* Wait for a reply, return good/bad news */
12502 W;
12503}
12504
Dave Barach72d72232016-08-04 10:15:08 -040012505static int
12506api_map_add_del_rule (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012507{
12508 unformat_input_t *i = vam->input;
12509 vl_api_map_add_del_rule_t *mp;
12510 f64 timeout;
12511 u8 is_add = 1;
12512 ip6_address_t ip6_dst;
Dave Barach839fe3e2016-08-10 11:35:54 -040012513 u32 num_m_args = 0, index, psid = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012514
Dave Barach72d72232016-08-04 10:15:08 -040012515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12516 {
12517 if (unformat (i, "index %d", &index))
12518 num_m_args++;
12519 else if (unformat (i, "psid %d", &psid))
12520 num_m_args++;
12521 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
12522 num_m_args++;
12523 else if (unformat (i, "del"))
12524 {
12525 is_add = 0;
12526 }
12527 else
12528 {
12529 clib_warning ("parse error '%U'", format_unformat_error, i);
12530 return -99;
12531 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012532 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012533
12534 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040012535 M (MAP_ADD_DEL_RULE, map_add_del_rule);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012536
Dave Barach72d72232016-08-04 10:15:08 -040012537 mp->index = ntohl (index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012538 mp->is_add = is_add;
Dave Barach72d72232016-08-04 10:15:08 -040012539 clib_memcpy (mp->ip6_dst, &ip6_dst, sizeof (ip6_dst));
12540 mp->psid = ntohs (psid);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012541
12542 /* send it... */
12543 S;
12544
12545 /* Wait for a reply, return good/bad news */
12546 W;
12547}
12548
Dave Barach72d72232016-08-04 10:15:08 -040012549static int
12550api_map_domain_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012551{
Dave Barach72d72232016-08-04 10:15:08 -040012552 vl_api_map_domain_dump_t *mp;
12553 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012554
Dave Barach72d72232016-08-04 10:15:08 -040012555 /* Construct the API message */
12556 M (MAP_DOMAIN_DUMP, map_domain_dump);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012557
Dave Barach72d72232016-08-04 10:15:08 -040012558 /* send it... */
12559 S;
12560
12561 /* Use a control ping for synchronization */
12562 {
12563 vl_api_control_ping_t *mp;
12564 M (CONTROL_PING, control_ping);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012565 S;
Dave Barach72d72232016-08-04 10:15:08 -040012566 }
12567 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012568}
12569
Dave Barach72d72232016-08-04 10:15:08 -040012570static int
12571api_map_rule_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012572{
Dave Barach72d72232016-08-04 10:15:08 -040012573 unformat_input_t *i = vam->input;
12574 vl_api_map_rule_dump_t *mp;
12575 f64 timeout;
12576 u32 domain_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012577
Dave Barach72d72232016-08-04 10:15:08 -040012578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012579 {
Dave Barach72d72232016-08-04 10:15:08 -040012580 if (unformat (i, "index %u", &domain_index))
12581 ;
12582 else
12583 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012584 }
Dave Barach72d72232016-08-04 10:15:08 -040012585
12586 if (domain_index == ~0)
12587 {
12588 clib_warning ("parse error: domain index expected");
12589 return -99;
12590 }
12591
12592 /* Construct the API message */
12593 M (MAP_RULE_DUMP, map_rule_dump);
12594
12595 mp->domain_index = htonl (domain_index);
12596
12597 /* send it... */
12598 S;
12599
12600 /* Use a control ping for synchronization */
12601 {
12602 vl_api_control_ping_t *mp;
12603 M (CONTROL_PING, control_ping);
12604 S;
12605 }
12606 W;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012607}
12608
12609static void vl_api_map_add_domain_reply_t_handler
Dave Barach72d72232016-08-04 10:15:08 -040012610 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012611{
Dave Barach72d72232016-08-04 10:15:08 -040012612 vat_main_t *vam = &vat_main;
12613 i32 retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012614
Dave Barach72d72232016-08-04 10:15:08 -040012615 if (vam->async_mode)
12616 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012617 vam->async_errors += (retval < 0);
Dave Barach72d72232016-08-04 10:15:08 -040012618 }
12619 else
12620 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070012621 vam->retval = retval;
12622 vam->result_ready = 1;
Dave Barach72d72232016-08-04 10:15:08 -040012623 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070012624}
12625
12626static void vl_api_map_add_domain_reply_t_handler_json
Dave Barach72d72232016-08-04 10:15:08 -040012627 (vl_api_map_add_domain_reply_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070012628{
Dave Barach72d72232016-08-04 10:15:08 -040012629 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012630 vat_json_node_t node;
12631
Dave Barach72d72232016-08-04 10:15:08 -040012632 vat_json_init_object (&node);
12633 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12634 vat_json_object_add_uint (&node, "index", ntohl (mp->index));
Ed Warnickecb9cada2015-12-08 15:45:58 -070012635
Dave Barach72d72232016-08-04 10:15:08 -040012636 vat_json_print (vam->ofp, &node);
12637 vat_json_free (&node);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012638
Dave Barach72d72232016-08-04 10:15:08 -040012639 vam->retval = ntohl (mp->retval);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012640 vam->result_ready = 1;
12641}
12642
12643static int
12644api_get_first_msg_id (vat_main_t * vam)
12645{
Dave Barach72d72232016-08-04 10:15:08 -040012646 vl_api_get_first_msg_id_t *mp;
12647 f64 timeout;
12648 unformat_input_t *i = vam->input;
12649 u8 *name;
12650 u8 name_set = 0;
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012651
Dave Barach72d72232016-08-04 10:15:08 -040012652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12653 {
12654 if (unformat (i, "client %s", &name))
12655 name_set = 1;
12656 else
12657 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012658 }
12659
Dave Barach72d72232016-08-04 10:15:08 -040012660 if (name_set == 0)
12661 {
12662 errmsg ("missing client name\n");
12663 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012664 }
Dave Barach72d72232016-08-04 10:15:08 -040012665 vec_add1 (name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070012666
Dave Barach72d72232016-08-04 10:15:08 -040012667 if (vec_len (name) > 63)
12668 {
12669 errmsg ("client name too long\n");
12670 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012671 }
12672
Dave Barach72d72232016-08-04 10:15:08 -040012673 M (GET_FIRST_MSG_ID, get_first_msg_id);
12674 clib_memcpy (mp->name, name, vec_len (name));
12675 S;
12676 W;
12677 /* NOTREACHED */
12678 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070012679}
12680
Dave Barach72d72232016-08-04 10:15:08 -040012681static int
12682api_cop_interface_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012683{
Dave Barach72d72232016-08-04 10:15:08 -040012684 unformat_input_t *line_input = vam->input;
12685 vl_api_cop_interface_enable_disable_t *mp;
12686 f64 timeout;
12687 u32 sw_if_index = ~0;
12688 u8 enable_disable = 1;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012689
Dave Barach72d72232016-08-04 10:15:08 -040012690 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12691 {
12692 if (unformat (line_input, "disable"))
12693 enable_disable = 0;
12694 if (unformat (line_input, "enable"))
12695 enable_disable = 1;
12696 else if (unformat (line_input, "%U", unformat_sw_if_index,
12697 vam, &sw_if_index))
12698 ;
12699 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12700 ;
12701 else
12702 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012703 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012704
Dave Barach72d72232016-08-04 10:15:08 -040012705 if (sw_if_index == ~0)
12706 {
12707 errmsg ("missing interface name or sw_if_index\n");
12708 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012709 }
12710
Dave Barach72d72232016-08-04 10:15:08 -040012711 /* Construct the API message */
12712 M (COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
12713 mp->sw_if_index = ntohl (sw_if_index);
12714 mp->enable_disable = enable_disable;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012715
Dave Barach72d72232016-08-04 10:15:08 -040012716 /* send it... */
12717 S;
12718 /* Wait for the reply */
12719 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012720}
12721
Dave Barach72d72232016-08-04 10:15:08 -040012722static int
12723api_cop_whitelist_enable_disable (vat_main_t * vam)
Dave Barachc07bf5d2016-02-17 17:52:26 -050012724{
Dave Barach72d72232016-08-04 10:15:08 -040012725 unformat_input_t *line_input = vam->input;
12726 vl_api_cop_whitelist_enable_disable_t *mp;
12727 f64 timeout;
12728 u32 sw_if_index = ~0;
12729 u8 ip4 = 0, ip6 = 0, default_cop = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040012730 u32 fib_id = 0;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012731
Dave Barach72d72232016-08-04 10:15:08 -040012732 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12733 {
12734 if (unformat (line_input, "ip4"))
12735 ip4 = 1;
12736 else if (unformat (line_input, "ip6"))
12737 ip6 = 1;
12738 else if (unformat (line_input, "default"))
12739 default_cop = 1;
12740 else if (unformat (line_input, "%U", unformat_sw_if_index,
12741 vam, &sw_if_index))
12742 ;
12743 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
12744 ;
12745 else if (unformat (line_input, "fib-id %d", &fib_id))
12746 ;
12747 else
12748 break;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012749 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080012750
Dave Barach72d72232016-08-04 10:15:08 -040012751 if (sw_if_index == ~0)
12752 {
12753 errmsg ("missing interface name or sw_if_index\n");
12754 return -99;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012755 }
12756
Dave Barach72d72232016-08-04 10:15:08 -040012757 /* Construct the API message */
12758 M (COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
12759 mp->sw_if_index = ntohl (sw_if_index);
12760 mp->fib_id = ntohl (fib_id);
12761 mp->ip4 = ip4;
12762 mp->ip6 = ip6;
12763 mp->default_cop = default_cop;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012764
Dave Barach72d72232016-08-04 10:15:08 -040012765 /* send it... */
12766 S;
12767 /* Wait for the reply */
12768 W;
Dave Barachc07bf5d2016-02-17 17:52:26 -050012769}
12770
Dave Barach72d72232016-08-04 10:15:08 -040012771static int
12772api_get_node_graph (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050012773{
Dave Barach72d72232016-08-04 10:15:08 -040012774 vl_api_get_node_graph_t *mp;
12775 f64 timeout;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012776
Dave Barach72d72232016-08-04 10:15:08 -040012777 M (GET_NODE_GRAPH, get_node_graph);
Dave Barachb44e9bc2016-02-19 09:06:23 -050012778
Dave Barach72d72232016-08-04 10:15:08 -040012779 /* send it... */
12780 S;
12781 /* Wait for the reply */
12782 W;
Dave Barachb44e9bc2016-02-19 09:06:23 -050012783}
12784
Dave Barach72d72232016-08-04 10:15:08 -040012785/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020012786/** Used for parsing LISP eids */
12787typedef CLIB_PACKED(struct{
12788 u8 addr[16]; /**< eid address */
12789 u32 len; /**< prefix length if IP */
12790 u8 type; /**< type of eid */
12791}) lisp_eid_vat_t;
Dave Barach72d72232016-08-04 10:15:08 -040012792/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020012793
12794static uword
12795unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
12796{
Dave Barach72d72232016-08-04 10:15:08 -040012797 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
Florin Coras429e7952016-08-02 02:31:03 +020012798
Dave Barach72d72232016-08-04 10:15:08 -040012799 memset (a, 0, sizeof (a[0]));
Florin Coras429e7952016-08-02 02:31:03 +020012800
Dave Barach72d72232016-08-04 10:15:08 -040012801 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
12802 {
12803 a->type = 0; /* ipv4 type */
12804 }
12805 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
12806 {
12807 a->type = 1; /* ipv6 type */
12808 }
12809 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
12810 {
12811 a->type = 2; /* mac type */
12812 }
12813 else
12814 {
Florin Coras429e7952016-08-02 02:31:03 +020012815 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012816 }
Florin Coras429e7952016-08-02 02:31:03 +020012817
Dave Barach72d72232016-08-04 10:15:08 -040012818 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
12819 {
Florin Coras429e7952016-08-02 02:31:03 +020012820 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040012821 }
Florin Coras429e7952016-08-02 02:31:03 +020012822
12823 return 1;
12824}
12825
12826static int
12827lisp_eid_size_vat (u8 type)
12828{
Dave Barach72d72232016-08-04 10:15:08 -040012829 switch (type)
12830 {
Florin Coras429e7952016-08-02 02:31:03 +020012831 case 0:
12832 return 4;
12833 case 1:
12834 return 16;
12835 case 2:
12836 return 6;
Dave Barach72d72232016-08-04 10:15:08 -040012837 }
Florin Coras429e7952016-08-02 02:31:03 +020012838 return 0;
12839}
12840
12841static void
12842lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
12843{
Dave Barach72d72232016-08-04 10:15:08 -040012844 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
Florin Coras429e7952016-08-02 02:31:03 +020012845}
12846
Dave Barach72d72232016-08-04 10:15:08 -040012847/* *INDENT-OFF* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012848/** Used for transferring locators via VPP API */
12849typedef CLIB_PACKED(struct
12850{
Dave Barach72d72232016-08-04 10:15:08 -040012851 u32 sw_if_index; /**< locator sw_if_index */
12852 u8 priority; /**< locator priority */
12853 u8 weight; /**< locator weight */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012854}) ls_locator_t;
Dave Barach72d72232016-08-04 10:15:08 -040012855/* *INDENT-ON* */
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012856
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012857static int
Dave Barach72d72232016-08-04 10:15:08 -040012858api_lisp_add_del_locator_set (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012859{
Dave Barach72d72232016-08-04 10:15:08 -040012860 unformat_input_t *input = vam->input;
12861 vl_api_lisp_add_del_locator_set_t *mp;
12862 f64 timeout = ~0;
12863 u8 is_add = 1;
12864 u8 *locator_set_name = NULL;
12865 u8 locator_set_name_set = 0;
12866 ls_locator_t locator, *locators = 0;
12867 u32 sw_if_index, priority, weight;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012868 u32 data_len = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012869
Dave Barach72d72232016-08-04 10:15:08 -040012870 /* Parse args required to build the message */
12871 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12872 {
12873 if (unformat (input, "del"))
12874 {
12875 is_add = 0;
12876 }
12877 else if (unformat (input, "locator-set %s", &locator_set_name))
12878 {
12879 locator_set_name_set = 1;
12880 }
12881 else if (unformat (input, "sw_if_index %u p %u w %u",
12882 &sw_if_index, &priority, &weight))
12883 {
12884 locator.sw_if_index = htonl (sw_if_index);
12885 locator.priority = priority;
12886 locator.weight = weight;
12887 vec_add1 (locators, locator);
12888 }
12889 else if (unformat (input, "iface %U p %u w %u", unformat_sw_if_index,
12890 vam, &sw_if_index, &priority, &weight))
12891 {
12892 locator.sw_if_index = htonl (sw_if_index);
12893 locator.priority = priority;
12894 locator.weight = weight;
12895 vec_add1 (locators, locator);
12896 }
12897 else
12898 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012899 }
12900
Dave Barach72d72232016-08-04 10:15:08 -040012901 if (locator_set_name_set == 0)
12902 {
12903 errmsg ("missing locator-set name");
12904 vec_free (locators);
12905 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012906 }
12907
Dave Barach72d72232016-08-04 10:15:08 -040012908 if (vec_len (locator_set_name) > 64)
12909 {
12910 errmsg ("locator-set name too long\n");
12911 vec_free (locator_set_name);
12912 vec_free (locators);
12913 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012914 }
Dave Barach72d72232016-08-04 10:15:08 -040012915 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012916
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012917 data_len = sizeof (ls_locator_t) * vec_len (locators);
12918
Dave Barach72d72232016-08-04 10:15:08 -040012919 /* Construct the API message */
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012920 M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012921
Dave Barach72d72232016-08-04 10:15:08 -040012922 mp->is_add = is_add;
12923 clib_memcpy (mp->locator_set_name, locator_set_name,
12924 vec_len (locator_set_name));
12925 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012926
Filip Tehlare3552c42016-08-26 12:44:38 +020012927 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
Dave Barach839fe3e2016-08-10 11:35:54 -040012928 if (locators)
Filip Tehlar3fa0af52016-09-27 13:28:01 +020012929 clib_memcpy (mp->locators, locators, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040012930 vec_free (locators);
Andrej Kozemcaka8691752016-07-27 10:33:38 +020012931
Dave Barach72d72232016-08-04 10:15:08 -040012932 /* send it... */
12933 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012934
Dave Barach72d72232016-08-04 10:15:08 -040012935 /* Wait for a reply... */
12936 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012937
Dave Barach72d72232016-08-04 10:15:08 -040012938 /* NOTREACHED */
12939 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012940}
12941
12942static int
Dave Barach72d72232016-08-04 10:15:08 -040012943api_lisp_add_del_locator (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012944{
Dave Barach72d72232016-08-04 10:15:08 -040012945 unformat_input_t *input = vam->input;
12946 vl_api_lisp_add_del_locator_t *mp;
12947 f64 timeout = ~0;
12948 u32 tmp_if_index = ~0;
12949 u32 sw_if_index = ~0;
12950 u8 sw_if_index_set = 0;
12951 u8 sw_if_index_if_name_set = 0;
12952 u32 priority = ~0;
12953 u8 priority_set = 0;
12954 u32 weight = ~0;
12955 u8 weight_set = 0;
12956 u8 is_add = 1;
12957 u8 *locator_set_name = NULL;
12958 u8 locator_set_name_set = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012959
Dave Barach72d72232016-08-04 10:15:08 -040012960 /* Parse args required to build the message */
12961 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12962 {
12963 if (unformat (input, "del"))
12964 {
12965 is_add = 0;
12966 }
12967 else if (unformat (input, "locator-set %s", &locator_set_name))
12968 {
12969 locator_set_name_set = 1;
12970 }
12971 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
12972 &tmp_if_index))
12973 {
12974 sw_if_index_if_name_set = 1;
12975 sw_if_index = tmp_if_index;
12976 }
12977 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
12978 {
12979 sw_if_index_set = 1;
12980 sw_if_index = tmp_if_index;
12981 }
12982 else if (unformat (input, "p %d", &priority))
12983 {
12984 priority_set = 1;
12985 }
12986 else if (unformat (input, "w %d", &weight))
12987 {
12988 weight_set = 1;
12989 }
12990 else
12991 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012992 }
12993
Dave Barach72d72232016-08-04 10:15:08 -040012994 if (locator_set_name_set == 0)
12995 {
12996 errmsg ("missing locator-set name");
12997 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020012998 }
12999
Dave Barach72d72232016-08-04 10:15:08 -040013000 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
13001 {
13002 errmsg ("missing sw_if_index");
13003 vec_free (locator_set_name);
13004 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013005 }
13006
Dave Barach72d72232016-08-04 10:15:08 -040013007 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
13008 {
13009 errmsg ("cannot use both params interface name and sw_if_index");
13010 vec_free (locator_set_name);
13011 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013012 }
13013
Dave Barach72d72232016-08-04 10:15:08 -040013014 if (priority_set == 0)
13015 {
13016 errmsg ("missing locator-set priority\n");
13017 vec_free (locator_set_name);
13018 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013019 }
13020
Dave Barach72d72232016-08-04 10:15:08 -040013021 if (weight_set == 0)
13022 {
13023 errmsg ("missing locator-set weight\n");
13024 vec_free (locator_set_name);
13025 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013026 }
13027
Dave Barach72d72232016-08-04 10:15:08 -040013028 if (vec_len (locator_set_name) > 64)
13029 {
13030 errmsg ("locator-set name too long\n");
13031 vec_free (locator_set_name);
13032 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013033 }
Dave Barach72d72232016-08-04 10:15:08 -040013034 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013035
Dave Barach72d72232016-08-04 10:15:08 -040013036 /* Construct the API message */
13037 M (LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013038
Dave Barach72d72232016-08-04 10:15:08 -040013039 mp->is_add = is_add;
13040 mp->sw_if_index = ntohl (sw_if_index);
13041 mp->priority = priority;
13042 mp->weight = weight;
13043 clib_memcpy (mp->locator_set_name, locator_set_name,
13044 vec_len (locator_set_name));
13045 vec_free (locator_set_name);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013046
Dave Barach72d72232016-08-04 10:15:08 -040013047 /* send it... */
13048 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013049
Dave Barach72d72232016-08-04 10:15:08 -040013050 /* Wait for a reply... */
13051 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013052
Dave Barach72d72232016-08-04 10:15:08 -040013053 /* NOTREACHED */
13054 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013055}
13056
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013057uword
13058unformat_hmac_key_id (unformat_input_t * input, va_list * args)
13059{
13060 u32 *key_id = va_arg (*args, u32 *);
13061 u8 *s = 0;
13062
13063 if (unformat (input, "%s", &s))
13064 {
13065 if (!strcmp ((char *) s, "sha1"))
13066 key_id[0] = HMAC_SHA_1_96;
13067 else if (!strcmp ((char *) s, "sha256"))
13068 key_id[0] = HMAC_SHA_256_128;
13069 else
13070 {
13071 clib_warning ("invalid key_id: '%s'", s);
13072 key_id[0] = HMAC_NO_KEY;
13073 }
13074 }
13075 else
13076 return 0;
13077
13078 vec_free (s);
13079 return 1;
13080}
13081
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013082static int
Dave Barach72d72232016-08-04 10:15:08 -040013083api_lisp_add_del_local_eid (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013084{
Dave Barach72d72232016-08-04 10:15:08 -040013085 unformat_input_t *input = vam->input;
13086 vl_api_lisp_add_del_local_eid_t *mp;
13087 f64 timeout = ~0;
13088 u8 is_add = 1;
13089 u8 eid_set = 0;
13090 lisp_eid_vat_t _eid, *eid = &_eid;
13091 u8 *locator_set_name = 0;
13092 u8 locator_set_name_set = 0;
13093 u32 vni = 0;
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013094 u16 key_id = 0;
13095 u8 *key = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013096
Dave Barach72d72232016-08-04 10:15:08 -040013097 /* Parse args required to build the message */
13098 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13099 {
13100 if (unformat (input, "del"))
13101 {
13102 is_add = 0;
13103 }
13104 else if (unformat (input, "vni %d", &vni))
13105 {
13106 ;
13107 }
13108 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
13109 {
13110 eid_set = 1;
13111 }
13112 else if (unformat (input, "locator-set %s", &locator_set_name))
13113 {
13114 locator_set_name_set = 1;
13115 }
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013116 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
13117 ;
13118 else if (unformat (input, "secret-key %_%v%_", &key))
13119 ;
Dave Barach72d72232016-08-04 10:15:08 -040013120 else
13121 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013122 }
13123
Dave Barach72d72232016-08-04 10:15:08 -040013124 if (locator_set_name_set == 0)
13125 {
13126 errmsg ("missing locator-set name\n");
13127 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013128 }
13129
Dave Barach72d72232016-08-04 10:15:08 -040013130 if (0 == eid_set)
13131 {
13132 errmsg ("EID address not set!");
13133 vec_free (locator_set_name);
13134 return -99;
Filip Tehlar006eb262016-06-27 13:09:20 +020013135 }
13136
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013137 if (key && (0 == key_id))
13138 {
13139 errmsg ("invalid key_id!");
13140 return -99;
13141 }
13142
13143 if (vec_len (key) > 64)
13144 {
13145 errmsg ("key too long");
13146 vec_free (key);
13147 return -99;
13148 }
13149
Dave Barach72d72232016-08-04 10:15:08 -040013150 if (vec_len (locator_set_name) > 64)
13151 {
13152 errmsg ("locator-set name too long\n");
13153 vec_free (locator_set_name);
13154 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013155 }
Dave Barach72d72232016-08-04 10:15:08 -040013156 vec_add1 (locator_set_name, 0);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013157
Dave Barach72d72232016-08-04 10:15:08 -040013158 /* Construct the API message */
13159 M (LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013160
Dave Barach72d72232016-08-04 10:15:08 -040013161 mp->is_add = is_add;
13162 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
13163 mp->eid_type = eid->type;
13164 mp->prefix_len = eid->len;
13165 mp->vni = clib_host_to_net_u32 (vni);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013166 mp->key_id = clib_host_to_net_u16 (key_id);
Dave Barach72d72232016-08-04 10:15:08 -040013167 clib_memcpy (mp->locator_set_name, locator_set_name,
13168 vec_len (locator_set_name));
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013169 clib_memcpy (mp->key, key, vec_len (key));
Florin Coras429e7952016-08-02 02:31:03 +020013170
Dave Barach72d72232016-08-04 10:15:08 -040013171 vec_free (locator_set_name);
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013172 vec_free (key);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013173
Dave Barach72d72232016-08-04 10:15:08 -040013174 /* send it... */
13175 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013176
Dave Barach72d72232016-08-04 10:15:08 -040013177 /* Wait for a reply... */
13178 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013179
Dave Barach72d72232016-08-04 10:15:08 -040013180 /* NOTREACHED */
13181 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013182}
13183
Dave Barach72d72232016-08-04 10:15:08 -040013184/* *INDENT-OFF* */
Florin Coras429e7952016-08-02 02:31:03 +020013185/** Used for transferring locators via VPP API */
13186typedef CLIB_PACKED(struct
13187{
Dave Barach72d72232016-08-04 10:15:08 -040013188 u8 is_ip4; /**< is locator an IPv4 address? */
13189 u8 priority; /**< locator priority */
13190 u8 weight; /**< locator weight */
13191 u8 addr[16]; /**< IPv4/IPv6 address */
Florin Coras429e7952016-08-02 02:31:03 +020013192}) rloc_t;
Dave Barach72d72232016-08-04 10:15:08 -040013193/* *INDENT-ON* */
Florin Coras429e7952016-08-02 02:31:03 +020013194
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013195static int
Dave Barach72d72232016-08-04 10:15:08 -040013196api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013197{
Dave Barach72d72232016-08-04 10:15:08 -040013198 unformat_input_t *input = vam->input;
13199 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
13200 f64 timeout = ~0;
13201 u8 is_add = 1;
13202 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
13203 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
13204 u8 rmt_eid_set = 0, lcl_eid_set = 0;
13205 u32 action = ~0, p, w;
13206 ip4_address_t rmt_rloc4, lcl_rloc4;
13207 ip6_address_t rmt_rloc6, lcl_rloc6;
13208 rloc_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013209
Dave Barach839fe3e2016-08-10 11:35:54 -040013210 memset (&rloc, 0, sizeof (rloc));
Florin Coras7fbfad32016-08-05 16:57:33 +020013211
Dave Barach72d72232016-08-04 10:15:08 -040013212 /* Parse args required to build the message */
13213 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13214 {
13215 if (unformat (input, "del"))
13216 {
13217 is_add = 0;
13218 }
13219 else if (unformat (input, "rmt_eid %U", unformat_lisp_eid_vat, rmt_eid))
13220 {
13221 rmt_eid_set = 1;
13222 }
13223 else if (unformat (input, "lcl_eid %U", unformat_lisp_eid_vat, lcl_eid))
13224 {
13225 lcl_eid_set = 1;
13226 }
13227 else if (unformat (input, "p %d w %d", &p, &w))
13228 {
13229 if (!curr_rloc)
13230 {
13231 errmsg ("No RLOC configured for setting priority/weight!");
13232 return -99;
13233 }
13234 curr_rloc->priority = p;
13235 curr_rloc->weight = w;
13236 }
13237 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
13238 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
13239 {
13240 rloc.is_ip4 = 1;
Florin Coras7fbfad32016-08-05 16:57:33 +020013241
Dave Barach72d72232016-08-04 10:15:08 -040013242 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Florin Coras7fbfad32016-08-05 16:57:33 +020013243 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013244 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013245
Dave Barach72d72232016-08-04 10:15:08 -040013246 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
13247 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013248 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013249 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13250 }
Florin Coras7fbfad32016-08-05 16:57:33 +020013251 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
Dave Barach72d72232016-08-04 10:15:08 -040013252 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
13253 {
13254 rloc.is_ip4 = 0;
13255 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Florin Coras7fbfad32016-08-05 16:57:33 +020013256 rloc.priority = rloc.weight = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013257 vec_add1 (lcl_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013258
Dave Barach72d72232016-08-04 10:15:08 -040013259 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
13260 vec_add1 (rmt_locs, rloc);
Florin Coras7fbfad32016-08-05 16:57:33 +020013261 /* priority and weight saved in rmt loc */
Dave Barach72d72232016-08-04 10:15:08 -040013262 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
13263 }
13264 else if (unformat (input, "action %d", &action))
13265 {
13266 ;
13267 }
13268 else
13269 {
13270 clib_warning ("parse error '%U'", format_unformat_error, input);
13271 return -99;
13272 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013273 }
13274
Dave Barach72d72232016-08-04 10:15:08 -040013275 if (!rmt_eid_set)
13276 {
13277 errmsg ("remote eid addresses not set\n");
13278 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013279 }
13280
Dave Barach72d72232016-08-04 10:15:08 -040013281 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
13282 {
13283 errmsg ("eid types don't match\n");
13284 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013285 }
13286
Dave Barach839fe3e2016-08-10 11:35:54 -040013287 if (0 == rmt_locs && (u32) ~ 0 == action)
Florin Coras7fbfad32016-08-05 16:57:33 +020013288 {
13289 errmsg ("action not set for negative mapping\n");
13290 return -99;
13291 }
13292
Dave Barach72d72232016-08-04 10:15:08 -040013293 /* Construct the API message */
13294 M (LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013295
Dave Barach72d72232016-08-04 10:15:08 -040013296 mp->is_add = is_add;
13297 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
13298 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
13299 mp->eid_type = rmt_eid->type;
13300 mp->rmt_len = rmt_eid->len;
13301 mp->lcl_len = lcl_eid->len;
13302 mp->action = action;
Florin Coras429e7952016-08-02 02:31:03 +020013303
Florin Coras7fbfad32016-08-05 16:57:33 +020013304 if (0 != rmt_locs && 0 != lcl_locs)
13305 {
Dave Barach839fe3e2016-08-10 11:35:54 -040013306 mp->loc_num = vec_len (rmt_locs);
Florin Coras7fbfad32016-08-05 16:57:33 +020013307 clib_memcpy (mp->lcl_locs, lcl_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013308 (sizeof (rloc_t) * vec_len (lcl_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013309 clib_memcpy (mp->rmt_locs, rmt_locs,
Dave Barach839fe3e2016-08-10 11:35:54 -040013310 (sizeof (rloc_t) * vec_len (rmt_locs)));
Florin Coras7fbfad32016-08-05 16:57:33 +020013311 }
Dave Barach72d72232016-08-04 10:15:08 -040013312 vec_free (lcl_locs);
13313 vec_free (rmt_locs);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013314
Dave Barach72d72232016-08-04 10:15:08 -040013315 /* send it... */
13316 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013317
Dave Barach72d72232016-08-04 10:15:08 -040013318 /* Wait for a reply... */
13319 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013320
Dave Barach72d72232016-08-04 10:15:08 -040013321 /* NOTREACHED */
13322 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013323}
13324
13325static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013326api_lisp_add_del_map_server (vat_main_t * vam)
13327{
13328 unformat_input_t *input = vam->input;
13329 vl_api_lisp_add_del_map_server_t *mp;
13330 f64 timeout = ~0;
13331 u8 is_add = 1;
13332 u8 ipv4_set = 0;
13333 u8 ipv6_set = 0;
13334 ip4_address_t ipv4;
13335 ip6_address_t ipv6;
13336
13337 /* Parse args required to build the message */
13338 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13339 {
13340 if (unformat (input, "del"))
13341 {
13342 is_add = 0;
13343 }
13344 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13345 {
13346 ipv4_set = 1;
13347 }
13348 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13349 {
13350 ipv6_set = 1;
13351 }
13352 else
13353 break;
13354 }
13355
13356 if (ipv4_set && ipv6_set)
13357 {
13358 errmsg ("both eid v4 and v6 addresses set\n");
13359 return -99;
13360 }
13361
13362 if (!ipv4_set && !ipv6_set)
13363 {
13364 errmsg ("eid addresses not set\n");
13365 return -99;
13366 }
13367
13368 /* Construct the API message */
13369 M (LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server);
13370
13371 mp->is_add = is_add;
13372 if (ipv6_set)
13373 {
13374 mp->is_ipv6 = 1;
13375 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13376 }
13377 else
13378 {
13379 mp->is_ipv6 = 0;
13380 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
13381 }
13382
13383 /* send it... */
13384 S;
13385
13386 /* Wait for a reply... */
13387 W;
13388
13389 /* NOTREACHED */
13390 return 0;
13391}
13392
13393static int
Dave Barach72d72232016-08-04 10:15:08 -040013394api_lisp_add_del_map_resolver (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013395{
Dave Barach72d72232016-08-04 10:15:08 -040013396 unformat_input_t *input = vam->input;
13397 vl_api_lisp_add_del_map_resolver_t *mp;
13398 f64 timeout = ~0;
13399 u8 is_add = 1;
13400 u8 ipv4_set = 0;
13401 u8 ipv6_set = 0;
13402 ip4_address_t ipv4;
13403 ip6_address_t ipv6;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013404
Dave Barach72d72232016-08-04 10:15:08 -040013405 /* Parse args required to build the message */
13406 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13407 {
13408 if (unformat (input, "del"))
13409 {
13410 is_add = 0;
13411 }
13412 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
13413 {
13414 ipv4_set = 1;
13415 }
13416 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
13417 {
13418 ipv6_set = 1;
13419 }
13420 else
13421 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013422 }
13423
Dave Barach72d72232016-08-04 10:15:08 -040013424 if (ipv4_set && ipv6_set)
13425 {
13426 errmsg ("both eid v4 and v6 addresses set\n");
13427 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013428 }
13429
Dave Barach72d72232016-08-04 10:15:08 -040013430 if (!ipv4_set && !ipv6_set)
13431 {
13432 errmsg ("eid addresses not set\n");
13433 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013434 }
13435
Dave Barach72d72232016-08-04 10:15:08 -040013436 /* Construct the API message */
13437 M (LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013438
Dave Barach72d72232016-08-04 10:15:08 -040013439 mp->is_add = is_add;
13440 if (ipv6_set)
13441 {
13442 mp->is_ipv6 = 1;
13443 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
13444 }
13445 else
13446 {
13447 mp->is_ipv6 = 0;
13448 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013449 }
13450
Dave Barach72d72232016-08-04 10:15:08 -040013451 /* send it... */
13452 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013453
Dave Barach72d72232016-08-04 10:15:08 -040013454 /* Wait for a reply... */
13455 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013456
Dave Barach72d72232016-08-04 10:15:08 -040013457 /* NOTREACHED */
13458 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020013459}
13460
13461static int
Florin Coras577c3552016-04-21 00:45:40 +020013462api_lisp_gpe_enable_disable (vat_main_t * vam)
13463{
Dave Barach72d72232016-08-04 10:15:08 -040013464 unformat_input_t *input = vam->input;
Florin Coras577c3552016-04-21 00:45:40 +020013465 vl_api_lisp_gpe_enable_disable_t *mp;
13466 f64 timeout = ~0;
13467 u8 is_set = 0;
13468 u8 is_en = 1;
13469
13470 /* Parse args required to build the message */
Dave Barach72d72232016-08-04 10:15:08 -040013471 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13472 {
13473 if (unformat (input, "enable"))
13474 {
13475 is_set = 1;
13476 is_en = 1;
13477 }
13478 else if (unformat (input, "disable"))
13479 {
13480 is_set = 1;
13481 is_en = 0;
13482 }
13483 else
13484 break;
13485 }
Florin Coras577c3552016-04-21 00:45:40 +020013486
Dave Barach72d72232016-08-04 10:15:08 -040013487 if (is_set == 0)
13488 {
13489 errmsg ("Value not set\n");
Florin Coras577c3552016-04-21 00:45:40 +020013490 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040013491 }
Florin Coras577c3552016-04-21 00:45:40 +020013492
13493 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013494 M (LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
Florin Coras577c3552016-04-21 00:45:40 +020013495
13496 mp->is_en = is_en;
13497
13498 /* send it... */
13499 S;
13500
13501 /* Wait for a reply... */
13502 W;
13503
13504 /* NOTREACHED */
13505 return 0;
13506}
13507
13508static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013509api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
13510{
13511 unformat_input_t *input = vam->input;
13512 vl_api_lisp_rloc_probe_enable_disable_t *mp;
13513 f64 timeout = ~0;
13514 u8 is_set = 0;
13515 u8 is_en = 0;
13516
13517 /* Parse args required to build the message */
13518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13519 {
13520 if (unformat (input, "enable"))
13521 {
13522 is_set = 1;
13523 is_en = 1;
13524 }
13525 else if (unformat (input, "disable"))
13526 is_set = 1;
13527 else
13528 break;
13529 }
13530
13531 if (!is_set)
13532 {
13533 errmsg ("Value not set\n");
13534 return -99;
13535 }
13536
13537 /* Construct the API message */
13538 M (LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable);
13539
13540 mp->is_enabled = is_en;
13541
13542 /* send it... */
13543 S;
13544
13545 /* Wait for a reply... */
13546 W;
13547
13548 /* NOTREACHED */
13549 return 0;
13550}
13551
13552static int
13553api_lisp_map_register_enable_disable (vat_main_t * vam)
13554{
13555 unformat_input_t *input = vam->input;
13556 vl_api_lisp_map_register_enable_disable_t *mp;
13557 f64 timeout = ~0;
13558 u8 is_set = 0;
13559 u8 is_en = 0;
13560
13561 /* Parse args required to build the message */
13562 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13563 {
13564 if (unformat (input, "enable"))
13565 {
13566 is_set = 1;
13567 is_en = 1;
13568 }
13569 else if (unformat (input, "disable"))
13570 is_set = 1;
13571 else
13572 break;
13573 }
13574
13575 if (!is_set)
13576 {
13577 errmsg ("Value not set\n");
13578 return -99;
13579 }
13580
13581 /* Construct the API message */
13582 M (LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable);
13583
13584 mp->is_enabled = is_en;
13585
13586 /* send it... */
13587 S;
13588
13589 /* Wait for a reply... */
13590 W;
13591
13592 /* NOTREACHED */
13593 return 0;
13594}
13595
13596static int
Filip Tehlar46d4e362016-05-09 09:39:26 +020013597api_lisp_enable_disable (vat_main_t * vam)
13598{
Dave Barach72d72232016-08-04 10:15:08 -040013599 unformat_input_t *input = vam->input;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013600 vl_api_lisp_enable_disable_t *mp;
13601 f64 timeout = ~0;
13602 u8 is_set = 0;
13603 u8 is_en = 0;
13604
13605 /* Parse args required to build the message */
13606 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13607 {
13608 if (unformat (input, "enable"))
Dave Barach72d72232016-08-04 10:15:08 -040013609 {
13610 is_set = 1;
13611 is_en = 1;
13612 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013613 else if (unformat (input, "disable"))
Dave Barach72d72232016-08-04 10:15:08 -040013614 {
13615 is_set = 1;
13616 }
Filip Tehlar46d4e362016-05-09 09:39:26 +020013617 else
Dave Barach72d72232016-08-04 10:15:08 -040013618 break;
Filip Tehlar46d4e362016-05-09 09:39:26 +020013619 }
13620
13621 if (!is_set)
13622 {
13623 errmsg ("Value not set\n");
13624 return -99;
13625 }
13626
13627 /* Construct the API message */
Dave Barach72d72232016-08-04 10:15:08 -040013628 M (LISP_ENABLE_DISABLE, lisp_enable_disable);
Filip Tehlar46d4e362016-05-09 09:39:26 +020013629
13630 mp->is_en = is_en;
13631
13632 /* send it... */
13633 S;
13634
13635 /* Wait for a reply... */
13636 W;
13637
13638 /* NOTREACHED */
13639 return 0;
13640}
13641
Florin Corasdca88042016-09-14 16:01:38 +020013642static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020013643api_show_lisp_map_register_state (vat_main_t * vam)
13644{
13645 f64 timeout = ~0;
13646 vl_api_show_lisp_map_register_state_t *mp;
13647
13648 M (SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state);
13649
13650 /* send */
13651 S;
13652
13653 /* wait for reply */
13654 W;
13655
13656 return 0;
13657}
13658
13659static int
13660api_show_lisp_rloc_probe_state (vat_main_t * vam)
13661{
13662 f64 timeout = ~0;
13663 vl_api_show_lisp_rloc_probe_state_t *mp;
13664
13665 M (SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state);
13666
13667 /* send */
13668 S;
13669
13670 /* wait for reply */
13671 W;
13672
13673 return 0;
13674}
13675
13676static int
Florin Corasdca88042016-09-14 16:01:38 +020013677api_show_lisp_map_request_mode (vat_main_t * vam)
13678{
13679 f64 timeout = ~0;
13680 vl_api_show_lisp_map_request_mode_t *mp;
13681
13682 M (SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode);
13683
13684 /* send */
13685 S;
13686
13687 /* wait for reply */
13688 W;
13689
13690 return 0;
13691}
13692
13693static int
13694api_lisp_map_request_mode (vat_main_t * vam)
13695{
13696 f64 timeout = ~0;
13697 unformat_input_t *input = vam->input;
13698 vl_api_lisp_map_request_mode_t *mp;
13699 u8 mode = 0;
13700
13701 /* Parse args required to build the message */
13702 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13703 {
13704 if (unformat (input, "dst-only"))
13705 mode = 0;
13706 else if (unformat (input, "src-dst"))
13707 mode = 1;
13708 else
13709 {
13710 errmsg ("parse error '%U'", format_unformat_error, input);
13711 return -99;
13712 }
13713 }
13714
13715 M (LISP_MAP_REQUEST_MODE, lisp_map_request_mode);
13716
13717 mp->mode = mode;
13718
13719 /* send */
13720 S;
13721
13722 /* wait for reply */
13723 W;
13724
13725 /* notreached */
13726 return 0;
13727}
13728
Filip Tehlar195bcee2016-05-13 17:37:35 +020013729/**
Filip Tehlar53f09e32016-05-19 14:25:44 +020013730 * Enable/disable LISP proxy ITR.
13731 *
13732 * @param vam vpp API test context
13733 * @return return code
13734 */
13735static int
13736api_lisp_pitr_set_locator_set (vat_main_t * vam)
13737{
13738 f64 timeout = ~0;
13739 u8 ls_name_set = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013740 unformat_input_t *input = vam->input;
13741 vl_api_lisp_pitr_set_locator_set_t *mp;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013742 u8 is_add = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013743 u8 *ls_name = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013744
13745 /* Parse args required to build the message */
13746 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13747 {
13748 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013749 is_add = 0;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013750 else if (unformat (input, "locator-set %s", &ls_name))
Dave Barach72d72232016-08-04 10:15:08 -040013751 ls_name_set = 1;
Filip Tehlar53f09e32016-05-19 14:25:44 +020013752 else
Dave Barach72d72232016-08-04 10:15:08 -040013753 {
13754 errmsg ("parse error '%U'", format_unformat_error, input);
13755 return -99;
13756 }
Filip Tehlar53f09e32016-05-19 14:25:44 +020013757 }
13758
13759 if (!ls_name_set)
13760 {
13761 errmsg ("locator-set name not set!");
13762 return -99;
13763 }
13764
Dave Barach72d72232016-08-04 10:15:08 -040013765 M (LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
Filip Tehlar53f09e32016-05-19 14:25:44 +020013766
13767 mp->is_add = is_add;
13768 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
13769 vec_free (ls_name);
13770
13771 /* send */
13772 S;
13773
13774 /* wait for reply */
13775 W;
13776
Dave Barach72d72232016-08-04 10:15:08 -040013777 /* notreached */
Filip Tehlar53f09e32016-05-19 14:25:44 +020013778 return 0;
13779}
13780
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013781static int
13782api_show_lisp_pitr (vat_main_t * vam)
13783{
Dave Barach72d72232016-08-04 10:15:08 -040013784 vl_api_show_lisp_pitr_t *mp;
13785 f64 timeout = ~0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013786
Dave Barach72d72232016-08-04 10:15:08 -040013787 if (!vam->json_output)
13788 {
13789 fformat (vam->ofp, "%=20s\n", "lisp status:");
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013790 }
13791
Dave Barach72d72232016-08-04 10:15:08 -040013792 M (SHOW_LISP_PITR, show_lisp_pitr);
13793 /* send it... */
13794 S;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013795
Dave Barach72d72232016-08-04 10:15:08 -040013796 /* Wait for a reply... */
13797 W;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013798
Dave Barach72d72232016-08-04 10:15:08 -040013799 /* NOTREACHED */
13800 return 0;
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020013801}
13802
Filip Tehlar53f09e32016-05-19 14:25:44 +020013803/**
Filip Tehlar324112f2016-06-02 16:07:38 +020013804 * Add/delete mapping between vni and vrf
13805 */
13806static int
13807api_lisp_eid_table_add_del_map (vat_main_t * vam)
13808{
13809 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040013810 unformat_input_t *input = vam->input;
Filip Tehlar324112f2016-06-02 16:07:38 +020013811 vl_api_lisp_eid_table_add_del_map_t *mp;
Florin Coras1a1adc72016-07-22 01:45:30 +020013812 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
13813 u32 vni, vrf, bd_index;
Filip Tehlar324112f2016-06-02 16:07:38 +020013814
13815 /* Parse args required to build the message */
13816 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13817 {
13818 if (unformat (input, "del"))
Dave Barach72d72232016-08-04 10:15:08 -040013819 is_add = 0;
13820 else if (unformat (input, "vrf %d", &vrf))
13821 vrf_set = 1;
13822 else if (unformat (input, "bd_index %d", &bd_index))
13823 bd_index_set = 1;
13824 else if (unformat (input, "vni %d", &vni))
13825 vni_set = 1;
Filip Tehlar324112f2016-06-02 16:07:38 +020013826 else
Dave Barach72d72232016-08-04 10:15:08 -040013827 break;
Filip Tehlar324112f2016-06-02 16:07:38 +020013828 }
13829
Florin Coras1a1adc72016-07-22 01:45:30 +020013830 if (!vni_set || (!vrf_set && !bd_index_set))
Filip Tehlar324112f2016-06-02 16:07:38 +020013831 {
13832 errmsg ("missing arguments!");
13833 return -99;
13834 }
13835
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013836 if (vrf_set && bd_index_set)
13837 {
13838 errmsg ("error: both vrf and bd entered!");
13839 return -99;
13840 }
13841
Dave Barach72d72232016-08-04 10:15:08 -040013842 M (LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
Filip Tehlar324112f2016-06-02 16:07:38 +020013843
13844 mp->is_add = is_add;
13845 mp->vni = htonl (vni);
Filip Tehlar5a4e2dd2016-08-30 15:05:18 +020013846 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
Florin Coras1a1adc72016-07-22 01:45:30 +020013847 mp->is_l2 = bd_index_set;
Filip Tehlar324112f2016-06-02 16:07:38 +020013848
13849 /* send */
13850 S;
13851
13852 /* wait for reply */
13853 W;
13854
Dave Barach72d72232016-08-04 10:15:08 -040013855 /* notreached */
Filip Tehlar324112f2016-06-02 16:07:38 +020013856 return 0;
13857}
13858
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013859uword
13860unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
13861{
13862 u32 *action = va_arg (*args, u32 *);
13863 u8 *s = 0;
13864
13865 if (unformat (input, "%s", &s))
13866 {
13867 if (!strcmp ((char *) s, "no-action"))
13868 action[0] = 0;
13869 else if (!strcmp ((char *) s, "natively-forward"))
13870 action[0] = 1;
13871 else if (!strcmp ((char *) s, "send-map-request"))
13872 action[0] = 2;
13873 else if (!strcmp ((char *) s, "drop"))
13874 action[0] = 3;
13875 else
13876 {
13877 clib_warning ("invalid action: '%s'", s);
13878 action[0] = 3;
13879 }
13880 }
13881 else
13882 return 0;
13883
13884 vec_free (s);
13885 return 1;
13886}
13887
Filip Tehlar324112f2016-06-02 16:07:38 +020013888/**
Florin Corasf727db92016-06-23 15:01:58 +020013889 * Add/del remote mapping to/from LISP control plane
Filip Tehlar195bcee2016-05-13 17:37:35 +020013890 *
13891 * @param vam vpp API test context
13892 * @return return code
13893 */
13894static int
13895api_lisp_add_del_remote_mapping (vat_main_t * vam)
13896{
Dave Barach72d72232016-08-04 10:15:08 -040013897 unformat_input_t *input = vam->input;
13898 vl_api_lisp_add_del_remote_mapping_t *mp;
13899 f64 timeout = ~0;
13900 u32 vni = 0;
Dave Barach72d72232016-08-04 10:15:08 -040013901 lisp_eid_vat_t _eid, *eid = &_eid;
13902 lisp_eid_vat_t _seid, *seid = &_seid;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013903 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013904 u32 action = ~0, p, w, data_len;
Dave Barach72d72232016-08-04 10:15:08 -040013905 ip4_address_t rloc4;
13906 ip6_address_t rloc6;
13907 rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013908
Dave Barach839fe3e2016-08-10 11:35:54 -040013909 memset (&rloc, 0, sizeof (rloc));
13910
Dave Barach72d72232016-08-04 10:15:08 -040013911 /* Parse args required to build the message */
13912 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13913 {
13914 if (unformat (input, "del-all"))
13915 {
13916 del_all = 1;
13917 }
13918 else if (unformat (input, "del"))
13919 {
13920 is_add = 0;
13921 }
13922 else if (unformat (input, "add"))
13923 {
13924 is_add = 1;
13925 }
Filip Tehlarc9e08432016-09-22 15:30:01 +020013926 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
Dave Barach72d72232016-08-04 10:15:08 -040013927 {
13928 eid_set = 1;
13929 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013930 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
Dave Barach72d72232016-08-04 10:15:08 -040013931 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013932 seid_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040013933 }
13934 else if (unformat (input, "vni %d", &vni))
13935 {
13936 ;
13937 }
13938 else if (unformat (input, "p %d w %d", &p, &w))
13939 {
13940 if (!curr_rloc)
13941 {
13942 errmsg ("No RLOC configured for setting priority/weight!");
13943 return -99;
13944 }
13945 curr_rloc->priority = p;
13946 curr_rloc->weight = w;
13947 }
13948 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
13949 {
13950 rloc.is_ip4 = 1;
13951 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
13952 vec_add1 (rlocs, rloc);
13953 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13954 }
13955 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
13956 {
13957 rloc.is_ip4 = 0;
13958 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
13959 vec_add1 (rlocs, rloc);
13960 curr_rloc = &rlocs[vec_len (rlocs) - 1];
13961 }
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013962 else if (unformat (input, "action %U",
13963 unformat_negative_mapping_action, &action))
Dave Barach72d72232016-08-04 10:15:08 -040013964 {
13965 ;
13966 }
13967 else
13968 {
13969 clib_warning ("parse error '%U'", format_unformat_error, input);
13970 return -99;
13971 }
Filip Tehlar195bcee2016-05-13 17:37:35 +020013972 }
13973
Dave Barach72d72232016-08-04 10:15:08 -040013974 if (0 == eid_set)
13975 {
13976 errmsg ("missing params!");
13977 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013978 }
13979
Dave Barach72d72232016-08-04 10:15:08 -040013980 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
13981 {
13982 errmsg ("no action set for negative map-reply!");
13983 return -99;
Filip Tehlar195bcee2016-05-13 17:37:35 +020013984 }
13985
Filip Tehlar3fa0af52016-09-27 13:28:01 +020013986 data_len = vec_len (rlocs) * sizeof (rloc_t);
13987
13988 M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040013989 mp->is_add = is_add;
13990 mp->vni = htonl (vni);
13991 mp->action = (u8) action;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013992 mp->is_src_dst = seid_set;
Dave Barach72d72232016-08-04 10:15:08 -040013993 mp->eid_len = eid->len;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013994 mp->seid_len = seid->len;
Dave Barach72d72232016-08-04 10:15:08 -040013995 mp->del_all = del_all;
13996 mp->eid_type = eid->type;
13997 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020013998 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
Filip Tehlar195bcee2016-05-13 17:37:35 +020013999
Filip Tehlare3552c42016-08-26 12:44:38 +020014000 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
Filip Tehlar3fa0af52016-09-27 13:28:01 +020014001 clib_memcpy (mp->rlocs, rlocs, data_len);
Dave Barach72d72232016-08-04 10:15:08 -040014002 vec_free (rlocs);
Filip Tehlar195bcee2016-05-13 17:37:35 +020014003
Dave Barach72d72232016-08-04 10:15:08 -040014004 /* send it... */
14005 S;
Filip Tehlar195bcee2016-05-13 17:37:35 +020014006
Dave Barach72d72232016-08-04 10:15:08 -040014007 /* Wait for a reply... */
14008 W;
Filip Tehlar195bcee2016-05-13 17:37:35 +020014009
Dave Barach72d72232016-08-04 10:15:08 -040014010 /* NOTREACHED */
14011 return 0;
Filip Tehlar195bcee2016-05-13 17:37:35 +020014012}
14013
Florin Corasf727db92016-06-23 15:01:58 +020014014/**
14015 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
14016 * forwarding entries in data-plane accordingly.
14017 *
14018 * @param vam vpp API test context
14019 * @return return code
14020 */
14021static int
14022api_lisp_add_del_adjacency (vat_main_t * vam)
14023{
Dave Barach72d72232016-08-04 10:15:08 -040014024 unformat_input_t *input = vam->input;
14025 vl_api_lisp_add_del_adjacency_t *mp;
14026 f64 timeout = ~0;
14027 u32 vni = 0;
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014028 ip4_address_t leid4, reid4;
14029 ip6_address_t leid6, reid6;
14030 u8 reid_mac[6] = { 0 };
14031 u8 leid_mac[6] = { 0 };
14032 u8 reid_type, leid_type;
14033 u32 leid_len = 0, reid_len = 0, len;
Dave Barach72d72232016-08-04 10:15:08 -040014034 u8 is_add = 1;
Florin Corasf727db92016-06-23 15:01:58 +020014035
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014036 leid_type = reid_type = (u8) ~ 0;
Florin Corasf727db92016-06-23 15:01:58 +020014037
Dave Barach72d72232016-08-04 10:15:08 -040014038 /* Parse args required to build the message */
14039 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14040 {
14041 if (unformat (input, "del"))
14042 {
14043 is_add = 0;
14044 }
14045 else if (unformat (input, "add"))
14046 {
14047 is_add = 1;
14048 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014049 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
14050 &reid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014051 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014052 reid_type = 0; /* ipv4 */
14053 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014054 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014055 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
14056 &reid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014057 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014058 reid_type = 1; /* ipv6 */
14059 reid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014060 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014061 else if (unformat (input, "reid %U", unformat_ethernet_address,
14062 reid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040014063 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014064 reid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040014065 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014066 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
14067 &leid4, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014068 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014069 leid_type = 0; /* ipv4 */
14070 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014071 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014072 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
14073 &leid6, &len))
Dave Barach72d72232016-08-04 10:15:08 -040014074 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014075 leid_type = 1; /* ipv6 */
14076 leid_len = len;
Dave Barach72d72232016-08-04 10:15:08 -040014077 }
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014078 else if (unformat (input, "leid %U", unformat_ethernet_address,
14079 leid_mac))
Dave Barach72d72232016-08-04 10:15:08 -040014080 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014081 leid_type = 2; /* mac */
Dave Barach72d72232016-08-04 10:15:08 -040014082 }
14083 else if (unformat (input, "vni %d", &vni))
14084 {
14085 ;
14086 }
14087 else
14088 {
14089 errmsg ("parse error '%U'", format_unformat_error, input);
14090 return -99;
14091 }
Florin Corasf727db92016-06-23 15:01:58 +020014092 }
14093
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014094 if ((u8) ~ 0 == reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014095 {
14096 errmsg ("missing params!");
14097 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014098 }
14099
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014100 if (leid_type != reid_type)
Dave Barach72d72232016-08-04 10:15:08 -040014101 {
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014102 errmsg ("remote and local EIDs are of different types!");
Dave Barach72d72232016-08-04 10:15:08 -040014103 return -99;
Florin Corasf727db92016-06-23 15:01:58 +020014104 }
14105
Dave Barach72d72232016-08-04 10:15:08 -040014106 M (LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
14107 mp->is_add = is_add;
14108 mp->vni = htonl (vni);
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014109 mp->leid_len = leid_len;
14110 mp->reid_len = reid_len;
14111 mp->eid_type = reid_type;
Florin Corasf727db92016-06-23 15:01:58 +020014112
Dave Barach72d72232016-08-04 10:15:08 -040014113 switch (mp->eid_type)
14114 {
Florin Corasf727db92016-06-23 15:01:58 +020014115 case 0:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014116 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
14117 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
Dave Barach72d72232016-08-04 10:15:08 -040014118 break;
Florin Corasf727db92016-06-23 15:01:58 +020014119 case 1:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014120 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
14121 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
Dave Barach72d72232016-08-04 10:15:08 -040014122 break;
Florin Corasf727db92016-06-23 15:01:58 +020014123 case 2:
Filip Tehlar2fdaece2016-09-28 14:27:59 +020014124 clib_memcpy (mp->leid, leid_mac, 6);
14125 clib_memcpy (mp->reid, reid_mac, 6);
Dave Barach72d72232016-08-04 10:15:08 -040014126 break;
Florin Corasf727db92016-06-23 15:01:58 +020014127 default:
Dave Barach72d72232016-08-04 10:15:08 -040014128 errmsg ("unknown EID type %d!", mp->eid_type);
14129 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014130 }
14131
Dave Barach72d72232016-08-04 10:15:08 -040014132 /* send it... */
14133 S;
Florin Corasf727db92016-06-23 15:01:58 +020014134
Dave Barach72d72232016-08-04 10:15:08 -040014135 /* Wait for a reply... */
14136 W;
Florin Corasf727db92016-06-23 15:01:58 +020014137
Dave Barach72d72232016-08-04 10:15:08 -040014138 /* NOTREACHED */
14139 return 0;
Florin Corasf727db92016-06-23 15:01:58 +020014140}
14141
Filip Tehlar46d4e362016-05-09 09:39:26 +020014142static int
Dave Barach72d72232016-08-04 10:15:08 -040014143api_lisp_gpe_add_del_iface (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014144{
Dave Barach72d72232016-08-04 10:15:08 -040014145 unformat_input_t *input = vam->input;
14146 vl_api_lisp_gpe_add_del_iface_t *mp;
14147 f64 timeout = ~0;
Florin Coras7fbfad32016-08-05 16:57:33 +020014148 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
Dave Barach839fe3e2016-08-10 11:35:54 -040014149 u32 dp_table = 0, vni = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014150
Dave Barach72d72232016-08-04 10:15:08 -040014151 /* Parse args required to build the message */
14152 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14153 {
14154 if (unformat (input, "up"))
14155 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014156 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014157 is_add = 1;
14158 }
14159 else if (unformat (input, "down"))
14160 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014161 action_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014162 is_add = 0;
14163 }
14164 else if (unformat (input, "table_id %d", &dp_table))
14165 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014166 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014167 }
14168 else if (unformat (input, "bd_id %d", &dp_table))
14169 {
Dave Barach839fe3e2016-08-10 11:35:54 -040014170 dp_table_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014171 is_l2 = 1;
14172 }
14173 else if (unformat (input, "vni %d", &vni))
14174 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014175 vni_set = 1;
Dave Barach72d72232016-08-04 10:15:08 -040014176 }
14177 else
14178 break;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014179 }
14180
Florin Coras7fbfad32016-08-05 16:57:33 +020014181 if (action_set == 0)
Dave Barach72d72232016-08-04 10:15:08 -040014182 {
Florin Coras7fbfad32016-08-05 16:57:33 +020014183 errmsg ("Action not set\n");
14184 return -99;
14185 }
14186 if (dp_table_set == 0 || vni_set == 0)
14187 {
14188 errmsg ("vni and dp_table must be set\n");
Dave Barach72d72232016-08-04 10:15:08 -040014189 return -99;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014190 }
14191
Dave Barach72d72232016-08-04 10:15:08 -040014192 /* Construct the API message */
14193 M (LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014194
Dave Barach72d72232016-08-04 10:15:08 -040014195 mp->is_add = is_add;
14196 mp->dp_table = dp_table;
14197 mp->is_l2 = is_l2;
14198 mp->vni = vni;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014199
Dave Barach72d72232016-08-04 10:15:08 -040014200 /* send it... */
14201 S;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014202
Dave Barach72d72232016-08-04 10:15:08 -040014203 /* Wait for a reply... */
14204 W;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014205
Dave Barach72d72232016-08-04 10:15:08 -040014206 /* NOTREACHED */
14207 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014208}
14209
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014210/**
14211 * Add/del map request itr rlocs from LISP control plane and updates
14212 *
14213 * @param vam vpp API test context
14214 * @return return code
14215 */
14216static int
Dave Barach72d72232016-08-04 10:15:08 -040014217api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014218{
Dave Barach72d72232016-08-04 10:15:08 -040014219 unformat_input_t *input = vam->input;
14220 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
14221 f64 timeout = ~0;
14222 u8 *locator_set_name = 0;
14223 u8 locator_set_name_set = 0;
14224 u8 is_add = 1;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014225
Dave Barach72d72232016-08-04 10:15:08 -040014226 /* Parse args required to build the message */
14227 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014228 {
Dave Barach72d72232016-08-04 10:15:08 -040014229 if (unformat (input, "del"))
14230 {
14231 is_add = 0;
14232 }
14233 else if (unformat (input, "%_%v%_", &locator_set_name))
14234 {
14235 locator_set_name_set = 1;
14236 }
14237 else
14238 {
14239 clib_warning ("parse error '%U'", format_unformat_error, input);
14240 return -99;
14241 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014242 }
14243
Dave Barach72d72232016-08-04 10:15:08 -040014244 if (is_add && !locator_set_name_set)
14245 {
14246 errmsg ("itr-rloc is not set!");
Andrej Kozemcakd9831182016-06-20 08:47:57 +020014247 return -99;
14248 }
14249
Dave Barach72d72232016-08-04 10:15:08 -040014250 if (is_add && vec_len (locator_set_name) > 64)
Filip Tehlar2f653d02016-07-13 13:17:15 +020014251 {
Dave Barach72d72232016-08-04 10:15:08 -040014252 errmsg ("itr-rloc locator-set name too long\n");
14253 vec_free (locator_set_name);
14254 return -99;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014255 }
14256
Dave Barach72d72232016-08-04 10:15:08 -040014257 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
14258 mp->is_add = is_add;
14259 if (is_add)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014260 {
Dave Barach72d72232016-08-04 10:15:08 -040014261 clib_memcpy (mp->locator_set_name, locator_set_name,
14262 vec_len (locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014263 }
Dave Barach72d72232016-08-04 10:15:08 -040014264 else
14265 {
14266 memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014267 }
Dave Barach72d72232016-08-04 10:15:08 -040014268 vec_free (locator_set_name);
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014269
Dave Barach72d72232016-08-04 10:15:08 -040014270 /* send it... */
14271 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014272
Dave Barach72d72232016-08-04 10:15:08 -040014273 /* Wait for a reply... */
14274 W;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014275
Dave Barach72d72232016-08-04 10:15:08 -040014276 /* NOTREACHED */
14277 return 0;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014278}
14279
14280static int
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014281api_lisp_locator_dump (vat_main_t * vam)
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014282{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014283 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014284 vl_api_lisp_locator_dump_t *mp;
14285 f64 timeout = ~0;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014286 u8 is_index_set = 0, is_name_set = 0;
14287 u8 *ls_name = 0;
14288 u32 ls_index = ~0;
14289
14290 /* Parse args required to build the message */
14291 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14292 {
14293 if (unformat (input, "ls_name %_%v%_", &ls_name))
14294 {
14295 is_name_set = 1;
14296 }
14297 else if (unformat (input, "ls_index %d", &ls_index))
14298 {
14299 is_index_set = 1;
14300 }
14301 else
14302 {
14303 errmsg ("parse error '%U'", format_unformat_error, input);
14304 return -99;
14305 }
14306 }
14307
14308 if (!is_index_set && !is_name_set)
14309 {
14310 errmsg ("error: expected one of index or name!\n");
14311 return -99;
14312 }
14313
14314 if (is_index_set && is_name_set)
14315 {
14316 errmsg ("error: only one param expected!\n");
14317 return -99;
14318 }
14319
Florin Coras042d2122016-09-21 16:38:19 +020014320 if (vec_len (ls_name) > 62)
Filip Tehlarf07fb712016-09-20 12:37:09 +020014321 {
14322 errmsg ("error: locator set name too long!");
14323 return -99;
14324 }
14325
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014326 if (!vam->json_output)
14327 {
14328 fformat (vam->ofp, "%=16s%=16s%=16s\n", "locator", "priority",
14329 "weight");
14330 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014331
Dave Barach72d72232016-08-04 10:15:08 -040014332 M (LISP_LOCATOR_DUMP, lisp_locator_dump);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014333 mp->is_index_set = is_index_set;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014334
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014335 if (is_index_set)
14336 mp->ls_index = clib_host_to_net_u32 (ls_index);
14337 else
14338 {
14339 vec_add1 (ls_name, 0);
Florin Coras042d2122016-09-21 16:38:19 +020014340 strncpy ((char *) mp->ls_name, (char *) ls_name,
14341 sizeof (mp->ls_name) - 1);
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014342 }
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014343
Dave Barach72d72232016-08-04 10:15:08 -040014344 /* send it... */
14345 S;
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020014346
Dave Barach72d72232016-08-04 10:15:08 -040014347 /* Use a control ping for synchronization */
14348 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014349 vl_api_control_ping_t *mp;
14350 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014351 S;
14352 }
14353 /* Wait for a reply... */
14354 W;
Dave Barach72d72232016-08-04 10:15:08 -040014355
14356 /* NOTREACHED */
14357 return 0;
14358}
14359
14360static int
14361api_lisp_locator_set_dump (vat_main_t * vam)
14362{
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014363 vl_api_lisp_locator_set_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040014364 unformat_input_t *input = vam->input;
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014365 f64 timeout = ~0;
Dave Barach72d72232016-08-04 10:15:08 -040014366 u8 filter = 0;
Dave Barach72d72232016-08-04 10:15:08 -040014367
14368 /* Parse args required to build the message */
14369 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14370 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014371 if (unformat (input, "local"))
Dave Barach72d72232016-08-04 10:15:08 -040014372 {
14373 filter = 1;
14374 }
14375 else if (unformat (input, "remote"))
14376 {
14377 filter = 2;
14378 }
14379 else
14380 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014381 errmsg ("parse error '%U'", format_unformat_error, input);
14382 return -99;
Dave Barach72d72232016-08-04 10:15:08 -040014383 }
14384 }
14385
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014386 if (!vam->json_output)
Dave Barach72d72232016-08-04 10:15:08 -040014387 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014388 fformat (vam->ofp, "%=10s%=15s\n", "ls_index", "ls_name");
Dave Barach72d72232016-08-04 10:15:08 -040014389 }
14390
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014391 M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
Dave Barach72d72232016-08-04 10:15:08 -040014392
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014393 mp->filter = filter;
Dave Barach72d72232016-08-04 10:15:08 -040014394
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014395 /* send it... */
14396 S;
14397
14398 /* Use a control ping for synchronization */
14399 {
14400 vl_api_control_ping_t *mp;
14401 M (CONTROL_PING, control_ping);
14402 S;
14403 }
14404 /* Wait for a reply... */
14405 W;
14406
14407 /* NOTREACHED */
14408 return 0;
Dave Barach72d72232016-08-04 10:15:08 -040014409}
14410
14411static int
14412api_lisp_eid_table_map_dump (vat_main_t * vam)
14413{
Filip Tehlarc0681792016-08-24 14:11:07 +020014414 u8 is_l2 = 0;
14415 u8 mode_set = 0;
14416 unformat_input_t *input = vam->input;
Dave Barach72d72232016-08-04 10:15:08 -040014417 vl_api_lisp_eid_table_map_dump_t *mp;
14418 f64 timeout = ~0;
14419
Filip Tehlarc0681792016-08-24 14:11:07 +020014420 /* Parse args required to build the message */
14421 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
14422 {
14423 if (unformat (input, "l2"))
14424 {
14425 is_l2 = 1;
14426 mode_set = 1;
14427 }
14428 else if (unformat (input, "l3"))
14429 {
14430 is_l2 = 0;
14431 mode_set = 1;
14432 }
14433 else
14434 {
14435 errmsg ("parse error '%U'", format_unformat_error, input);
14436 return -99;
14437 }
14438 }
14439
14440 if (!mode_set)
14441 {
14442 errmsg ("expected one of 'l2' or 'l3' parameter!\n");
14443 return -99;
14444 }
14445
Dave Barach72d72232016-08-04 10:15:08 -040014446 if (!vam->json_output)
14447 {
Filip Tehlarc0681792016-08-24 14:11:07 +020014448 fformat (vam->ofp, "%=10s%=10s\n", "VNI", is_l2 ? "BD" : "VRF");
Dave Barach72d72232016-08-04 10:15:08 -040014449 }
14450
14451 M (LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
Filip Tehlarc0681792016-08-24 14:11:07 +020014452 mp->is_l2 = is_l2;
Dave Barach72d72232016-08-04 10:15:08 -040014453
14454 /* send it... */
14455 S;
14456
14457 /* Use a control ping for synchronization */
14458 {
14459 vl_api_control_ping_t *mp;
14460 M (CONTROL_PING, control_ping);
14461 S;
14462 }
14463 /* Wait for a reply... */
14464 W;
14465
14466 /* NOTREACHED */
14467 return 0;
14468}
14469
14470static int
Filip Tehlar50a4e142016-08-24 11:28:02 +020014471api_lisp_eid_table_vni_dump (vat_main_t * vam)
14472{
14473 vl_api_lisp_eid_table_vni_dump_t *mp;
14474 f64 timeout = ~0;
14475
14476 if (!vam->json_output)
14477 {
14478 fformat (vam->ofp, "VNI\n");
14479 }
14480
14481 M (LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump);
14482
14483 /* send it... */
14484 S;
14485
14486 /* Use a control ping for synchronization */
14487 {
14488 vl_api_control_ping_t *mp;
14489 M (CONTROL_PING, control_ping);
14490 S;
14491 }
14492 /* Wait for a reply... */
14493 W;
14494
14495 /* NOTREACHED */
14496 return 0;
14497}
14498
14499static int
Dave Barach72d72232016-08-04 10:15:08 -040014500api_lisp_eid_table_dump (vat_main_t * vam)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014501{
Dave Barach72d72232016-08-04 10:15:08 -040014502 unformat_input_t *i = vam->input;
14503 vl_api_lisp_eid_table_dump_t *mp;
14504 f64 timeout = ~0;
14505 struct in_addr ip4;
14506 struct in6_addr ip6;
14507 u8 mac[6];
14508 u8 eid_type = ~0, eid_set = 0;
14509 u32 prefix_length = ~0, t, vni = 0;
14510 u8 filter = 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014511
Dave Barach72d72232016-08-04 10:15:08 -040014512 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014513 {
Dave Barach72d72232016-08-04 10:15:08 -040014514 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
14515 {
14516 eid_set = 1;
14517 eid_type = 0;
14518 prefix_length = t;
14519 }
14520 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
14521 {
14522 eid_set = 1;
14523 eid_type = 1;
14524 prefix_length = t;
14525 }
14526 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
14527 {
14528 eid_set = 1;
14529 eid_type = 2;
14530 }
14531 else if (unformat (i, "vni %d", &t))
14532 {
14533 vni = t;
14534 }
14535 else if (unformat (i, "local"))
14536 {
14537 filter = 1;
14538 }
14539 else if (unformat (i, "remote"))
14540 {
14541 filter = 2;
14542 }
14543 else
14544 {
14545 errmsg ("parse error '%U'", format_unformat_error, i);
14546 return -99;
14547 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014548 }
14549
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014550 if (!vam->json_output)
14551 {
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014552 fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s\n", "EID",
14553 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014554 }
14555
Dave Barach72d72232016-08-04 10:15:08 -040014556 M (LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014557
Dave Barach72d72232016-08-04 10:15:08 -040014558 mp->filter = filter;
14559 if (eid_set)
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014560 {
Dave Barach72d72232016-08-04 10:15:08 -040014561 mp->eid_set = 1;
14562 mp->vni = htonl (vni);
14563 mp->eid_type = eid_type;
14564 switch (eid_type)
14565 {
14566 case 0:
14567 mp->prefix_length = prefix_length;
14568 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
14569 break;
14570 case 1:
14571 mp->prefix_length = prefix_length;
14572 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
14573 break;
14574 case 2:
14575 clib_memcpy (mp->eid, mac, sizeof (mac));
14576 break;
14577 default:
14578 errmsg ("unknown EID type %d!", eid_type);
14579 return -99;
14580 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014581 }
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014582
Dave Barach72d72232016-08-04 10:15:08 -040014583 /* send it... */
14584 S;
14585
14586 /* Use a control ping for synchronization */
14587 {
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014588 vl_api_control_ping_t *mp;
14589 M (CONTROL_PING, control_ping);
Dave Barach72d72232016-08-04 10:15:08 -040014590 S;
14591 }
14592
14593 /* Wait for a reply... */
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020014594 W;
Dave Barach72d72232016-08-04 10:15:08 -040014595
14596 /* NOTREACHED */
14597 return 0;
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020014598}
14599
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014600static int
Dave Barach72d72232016-08-04 10:15:08 -040014601api_lisp_gpe_tunnel_dump (vat_main_t * vam)
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014602{
Dave Barach72d72232016-08-04 10:15:08 -040014603 vl_api_lisp_gpe_tunnel_dump_t *mp;
14604 f64 timeout = ~0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014605
Dave Barach72d72232016-08-04 10:15:08 -040014606 if (!vam->json_output)
14607 {
14608 fformat (vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
14609 "%=16s%=16s%=16s%=16s%=16s\n",
14610 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
14611 "Decap next", "Lisp version", "Flags", "Next protocol",
14612 "ver_res", "res", "iid");
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014613 }
14614
Dave Barach72d72232016-08-04 10:15:08 -040014615 M (LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
14616 /* send it... */
14617 S;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014618
Dave Barach72d72232016-08-04 10:15:08 -040014619 /* Use a control ping for synchronization */
14620 {
14621 vl_api_control_ping_t *mp;
14622 M (CONTROL_PING, control_ping);
14623 S;
14624 }
14625 /* Wait for a reply... */
14626 W;
14627
14628 /* NOTREACHED */
14629 return 0;
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020014630}
14631
Matus Fabian8a95a482016-05-06 15:14:13 +020014632static int
Filip Tehlar69a9b762016-09-23 10:00:52 +020014633api_lisp_adjacencies_get (vat_main_t * vam)
14634{
14635 unformat_input_t *i = vam->input;
14636 vl_api_lisp_adjacencies_get_t *mp;
14637 f64 timeout = ~0;
14638 u8 vni_set = 0;
14639 u32 vni = ~0;
14640
14641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14642 {
14643 if (unformat (i, "vni %d", &vni))
14644 {
14645 vni_set = 1;
14646 }
14647 else
14648 {
14649 errmsg ("parse error '%U'\n", format_unformat_error, i);
14650 return -99;
14651 }
14652 }
14653
14654 if (!vni_set)
14655 {
14656 errmsg ("vni not set!\n");
14657 return -99;
14658 }
14659
14660 if (!vam->json_output)
14661 {
14662 fformat (vam->ofp, "%s %40s\n", "leid", "reid");
14663 }
14664
14665 M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
14666 mp->vni = clib_host_to_net_u32 (vni);
14667
14668 /* send it... */
14669 S;
14670
14671 /* Wait for a reply... */
14672 W;
14673
14674 /* NOTREACHED */
14675 return 0;
14676}
14677
14678static int
Filip Tehlar397fd7d2016-10-26 14:31:24 +020014679api_lisp_map_server_dump (vat_main_t * vam)
14680{
14681 vl_api_lisp_map_server_dump_t *mp;
14682 f64 timeout = ~0;
14683
14684 if (!vam->json_output)
14685 {
14686 fformat (vam->ofp, "%=20s\n", "Map server");
14687 }
14688
14689 M (LISP_MAP_SERVER_DUMP, lisp_map_server_dump);
14690 /* send it... */
14691 S;
14692
14693 /* Use a control ping for synchronization */
14694 {
14695 vl_api_control_ping_t *mp;
14696 M (CONTROL_PING, control_ping);
14697 S;
14698 }
14699 /* Wait for a reply... */
14700 W;
14701
14702 /* NOTREACHED */
14703 return 0;
14704}
14705
14706static int
Dave Barach72d72232016-08-04 10:15:08 -040014707api_lisp_map_resolver_dump (vat_main_t * vam)
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014708{
Dave Barach72d72232016-08-04 10:15:08 -040014709 vl_api_lisp_map_resolver_dump_t *mp;
14710 f64 timeout = ~0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014711
Dave Barach72d72232016-08-04 10:15:08 -040014712 if (!vam->json_output)
14713 {
14714 fformat (vam->ofp, "%=20s\n", "Map resolver");
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014715 }
14716
Dave Barach72d72232016-08-04 10:15:08 -040014717 M (LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
14718 /* send it... */
14719 S;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014720
Dave Barach72d72232016-08-04 10:15:08 -040014721 /* Use a control ping for synchronization */
14722 {
14723 vl_api_control_ping_t *mp;
14724 M (CONTROL_PING, control_ping);
14725 S;
14726 }
14727 /* Wait for a reply... */
14728 W;
14729
14730 /* NOTREACHED */
14731 return 0;
14732}
14733
14734static int
14735api_show_lisp_status (vat_main_t * vam)
14736{
14737 vl_api_show_lisp_status_t *mp;
14738 f64 timeout = ~0;
14739
14740 if (!vam->json_output)
14741 {
14742 fformat (vam->ofp, "%-20s%-16s\n", "lisp status", "locator-set");
14743 }
14744
14745 M (SHOW_LISP_STATUS, show_lisp_status);
14746 /* send it... */
14747 S;
14748 /* Wait for a reply... */
14749 W;
14750
14751 /* NOTREACHED */
14752 return 0;
14753}
14754
14755static int
14756api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
14757{
14758 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
14759 f64 timeout = ~0;
14760
14761 if (!vam->json_output)
14762 {
14763 fformat (vam->ofp, "%=20s\n", "itr-rlocs:");
14764 }
14765
14766 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
14767 /* send it... */
14768 S;
14769 /* Wait for a reply... */
14770 W;
14771
14772 /* NOTREACHED */
14773 return 0;
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020014774}
14775
14776static int
Matus Fabian8a95a482016-05-06 15:14:13 +020014777api_af_packet_create (vat_main_t * vam)
14778{
Dave Barach72d72232016-08-04 10:15:08 -040014779 unformat_input_t *i = vam->input;
14780 vl_api_af_packet_create_t *mp;
14781 f64 timeout;
14782 u8 *host_if_name = 0;
14783 u8 hw_addr[6];
14784 u8 random_hw_addr = 1;
Matus Fabian8a95a482016-05-06 15:14:13 +020014785
Dave Barach72d72232016-08-04 10:15:08 -040014786 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian8a95a482016-05-06 15:14:13 +020014787
Dave Barach72d72232016-08-04 10:15:08 -040014788 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14789 {
14790 if (unformat (i, "name %s", &host_if_name))
14791 vec_add1 (host_if_name, 0);
14792 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
14793 random_hw_addr = 0;
14794 else
14795 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014796 }
14797
Dave Barach72d72232016-08-04 10:15:08 -040014798 if (!vec_len (host_if_name))
14799 {
14800 errmsg ("host-interface name must be specified");
14801 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014802 }
14803
Dave Barach72d72232016-08-04 10:15:08 -040014804 if (vec_len (host_if_name) > 64)
14805 {
14806 errmsg ("host-interface name too long");
14807 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014808 }
14809
Dave Barach72d72232016-08-04 10:15:08 -040014810 M (AF_PACKET_CREATE, af_packet_create);
Matus Fabian8a95a482016-05-06 15:14:13 +020014811
Dave Barach72d72232016-08-04 10:15:08 -040014812 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14813 clib_memcpy (mp->hw_addr, hw_addr, 6);
14814 mp->use_random_hw_addr = random_hw_addr;
14815 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014816
Dave Barach72d72232016-08-04 10:15:08 -040014817 S;
14818 W2 (fprintf (vam->ofp, " new sw_if_index = %d ", vam->sw_if_index));
14819 /* NOTREACHED */
14820 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014821}
14822
14823static int
14824api_af_packet_delete (vat_main_t * vam)
14825{
Dave Barach72d72232016-08-04 10:15:08 -040014826 unformat_input_t *i = vam->input;
14827 vl_api_af_packet_delete_t *mp;
14828 f64 timeout;
14829 u8 *host_if_name = 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014830
Dave Barach72d72232016-08-04 10:15:08 -040014831 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14832 {
14833 if (unformat (i, "name %s", &host_if_name))
14834 vec_add1 (host_if_name, 0);
14835 else
14836 break;
Matus Fabian8a95a482016-05-06 15:14:13 +020014837 }
14838
Dave Barach72d72232016-08-04 10:15:08 -040014839 if (!vec_len (host_if_name))
14840 {
14841 errmsg ("host-interface name must be specified");
14842 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014843 }
14844
Dave Barach72d72232016-08-04 10:15:08 -040014845 if (vec_len (host_if_name) > 64)
14846 {
14847 errmsg ("host-interface name too long");
14848 return -99;
Matus Fabian8a95a482016-05-06 15:14:13 +020014849 }
14850
Dave Barach72d72232016-08-04 10:15:08 -040014851 M (AF_PACKET_DELETE, af_packet_delete);
Matus Fabian8a95a482016-05-06 15:14:13 +020014852
Dave Barach72d72232016-08-04 10:15:08 -040014853 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
14854 vec_free (host_if_name);
Matus Fabian8a95a482016-05-06 15:14:13 +020014855
Dave Barach72d72232016-08-04 10:15:08 -040014856 S;
14857 W;
14858 /* NOTREACHED */
14859 return 0;
Matus Fabian8a95a482016-05-06 15:14:13 +020014860}
14861
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014862static int
14863api_policer_add_del (vat_main_t * vam)
14864{
Dave Barach72d72232016-08-04 10:15:08 -040014865 unformat_input_t *i = vam->input;
14866 vl_api_policer_add_del_t *mp;
14867 f64 timeout;
14868 u8 is_add = 1;
14869 u8 *name = 0;
14870 u32 cir = 0;
14871 u32 eir = 0;
14872 u64 cb = 0;
14873 u64 eb = 0;
14874 u8 rate_type = 0;
14875 u8 round_type = 0;
14876 u8 type = 0;
14877 u8 color_aware = 0;
14878 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014879
Dave Barach839fe3e2016-08-10 11:35:54 -040014880 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
14881 conform_action.dscp = 0;
14882 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
14883 exceed_action.dscp = 0;
14884 violate_action.action_type = SSE2_QOS_ACTION_DROP;
14885 violate_action.dscp = 0;
14886
Dave Barach72d72232016-08-04 10:15:08 -040014887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14888 {
14889 if (unformat (i, "del"))
14890 is_add = 0;
14891 else if (unformat (i, "name %s", &name))
14892 vec_add1 (name, 0);
14893 else if (unformat (i, "cir %u", &cir))
14894 ;
14895 else if (unformat (i, "eir %u", &eir))
14896 ;
14897 else if (unformat (i, "cb %u", &cb))
14898 ;
14899 else if (unformat (i, "eb %u", &eb))
14900 ;
14901 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
14902 &rate_type))
14903 ;
14904 else if (unformat (i, "round_type %U", unformat_policer_round_type,
14905 &round_type))
14906 ;
14907 else if (unformat (i, "type %U", unformat_policer_type, &type))
14908 ;
14909 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
14910 &conform_action))
14911 ;
14912 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
14913 &exceed_action))
14914 ;
14915 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
14916 &violate_action))
14917 ;
14918 else if (unformat (i, "color-aware"))
14919 color_aware = 1;
14920 else
14921 break;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014922 }
14923
Dave Barach72d72232016-08-04 10:15:08 -040014924 if (!vec_len (name))
14925 {
14926 errmsg ("policer name must be specified");
14927 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014928 }
14929
Dave Barach72d72232016-08-04 10:15:08 -040014930 if (vec_len (name) > 64)
14931 {
14932 errmsg ("policer name too long");
14933 return -99;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014934 }
14935
Dave Barach72d72232016-08-04 10:15:08 -040014936 M (POLICER_ADD_DEL, policer_add_del);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014937
Dave Barach72d72232016-08-04 10:15:08 -040014938 clib_memcpy (mp->name, name, vec_len (name));
14939 vec_free (name);
14940 mp->is_add = is_add;
14941 mp->cir = cir;
14942 mp->eir = eir;
14943 mp->cb = cb;
14944 mp->eb = eb;
14945 mp->rate_type = rate_type;
14946 mp->round_type = round_type;
14947 mp->type = type;
14948 mp->conform_action_type = conform_action.action_type;
14949 mp->conform_dscp = conform_action.dscp;
14950 mp->exceed_action_type = exceed_action.action_type;
14951 mp->exceed_dscp = exceed_action.dscp;
14952 mp->violate_action_type = violate_action.action_type;
14953 mp->violate_dscp = violate_action.dscp;
14954 mp->color_aware = color_aware;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014955
Dave Barach72d72232016-08-04 10:15:08 -040014956 S;
14957 W;
14958 /* NOTREACHED */
14959 return 0;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070014960}
14961
Matus Fabian82e29c42016-05-11 04:49:46 -070014962static int
Dave Barach72d72232016-08-04 10:15:08 -040014963api_policer_dump (vat_main_t * vam)
Matus Fabiane8554802016-05-18 23:40:37 -070014964{
Dave Barach72d72232016-08-04 10:15:08 -040014965 unformat_input_t *i = vam->input;
14966 vl_api_policer_dump_t *mp;
14967 f64 timeout = ~0;
14968 u8 *match_name = 0;
14969 u8 match_name_valid = 0;
Matus Fabiane8554802016-05-18 23:40:37 -070014970
Dave Barach72d72232016-08-04 10:15:08 -040014971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Matus Fabiane8554802016-05-18 23:40:37 -070014972 {
Dave Barach72d72232016-08-04 10:15:08 -040014973 if (unformat (i, "name %s", &match_name))
14974 {
14975 vec_add1 (match_name, 0);
14976 match_name_valid = 1;
14977 }
14978 else
14979 break;
Matus Fabiane8554802016-05-18 23:40:37 -070014980 }
Matus Fabiane8554802016-05-18 23:40:37 -070014981
Dave Barach72d72232016-08-04 10:15:08 -040014982 M (POLICER_DUMP, policer_dump);
14983 mp->match_name_valid = match_name_valid;
14984 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
14985 vec_free (match_name);
14986 /* send it... */
14987 S;
14988
14989 /* Use a control ping for synchronization */
14990 {
14991 vl_api_control_ping_t *mp;
14992 M (CONTROL_PING, control_ping);
14993 S;
14994 }
14995 /* Wait for a reply... */
14996 W;
14997
14998 /* NOTREACHED */
14999 return 0;
Matus Fabiane8554802016-05-18 23:40:37 -070015000}
15001
15002static int
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015003api_policer_classify_set_interface (vat_main_t * vam)
15004{
Dave Barach72d72232016-08-04 10:15:08 -040015005 unformat_input_t *i = vam->input;
15006 vl_api_policer_classify_set_interface_t *mp;
15007 f64 timeout;
15008 u32 sw_if_index;
15009 int sw_if_index_set;
15010 u32 ip4_table_index = ~0;
15011 u32 ip6_table_index = ~0;
15012 u32 l2_table_index = ~0;
15013 u8 is_add = 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015014
Dave Barach72d72232016-08-04 10:15:08 -040015015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15016 {
15017 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15018 sw_if_index_set = 1;
15019 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15020 sw_if_index_set = 1;
15021 else if (unformat (i, "del"))
15022 is_add = 0;
15023 else if (unformat (i, "ip4-table %d", &ip4_table_index))
15024 ;
15025 else if (unformat (i, "ip6-table %d", &ip6_table_index))
15026 ;
15027 else if (unformat (i, "l2-table %d", &l2_table_index))
15028 ;
15029 else
15030 {
15031 clib_warning ("parse error '%U'", format_unformat_error, i);
15032 return -99;
15033 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015034 }
15035
Dave Barach72d72232016-08-04 10:15:08 -040015036 if (sw_if_index_set == 0)
15037 {
15038 errmsg ("missing interface name or sw_if_index\n");
15039 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015040 }
15041
Dave Barach72d72232016-08-04 10:15:08 -040015042 M (POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015043
Dave Barach72d72232016-08-04 10:15:08 -040015044 mp->sw_if_index = ntohl (sw_if_index);
15045 mp->ip4_table_index = ntohl (ip4_table_index);
15046 mp->ip6_table_index = ntohl (ip6_table_index);
15047 mp->l2_table_index = ntohl (l2_table_index);
15048 mp->is_add = is_add;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015049
Dave Barach72d72232016-08-04 10:15:08 -040015050 S;
15051 W;
15052 /* NOTREACHED */
15053 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015054}
15055
15056static int
Dave Barach72d72232016-08-04 10:15:08 -040015057api_policer_classify_dump (vat_main_t * vam)
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015058{
Dave Barach72d72232016-08-04 10:15:08 -040015059 unformat_input_t *i = vam->input;
15060 vl_api_policer_classify_dump_t *mp;
15061 f64 timeout = ~0;
15062 u8 type = POLICER_CLASSIFY_N_TABLES;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015063
Juraj Sloboda506b2452016-08-07 23:45:24 -070015064 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
Dave Barach72d72232016-08-04 10:15:08 -040015065 ;
15066 else
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015067 {
Dave Barach72d72232016-08-04 10:15:08 -040015068 errmsg ("classify table type must be specified\n");
15069 return -99;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015070 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015071
Dave Barach72d72232016-08-04 10:15:08 -040015072 if (!vam->json_output)
15073 {
15074 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
15075 }
15076
15077 M (POLICER_CLASSIFY_DUMP, policer_classify_dump);
15078 mp->type = type;
15079 /* send it... */
15080 S;
15081
15082 /* Use a control ping for synchronization */
15083 {
15084 vl_api_control_ping_t *mp;
15085 M (CONTROL_PING, control_ping);
15086 S;
15087 }
15088 /* Wait for a reply... */
15089 W;
15090
15091 /* NOTREACHED */
15092 return 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070015093}
15094
15095static int
Matus Fabian82e29c42016-05-11 04:49:46 -070015096api_netmap_create (vat_main_t * vam)
15097{
Dave Barach72d72232016-08-04 10:15:08 -040015098 unformat_input_t *i = vam->input;
15099 vl_api_netmap_create_t *mp;
15100 f64 timeout;
15101 u8 *if_name = 0;
15102 u8 hw_addr[6];
15103 u8 random_hw_addr = 1;
15104 u8 is_pipe = 0;
15105 u8 is_master = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015106
Dave Barach72d72232016-08-04 10:15:08 -040015107 memset (hw_addr, 0, sizeof (hw_addr));
Matus Fabian82e29c42016-05-11 04:49:46 -070015108
Dave Barach72d72232016-08-04 10:15:08 -040015109 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15110 {
15111 if (unformat (i, "name %s", &if_name))
15112 vec_add1 (if_name, 0);
15113 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
15114 random_hw_addr = 0;
15115 else if (unformat (i, "pipe"))
15116 is_pipe = 1;
15117 else if (unformat (i, "master"))
15118 is_master = 1;
15119 else if (unformat (i, "slave"))
15120 is_master = 0;
15121 else
15122 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015123 }
15124
Dave Barach72d72232016-08-04 10:15:08 -040015125 if (!vec_len (if_name))
15126 {
15127 errmsg ("interface name must be specified");
15128 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015129 }
15130
Dave Barach72d72232016-08-04 10:15:08 -040015131 if (vec_len (if_name) > 64)
15132 {
15133 errmsg ("interface name too long");
15134 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015135 }
15136
Dave Barach72d72232016-08-04 10:15:08 -040015137 M (NETMAP_CREATE, netmap_create);
Matus Fabian82e29c42016-05-11 04:49:46 -070015138
Dave Barach72d72232016-08-04 10:15:08 -040015139 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15140 clib_memcpy (mp->hw_addr, hw_addr, 6);
15141 mp->use_random_hw_addr = random_hw_addr;
15142 mp->is_pipe = is_pipe;
15143 mp->is_master = is_master;
15144 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015145
Dave Barach72d72232016-08-04 10:15:08 -040015146 S;
15147 W;
15148 /* NOTREACHED */
15149 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015150}
15151
15152static int
15153api_netmap_delete (vat_main_t * vam)
15154{
Dave Barach72d72232016-08-04 10:15:08 -040015155 unformat_input_t *i = vam->input;
15156 vl_api_netmap_delete_t *mp;
15157 f64 timeout;
15158 u8 *if_name = 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015159
Dave Barach72d72232016-08-04 10:15:08 -040015160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15161 {
15162 if (unformat (i, "name %s", &if_name))
15163 vec_add1 (if_name, 0);
15164 else
15165 break;
Matus Fabian82e29c42016-05-11 04:49:46 -070015166 }
15167
Dave Barach72d72232016-08-04 10:15:08 -040015168 if (!vec_len (if_name))
15169 {
15170 errmsg ("interface name must be specified");
15171 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015172 }
15173
Dave Barach72d72232016-08-04 10:15:08 -040015174 if (vec_len (if_name) > 64)
15175 {
15176 errmsg ("interface name too long");
15177 return -99;
Matus Fabian82e29c42016-05-11 04:49:46 -070015178 }
15179
Dave Barach72d72232016-08-04 10:15:08 -040015180 M (NETMAP_DELETE, netmap_delete);
Matus Fabian82e29c42016-05-11 04:49:46 -070015181
Dave Barach72d72232016-08-04 10:15:08 -040015182 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
15183 vec_free (if_name);
Matus Fabian82e29c42016-05-11 04:49:46 -070015184
Dave Barach72d72232016-08-04 10:15:08 -040015185 S;
15186 W;
15187 /* NOTREACHED */
15188 return 0;
Matus Fabian82e29c42016-05-11 04:49:46 -070015189}
15190
Neale Rannsad422ed2016-11-02 14:20:04 +000015191static void vl_api_mpls_tunnel_details_t_handler
15192 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015193{
Dave Barach72d72232016-08-04 10:15:08 -040015194 vat_main_t *vam = &vat_main;
Neale Rannsad422ed2016-11-02 14:20:04 +000015195 i32 len = mp->mt_next_hop_n_labels;
Dave Barach72d72232016-08-04 10:15:08 -040015196 i32 i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015197
Neale Rannsad422ed2016-11-02 14:20:04 +000015198 fformat (vam->ofp, "[%d]: via %U %d labels ",
15199 mp->tunnel_index,
15200 format_ip4_address, mp->mt_next_hop,
15201 ntohl (mp->mt_next_hop_sw_if_index));
Dave Barach72d72232016-08-04 10:15:08 -040015202 for (i = 0; i < len; i++)
15203 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015204 fformat (vam->ofp, "%u ", ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015205 }
Dave Barach72d72232016-08-04 10:15:08 -040015206 fformat (vam->ofp, "\n");
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015207}
15208
Neale Rannsad422ed2016-11-02 14:20:04 +000015209static void vl_api_mpls_tunnel_details_t_handler_json
15210 (vl_api_mpls_tunnel_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015211{
Dave Barach72d72232016-08-04 10:15:08 -040015212 vat_main_t *vam = &vat_main;
15213 vat_json_node_t *node = NULL;
15214 struct in_addr ip4;
15215 i32 i;
Neale Rannsad422ed2016-11-02 14:20:04 +000015216 i32 len = mp->mt_next_hop_n_labels;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015217
Dave Barach72d72232016-08-04 10:15:08 -040015218 if (VAT_JSON_ARRAY != vam->json_tree.type)
15219 {
15220 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15221 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015222 }
Dave Barach72d72232016-08-04 10:15:08 -040015223 node = vat_json_array_add (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015224
Dave Barach72d72232016-08-04 10:15:08 -040015225 vat_json_init_object (node);
15226 vat_json_object_add_uint (node, "tunnel_index", ntohl (mp->tunnel_index));
Neale Rannsad422ed2016-11-02 14:20:04 +000015227 clib_memcpy (&ip4, &(mp->mt_next_hop), sizeof (ip4));
15228 vat_json_object_add_ip4 (node, "next_hop", ip4);
15229 vat_json_object_add_uint (node, "next_hop_sw_if_index",
15230 ntohl (mp->mt_next_hop_sw_if_index));
15231 vat_json_object_add_uint (node, "l2_only", ntohl (mp->mt_l2_only));
Dave Barach72d72232016-08-04 10:15:08 -040015232 vat_json_object_add_uint (node, "label_count", len);
15233 for (i = 0; i < len; i++)
15234 {
Neale Rannsad422ed2016-11-02 14:20:04 +000015235 vat_json_object_add_uint (node, "label",
15236 ntohl (mp->mt_next_hop_out_labels[i]));
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015237 }
15238}
15239
Dave Barach72d72232016-08-04 10:15:08 -040015240static int
Neale Rannsad422ed2016-11-02 14:20:04 +000015241api_mpls_tunnel_dump (vat_main_t * vam)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015242{
Neale Rannsad422ed2016-11-02 14:20:04 +000015243 vl_api_mpls_tunnel_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015244 f64 timeout;
15245 i32 index = -1;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015246
Dave Barach72d72232016-08-04 10:15:08 -040015247 /* Parse args required to build the message */
15248 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015249 {
Dave Barach72d72232016-08-04 10:15:08 -040015250 if (!unformat (vam->input, "tunnel_index %d", &index))
15251 {
15252 index = -1;
15253 break;
15254 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015255 }
Dave Barach72d72232016-08-04 10:15:08 -040015256
15257 fformat (vam->ofp, " tunnel_index %d\n", index);
15258
Neale Rannsad422ed2016-11-02 14:20:04 +000015259 M (MPLS_TUNNEL_DUMP, mpls_tunnel_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015260 mp->tunnel_index = htonl (index);
15261 S;
15262
15263 /* Use a control ping for synchronization */
15264 {
15265 vl_api_control_ping_t *mp;
15266 M (CONTROL_PING, control_ping);
15267 S;
15268 }
15269 W;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015270}
15271
Steven01b07122016-11-02 10:40:09 -070015272#define vl_api_mpls_fib_details_t_endian vl_noop_handler
15273#define vl_api_mpls_fib_details_t_print vl_noop_handler
15274
Neale Ranns1357f3b2016-10-16 12:01:42 -070015275static void
15276vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015277{
Dave Barach72d72232016-08-04 10:15:08 -040015278 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070015279 int count = ntohl (mp->count);
Dave Barachb5e8a772016-12-06 12:04:42 -050015280 vl_api_fib_path2_t *fp;
Steven01b07122016-11-02 10:40:09 -070015281 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015282
Dave Barach72d72232016-08-04 10:15:08 -040015283 fformat (vam->ofp,
Neale Ranns1357f3b2016-10-16 12:01:42 -070015284 "table-id %d, label %u, ess_bit %u\n",
15285 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
Steven01b07122016-11-02 10:40:09 -070015286 fp = mp->path;
15287 for (i = 0; i < count; i++)
15288 {
Steven5858a822016-11-16 13:26:27 -080015289 if (fp->afi == IP46_TYPE_IP6)
15290 fformat (vam->ofp,
15291 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15292 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15293 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15294 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15295 format_ip6_address, fp->next_hop);
15296 else if (fp->afi == IP46_TYPE_IP4)
15297 fformat (vam->ofp,
15298 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15299 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15300 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15301 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15302 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015303 fp++;
15304 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015305}
15306
Neale Ranns1357f3b2016-10-16 12:01:42 -070015307static void vl_api_mpls_fib_details_t_handler_json
15308 (vl_api_mpls_fib_details_t * mp)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015309{
Dave Barach72d72232016-08-04 10:15:08 -040015310 vat_main_t *vam = &vat_main;
Steven01b07122016-11-02 10:40:09 -070015311 int count = ntohl (mp->count);
Dave Barach72d72232016-08-04 10:15:08 -040015312 vat_json_node_t *node = NULL;
Steven01b07122016-11-02 10:40:09 -070015313 struct in_addr ip4;
15314 struct in6_addr ip6;
Dave Barachb5e8a772016-12-06 12:04:42 -050015315 vl_api_fib_path2_t *fp;
Steven01b07122016-11-02 10:40:09 -070015316 int i;
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015317
Dave Barach72d72232016-08-04 10:15:08 -040015318 if (VAT_JSON_ARRAY != vam->json_tree.type)
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015319 {
Dave Barach72d72232016-08-04 10:15:08 -040015320 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15321 vat_json_init_array (&vam->json_tree);
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015322 }
Dave Barach72d72232016-08-04 10:15:08 -040015323 node = vat_json_array_add (&vam->json_tree);
15324
15325 vat_json_init_object (node);
Neale Ranns1357f3b2016-10-16 12:01:42 -070015326 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15327 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
Dave Barach72d72232016-08-04 10:15:08 -040015328 vat_json_object_add_uint (node, "label", ntohl (mp->label));
Steven01b07122016-11-02 10:40:09 -070015329 vat_json_object_add_uint (node, "path_count", count);
15330 fp = mp->path;
15331 for (i = 0; i < count; i++)
15332 {
15333 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15334 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15335 vat_json_object_add_uint (node, "is_local", fp->is_local);
15336 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15337 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15338 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15339 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15340 if (fp->afi == IP46_TYPE_IP4)
15341 {
15342 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15343 vat_json_object_add_ip4 (node, "next_hop", ip4);
15344 }
15345 else if (fp->afi == IP46_TYPE_IP6)
15346 {
15347 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15348 vat_json_object_add_ip6 (node, "next_hop", ip6);
15349 }
15350 }
marek zavodsky2c21a9a2016-06-21 05:35:16 +020015351}
15352
Dave Barach72d72232016-08-04 10:15:08 -040015353static int
Neale Ranns1357f3b2016-10-16 12:01:42 -070015354api_mpls_fib_dump (vat_main_t * vam)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015355{
Neale Ranns1357f3b2016-10-16 12:01:42 -070015356 vl_api_mpls_fib_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015357 f64 timeout;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015358
Neale Ranns1357f3b2016-10-16 12:01:42 -070015359 M (MPLS_FIB_DUMP, mpls_fib_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015360 S;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015361
Dave Barach72d72232016-08-04 10:15:08 -040015362 /* Use a control ping for synchronization */
15363 {
15364 vl_api_control_ping_t *mp;
15365 M (CONTROL_PING, control_ping);
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015366 S;
Dave Barach72d72232016-08-04 10:15:08 -040015367 }
15368 W;
15369}
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015370
Steven01b07122016-11-02 10:40:09 -070015371#define vl_api_ip_fib_details_t_endian vl_noop_handler
15372#define vl_api_ip_fib_details_t_print vl_noop_handler
15373
15374static void
15375vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
15376{
15377 vat_main_t *vam = &vat_main;
15378 int count = ntohl (mp->count);
15379 vl_api_fib_path_t *fp;
15380 int i;
15381
15382 fformat (vam->ofp,
15383 "table-id %d, prefix %U/%d\n",
15384 ntohl (mp->table_id), format_ip4_address, mp->address,
15385 mp->address_length);
15386 fp = mp->path;
15387 for (i = 0; i < count; i++)
15388 {
Steven5858a822016-11-16 13:26:27 -080015389 if (fp->afi == IP46_TYPE_IP6)
15390 fformat (vam->ofp,
15391 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15392 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15393 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15394 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15395 format_ip6_address, fp->next_hop);
15396 else if (fp->afi == IP46_TYPE_IP4)
15397 fformat (vam->ofp,
15398 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15399 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15400 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15401 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15402 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015403 fp++;
15404 }
15405}
15406
15407static void vl_api_ip_fib_details_t_handler_json
15408 (vl_api_ip_fib_details_t * mp)
15409{
15410 vat_main_t *vam = &vat_main;
15411 int count = ntohl (mp->count);
15412 vat_json_node_t *node = NULL;
15413 struct in_addr ip4;
15414 struct in6_addr ip6;
15415 vl_api_fib_path_t *fp;
15416 int i;
15417
15418 if (VAT_JSON_ARRAY != vam->json_tree.type)
15419 {
15420 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15421 vat_json_init_array (&vam->json_tree);
15422 }
15423 node = vat_json_array_add (&vam->json_tree);
15424
15425 vat_json_init_object (node);
15426 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15427 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
15428 vat_json_object_add_ip4 (node, "prefix", ip4);
15429 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15430 vat_json_object_add_uint (node, "path_count", count);
15431 fp = mp->path;
15432 for (i = 0; i < count; i++)
15433 {
15434 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15435 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15436 vat_json_object_add_uint (node, "is_local", fp->is_local);
15437 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15438 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15439 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15440 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15441 if (fp->afi == IP46_TYPE_IP4)
15442 {
15443 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15444 vat_json_object_add_ip4 (node, "next_hop", ip4);
15445 }
15446 else if (fp->afi == IP46_TYPE_IP6)
15447 {
15448 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15449 vat_json_object_add_ip6 (node, "next_hop", ip6);
15450 }
15451 }
15452}
15453
15454static int
15455api_ip_fib_dump (vat_main_t * vam)
15456{
15457 vl_api_ip_fib_dump_t *mp;
15458 f64 timeout;
15459
15460 M (IP_FIB_DUMP, ip_fib_dump);
15461 S;
15462
15463 /* Use a control ping for synchronization */
15464 {
15465 vl_api_control_ping_t *mp;
15466 M (CONTROL_PING, control_ping);
15467 S;
15468 }
15469 W;
15470}
15471
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010015472static void vl_api_ip_neighbor_details_t_handler
15473 (vl_api_ip_neighbor_details_t * mp)
15474{
15475 vat_main_t *vam = &vat_main;
15476
15477 fformat (vam->ofp, "%c %U %U\n",
15478 (mp->is_static) ? 'S' : 'D',
15479 format_ethernet_address, &mp->mac_address,
15480 (mp->is_ipv6) ? format_ip6_address : format_ip4_address,
15481 &mp->ip_address);
15482}
15483
15484static void vl_api_ip_neighbor_details_t_handler_json
15485 (vl_api_ip_neighbor_details_t * mp)
15486{
15487
15488 vat_main_t *vam = &vat_main;
15489 vat_json_node_t *node;
15490 struct in_addr ip4;
15491 struct in6_addr ip6;
15492
15493 if (VAT_JSON_ARRAY != vam->json_tree.type)
15494 {
15495 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15496 vat_json_init_array (&vam->json_tree);
15497 }
15498 node = vat_json_array_add (&vam->json_tree);
15499
15500 vat_json_init_object (node);
15501 vat_json_object_add_string_copy (node, "flag",
15502 (mp->is_static) ? (u8 *) "static" : (u8 *)
15503 "dynamic");
15504
15505 vat_json_object_add_string_copy (node, "link_layer",
15506 format (0, "%U", format_ethernet_address,
15507 &mp->mac_address));
15508
15509 if (mp->is_ipv6)
15510 {
15511 clib_memcpy (&ip6, &mp->ip_address, sizeof (ip6));
15512 vat_json_object_add_ip6 (node, "ip_address", ip6);
15513 }
15514 else
15515 {
15516 clib_memcpy (&ip4, &mp->ip_address, sizeof (ip4));
15517 vat_json_object_add_ip4 (node, "ip_address", ip4);
15518 }
15519}
15520
15521static int
15522api_ip_neighbor_dump (vat_main_t * vam)
15523{
15524 unformat_input_t *i = vam->input;
15525 vl_api_ip_neighbor_dump_t *mp;
15526 f64 timeout;
15527 u8 is_ipv6 = 0;
15528 u32 sw_if_index = ~0;
15529
15530 /* Parse args required to build the message */
15531 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15532 {
15533 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
15534 ;
15535 else if (unformat (i, "sw_if_index %d", &sw_if_index))
15536 ;
15537 else if (unformat (i, "ip6"))
15538 is_ipv6 = 1;
15539 else
15540 break;
15541 }
15542
15543 if (sw_if_index == ~0)
15544 {
15545 errmsg ("missing interface name or sw_if_index\n");
15546 return -99;
15547 }
15548
15549 M (IP_NEIGHBOR_DUMP, ip_neighbor_dump);
15550 mp->is_ipv6 = (u8) is_ipv6;
15551 mp->sw_if_index = ntohl (sw_if_index);
15552 S;
15553
15554 /* Use a control ping for synchronization */
15555 {
15556 vl_api_control_ping_t *mp;
15557 M (CONTROL_PING, control_ping);
15558 S;
15559 }
15560 W;
15561}
15562
Steven01b07122016-11-02 10:40:09 -070015563#define vl_api_ip6_fib_details_t_endian vl_noop_handler
15564#define vl_api_ip6_fib_details_t_print vl_noop_handler
15565
15566static void
15567vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
15568{
15569 vat_main_t *vam = &vat_main;
15570 int count = ntohl (mp->count);
15571 vl_api_fib_path_t *fp;
15572 int i;
15573
15574 fformat (vam->ofp,
15575 "table-id %d, prefix %U/%d\n",
15576 ntohl (mp->table_id), format_ip6_address, mp->address,
15577 mp->address_length);
15578 fp = mp->path;
15579 for (i = 0; i < count; i++)
15580 {
Steven5858a822016-11-16 13:26:27 -080015581 if (fp->afi == IP46_TYPE_IP6)
15582 fformat (vam->ofp,
15583 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15584 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15585 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15586 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15587 format_ip6_address, fp->next_hop);
15588 else if (fp->afi == IP46_TYPE_IP4)
15589 fformat (vam->ofp,
15590 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
15591 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n",
15592 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
15593 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
15594 format_ip4_address, fp->next_hop);
Steven01b07122016-11-02 10:40:09 -070015595 fp++;
15596 }
15597}
15598
15599static void vl_api_ip6_fib_details_t_handler_json
15600 (vl_api_ip6_fib_details_t * mp)
15601{
15602 vat_main_t *vam = &vat_main;
15603 int count = ntohl (mp->count);
15604 vat_json_node_t *node = NULL;
15605 struct in_addr ip4;
15606 struct in6_addr ip6;
15607 vl_api_fib_path_t *fp;
15608 int i;
15609
15610 if (VAT_JSON_ARRAY != vam->json_tree.type)
15611 {
15612 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15613 vat_json_init_array (&vam->json_tree);
15614 }
15615 node = vat_json_array_add (&vam->json_tree);
15616
15617 vat_json_init_object (node);
15618 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
15619 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
15620 vat_json_object_add_ip6 (node, "prefix", ip6);
15621 vat_json_object_add_uint (node, "mask_length", mp->address_length);
15622 vat_json_object_add_uint (node, "path_count", count);
15623 fp = mp->path;
15624 for (i = 0; i < count; i++)
15625 {
15626 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
15627 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
15628 vat_json_object_add_uint (node, "is_local", fp->is_local);
15629 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
15630 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
15631 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
15632 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
15633 if (fp->afi == IP46_TYPE_IP4)
15634 {
15635 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
15636 vat_json_object_add_ip4 (node, "next_hop", ip4);
15637 }
15638 else if (fp->afi == IP46_TYPE_IP6)
15639 {
15640 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
15641 vat_json_object_add_ip6 (node, "next_hop", ip6);
15642 }
15643 }
15644}
15645
15646static int
15647api_ip6_fib_dump (vat_main_t * vam)
15648{
15649 vl_api_ip6_fib_dump_t *mp;
15650 f64 timeout;
15651
15652 M (IP6_FIB_DUMP, ip6_fib_dump);
15653 S;
15654
15655 /* Use a control ping for synchronization */
15656 {
15657 vl_api_control_ping_t *mp;
15658 M (CONTROL_PING, control_ping);
15659 S;
15660 }
15661 W;
15662}
15663
Dave Barach72d72232016-08-04 10:15:08 -040015664int
15665api_classify_table_ids (vat_main_t * vam)
15666{
15667 vl_api_classify_table_ids_t *mp;
15668 f64 timeout;
15669
15670 /* Construct the API message */
15671 M (CLASSIFY_TABLE_IDS, classify_table_ids);
15672 mp->context = 0;
15673
15674 S;
15675 W;
15676 /* NOTREACHED */
15677 return 0;
15678}
15679
15680int
15681api_classify_table_by_interface (vat_main_t * vam)
15682{
15683 unformat_input_t *input = vam->input;
15684 vl_api_classify_table_by_interface_t *mp;
15685 f64 timeout;
15686
15687 u32 sw_if_index = ~0;
15688 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015689 {
Dave Barach72d72232016-08-04 10:15:08 -040015690 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
15691 ;
15692 else if (unformat (input, "sw_if_index %d", &sw_if_index))
15693 ;
15694 else
15695 break;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015696 }
Dave Barach72d72232016-08-04 10:15:08 -040015697 if (sw_if_index == ~0)
15698 {
15699 errmsg ("missing interface name or sw_if_index\n");
15700 return -99;
15701 }
15702
15703 /* Construct the API message */
15704 M (CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
15705 mp->context = 0;
15706 mp->sw_if_index = ntohl (sw_if_index);
15707
15708 S;
15709 W;
15710 /* NOTREACHED */
15711 return 0;
Pavel Kotucek20c90f72016-06-07 14:44:26 +020015712}
15713
Dave Barach72d72232016-08-04 10:15:08 -040015714int
15715api_classify_table_info (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015716{
Dave Barach72d72232016-08-04 10:15:08 -040015717 unformat_input_t *input = vam->input;
15718 vl_api_classify_table_info_t *mp;
15719 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015720
Dave Barach72d72232016-08-04 10:15:08 -040015721 u32 table_id = ~0;
15722 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15723 {
15724 if (unformat (input, "table_id %d", &table_id))
15725 ;
15726 else
15727 break;
15728 }
15729 if (table_id == ~0)
15730 {
15731 errmsg ("missing table id\n");
15732 return -99;
15733 }
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015734
Dave Barach72d72232016-08-04 10:15:08 -040015735 /* Construct the API message */
15736 M (CLASSIFY_TABLE_INFO, classify_table_info);
15737 mp->context = 0;
15738 mp->table_id = ntohl (table_id);
15739
15740 S;
15741 W;
15742 /* NOTREACHED */
15743 return 0;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015744}
15745
Dave Barach72d72232016-08-04 10:15:08 -040015746int
15747api_classify_session_dump (vat_main_t * vam)
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015748{
Dave Barach72d72232016-08-04 10:15:08 -040015749 unformat_input_t *input = vam->input;
15750 vl_api_classify_session_dump_t *mp;
15751 f64 timeout;
Juraj Slobodaac645ad2016-07-07 00:18:57 -070015752
Dave Barach72d72232016-08-04 10:15:08 -040015753 u32 table_id = ~0;
15754 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
15755 {
15756 if (unformat (input, "table_id %d", &table_id))
15757 ;
15758 else
15759 break;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015760 }
Dave Barach72d72232016-08-04 10:15:08 -040015761 if (table_id == ~0)
15762 {
15763 errmsg ("missing table id\n");
15764 return -99;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015765 }
15766
Dave Barach72d72232016-08-04 10:15:08 -040015767 /* Construct the API message */
15768 M (CLASSIFY_SESSION_DUMP, classify_session_dump);
15769 mp->context = 0;
15770 mp->table_id = ntohl (table_id);
15771 S;
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020015772
Dave Barach72d72232016-08-04 10:15:08 -040015773 /* Use a control ping for synchronization */
15774 {
15775 vl_api_control_ping_t *mp;
15776 M (CONTROL_PING, control_ping);
Dave Barach6f9bca22016-04-30 10:25:32 -040015777 S;
Dave Barach72d72232016-08-04 10:15:08 -040015778 }
15779 W;
15780 /* NOTREACHED */
15781 return 0;
Dave Barach6f9bca22016-04-30 10:25:32 -040015782}
15783
Dave Barach72d72232016-08-04 10:15:08 -040015784static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015785vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015786{
Dave Barach72d72232016-08-04 10:15:08 -040015787 vat_main_t *vam = &vat_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015788
Dave Barach72d72232016-08-04 10:15:08 -040015789 fformat (vam->ofp, "collector_address %U, collector_port %d, "
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015790 "src_address %U, vrf_id %d, path_mtu %u, "
15791 "template_interval %u, udp_checksum %d\n",
Dave Barach72d72232016-08-04 10:15:08 -040015792 format_ip4_address, mp->collector_address,
15793 ntohs (mp->collector_port),
15794 format_ip4_address, mp->src_address,
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015795 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
15796 ntohl (mp->template_interval), mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015797
15798 vam->retval = 0;
15799 vam->result_ready = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015800}
15801
Dave Barach72d72232016-08-04 10:15:08 -040015802static void
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015803 vl_api_ipfix_exporter_details_t_handler_json
15804 (vl_api_ipfix_exporter_details_t * mp)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015805{
Dave Barach72d72232016-08-04 10:15:08 -040015806 vat_main_t *vam = &vat_main;
15807 vat_json_node_t node;
15808 struct in_addr collector_address;
15809 struct in_addr src_address;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015810
Dave Barach72d72232016-08-04 10:15:08 -040015811 vat_json_init_object (&node);
15812 clib_memcpy (&collector_address, &mp->collector_address,
15813 sizeof (collector_address));
15814 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
15815 vat_json_object_add_uint (&node, "collector_port",
15816 ntohs (mp->collector_port));
15817 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
15818 vat_json_object_add_ip4 (&node, "src_address", src_address);
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015819 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
Dave Barach72d72232016-08-04 10:15:08 -040015820 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
15821 vat_json_object_add_uint (&node, "template_interval",
15822 ntohl (mp->template_interval));
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015823 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
Dave Barach72d72232016-08-04 10:15:08 -040015824
15825 vat_json_print (vam->ofp, &node);
15826 vat_json_free (&node);
15827 vam->retval = 0;
15828 vam->result_ready = 1;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050015829}
15830
Dave Barach72d72232016-08-04 10:15:08 -040015831int
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015832api_ipfix_exporter_dump (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070015833{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015834 vl_api_ipfix_exporter_dump_t *mp;
Dave Barach72d72232016-08-04 10:15:08 -040015835 f64 timeout;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015836
Dave Barach72d72232016-08-04 10:15:08 -040015837 /* Construct the API message */
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015838 M (IPFIX_EXPORTER_DUMP, ipfix_exporter_dump);
Dave Barach72d72232016-08-04 10:15:08 -040015839 mp->context = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070015840
Dave Barach72d72232016-08-04 10:15:08 -040015841 S;
15842 W;
15843 /* NOTREACHED */
15844 return 0;
15845}
Ed Warnickecb9cada2015-12-08 15:45:58 -070015846
Juraj Slobodaffa652a2016-08-07 23:43:42 -070015847static int
15848api_ipfix_classify_stream_dump (vat_main_t * vam)
15849{
15850 vl_api_ipfix_classify_stream_dump_t *mp;
15851 f64 timeout;
15852
15853 /* Construct the API message */
15854 M (IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump);
15855 mp->context = 0;
15856
15857 S;
15858 W;
15859 /* NOTREACHED */
15860 return 0;
15861}
15862
15863static void
15864 vl_api_ipfix_classify_stream_details_t_handler
15865 (vl_api_ipfix_classify_stream_details_t * mp)
15866{
15867 vat_main_t *vam = &vat_main;
15868 fformat (vam->ofp, "domain_id %d, src_port %d\n",
15869 ntohl (mp->domain_id), ntohs (mp->src_port));
15870 vam->retval = 0;
15871 vam->result_ready = 1;
15872}
15873
15874static void
15875 vl_api_ipfix_classify_stream_details_t_handler_json
15876 (vl_api_ipfix_classify_stream_details_t * mp)
15877{
15878 vat_main_t *vam = &vat_main;
15879 vat_json_node_t node;
15880
15881 vat_json_init_object (&node);
15882 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
15883 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
15884
15885 vat_json_print (vam->ofp, &node);
15886 vat_json_free (&node);
15887 vam->retval = 0;
15888 vam->result_ready = 1;
15889}
15890
15891static int
15892api_ipfix_classify_table_dump (vat_main_t * vam)
15893{
15894 vl_api_ipfix_classify_table_dump_t *mp;
15895 f64 timeout;
15896
15897 if (!vam->json_output)
15898 {
15899 fformat (vam->ofp, "%15s%15s%20s\n", "table_id", "ip_version",
15900 "transport_protocol");
15901 }
15902
15903 /* Construct the API message */
15904 M (IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump);
15905
15906 /* send it... */
15907 S;
15908
15909 /* Use a control ping for synchronization */
15910 {
15911 vl_api_control_ping_t *mp;
15912 M (CONTROL_PING, control_ping);
15913 S;
15914 }
15915 W;
15916}
15917
15918static void
15919 vl_api_ipfix_classify_table_details_t_handler
15920 (vl_api_ipfix_classify_table_details_t * mp)
15921{
15922 vat_main_t *vam = &vat_main;
15923 fformat (vam->ofp, "%15d%15d%20d\n", ntohl (mp->table_id), mp->ip_version,
15924 mp->transport_protocol);
15925}
15926
15927static void
15928 vl_api_ipfix_classify_table_details_t_handler_json
15929 (vl_api_ipfix_classify_table_details_t * mp)
15930{
15931 vat_json_node_t *node = NULL;
15932 vat_main_t *vam = &vat_main;
15933
15934 if (VAT_JSON_ARRAY != vam->json_tree.type)
15935 {
15936 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15937 vat_json_init_array (&vam->json_tree);
15938 }
15939
15940 node = vat_json_array_add (&vam->json_tree);
15941 vat_json_init_object (node);
15942
15943 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
15944 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
15945 vat_json_object_add_uint (node, "transport_protocol",
15946 mp->transport_protocol);
15947}
15948
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015949static int
15950api_sw_interface_span_enable_disable (vat_main_t * vam)
15951{
15952 unformat_input_t *i = vam->input;
15953 vl_api_sw_interface_span_enable_disable_t *mp;
15954 f64 timeout;
15955 u32 src_sw_if_index = ~0;
15956 u32 dst_sw_if_index = ~0;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015957 u8 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015958
15959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15960 {
15961 if (unformat (i, "src %U", unformat_sw_if_index, vam, &src_sw_if_index))
15962 ;
15963 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
15964 ;
15965 else
15966 if (unformat
15967 (i, "dst %U", unformat_sw_if_index, vam, &dst_sw_if_index))
15968 ;
15969 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
15970 ;
15971 else if (unformat (i, "disable"))
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015972 state = 0;
15973 else if (unformat (i, "rx"))
15974 state = 1;
15975 else if (unformat (i, "tx"))
15976 state = 2;
15977 else if (unformat (i, "both"))
15978 state = 3;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015979 else
15980 break;
15981 }
15982
15983 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, sw_interface_span_enable_disable);
15984
15985 mp->sw_if_index_from = htonl (src_sw_if_index);
15986 mp->sw_if_index_to = htonl (dst_sw_if_index);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010015987 mp->state = state;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010015988
15989 S;
15990 W;
15991 /* NOTREACHED */
15992 return 0;
15993}
15994
15995static void
15996vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
15997 * mp)
15998{
15999 vat_main_t *vam = &vat_main;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016000 u8 *sw_if_from_name = 0;
16001 u8 *sw_if_to_name = 0;
16002 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
16003 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
16004 char *states[] = { "none", "rx", "tx", "both" };
16005 hash_pair_t *p;
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016006
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016007 /* *INDENT-OFF* */
16008 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
16009 ({
16010 if ((u32) p->value[0] == sw_if_index_from)
16011 {
16012 sw_if_from_name = (u8 *)(p->key);
16013 if (sw_if_to_name)
16014 break;
16015 }
16016 if ((u32) p->value[0] == sw_if_index_to)
16017 {
16018 sw_if_to_name = (u8 *)(p->key);
16019 if (sw_if_from_name)
16020 break;
16021 }
16022 }));
16023 /* *INDENT-ON* */
16024 fformat (vam->ofp, "%20s => %20s (%s)\n",
16025 sw_if_from_name, sw_if_to_name, states[mp->state]);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016026}
16027
16028static void
16029 vl_api_sw_interface_span_details_t_handler_json
16030 (vl_api_sw_interface_span_details_t * mp)
16031{
16032 vat_main_t *vam = &vat_main;
16033 vat_json_node_t *node = NULL;
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016034 u8 *sw_if_from_name = 0;
16035 u8 *sw_if_to_name = 0;
16036 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
16037 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
16038 hash_pair_t *p;
16039
16040 /* *INDENT-OFF* */
16041 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
16042 ({
16043 if ((u32) p->value[0] == sw_if_index_from)
16044 {
16045 sw_if_from_name = (u8 *)(p->key);
16046 if (sw_if_to_name)
16047 break;
16048 }
16049 if ((u32) p->value[0] == sw_if_index_to)
16050 {
16051 sw_if_to_name = (u8 *)(p->key);
16052 if (sw_if_from_name)
16053 break;
16054 }
16055 }));
16056 /* *INDENT-ON* */
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016057
16058 if (VAT_JSON_ARRAY != vam->json_tree.type)
16059 {
16060 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16061 vat_json_init_array (&vam->json_tree);
16062 }
16063 node = vat_json_array_add (&vam->json_tree);
16064
16065 vat_json_init_object (node);
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010016066 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
16067 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
16068 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
16069 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
16070 vat_json_object_add_uint (node, "state", mp->state);
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010016071}
16072
16073static int
16074api_sw_interface_span_dump (vat_main_t * vam)
16075{
16076 vl_api_sw_interface_span_dump_t *mp;
16077 f64 timeout;
16078
16079 M (SW_INTERFACE_SPAN_DUMP, sw_interface_span_dump);
16080 S;
16081
16082 /* Use a control ping for synchronization */
16083 {
16084 vl_api_control_ping_t *mp;
16085 M (CONTROL_PING, control_ping);
16086 S;
16087 }
16088 W;
16089}
16090
Dave Barach72d72232016-08-04 10:15:08 -040016091int
16092api_pg_create_interface (vat_main_t * vam)
16093{
16094 unformat_input_t *input = vam->input;
16095 vl_api_pg_create_interface_t *mp;
16096 f64 timeout;
16097
16098 u32 if_id = ~0;
16099 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16100 {
16101 if (unformat (input, "if_id %d", &if_id))
16102 ;
16103 else
16104 break;
16105 }
16106 if (if_id == ~0)
16107 {
16108 errmsg ("missing pg interface index\n");
16109 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070016110 }
16111
Dave Barach72d72232016-08-04 10:15:08 -040016112 /* Construct the API message */
16113 M (PG_CREATE_INTERFACE, pg_create_interface);
16114 mp->context = 0;
16115 mp->interface_id = ntohl (if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -070016116
Dave Barach72d72232016-08-04 10:15:08 -040016117 S;
16118 W;
16119 /* NOTREACHED */
16120 return 0;
16121}
16122
16123int
16124api_pg_capture (vat_main_t * vam)
16125{
16126 unformat_input_t *input = vam->input;
16127 vl_api_pg_capture_t *mp;
16128 f64 timeout;
16129
16130 u32 if_id = ~0;
16131 u8 enable = 1;
16132 u32 count = 1;
16133 u8 pcap_file_set = 0;
16134 u8 *pcap_file = 0;
16135 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16136 {
16137 if (unformat (input, "if_id %d", &if_id))
16138 ;
16139 else if (unformat (input, "pcap %s", &pcap_file))
16140 pcap_file_set = 1;
16141 else if (unformat (input, "count %d", &count))
16142 ;
16143 else if (unformat (input, "disable"))
16144 enable = 0;
16145 else
16146 break;
16147 }
16148 if (if_id == ~0)
16149 {
16150 errmsg ("missing pg interface index\n");
16151 return -99;
16152 }
16153 if (pcap_file_set > 0)
16154 {
16155 if (vec_len (pcap_file) > 255)
16156 {
16157 errmsg ("pcap file name is too long\n");
16158 return -99;
16159 }
16160 }
16161
16162 u32 name_len = vec_len (pcap_file);
16163 /* Construct the API message */
16164 M (PG_CAPTURE, pg_capture);
16165 mp->context = 0;
16166 mp->interface_id = ntohl (if_id);
16167 mp->is_enabled = enable;
16168 mp->count = ntohl (count);
16169 mp->pcap_name_length = ntohl (name_len);
16170 if (pcap_file_set != 0)
16171 {
16172 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
16173 }
16174 vec_free (pcap_file);
16175
16176 S;
16177 W;
16178 /* NOTREACHED */
16179 return 0;
16180}
16181
16182int
16183api_pg_enable_disable (vat_main_t * vam)
16184{
16185 unformat_input_t *input = vam->input;
16186 vl_api_pg_enable_disable_t *mp;
16187 f64 timeout;
16188
16189 u8 enable = 1;
16190 u8 stream_name_set = 0;
16191 u8 *stream_name = 0;
16192 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16193 {
16194 if (unformat (input, "stream %s", &stream_name))
16195 stream_name_set = 1;
16196 else if (unformat (input, "disable"))
16197 enable = 0;
16198 else
16199 break;
16200 }
16201
16202 if (stream_name_set > 0)
16203 {
16204 if (vec_len (stream_name) > 255)
16205 {
16206 errmsg ("stream name too long\n");
16207 return -99;
16208 }
16209 }
16210
16211 u32 name_len = vec_len (stream_name);
16212 /* Construct the API message */
16213 M (PG_ENABLE_DISABLE, pg_enable_disable);
16214 mp->context = 0;
16215 mp->is_enabled = enable;
16216 if (stream_name_set != 0)
16217 {
16218 mp->stream_name_length = ntohl (name_len);
16219 clib_memcpy (mp->stream_name, stream_name, name_len);
16220 }
16221 vec_free (stream_name);
16222
16223 S;
16224 W;
16225 /* NOTREACHED */
16226 return 0;
16227}
16228
16229int
16230api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
16231{
16232 unformat_input_t *input = vam->input;
16233 vl_api_ip_source_and_port_range_check_add_del_t *mp;
16234 f64 timeout;
16235
16236 u16 *low_ports = 0;
16237 u16 *high_ports = 0;
16238 u16 this_low;
16239 u16 this_hi;
16240 ip4_address_t ip4_addr;
16241 ip6_address_t ip6_addr;
16242 u32 length;
16243 u32 tmp, tmp2;
16244 u8 prefix_set = 0;
16245 u32 vrf_id = ~0;
16246 u8 is_add = 1;
16247 u8 is_ipv6 = 0;
16248
16249 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16250 {
16251 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
16252 {
16253 prefix_set = 1;
16254 }
16255 else
16256 if (unformat
16257 (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
16258 {
16259 prefix_set = 1;
16260 is_ipv6 = 1;
16261 }
16262 else if (unformat (input, "vrf %d", &vrf_id))
16263 ;
16264 else if (unformat (input, "del"))
16265 is_add = 0;
16266 else if (unformat (input, "port %d", &tmp))
16267 {
16268 if (tmp == 0 || tmp > 65535)
16269 {
16270 errmsg ("port %d out of range", tmp);
16271 return -99;
16272 }
16273 this_low = tmp;
16274 this_hi = this_low + 1;
16275 vec_add1 (low_ports, this_low);
16276 vec_add1 (high_ports, this_hi);
16277 }
16278 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
16279 {
16280 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
16281 {
16282 errmsg ("incorrect range parameters\n");
16283 return -99;
16284 }
16285 this_low = tmp;
16286 /* Note: in debug CLI +1 is added to high before
16287 passing to real fn that does "the work"
16288 (ip_source_and_port_range_check_add_del).
16289 This fn is a wrapper around the binary API fn a
16290 control plane will call, which expects this increment
16291 to have occurred. Hence letting the binary API control
16292 plane fn do the increment for consistency between VAT
16293 and other control planes.
16294 */
16295 this_hi = tmp2;
16296 vec_add1 (low_ports, this_low);
16297 vec_add1 (high_ports, this_hi);
16298 }
16299 else
16300 break;
16301 }
16302
16303 if (prefix_set == 0)
16304 {
16305 errmsg ("<address>/<mask> not specified\n");
16306 return -99;
16307 }
16308
16309 if (vrf_id == ~0)
16310 {
16311 errmsg ("VRF ID required, not specified\n");
16312 return -99;
16313 }
16314
16315 if (vrf_id == 0)
16316 {
16317 errmsg
16318 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16319 return -99;
16320 }
16321
16322 if (vec_len (low_ports) == 0)
16323 {
16324 errmsg ("At least one port or port range required\n");
16325 return -99;
16326 }
16327
16328 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,
16329 ip_source_and_port_range_check_add_del);
16330
16331 mp->is_add = is_add;
16332
16333 if (is_ipv6)
16334 {
16335 mp->is_ipv6 = 1;
16336 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
16337 }
16338 else
16339 {
16340 mp->is_ipv6 = 0;
16341 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
16342 }
16343
16344 mp->mask_length = length;
16345 mp->number_of_ranges = vec_len (low_ports);
16346
16347 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
16348 vec_free (low_ports);
16349
16350 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
16351 vec_free (high_ports);
16352
16353 mp->vrf_id = ntohl (vrf_id);
16354
16355 S;
16356 W;
16357 /* NOTREACHED */
16358 return 0;
16359}
16360
16361int
16362api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
16363{
16364 unformat_input_t *input = vam->input;
16365 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
16366 f64 timeout;
16367 u32 sw_if_index = ~0;
16368 int vrf_set = 0;
16369 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
16370 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
16371 u8 is_add = 1;
16372
16373 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16374 {
16375 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
16376 ;
16377 else if (unformat (input, "sw_if_index %d", &sw_if_index))
16378 ;
16379 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
16380 vrf_set = 1;
16381 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
16382 vrf_set = 1;
16383 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
16384 vrf_set = 1;
16385 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
16386 vrf_set = 1;
16387 else if (unformat (input, "del"))
16388 is_add = 0;
16389 else
16390 break;
16391 }
16392
16393 if (sw_if_index == ~0)
16394 {
16395 errmsg ("Interface required but not specified\n");
16396 return -99;
16397 }
16398
16399 if (vrf_set == 0)
16400 {
16401 errmsg ("VRF ID required but not specified\n");
16402 return -99;
16403 }
16404
16405 if (tcp_out_vrf_id == 0
16406 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
16407 {
16408 errmsg
16409 ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
16410 return -99;
16411 }
16412
16413 /* Construct the API message */
16414 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,
16415 ip_source_and_port_range_check_interface_add_del);
16416
16417 mp->sw_if_index = ntohl (sw_if_index);
16418 mp->is_add = is_add;
16419 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
16420 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
16421 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
16422 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
16423
16424 /* send it... */
16425 S;
16426
16427 /* Wait for a reply... */
16428 W;
16429}
16430
16431static int
Matus Fabian694265d2016-08-10 01:55:36 -070016432api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
16433{
16434 unformat_input_t *i = vam->input;
16435 vl_api_ipsec_gre_add_del_tunnel_t *mp;
16436 f64 timeout;
16437 u32 local_sa_id = 0;
16438 u32 remote_sa_id = 0;
16439 ip4_address_t src_address;
16440 ip4_address_t dst_address;
16441 u8 is_add = 1;
16442
16443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16444 {
16445 if (unformat (i, "local_sa %d", &local_sa_id))
16446 ;
16447 else if (unformat (i, "remote_sa %d", &remote_sa_id))
16448 ;
16449 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
16450 ;
16451 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
16452 ;
16453 else if (unformat (i, "del"))
16454 is_add = 0;
16455 else
16456 {
16457 clib_warning ("parse error '%U'", format_unformat_error, i);
16458 return -99;
16459 }
16460 }
16461
16462 M (IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel);
16463
16464 mp->local_sa_id = ntohl (local_sa_id);
16465 mp->remote_sa_id = ntohl (remote_sa_id);
16466 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
16467 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
16468 mp->is_add = is_add;
16469
16470 S;
16471 W;
16472 /* NOTREACHED */
16473 return 0;
16474}
16475
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070016476static int
16477api_punt (vat_main_t * vam)
16478{
16479 unformat_input_t *i = vam->input;
16480 vl_api_punt_t *mp;
16481 f64 timeout;
16482 u32 ipv = ~0;
16483 u32 protocol = ~0;
16484 u32 port = ~0;
16485 int is_add = 1;
16486
16487 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16488 {
16489 if (unformat (i, "ip %d", &ipv))
16490 ;
16491 else if (unformat (i, "protocol %d", &protocol))
16492 ;
16493 else if (unformat (i, "port %d", &port))
16494 ;
16495 else if (unformat (i, "del"))
16496 is_add = 0;
16497 else
16498 {
16499 clib_warning ("parse error '%U'", format_unformat_error, i);
16500 return -99;
16501 }
16502 }
16503
16504 M (PUNT, punt);
16505
16506 mp->is_add = (u8) is_add;
16507 mp->ipv = (u8) ipv;
16508 mp->l4_protocol = (u8) protocol;
16509 mp->l4_port = htons ((u16) port);
16510
16511 S;
16512 W;
16513 /* NOTREACHED */
16514 return 0;
16515}
16516
Matus Fabian694265d2016-08-10 01:55:36 -070016517static void vl_api_ipsec_gre_tunnel_details_t_handler
16518 (vl_api_ipsec_gre_tunnel_details_t * mp)
16519{
16520 vat_main_t *vam = &vat_main;
16521
16522 fformat (vam->ofp, "%11d%15U%15U%14d%14d\n",
16523 ntohl (mp->sw_if_index),
16524 format_ip4_address, &mp->src_address,
16525 format_ip4_address, &mp->dst_address,
16526 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
16527}
16528
16529static void vl_api_ipsec_gre_tunnel_details_t_handler_json
16530 (vl_api_ipsec_gre_tunnel_details_t * mp)
16531{
16532 vat_main_t *vam = &vat_main;
16533 vat_json_node_t *node = NULL;
16534 struct in_addr ip4;
16535
16536 if (VAT_JSON_ARRAY != vam->json_tree.type)
16537 {
16538 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16539 vat_json_init_array (&vam->json_tree);
16540 }
16541 node = vat_json_array_add (&vam->json_tree);
16542
16543 vat_json_init_object (node);
16544 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
16545 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
16546 vat_json_object_add_ip4 (node, "src_address", ip4);
16547 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
16548 vat_json_object_add_ip4 (node, "dst_address", ip4);
16549 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
16550 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
16551}
16552
16553static int
16554api_ipsec_gre_tunnel_dump (vat_main_t * vam)
16555{
16556 unformat_input_t *i = vam->input;
16557 vl_api_ipsec_gre_tunnel_dump_t *mp;
16558 f64 timeout;
16559 u32 sw_if_index;
16560 u8 sw_if_index_set = 0;
16561
16562 /* Parse args required to build the message */
16563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16564 {
16565 if (unformat (i, "sw_if_index %d", &sw_if_index))
16566 sw_if_index_set = 1;
16567 else
16568 break;
16569 }
16570
16571 if (sw_if_index_set == 0)
16572 {
16573 sw_if_index = ~0;
16574 }
16575
16576 if (!vam->json_output)
16577 {
16578 fformat (vam->ofp, "%11s%15s%15s%14s%14s\n",
16579 "sw_if_index", "src_address", "dst_address",
16580 "local_sa_id", "remote_sa_id");
16581 }
16582
16583 /* Get list of gre-tunnel interfaces */
16584 M (IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump);
16585
16586 mp->sw_if_index = htonl (sw_if_index);
16587
16588 S;
16589
16590 /* Use a control ping for synchronization */
16591 {
16592 vl_api_control_ping_t *mp;
16593 M (CONTROL_PING, control_ping);
16594 S;
16595 }
16596 W;
16597}
16598
16599static int
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016600api_delete_subif (vat_main_t * vam)
16601{
16602 unformat_input_t *i = vam->input;
16603 vl_api_delete_subif_t *mp;
16604 f64 timeout;
16605 u32 sw_if_index = ~0;
16606
16607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16608 {
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020016609 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16610 ;
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016611 if (unformat (i, "sw_if_index %d", &sw_if_index))
16612 ;
16613 else
16614 break;
16615 }
16616
16617 if (sw_if_index == ~0)
16618 {
16619 errmsg ("missing sw_if_index\n");
16620 return -99;
16621 }
16622
16623 /* Construct the API message */
16624 M (DELETE_SUBIF, delete_subif);
16625 mp->sw_if_index = ntohl (sw_if_index);
16626
16627 S;
16628 W;
16629}
16630
Pavel Kotucek95300d12016-08-26 16:11:36 +020016631#define foreach_pbb_vtr_op \
16632_("disable", L2_VTR_DISABLED) \
16633_("pop", L2_VTR_POP_2) \
16634_("push", L2_VTR_PUSH_2)
16635
16636static int
16637api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
16638{
16639 unformat_input_t *i = vam->input;
16640 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
16641 f64 timeout;
16642 u32 sw_if_index = ~0, vtr_op = ~0;
16643 u16 outer_tag = ~0;
16644 u8 dmac[6], smac[6];
16645 u8 dmac_set = 0, smac_set = 0;
16646 u16 vlanid = 0;
16647 u32 sid = ~0;
16648 u32 tmp;
16649
Dave Barach75665d32016-11-17 11:36:59 -050016650 /* Shut up coverity */
16651 memset (dmac, 0, sizeof (dmac));
16652 memset (smac, 0, sizeof (smac));
16653
Pavel Kotucek95300d12016-08-26 16:11:36 +020016654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16655 {
16656 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16657 ;
16658 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16659 ;
16660 else if (unformat (i, "vtr_op %d", &vtr_op))
16661 ;
16662#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
16663 foreach_pbb_vtr_op
16664#undef _
16665 else if (unformat (i, "translate_pbb_stag"))
16666 {
16667 if (unformat (i, "%d", &tmp))
16668 {
16669 vtr_op = L2_VTR_TRANSLATE_2_1;
16670 outer_tag = tmp;
16671 }
16672 else
16673 {
16674 errmsg
16675 ("translate_pbb_stag operation requires outer tag definition\n");
16676 return -99;
16677 }
16678 }
16679 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
16680 dmac_set++;
16681 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
16682 smac_set++;
16683 else if (unformat (i, "sid %d", &sid))
16684 ;
16685 else if (unformat (i, "vlanid %d", &tmp))
16686 vlanid = tmp;
16687 else
16688 {
16689 clib_warning ("parse error '%U'", format_unformat_error, i);
16690 return -99;
16691 }
16692 }
16693
16694 if ((sw_if_index == ~0) || (vtr_op == ~0))
16695 {
16696 errmsg ("missing sw_if_index or vtr operation\n");
16697 return -99;
16698 }
16699 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
16700 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
16701 {
16702 errmsg
16703 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid\n");
16704 return -99;
16705 }
16706
16707 M (L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite);
16708 mp->sw_if_index = ntohl (sw_if_index);
16709 mp->vtr_op = ntohl (vtr_op);
16710 mp->outer_tag = ntohs (outer_tag);
16711 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
16712 clib_memcpy (mp->b_smac, smac, sizeof (smac));
16713 mp->b_vlanid = ntohs (vlanid);
16714 mp->i_sid = ntohl (sid);
16715
16716 S;
16717 W;
16718 /* NOTREACHED */
16719 return 0;
16720}
16721
Pavel Kotucekd85590a2016-08-26 13:35:40 +020016722static int
Juraj Sloboda506b2452016-08-07 23:45:24 -070016723api_flow_classify_set_interface (vat_main_t * vam)
16724{
16725 unformat_input_t *i = vam->input;
16726 vl_api_flow_classify_set_interface_t *mp;
16727 f64 timeout;
16728 u32 sw_if_index;
16729 int sw_if_index_set;
16730 u32 ip4_table_index = ~0;
16731 u32 ip6_table_index = ~0;
16732 u8 is_add = 1;
16733
16734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16735 {
16736 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16737 sw_if_index_set = 1;
16738 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16739 sw_if_index_set = 1;
16740 else if (unformat (i, "del"))
16741 is_add = 0;
16742 else if (unformat (i, "ip4-table %d", &ip4_table_index))
16743 ;
16744 else if (unformat (i, "ip6-table %d", &ip6_table_index))
16745 ;
16746 else
16747 {
16748 clib_warning ("parse error '%U'", format_unformat_error, i);
16749 return -99;
16750 }
16751 }
16752
16753 if (sw_if_index_set == 0)
16754 {
16755 errmsg ("missing interface name or sw_if_index\n");
16756 return -99;
16757 }
16758
16759 M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface);
16760
16761 mp->sw_if_index = ntohl (sw_if_index);
16762 mp->ip4_table_index = ntohl (ip4_table_index);
16763 mp->ip6_table_index = ntohl (ip6_table_index);
16764 mp->is_add = is_add;
16765
16766 S;
16767 W;
16768 /* NOTREACHED */
16769 return 0;
16770}
16771
16772static int
16773api_flow_classify_dump (vat_main_t * vam)
16774{
16775 unformat_input_t *i = vam->input;
16776 vl_api_flow_classify_dump_t *mp;
16777 f64 timeout = ~0;
16778 u8 type = FLOW_CLASSIFY_N_TABLES;
16779
16780 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
16781 ;
16782 else
16783 {
16784 errmsg ("classify table type must be specified\n");
16785 return -99;
16786 }
16787
16788 if (!vam->json_output)
16789 {
16790 fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
16791 }
16792
16793 M (FLOW_CLASSIFY_DUMP, flow_classify_dump);
16794 mp->type = type;
16795 /* send it... */
16796 S;
16797
16798 /* Use a control ping for synchronization */
16799 {
16800 vl_api_control_ping_t *mp;
16801 M (CONTROL_PING, control_ping);
16802 S;
16803 }
16804 /* Wait for a reply... */
16805 W;
16806
16807 /* NOTREACHED */
16808 return 0;
16809}
16810
16811static int
Pavel Kotucek7490a752016-11-15 09:19:11 +010016812api_feature_enable_disable (vat_main_t * vam)
16813{
16814 unformat_input_t *i = vam->input;
16815 vl_api_feature_enable_disable_t *mp;
16816 f64 timeout;
16817 u8 *arc_name = 0;
16818 u8 *feature_name = 0;
16819 u32 sw_if_index = ~0;
16820 u8 enable = 1;
16821
16822 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16823 {
16824 if (unformat (i, "arc_name %s", &arc_name))
16825 ;
16826 else if (unformat (i, "feature_name %s", &feature_name))
16827 ;
16828 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16829 ;
16830 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16831 ;
16832 else if (unformat (i, "disable"))
16833 enable = 0;
16834 else
16835 break;
16836 }
16837
16838 if (arc_name == 0)
16839 {
16840 errmsg ("missing arc name\n");
16841 return -99;
16842 }
16843 if (vec_len (arc_name) > 63)
16844 {
16845 errmsg ("arc name too long\n");
16846 }
16847
16848 if (feature_name == 0)
16849 {
16850 errmsg ("missing feature name\n");
16851 return -99;
16852 }
16853 if (vec_len (feature_name) > 63)
16854 {
16855 errmsg ("feature name too long\n");
16856 }
16857
16858 if (sw_if_index == ~0)
16859 {
16860 errmsg ("missing interface name or sw_if_index\n");
16861 return -99;
16862 }
16863
16864 /* Construct the API message */
16865 M (FEATURE_ENABLE_DISABLE, feature_enable_disable);
16866 mp->sw_if_index = ntohl (sw_if_index);
16867 mp->enable = enable;
16868 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
16869 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
16870 vec_free (arc_name);
16871 vec_free (feature_name);
16872
16873 S;
16874 W;
16875}
16876
16877static int
Dave Barach7be864a2016-11-28 11:41:35 -050016878api_sw_interface_tag_add_del (vat_main_t * vam)
16879{
16880 unformat_input_t *i = vam->input;
16881 vl_api_sw_interface_tag_add_del_t *mp;
16882 f64 timeout;
16883 u32 sw_if_index = ~0;
16884 u8 *tag = 0;
16885 u8 enable = 1;
16886
16887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16888 {
16889 if (unformat (i, "tag %s", &tag))
16890 ;
16891 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16892 ;
16893 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16894 ;
16895 else if (unformat (i, "del"))
16896 enable = 0;
16897 else
16898 break;
16899 }
16900
16901 if (sw_if_index == ~0)
16902 {
16903 errmsg ("missing interface name or sw_if_index\n");
16904 return -99;
16905 }
16906
16907 if (enable && (tag == 0))
16908 {
16909 errmsg ("no tag specified\n");
16910 return -99;
16911 }
16912
16913 /* Construct the API message */
16914 M (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del);
16915 mp->sw_if_index = ntohl (sw_if_index);
16916 mp->is_add = enable;
16917 if (enable)
16918 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
16919 vec_free (tag);
16920
16921 S;
16922 W;
16923}
16924
Matus Fabianf468e232016-12-02 06:00:53 -080016925static void vl_api_l2_xconnect_details_t_handler
16926 (vl_api_l2_xconnect_details_t * mp)
16927{
16928 vat_main_t *vam = &vat_main;
16929
16930 fformat (vam->ofp, "%15d%15d\n",
16931 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
16932}
16933
16934static void vl_api_l2_xconnect_details_t_handler_json
16935 (vl_api_l2_xconnect_details_t * mp)
16936{
16937 vat_main_t *vam = &vat_main;
16938 vat_json_node_t *node = NULL;
16939
16940 if (VAT_JSON_ARRAY != vam->json_tree.type)
16941 {
16942 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
16943 vat_json_init_array (&vam->json_tree);
16944 }
16945 node = vat_json_array_add (&vam->json_tree);
16946
16947 vat_json_init_object (node);
16948 vat_json_object_add_uint (node, "rx_sw_if_index",
16949 ntohl (mp->rx_sw_if_index));
16950 vat_json_object_add_uint (node, "tx_sw_if_index",
16951 ntohl (mp->tx_sw_if_index));
16952}
16953
16954static int
16955api_l2_xconnect_dump (vat_main_t * vam)
16956{
16957 vl_api_l2_xconnect_dump_t *mp;
16958 f64 timeout;
16959
16960 if (!vam->json_output)
16961 {
16962 fformat (vam->ofp, "%15s%15s\n", "rx_sw_if_index", "tx_sw_if_index");
16963 }
16964
16965 M (L2_XCONNECT_DUMP, l2_xconnect_dump);
16966
16967 S;
16968
16969 /* Use a control ping for synchronization */
16970 {
16971 vl_api_control_ping_t *mp;
16972 M (CONTROL_PING, control_ping);
16973 S;
16974 }
16975 W;
16976}
16977
Dave Barach7be864a2016-11-28 11:41:35 -050016978static int
Matus Fabiand162f3d2016-12-05 01:05:35 -080016979api_sw_interface_set_mtu (vat_main_t * vam)
16980{
16981 unformat_input_t *i = vam->input;
16982 vl_api_sw_interface_set_mtu_t *mp;
16983 f64 timeout;
16984 u32 sw_if_index = ~0;
16985 u32 mtu = 0;
16986
16987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16988 {
16989 if (unformat (i, "mtu %d", &mtu))
16990 ;
16991 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
16992 ;
16993 else if (unformat (i, "sw_if_index %d", &sw_if_index))
16994 ;
16995 else
16996 break;
16997 }
16998
16999 if (sw_if_index == ~0)
17000 {
17001 errmsg ("missing interface name or sw_if_index\n");
17002 return -99;
17003 }
17004
17005 if (mtu == 0)
17006 {
17007 errmsg ("no mtu specified\n");
17008 return -99;
17009 }
17010
17011 /* Construct the API message */
17012 M (SW_INTERFACE_SET_MTU, sw_interface_set_mtu);
17013 mp->sw_if_index = ntohl (sw_if_index);
17014 mp->mtu = ntohs ((u16) mtu);
17015
17016 S;
17017 W;
17018}
17019
17020
17021static int
Dave Barach72d72232016-08-04 10:15:08 -040017022q_or_quit (vat_main_t * vam)
17023{
17024 longjmp (vam->jump_buf, 1);
17025 return 0; /* not so much */
17026}
17027
17028static int
17029q (vat_main_t * vam)
17030{
17031 return q_or_quit (vam);
17032}
17033
17034static int
17035quit (vat_main_t * vam)
17036{
17037 return q_or_quit (vam);
17038}
17039
17040static int
17041comment (vat_main_t * vam)
17042{
17043 return 0;
17044}
17045
17046static int
17047cmd_cmp (void *a1, void *a2)
17048{
17049 u8 **c1 = a1;
17050 u8 **c2 = a2;
17051
17052 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
17053}
17054
17055static int
17056help (vat_main_t * vam)
17057{
17058 u8 **cmds = 0;
17059 u8 *name = 0;
17060 hash_pair_t *p;
17061 unformat_input_t *i = vam->input;
17062 int j;
17063
17064 if (unformat (i, "%s", &name))
17065 {
17066 uword *hs;
17067
17068 vec_add1 (name, 0);
17069
17070 hs = hash_get_mem (vam->help_by_name, name);
17071 if (hs)
17072 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
17073 else
17074 fformat (vam->ofp, "No such msg / command '%s'\n", name);
17075 vec_free (name);
17076 return 0;
17077 }
17078
17079 fformat (vam->ofp, "Help is available for the following:\n");
17080
17081 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017082 hash_foreach_pair (p, vam->function_by_name,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017083 ({
Dave Barach72d72232016-08-04 10:15:08 -040017084 vec_add1 (cmds, (u8 *)(p->key));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017085 }));
Dave Barach72d72232016-08-04 10:15:08 -040017086 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017087
Dave Barach72d72232016-08-04 10:15:08 -040017088 vec_sort_with_function (cmds, cmd_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017089
Dave Barach72d72232016-08-04 10:15:08 -040017090 for (j = 0; j < vec_len (cmds); j++)
17091 fformat (vam->ofp, "%s\n", cmds[j]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017092
Dave Barach72d72232016-08-04 10:15:08 -040017093 vec_free (cmds);
17094 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017095}
17096
Dave Barach72d72232016-08-04 10:15:08 -040017097static int
17098set (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017099{
Dave Barach72d72232016-08-04 10:15:08 -040017100 u8 *name = 0, *value = 0;
17101 unformat_input_t *i = vam->input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017102
Dave Barach72d72232016-08-04 10:15:08 -040017103 if (unformat (i, "%s", &name))
17104 {
17105 /* The input buffer is a vector, not a string. */
17106 value = vec_dup (i->buffer);
17107 vec_delete (value, i->index, 0);
17108 /* Almost certainly has a trailing newline */
17109 if (value[vec_len (value) - 1] == '\n')
17110 value[vec_len (value) - 1] = 0;
17111 /* Make sure it's a proper string, one way or the other */
17112 vec_add1 (value, 0);
17113 (void) clib_macro_set_value (&vam->macro_main,
17114 (char *) name, (char *) value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017115 }
Dave Barach72d72232016-08-04 10:15:08 -040017116 else
17117 errmsg ("usage: set <name> <value>\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017118
Dave Barach72d72232016-08-04 10:15:08 -040017119 vec_free (name);
17120 vec_free (value);
17121 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017122}
17123
Dave Barach72d72232016-08-04 10:15:08 -040017124static int
17125unset (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017126{
Dave Barach72d72232016-08-04 10:15:08 -040017127 u8 *name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017128
Dave Barach72d72232016-08-04 10:15:08 -040017129 if (unformat (vam->input, "%s", &name))
17130 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
17131 errmsg ("unset: %s wasn't set\n", name);
17132 vec_free (name);
17133 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017134}
17135
Dave Barach72d72232016-08-04 10:15:08 -040017136typedef struct
17137{
17138 u8 *name;
17139 u8 *value;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017140} macro_sort_t;
17141
17142
Dave Barach72d72232016-08-04 10:15:08 -040017143static int
17144macro_sort_cmp (void *a1, void *a2)
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017145{
Dave Barach72d72232016-08-04 10:15:08 -040017146 macro_sort_t *s1 = a1;
17147 macro_sort_t *s2 = a2;
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017148
Dave Barach72d72232016-08-04 10:15:08 -040017149 return strcmp ((char *) (s1->name), (char *) (s2->name));
Matus Fabiand2dc3df2015-12-14 10:31:33 -050017150}
17151
Dave Barach72d72232016-08-04 10:15:08 -040017152static int
17153dump_macro_table (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017154{
Dave Barach72d72232016-08-04 10:15:08 -040017155 macro_sort_t *sort_me = 0, *sm;
17156 int i;
17157 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017158
Dave Barach72d72232016-08-04 10:15:08 -040017159 /* *INDENT-OFF* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017160 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
Ed Warnickecb9cada2015-12-08 15:45:58 -070017161 ({
Dave Barach72d72232016-08-04 10:15:08 -040017162 vec_add2 (sort_me, sm, 1);
17163 sm->name = (u8 *)(p->key);
17164 sm->value = (u8 *) (p->value[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017165 }));
Dave Barach72d72232016-08-04 10:15:08 -040017166 /* *INDENT-ON* */
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017167
Dave Barach72d72232016-08-04 10:15:08 -040017168 vec_sort_with_function (sort_me, macro_sort_cmp);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017169
Dave Barach72d72232016-08-04 10:15:08 -040017170 if (vec_len (sort_me))
17171 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
17172 else
17173 fformat (vam->ofp, "The macro table is empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -070017174
Dave Barach72d72232016-08-04 10:15:08 -040017175 for (i = 0; i < vec_len (sort_me); i++)
17176 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name, sort_me[i].value);
17177 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017178}
17179
Dave Barach72d72232016-08-04 10:15:08 -040017180static int
17181dump_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017182{
Dave Barach72d72232016-08-04 10:15:08 -040017183 int i, j;
17184 vlib_node_t *node, *next_node;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017185
Dave Barach72d72232016-08-04 10:15:08 -040017186 if (vec_len (vam->graph_nodes) == 0)
17187 {
17188 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17189 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017190 }
17191
Dave Barach72d72232016-08-04 10:15:08 -040017192 for (i = 0; i < vec_len (vam->graph_nodes); i++)
17193 {
17194 node = vam->graph_nodes[i];
17195 fformat (vam->ofp, "[%d] %s\n", i, node->name);
17196 for (j = 0; j < vec_len (node->next_nodes); j++)
17197 {
17198 if (node->next_nodes[j] != ~0)
17199 {
17200 next_node = vam->graph_nodes[node->next_nodes[j]];
17201 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17202 }
17203 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017204 }
Dave Barach72d72232016-08-04 10:15:08 -040017205 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017206}
17207
Dave Barach72d72232016-08-04 10:15:08 -040017208static int
Dave Barach557d1282016-11-10 14:22:49 -050017209value_sort_cmp (void *a1, void *a2)
17210{
17211 name_sort_t *n1 = a1;
17212 name_sort_t *n2 = a2;
17213
17214 if (n1->value < n2->value)
17215 return -1;
17216 if (n1->value > n2->value)
17217 return 1;
17218 return 0;
17219}
17220
17221
17222static int
17223dump_msg_api_table (vat_main_t * vam)
17224{
17225 api_main_t *am = &api_main;
17226 name_sort_t *nses = 0, *ns;
17227 hash_pair_t *hp;
17228 int i;
17229
17230 /* *INDENT-OFF* */
17231 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
17232 ({
17233 vec_add2 (nses, ns, 1);
17234 ns->name = (u8 *)(hp->key);
17235 ns->value = (u32) hp->value[0];
17236 }));
17237 /* *INDENT-ON* */
17238
17239 vec_sort_with_function (nses, value_sort_cmp);
17240
17241 for (i = 0; i < vec_len (nses); i++)
17242 fformat (vam->ofp, " [%d]: %s\n", nses[i].value, nses[i].name);
17243 vec_free (nses);
17244 return 0;
17245}
17246
17247static int
17248get_msg_id (vat_main_t * vam)
17249{
17250 u8 *name_and_crc;
17251 u32 message_index;
17252
17253 if (unformat (vam->input, "%s", &name_and_crc))
17254 {
17255 message_index = vl_api_get_msg_index (name_and_crc);
17256 if (message_index == ~0)
17257 {
17258 fformat (vam->ofp, " '%s' not found\n", name_and_crc);
17259 return 0;
17260 }
17261 fformat (vam->ofp, " '%s' has message index %d\n",
17262 name_and_crc, message_index);
17263 return 0;
17264 }
17265 errmsg ("name_and_crc required...\n");
17266 return 0;
17267}
17268
17269static int
Dave Barach72d72232016-08-04 10:15:08 -040017270search_node_table (vat_main_t * vam)
Dave Barachb44e9bc2016-02-19 09:06:23 -050017271{
Dave Barach72d72232016-08-04 10:15:08 -040017272 unformat_input_t *line_input = vam->input;
17273 u8 *node_to_find;
17274 int j;
17275 vlib_node_t *node, *next_node;
17276 uword *p;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017277
Dave Barach72d72232016-08-04 10:15:08 -040017278 if (vam->graph_node_index_by_name == 0)
17279 {
17280 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
17281 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017282 }
17283
Dave Barach72d72232016-08-04 10:15:08 -040017284 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
17285 {
17286 if (unformat (line_input, "%s", &node_to_find))
17287 {
17288 vec_add1 (node_to_find, 0);
17289 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
17290 if (p == 0)
17291 {
17292 fformat (vam->ofp, "%s not found...\n", node_to_find);
17293 goto out;
17294 }
17295 node = vam->graph_nodes[p[0]];
17296 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
17297 for (j = 0; j < vec_len (node->next_nodes); j++)
17298 {
17299 if (node->next_nodes[j] != ~0)
17300 {
17301 next_node = vam->graph_nodes[node->next_nodes[j]];
17302 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
17303 }
17304 }
17305 }
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017306
Dave Barach72d72232016-08-04 10:15:08 -040017307 else
17308 {
17309 clib_warning ("parse error '%U'", format_unformat_error,
17310 line_input);
17311 return -99;
17312 }
Dave Barachb44e9bc2016-02-19 09:06:23 -050017313
17314 out:
Dave Barach72d72232016-08-04 10:15:08 -040017315 vec_free (node_to_find);
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017316
Dave Barachb44e9bc2016-02-19 09:06:23 -050017317 }
17318
Dave Barach72d72232016-08-04 10:15:08 -040017319 return 0;
Dave Barachb44e9bc2016-02-19 09:06:23 -050017320}
17321
17322
Dave Barach72d72232016-08-04 10:15:08 -040017323static int
17324script (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017325{
Dave Barach72d72232016-08-04 10:15:08 -040017326 u8 *s = 0;
17327 char *save_current_file;
17328 unformat_input_t save_input;
17329 jmp_buf save_jump_buf;
17330 u32 save_line_number;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017331
Dave Barach72d72232016-08-04 10:15:08 -040017332 FILE *new_fp, *save_ifp;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017333
Dave Barach72d72232016-08-04 10:15:08 -040017334 if (unformat (vam->input, "%s", &s))
17335 {
17336 new_fp = fopen ((char *) s, "r");
17337 if (new_fp == 0)
17338 {
17339 errmsg ("Couldn't open script file %s\n", s);
17340 vec_free (s);
17341 return -99;
17342 }
17343 }
17344 else
17345 {
17346 errmsg ("Missing script name\n");
17347 return -99;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017348 }
17349
Dave Barach72d72232016-08-04 10:15:08 -040017350 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
17351 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
17352 save_ifp = vam->ifp;
17353 save_line_number = vam->input_line_number;
17354 save_current_file = (char *) vam->current_file;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017355
Dave Barach72d72232016-08-04 10:15:08 -040017356 vam->input_line_number = 0;
17357 vam->ifp = new_fp;
17358 vam->current_file = s;
17359 do_one_file (vam);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017360
Dave Barach72d72232016-08-04 10:15:08 -040017361 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
17362 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
17363 vam->ifp = save_ifp;
17364 vam->input_line_number = save_line_number;
17365 vam->current_file = (u8 *) save_current_file;
17366 vec_free (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017367
Dave Barach72d72232016-08-04 10:15:08 -040017368 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017369}
17370
Dave Barach72d72232016-08-04 10:15:08 -040017371static int
17372echo (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017373{
Dave Barach72d72232016-08-04 10:15:08 -040017374 fformat (vam->ofp, "%v", vam->input->buffer);
17375 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017376}
17377
17378/* List of API message constructors, CLI names map to api_xxx */
17379#define foreach_vpe_api_msg \
17380_(create_loopback,"[mac <mac-addr>]") \
17381_(sw_interface_dump,"") \
17382_(sw_interface_set_flags, \
17383 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
17384_(sw_interface_add_del_address, \
17385 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
17386_(sw_interface_set_table, \
17387 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
John Lo06b14b92016-10-24 20:20:11 -040017388_(sw_interface_set_mpls_enable, \
17389 "<intfc> | sw_if_index [disable | dis]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017390_(sw_interface_set_vpath, \
17391 "<intfc> | sw_if_index <id> enable | disable") \
John Lo37682e12016-11-30 12:51:39 -050017392_(sw_interface_set_vxlan_bypass, \
17393 "<intfc> | sw_if_index <id> [ip4 | ip6] enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017394_(sw_interface_set_l2_xconnect, \
17395 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17396 "enable | disable") \
17397_(sw_interface_set_l2_bridge, \
Calvine2c987e2016-08-03 16:53:13 -040017398 "<intfc> | sw_if_index <id> bd_id <bridge-domain-id>\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017399 "[shg <split-horizon-group>] [bvi]\n" \
17400 "enable | disable") \
Jasvinder Singh85ecc812016-07-21 17:02:19 +010017401_(sw_interface_set_dpdk_hqos_pipe, \
17402 "rx <intfc> | sw_if_index <id> subport <subport-id> pipe <pipe-id>\n" \
17403 "profile <profile-id>\n") \
17404_(sw_interface_set_dpdk_hqos_subport, \
17405 "rx <intfc> | sw_if_index <id> subport <subport-id> [rate <n>]\n" \
17406 "[bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] [period <n>]\n") \
17407_(sw_interface_set_dpdk_hqos_tctbl, \
17408 "rx <intfc> | sw_if_index <id> entry <n> tc <n> queue <n>\n") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017409_(bridge_domain_add_del, \
17410 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
17411_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
17412_(l2fib_add_del, \
Dave Barach41da02d2016-07-11 16:48:42 -070017413 "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 -070017414_(l2_flags, \
17415 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
17416_(bridge_flags, \
17417 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
17418_(tap_connect, \
Dave Barach7be864a2016-11-28 11:41:35 -050017419 "tapname <name> mac <mac-addr> | random-mac [tag <string>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017420_(tap_modify, \
17421 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
17422_(tap_delete, \
17423 "<vpp-if-name> | sw_if_index <id>") \
17424_(sw_interface_tap_dump, "") \
17425_(ip_add_del_route, \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017426 "<addr>/<mask> via <addr> [table-id <n>]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017427 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17428 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17429 "[multipath] [count <n>]") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017430_(mpls_route_add_del, \
17431 "<label> <eos> via <addr> [table-id <n>]\n" \
17432 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
17433 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
17434 "[multipath] [count <n>]") \
17435_(mpls_ip_bind_unbind, \
17436 "<label> <addr/len>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017437_(mpls_tunnel_add_del, \
17438 " via <addr> [table-id <n>]\n" \
17439 "sw_if_index <id>] [l2] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017440_(proxy_arp_add_del, \
17441 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
17442_(proxy_arp_intfc_enable_disable, \
17443 "<intfc> | sw_if_index <id> enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017444_(sw_interface_set_unnumbered, \
17445 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
17446_(ip_neighbor_add_del, \
Chris Luke49a69632016-07-08 10:34:00 -040017447 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
17448 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017449_(reset_vrf, "vrf <id> [ipv6]") \
17450_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
17451_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
17452 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
17453 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
17454 "[outer_vlan_id_any][inner_vlan_id_any]") \
17455_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
17456_(reset_fib, "vrf <n> [ipv6]") \
17457_(dhcp_proxy_config, \
17458 "svr <v46-address> src <v46-address>\n" \
17459 "insert-cid <n> [del]") \
17460_(dhcp_proxy_config_2, \
17461 "svr <v46-address> src <v46-address>\n" \
17462 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
17463_(dhcp_proxy_set_vss, \
17464 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
17465_(dhcp_client_config, \
17466 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
17467_(set_ip_flow_hash, \
17468 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
17469_(sw_interface_ip6_enable_disable, \
17470 "<intfc> | sw_if_index <id> enable | disable") \
17471_(sw_interface_ip6_set_link_local_address, \
17472 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
17473_(sw_interface_ip6nd_ra_prefix, \
17474 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
17475 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
17476 "[nolink] [isno]") \
17477_(sw_interface_ip6nd_ra_config, \
17478 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
Chris Luke33879c92016-06-28 19:54:21 -040017479 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017480 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
17481_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
17482_(l2_patch_add_del, \
17483 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
17484 "enable | disable") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017485_(sr_tunnel_add_del, \
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070017486 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
17487 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
17488 "[policy <policy_name>]") \
17489_(sr_policy_add_del, \
17490 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
17491_(sr_multicast_map_add_del, \
17492 "address [ip6 multicast address] sr-policy [policy name] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017493_(classify_add_del_table, \
17494 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
Juraj Sloboda288e8932016-12-06 21:25:19 +010017495 " [del] [del-chain] mask <mask-value>\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017496 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
17497 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017498_(classify_add_del_session, \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017499 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
17500 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
Steve Shin25e26dc2016-11-08 10:47:10 -080017501 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
17502 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017503_(classify_set_interface_ip_table, \
17504 "<intfc> | sw_if_index <nn> table <nn>") \
17505_(classify_set_interface_l2_tables, \
17506 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17507 " [other-table <nn>]") \
17508_(get_node_index, "node <node-name") \
17509_(add_node_next, "node <node-name> next <next-node-name>") \
17510_(l2tpv3_create_tunnel, \
17511 "client_address <ip6-addr> our_address <ip6-addr>\n" \
17512 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
17513 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
17514_(l2tpv3_set_tunnel_cookies, \
17515 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
17516 "[new_remote_cookie <nn>]\n") \
17517_(l2tpv3_interface_enable_disable, \
17518 "<intfc> | sw_if_index <nn> enable | disable") \
17519_(l2tpv3_set_lookup_key, \
17520 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
17521_(sw_if_l2tpv3_tunnel_dump, "") \
17522_(vxlan_add_del_tunnel, \
Eyal Baric5b13602016-11-24 19:42:43 +020017523 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
17524 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
Hongjun Nibeb4bf72016-11-25 00:03:46 +080017525 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Dave Wallace60231f32015-12-17 21:04:30 -050017526_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017527_(gre_add_del_tunnel, \
David Hothama8cd3092016-09-19 09:55:07 -070017528 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
Chris Luke27fe48f2016-04-28 13:44:38 -040017529_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017530_(l2_fib_clear_table, "") \
17531_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
17532_(l2_interface_vlan_tag_rewrite, \
17533 "<intfc> | sw_if_index <nn> \n" \
17534 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
17535 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
17536_(create_vhost_user_if, \
Pierre Pfisteref65cb02016-02-19 13:52:44 +000017537 "socket <filename> [server] [renumber <dev_instance>] " \
17538 "[mac <mac_address>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017539_(modify_vhost_user_if, \
17540 "<intfc> | sw_if_index <nn> socket <filename>\n" \
17541 "[server] [renumber <dev_instance>]") \
17542_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
17543_(sw_interface_vhost_user_dump, "") \
17544_(show_version, "") \
Hongjun Ni0e06e2b2016-05-30 19:45:51 +080017545_(vxlan_gpe_add_del_tunnel, \
17546 "local <addr> remote <addr> vni <nn>\n" \
17547 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
17548 "[next-ethernet] [next-nsh]\n") \
17549_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017550_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017551_(interface_name_renumber, \
17552 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
17553_(input_acl_set_interface, \
17554 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17555 " [l2-table <nn>] [del]") \
17556_(want_ip4_arp_events, "address <ip4-address> [del]") \
John Lo1edfba92016-08-27 01:11:57 -040017557_(want_ip6_nd_events, "address <ip6-address> [del]") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017558_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
17559_(ip_dump, "ipv4 | ipv6") \
17560_(ipsec_spd_add_del, "spd_id <n> [del]") \
17561_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
17562 " spid_id <n> ") \
17563_(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
17564 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
17565 " integ_alg <alg> integ_key <hex>") \
17566_(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
17567 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
17568 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
17569 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
17570_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matus Fabiane5f42fe2016-04-08 11:18:08 +020017571_(ikev2_profile_add_del, "name <profile_name> [del]") \
17572_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
17573 "(auth_data 0x<data> | auth_data <data>)") \
17574_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
17575 "(id_data 0x<data> | id_data <data>) (local|remote)") \
17576_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
17577 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
17578 "(local|remote)") \
17579_(ikev2_set_local_key, "file <absolute_file_path>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017580_(delete_loopback,"sw_if_index <nn>") \
17581_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
17582_(map_add_domain, \
17583 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
17584 "ip6-src <ip6addr> " \
17585 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
17586_(map_del_domain, "index <n>") \
17587_(map_add_del_rule, \
17588 "index <n> psid <n> dst <ip6addr> [del]") \
17589_(map_domain_dump, "") \
17590_(map_rule_dump, "index <map-domain>") \
17591_(want_interface_events, "enable|disable") \
17592_(want_stats,"enable|disable") \
Dave Barachc07bf5d2016-02-17 17:52:26 -050017593_(get_first_msg_id, "client <name>") \
17594_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
17595_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017596 "fib-id <nn> [ip4][ip6][default]") \
Pavel Kotucek00bbf272016-03-03 13:27:11 +010017597_(get_node_graph, " ") \
Shwetha20a64f52016-03-25 10:55:01 +000017598_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
Vengada Govindan07d2f842016-08-25 10:34:34 -070017599_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
17600_(ioam_disable, "") \
Andrej Kozemcaka8691752016-07-27 10:33:38 +020017601_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
17602 " sw_if_index <sw_if_index> p <priority> " \
17603 "w <weight>] [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017604_(lisp_add_del_locator, "locator-set <locator_name> " \
17605 "iface <intf> | sw_if_index <sw_if_index> " \
17606 "p <priority> w <weight> [del]") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017607_(lisp_add_del_local_eid,"vni <vni> eid " \
17608 "<ipv4|ipv6>/<prefix> | <L2 address> " \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017609 "locator-set <locator_name> [del]" \
17610 "[key-id sha1|sha256 secret-key <secret-key>]")\
Florin Coras429e7952016-08-02 02:31:03 +020017611_(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
17612 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017613_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017614_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Florin Coras577c3552016-04-21 00:45:40 +020017615_(lisp_gpe_enable_disable, "enable|disable") \
Filip Tehlar46d4e362016-05-09 09:39:26 +020017616_(lisp_enable_disable, "enable|disable") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017617_(lisp_map_register_enable_disable, "enable|disable") \
17618_(lisp_rloc_probe_enable_disable, "enable|disable") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017619_(lisp_gpe_add_del_iface, "up|down") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017620_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
17621 "[seid <seid>] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017622 "rloc <locator> p <prio> " \
Filip Tehlar4d5cabd2016-07-07 15:40:36 +020017623 "w <weight> [rloc <loc> ... ] " \
Andrej Kozemcak438109d2016-07-22 12:54:12 +020017624 "action <action> [del-all]") \
Filip Tehlar2fdaece2016-09-28 14:27:59 +020017625_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
17626 "<local-eid>") \
Filip Tehlar53f09e32016-05-19 14:25:44 +020017627_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Florin Corasdca88042016-09-14 16:01:38 +020017628_(lisp_map_request_mode, "src-dst|dst-only") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017629_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
Filip Tehlar324112f2016-06-02 16:07:38 +020017630_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
Filip Tehlarc5bb0d62016-09-02 12:14:31 +020017631_(lisp_locator_set_dump, "[local | remote]") \
17632_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
Andrej Kozemcak6cc6f912016-07-13 13:01:01 +020017633_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
17634 "[local] | [remote]") \
Filip Tehlar50a4e142016-08-24 11:28:02 +020017635_(lisp_eid_table_vni_dump, "") \
Filip Tehlarc0681792016-08-24 14:11:07 +020017636_(lisp_eid_table_map_dump, "l2|l3") \
Andrej Kozemcakb92feb62016-03-31 13:51:42 +020017637_(lisp_gpe_tunnel_dump, "") \
Andrej Kozemcaka9edd852016-05-02 12:14:33 +020017638_(lisp_map_resolver_dump, "") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017639_(lisp_map_server_dump, "") \
Filip Tehlar69a9b762016-09-23 10:00:52 +020017640_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar397fd7d2016-10-26 14:31:24 +020017641_(show_lisp_rloc_probe_state, "") \
17642_(show_lisp_map_register_state, "") \
Andrej Kozemcakd9831182016-06-20 08:47:57 +020017643_(show_lisp_status, "") \
Andrej Kozemcakb6e4d392016-06-14 13:55:57 +020017644_(lisp_get_map_request_itr_rlocs, "") \
Andrej Kozemcak914f91b2016-07-18 13:55:37 +020017645_(show_lisp_pitr, "") \
Florin Corasdca88042016-09-14 16:01:38 +020017646_(show_lisp_map_request_mode, "") \
Matus Fabian8a95a482016-05-06 15:14:13 +020017647_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
Matus Fabian65fcd4d2016-05-13 05:44:48 -070017648_(af_packet_delete, "name <host interface name>") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017649_(policer_add_del, "name <policer name> <params> [del]") \
Matus Fabiane8554802016-05-18 23:40:37 -070017650_(policer_dump, "[name <policer name>]") \
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017651_(policer_classify_set_interface, \
17652 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
17653 " [l2-table <nn>] [del]") \
17654_(policer_classify_dump, "type [ip4|ip6|l2]") \
Matus Fabian82e29c42016-05-11 04:49:46 -070017655_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
17656 "[master|slave]") \
marek zavodsky2c21a9a2016-06-21 05:35:16 +020017657_(netmap_delete, "name <interface name>") \
Neale Rannsad422ed2016-11-02 14:20:04 +000017658_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
Neale Ranns1357f3b2016-10-16 12:01:42 -070017659_(mpls_fib_dump, "") \
Pavel Kotucek20c90f72016-06-07 14:44:26 +020017660_(classify_table_ids, "") \
17661_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
17662_(classify_table_info, "table_id <nn>") \
Juraj Slobodaac645ad2016-07-07 00:18:57 -070017663_(classify_session_dump, "table_id <nn>") \
Juraj Slobodaffa652a2016-08-07 23:43:42 -070017664_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
17665 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
17666 "[template_interval <nn>] [udp_checksum]") \
17667_(ipfix_exporter_dump, "") \
17668_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
17669_(ipfix_classify_stream_dump, "") \
17670_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]")\
17671_(ipfix_classify_table_dump, "") \
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +010017672_(sw_interface_span_enable_disable, "[src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010017673_(sw_interface_span_dump, "") \
Pavel Kotucek9e6ed6e2016-07-12 10:18:26 +020017674_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
17675_(pg_create_interface, "if_id <nn>") \
17676_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
Dave Barach6f9bca22016-04-30 10:25:32 -040017677_(pg_enable_disable, "[stream <id>] disable") \
17678_(ip_source_and_port_range_check_add_del, \
17679 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
17680_(ip_source_and_port_range_check_interface_add_del, \
Keith Burns (alagalah)9d3a8792016-08-02 11:57:37 -070017681 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
Matus Fabian694265d2016-08-10 01:55:36 -070017682 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
17683_(ipsec_gre_add_del_tunnel, \
17684 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
Pavel Kotucekd85590a2016-08-26 13:35:40 +020017685_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
Pavel Kotucek7c8eda12016-10-17 15:31:59 +020017686_(delete_subif,"<intfc> | sw_if_index <nn>") \
Pavel Kotucek95300d12016-08-26 16:11:36 +020017687_(l2_interface_pbb_tag_rewrite, \
17688 "<intfc> | sw_if_index <nn> \n" \
Alexander Popovsky (apopovsk)4a7e58b2016-10-05 22:31:23 -070017689 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
17690 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Juraj Sloboda506b2452016-08-07 23:45:24 -070017691_(punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
17692_(flow_classify_set_interface, \
17693 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
Steven01b07122016-11-02 10:40:09 -070017694_(flow_classify_dump, "type [ip4|ip6]") \
17695_(ip_fib_dump, "") \
Pavel Kotucek7490a752016-11-15 09:19:11 +010017696_(ip6_fib_dump, "") \
17697_(feature_enable_disable, "arc_name <arc_name> " \
Dave Barach7be864a2016-11-28 11:41:35 -050017698 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
17699_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
Matus Fabianf468e232016-12-02 06:00:53 -080017700"[disable]") \
Matus Fabiand162f3d2016-12-05 01:05:35 -080017701_(l2_xconnect_dump, "") \
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010017702_(sw_interface_set_mtu, "<intfc> | sw_if_index <nn> mtu <nn>") \
Juraj Slobodadfc19232016-12-05 13:20:37 +010017703_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>") \
17704_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]")
Ed Warnickecb9cada2015-12-08 15:45:58 -070017705
17706/* List of command functions, CLI names map directly to functions */
17707#define foreach_cli_function \
17708_(comment, "usage: comment <ignore-rest-of-line>") \
17709_(dump_interface_table, "usage: dump_interface_table") \
17710_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
17711_(dump_ipv4_table, "usage: dump_ipv4_table") \
17712_(dump_ipv6_table, "usage: dump_ipv6_table") \
17713_(dump_stats_table, "usage: dump_stats_table") \
17714_(dump_macro_table, "usage: dump_macro_table ") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017715_(dump_node_table, "usage: dump_node_table") \
Dave Barach557d1282016-11-10 14:22:49 -050017716_(dump_msg_api_table, "usage: dump_msg_api_table") \
17717_(get_msg_id, "usage: get_msg_id name_and_crc") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017718_(echo, "usage: echo <message>") \
17719_(exec, "usage: exec <vpe-debug-CLI-command>") \
Ole Troanc27213a2016-08-31 14:50:49 +020017720_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017721_(help, "usage: help") \
17722_(q, "usage: quit") \
17723_(quit, "usage: quit") \
Dave Barachb44e9bc2016-02-19 09:06:23 -050017724_(search_node_table, "usage: search_node_table <name>...") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070017725_(set, "usage: set <variable-name> <value>") \
17726_(script, "usage: script <file-name>") \
17727_(unset, "usage: unset <variable-name>")
17728
17729#define _(N,n) \
17730 static void vl_api_##n##_t_handler_uni \
17731 (vl_api_##n##_t * mp) \
17732 { \
17733 vat_main_t * vam = &vat_main; \
17734 if (vam->json_output) { \
17735 vl_api_##n##_t_handler_json(mp); \
17736 } else { \
17737 vl_api_##n##_t_handler(mp); \
17738 } \
17739 }
17740foreach_vpe_api_reply_msg;
17741#undef _
17742
Dave Barach72d72232016-08-04 10:15:08 -040017743void
17744vat_api_hookup (vat_main_t * vam)
Ed Warnickecb9cada2015-12-08 15:45:58 -070017745{
17746#define _(N,n) \
17747 vl_msg_api_set_handlers(VL_API_##N, #n, \
17748 vl_api_##n##_t_handler_uni, \
17749 vl_noop_handler, \
17750 vl_api_##n##_t_endian, \
17751 vl_api_##n##_t_print, \
Hongjun Ni11bfc2f2016-07-22 18:19:19 +080017752 sizeof(vl_api_##n##_t), 1);
Dave Barach72d72232016-08-04 10:15:08 -040017753 foreach_vpe_api_reply_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017754#undef _
17755
Dave Barach72d72232016-08-04 10:15:08 -040017756 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070017757
Dave Barach72d72232016-08-04 10:15:08 -040017758 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017759
Dave Barach72d72232016-08-04 10:15:08 -040017760 vam->function_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017761
Dave Barach72d72232016-08-04 10:15:08 -040017762 vam->help_by_name = hash_create_string (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070017763
Dave Barach72d72232016-08-04 10:15:08 -040017764 /* API messages we can send */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017765#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
Dave Barach72d72232016-08-04 10:15:08 -040017766 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017767#undef _
17768
Dave Barach72d72232016-08-04 10:15:08 -040017769 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017770#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017771 foreach_vpe_api_msg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017772#undef _
17773
Dave Barach72d72232016-08-04 10:15:08 -040017774 /* CLI functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017775#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
Dave Barach72d72232016-08-04 10:15:08 -040017776 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017777#undef _
17778
Dave Barach72d72232016-08-04 10:15:08 -040017779 /* Help strings */
Ed Warnickecb9cada2015-12-08 15:45:58 -070017780#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
Dave Barach72d72232016-08-04 10:15:08 -040017781 foreach_cli_function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070017782#undef _
17783}
17784
Dave Barach72d72232016-08-04 10:15:08 -040017785/*
17786 * fd.io coding-style-patch-verification: ON
17787 *
17788 * Local Variables:
17789 * eval: (c-set-style "gnu")
17790 * End:
17791 */