api_format.c revision 1bf83b9d
1/*
2 *------------------------------------------------------------------
3 * api_format.c
4 *
5 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
6 * 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
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
21#include <vlib/pci/pci.h>
22#include <vpp/api/types.h>
23#include <vppinfra/socket.h>
24#include <vlibapi/api.h>
25#include <vlibmemory/api.h>
26#include <vnet/ip/ip.h>
27#include <vnet/ip-neighbor/ip_neighbor.h>
28#include <vnet/ip/ip_types_api.h>
29#include <vnet/l2/l2_input.h>
30#include <vnet/l2tp/l2tp.h>
31#include <vnet/vxlan/vxlan.h>
32#include <vnet/geneve/geneve.h>
33#include <vnet/gre/gre.h>
34#include <vnet/vxlan-gpe/vxlan_gpe.h>
35#include <vnet/lisp-gpe/lisp_gpe.h>
36
37#include <vpp/api/vpe_msg_enum.h>
38#include <vnet/l2/l2_classify.h>
39#include <vnet/l2/l2_vtr.h>
40#include <vnet/classify/in_out_acl.h>
41#include <vnet/classify/policer_classify.h>
42#include <vnet/classify/flow_classify.h>
43#include <vnet/mpls/mpls.h>
44#include <vnet/ipsec/ipsec.h>
45#include <inttypes.h>
46#include <vnet/cop/cop.h>
47#include <vnet/ip/ip6_hop_by_hop.h>
48#include <vnet/ip/ip_source_and_port_range_check.h>
49#include <vnet/policer/xlate.h>
50#include <vnet/span/span.h>
51#include <vnet/policer/policer.h>
52#include <vnet/policer/police.h>
53#include <vnet/mfib/mfib_types.h>
54#include <vnet/bonding/node.h>
55#include <vnet/qos/qos_types.h>
56#include <vnet/ethernet/ethernet_types_api.h>
57#include <vnet/ip/ip_types_api.h>
58#include "vat/json_format.h"
59#include <vnet/ip/ip_types_api.h>
60#include <vnet/ethernet/ethernet_types_api.h>
61
62#include <inttypes.h>
63#include <sys/stat.h>
64
65#define vl_typedefs		/* define message structures */
66#include <vpp/api/vpe_all_api_h.h>
67#undef vl_typedefs
68
69/* declare message handlers for each api */
70
71#define vl_endianfun		/* define message structures */
72#include <vpp/api/vpe_all_api_h.h>
73#undef vl_endianfun
74
75/* instantiate all the print functions we know about */
76#if VPP_API_TEST_BUILTIN == 0
77#define vl_print(handle, ...)
78#else
79#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
80#endif
81#define vl_printfun
82#include <vpp/api/vpe_all_api_h.h>
83#undef vl_printfun
84
85#define __plugin_msg_base 0
86#include <vlibapi/vat_helper_macros.h>
87
88#include <vnet/format_fns.h>
89
90void vl_api_set_elog_main (elog_main_t * m);
91int vl_api_set_elog_trace_api_messages (int enable);
92
93#if VPP_API_TEST_BUILTIN == 0
94#include <netdb.h>
95
96u32
97vl (void *p)
98{
99  return vec_len (p);
100}
101
102int
103vat_socket_connect (vat_main_t * vam)
104{
105  int rv;
106  vam->socket_client_main = &socket_client_main;
107  if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
108				      "vpp_api_test",
109				      0 /* default socket rx, tx buffer */ )))
110    return rv;
111  /* vpp expects the client index in network order */
112  vam->my_client_index = htonl (socket_client_main.client_index);
113  return 0;
114}
115#else /* vpp built-in case, we don't do sockets... */
116int
117vat_socket_connect (vat_main_t * vam)
118{
119  return 0;
120}
121
122int
123vl_socket_client_read (int wait)
124{
125  return -1;
126};
127
128int
129vl_socket_client_write ()
130{
131  return -1;
132};
133
134void *
135vl_socket_client_msg_alloc (int nbytes)
136{
137  return 0;
138}
139#endif
140
141
142f64
143vat_time_now (vat_main_t * vam)
144{
145#if VPP_API_TEST_BUILTIN
146  return vlib_time_now (vam->vlib_main);
147#else
148  return clib_time_now (&vam->clib_time);
149#endif
150}
151
152void
153errmsg (char *fmt, ...)
154{
155  vat_main_t *vam = &vat_main;
156  va_list va;
157  u8 *s;
158
159  va_start (va, fmt);
160  s = va_format (0, fmt, &va);
161  va_end (va);
162
163  vec_add1 (s, 0);
164
165#if VPP_API_TEST_BUILTIN
166  vlib_cli_output (vam->vlib_main, (char *) s);
167#else
168  {
169    if (vam->ifp != stdin)
170      fformat (vam->ofp, "%s(%d): \n", vam->current_file,
171	       vam->input_line_number);
172    else
173      fformat (vam->ofp, "%s\n", (char *) s);
174    fflush (vam->ofp);
175  }
176#endif
177
178  vec_free (s);
179}
180
181#if VPP_API_TEST_BUILTIN == 0
182static uword
183api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
184{
185  vat_main_t *vam = va_arg (*args, vat_main_t *);
186  u32 *result = va_arg (*args, u32 *);
187  u8 *if_name;
188  uword *p;
189
190  if (!unformat (input, "%s", &if_name))
191    return 0;
192
193  p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
194  if (p == 0)
195    return 0;
196  *result = p[0];
197  return 1;
198}
199
200static uword
201api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
202{
203  return 0;
204}
205
206/* Parse an IP4 address %d.%d.%d.%d. */
207uword
208unformat_ip4_address (unformat_input_t * input, va_list * args)
209{
210  u8 *result = va_arg (*args, u8 *);
211  unsigned a[4];
212
213  if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
214    return 0;
215
216  if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217    return 0;
218
219  result[0] = a[0];
220  result[1] = a[1];
221  result[2] = a[2];
222  result[3] = a[3];
223
224  return 1;
225}
226
227uword
228unformat_ethernet_address (unformat_input_t * input, va_list * args)
229{
230  u8 *result = va_arg (*args, u8 *);
231  u32 i, a[6];
232
233  if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
234		 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
235    return 0;
236
237  /* Check range. */
238  for (i = 0; i < 6; i++)
239    if (a[i] >= (1 << 8))
240      return 0;
241
242  for (i = 0; i < 6; i++)
243    result[i] = a[i];
244
245  return 1;
246}
247
248/* Returns ethernet type as an int in host byte order. */
249uword
250unformat_ethernet_type_host_byte_order (unformat_input_t * input,
251					va_list * args)
252{
253  u16 *result = va_arg (*args, u16 *);
254  int type;
255
256  /* Numeric type. */
257  if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
258    {
259      if (type >= (1 << 16))
260	return 0;
261      *result = type;
262      return 1;
263    }
264  return 0;
265}
266
267/* Parse an IP6 address. */
268uword
269unformat_ip6_address (unformat_input_t * input, va_list * args)
270{
271  ip6_address_t *result = va_arg (*args, ip6_address_t *);
272  u16 hex_quads[8];
273  uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
274  uword c, n_colon, double_colon_index;
275
276  n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
277  double_colon_index = ARRAY_LEN (hex_quads);
278  while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
279    {
280      hex_digit = 16;
281      if (c >= '0' && c <= '9')
282	hex_digit = c - '0';
283      else if (c >= 'a' && c <= 'f')
284	hex_digit = c + 10 - 'a';
285      else if (c >= 'A' && c <= 'F')
286	hex_digit = c + 10 - 'A';
287      else if (c == ':' && n_colon < 2)
288	n_colon++;
289      else
290	{
291	  unformat_put_input (input);
292	  break;
293	}
294
295      /* Too many hex quads. */
296      if (n_hex_quads >= ARRAY_LEN (hex_quads))
297	return 0;
298
299      if (hex_digit < 16)
300	{
301	  hex_quad = (hex_quad << 4) | hex_digit;
302
303	  /* Hex quad must fit in 16 bits. */
304	  if (n_hex_digits >= 4)
305	    return 0;
306
307	  n_colon = 0;
308	  n_hex_digits++;
309	}
310
311      /* Save position of :: */
312      if (n_colon == 2)
313	{
314	  /* More than one :: ? */
315	  if (double_colon_index < ARRAY_LEN (hex_quads))
316	    return 0;
317	  double_colon_index = n_hex_quads;
318	}
319
320      if (n_colon > 0 && n_hex_digits > 0)
321	{
322	  hex_quads[n_hex_quads++] = hex_quad;
323	  hex_quad = 0;
324	  n_hex_digits = 0;
325	}
326    }
327
328  if (n_hex_digits > 0)
329    hex_quads[n_hex_quads++] = hex_quad;
330
331  {
332    word i;
333
334    /* Expand :: to appropriate number of zero hex quads. */
335    if (double_colon_index < ARRAY_LEN (hex_quads))
336      {
337	word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
338
339	for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
340	  hex_quads[n_zero + i] = hex_quads[i];
341
342	for (i = 0; i < n_zero; i++)
343	  hex_quads[double_colon_index + i] = 0;
344
345	n_hex_quads = ARRAY_LEN (hex_quads);
346      }
347
348    /* Too few hex quads given. */
349    if (n_hex_quads < ARRAY_LEN (hex_quads))
350      return 0;
351
352    for (i = 0; i < ARRAY_LEN (hex_quads); i++)
353      result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
354
355    return 1;
356  }
357}
358
359uword
360unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
361{
362  u32 *r = va_arg (*args, u32 *);
363
364  if (0);
365#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
366  foreach_ipsec_policy_action
367#undef _
368    else
369    return 0;
370  return 1;
371}
372
373u8 *
374format_ipsec_crypto_alg (u8 * s, va_list * args)
375{
376  u32 i = va_arg (*args, u32);
377  u8 *t = 0;
378
379  switch (i)
380    {
381#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
382      foreach_ipsec_crypto_alg
383#undef _
384    default:
385      return format (s, "unknown");
386    }
387  return format (s, "%s", t);
388}
389
390u8 *
391format_ipsec_integ_alg (u8 * s, va_list * args)
392{
393  u32 i = va_arg (*args, u32);
394  u8 *t = 0;
395
396  switch (i)
397    {
398#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
399      foreach_ipsec_integ_alg
400#undef _
401    default:
402      return format (s, "unknown");
403    }
404  return format (s, "%s", t);
405}
406
407#else /* VPP_API_TEST_BUILTIN == 1 */
408static uword
409api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
410{
411  vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
412  vnet_main_t *vnm = vnet_get_main ();
413  u32 *result = va_arg (*args, u32 *);
414
415  return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
416}
417
418static uword
419api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
420{
421  vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
422  vnet_main_t *vnm = vnet_get_main ();
423  u32 *result = va_arg (*args, u32 *);
424
425  return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
426}
427
428#endif /* VPP_API_TEST_BUILTIN */
429
430uword
431unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
432{
433  u32 *r = va_arg (*args, u32 *);
434
435  if (0);
436#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
437  foreach_ipsec_crypto_alg
438#undef _
439    else
440    return 0;
441  return 1;
442}
443
444uword
445unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
446{
447  u32 *r = va_arg (*args, u32 *);
448
449  if (0);
450#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
451  foreach_ipsec_integ_alg
452#undef _
453    else
454    return 0;
455  return 1;
456}
457
458static uword
459unformat_policer_rate_type (unformat_input_t * input, va_list * args)
460{
461  u8 *r = va_arg (*args, u8 *);
462
463  if (unformat (input, "kbps"))
464    *r = SSE2_QOS_RATE_KBPS;
465  else if (unformat (input, "pps"))
466    *r = SSE2_QOS_RATE_PPS;
467  else
468    return 0;
469  return 1;
470}
471
472static uword
473unformat_policer_round_type (unformat_input_t * input, va_list * args)
474{
475  u8 *r = va_arg (*args, u8 *);
476
477  if (unformat (input, "closest"))
478    *r = SSE2_QOS_ROUND_TO_CLOSEST;
479  else if (unformat (input, "up"))
480    *r = SSE2_QOS_ROUND_TO_UP;
481  else if (unformat (input, "down"))
482    *r = SSE2_QOS_ROUND_TO_DOWN;
483  else
484    return 0;
485  return 1;
486}
487
488static uword
489unformat_policer_type (unformat_input_t * input, va_list * args)
490{
491  u8 *r = va_arg (*args, u8 *);
492
493  if (unformat (input, "1r2c"))
494    *r = SSE2_QOS_POLICER_TYPE_1R2C;
495  else if (unformat (input, "1r3c"))
496    *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
497  else if (unformat (input, "2r3c-2698"))
498    *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
499  else if (unformat (input, "2r3c-4115"))
500    *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
501  else if (unformat (input, "2r3c-mef5cf1"))
502    *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
503  else
504    return 0;
505  return 1;
506}
507
508static uword
509unformat_dscp (unformat_input_t * input, va_list * va)
510{
511  u8 *r = va_arg (*va, u8 *);
512
513  if (0);
514#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
515  foreach_vnet_dscp
516#undef _
517    else
518    return 0;
519  return 1;
520}
521
522static uword
523unformat_policer_action_type (unformat_input_t * input, va_list * va)
524{
525  sse2_qos_pol_action_params_st *a
526    = va_arg (*va, sse2_qos_pol_action_params_st *);
527
528  if (unformat (input, "drop"))
529    a->action_type = SSE2_QOS_ACTION_DROP;
530  else if (unformat (input, "transmit"))
531    a->action_type = SSE2_QOS_ACTION_TRANSMIT;
532  else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
533    a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
534  else
535    return 0;
536  return 1;
537}
538
539static uword
540unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
541{
542  u32 *r = va_arg (*va, u32 *);
543  u32 tid;
544
545  if (unformat (input, "ip4"))
546    tid = POLICER_CLASSIFY_TABLE_IP4;
547  else if (unformat (input, "ip6"))
548    tid = POLICER_CLASSIFY_TABLE_IP6;
549  else if (unformat (input, "l2"))
550    tid = POLICER_CLASSIFY_TABLE_L2;
551  else
552    return 0;
553
554  *r = tid;
555  return 1;
556}
557
558static uword
559unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
560{
561  u32 *r = va_arg (*va, u32 *);
562  u32 tid;
563
564  if (unformat (input, "ip4"))
565    tid = FLOW_CLASSIFY_TABLE_IP4;
566  else if (unformat (input, "ip6"))
567    tid = FLOW_CLASSIFY_TABLE_IP6;
568  else
569    return 0;
570
571  *r = tid;
572  return 1;
573}
574
575#if (VPP_API_TEST_BUILTIN==0)
576
577static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
578static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
579static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
580static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
581
582uword
583unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
584{
585  mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
586  mfib_itf_attribute_t attr;
587
588  old = *iflags;
589  FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
590  {
591    if (unformat (input, mfib_itf_flag_long_names[attr]))
592      *iflags |= (1 << attr);
593  }
594  FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
595  {
596    if (unformat (input, mfib_itf_flag_names[attr]))
597      *iflags |= (1 << attr);
598  }
599
600  return (old == *iflags ? 0 : 1);
601}
602
603uword
604unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
605{
606  mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
607  mfib_entry_attribute_t attr;
608
609  old = *eflags;
610  FOR_EACH_MFIB_ATTRIBUTE (attr)
611  {
612    if (unformat (input, mfib_flag_long_names[attr]))
613      *eflags |= (1 << attr);
614  }
615  FOR_EACH_MFIB_ATTRIBUTE (attr)
616  {
617    if (unformat (input, mfib_flag_names[attr]))
618      *eflags |= (1 << attr);
619  }
620
621  return (old == *eflags ? 0 : 1);
622}
623
624u8 *
625format_ip4_address (u8 * s, va_list * args)
626{
627  u8 *a = va_arg (*args, u8 *);
628  return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
629}
630
631u8 *
632format_ip6_address (u8 * s, va_list * args)
633{
634  ip6_address_t *a = va_arg (*args, ip6_address_t *);
635  u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
636
637  i_max_n_zero = ARRAY_LEN (a->as_u16);
638  max_n_zeros = 0;
639  i_first_zero = i_max_n_zero;
640  n_zeros = 0;
641  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
642    {
643      u32 is_zero = a->as_u16[i] == 0;
644      if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
645	{
646	  i_first_zero = i;
647	  n_zeros = 0;
648	}
649      n_zeros += is_zero;
650      if ((!is_zero && n_zeros > max_n_zeros)
651	  || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
652	{
653	  i_max_n_zero = i_first_zero;
654	  max_n_zeros = n_zeros;
655	  i_first_zero = ARRAY_LEN (a->as_u16);
656	  n_zeros = 0;
657	}
658    }
659
660  last_double_colon = 0;
661  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
662    {
663      if (i == i_max_n_zero && max_n_zeros > 1)
664	{
665	  s = format (s, "::");
666	  i += max_n_zeros - 1;
667	  last_double_colon = 1;
668	}
669      else
670	{
671	  s = format (s, "%s%x",
672		      (last_double_colon || i == 0) ? "" : ":",
673		      clib_net_to_host_u16 (a->as_u16[i]));
674	  last_double_colon = 0;
675	}
676    }
677
678  return s;
679}
680
681/* Format an IP46 address. */
682u8 *
683format_ip46_address (u8 * s, va_list * args)
684{
685  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
686  ip46_type_t type = va_arg (*args, ip46_type_t);
687  int is_ip4 = 1;
688
689  switch (type)
690    {
691    case IP46_TYPE_ANY:
692      is_ip4 = ip46_address_is_ip4 (ip46);
693      break;
694    case IP46_TYPE_IP4:
695      is_ip4 = 1;
696      break;
697    case IP46_TYPE_IP6:
698      is_ip4 = 0;
699      break;
700    }
701
702  return is_ip4 ?
703    format (s, "%U", format_ip4_address, &ip46->ip4) :
704    format (s, "%U", format_ip6_address, &ip46->ip6);
705}
706
707u8 *
708format_ethernet_address (u8 * s, va_list * args)
709{
710  u8 *a = va_arg (*args, u8 *);
711
712  return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
713		 a[0], a[1], a[2], a[3], a[4], a[5]);
714}
715#endif
716
717static void
718increment_v4_address (vl_api_ip4_address_t * i)
719{
720  ip4_address_t *a = (ip4_address_t *) i;
721  u32 v;
722
723  v = ntohl (a->as_u32) + 1;
724  a->as_u32 = ntohl (v);
725}
726
727static void
728increment_v6_address (vl_api_ip6_address_t * i)
729{
730  ip6_address_t *a = (ip6_address_t *) i;
731  u64 v0, v1;
732
733  v0 = clib_net_to_host_u64 (a->as_u64[0]);
734  v1 = clib_net_to_host_u64 (a->as_u64[1]);
735
736  v1 += 1;
737  if (v1 == 0)
738    v0 += 1;
739  a->as_u64[0] = clib_net_to_host_u64 (v0);
740  a->as_u64[1] = clib_net_to_host_u64 (v1);
741}
742
743static void
744increment_address (vl_api_address_t * a)
745{
746  if (clib_net_to_host_u32 (a->af) == ADDRESS_IP4)
747    increment_v4_address (&a->un.ip4);
748  else if (clib_net_to_host_u32 (a->af) == ADDRESS_IP6)
749    increment_v6_address (&a->un.ip6);
750}
751
752static void
753set_ip4_address (vl_api_address_t * a, u32 v)
754{
755  if (a->af == ADDRESS_IP4)
756    {
757      ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
758      i->as_u32 = v;
759    }
760}
761
762static void
763increment_mac_address (u8 * mac)
764{
765  u64 tmp = *((u64 *) mac);
766  tmp = clib_net_to_host_u64 (tmp);
767  tmp += 1 << 16;		/* skip unused (least significant) octets */
768  tmp = clib_host_to_net_u64 (tmp);
769
770  clib_memcpy (mac, &tmp, 6);
771}
772
773static void
774vat_json_object_add_address (vat_json_node_t * node,
775			     const char *str, const vl_api_address_t * addr)
776{
777  if (ADDRESS_IP6 == addr->af)
778    {
779      struct in6_addr ip6;
780
781      clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
782      vat_json_object_add_ip6 (node, str, ip6);
783    }
784  else
785    {
786      struct in_addr ip4;
787
788      clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
789      vat_json_object_add_ip4 (node, str, ip4);
790    }
791}
792
793static void
794vat_json_object_add_prefix (vat_json_node_t * node,
795			    const vl_api_prefix_t * prefix)
796{
797  vat_json_object_add_uint (node, "len", prefix->len);
798  vat_json_object_add_address (node, "address", &prefix->address);
799}
800
801static void vl_api_create_loopback_reply_t_handler
802  (vl_api_create_loopback_reply_t * mp)
803{
804  vat_main_t *vam = &vat_main;
805  i32 retval = ntohl (mp->retval);
806
807  vam->retval = retval;
808  vam->regenerate_interface_table = 1;
809  vam->sw_if_index = ntohl (mp->sw_if_index);
810  vam->result_ready = 1;
811}
812
813static void vl_api_create_loopback_reply_t_handler_json
814  (vl_api_create_loopback_reply_t * mp)
815{
816  vat_main_t *vam = &vat_main;
817  vat_json_node_t node;
818
819  vat_json_init_object (&node);
820  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
821  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
822
823  vat_json_print (vam->ofp, &node);
824  vat_json_free (&node);
825  vam->retval = ntohl (mp->retval);
826  vam->result_ready = 1;
827}
828
829static void vl_api_create_loopback_instance_reply_t_handler
830  (vl_api_create_loopback_instance_reply_t * mp)
831{
832  vat_main_t *vam = &vat_main;
833  i32 retval = ntohl (mp->retval);
834
835  vam->retval = retval;
836  vam->regenerate_interface_table = 1;
837  vam->sw_if_index = ntohl (mp->sw_if_index);
838  vam->result_ready = 1;
839}
840
841static void vl_api_create_loopback_instance_reply_t_handler_json
842  (vl_api_create_loopback_instance_reply_t * mp)
843{
844  vat_main_t *vam = &vat_main;
845  vat_json_node_t node;
846
847  vat_json_init_object (&node);
848  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
849  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
850
851  vat_json_print (vam->ofp, &node);
852  vat_json_free (&node);
853  vam->retval = ntohl (mp->retval);
854  vam->result_ready = 1;
855}
856
857static void vl_api_af_packet_create_reply_t_handler
858  (vl_api_af_packet_create_reply_t * mp)
859{
860  vat_main_t *vam = &vat_main;
861  i32 retval = ntohl (mp->retval);
862
863  vam->retval = retval;
864  vam->regenerate_interface_table = 1;
865  vam->sw_if_index = ntohl (mp->sw_if_index);
866  vam->result_ready = 1;
867}
868
869static void vl_api_af_packet_create_reply_t_handler_json
870  (vl_api_af_packet_create_reply_t * mp)
871{
872  vat_main_t *vam = &vat_main;
873  vat_json_node_t node;
874
875  vat_json_init_object (&node);
876  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
877  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
878
879  vat_json_print (vam->ofp, &node);
880  vat_json_free (&node);
881
882  vam->retval = ntohl (mp->retval);
883  vam->result_ready = 1;
884}
885
886static void vl_api_create_vlan_subif_reply_t_handler
887  (vl_api_create_vlan_subif_reply_t * mp)
888{
889  vat_main_t *vam = &vat_main;
890  i32 retval = ntohl (mp->retval);
891
892  vam->retval = retval;
893  vam->regenerate_interface_table = 1;
894  vam->sw_if_index = ntohl (mp->sw_if_index);
895  vam->result_ready = 1;
896}
897
898static void vl_api_create_vlan_subif_reply_t_handler_json
899  (vl_api_create_vlan_subif_reply_t * mp)
900{
901  vat_main_t *vam = &vat_main;
902  vat_json_node_t node;
903
904  vat_json_init_object (&node);
905  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
906  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
907
908  vat_json_print (vam->ofp, &node);
909  vat_json_free (&node);
910
911  vam->retval = ntohl (mp->retval);
912  vam->result_ready = 1;
913}
914
915static void vl_api_create_subif_reply_t_handler
916  (vl_api_create_subif_reply_t * mp)
917{
918  vat_main_t *vam = &vat_main;
919  i32 retval = ntohl (mp->retval);
920
921  vam->retval = retval;
922  vam->regenerate_interface_table = 1;
923  vam->sw_if_index = ntohl (mp->sw_if_index);
924  vam->result_ready = 1;
925}
926
927static void vl_api_create_subif_reply_t_handler_json
928  (vl_api_create_subif_reply_t * mp)
929{
930  vat_main_t *vam = &vat_main;
931  vat_json_node_t node;
932
933  vat_json_init_object (&node);
934  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
935  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
936
937  vat_json_print (vam->ofp, &node);
938  vat_json_free (&node);
939
940  vam->retval = ntohl (mp->retval);
941  vam->result_ready = 1;
942}
943
944static void vl_api_interface_name_renumber_reply_t_handler
945  (vl_api_interface_name_renumber_reply_t * mp)
946{
947  vat_main_t *vam = &vat_main;
948  i32 retval = ntohl (mp->retval);
949
950  vam->retval = retval;
951  vam->regenerate_interface_table = 1;
952  vam->result_ready = 1;
953}
954
955static void vl_api_interface_name_renumber_reply_t_handler_json
956  (vl_api_interface_name_renumber_reply_t * mp)
957{
958  vat_main_t *vam = &vat_main;
959  vat_json_node_t node;
960
961  vat_json_init_object (&node);
962  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
963
964  vat_json_print (vam->ofp, &node);
965  vat_json_free (&node);
966
967  vam->retval = ntohl (mp->retval);
968  vam->result_ready = 1;
969}
970
971/*
972 * Special-case: build the interface table, maintain
973 * the next loopback sw_if_index vbl.
974 */
975static void vl_api_sw_interface_details_t_handler
976  (vl_api_sw_interface_details_t * mp)
977{
978  vat_main_t *vam = &vat_main;
979  u8 *s = format (0, "%s%c", mp->interface_name, 0);
980
981  hash_set_mem (vam->sw_if_index_by_interface_name, s,
982		ntohl (mp->sw_if_index));
983
984  /* In sub interface case, fill the sub interface table entry */
985  if (mp->sw_if_index != mp->sup_sw_if_index)
986    {
987      sw_interface_subif_t *sub = NULL;
988
989      vec_add2 (vam->sw_if_subif_table, sub, 1);
990
991      vec_validate (sub->interface_name, strlen ((char *) s) + 1);
992      strncpy ((char *) sub->interface_name, (char *) s,
993	       vec_len (sub->interface_name));
994      sub->sw_if_index = ntohl (mp->sw_if_index);
995      sub->sub_id = ntohl (mp->sub_id);
996
997      sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
998
999      sub->sub_number_of_tags = mp->sub_number_of_tags;
1000      sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1001      sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
1002
1003      /* vlan tag rewrite */
1004      sub->vtr_op = ntohl (mp->vtr_op);
1005      sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1006      sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1007      sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1008    }
1009}
1010
1011static void vl_api_sw_interface_details_t_handler_json
1012  (vl_api_sw_interface_details_t * mp)
1013{
1014  vat_main_t *vam = &vat_main;
1015  vat_json_node_t *node = NULL;
1016
1017  if (VAT_JSON_ARRAY != vam->json_tree.type)
1018    {
1019      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1020      vat_json_init_array (&vam->json_tree);
1021    }
1022  node = vat_json_array_add (&vam->json_tree);
1023
1024  vat_json_init_object (node);
1025  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1026  vat_json_object_add_uint (node, "sup_sw_if_index",
1027			    ntohl (mp->sup_sw_if_index));
1028  vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1029			     sizeof (mp->l2_address));
1030  vat_json_object_add_string_copy (node, "interface_name",
1031				   mp->interface_name);
1032  vat_json_object_add_string_copy (node, "interface_dev_type",
1033				   mp->interface_dev_type);
1034  vat_json_object_add_uint (node, "flags", mp->flags);
1035  vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1036  vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1037  vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1038  vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1039  vat_json_object_add_uint (node, "sub_number_of_tags",
1040			    mp->sub_number_of_tags);
1041  vat_json_object_add_uint (node, "sub_outer_vlan_id",
1042			    ntohs (mp->sub_outer_vlan_id));
1043  vat_json_object_add_uint (node, "sub_inner_vlan_id",
1044			    ntohs (mp->sub_inner_vlan_id));
1045  vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1046  vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1047  vat_json_object_add_uint (node, "vtr_push_dot1q",
1048			    ntohl (mp->vtr_push_dot1q));
1049  vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1050  vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1051  if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1052    {
1053      vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1054				       format (0, "%U",
1055					       format_ethernet_address,
1056					       &mp->b_dmac));
1057      vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1058				       format (0, "%U",
1059					       format_ethernet_address,
1060					       &mp->b_smac));
1061      vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1062      vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1063    }
1064}
1065
1066#if VPP_API_TEST_BUILTIN == 0
1067static void vl_api_sw_interface_event_t_handler
1068  (vl_api_sw_interface_event_t * mp)
1069{
1070  vat_main_t *vam = &vat_main;
1071  if (vam->interface_event_display)
1072    errmsg ("interface flags: sw_if_index %d %s %s",
1073	    ntohl (mp->sw_if_index),
1074	    ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1075	    "admin-up" : "admin-down",
1076	    ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1077	    "link-up" : "link-down");
1078}
1079#endif
1080
1081__clib_unused static void
1082vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1083{
1084  /* JSON output not supported */
1085}
1086
1087static void
1088vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1089{
1090  vat_main_t *vam = &vat_main;
1091  i32 retval = ntohl (mp->retval);
1092
1093  vam->retval = retval;
1094  vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1095  vam->result_ready = 1;
1096}
1097
1098static void
1099vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1100{
1101  vat_main_t *vam = &vat_main;
1102  vat_json_node_t node;
1103  void *oldheap;
1104  u8 *reply;
1105
1106  vat_json_init_object (&node);
1107  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1108  vat_json_object_add_uint (&node, "reply_in_shmem",
1109			    ntohl (mp->reply_in_shmem));
1110  /* Toss the shared-memory original... */
1111  oldheap = vl_msg_push_heap ();
1112
1113  reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1114  vec_free (reply);
1115
1116  vl_msg_pop_heap (oldheap);
1117
1118  vat_json_print (vam->ofp, &node);
1119  vat_json_free (&node);
1120
1121  vam->retval = ntohl (mp->retval);
1122  vam->result_ready = 1;
1123}
1124
1125static void
1126vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1127{
1128  vat_main_t *vam = &vat_main;
1129  i32 retval = ntohl (mp->retval);
1130  u32 length = vl_api_string_len (&mp->reply);
1131
1132  vec_reset_length (vam->cmd_reply);
1133
1134  vam->retval = retval;
1135  if (retval == 0)
1136    {
1137      vec_validate (vam->cmd_reply, length);
1138      clib_memcpy ((char *) (vam->cmd_reply),
1139		   vl_api_from_api_string (&mp->reply), length);
1140      vam->cmd_reply[length] = 0;
1141    }
1142  vam->result_ready = 1;
1143}
1144
1145static void
1146vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1147{
1148  vat_main_t *vam = &vat_main;
1149  vat_json_node_t node;
1150
1151  vec_reset_length (vam->cmd_reply);
1152
1153  vat_json_init_object (&node);
1154  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1155  vat_json_object_add_string_copy (&node, "reply",
1156				   vl_api_from_api_string (&mp->reply));
1157
1158  vat_json_print (vam->ofp, &node);
1159  vat_json_free (&node);
1160
1161  vam->retval = ntohl (mp->retval);
1162  vam->result_ready = 1;
1163}
1164
1165static void vl_api_classify_add_del_table_reply_t_handler
1166  (vl_api_classify_add_del_table_reply_t * mp)
1167{
1168  vat_main_t *vam = &vat_main;
1169  i32 retval = ntohl (mp->retval);
1170  if (vam->async_mode)
1171    {
1172      vam->async_errors += (retval < 0);
1173    }
1174  else
1175    {
1176      vam->retval = retval;
1177      if (retval == 0 &&
1178	  ((mp->new_table_index != 0xFFFFFFFF) ||
1179	   (mp->skip_n_vectors != 0xFFFFFFFF) ||
1180	   (mp->match_n_vectors != 0xFFFFFFFF)))
1181	/*
1182	 * Note: this is just barely thread-safe, depends on
1183	 * the main thread spinning waiting for an answer...
1184	 */
1185	errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1186		ntohl (mp->new_table_index),
1187		ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1188      vam->result_ready = 1;
1189    }
1190}
1191
1192static void vl_api_classify_add_del_table_reply_t_handler_json
1193  (vl_api_classify_add_del_table_reply_t * mp)
1194{
1195  vat_main_t *vam = &vat_main;
1196  vat_json_node_t node;
1197
1198  vat_json_init_object (&node);
1199  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1200  vat_json_object_add_uint (&node, "new_table_index",
1201			    ntohl (mp->new_table_index));
1202  vat_json_object_add_uint (&node, "skip_n_vectors",
1203			    ntohl (mp->skip_n_vectors));
1204  vat_json_object_add_uint (&node, "match_n_vectors",
1205			    ntohl (mp->match_n_vectors));
1206
1207  vat_json_print (vam->ofp, &node);
1208  vat_json_free (&node);
1209
1210  vam->retval = ntohl (mp->retval);
1211  vam->result_ready = 1;
1212}
1213
1214static void vl_api_get_node_index_reply_t_handler
1215  (vl_api_get_node_index_reply_t * mp)
1216{
1217  vat_main_t *vam = &vat_main;
1218  i32 retval = ntohl (mp->retval);
1219  if (vam->async_mode)
1220    {
1221      vam->async_errors += (retval < 0);
1222    }
1223  else
1224    {
1225      vam->retval = retval;
1226      if (retval == 0)
1227	errmsg ("node index %d", ntohl (mp->node_index));
1228      vam->result_ready = 1;
1229    }
1230}
1231
1232static void vl_api_get_node_index_reply_t_handler_json
1233  (vl_api_get_node_index_reply_t * mp)
1234{
1235  vat_main_t *vam = &vat_main;
1236  vat_json_node_t node;
1237
1238  vat_json_init_object (&node);
1239  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1240  vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1241
1242  vat_json_print (vam->ofp, &node);
1243  vat_json_free (&node);
1244
1245  vam->retval = ntohl (mp->retval);
1246  vam->result_ready = 1;
1247}
1248
1249static void vl_api_get_next_index_reply_t_handler
1250  (vl_api_get_next_index_reply_t * mp)
1251{
1252  vat_main_t *vam = &vat_main;
1253  i32 retval = ntohl (mp->retval);
1254  if (vam->async_mode)
1255    {
1256      vam->async_errors += (retval < 0);
1257    }
1258  else
1259    {
1260      vam->retval = retval;
1261      if (retval == 0)
1262	errmsg ("next node index %d", ntohl (mp->next_index));
1263      vam->result_ready = 1;
1264    }
1265}
1266
1267static void vl_api_get_next_index_reply_t_handler_json
1268  (vl_api_get_next_index_reply_t * mp)
1269{
1270  vat_main_t *vam = &vat_main;
1271  vat_json_node_t node;
1272
1273  vat_json_init_object (&node);
1274  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1275  vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1276
1277  vat_json_print (vam->ofp, &node);
1278  vat_json_free (&node);
1279
1280  vam->retval = ntohl (mp->retval);
1281  vam->result_ready = 1;
1282}
1283
1284static void vl_api_add_node_next_reply_t_handler
1285  (vl_api_add_node_next_reply_t * mp)
1286{
1287  vat_main_t *vam = &vat_main;
1288  i32 retval = ntohl (mp->retval);
1289  if (vam->async_mode)
1290    {
1291      vam->async_errors += (retval < 0);
1292    }
1293  else
1294    {
1295      vam->retval = retval;
1296      if (retval == 0)
1297	errmsg ("next index %d", ntohl (mp->next_index));
1298      vam->result_ready = 1;
1299    }
1300}
1301
1302static void vl_api_add_node_next_reply_t_handler_json
1303  (vl_api_add_node_next_reply_t * mp)
1304{
1305  vat_main_t *vam = &vat_main;
1306  vat_json_node_t node;
1307
1308  vat_json_init_object (&node);
1309  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1310  vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1311
1312  vat_json_print (vam->ofp, &node);
1313  vat_json_free (&node);
1314
1315  vam->retval = ntohl (mp->retval);
1316  vam->result_ready = 1;
1317}
1318
1319static void vl_api_show_version_reply_t_handler
1320  (vl_api_show_version_reply_t * mp)
1321{
1322  vat_main_t *vam = &vat_main;
1323  i32 retval = ntohl (mp->retval);
1324
1325  if (retval >= 0)
1326    {
1327      errmsg ("        program: %s", mp->program);
1328      errmsg ("        version: %s", mp->version);
1329      errmsg ("     build date: %s", mp->build_date);
1330      errmsg ("build directory: %s", mp->build_directory);
1331    }
1332  vam->retval = retval;
1333  vam->result_ready = 1;
1334}
1335
1336static void vl_api_show_version_reply_t_handler_json
1337  (vl_api_show_version_reply_t * mp)
1338{
1339  vat_main_t *vam = &vat_main;
1340  vat_json_node_t node;
1341
1342  vat_json_init_object (&node);
1343  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1344  vat_json_object_add_string_copy (&node, "program", mp->program);
1345  vat_json_object_add_string_copy (&node, "version", mp->version);
1346  vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1347  vat_json_object_add_string_copy (&node, "build_directory",
1348				   mp->build_directory);
1349
1350  vat_json_print (vam->ofp, &node);
1351  vat_json_free (&node);
1352
1353  vam->retval = ntohl (mp->retval);
1354  vam->result_ready = 1;
1355}
1356
1357static void vl_api_show_threads_reply_t_handler
1358  (vl_api_show_threads_reply_t * mp)
1359{
1360  vat_main_t *vam = &vat_main;
1361  i32 retval = ntohl (mp->retval);
1362  int i, count = 0;
1363
1364  if (retval >= 0)
1365    count = ntohl (mp->count);
1366
1367  for (i = 0; i < count; i++)
1368    print (vam->ofp,
1369	   "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1370	   ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1371	   mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1372	   ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1373	   ntohl (mp->thread_data[i].cpu_socket));
1374
1375  vam->retval = retval;
1376  vam->result_ready = 1;
1377}
1378
1379static void vl_api_show_threads_reply_t_handler_json
1380  (vl_api_show_threads_reply_t * mp)
1381{
1382  vat_main_t *vam = &vat_main;
1383  vat_json_node_t node;
1384  vl_api_thread_data_t *td;
1385  i32 retval = ntohl (mp->retval);
1386  int i, count = 0;
1387
1388  if (retval >= 0)
1389    count = ntohl (mp->count);
1390
1391  vat_json_init_object (&node);
1392  vat_json_object_add_int (&node, "retval", retval);
1393  vat_json_object_add_uint (&node, "count", count);
1394
1395  for (i = 0; i < count; i++)
1396    {
1397      td = &mp->thread_data[i];
1398      vat_json_object_add_uint (&node, "id", ntohl (td->id));
1399      vat_json_object_add_string_copy (&node, "name", td->name);
1400      vat_json_object_add_string_copy (&node, "type", td->type);
1401      vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1402      vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1403      vat_json_object_add_int (&node, "core", ntohl (td->id));
1404      vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1405    }
1406
1407  vat_json_print (vam->ofp, &node);
1408  vat_json_free (&node);
1409
1410  vam->retval = retval;
1411  vam->result_ready = 1;
1412}
1413
1414static int
1415api_show_threads (vat_main_t * vam)
1416{
1417  vl_api_show_threads_t *mp;
1418  int ret;
1419
1420  print (vam->ofp,
1421	 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1422	 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1423
1424  M (SHOW_THREADS, mp);
1425
1426  S (mp);
1427  W (ret);
1428  return ret;
1429}
1430
1431static void
1432vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1433{
1434  u32 n_macs = ntohl (mp->n_macs);
1435  errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1436	  ntohl (mp->pid), mp->client_index, n_macs);
1437  int i;
1438  for (i = 0; i < n_macs; i++)
1439    {
1440      vl_api_mac_entry_t *mac = &mp->mac[i];
1441      errmsg (" [%d] sw_if_index %d  mac_addr %U  action %d \n",
1442	      i + 1, ntohl (mac->sw_if_index),
1443	      format_ethernet_address, mac->mac_addr, mac->action);
1444      if (i == 1000)
1445	break;
1446    }
1447}
1448
1449static void
1450vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1451{
1452  /* JSON output not supported */
1453}
1454
1455#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1456#define vl_api_bridge_domain_details_t_print vl_noop_handler
1457
1458/*
1459 * Special-case: build the bridge domain table, maintain
1460 * the next bd id vbl.
1461 */
1462static void vl_api_bridge_domain_details_t_handler
1463  (vl_api_bridge_domain_details_t * mp)
1464{
1465  vat_main_t *vam = &vat_main;
1466  u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1467  int i;
1468
1469  print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1470	 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1471
1472  print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1473	 ntohl (mp->bd_id), mp->learn, mp->forward,
1474	 mp->flood, ntohl (mp->bvi_sw_if_index),
1475	 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1476
1477  if (n_sw_ifs)
1478    {
1479      vl_api_bridge_domain_sw_if_t *sw_ifs;
1480      print (vam->ofp, "\n\n%s %s  %s", "sw_if_index", "SHG",
1481	     "Interface Name");
1482
1483      sw_ifs = mp->sw_if_details;
1484      for (i = 0; i < n_sw_ifs; i++)
1485	{
1486	  u8 *sw_if_name = 0;
1487	  u32 sw_if_index;
1488	  hash_pair_t *p;
1489
1490	  sw_if_index = ntohl (sw_ifs->sw_if_index);
1491
1492	  /* *INDENT-OFF* */
1493	  hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1494			     ({
1495			       if ((u32) p->value[0] == sw_if_index)
1496				 {
1497				   sw_if_name = (u8 *)(p->key);
1498				   break;
1499				 }
1500			     }));
1501	  /* *INDENT-ON* */
1502	  print (vam->ofp, "%7d     %3d  %s", sw_if_index,
1503		 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1504		 "sw_if_index not found!");
1505
1506	  sw_ifs++;
1507	}
1508    }
1509}
1510
1511static void vl_api_bridge_domain_details_t_handler_json
1512  (vl_api_bridge_domain_details_t * mp)
1513{
1514  vat_main_t *vam = &vat_main;
1515  vat_json_node_t *node, *array = NULL;
1516  u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1517
1518  if (VAT_JSON_ARRAY != vam->json_tree.type)
1519    {
1520      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1521      vat_json_init_array (&vam->json_tree);
1522    }
1523  node = vat_json_array_add (&vam->json_tree);
1524
1525  vat_json_init_object (node);
1526  vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1527  vat_json_object_add_uint (node, "flood", mp->flood);
1528  vat_json_object_add_uint (node, "forward", mp->forward);
1529  vat_json_object_add_uint (node, "learn", mp->learn);
1530  vat_json_object_add_uint (node, "bvi_sw_if_index",
1531			    ntohl (mp->bvi_sw_if_index));
1532  vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1533  array = vat_json_object_add (node, "sw_if");
1534  vat_json_init_array (array);
1535
1536
1537
1538  if (n_sw_ifs)
1539    {
1540      vl_api_bridge_domain_sw_if_t *sw_ifs;
1541      int i;
1542
1543      sw_ifs = mp->sw_if_details;
1544      for (i = 0; i < n_sw_ifs; i++)
1545	{
1546	  node = vat_json_array_add (array);
1547	  vat_json_init_object (node);
1548	  vat_json_object_add_uint (node, "sw_if_index",
1549				    ntohl (sw_ifs->sw_if_index));
1550	  vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1551	  sw_ifs++;
1552	}
1553    }
1554}
1555
1556static void vl_api_control_ping_reply_t_handler
1557  (vl_api_control_ping_reply_t * mp)
1558{
1559  vat_main_t *vam = &vat_main;
1560  i32 retval = ntohl (mp->retval);
1561  if (vam->async_mode)
1562    {
1563      vam->async_errors += (retval < 0);
1564    }
1565  else
1566    {
1567      vam->retval = retval;
1568      vam->result_ready = 1;
1569    }
1570  if (vam->socket_client_main)
1571    vam->socket_client_main->control_pings_outstanding--;
1572}
1573
1574static void vl_api_control_ping_reply_t_handler_json
1575  (vl_api_control_ping_reply_t * mp)
1576{
1577  vat_main_t *vam = &vat_main;
1578  i32 retval = ntohl (mp->retval);
1579
1580  if (VAT_JSON_NONE != vam->json_tree.type)
1581    {
1582      vat_json_print (vam->ofp, &vam->json_tree);
1583      vat_json_free (&vam->json_tree);
1584      vam->json_tree.type = VAT_JSON_NONE;
1585    }
1586  else
1587    {
1588      /* just print [] */
1589      vat_json_init_array (&vam->json_tree);
1590      vat_json_print (vam->ofp, &vam->json_tree);
1591      vam->json_tree.type = VAT_JSON_NONE;
1592    }
1593
1594  vam->retval = retval;
1595  vam->result_ready = 1;
1596}
1597
1598static void
1599  vl_api_bridge_domain_set_mac_age_reply_t_handler
1600  (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1601{
1602  vat_main_t *vam = &vat_main;
1603  i32 retval = ntohl (mp->retval);
1604  if (vam->async_mode)
1605    {
1606      vam->async_errors += (retval < 0);
1607    }
1608  else
1609    {
1610      vam->retval = retval;
1611      vam->result_ready = 1;
1612    }
1613}
1614
1615static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1616  (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1617{
1618  vat_main_t *vam = &vat_main;
1619  vat_json_node_t node;
1620
1621  vat_json_init_object (&node);
1622  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1623
1624  vat_json_print (vam->ofp, &node);
1625  vat_json_free (&node);
1626
1627  vam->retval = ntohl (mp->retval);
1628  vam->result_ready = 1;
1629}
1630
1631static void
1632vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1633{
1634  vat_main_t *vam = &vat_main;
1635  i32 retval = ntohl (mp->retval);
1636  if (vam->async_mode)
1637    {
1638      vam->async_errors += (retval < 0);
1639    }
1640  else
1641    {
1642      vam->retval = retval;
1643      vam->result_ready = 1;
1644    }
1645}
1646
1647static void vl_api_l2_flags_reply_t_handler_json
1648  (vl_api_l2_flags_reply_t * mp)
1649{
1650  vat_main_t *vam = &vat_main;
1651  vat_json_node_t node;
1652
1653  vat_json_init_object (&node);
1654  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1655  vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1656			    ntohl (mp->resulting_feature_bitmap));
1657
1658  vat_json_print (vam->ofp, &node);
1659  vat_json_free (&node);
1660
1661  vam->retval = ntohl (mp->retval);
1662  vam->result_ready = 1;
1663}
1664
1665static void vl_api_bridge_flags_reply_t_handler
1666  (vl_api_bridge_flags_reply_t * mp)
1667{
1668  vat_main_t *vam = &vat_main;
1669  i32 retval = ntohl (mp->retval);
1670  if (vam->async_mode)
1671    {
1672      vam->async_errors += (retval < 0);
1673    }
1674  else
1675    {
1676      vam->retval = retval;
1677      vam->result_ready = 1;
1678    }
1679}
1680
1681static void vl_api_bridge_flags_reply_t_handler_json
1682  (vl_api_bridge_flags_reply_t * mp)
1683{
1684  vat_main_t *vam = &vat_main;
1685  vat_json_node_t node;
1686
1687  vat_json_init_object (&node);
1688  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1689  vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1690			    ntohl (mp->resulting_feature_bitmap));
1691
1692  vat_json_print (vam->ofp, &node);
1693  vat_json_free (&node);
1694
1695  vam->retval = ntohl (mp->retval);
1696  vam->result_ready = 1;
1697}
1698
1699static void
1700vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1701{
1702  vat_main_t *vam = &vat_main;
1703  i32 retval = ntohl (mp->retval);
1704  if (vam->async_mode)
1705    {
1706      vam->async_errors += (retval < 0);
1707    }
1708  else
1709    {
1710      vam->retval = retval;
1711      vam->sw_if_index = ntohl (mp->sw_if_index);
1712      vam->result_ready = 1;
1713    }
1714
1715}
1716
1717static void vl_api_tap_create_v2_reply_t_handler_json
1718  (vl_api_tap_create_v2_reply_t * mp)
1719{
1720  vat_main_t *vam = &vat_main;
1721  vat_json_node_t node;
1722
1723  vat_json_init_object (&node);
1724  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1725  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1726
1727  vat_json_print (vam->ofp, &node);
1728  vat_json_free (&node);
1729
1730  vam->retval = ntohl (mp->retval);
1731  vam->result_ready = 1;
1732
1733}
1734
1735static void
1736vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1737{
1738  vat_main_t *vam = &vat_main;
1739  i32 retval = ntohl (mp->retval);
1740  if (vam->async_mode)
1741    {
1742      vam->async_errors += (retval < 0);
1743    }
1744  else
1745    {
1746      vam->retval = retval;
1747      vam->result_ready = 1;
1748    }
1749}
1750
1751static void vl_api_tap_delete_v2_reply_t_handler_json
1752  (vl_api_tap_delete_v2_reply_t * mp)
1753{
1754  vat_main_t *vam = &vat_main;
1755  vat_json_node_t node;
1756
1757  vat_json_init_object (&node);
1758  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1759
1760  vat_json_print (vam->ofp, &node);
1761  vat_json_free (&node);
1762
1763  vam->retval = ntohl (mp->retval);
1764  vam->result_ready = 1;
1765}
1766
1767static void
1768vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1769					  mp)
1770{
1771  vat_main_t *vam = &vat_main;
1772  i32 retval = ntohl (mp->retval);
1773  if (vam->async_mode)
1774    {
1775      vam->async_errors += (retval < 0);
1776    }
1777  else
1778    {
1779      vam->retval = retval;
1780      vam->sw_if_index = ntohl (mp->sw_if_index);
1781      vam->result_ready = 1;
1782    }
1783}
1784
1785static void vl_api_virtio_pci_create_reply_t_handler_json
1786  (vl_api_virtio_pci_create_reply_t * mp)
1787{
1788  vat_main_t *vam = &vat_main;
1789  vat_json_node_t node;
1790
1791  vat_json_init_object (&node);
1792  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1793  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1794
1795  vat_json_print (vam->ofp, &node);
1796  vat_json_free (&node);
1797
1798  vam->retval = ntohl (mp->retval);
1799  vam->result_ready = 1;
1800
1801}
1802
1803static void
1804vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1805					  mp)
1806{
1807  vat_main_t *vam = &vat_main;
1808  i32 retval = ntohl (mp->retval);
1809  if (vam->async_mode)
1810    {
1811      vam->async_errors += (retval < 0);
1812    }
1813  else
1814    {
1815      vam->retval = retval;
1816      vam->result_ready = 1;
1817    }
1818}
1819
1820static void vl_api_virtio_pci_delete_reply_t_handler_json
1821  (vl_api_virtio_pci_delete_reply_t * mp)
1822{
1823  vat_main_t *vam = &vat_main;
1824  vat_json_node_t node;
1825
1826  vat_json_init_object (&node);
1827  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1828
1829  vat_json_print (vam->ofp, &node);
1830  vat_json_free (&node);
1831
1832  vam->retval = ntohl (mp->retval);
1833  vam->result_ready = 1;
1834}
1835
1836static void
1837vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1838{
1839  vat_main_t *vam = &vat_main;
1840  i32 retval = ntohl (mp->retval);
1841
1842  if (vam->async_mode)
1843    {
1844      vam->async_errors += (retval < 0);
1845    }
1846  else
1847    {
1848      vam->retval = retval;
1849      vam->sw_if_index = ntohl (mp->sw_if_index);
1850      vam->result_ready = 1;
1851    }
1852}
1853
1854static void vl_api_bond_create_reply_t_handler_json
1855  (vl_api_bond_create_reply_t * mp)
1856{
1857  vat_main_t *vam = &vat_main;
1858  vat_json_node_t node;
1859
1860  vat_json_init_object (&node);
1861  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1862  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1863
1864  vat_json_print (vam->ofp, &node);
1865  vat_json_free (&node);
1866
1867  vam->retval = ntohl (mp->retval);
1868  vam->result_ready = 1;
1869}
1870
1871static void
1872vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1873{
1874  vat_main_t *vam = &vat_main;
1875  i32 retval = ntohl (mp->retval);
1876
1877  if (vam->async_mode)
1878    {
1879      vam->async_errors += (retval < 0);
1880    }
1881  else
1882    {
1883      vam->retval = retval;
1884      vam->result_ready = 1;
1885    }
1886}
1887
1888static void vl_api_bond_delete_reply_t_handler_json
1889  (vl_api_bond_delete_reply_t * mp)
1890{
1891  vat_main_t *vam = &vat_main;
1892  vat_json_node_t node;
1893
1894  vat_json_init_object (&node);
1895  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1896
1897  vat_json_print (vam->ofp, &node);
1898  vat_json_free (&node);
1899
1900  vam->retval = ntohl (mp->retval);
1901  vam->result_ready = 1;
1902}
1903
1904static void
1905vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
1906{
1907  vat_main_t *vam = &vat_main;
1908  i32 retval = ntohl (mp->retval);
1909
1910  if (vam->async_mode)
1911    {
1912      vam->async_errors += (retval < 0);
1913    }
1914  else
1915    {
1916      vam->retval = retval;
1917      vam->result_ready = 1;
1918    }
1919}
1920
1921static void vl_api_bond_enslave_reply_t_handler_json
1922  (vl_api_bond_enslave_reply_t * mp)
1923{
1924  vat_main_t *vam = &vat_main;
1925  vat_json_node_t node;
1926
1927  vat_json_init_object (&node);
1928  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1929
1930  vat_json_print (vam->ofp, &node);
1931  vat_json_free (&node);
1932
1933  vam->retval = ntohl (mp->retval);
1934  vam->result_ready = 1;
1935}
1936
1937static void
1938vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
1939					  mp)
1940{
1941  vat_main_t *vam = &vat_main;
1942  i32 retval = ntohl (mp->retval);
1943
1944  if (vam->async_mode)
1945    {
1946      vam->async_errors += (retval < 0);
1947    }
1948  else
1949    {
1950      vam->retval = retval;
1951      vam->result_ready = 1;
1952    }
1953}
1954
1955static void vl_api_bond_detach_slave_reply_t_handler_json
1956  (vl_api_bond_detach_slave_reply_t * mp)
1957{
1958  vat_main_t *vam = &vat_main;
1959  vat_json_node_t node;
1960
1961  vat_json_init_object (&node);
1962  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1963
1964  vat_json_print (vam->ofp, &node);
1965  vat_json_free (&node);
1966
1967  vam->retval = ntohl (mp->retval);
1968  vam->result_ready = 1;
1969}
1970
1971static int
1972api_sw_interface_set_bond_weight (vat_main_t * vam)
1973{
1974  unformat_input_t *i = vam->input;
1975  vl_api_sw_interface_set_bond_weight_t *mp;
1976  u32 sw_if_index = ~0;
1977  u32 weight = 0;
1978  u8 weight_enter = 0;
1979  int ret;
1980
1981  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1982    {
1983      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1984	;
1985      else if (unformat (i, "sw_if_index %d", &sw_if_index))
1986	;
1987      else if (unformat (i, "weight %u", &weight))
1988	weight_enter = 1;
1989      else
1990	break;
1991    }
1992
1993  if (sw_if_index == ~0)
1994    {
1995      errmsg ("missing interface name or sw_if_index");
1996      return -99;
1997    }
1998  if (weight_enter == 0)
1999    {
2000      errmsg ("missing valid weight");
2001      return -99;
2002    }
2003
2004  /* Construct the API message */
2005  M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2006  mp->sw_if_index = ntohl (sw_if_index);
2007  mp->weight = ntohl (weight);
2008
2009  S (mp);
2010  W (ret);
2011  return ret;
2012}
2013
2014static void vl_api_sw_interface_bond_details_t_handler
2015  (vl_api_sw_interface_bond_details_t * mp)
2016{
2017  vat_main_t *vam = &vat_main;
2018
2019  print (vam->ofp,
2020	 "%-16s %-12d %-12U %-13U %-14u %-14u",
2021	 mp->interface_name, ntohl (mp->sw_if_index),
2022	 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2023	 ntohl (mp->lb), ntohl (mp->active_slaves), ntohl (mp->slaves));
2024}
2025
2026static void vl_api_sw_interface_bond_details_t_handler_json
2027  (vl_api_sw_interface_bond_details_t * mp)
2028{
2029  vat_main_t *vam = &vat_main;
2030  vat_json_node_t *node = NULL;
2031
2032  if (VAT_JSON_ARRAY != vam->json_tree.type)
2033    {
2034      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2035      vat_json_init_array (&vam->json_tree);
2036    }
2037  node = vat_json_array_add (&vam->json_tree);
2038
2039  vat_json_init_object (node);
2040  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2041  vat_json_object_add_string_copy (node, "interface_name",
2042				   mp->interface_name);
2043  vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2044  vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2045  vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
2046  vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
2047}
2048
2049static int
2050api_sw_interface_bond_dump (vat_main_t * vam)
2051{
2052  vl_api_sw_interface_bond_dump_t *mp;
2053  vl_api_control_ping_t *mp_ping;
2054  int ret;
2055
2056  print (vam->ofp,
2057	 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2058	 "interface name", "sw_if_index", "mode", "load balance",
2059	 "active slaves", "slaves");
2060
2061  /* Get list of bond interfaces */
2062  M (SW_INTERFACE_BOND_DUMP, mp);
2063  S (mp);
2064
2065  /* Use a control ping for synchronization */
2066  MPING (CONTROL_PING, mp_ping);
2067  S (mp_ping);
2068
2069  W (ret);
2070  return ret;
2071}
2072
2073static void vl_api_sw_interface_slave_details_t_handler
2074  (vl_api_sw_interface_slave_details_t * mp)
2075{
2076  vat_main_t *vam = &vat_main;
2077
2078  print (vam->ofp,
2079	 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2080	 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2081	 ntohl (mp->weight), mp->is_local_numa);
2082}
2083
2084static void vl_api_sw_interface_slave_details_t_handler_json
2085  (vl_api_sw_interface_slave_details_t * mp)
2086{
2087  vat_main_t *vam = &vat_main;
2088  vat_json_node_t *node = NULL;
2089
2090  if (VAT_JSON_ARRAY != vam->json_tree.type)
2091    {
2092      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2093      vat_json_init_array (&vam->json_tree);
2094    }
2095  node = vat_json_array_add (&vam->json_tree);
2096
2097  vat_json_init_object (node);
2098  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2099  vat_json_object_add_string_copy (node, "interface_name",
2100				   mp->interface_name);
2101  vat_json_object_add_uint (node, "passive", mp->is_passive);
2102  vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2103  vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2104  vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2105}
2106
2107static int
2108api_sw_interface_slave_dump (vat_main_t * vam)
2109{
2110  unformat_input_t *i = vam->input;
2111  vl_api_sw_interface_slave_dump_t *mp;
2112  vl_api_control_ping_t *mp_ping;
2113  u32 sw_if_index = ~0;
2114  u8 sw_if_index_set = 0;
2115  int ret;
2116
2117  /* Parse args required to build the message */
2118  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2119    {
2120      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2121	sw_if_index_set = 1;
2122      else if (unformat (i, "sw_if_index %d", &sw_if_index))
2123	sw_if_index_set = 1;
2124      else
2125	break;
2126    }
2127
2128  if (sw_if_index_set == 0)
2129    {
2130      errmsg ("missing vpp interface name. ");
2131      return -99;
2132    }
2133
2134  print (vam->ofp,
2135	 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2136	 "slave interface name", "sw_if_index", "passive", "long_timeout",
2137	 "weight", "local numa");
2138
2139  /* Get list of bond interfaces */
2140  M (SW_INTERFACE_SLAVE_DUMP, mp);
2141  mp->sw_if_index = ntohl (sw_if_index);
2142  S (mp);
2143
2144  /* Use a control ping for synchronization */
2145  MPING (CONTROL_PING, mp_ping);
2146  S (mp_ping);
2147
2148  W (ret);
2149  return ret;
2150}
2151
2152static void vl_api_mpls_tunnel_add_del_reply_t_handler
2153  (vl_api_mpls_tunnel_add_del_reply_t * mp)
2154{
2155  vat_main_t *vam = &vat_main;
2156  i32 retval = ntohl (mp->retval);
2157  if (vam->async_mode)
2158    {
2159      vam->async_errors += (retval < 0);
2160    }
2161  else
2162    {
2163      vam->retval = retval;
2164      vam->sw_if_index = ntohl (mp->sw_if_index);
2165      vam->result_ready = 1;
2166    }
2167  vam->regenerate_interface_table = 1;
2168}
2169
2170static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2171  (vl_api_mpls_tunnel_add_del_reply_t * mp)
2172{
2173  vat_main_t *vam = &vat_main;
2174  vat_json_node_t node;
2175
2176  vat_json_init_object (&node);
2177  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2178  vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2179			    ntohl (mp->sw_if_index));
2180
2181  vat_json_print (vam->ofp, &node);
2182  vat_json_free (&node);
2183
2184  vam->retval = ntohl (mp->retval);
2185  vam->result_ready = 1;
2186}
2187
2188static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2189  (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2190{
2191  vat_main_t *vam = &vat_main;
2192  i32 retval = ntohl (mp->retval);
2193  if (vam->async_mode)
2194    {
2195      vam->async_errors += (retval < 0);
2196    }
2197  else
2198    {
2199      vam->retval = retval;
2200      vam->sw_if_index = ntohl (mp->sw_if_index);
2201      vam->result_ready = 1;
2202    }
2203}
2204
2205static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2206  (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2207{
2208  vat_main_t *vam = &vat_main;
2209  vat_json_node_t node;
2210
2211  vat_json_init_object (&node);
2212  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2213  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2214
2215  vat_json_print (vam->ofp, &node);
2216  vat_json_free (&node);
2217
2218  vam->retval = ntohl (mp->retval);
2219  vam->result_ready = 1;
2220}
2221
2222static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2223  (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2224{
2225  vat_main_t *vam = &vat_main;
2226  i32 retval = ntohl (mp->retval);
2227  if (vam->async_mode)
2228    {
2229      vam->async_errors += (retval < 0);
2230    }
2231  else
2232    {
2233      vam->retval = retval;
2234      vam->result_ready = 1;
2235    }
2236}
2237
2238static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2239  (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2240{
2241  vat_main_t *vam = &vat_main;
2242  vat_json_node_t node;
2243
2244  vat_json_init_object (&node);
2245  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2246  vat_json_object_add_uint (&node, "fwd_entry_index",
2247			    clib_net_to_host_u32 (mp->fwd_entry_index));
2248
2249  vat_json_print (vam->ofp, &node);
2250  vat_json_free (&node);
2251
2252  vam->retval = ntohl (mp->retval);
2253  vam->result_ready = 1;
2254}
2255
2256u8 *
2257format_lisp_transport_protocol (u8 * s, va_list * args)
2258{
2259  u32 proto = va_arg (*args, u32);
2260
2261  switch (proto)
2262    {
2263    case 1:
2264      return format (s, "udp");
2265    case 2:
2266      return format (s, "api");
2267    default:
2268      return 0;
2269    }
2270  return 0;
2271}
2272
2273static void vl_api_one_get_transport_protocol_reply_t_handler
2274  (vl_api_one_get_transport_protocol_reply_t * mp)
2275{
2276  vat_main_t *vam = &vat_main;
2277  i32 retval = ntohl (mp->retval);
2278  if (vam->async_mode)
2279    {
2280      vam->async_errors += (retval < 0);
2281    }
2282  else
2283    {
2284      u32 proto = mp->protocol;
2285      print (vam->ofp, "Transport protocol: %U",
2286	     format_lisp_transport_protocol, proto);
2287      vam->retval = retval;
2288      vam->result_ready = 1;
2289    }
2290}
2291
2292static void vl_api_one_get_transport_protocol_reply_t_handler_json
2293  (vl_api_one_get_transport_protocol_reply_t * mp)
2294{
2295  vat_main_t *vam = &vat_main;
2296  vat_json_node_t node;
2297  u8 *s;
2298
2299  s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2300  vec_add1 (s, 0);
2301
2302  vat_json_init_object (&node);
2303  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2304  vat_json_object_add_string_copy (&node, "transport-protocol", s);
2305
2306  vec_free (s);
2307  vat_json_print (vam->ofp, &node);
2308  vat_json_free (&node);
2309
2310  vam->retval = ntohl (mp->retval);
2311  vam->result_ready = 1;
2312}
2313
2314static void vl_api_one_add_del_locator_set_reply_t_handler
2315  (vl_api_one_add_del_locator_set_reply_t * mp)
2316{
2317  vat_main_t *vam = &vat_main;
2318  i32 retval = ntohl (mp->retval);
2319  if (vam->async_mode)
2320    {
2321      vam->async_errors += (retval < 0);
2322    }
2323  else
2324    {
2325      vam->retval = retval;
2326      vam->result_ready = 1;
2327    }
2328}
2329
2330static void vl_api_one_add_del_locator_set_reply_t_handler_json
2331  (vl_api_one_add_del_locator_set_reply_t * mp)
2332{
2333  vat_main_t *vam = &vat_main;
2334  vat_json_node_t node;
2335
2336  vat_json_init_object (&node);
2337  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2338  vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2339
2340  vat_json_print (vam->ofp, &node);
2341  vat_json_free (&node);
2342
2343  vam->retval = ntohl (mp->retval);
2344  vam->result_ready = 1;
2345}
2346
2347static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2348  (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2349{
2350  vat_main_t *vam = &vat_main;
2351  i32 retval = ntohl (mp->retval);
2352  if (vam->async_mode)
2353    {
2354      vam->async_errors += (retval < 0);
2355    }
2356  else
2357    {
2358      vam->retval = retval;
2359      vam->sw_if_index = ntohl (mp->sw_if_index);
2360      vam->result_ready = 1;
2361    }
2362  vam->regenerate_interface_table = 1;
2363}
2364
2365static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2366  (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2367{
2368  vat_main_t *vam = &vat_main;
2369  vat_json_node_t node;
2370
2371  vat_json_init_object (&node);
2372  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2373  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2374
2375  vat_json_print (vam->ofp, &node);
2376  vat_json_free (&node);
2377
2378  vam->retval = ntohl (mp->retval);
2379  vam->result_ready = 1;
2380}
2381
2382static void vl_api_vxlan_offload_rx_reply_t_handler
2383  (vl_api_vxlan_offload_rx_reply_t * mp)
2384{
2385  vat_main_t *vam = &vat_main;
2386  i32 retval = ntohl (mp->retval);
2387  if (vam->async_mode)
2388    {
2389      vam->async_errors += (retval < 0);
2390    }
2391  else
2392    {
2393      vam->retval = retval;
2394      vam->result_ready = 1;
2395    }
2396}
2397
2398static void vl_api_vxlan_offload_rx_reply_t_handler_json
2399  (vl_api_vxlan_offload_rx_reply_t * mp)
2400{
2401  vat_main_t *vam = &vat_main;
2402  vat_json_node_t node;
2403
2404  vat_json_init_object (&node);
2405  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2406
2407  vat_json_print (vam->ofp, &node);
2408  vat_json_free (&node);
2409
2410  vam->retval = ntohl (mp->retval);
2411  vam->result_ready = 1;
2412}
2413
2414static void vl_api_geneve_add_del_tunnel_reply_t_handler
2415  (vl_api_geneve_add_del_tunnel_reply_t * mp)
2416{
2417  vat_main_t *vam = &vat_main;
2418  i32 retval = ntohl (mp->retval);
2419  if (vam->async_mode)
2420    {
2421      vam->async_errors += (retval < 0);
2422    }
2423  else
2424    {
2425      vam->retval = retval;
2426      vam->sw_if_index = ntohl (mp->sw_if_index);
2427      vam->result_ready = 1;
2428    }
2429}
2430
2431static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2432  (vl_api_geneve_add_del_tunnel_reply_t * mp)
2433{
2434  vat_main_t *vam = &vat_main;
2435  vat_json_node_t node;
2436
2437  vat_json_init_object (&node);
2438  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2439  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2440
2441  vat_json_print (vam->ofp, &node);
2442  vat_json_free (&node);
2443
2444  vam->retval = ntohl (mp->retval);
2445  vam->result_ready = 1;
2446}
2447
2448static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2449  (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2450{
2451  vat_main_t *vam = &vat_main;
2452  i32 retval = ntohl (mp->retval);
2453  if (vam->async_mode)
2454    {
2455      vam->async_errors += (retval < 0);
2456    }
2457  else
2458    {
2459      vam->retval = retval;
2460      vam->sw_if_index = ntohl (mp->sw_if_index);
2461      vam->result_ready = 1;
2462    }
2463  vam->regenerate_interface_table = 1;
2464}
2465
2466static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2467  (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2468{
2469  vat_main_t *vam = &vat_main;
2470  vat_json_node_t node;
2471
2472  vat_json_init_object (&node);
2473  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2474  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2475
2476  vat_json_print (vam->ofp, &node);
2477  vat_json_free (&node);
2478
2479  vam->retval = ntohl (mp->retval);
2480  vam->result_ready = 1;
2481}
2482
2483static void vl_api_gre_tunnel_add_del_reply_t_handler
2484  (vl_api_gre_tunnel_add_del_reply_t * mp)
2485{
2486  vat_main_t *vam = &vat_main;
2487  i32 retval = ntohl (mp->retval);
2488  if (vam->async_mode)
2489    {
2490      vam->async_errors += (retval < 0);
2491    }
2492  else
2493    {
2494      vam->retval = retval;
2495      vam->sw_if_index = ntohl (mp->sw_if_index);
2496      vam->result_ready = 1;
2497    }
2498}
2499
2500static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2501  (vl_api_gre_tunnel_add_del_reply_t * mp)
2502{
2503  vat_main_t *vam = &vat_main;
2504  vat_json_node_t node;
2505
2506  vat_json_init_object (&node);
2507  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2508  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2509
2510  vat_json_print (vam->ofp, &node);
2511  vat_json_free (&node);
2512
2513  vam->retval = ntohl (mp->retval);
2514  vam->result_ready = 1;
2515}
2516
2517static void vl_api_create_vhost_user_if_reply_t_handler
2518  (vl_api_create_vhost_user_if_reply_t * mp)
2519{
2520  vat_main_t *vam = &vat_main;
2521  i32 retval = ntohl (mp->retval);
2522  if (vam->async_mode)
2523    {
2524      vam->async_errors += (retval < 0);
2525    }
2526  else
2527    {
2528      vam->retval = retval;
2529      vam->sw_if_index = ntohl (mp->sw_if_index);
2530      vam->result_ready = 1;
2531    }
2532  vam->regenerate_interface_table = 1;
2533}
2534
2535static void vl_api_create_vhost_user_if_reply_t_handler_json
2536  (vl_api_create_vhost_user_if_reply_t * mp)
2537{
2538  vat_main_t *vam = &vat_main;
2539  vat_json_node_t node;
2540
2541  vat_json_init_object (&node);
2542  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2543  vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2544
2545  vat_json_print (vam->ofp, &node);
2546  vat_json_free (&node);
2547
2548  vam->retval = ntohl (mp->retval);
2549  vam->result_ready = 1;
2550}
2551
2552static void vl_api_ip_address_details_t_handler
2553  (vl_api_ip_address_details_t * mp)
2554{
2555  vat_main_t *vam = &vat_main;
2556  static ip_address_details_t empty_ip_address_details = { {0} };
2557  ip_address_details_t *address = NULL;
2558  ip_details_t *current_ip_details = NULL;
2559  ip_details_t *details = NULL;
2560
2561  details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2562
2563  if (!details || vam->current_sw_if_index >= vec_len (details)
2564      || !details[vam->current_sw_if_index].present)
2565    {
2566      errmsg ("ip address details arrived but not stored");
2567      errmsg ("ip_dump should be called first");
2568      return;
2569    }
2570
2571  current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2572
2573#define addresses (current_ip_details->addr)
2574
2575  vec_validate_init_empty (addresses, vec_len (addresses),
2576			   empty_ip_address_details);
2577
2578  address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2579
2580  clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2581  address->prefix_length = mp->prefix.len;
2582#undef addresses
2583}
2584
2585static void vl_api_ip_address_details_t_handler_json
2586  (vl_api_ip_address_details_t * mp)
2587{
2588  vat_main_t *vam = &vat_main;
2589  vat_json_node_t *node = NULL;
2590
2591  if (VAT_JSON_ARRAY != vam->json_tree.type)
2592    {
2593      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2594      vat_json_init_array (&vam->json_tree);
2595    }
2596  node = vat_json_array_add (&vam->json_tree);
2597
2598  vat_json_init_object (node);
2599  vat_json_object_add_prefix (node, &mp->prefix);
2600}
2601
2602static void
2603vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2604{
2605  vat_main_t *vam = &vat_main;
2606  static ip_details_t empty_ip_details = { 0 };
2607  ip_details_t *ip = NULL;
2608  u32 sw_if_index = ~0;
2609
2610  sw_if_index = ntohl (mp->sw_if_index);
2611
2612  vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2613			   sw_if_index, empty_ip_details);
2614
2615  ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2616			 sw_if_index);
2617
2618  ip->present = 1;
2619}
2620
2621static void
2622vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2623{
2624  vat_main_t *vam = &vat_main;
2625
2626  if (VAT_JSON_ARRAY != vam->json_tree.type)
2627    {
2628      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2629      vat_json_init_array (&vam->json_tree);
2630    }
2631  vat_json_array_add_uint (&vam->json_tree,
2632			   clib_net_to_host_u32 (mp->sw_if_index));
2633}
2634
2635static void vl_api_get_first_msg_id_reply_t_handler
2636  (vl_api_get_first_msg_id_reply_t * mp)
2637{
2638  vat_main_t *vam = &vat_main;
2639  i32 retval = ntohl (mp->retval);
2640
2641  if (vam->async_mode)
2642    {
2643      vam->async_errors += (retval < 0);
2644    }
2645  else
2646    {
2647      vam->retval = retval;
2648      vam->result_ready = 1;
2649    }
2650  if (retval >= 0)
2651    {
2652      errmsg ("first message id %d", ntohs (mp->first_msg_id));
2653    }
2654}
2655
2656static void vl_api_get_first_msg_id_reply_t_handler_json
2657  (vl_api_get_first_msg_id_reply_t * mp)
2658{
2659  vat_main_t *vam = &vat_main;
2660  vat_json_node_t node;
2661
2662  vat_json_init_object (&node);
2663  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2664  vat_json_object_add_uint (&node, "first_msg_id",
2665			    (uint) ntohs (mp->first_msg_id));
2666
2667  vat_json_print (vam->ofp, &node);
2668  vat_json_free (&node);
2669
2670  vam->retval = ntohl (mp->retval);
2671  vam->result_ready = 1;
2672}
2673
2674static void vl_api_get_node_graph_reply_t_handler
2675  (vl_api_get_node_graph_reply_t * mp)
2676{
2677  vat_main_t *vam = &vat_main;
2678  i32 retval = ntohl (mp->retval);
2679  u8 *pvt_copy, *reply;
2680  void *oldheap;
2681  vlib_node_t *node;
2682  int i;
2683
2684  if (vam->async_mode)
2685    {
2686      vam->async_errors += (retval < 0);
2687    }
2688  else
2689    {
2690      vam->retval = retval;
2691      vam->result_ready = 1;
2692    }
2693
2694  /* "Should never happen..." */
2695  if (retval != 0)
2696    return;
2697
2698  reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2699  pvt_copy = vec_dup (reply);
2700
2701  /* Toss the shared-memory original... */
2702  oldheap = vl_msg_push_heap ();
2703
2704  vec_free (reply);
2705
2706  vl_msg_pop_heap (oldheap);
2707
2708  if (vam->graph_nodes)
2709    {
2710      hash_free (vam->graph_node_index_by_name);
2711
2712      for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2713	{
2714	  node = vam->graph_nodes[0][i];
2715	  vec_free (node->name);
2716	  vec_free (node->next_nodes);
2717	  vec_free (node);
2718	}
2719      vec_free (vam->graph_nodes[0]);
2720      vec_free (vam->graph_nodes);
2721    }
2722
2723  vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2724  vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2725  vec_free (pvt_copy);
2726
2727  for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2728    {
2729      node = vam->graph_nodes[0][i];
2730      hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2731    }
2732}
2733
2734static void vl_api_get_node_graph_reply_t_handler_json
2735  (vl_api_get_node_graph_reply_t * mp)
2736{
2737  vat_main_t *vam = &vat_main;
2738  void *oldheap;
2739  vat_json_node_t node;
2740  u8 *reply;
2741
2742  /* $$$$ make this real? */
2743  vat_json_init_object (&node);
2744  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2745  vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2746
2747  reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2748
2749  /* Toss the shared-memory original... */
2750  oldheap = vl_msg_push_heap ();
2751
2752  vec_free (reply);
2753
2754  vl_msg_pop_heap (oldheap);
2755
2756  vat_json_print (vam->ofp, &node);
2757  vat_json_free (&node);
2758
2759  vam->retval = ntohl (mp->retval);
2760  vam->result_ready = 1;
2761}
2762
2763static void
2764vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
2765{
2766  vat_main_t *vam = &vat_main;
2767  u8 *s = 0;
2768
2769  if (mp->local)
2770    {
2771      s = format (s, "%=16d%=16d%=16d",
2772		  ntohl (mp->sw_if_index), mp->priority, mp->weight);
2773    }
2774  else
2775    {
2776      s = format (s, "%=16U%=16d%=16d",
2777		  mp->is_ipv6 ? format_ip6_address :
2778		  format_ip4_address,
2779		  mp->ip_address, mp->priority, mp->weight);
2780    }
2781
2782  print (vam->ofp, "%v", s);
2783  vec_free (s);
2784}
2785
2786static void
2787vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
2788{
2789  vat_main_t *vam = &vat_main;
2790  vat_json_node_t *node = NULL;
2791  struct in6_addr ip6;
2792  struct in_addr ip4;
2793
2794  if (VAT_JSON_ARRAY != vam->json_tree.type)
2795    {
2796      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2797      vat_json_init_array (&vam->json_tree);
2798    }
2799  node = vat_json_array_add (&vam->json_tree);
2800  vat_json_init_object (node);
2801
2802  vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2803  vat_json_object_add_uint (node, "priority", mp->priority);
2804  vat_json_object_add_uint (node, "weight", mp->weight);
2805
2806  if (mp->local)
2807    vat_json_object_add_uint (node, "sw_if_index",
2808			      clib_net_to_host_u32 (mp->sw_if_index));
2809  else
2810    {
2811      if (mp->is_ipv6)
2812	{
2813	  clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2814	  vat_json_object_add_ip6 (node, "address", ip6);
2815	}
2816      else
2817	{
2818	  clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2819	  vat_json_object_add_ip4 (node, "address", ip4);
2820	}
2821    }
2822}
2823
2824static void
2825vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2826					  mp)
2827{
2828  vat_main_t *vam = &vat_main;
2829  u8 *ls_name = 0;
2830
2831  ls_name = format (0, "%s", mp->ls_name);
2832
2833  print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2834	 ls_name);
2835  vec_free (ls_name);
2836}
2837
2838static void
2839  vl_api_one_locator_set_details_t_handler_json
2840  (vl_api_one_locator_set_details_t * mp)
2841{
2842  vat_main_t *vam = &vat_main;
2843  vat_json_node_t *node = 0;
2844  u8 *ls_name = 0;
2845
2846  ls_name = format (0, "%s", mp->ls_name);
2847  vec_add1 (ls_name, 0);
2848
2849  if (VAT_JSON_ARRAY != vam->json_tree.type)
2850    {
2851      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2852      vat_json_init_array (&vam->json_tree);
2853    }
2854  node = vat_json_array_add (&vam->json_tree);
2855
2856  vat_json_init_object (node);
2857  vat_json_object_add_string_copy (node, "ls_name", ls_name);
2858  vat_json_object_add_uint (node, "ls_index",
2859			    clib_net_to_host_u32 (mp->ls_index));
2860  vec_free (ls_name);
2861}
2862
2863typedef struct
2864{
2865  u32 spi;
2866  u8 si;
2867} __attribute__ ((__packed__)) lisp_nsh_api_t;
2868
2869uword
2870unformat_nsh_address (unformat_input_t * input, va_list * args)
2871{
2872  lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2873  return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2874}
2875
2876u8 *
2877format_nsh_address_vat (u8 * s, va_list * args)
2878{
2879  nsh_t *a = va_arg (*args, nsh_t *);
2880  return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
2881}
2882
2883static u8 *
2884format_lisp_flat_eid (u8 * s, va_list * args)
2885{
2886  u32 type = va_arg (*args, u32);
2887  u8 *eid = va_arg (*args, u8 *);
2888  u32 eid_len = va_arg (*args, u32);
2889
2890  switch (type)
2891    {
2892    case 0:
2893      return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2894    case 1:
2895      return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2896    case 2:
2897      return format (s, "%U", format_ethernet_address, eid);
2898    case 3:
2899      return format (s, "%U", format_nsh_address_vat, eid);
2900    }
2901  return 0;
2902}
2903
2904static u8 *
2905format_lisp_eid_vat (u8 * s, va_list * args)
2906{
2907  u32 type = va_arg (*args, u32);
2908  u8 *eid = va_arg (*args, u8 *);
2909  u32 eid_len = va_arg (*args, u32);
2910  u8 *seid = va_arg (*args, u8 *);
2911  u32 seid_len = va_arg (*args, u32);
2912  u32 is_src_dst = va_arg (*args, u32);
2913
2914  if (is_src_dst)
2915    s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
2916
2917  s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
2918
2919  return s;
2920}
2921
2922static void
2923vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
2924{
2925  vat_main_t *vam = &vat_main;
2926  u8 *s = 0, *eid = 0;
2927
2928  if (~0 == mp->locator_set_index)
2929    s = format (0, "action: %d", mp->action);
2930  else
2931    s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
2932
2933  eid = format (0, "%U", format_lisp_eid_vat,
2934		mp->eid_type,
2935		mp->eid,
2936		mp->eid_prefix_len,
2937		mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2938  vec_add1 (eid, 0);
2939
2940  print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
2941	 clib_net_to_host_u32 (mp->vni),
2942	 eid,
2943	 mp->is_local ? "local" : "remote",
2944	 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
2945	 clib_net_to_host_u16 (mp->key_id), mp->key);
2946
2947  vec_free (s);
2948  vec_free (eid);
2949}
2950
2951static void
2952vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
2953					     * mp)
2954{
2955  vat_main_t *vam = &vat_main;
2956  vat_json_node_t *node = 0;
2957  u8 *eid = 0;
2958
2959  if (VAT_JSON_ARRAY != vam->json_tree.type)
2960    {
2961      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2962      vat_json_init_array (&vam->json_tree);
2963    }
2964  node = vat_json_array_add (&vam->json_tree);
2965
2966  vat_json_init_object (node);
2967  if (~0 == mp->locator_set_index)
2968    vat_json_object_add_uint (node, "action", mp->action);
2969  else
2970    vat_json_object_add_uint (node, "locator_set_index",
2971			      clib_net_to_host_u32 (mp->locator_set_index));
2972
2973  vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
2974  if (mp->eid_type == 3)
2975    {
2976      vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
2977      vat_json_init_object (nsh_json);
2978      lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) mp->eid;
2979      vat_json_object_add_uint (nsh_json, "spi",
2980				clib_net_to_host_u32 (nsh->spi));
2981      vat_json_object_add_uint (nsh_json, "si", nsh->si);
2982    }
2983  else
2984    {
2985      eid = format (0, "%U", format_lisp_eid_vat,
2986		    mp->eid_type,
2987		    mp->eid,
2988		    mp->eid_prefix_len,
2989		    mp->seid, mp->seid_prefix_len, mp->is_src_dst);
2990      vec_add1 (eid, 0);
2991      vat_json_object_add_string_copy (node, "eid", eid);
2992      vec_free (eid);
2993    }
2994  vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
2995  vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
2996  vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
2997
2998  if (mp->key_id)
2999    {
3000      vat_json_object_add_uint (node, "key_id",
3001				clib_net_to_host_u16 (mp->key_id));
3002      vat_json_object_add_string_copy (node, "key", mp->key);
3003    }
3004}
3005
3006static void
3007vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3008{
3009  vat_main_t *vam = &vat_main;
3010  u8 *seid = 0, *deid = 0;
3011  u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3012
3013  deid = format (0, "%U", format_lisp_eid_vat,
3014		 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3015
3016  seid = format (0, "%U", format_lisp_eid_vat,
3017		 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3018
3019  vec_add1 (deid, 0);
3020  vec_add1 (seid, 0);
3021
3022  if (mp->is_ip4)
3023    format_ip_address_fcn = format_ip4_address;
3024  else
3025    format_ip_address_fcn = format_ip6_address;
3026
3027
3028  print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3029	 clib_net_to_host_u32 (mp->vni),
3030	 seid, deid,
3031	 format_ip_address_fcn, mp->lloc,
3032	 format_ip_address_fcn, mp->rloc,
3033	 clib_net_to_host_u32 (mp->pkt_count),
3034	 clib_net_to_host_u32 (mp->bytes));
3035
3036  vec_free (deid);
3037  vec_free (seid);
3038}
3039
3040static void
3041vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3042{
3043  struct in6_addr ip6;
3044  struct in_addr ip4;
3045  vat_main_t *vam = &vat_main;
3046  vat_json_node_t *node = 0;
3047  u8 *deid = 0, *seid = 0;
3048
3049  if (VAT_JSON_ARRAY != vam->json_tree.type)
3050    {
3051      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3052      vat_json_init_array (&vam->json_tree);
3053    }
3054  node = vat_json_array_add (&vam->json_tree);
3055
3056  vat_json_init_object (node);
3057  deid = format (0, "%U", format_lisp_eid_vat,
3058		 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3059
3060  seid = format (0, "%U", format_lisp_eid_vat,
3061		 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3062
3063  vec_add1 (deid, 0);
3064  vec_add1 (seid, 0);
3065
3066  vat_json_object_add_string_copy (node, "seid", seid);
3067  vat_json_object_add_string_copy (node, "deid", deid);
3068  vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3069
3070  if (mp->is_ip4)
3071    {
3072      clib_memcpy (&ip4, mp->lloc, sizeof (ip4));
3073      vat_json_object_add_ip4 (node, "lloc", ip4);
3074      clib_memcpy (&ip4, mp->rloc, sizeof (ip4));
3075      vat_json_object_add_ip4 (node, "rloc", ip4);
3076    }
3077  else
3078    {
3079      clib_memcpy (&ip6, mp->lloc, sizeof (ip6));
3080      vat_json_object_add_ip6 (node, "lloc", ip6);
3081      clib_memcpy (&ip6, mp->rloc, sizeof (ip6));
3082      vat_json_object_add_ip6 (node, "rloc", ip6);
3083    }
3084  vat_json_object_add_uint (node, "pkt_count",
3085			    clib_net_to_host_u32 (mp->pkt_count));
3086  vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3087
3088  vec_free (deid);
3089  vec_free (seid);
3090}
3091
3092static void
3093  vl_api_one_eid_table_map_details_t_handler
3094  (vl_api_one_eid_table_map_details_t * mp)
3095{
3096  vat_main_t *vam = &vat_main;
3097
3098  u8 *line = format (0, "%=10d%=10d",
3099		     clib_net_to_host_u32 (mp->vni),
3100		     clib_net_to_host_u32 (mp->dp_table));
3101  print (vam->ofp, "%v", line);
3102  vec_free (line);
3103}
3104
3105static void
3106  vl_api_one_eid_table_map_details_t_handler_json
3107  (vl_api_one_eid_table_map_details_t * mp)
3108{
3109  vat_main_t *vam = &vat_main;
3110  vat_json_node_t *node = NULL;
3111
3112  if (VAT_JSON_ARRAY != vam->json_tree.type)
3113    {
3114      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3115      vat_json_init_array (&vam->json_tree);
3116    }
3117  node = vat_json_array_add (&vam->json_tree);
3118  vat_json_init_object (node);
3119  vat_json_object_add_uint (node, "dp_table",
3120			    clib_net_to_host_u32 (mp->dp_table));
3121  vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3122}
3123
3124static void
3125  vl_api_one_eid_table_vni_details_t_handler
3126  (vl_api_one_eid_table_vni_details_t * mp)
3127{
3128  vat_main_t *vam = &vat_main;
3129
3130  u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3131  print (vam->ofp, "%v", line);
3132  vec_free (line);
3133}
3134
3135static void
3136  vl_api_one_eid_table_vni_details_t_handler_json
3137  (vl_api_one_eid_table_vni_details_t * mp)
3138{
3139  vat_main_t *vam = &vat_main;
3140  vat_json_node_t *node = NULL;
3141
3142  if (VAT_JSON_ARRAY != vam->json_tree.type)
3143    {
3144      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3145      vat_json_init_array (&vam->json_tree);
3146    }
3147  node = vat_json_array_add (&vam->json_tree);
3148  vat_json_init_object (node);
3149  vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3150}
3151
3152static void
3153  vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3154  (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3155{
3156  vat_main_t *vam = &vat_main;
3157  int retval = clib_net_to_host_u32 (mp->retval);
3158
3159  vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3160  print (vam->ofp, "fallback threshold value: %d", mp->value);
3161
3162  vam->retval = retval;
3163  vam->result_ready = 1;
3164}
3165
3166static void
3167  vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3168  (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3169{
3170  vat_main_t *vam = &vat_main;
3171  vat_json_node_t _node, *node = &_node;
3172  int retval = clib_net_to_host_u32 (mp->retval);
3173
3174  vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3175  vat_json_init_object (node);
3176  vat_json_object_add_uint (node, "value", mp->value);
3177
3178  vat_json_print (vam->ofp, node);
3179  vat_json_free (node);
3180
3181  vam->retval = retval;
3182  vam->result_ready = 1;
3183}
3184
3185static void
3186  vl_api_show_one_map_register_state_reply_t_handler
3187  (vl_api_show_one_map_register_state_reply_t * mp)
3188{
3189  vat_main_t *vam = &vat_main;
3190  int retval = clib_net_to_host_u32 (mp->retval);
3191
3192  print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3193
3194  vam->retval = retval;
3195  vam->result_ready = 1;
3196}
3197
3198static void
3199  vl_api_show_one_map_register_state_reply_t_handler_json
3200  (vl_api_show_one_map_register_state_reply_t * mp)
3201{
3202  vat_main_t *vam = &vat_main;
3203  vat_json_node_t _node, *node = &_node;
3204  int retval = clib_net_to_host_u32 (mp->retval);
3205
3206  u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3207
3208  vat_json_init_object (node);
3209  vat_json_object_add_string_copy (node, "state", s);
3210
3211  vat_json_print (vam->ofp, node);
3212  vat_json_free (node);
3213
3214  vam->retval = retval;
3215  vam->result_ready = 1;
3216  vec_free (s);
3217}
3218
3219static void
3220  vl_api_show_one_rloc_probe_state_reply_t_handler
3221  (vl_api_show_one_rloc_probe_state_reply_t * mp)
3222{
3223  vat_main_t *vam = &vat_main;
3224  int retval = clib_net_to_host_u32 (mp->retval);
3225
3226  if (retval)
3227    goto end;
3228
3229  print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3230end:
3231  vam->retval = retval;
3232  vam->result_ready = 1;
3233}
3234
3235static void
3236  vl_api_show_one_rloc_probe_state_reply_t_handler_json
3237  (vl_api_show_one_rloc_probe_state_reply_t * mp)
3238{
3239  vat_main_t *vam = &vat_main;
3240  vat_json_node_t _node, *node = &_node;
3241  int retval = clib_net_to_host_u32 (mp->retval);
3242
3243  u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3244  vat_json_init_object (node);
3245  vat_json_object_add_string_copy (node, "state", s);
3246
3247  vat_json_print (vam->ofp, node);
3248  vat_json_free (node);
3249
3250  vam->retval = retval;
3251  vam->result_ready = 1;
3252  vec_free (s);
3253}
3254
3255static void
3256  vl_api_show_one_stats_enable_disable_reply_t_handler
3257  (vl_api_show_one_stats_enable_disable_reply_t * mp)
3258{
3259  vat_main_t *vam = &vat_main;
3260  int retval = clib_net_to_host_u32 (mp->retval);
3261
3262  if (retval)
3263    goto end;
3264
3265  print (vam->ofp, "%s", mp->is_en ? "enabled" : "disabled");
3266end:
3267  vam->retval = retval;
3268  vam->result_ready = 1;
3269}
3270
3271static void
3272  vl_api_show_one_stats_enable_disable_reply_t_handler_json
3273  (vl_api_show_one_stats_enable_disable_reply_t * mp)
3274{
3275  vat_main_t *vam = &vat_main;
3276  vat_json_node_t _node, *node = &_node;
3277  int retval = clib_net_to_host_u32 (mp->retval);
3278
3279  u8 *s = format (0, "%s", mp->is_en ? "enabled" : "disabled");
3280  vat_json_init_object (node);
3281  vat_json_object_add_string_copy (node, "state", s);
3282
3283  vat_json_print (vam->ofp, node);
3284  vat_json_free (node);
3285
3286  vam->retval = retval;
3287  vam->result_ready = 1;
3288  vec_free (s);
3289}
3290
3291static void
3292api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
3293{
3294  e->dp_table = clib_net_to_host_u32 (e->dp_table);
3295  e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
3296  e->vni = clib_net_to_host_u32 (e->vni);
3297}
3298
3299static void
3300  gpe_fwd_entries_get_reply_t_net_to_host
3301  (vl_api_gpe_fwd_entries_get_reply_t * mp)
3302{
3303  u32 i;
3304
3305  mp->count = clib_net_to_host_u32 (mp->count);
3306  for (i = 0; i < mp->count; i++)
3307    {
3308      api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
3309    }
3310}
3311
3312static u8 *
3313format_gpe_encap_mode (u8 * s, va_list * args)
3314{
3315  u32 mode = va_arg (*args, u32);
3316
3317  switch (mode)
3318    {
3319    case 0:
3320      return format (s, "lisp");
3321    case 1:
3322      return format (s, "vxlan");
3323    }
3324  return 0;
3325}
3326
3327static void
3328  vl_api_gpe_get_encap_mode_reply_t_handler
3329  (vl_api_gpe_get_encap_mode_reply_t * mp)
3330{
3331  vat_main_t *vam = &vat_main;
3332
3333  print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3334  vam->retval = ntohl (mp->retval);
3335  vam->result_ready = 1;
3336}
3337
3338static void
3339  vl_api_gpe_get_encap_mode_reply_t_handler_json
3340  (vl_api_gpe_get_encap_mode_reply_t * mp)
3341{
3342  vat_main_t *vam = &vat_main;
3343  vat_json_node_t node;
3344
3345  u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3346  vec_add1 (encap_mode, 0);
3347
3348  vat_json_init_object (&node);
3349  vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3350
3351  vec_free (encap_mode);
3352  vat_json_print (vam->ofp, &node);
3353  vat_json_free (&node);
3354
3355  vam->retval = ntohl (mp->retval);
3356  vam->result_ready = 1;
3357}
3358
3359static void
3360  vl_api_gpe_fwd_entry_path_details_t_handler
3361  (vl_api_gpe_fwd_entry_path_details_t * mp)
3362{
3363  vat_main_t *vam = &vat_main;
3364  u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3365
3366  if (mp->lcl_loc.is_ip4)
3367    format_ip_address_fcn = format_ip4_address;
3368  else
3369    format_ip_address_fcn = format_ip6_address;
3370
3371  print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
3372	 format_ip_address_fcn, &mp->lcl_loc,
3373	 format_ip_address_fcn, &mp->rmt_loc);
3374}
3375
3376static void
3377lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
3378{
3379  struct in6_addr ip6;
3380  struct in_addr ip4;
3381
3382  if (loc->is_ip4)
3383    {
3384      clib_memcpy (&ip4, loc->addr, sizeof (ip4));
3385      vat_json_object_add_ip4 (n, "address", ip4);
3386    }
3387  else
3388    {
3389      clib_memcpy (&ip6, loc->addr, sizeof (ip6));
3390      vat_json_object_add_ip6 (n, "address", ip6);
3391    }
3392  vat_json_object_add_uint (n, "weight", loc->weight);
3393}
3394
3395static void
3396  vl_api_gpe_fwd_entry_path_details_t_handler_json
3397  (vl_api_gpe_fwd_entry_path_details_t * mp)
3398{
3399  vat_main_t *vam = &vat_main;
3400  vat_json_node_t *node = NULL;
3401  vat_json_node_t *loc_node;
3402
3403  if (VAT_JSON_ARRAY != vam->json_tree.type)
3404    {
3405      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3406      vat_json_init_array (&vam->json_tree);
3407    }
3408  node = vat_json_array_add (&vam->json_tree);
3409  vat_json_init_object (node);
3410
3411  loc_node = vat_json_object_add (node, "local_locator");
3412  vat_json_init_object (loc_node);
3413  lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3414
3415  loc_node = vat_json_object_add (node, "remote_locator");
3416  vat_json_init_object (loc_node);
3417  lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3418}
3419
3420static void
3421  vl_api_gpe_fwd_entries_get_reply_t_handler
3422  (vl_api_gpe_fwd_entries_get_reply_t * mp)
3423{
3424  vat_main_t *vam = &vat_main;
3425  u32 i;
3426  int retval = clib_net_to_host_u32 (mp->retval);
3427  vl_api_gpe_fwd_entry_t *e;
3428
3429  if (retval)
3430    goto end;
3431
3432  gpe_fwd_entries_get_reply_t_net_to_host (mp);
3433
3434  for (i = 0; i < mp->count; i++)
3435    {
3436      e = &mp->entries[i];
3437      print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
3438	     format_lisp_flat_eid, e->eid_type, e->leid, e->leid_prefix_len,
3439	     format_lisp_flat_eid, e->eid_type, e->reid, e->reid_prefix_len);
3440    }
3441
3442end:
3443  vam->retval = retval;
3444  vam->result_ready = 1;
3445}
3446
3447static void
3448  vl_api_gpe_fwd_entries_get_reply_t_handler_json
3449  (vl_api_gpe_fwd_entries_get_reply_t * mp)
3450{
3451  u8 *s = 0;
3452  vat_main_t *vam = &vat_main;
3453  vat_json_node_t *e = 0, root;
3454  u32 i;
3455  int retval = clib_net_to_host_u32 (mp->retval);
3456  vl_api_gpe_fwd_entry_t *fwd;
3457
3458  if (retval)
3459    goto end;
3460
3461  gpe_fwd_entries_get_reply_t_net_to_host (mp);
3462  vat_json_init_array (&root);
3463
3464  for (i = 0; i < mp->count; i++)
3465    {
3466      e = vat_json_array_add (&root);
3467      fwd = &mp->entries[i];
3468
3469      vat_json_init_object (e);
3470      vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3471      vat_json_object_add_int (e, "dp_table", fwd->dp_table);
3472      vat_json_object_add_int (e, "vni", fwd->vni);
3473      vat_json_object_add_int (e, "action", fwd->action);
3474
3475      s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->leid,
3476		  fwd->leid_prefix_len);
3477      vec_add1 (s, 0);
3478      vat_json_object_add_string_copy (e, "leid", s);
3479      vec_free (s);
3480
3481      s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->reid,
3482		  fwd->reid_prefix_len);
3483      vec_add1 (s, 0);
3484      vat_json_object_add_string_copy (e, "reid", s);
3485      vec_free (s);
3486    }
3487
3488  vat_json_print (vam->ofp, &root);
3489  vat_json_free (&root);
3490
3491end:
3492  vam->retval = retval;
3493  vam->result_ready = 1;
3494}
3495
3496static void
3497  vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3498  (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3499{
3500  vat_main_t *vam = &vat_main;
3501  u32 i, n;
3502  int retval = clib_net_to_host_u32 (mp->retval);
3503  vl_api_gpe_native_fwd_rpath_t *r;
3504
3505  if (retval)
3506    goto end;
3507
3508  n = clib_net_to_host_u32 (mp->count);
3509
3510  for (i = 0; i < n; i++)
3511    {
3512      r = &mp->entries[i];
3513      print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3514	     clib_net_to_host_u32 (r->fib_index),
3515	     clib_net_to_host_u32 (r->nh_sw_if_index),
3516	     r->is_ip4 ? format_ip4_address : format_ip6_address, r->nh_addr);
3517    }
3518
3519end:
3520  vam->retval = retval;
3521  vam->result_ready = 1;
3522}
3523
3524static void
3525  vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3526  (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3527{
3528  vat_main_t *vam = &vat_main;
3529  vat_json_node_t root, *e;
3530  u32 i, n;
3531  int retval = clib_net_to_host_u32 (mp->retval);
3532  vl_api_gpe_native_fwd_rpath_t *r;
3533  u8 *s;
3534
3535  if (retval)
3536    goto end;
3537
3538  n = clib_net_to_host_u32 (mp->count);
3539  vat_json_init_array (&root);
3540
3541  for (i = 0; i < n; i++)
3542    {
3543      e = vat_json_array_add (&root);
3544      vat_json_init_object (e);
3545      r = &mp->entries[i];
3546      s =
3547	format (0, "%U", r->is_ip4 ? format_ip4_address : format_ip6_address,
3548		r->nh_addr);
3549      vec_add1 (s, 0);
3550      vat_json_object_add_string_copy (e, "ip4", s);
3551      vec_free (s);
3552
3553      vat_json_object_add_uint (e, "fib_index",
3554				clib_net_to_host_u32 (r->fib_index));
3555      vat_json_object_add_uint (e, "nh_sw_if_index",
3556				clib_net_to_host_u32 (r->nh_sw_if_index));
3557    }
3558
3559  vat_json_print (vam->ofp, &root);
3560  vat_json_free (&root);
3561
3562end:
3563  vam->retval = retval;
3564  vam->result_ready = 1;
3565}
3566
3567static void
3568  vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3569  (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3570{
3571  vat_main_t *vam = &vat_main;
3572  u32 i, n;
3573  int retval = clib_net_to_host_u32 (mp->retval);
3574
3575  if (retval)
3576    goto end;
3577
3578  n = clib_net_to_host_u32 (mp->count);
3579
3580  for (i = 0; i < n; i++)
3581    print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3582
3583end:
3584  vam->retval = retval;
3585  vam->result_ready = 1;
3586}
3587
3588static void
3589  vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3590  (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3591{
3592  vat_main_t *vam = &vat_main;
3593  vat_json_node_t root;
3594  u32 i, n;
3595  int retval = clib_net_to_host_u32 (mp->retval);
3596
3597  if (retval)
3598    goto end;
3599
3600  n = clib_net_to_host_u32 (mp->count);
3601  vat_json_init_array (&root);
3602
3603  for (i = 0; i < n; i++)
3604    vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3605
3606  vat_json_print (vam->ofp, &root);
3607  vat_json_free (&root);
3608
3609end:
3610  vam->retval = retval;
3611  vam->result_ready = 1;
3612}
3613
3614static void
3615  vl_api_one_ndp_entries_get_reply_t_handler
3616  (vl_api_one_ndp_entries_get_reply_t * mp)
3617{
3618  vat_main_t *vam = &vat_main;
3619  u32 i, n;
3620  int retval = clib_net_to_host_u32 (mp->retval);
3621
3622  if (retval)
3623    goto end;
3624
3625  n = clib_net_to_host_u32 (mp->count);
3626
3627  for (i = 0; i < n; i++)
3628    print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3629	   format_ethernet_address, mp->entries[i].mac);
3630
3631end:
3632  vam->retval = retval;
3633  vam->result_ready = 1;
3634}
3635
3636static void
3637  vl_api_one_ndp_entries_get_reply_t_handler_json
3638  (vl_api_one_ndp_entries_get_reply_t * mp)
3639{
3640  u8 *s = 0;
3641  vat_main_t *vam = &vat_main;
3642  vat_json_node_t *e = 0, root;
3643  u32 i, n;
3644  int retval = clib_net_to_host_u32 (mp->retval);
3645  vl_api_one_ndp_entry_t *arp_entry;
3646
3647  if (retval)
3648    goto end;
3649
3650  n = clib_net_to_host_u32 (mp->count);
3651  vat_json_init_array (&root);
3652
3653  for (i = 0; i < n; i++)
3654    {
3655      e = vat_json_array_add (&root);
3656      arp_entry = &mp->entries[i];
3657
3658      vat_json_init_object (e);
3659      s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3660      vec_add1 (s, 0);
3661
3662      vat_json_object_add_string_copy (e, "mac", s);
3663      vec_free (s);
3664
3665      s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3666      vec_add1 (s, 0);
3667      vat_json_object_add_string_copy (e, "ip6", s);
3668      vec_free (s);
3669    }
3670
3671  vat_json_print (vam->ofp, &root);
3672  vat_json_free (&root);
3673
3674end:
3675  vam->retval = retval;
3676  vam->result_ready = 1;
3677}
3678
3679static void
3680  vl_api_one_l2_arp_entries_get_reply_t_handler
3681  (vl_api_one_l2_arp_entries_get_reply_t * mp)
3682{
3683  vat_main_t *vam = &vat_main;
3684  u32 i, n;
3685  int retval = clib_net_to_host_u32 (mp->retval);
3686
3687  if (retval)
3688    goto end;
3689
3690  n = clib_net_to_host_u32 (mp->count);
3691
3692  for (i = 0; i < n; i++)
3693    print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3694	   format_ethernet_address, mp->entries[i].mac);
3695
3696end:
3697  vam->retval = retval;
3698  vam->result_ready = 1;
3699}
3700
3701static void
3702  vl_api_one_l2_arp_entries_get_reply_t_handler_json
3703  (vl_api_one_l2_arp_entries_get_reply_t * mp)
3704{
3705  u8 *s = 0;
3706  vat_main_t *vam = &vat_main;
3707  vat_json_node_t *e = 0, root;
3708  u32 i, n;
3709  int retval = clib_net_to_host_u32 (mp->retval);
3710  vl_api_one_l2_arp_entry_t *arp_entry;
3711
3712  if (retval)
3713    goto end;
3714
3715  n = clib_net_to_host_u32 (mp->count);
3716  vat_json_init_array (&root);
3717
3718  for (i = 0; i < n; i++)
3719    {
3720      e = vat_json_array_add (&root);
3721      arp_entry = &mp->entries[i];
3722
3723      vat_json_init_object (e);
3724      s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3725      vec_add1 (s, 0);
3726
3727      vat_json_object_add_string_copy (e, "mac", s);
3728      vec_free (s);
3729
3730      s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3731      vec_add1 (s, 0);
3732      vat_json_object_add_string_copy (e, "ip4", s);
3733      vec_free (s);
3734    }
3735
3736  vat_json_print (vam->ofp, &root);
3737  vat_json_free (&root);
3738
3739end:
3740  vam->retval = retval;
3741  vam->result_ready = 1;
3742}
3743
3744static void
3745vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3746{
3747  vat_main_t *vam = &vat_main;
3748  u32 i, n;
3749  int retval = clib_net_to_host_u32 (mp->retval);
3750
3751  if (retval)
3752    goto end;
3753
3754  n = clib_net_to_host_u32 (mp->count);
3755
3756  for (i = 0; i < n; i++)
3757    {
3758      print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3759    }
3760
3761end:
3762  vam->retval = retval;
3763  vam->result_ready = 1;
3764}
3765
3766static void
3767  vl_api_one_ndp_bd_get_reply_t_handler_json
3768  (vl_api_one_ndp_bd_get_reply_t * mp)
3769{
3770  vat_main_t *vam = &vat_main;
3771  vat_json_node_t root;
3772  u32 i, n;
3773  int retval = clib_net_to_host_u32 (mp->retval);
3774
3775  if (retval)
3776    goto end;
3777
3778  n = clib_net_to_host_u32 (mp->count);
3779  vat_json_init_array (&root);
3780
3781  for (i = 0; i < n; i++)
3782    {
3783      vat_json_array_add_uint (&root,
3784			       clib_net_to_host_u32 (mp->bridge_domains[i]));
3785    }
3786
3787  vat_json_print (vam->ofp, &root);
3788  vat_json_free (&root);
3789
3790end:
3791  vam->retval = retval;
3792  vam->result_ready = 1;
3793}
3794
3795static void
3796  vl_api_one_l2_arp_bd_get_reply_t_handler
3797  (vl_api_one_l2_arp_bd_get_reply_t * mp)
3798{
3799  vat_main_t *vam = &vat_main;
3800  u32 i, n;
3801  int retval = clib_net_to_host_u32 (mp->retval);
3802
3803  if (retval)
3804    goto end;
3805
3806  n = clib_net_to_host_u32 (mp->count);
3807
3808  for (i = 0; i < n; i++)
3809    {
3810      print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3811    }
3812
3813end:
3814  vam->retval = retval;
3815  vam->result_ready = 1;
3816}
3817
3818static void
3819  vl_api_one_l2_arp_bd_get_reply_t_handler_json
3820  (vl_api_one_l2_arp_bd_get_reply_t * mp)
3821{
3822  vat_main_t *vam = &vat_main;
3823  vat_json_node_t root;
3824  u32 i, n;
3825  int retval = clib_net_to_host_u32 (mp->retval);
3826
3827  if (retval)
3828    goto end;
3829
3830  n = clib_net_to_host_u32 (mp->count);
3831  vat_json_init_array (&root);
3832
3833  for (i = 0; i < n; i++)
3834    {
3835      vat_json_array_add_uint (&root,
3836			       clib_net_to_host_u32 (mp->bridge_domains[i]));
3837    }
3838
3839  vat_json_print (vam->ofp, &root);
3840  vat_json_free (&root);
3841
3842end:
3843  vam->retval = retval;
3844  vam->result_ready = 1;
3845}
3846
3847static void
3848  vl_api_one_adjacencies_get_reply_t_handler
3849  (vl_api_one_adjacencies_get_reply_t * mp)
3850{
3851  vat_main_t *vam = &vat_main;
3852  u32 i, n;
3853  int retval = clib_net_to_host_u32 (mp->retval);
3854  vl_api_one_adjacency_t *a;
3855
3856  if (retval)
3857    goto end;
3858
3859  n = clib_net_to_host_u32 (mp->count);
3860
3861  for (i = 0; i < n; i++)
3862    {
3863      a = &mp->adjacencies[i];
3864      print (vam->ofp, "%U %40U",
3865	     format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
3866	     format_lisp_flat_eid, a->eid_type, a->reid, a->reid_prefix_len);
3867    }
3868
3869end:
3870  vam->retval = retval;
3871  vam->result_ready = 1;
3872}
3873
3874static void
3875  vl_api_one_adjacencies_get_reply_t_handler_json
3876  (vl_api_one_adjacencies_get_reply_t * mp)
3877{
3878  u8 *s = 0;
3879  vat_main_t *vam = &vat_main;
3880  vat_json_node_t *e = 0, root;
3881  u32 i, n;
3882  int retval = clib_net_to_host_u32 (mp->retval);
3883  vl_api_one_adjacency_t *a;
3884
3885  if (retval)
3886    goto end;
3887
3888  n = clib_net_to_host_u32 (mp->count);
3889  vat_json_init_array (&root);
3890
3891  for (i = 0; i < n; i++)
3892    {
3893      e = vat_json_array_add (&root);
3894      a = &mp->adjacencies[i];
3895
3896      vat_json_init_object (e);
3897      s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
3898		  a->leid_prefix_len);
3899      vec_add1 (s, 0);
3900      vat_json_object_add_string_copy (e, "leid", s);
3901      vec_free (s);
3902
3903      s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
3904		  a->reid_prefix_len);
3905      vec_add1 (s, 0);
3906      vat_json_object_add_string_copy (e, "reid", s);
3907      vec_free (s);
3908    }
3909
3910  vat_json_print (vam->ofp, &root);
3911  vat_json_free (&root);
3912
3913end:
3914  vam->retval = retval;
3915  vam->result_ready = 1;
3916}
3917
3918static void
3919vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
3920{
3921  vat_main_t *vam = &vat_main;
3922
3923  print (vam->ofp, "%=20U",
3924	 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
3925	 mp->ip_address);
3926}
3927
3928static void
3929  vl_api_one_map_server_details_t_handler_json
3930  (vl_api_one_map_server_details_t * mp)
3931{
3932  vat_main_t *vam = &vat_main;
3933  vat_json_node_t *node = NULL;
3934  struct in6_addr ip6;
3935  struct in_addr ip4;
3936
3937  if (VAT_JSON_ARRAY != vam->json_tree.type)
3938    {
3939      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3940      vat_json_init_array (&vam->json_tree);
3941    }
3942  node = vat_json_array_add (&vam->json_tree);
3943
3944  vat_json_init_object (node);
3945  if (mp->is_ipv6)
3946    {
3947      clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
3948      vat_json_object_add_ip6 (node, "map-server", ip6);
3949    }
3950  else
3951    {
3952      clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
3953      vat_json_object_add_ip4 (node, "map-server", ip4);
3954    }
3955}
3956
3957static void
3958vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
3959					   * mp)
3960{
3961  vat_main_t *vam = &vat_main;
3962
3963  print (vam->ofp, "%=20U",
3964	 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
3965	 mp->ip_address);
3966}
3967
3968static void
3969  vl_api_one_map_resolver_details_t_handler_json
3970  (vl_api_one_map_resolver_details_t * mp)
3971{
3972  vat_main_t *vam = &vat_main;
3973  vat_json_node_t *node = NULL;
3974  struct in6_addr ip6;
3975  struct in_addr ip4;
3976
3977  if (VAT_JSON_ARRAY != vam->json_tree.type)
3978    {
3979      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3980      vat_json_init_array (&vam->json_tree);
3981    }
3982  node = vat_json_array_add (&vam->json_tree);
3983
3984  vat_json_init_object (node);
3985  if (mp->is_ipv6)
3986    {
3987      clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
3988      vat_json_object_add_ip6 (node, "map resolver", ip6);
3989    }
3990  else
3991    {
3992      clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
3993      vat_json_object_add_ip4 (node, "map resolver", ip4);
3994    }
3995}
3996
3997static void
3998vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
3999{
4000  vat_main_t *vam = &vat_main;
4001  i32 retval = ntohl (mp->retval);
4002
4003  if (0 <= retval)
4004    {
4005      print (vam->ofp, "feature: %s\ngpe: %s",
4006	     mp->feature_status ? "enabled" : "disabled",
4007	     mp->gpe_status ? "enabled" : "disabled");
4008    }
4009
4010  vam->retval = retval;
4011  vam->result_ready = 1;
4012}
4013
4014static void
4015  vl_api_show_one_status_reply_t_handler_json
4016  (vl_api_show_one_status_reply_t * mp)
4017{
4018  vat_main_t *vam = &vat_main;
4019  vat_json_node_t node;
4020  u8 *gpe_status = NULL;
4021  u8 *feature_status = NULL;
4022
4023  gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4024  feature_status = format (0, "%s",
4025			   mp->feature_status ? "enabled" : "disabled");
4026  vec_add1 (gpe_status, 0);
4027  vec_add1 (feature_status, 0);
4028
4029  vat_json_init_object (&node);
4030  vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4031  vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4032
4033  vec_free (gpe_status);
4034  vec_free (feature_status);
4035
4036  vat_json_print (vam->ofp, &node);
4037  vat_json_free (&node);
4038
4039  vam->retval = ntohl (mp->retval);
4040  vam->result_ready = 1;
4041}
4042
4043static void
4044  vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4045  (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
4046{
4047  vat_main_t *vam = &vat_main;
4048  i32 retval = ntohl (mp->retval);
4049
4050  if (retval >= 0)
4051    {
4052      print (vam->ofp, "%=20s", mp->locator_set_name);
4053    }
4054
4055  vam->retval = retval;
4056  vam->result_ready = 1;
4057}
4058
4059static void
4060  vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4061  (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
4062{
4063  vat_main_t *vam = &vat_main;
4064  vat_json_node_t *node = NULL;
4065
4066  if (VAT_JSON_ARRAY != vam->json_tree.type)
4067    {
4068      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4069      vat_json_init_array (&vam->json_tree);
4070    }
4071  node = vat_json_array_add (&vam->json_tree);
4072
4073  vat_json_init_object (node);
4074  vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4075
4076  vat_json_print (vam->ofp, node);
4077  vat_json_free (node);
4078
4079  vam->retval = ntohl (mp->retval);
4080  vam->result_ready = 1;
4081}
4082
4083static u8 *
4084format_lisp_map_request_mode (u8 * s, va_list * args)
4085{
4086  u32 mode = va_arg (*args, u32);
4087
4088  switch (mode)
4089    {
4090    case 0:
4091      return format (0, "dst-only");
4092    case 1:
4093      return format (0, "src-dst");
4094    }
4095  return 0;
4096}
4097
4098static void
4099  vl_api_show_one_map_request_mode_reply_t_handler
4100  (vl_api_show_one_map_request_mode_reply_t * mp)
4101{
4102  vat_main_t *vam = &vat_main;
4103  i32 retval = ntohl (mp->retval);
4104
4105  if (0 <= retval)
4106    {
4107      u32 mode = mp->mode;
4108      print (vam->ofp, "map_request_mode: %U",
4109	     format_lisp_map_request_mode, mode);
4110    }
4111
4112  vam->retval = retval;
4113  vam->result_ready = 1;
4114}
4115
4116static void
4117  vl_api_show_one_map_request_mode_reply_t_handler_json
4118  (vl_api_show_one_map_request_mode_reply_t * mp)
4119{
4120  vat_main_t *vam = &vat_main;
4121  vat_json_node_t node;
4122  u8 *s = 0;
4123  u32 mode;
4124
4125  mode = mp->mode;
4126  s = format (0, "%U", format_lisp_map_request_mode, mode);
4127  vec_add1 (s, 0);
4128
4129  vat_json_init_object (&node);
4130  vat_json_object_add_string_copy (&node, "map_request_mode", s);
4131  vat_json_print (vam->ofp, &node);
4132  vat_json_free (&node);
4133
4134  vec_free (s);
4135  vam->retval = ntohl (mp->retval);
4136  vam->result_ready = 1;
4137}
4138
4139static void
4140  vl_api_one_show_xtr_mode_reply_t_handler
4141  (vl_api_one_show_xtr_mode_reply_t * mp)
4142{
4143  vat_main_t *vam = &vat_main;
4144  i32 retval = ntohl (mp->retval);
4145
4146  if (0 <= retval)
4147    {
4148      print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4149    }
4150
4151  vam->retval = retval;
4152  vam->result_ready = 1;
4153}
4154
4155static void
4156  vl_api_one_show_xtr_mode_reply_t_handler_json
4157  (vl_api_one_show_xtr_mode_reply_t * mp)
4158{
4159  vat_main_t *vam = &vat_main;
4160  vat_json_node_t node;
4161  u8 *status = 0;
4162
4163  status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4164  vec_add1 (status, 0);
4165
4166  vat_json_init_object (&node);
4167  vat_json_object_add_string_copy (&node, "status", status);
4168
4169  vec_free (status);
4170
4171  vat_json_print (vam->ofp, &node);
4172  vat_json_free (&node);
4173
4174  vam->retval = ntohl (mp->retval);
4175  vam->result_ready = 1;
4176}
4177
4178static void
4179  vl_api_one_show_pitr_mode_reply_t_handler
4180  (vl_api_one_show_pitr_mode_reply_t * mp)
4181{
4182  vat_main_t *vam = &vat_main;
4183  i32 retval = ntohl (mp->retval);
4184
4185  if (0 <= retval)
4186    {
4187      print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4188    }
4189
4190  vam->retval = retval;
4191  vam->result_ready = 1;
4192}
4193
4194static void
4195  vl_api_one_show_pitr_mode_reply_t_handler_json
4196  (vl_api_one_show_pitr_mode_reply_t * mp)
4197{
4198  vat_main_t *vam = &vat_main;
4199  vat_json_node_t node;
4200  u8 *status = 0;
4201
4202  status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4203  vec_add1 (status, 0);
4204
4205  vat_json_init_object (&node);
4206  vat_json_object_add_string_copy (&node, "status", status);
4207
4208  vec_free (status);
4209
4210  vat_json_print (vam->ofp, &node);
4211  vat_json_free (&node);
4212
4213  vam->retval = ntohl (mp->retval);
4214  vam->result_ready = 1;
4215}
4216
4217static void
4218  vl_api_one_show_petr_mode_reply_t_handler
4219  (vl_api_one_show_petr_mode_reply_t * mp)
4220{
4221  vat_main_t *vam = &vat_main;
4222  i32 retval = ntohl (mp->retval);
4223
4224  if (0 <= retval)
4225    {
4226      print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4227    }
4228
4229  vam->retval = retval;
4230  vam->result_ready = 1;
4231}
4232
4233static void
4234  vl_api_one_show_petr_mode_reply_t_handler_json
4235  (vl_api_one_show_petr_mode_reply_t * mp)
4236{
4237  vat_main_t *vam = &vat_main;
4238  vat_json_node_t node;
4239  u8 *status = 0;
4240
4241  status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4242  vec_add1 (status, 0);
4243
4244  vat_json_init_object (&node);
4245  vat_json_object_add_string_copy (&node, "status", status);
4246
4247  vec_free (status);
4248
4249  vat_json_print (vam->ofp, &node);
4250  vat_json_free (&node);
4251
4252  vam->retval = ntohl (mp->retval);
4253  vam->result_ready = 1;
4254}
4255
4256static void
4257  vl_api_show_one_use_petr_reply_t_handler
4258  (vl_api_show_one_use_petr_reply_t * mp)
4259{
4260  vat_main_t *vam = &vat_main;
4261  i32 retval = ntohl (mp->retval);
4262
4263  if (0 <= retval)
4264    {
4265      print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4266      if (mp->status)
4267	{
4268	  print (vam->ofp, "Proxy-ETR address; %U",
4269		 mp->is_ip4 ? format_ip4_address : format_ip6_address,
4270		 mp->address);
4271	}
4272    }
4273
4274  vam->retval = retval;
4275  vam->result_ready = 1;
4276}
4277
4278static void
4279  vl_api_show_one_use_petr_reply_t_handler_json
4280  (vl_api_show_one_use_petr_reply_t * mp)
4281{
4282  vat_main_t *vam = &vat_main;
4283  vat_json_node_t node;
4284  u8 *status = 0;
4285  struct in_addr ip4;
4286  struct in6_addr ip6;
4287
4288  status = format (0, "%s", mp->status ? "enabled" : "disabled");
4289  vec_add1 (status, 0);
4290
4291  vat_json_init_object (&node);
4292  vat_json_object_add_string_copy (&node, "status", status);
4293  if (mp->status)
4294    {
4295      if (mp->is_ip4)
4296	{
4297	  clib_memcpy (&ip6, mp->address, sizeof (ip6));
4298	  vat_json_object_add_ip6 (&node, "address", ip6);
4299	}
4300      else
4301	{
4302	  clib_memcpy (&ip4, mp->address, sizeof (ip4));
4303	  vat_json_object_add_ip4 (&node, "address", ip4);
4304	}
4305    }
4306
4307  vec_free (status);
4308
4309  vat_json_print (vam->ofp, &node);
4310  vat_json_free (&node);
4311
4312  vam->retval = ntohl (mp->retval);
4313  vam->result_ready = 1;
4314}
4315
4316static void
4317  vl_api_show_one_nsh_mapping_reply_t_handler
4318  (vl_api_show_one_nsh_mapping_reply_t * mp)
4319{
4320  vat_main_t *vam = &vat_main;
4321  i32 retval = ntohl (mp->retval);
4322
4323  if (0 <= retval)
4324    {
4325      print (vam->ofp, "%-20s%-16s",
4326	     mp->is_set ? "set" : "not-set",
4327	     mp->is_set ? (char *) mp->locator_set_name : "");
4328    }
4329
4330  vam->retval = retval;
4331  vam->result_ready = 1;
4332}
4333
4334static void
4335  vl_api_show_one_nsh_mapping_reply_t_handler_json
4336  (vl_api_show_one_nsh_mapping_reply_t * mp)
4337{
4338  vat_main_t *vam = &vat_main;
4339  vat_json_node_t node;
4340  u8 *status = 0;
4341
4342  status = format (0, "%s", mp->is_set ? "yes" : "no");
4343  vec_add1 (status, 0);
4344
4345  vat_json_init_object (&node);
4346  vat_json_object_add_string_copy (&node, "is_set", status);
4347  if (mp->is_set)
4348    {
4349      vat_json_object_add_string_copy (&node, "locator_set",
4350				       mp->locator_set_name);
4351    }
4352
4353  vec_free (status);
4354
4355  vat_json_print (vam->ofp, &node);
4356  vat_json_free (&node);
4357
4358  vam->retval = ntohl (mp->retval);
4359  vam->result_ready = 1;
4360}
4361
4362static void
4363  vl_api_show_one_map_register_ttl_reply_t_handler
4364  (vl_api_show_one_map_register_ttl_reply_t * mp)
4365{
4366  vat_main_t *vam = &vat_main;
4367  i32 retval = ntohl (mp->retval);
4368
4369  vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4370
4371  if (0 <= retval)
4372    {
4373      print (vam->ofp, "ttl: %u", mp->ttl);
4374    }
4375
4376  vam->retval = retval;
4377  vam->result_ready = 1;
4378}
4379
4380static void
4381  vl_api_show_one_map_register_ttl_reply_t_handler_json
4382  (vl_api_show_one_map_register_ttl_reply_t * mp)
4383{
4384  vat_main_t *vam = &vat_main;
4385  vat_json_node_t node;
4386
4387  vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4388  vat_json_init_object (&node);
4389  vat_json_object_add_uint (&node, "ttl", mp->ttl);
4390
4391  vat_json_print (vam->ofp, &node);
4392  vat_json_free (&node);
4393
4394  vam->retval = ntohl (mp->retval);
4395  vam->result_ready = 1;
4396}
4397
4398static void
4399vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
4400{
4401  vat_main_t *vam = &vat_main;
4402  i32 retval = ntohl (mp->retval);
4403
4404  if (0 <= retval)
4405    {
4406      print (vam->ofp, "%-20s%-16s",
4407	     mp->status ? "enabled" : "disabled",
4408	     mp->status ? (char *) mp->locator_set_name : "");
4409    }
4410
4411  vam->retval = retval;
4412  vam->result_ready = 1;
4413}
4414
4415static void
4416vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
4417{
4418  vat_main_t *vam = &vat_main;
4419  vat_json_node_t node;
4420  u8 *status = 0;
4421
4422  status = format (0, "%s", mp->status ? "enabled" : "disabled");
4423  vec_add1 (status, 0);
4424
4425  vat_json_init_object (&node);
4426  vat_json_object_add_string_copy (&node, "status", status);
4427  if (mp->status)
4428    {
4429      vat_json_object_add_string_copy (&node, "locator_set",
4430				       mp->locator_set_name);
4431    }
4432
4433  vec_free (status);
4434
4435  vat_json_print (vam->ofp, &node);
4436  vat_json_free (&node);
4437
4438  vam->retval = ntohl (mp->retval);
4439  vam->result_ready = 1;
4440}
4441
4442static u8 *
4443format_policer_type (u8 * s, va_list * va)
4444{
4445  u32 i = va_arg (*va, u32);
4446
4447  if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4448    s = format (s, "1r2c");
4449  else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4450    s = format (s, "1r3c");
4451  else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4452    s = format (s, "2r3c-2698");
4453  else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4454    s = format (s, "2r3c-4115");
4455  else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4456    s = format (s, "2r3c-mef5cf1");
4457  else
4458    s = format (s, "ILLEGAL");
4459  return s;
4460}
4461
4462static u8 *
4463format_policer_rate_type (u8 * s, va_list * va)
4464{
4465  u32 i = va_arg (*va, u32);
4466
4467  if (i == SSE2_QOS_RATE_KBPS)
4468    s = format (s, "kbps");
4469  else if (i == SSE2_QOS_RATE_PPS)
4470    s = format (s, "pps");
4471  else
4472    s = format (s, "ILLEGAL");
4473  return s;
4474}
4475
4476static u8 *
4477format_policer_round_type (u8 * s, va_list * va)
4478{
4479  u32 i = va_arg (*va, u32);
4480
4481  if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4482    s = format (s, "closest");
4483  else if (i == SSE2_QOS_ROUND_TO_UP)
4484    s = format (s, "up");
4485  else if (i == SSE2_QOS_ROUND_TO_DOWN)
4486    s = format (s, "down");
4487  else
4488    s = format (s, "ILLEGAL");
4489  return s;
4490}
4491
4492static u8 *
4493format_policer_action_type (u8 * s, va_list * va)
4494{
4495  u32 i = va_arg (*va, u32);
4496
4497  if (i == SSE2_QOS_ACTION_DROP)
4498    s = format (s, "drop");
4499  else if (i == SSE2_QOS_ACTION_TRANSMIT)
4500    s = format (s, "transmit");
4501  else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4502    s = format (s, "mark-and-transmit");
4503  else
4504    s = format (s, "ILLEGAL");
4505  return s;
4506}
4507
4508static u8 *
4509format_dscp (u8 * s, va_list * va)
4510{
4511  u32 i = va_arg (*va, u32);
4512  char *t = 0;
4513
4514  switch (i)
4515    {
4516#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4517      foreach_vnet_dscp
4518#undef _
4519    default:
4520      return format (s, "ILLEGAL");
4521    }
4522  s = format (s, "%s", t);
4523  return s;
4524}
4525
4526static void
4527vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4528{
4529  vat_main_t *vam = &vat_main;
4530  u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4531
4532  if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4533    conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4534  else
4535    conform_dscp_str = format (0, "");
4536
4537  if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4538    exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4539  else
4540    exceed_dscp_str = format (0, "");
4541
4542  if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4543    violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4544  else
4545    violate_dscp_str = format (0, "");
4546
4547  print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4548	 "rate type %U, round type %U, %s rate, %s color-aware, "
4549	 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4550	 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4551	 "conform action %U%s, exceed action %U%s, violate action %U%s",
4552	 mp->name,
4553	 format_policer_type, mp->type,
4554	 ntohl (mp->cir),
4555	 ntohl (mp->eir),
4556	 clib_net_to_host_u64 (mp->cb),
4557	 clib_net_to_host_u64 (mp->eb),
4558	 format_policer_rate_type, mp->rate_type,
4559	 format_policer_round_type, mp->round_type,
4560	 mp->single_rate ? "single" : "dual",
4561	 mp->color_aware ? "is" : "not",
4562	 ntohl (mp->cir_tokens_per_period),
4563	 ntohl (mp->pir_tokens_per_period),
4564	 ntohl (mp->scale),
4565	 ntohl (mp->current_limit),
4566	 ntohl (mp->current_bucket),
4567	 ntohl (mp->extended_limit),
4568	 ntohl (mp->extended_bucket),
4569	 clib_net_to_host_u64 (mp->last_update_time),
4570	 format_policer_action_type, mp->conform_action_type,
4571	 conform_dscp_str,
4572	 format_policer_action_type, mp->exceed_action_type,
4573	 exceed_dscp_str,
4574	 format_policer_action_type, mp->violate_action_type,
4575	 violate_dscp_str);
4576
4577  vec_free (conform_dscp_str);
4578  vec_free (exceed_dscp_str);
4579  vec_free (violate_dscp_str);
4580}
4581
4582static void vl_api_policer_details_t_handler_json
4583  (vl_api_policer_details_t * mp)
4584{
4585  vat_main_t *vam = &vat_main;
4586  vat_json_node_t *node;
4587  u8 *rate_type_str, *round_type_str, *type_str;
4588  u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4589
4590  rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4591  round_type_str =
4592    format (0, "%U", format_policer_round_type, mp->round_type);
4593  type_str = format (0, "%U", format_policer_type, mp->type);
4594  conform_action_str = format (0, "%U", format_policer_action_type,
4595			       mp->conform_action_type);
4596  exceed_action_str = format (0, "%U", format_policer_action_type,
4597			      mp->exceed_action_type);
4598  violate_action_str = format (0, "%U", format_policer_action_type,
4599			       mp->violate_action_type);
4600
4601  if (VAT_JSON_ARRAY != vam->json_tree.type)
4602    {
4603      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4604      vat_json_init_array (&vam->json_tree);
4605    }
4606  node = vat_json_array_add (&vam->json_tree);
4607
4608  vat_json_init_object (node);
4609  vat_json_object_add_string_copy (node, "name", mp->name);
4610  vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4611  vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
4612  vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4613  vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
4614  vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4615  vat_json_object_add_string_copy (node, "round_type", round_type_str);
4616  vat_json_object_add_string_copy (node, "type", type_str);
4617  vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4618  vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4619  vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4620  vat_json_object_add_uint (node, "cir_tokens_per_period",
4621			    ntohl (mp->cir_tokens_per_period));
4622  vat_json_object_add_uint (node, "eir_tokens_per_period",
4623			    ntohl (mp->pir_tokens_per_period));
4624  vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4625  vat_json_object_add_uint (node, "current_bucket",
4626			    ntohl (mp->current_bucket));
4627  vat_json_object_add_uint (node, "extended_limit",
4628			    ntohl (mp->extended_limit));
4629  vat_json_object_add_uint (node, "extended_bucket",
4630			    ntohl (mp->extended_bucket));
4631  vat_json_object_add_uint (node, "last_update_time",
4632			    ntohl (mp->last_update_time));
4633  vat_json_object_add_string_copy (node, "conform_action",
4634				   conform_action_str);
4635  if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4636    {
4637      u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4638      vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4639      vec_free (dscp_str);
4640    }
4641  vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
4642  if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4643    {
4644      u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4645      vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4646      vec_free (dscp_str);
4647    }
4648  vat_json_object_add_string_copy (node, "violate_action",
4649				   violate_action_str);
4650  if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4651    {
4652      u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4653      vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4654      vec_free (dscp_str);
4655    }
4656
4657  vec_free (rate_type_str);
4658  vec_free (round_type_str);
4659  vec_free (type_str);
4660  vec_free (conform_action_str);
4661  vec_free (exceed_action_str);
4662  vec_free (violate_action_str);
4663}
4664
4665static void
4666vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4667					   mp)
4668{
4669  vat_main_t *vam = &vat_main;
4670  int i, count = ntohl (mp->count);
4671
4672  if (count > 0)
4673    print (vam->ofp, "classify table ids (%d) : ", count);
4674  for (i = 0; i < count; i++)
4675    {
4676      print (vam->ofp, "%d", ntohl (mp->ids[i]));
4677      print (vam->ofp, (i < count - 1) ? "," : "");
4678    }
4679  vam->retval = ntohl (mp->retval);
4680  vam->result_ready = 1;
4681}
4682
4683static void
4684  vl_api_classify_table_ids_reply_t_handler_json
4685  (vl_api_classify_table_ids_reply_t * mp)
4686{
4687  vat_main_t *vam = &vat_main;
4688  int i, count = ntohl (mp->count);
4689
4690  if (count > 0)
4691    {
4692      vat_json_node_t node;
4693
4694      vat_json_init_object (&node);
4695      for (i = 0; i < count; i++)
4696	{
4697	  vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4698	}
4699      vat_json_print (vam->ofp, &node);
4700      vat_json_free (&node);
4701    }
4702  vam->retval = ntohl (mp->retval);
4703  vam->result_ready = 1;
4704}
4705
4706static void
4707  vl_api_classify_table_by_interface_reply_t_handler
4708  (vl_api_classify_table_by_interface_reply_t * mp)
4709{
4710  vat_main_t *vam = &vat_main;
4711  u32 table_id;
4712
4713  table_id = ntohl (mp->l2_table_id);
4714  if (table_id != ~0)
4715    print (vam->ofp, "l2 table id : %d", table_id);
4716  else
4717    print (vam->ofp, "l2 table id : No input ACL tables configured");
4718  table_id = ntohl (mp->ip4_table_id);
4719  if (table_id != ~0)
4720    print (vam->ofp, "ip4 table id : %d", table_id);
4721  else
4722    print (vam->ofp, "ip4 table id : No input ACL tables configured");
4723  table_id = ntohl (mp->ip6_table_id);
4724  if (table_id != ~0)
4725    print (vam->ofp, "ip6 table id : %d", table_id);
4726  else
4727    print (vam->ofp, "ip6 table id : No input ACL tables configured");
4728  vam->retval = ntohl (mp->retval);
4729  vam->result_ready = 1;
4730}
4731
4732static void
4733  vl_api_classify_table_by_interface_reply_t_handler_json
4734  (vl_api_classify_table_by_interface_reply_t * mp)
4735{
4736  vat_main_t *vam = &vat_main;
4737  vat_json_node_t node;
4738
4739  vat_json_init_object (&node);
4740
4741  vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4742  vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4743  vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4744
4745  vat_json_print (vam->ofp, &node);
4746  vat_json_free (&node);
4747
4748  vam->retval = ntohl (mp->retval);
4749  vam->result_ready = 1;
4750}
4751
4752static void vl_api_policer_add_del_reply_t_handler
4753  (vl_api_policer_add_del_reply_t * mp)
4754{
4755  vat_main_t *vam = &vat_main;
4756  i32 retval = ntohl (mp->retval);
4757  if (vam->async_mode)
4758    {
4759      vam->async_errors += (retval < 0);
4760    }
4761  else
4762    {
4763      vam->retval = retval;
4764      vam->result_ready = 1;
4765      if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4766	/*
4767	 * Note: this is just barely thread-safe, depends on
4768	 * the main thread spinning waiting for an answer...
4769	 */
4770	errmsg ("policer index %d", ntohl (mp->policer_index));
4771    }
4772}
4773
4774static void vl_api_policer_add_del_reply_t_handler_json
4775  (vl_api_policer_add_del_reply_t * mp)
4776{
4777  vat_main_t *vam = &vat_main;
4778  vat_json_node_t node;
4779
4780  vat_json_init_object (&node);
4781  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4782  vat_json_object_add_uint (&node, "policer_index",
4783			    ntohl (mp->policer_index));
4784
4785  vat_json_print (vam->ofp, &node);
4786  vat_json_free (&node);
4787
4788  vam->retval = ntohl (mp->retval);
4789  vam->result_ready = 1;
4790}
4791
4792/* Format hex dump. */
4793u8 *
4794format_hex_bytes (u8 * s, va_list * va)
4795{
4796  u8 *bytes = va_arg (*va, u8 *);
4797  int n_bytes = va_arg (*va, int);
4798  uword i;
4799
4800  /* Print short or long form depending on byte count. */
4801  uword short_form = n_bytes <= 32;
4802  u32 indent = format_get_indent (s);
4803
4804  if (n_bytes == 0)
4805    return s;
4806
4807  for (i = 0; i < n_bytes; i++)
4808    {
4809      if (!short_form && (i % 32) == 0)
4810	s = format (s, "%08x: ", i);
4811      s = format (s, "%02x", bytes[i]);
4812      if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4813	s = format (s, "\n%U", format_white_space, indent);
4814    }
4815
4816  return s;
4817}
4818
4819static void
4820vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4821					    * mp)
4822{
4823  vat_main_t *vam = &vat_main;
4824  i32 retval = ntohl (mp->retval);
4825  if (retval == 0)
4826    {
4827      print (vam->ofp, "classify table info :");
4828      print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4829	     ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4830	     ntohl (mp->miss_next_index));
4831      print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4832	     ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4833	     ntohl (mp->match_n_vectors));
4834      print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4835	     ntohl (mp->mask_length));
4836    }
4837  vam->retval = retval;
4838  vam->result_ready = 1;
4839}
4840
4841static void
4842  vl_api_classify_table_info_reply_t_handler_json
4843  (vl_api_classify_table_info_reply_t * mp)
4844{
4845  vat_main_t *vam = &vat_main;
4846  vat_json_node_t node;
4847
4848  i32 retval = ntohl (mp->retval);
4849  if (retval == 0)
4850    {
4851      vat_json_init_object (&node);
4852
4853      vat_json_object_add_int (&node, "sessions",
4854			       ntohl (mp->active_sessions));
4855      vat_json_object_add_int (&node, "nexttbl",
4856			       ntohl (mp->next_table_index));
4857      vat_json_object_add_int (&node, "nextnode",
4858			       ntohl (mp->miss_next_index));
4859      vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4860      vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4861      vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4862      u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4863		      ntohl (mp->mask_length), 0);
4864      vat_json_object_add_string_copy (&node, "mask", s);
4865
4866      vat_json_print (vam->ofp, &node);
4867      vat_json_free (&node);
4868    }
4869  vam->retval = ntohl (mp->retval);
4870  vam->result_ready = 1;
4871}
4872
4873static void
4874vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4875					   mp)
4876{
4877  vat_main_t *vam = &vat_main;
4878
4879  print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4880	 ntohl (mp->hit_next_index), ntohl (mp->advance),
4881	 ntohl (mp->opaque_index));
4882  print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
4883	 ntohl (mp->match_length));
4884}
4885
4886static void
4887  vl_api_classify_session_details_t_handler_json
4888  (vl_api_classify_session_details_t * mp)
4889{
4890  vat_main_t *vam = &vat_main;
4891  vat_json_node_t *node = NULL;
4892
4893  if (VAT_JSON_ARRAY != vam->json_tree.type)
4894    {
4895      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4896      vat_json_init_array (&vam->json_tree);
4897    }
4898  node = vat_json_array_add (&vam->json_tree);
4899
4900  vat_json_init_object (node);
4901  vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
4902  vat_json_object_add_int (node, "advance", ntohl (mp->advance));
4903  vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
4904  u8 *s =
4905    format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
4906	    0);
4907  vat_json_object_add_string_copy (node, "match", s);
4908}
4909
4910static void vl_api_pg_create_interface_reply_t_handler
4911  (vl_api_pg_create_interface_reply_t * mp)
4912{
4913  vat_main_t *vam = &vat_main;
4914
4915  vam->retval = ntohl (mp->retval);
4916  vam->result_ready = 1;
4917}
4918
4919static void vl_api_pg_create_interface_reply_t_handler_json
4920  (vl_api_pg_create_interface_reply_t * mp)
4921{
4922  vat_main_t *vam = &vat_main;
4923  vat_json_node_t node;
4924
4925  i32 retval = ntohl (mp->retval);
4926  if (retval == 0)
4927    {
4928      vat_json_init_object (&node);
4929
4930      vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
4931
4932      vat_json_print (vam->ofp, &node);
4933      vat_json_free (&node);
4934    }
4935  vam->retval = ntohl (mp->retval);
4936  vam->result_ready = 1;
4937}
4938
4939static void vl_api_policer_classify_details_t_handler
4940  (vl_api_policer_classify_details_t * mp)
4941{
4942  vat_main_t *vam = &vat_main;
4943
4944  print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
4945	 ntohl (mp->table_index));
4946}
4947
4948static void vl_api_policer_classify_details_t_handler_json
4949  (vl_api_policer_classify_details_t * mp)
4950{
4951  vat_main_t *vam = &vat_main;
4952  vat_json_node_t *node;
4953
4954  if (VAT_JSON_ARRAY != vam->json_tree.type)
4955    {
4956      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4957      vat_json_init_array (&vam->json_tree);
4958    }
4959  node = vat_json_array_add (&vam->json_tree);
4960
4961  vat_json_init_object (node);
4962  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4963  vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
4964}
4965
4966static void vl_api_flow_classify_details_t_handler
4967  (vl_api_flow_classify_details_t * mp)
4968{
4969  vat_main_t *vam = &vat_main;
4970
4971  print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
4972	 ntohl (mp->table_index));
4973}
4974
4975static void vl_api_flow_classify_details_t_handler_json
4976  (vl_api_flow_classify_details_t * mp)
4977{
4978  vat_main_t *vam = &vat_main;
4979  vat_json_node_t *node;
4980
4981  if (VAT_JSON_ARRAY != vam->json_tree.type)
4982    {
4983      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4984      vat_json_init_array (&vam->json_tree);
4985    }
4986  node = vat_json_array_add (&vam->json_tree);
4987
4988  vat_json_init_object (node);
4989  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4990  vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
4991}
4992
4993#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
4994#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
4995#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
4996#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
4997#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
4998#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
4999#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5000#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5001#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5002#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
5003
5004/*
5005 * Generate boilerplate reply handlers, which
5006 * dig the return value out of the xxx_reply_t API message,
5007 * stick it into vam->retval, and set vam->result_ready
5008 *
5009 * Could also do this by pointing N message decode slots at
5010 * a single function, but that could break in subtle ways.
5011 */
5012
5013#define foreach_standard_reply_retval_handler           \
5014_(sw_interface_set_flags_reply)                         \
5015_(sw_interface_add_del_address_reply)                   \
5016_(sw_interface_set_rx_mode_reply)                       \
5017_(sw_interface_set_rx_placement_reply)                  \
5018_(sw_interface_set_table_reply)                         \
5019_(sw_interface_set_mpls_enable_reply)                   \
5020_(sw_interface_set_vpath_reply)                         \
5021_(sw_interface_set_vxlan_bypass_reply)                  \
5022_(sw_interface_set_geneve_bypass_reply)                 \
5023_(sw_interface_set_vxlan_gpe_bypass_reply)              \
5024_(sw_interface_set_l2_bridge_reply)                     \
5025_(sw_interface_set_bond_weight_reply)                   \
5026_(bridge_domain_add_del_reply)                          \
5027_(sw_interface_set_l2_xconnect_reply)                   \
5028_(l2fib_add_del_reply)                                  \
5029_(l2fib_flush_int_reply)                                \
5030_(l2fib_flush_bd_reply)                                 \
5031_(ip_route_add_del_reply)                               \
5032_(ip_table_add_del_reply)                               \
5033_(ip_table_replace_begin_reply)                         \
5034_(ip_table_flush_reply)                                 \
5035_(ip_table_replace_end_reply)                           \
5036_(ip_mroute_add_del_reply)                              \
5037_(mpls_route_add_del_reply)                             \
5038_(mpls_table_add_del_reply)                             \
5039_(mpls_ip_bind_unbind_reply)                            \
5040_(bier_route_add_del_reply)                             \
5041_(bier_table_add_del_reply)                             \
5042_(sw_interface_set_unnumbered_reply)                    \
5043_(set_ip_flow_hash_reply)                               \
5044_(sw_interface_ip6_enable_disable_reply)                \
5045_(l2_patch_add_del_reply)                               \
5046_(sr_mpls_policy_add_reply)                             \
5047_(sr_mpls_policy_mod_reply)                             \
5048_(sr_mpls_policy_del_reply)                             \
5049_(sr_policy_add_reply)                                  \
5050_(sr_policy_mod_reply)                                  \
5051_(sr_policy_del_reply)                                  \
5052_(sr_localsid_add_del_reply)                            \
5053_(sr_steering_add_del_reply)                            \
5054_(classify_add_del_session_reply)                       \
5055_(classify_set_interface_ip_table_reply)                \
5056_(classify_set_interface_l2_tables_reply)               \
5057_(l2tpv3_set_tunnel_cookies_reply)                      \
5058_(l2tpv3_interface_enable_disable_reply)                \
5059_(l2tpv3_set_lookup_key_reply)                          \
5060_(l2_fib_clear_table_reply)                             \
5061_(l2_interface_efp_filter_reply)                        \
5062_(l2_interface_vlan_tag_rewrite_reply)                  \
5063_(modify_vhost_user_if_reply)                           \
5064_(delete_vhost_user_if_reply)                           \
5065_(want_l2_macs_events_reply)                            \
5066_(input_acl_set_interface_reply)                        \
5067_(ipsec_spd_add_del_reply)                              \
5068_(ipsec_interface_add_del_spd_reply)                    \
5069_(ipsec_spd_entry_add_del_reply)                        \
5070_(ipsec_sad_entry_add_del_reply)                        \
5071_(ipsec_tunnel_if_add_del_reply)                        \
5072_(ipsec_tunnel_if_set_sa_reply)                         \
5073_(delete_loopback_reply)                                \
5074_(bd_ip_mac_add_del_reply)                              \
5075_(bd_ip_mac_flush_reply)                                \
5076_(want_interface_events_reply)                          \
5077_(cop_interface_enable_disable_reply)			\
5078_(cop_whitelist_enable_disable_reply)                   \
5079_(sw_interface_clear_stats_reply)                       \
5080_(ioam_enable_reply)                                    \
5081_(ioam_disable_reply)                                   \
5082_(one_add_del_locator_reply)                            \
5083_(one_add_del_local_eid_reply)                          \
5084_(one_add_del_remote_mapping_reply)                     \
5085_(one_add_del_adjacency_reply)                          \
5086_(one_add_del_map_resolver_reply)                       \
5087_(one_add_del_map_server_reply)                         \
5088_(one_enable_disable_reply)                             \
5089_(one_rloc_probe_enable_disable_reply)                  \
5090_(one_map_register_enable_disable_reply)                \
5091_(one_map_register_set_ttl_reply)                       \
5092_(one_set_transport_protocol_reply)                     \
5093_(one_map_register_fallback_threshold_reply)            \
5094_(one_pitr_set_locator_set_reply)                       \
5095_(one_map_request_mode_reply)                           \
5096_(one_add_del_map_request_itr_rlocs_reply)              \
5097_(one_eid_table_add_del_map_reply)                      \
5098_(one_use_petr_reply)                                   \
5099_(one_stats_enable_disable_reply)                       \
5100_(one_add_del_l2_arp_entry_reply)                       \
5101_(one_add_del_ndp_entry_reply)                          \
5102_(one_stats_flush_reply)                                \
5103_(one_enable_disable_xtr_mode_reply)                    \
5104_(one_enable_disable_pitr_mode_reply)                   \
5105_(one_enable_disable_petr_mode_reply)                   \
5106_(gpe_enable_disable_reply)                             \
5107_(gpe_set_encap_mode_reply)                             \
5108_(gpe_add_del_iface_reply)                              \
5109_(gpe_add_del_native_fwd_rpath_reply)                   \
5110_(af_packet_delete_reply)                               \
5111_(policer_classify_set_interface_reply)                 \
5112_(netmap_create_reply)                                  \
5113_(netmap_delete_reply)                                  \
5114_(set_ipfix_exporter_reply)                             \
5115_(set_ipfix_classify_stream_reply)                      \
5116_(ipfix_classify_table_add_del_reply)                   \
5117_(flow_classify_set_interface_reply)                    \
5118_(sw_interface_span_enable_disable_reply)               \
5119_(pg_capture_reply)                                     \
5120_(pg_enable_disable_reply)                              \
5121_(ip_source_and_port_range_check_add_del_reply)         \
5122_(ip_source_and_port_range_check_interface_add_del_reply)\
5123_(delete_subif_reply)                                   \
5124_(l2_interface_pbb_tag_rewrite_reply)                   \
5125_(set_punt_reply)                                       \
5126_(feature_enable_disable_reply)				\
5127_(feature_gso_enable_disable_reply)	                \
5128_(sw_interface_tag_add_del_reply)			\
5129_(sw_interface_add_del_mac_address_reply)		\
5130_(hw_interface_set_mtu_reply)                           \
5131_(p2p_ethernet_add_reply)                               \
5132_(p2p_ethernet_del_reply)                               \
5133_(lldp_config_reply)                                    \
5134_(sw_interface_set_lldp_reply)				\
5135_(tcp_configure_src_addresses_reply)			\
5136_(session_rule_add_del_reply)				\
5137_(ip_container_proxy_add_del_reply)                     \
5138_(output_acl_set_interface_reply)                       \
5139_(qos_record_enable_disable_reply)
5140
5141#define _(n)                                    \
5142    static void vl_api_##n##_t_handler          \
5143    (vl_api_##n##_t * mp)                       \
5144    {                                           \
5145        vat_main_t * vam = &vat_main;           \
5146        i32 retval = ntohl(mp->retval);         \
5147        if (vam->async_mode) {                  \
5148            vam->async_errors += (retval < 0);  \
5149        } else {                                \
5150            vam->retval = retval;               \
5151            vam->result_ready = 1;              \
5152        }                                       \
5153    }
5154foreach_standard_reply_retval_handler;
5155#undef _
5156
5157#define _(n)                                    \
5158    static void vl_api_##n##_t_handler_json     \
5159    (vl_api_##n##_t * mp)                       \
5160    {                                           \
5161        vat_main_t * vam = &vat_main;           \
5162        vat_json_node_t node;                   \
5163        vat_json_init_object(&node);            \
5164        vat_json_object_add_int(&node, "retval", ntohl(mp->retval));    \
5165        vat_json_print(vam->ofp, &node);        \
5166        vam->retval = ntohl(mp->retval);        \
5167        vam->result_ready = 1;                  \
5168    }
5169foreach_standard_reply_retval_handler;
5170#undef _
5171
5172/*
5173 * Table of message reply handlers, must include boilerplate handlers
5174 * we just generated
5175 */
5176
5177#define foreach_vpe_api_reply_msg                                       \
5178_(CREATE_LOOPBACK_REPLY, create_loopback_reply)                         \
5179_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply)       \
5180_(SW_INTERFACE_DETAILS, sw_interface_details)                           \
5181_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply)           \
5182_(CONTROL_PING_REPLY, control_ping_reply)                               \
5183_(CLI_REPLY, cli_reply)                                                 \
5184_(CLI_INBAND_REPLY, cli_inband_reply)                                   \
5185_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY,                                   \
5186  sw_interface_add_del_address_reply)                                   \
5187_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply)       \
5188_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply)	\
5189_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details)	\
5190_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) 		\
5191_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5192_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) 		\
5193_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
5194_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
5195_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
5196_(SW_INTERFACE_SET_L2_XCONNECT_REPLY,                                   \
5197  sw_interface_set_l2_xconnect_reply)                                   \
5198_(SW_INTERFACE_SET_L2_BRIDGE_REPLY,                                     \
5199  sw_interface_set_l2_bridge_reply)                                     \
5200_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply)             \
5201_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details)                         \
5202_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply)     \
5203_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply)                             \
5204_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply)                         \
5205_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply)                           \
5206_(L2_FLAGS_REPLY, l2_flags_reply)                                       \
5207_(BRIDGE_FLAGS_REPLY, bridge_flags_reply)                               \
5208_(TAP_CREATE_V2_REPLY, tap_create_v2_reply)				\
5209_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply)				\
5210_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details)             \
5211_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply)			\
5212_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply)			\
5213_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details)     \
5214_(BOND_CREATE_REPLY, bond_create_reply)	   			        \
5215_(BOND_DELETE_REPLY, bond_delete_reply)			  	        \
5216_(BOND_ENSLAVE_REPLY, bond_enslave_reply)				\
5217_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply)			\
5218_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
5219_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details)                 \
5220_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details)               \
5221_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply)			\
5222_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply)			\
5223_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply)           \
5224_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply)                           \
5225_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply)               \
5226_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply)			\
5227_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply)			\
5228_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply)			\
5229_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply)			\
5230_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply)			\
5231_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply)			\
5232_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply)                 \
5233_(SW_INTERFACE_SET_UNNUMBERED_REPLY,                                    \
5234  sw_interface_set_unnumbered_reply)                                    \
5235_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply)                     \
5236_(CREATE_SUBIF_REPLY, create_subif_reply)                     		\
5237_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply)                       \
5238_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY,                                \
5239  sw_interface_ip6_enable_disable_reply)                                \
5240_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply)                       \
5241_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply)                   \
5242_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply)                   \
5243_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply)                   \
5244_(SR_POLICY_ADD_REPLY, sr_policy_add_reply)                             \
5245_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply)                             \
5246_(SR_POLICY_DEL_REPLY, sr_policy_del_reply)                             \
5247_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply)                 \
5248_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply)                 \
5249_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply)           \
5250_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply)       \
5251_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY,                                \
5252classify_set_interface_ip_table_reply)                                  \
5253_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY,                               \
5254  classify_set_interface_l2_tables_reply)                               \
5255_(GET_NODE_INDEX_REPLY, get_node_index_reply)                           \
5256_(ADD_NODE_NEXT_REPLY, add_node_next_reply)                             \
5257_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply)               \
5258_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply)     \
5259_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY,                                \
5260  l2tpv3_interface_enable_disable_reply)                                \
5261_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply)             \
5262_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details)             \
5263_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply)               \
5264_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply)               \
5265_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply)             \
5266_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details)                           \
5267_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details)                         \
5268_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply)                   \
5269_(GRE_TUNNEL_DETAILS, gre_tunnel_details)                               \
5270_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply)                   \
5271_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply)         \
5272_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5273_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details)     \
5274_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply)               \
5275_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply)               \
5276_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply)               \
5277_(SHOW_VERSION_REPLY, show_version_reply)                               \
5278_(SHOW_THREADS_REPLY, show_threads_reply)                               \
5279_(L2_FIB_TABLE_DETAILS, l2_fib_table_details)				\
5280_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply)	\
5281_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details)                   \
5282_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply)		\
5283_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply)			\
5284_(L2_MACS_EVENT, l2_macs_event)						\
5285_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply)         \
5286_(IP_ADDRESS_DETAILS, ip_address_details)                               \
5287_(IP_DETAILS, ip_details)                                               \
5288_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply)                     \
5289_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
5290_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply)         \
5291_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply)         \
5292_(IPSEC_SA_DETAILS, ipsec_sa_details)                                   \
5293_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply)         \
5294_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply)           \
5295_(DELETE_LOOPBACK_REPLY, delete_loopback_reply)                         \
5296_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply)                     \
5297_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply)                         \
5298_(BD_IP_MAC_DETAILS, bd_ip_mac_details)                                 \
5299_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply)             \
5300_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply)    			\
5301_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5302_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5303_(GET_NODE_GRAPH_REPLY, get_node_graph_reply)                           \
5304_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply)      \
5305_(IOAM_ENABLE_REPLY, ioam_enable_reply)                   \
5306_(IOAM_DISABLE_REPLY, ioam_disable_reply)                     \
5307_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply)         \
5308_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply)                 \
5309_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply)             \
5310_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply)   \
5311_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply)             \
5312_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply)       \
5313_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply)           \
5314_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply)                   \
5315_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY,                                \
5316  one_map_register_enable_disable_reply)                                \
5317_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply)       \
5318_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply)   \
5319_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply)   \
5320_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,                            \
5321  one_map_register_fallback_threshold_reply)                            \
5322_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY,                                  \
5323  one_rloc_probe_enable_disable_reply)                                  \
5324_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply)       \
5325_(ONE_USE_PETR_REPLY, one_use_petr_reply)                               \
5326_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply)               \
5327_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply)     \
5328_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details)                     \
5329_(ONE_LOCATOR_DETAILS, one_locator_details)                             \
5330_(ONE_EID_TABLE_DETAILS, one_eid_table_details)                         \
5331_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details)                 \
5332_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details)                 \
5333_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details)                   \
5334_(ONE_MAP_SERVER_DETAILS, one_map_server_details)                       \
5335_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply)                 \
5336_(ONE_STATS_DETAILS, one_stats_details)                                 \
5337_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply)                         \
5338_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply)       \
5339_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,                                  \
5340  show_one_stats_enable_disable_reply)                                  \
5341_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply)             \
5342_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply)                           \
5343_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply)                 \
5344_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply)       \
5345_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply)                     \
5346_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply)           \
5347_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5348_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY,                                   \
5349  one_enable_disable_pitr_mode_reply)                                   \
5350_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY,                                   \
5351  one_enable_disable_petr_mode_reply)                                   \
5352_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply)                     \
5353_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply)                   \
5354_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply)                   \
5355_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply)                   \
5356_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply)                   \
5357_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply)                     \
5358_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply)                   \
5359_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply)             \
5360_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply)           \
5361_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply)                 \
5362_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply)     \
5363_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY,                                   \
5364  gpe_add_del_native_fwd_rpath_reply)                                   \
5365_(GPE_FWD_ENTRY_PATH_DETAILS,                                           \
5366  gpe_fwd_entry_path_details)                                           \
5367_(SHOW_ONE_STATUS_REPLY, show_one_status_reply)                         \
5368_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY,                              \
5369  one_add_del_map_request_itr_rlocs_reply)                              \
5370_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,                                  \
5371  one_get_map_request_itr_rlocs_reply)                                  \
5372_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply)               \
5373_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply)                             \
5374_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply)                     \
5375_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply)     \
5376_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply)     \
5377_(SHOW_ONE_MAP_REGISTER_STATE_REPLY,                                    \
5378  show_one_map_register_state_reply)                                    \
5379_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply)     \
5380_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,                       \
5381  show_one_map_register_fallback_threshold_reply)                       \
5382_(AF_PACKET_CREATE_REPLY, af_packet_create_reply)                       \
5383_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)                       \
5384_(AF_PACKET_DETAILS, af_packet_details)					\
5385_(POLICER_ADD_DEL_REPLY, policer_add_del_reply)                         \
5386_(POLICER_DETAILS, policer_details)                                     \
5387_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5388_(POLICER_CLASSIFY_DETAILS, policer_classify_details)                   \
5389_(NETMAP_CREATE_REPLY, netmap_create_reply)                             \
5390_(NETMAP_DELETE_REPLY, netmap_delete_reply)                             \
5391_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details)                             \
5392_(MPLS_TABLE_DETAILS, mpls_table_details)                               \
5393_(MPLS_ROUTE_DETAILS, mpls_route_details)                               \
5394_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply)                   \
5395_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5396_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply)                 \
5397_(CLASSIFY_SESSION_DETAILS, classify_session_details)                   \
5398_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply)                   \
5399_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details)                       \
5400_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply)     \
5401_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details)         \
5402_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5403_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details)           \
5404_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5405_(FLOW_CLASSIFY_DETAILS, flow_classify_details)                         \
5406_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5407_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details)                 \
5408_(GET_NEXT_INDEX_REPLY, get_next_index_reply)                           \
5409_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply)                 \
5410_(PG_CAPTURE_REPLY, pg_capture_reply)                                   \
5411_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply)                     \
5412_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY,                         \
5413 ip_source_and_port_range_check_add_del_reply)                          \
5414_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY,               \
5415 ip_source_and_port_range_check_interface_add_del_reply)                \
5416_(DELETE_SUBIF_REPLY, delete_subif_reply)                               \
5417_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
5418_(SET_PUNT_REPLY, set_punt_reply)                                       \
5419_(IP_TABLE_DETAILS, ip_table_details)                                   \
5420_(IP_ROUTE_DETAILS, ip_route_details)                                   \
5421_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply)           \
5422_(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply)   \
5423_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply)     	\
5424_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
5425_(L2_XCONNECT_DETAILS, l2_xconnect_details)                             \
5426_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply)               \
5427_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply)           \
5428_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply)                       \
5429_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply)                       \
5430_(LLDP_CONFIG_REPLY, lldp_config_reply)                                 \
5431_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply)		\
5432_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply)	\
5433_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply)		\
5434_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply)		\
5435_(SESSION_RULES_DETAILS, session_rules_details)				\
5436_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply)	\
5437_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply)       \
5438_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
5439
5440#define foreach_standalone_reply_msg					\
5441_(SW_INTERFACE_EVENT, sw_interface_event)
5442
5443typedef struct
5444{
5445  u8 *name;
5446  u32 value;
5447} name_sort_t;
5448
5449#define STR_VTR_OP_CASE(op)     \
5450    case L2_VTR_ ## op:         \
5451        return "" # op;
5452
5453static const char *
5454str_vtr_op (u32 vtr_op)
5455{
5456  switch (vtr_op)
5457    {
5458      STR_VTR_OP_CASE (DISABLED);
5459      STR_VTR_OP_CASE (PUSH_1);
5460      STR_VTR_OP_CASE (PUSH_2);
5461      STR_VTR_OP_CASE (POP_1);
5462      STR_VTR_OP_CASE (POP_2);
5463      STR_VTR_OP_CASE (TRANSLATE_1_1);
5464      STR_VTR_OP_CASE (TRANSLATE_1_2);
5465      STR_VTR_OP_CASE (TRANSLATE_2_1);
5466      STR_VTR_OP_CASE (TRANSLATE_2_2);
5467    }
5468
5469  return "UNKNOWN";
5470}
5471
5472static int
5473dump_sub_interface_table (vat_main_t * vam)
5474{
5475  const sw_interface_subif_t *sub = NULL;
5476
5477  if (vam->json_output)
5478    {
5479      clib_warning
5480	("JSON output supported only for VPE API calls and dump_stats_table");
5481      return -99;
5482    }
5483
5484  print (vam->ofp,
5485	 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5486	 "Interface", "sw_if_index",
5487	 "sub id", "dot1ad", "tags", "outer id",
5488	 "inner id", "exact", "default", "outer any", "inner any");
5489
5490  vec_foreach (sub, vam->sw_if_subif_table)
5491  {
5492    print (vam->ofp,
5493	   "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5494	   sub->interface_name,
5495	   sub->sw_if_index,
5496	   sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5497	   sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5498	   sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5499	   sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5500    if (sub->vtr_op != L2_VTR_DISABLED)
5501      {
5502	print (vam->ofp,
5503	       "  vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5504	       "tag1: %d tag2: %d ]",
5505	       str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5506	       sub->vtr_tag1, sub->vtr_tag2);
5507      }
5508  }
5509
5510  return 0;
5511}
5512
5513static int
5514name_sort_cmp (void *a1, void *a2)
5515{
5516  name_sort_t *n1 = a1;
5517  name_sort_t *n2 = a2;
5518
5519  return strcmp ((char *) n1->name, (char *) n2->name);
5520}
5521
5522static int
5523dump_interface_table (vat_main_t * vam)
5524{
5525  hash_pair_t *p;
5526  name_sort_t *nses = 0, *ns;
5527
5528  if (vam->json_output)
5529    {
5530      clib_warning
5531	("JSON output supported only for VPE API calls and dump_stats_table");
5532      return -99;
5533    }
5534
5535  /* *INDENT-OFF* */
5536  hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5537  ({
5538    vec_add2 (nses, ns, 1);
5539    ns->name = (u8 *)(p->key);
5540    ns->value = (u32) p->value[0];
5541  }));
5542  /* *INDENT-ON* */
5543
5544  vec_sort_with_function (nses, name_sort_cmp);
5545
5546  print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5547  vec_foreach (ns, nses)
5548  {
5549    print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5550  }
5551  vec_free (nses);
5552  return 0;
5553}
5554
5555static int
5556dump_ip_table (vat_main_t * vam, int is_ipv6)
5557{
5558  const ip_details_t *det = NULL;
5559  const ip_address_details_t *address = NULL;
5560  u32 i = ~0;
5561
5562  print (vam->ofp, "%-12s", "sw_if_index");
5563
5564  vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5565  {
5566    i++;
5567    if (!det->present)
5568      {
5569	continue;
5570      }
5571    print (vam->ofp, "%-12d", i);
5572    print (vam->ofp, "            %-30s%-13s", "Address", "Prefix length");
5573    if (!det->addr)
5574      {
5575	continue;
5576      }
5577    vec_foreach (address, det->addr)
5578    {
5579      print (vam->ofp,
5580	     "            %-30U%-13d",
5581	     is_ipv6 ? format_ip6_address : format_ip4_address,
5582	     address->ip, address->prefix_length);
5583    }
5584  }
5585
5586  return 0;
5587}
5588
5589static int
5590dump_ipv4_table (vat_main_t * vam)
5591{
5592  if (vam->json_output)
5593    {
5594      clib_warning
5595	("JSON output supported only for VPE API calls and dump_stats_table");
5596      return -99;
5597    }
5598
5599  return dump_ip_table (vam, 0);
5600}
5601
5602static int
5603dump_ipv6_table (vat_main_t * vam)
5604{
5605  if (vam->json_output)
5606    {
5607      clib_warning
5608	("JSON output supported only for VPE API calls and dump_stats_table");
5609      return -99;
5610    }
5611
5612  return dump_ip_table (vam, 1);
5613}
5614
5615/*
5616 * Pass CLI buffers directly in the CLI_INBAND API message,
5617 * instead of an additional shared memory area.
5618 */
5619static int
5620exec_inband (vat_main_t * vam)
5621{
5622  vl_api_cli_inband_t *mp;
5623  unformat_input_t *i = vam->input;
5624  int ret;
5625
5626  if (vec_len (i->buffer) == 0)
5627    return -1;
5628
5629  if (vam->exec_mode == 0 && unformat (i, "mode"))
5630    {
5631      vam->exec_mode = 1;
5632      return 0;
5633    }
5634  if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5635    {
5636      vam->exec_mode = 0;
5637      return 0;
5638    }
5639
5640  /*
5641   * In order for the CLI command to work, it
5642   * must be a vector ending in \n, not a C-string ending
5643   * in \n\0.
5644   */
5645  u32 len = vec_len (vam->input->buffer);
5646  M2 (CLI_INBAND, mp, len);
5647  vl_api_to_api_string (len - 1, (const char *) vam->input->buffer, &mp->cmd);
5648
5649  S (mp);
5650  W (ret);
5651  /* json responses may or may not include a useful reply... */
5652  if (vec_len (vam->cmd_reply))
5653    print (vam->ofp, "%v", (char *) (vam->cmd_reply));
5654  return ret;
5655}
5656
5657int
5658exec (vat_main_t * vam)
5659{
5660  return exec_inband (vam);
5661}
5662
5663static int
5664api_create_loopback (vat_main_t * vam)
5665{
5666  unformat_input_t *i = vam->input;
5667  vl_api_create_loopback_t *mp;
5668  vl_api_create_loopback_instance_t *mp_lbi;
5669  u8 mac_address[6];
5670  u8 mac_set = 0;
5671  u8 is_specified = 0;
5672  u32 user_instance = 0;
5673  int ret;
5674
5675  clib_memset (mac_address, 0, sizeof (mac_address));
5676
5677  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5678    {
5679      if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5680	mac_set = 1;
5681      if (unformat (i, "instance %d", &user_instance))
5682	is_specified = 1;
5683      else
5684	break;
5685    }
5686
5687  if (is_specified)
5688    {
5689      M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5690      mp_lbi->is_specified = is_specified;
5691      if (is_specified)
5692	mp_lbi->user_instance = htonl (user_instance);
5693      if (mac_set)
5694	clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5695      S (mp_lbi);
5696    }
5697  else
5698    {
5699      /* Construct the API message */
5700      M (CREATE_LOOPBACK, mp);
5701      if (mac_set)
5702	clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5703      S (mp);
5704    }
5705
5706  W (ret);
5707  return ret;
5708}
5709
5710static int
5711api_delete_loopback (vat_main_t * vam)
5712{
5713  unformat_input_t *i = vam->input;
5714  vl_api_delete_loopback_t *mp;
5715  u32 sw_if_index = ~0;
5716  int ret;
5717
5718  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5719    {
5720      if (unformat (i, "sw_if_index %d", &sw_if_index))
5721	;
5722      else
5723	break;
5724    }
5725
5726  if (sw_if_index == ~0)
5727    {
5728      errmsg ("missing sw_if_index");
5729      return -99;
5730    }
5731
5732  /* Construct the API message */
5733  M (DELETE_LOOPBACK, mp);
5734  mp->sw_if_index = ntohl (sw_if_index);
5735
5736  S (mp);
5737  W (ret);
5738  return ret;
5739}
5740
5741static int
5742api_want_interface_events (vat_main_t * vam)
5743{
5744  unformat_input_t *i = vam->input;
5745  vl_api_want_interface_events_t *mp;
5746  int enable = -1;
5747  int ret;
5748
5749  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5750    {
5751      if (unformat (i, "enable"))
5752	enable = 1;
5753      else if (unformat (i, "disable"))
5754	enable = 0;
5755      else
5756	break;
5757    }
5758
5759  if (enable == -1)
5760    {
5761      errmsg ("missing enable|disable");
5762      return -99;
5763    }
5764
5765  M (WANT_INTERFACE_EVENTS, mp);
5766  mp->enable_disable = enable;
5767
5768  vam->interface_event_display = enable;
5769
5770  S (mp);
5771  W (ret);
5772  return ret;
5773}
5774
5775
5776/* Note: non-static, called once to set up the initial intfc table */
5777int
5778api_sw_interface_dump (vat_main_t * vam)
5779{
5780  vl_api_sw_interface_dump_t *mp;
5781  vl_api_control_ping_t *mp_ping;
5782  hash_pair_t *p;
5783  name_sort_t *nses = 0, *ns;
5784  sw_interface_subif_t *sub = NULL;
5785  int ret;
5786
5787  /* Toss the old name table */
5788  /* *INDENT-OFF* */
5789  hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5790  ({
5791    vec_add2 (nses, ns, 1);
5792    ns->name = (u8 *)(p->key);
5793    ns->value = (u32) p->value[0];
5794  }));
5795  /* *INDENT-ON* */
5796
5797  hash_free (vam->sw_if_index_by_interface_name);
5798
5799  vec_foreach (ns, nses) vec_free (ns->name);
5800
5801  vec_free (nses);
5802
5803  vec_foreach (sub, vam->sw_if_subif_table)
5804  {
5805    vec_free (sub->interface_name);
5806  }
5807  vec_free (vam->sw_if_subif_table);
5808
5809  /* recreate the interface name hash table */
5810  vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
5811
5812  /*
5813   * Ask for all interface names. Otherwise, the epic catalog of
5814   * name filters becomes ridiculously long, and vat ends up needing
5815   * to be taught about new interface types.
5816   */
5817  M (SW_INTERFACE_DUMP, mp);
5818  S (mp);
5819
5820  /* Use a control ping for synchronization */
5821  MPING (CONTROL_PING, mp_ping);
5822  S (mp_ping);
5823
5824  W (ret);
5825  return ret;
5826}
5827
5828static int
5829api_sw_interface_set_flags (vat_main_t * vam)
5830{
5831  unformat_input_t *i = vam->input;
5832  vl_api_sw_interface_set_flags_t *mp;
5833  u32 sw_if_index;
5834  u8 sw_if_index_set = 0;
5835  u8 admin_up = 0;
5836  int ret;
5837
5838  /* Parse args required to build the message */
5839  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5840    {
5841      if (unformat (i, "admin-up"))
5842	admin_up = 1;
5843      else if (unformat (i, "admin-down"))
5844	admin_up = 0;
5845      else
5846	if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5847	sw_if_index_set = 1;
5848      else if (unformat (i, "sw_if_index %d", &sw_if_index))
5849	sw_if_index_set = 1;
5850      else
5851	break;
5852    }
5853
5854  if (sw_if_index_set == 0)
5855    {
5856      errmsg ("missing interface name or sw_if_index");
5857      return -99;
5858    }
5859
5860  /* Construct the API message */
5861  M (SW_INTERFACE_SET_FLAGS, mp);
5862  mp->sw_if_index = ntohl (sw_if_index);
5863  mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
5864
5865  /* send it... */
5866  S (mp);
5867
5868  /* Wait for a reply, return the good/bad news... */
5869  W (ret);
5870  return ret;
5871}
5872
5873static int
5874api_sw_interface_set_rx_mode (vat_main_t * vam)
5875{
5876  unformat_input_t *i = vam->input;
5877  vl_api_sw_interface_set_rx_mode_t *mp;
5878  u32 sw_if_index;
5879  u8 sw_if_index_set = 0;
5880  int ret;
5881  u8 queue_id_valid = 0;
5882  u32 queue_id;
5883  vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
5884
5885  /* Parse args required to build the message */
5886  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5887    {
5888      if (unformat (i, "queue %d", &queue_id))
5889	queue_id_valid = 1;
5890      else if (unformat (i, "polling"))
5891	mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
5892      else if (unformat (i, "interrupt"))
5893	mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
5894      else if (unformat (i, "adaptive"))
5895	mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
5896      else
5897	if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5898	sw_if_index_set = 1;
5899      else if (unformat (i, "sw_if_index %d", &sw_if_index))
5900	sw_if_index_set = 1;
5901      else
5902	break;
5903    }
5904
5905  if (sw_if_index_set == 0)
5906    {
5907      errmsg ("missing interface name or sw_if_index");
5908      return -99;
5909    }
5910  if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
5911    {
5912      errmsg ("missing rx-mode");
5913      return -99;
5914    }
5915
5916  /* Construct the API message */
5917  M (SW_INTERFACE_SET_RX_MODE, mp);
5918  mp->sw_if_index = ntohl (sw_if_index);
5919  mp->mode = (vl_api_rx_mode_t) mode;
5920  mp->queue_id_valid = queue_id_valid;
5921  mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
5922
5923  /* send it... */
5924  S (mp);
5925
5926  /* Wait for a reply, return the good/bad news... */
5927  W (ret);
5928  return ret;
5929}
5930
5931static int
5932api_sw_interface_set_rx_placement (vat_main_t * vam)
5933{
5934  unformat_input_t *i = vam->input;
5935  vl_api_sw_interface_set_rx_placement_t *mp;
5936  u32 sw_if_index;
5937  u8 sw_if_index_set = 0;
5938  int ret;
5939  u8 is_main = 0;
5940  u32 queue_id, thread_index;
5941
5942  /* Parse args required to build the message */
5943  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5944    {
5945      if (unformat (i, "queue %d", &queue_id))
5946	;
5947      else if (unformat (i, "main"))
5948	is_main = 1;
5949      else if (unformat (i, "worker %d", &thread_index))
5950	;
5951      else
5952	if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5953	sw_if_index_set = 1;
5954      else if (unformat (i, "sw_if_index %d", &sw_if_index))
5955	sw_if_index_set = 1;
5956      else
5957	break;
5958    }
5959
5960  if (sw_if_index_set == 0)
5961    {
5962      errmsg ("missing interface name or sw_if_index");
5963      return -99;
5964    }
5965
5966  if (is_main)
5967    thread_index = 0;
5968  /* Construct the API message */
5969  M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
5970  mp->sw_if_index = ntohl (sw_if_index);
5971  mp->worker_id = ntohl (thread_index);
5972  mp->queue_id = ntohl (queue_id);
5973  mp->is_main = is_main;
5974
5975  /* send it... */
5976  S (mp);
5977  /* Wait for a reply, return the good/bad news... */
5978  W (ret);
5979  return ret;
5980}
5981
5982static void vl_api_sw_interface_rx_placement_details_t_handler
5983  (vl_api_sw_interface_rx_placement_details_t * mp)
5984{
5985  vat_main_t *vam = &vat_main;
5986  u32 worker_id = ntohl (mp->worker_id);
5987
5988  print (vam->ofp,
5989	 "\n%-11d %-11s %-6d %-5d %-9s",
5990	 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
5991	 worker_id, ntohl (mp->queue_id),
5992	 (mp->mode ==
5993	  1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
5994}
5995
5996static void vl_api_sw_interface_rx_placement_details_t_handler_json
5997  (vl_api_sw_interface_rx_placement_details_t * mp)
5998{
5999  vat_main_t *vam = &vat_main;
6000  vat_json_node_t *node = NULL;
6001
6002  if (VAT_JSON_ARRAY != vam->json_tree.type)
6003    {
6004      ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6005      vat_json_init_array (&vam->json_tree);
6006    }
6007  node = vat_json_array_add (&vam->json_tree);
6008
6009  vat_json_init_object (node);
6010  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6011  vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6012  vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6013  vat_json_object_add_uint (node, "mode", mp->mode);
6014}
6015
6016static int
6017api_sw_interface_rx_placement_dump (vat_main_t * vam)
6018{
6019  unformat_input_t *i = vam->input;
6020  vl_api_sw_interface_rx_placement_dump_t *mp;
6021  vl_api_control_ping_t *mp_ping;
6022  int ret;
6023  u32 sw_if_index;
6024  u8 sw_if_index_set = 0;
6025
6026  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6027    {
6028      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6029	sw_if_index_set++;
6030      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6031	sw_if_index_set++;
6032      else
6033	break;
6034    }
6035
6036  print (vam->ofp,
6037	 "\n%-11s %-11s %-6s %-5s %-4s",
6038	 "sw_if_index", "main/worker", "thread", "queue", "mode");
6039
6040  /* Dump Interface rx placement */
6041  M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6042
6043  if (sw_if_index_set)
6044    mp->sw_if_index = htonl (sw_if_index);
6045  else
6046    mp->sw_if_index = ~0;
6047
6048  S (mp);
6049
6050  /* Use a control ping for synchronization */
6051  MPING (CONTROL_PING, mp_ping);
6052  S (mp_ping);
6053
6054  W (ret);
6055  return ret;
6056}
6057
6058static int
6059api_sw_interface_clear_stats (vat_main_t * vam)
6060{
6061  unformat_input_t *i = vam->input;
6062  vl_api_sw_interface_clear_stats_t *mp;
6063  u32 sw_if_index;
6064  u8 sw_if_index_set = 0;
6065  int ret;
6066
6067  /* Parse args required to build the message */
6068  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6069    {
6070      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6071	sw_if_index_set = 1;
6072      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6073	sw_if_index_set = 1;
6074      else
6075	break;
6076    }
6077
6078  /* Construct the API message */
6079  M (SW_INTERFACE_CLEAR_STATS, mp);
6080
6081  if (sw_if_index_set == 1)
6082    mp->sw_if_index = ntohl (sw_if_index);
6083  else
6084    mp->sw_if_index = ~0;
6085
6086  /* send it... */
6087  S (mp);
6088
6089  /* Wait for a reply, return the good/bad news... */
6090  W (ret);
6091  return ret;
6092}
6093
6094static int
6095api_sw_interface_add_del_address (vat_main_t * vam)
6096{
6097  unformat_input_t *i = vam->input;
6098  vl_api_sw_interface_add_del_address_t *mp;
6099  u32 sw_if_index;
6100  u8 sw_if_index_set = 0;
6101  u8 is_add = 1, del_all = 0;
6102  u32 address_length = 0;
6103  u8 v4_address_set = 0;
6104  u8 v6_address_set = 0;
6105  ip4_address_t v4address;
6106  ip6_address_t v6address;
6107  int ret;
6108
6109  /* Parse args required to build the message */
6110  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6111    {
6112      if (unformat (i, "del-all"))
6113	del_all = 1;
6114      else if (unformat (i, "del"))
6115	is_add = 0;
6116      else
6117	if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6118	sw_if_index_set = 1;
6119      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6120	sw_if_index_set = 1;
6121      else if (unformat (i, "%U/%d",
6122			 unformat_ip4_address, &v4address, &address_length))
6123	v4_address_set = 1;
6124      else if (unformat (i, "%U/%d",
6125			 unformat_ip6_address, &v6address, &address_length))
6126	v6_address_set = 1;
6127      else
6128	break;
6129    }
6130
6131  if (sw_if_index_set == 0)
6132    {
6133      errmsg ("missing interface name or sw_if_index");
6134      return -99;
6135    }
6136  if (v4_address_set && v6_address_set)
6137    {
6138      errmsg ("both v4 and v6 addresses set");
6139      return -99;
6140    }
6141  if (!v4_address_set && !v6_address_set && !del_all)
6142    {
6143      errmsg ("no addresses set");
6144      return -99;
6145    }
6146
6147  /* Construct the API message */
6148  M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
6149
6150  mp->sw_if_index = ntohl (sw_if_index);
6151  mp->is_add = is_add;
6152  mp->del_all = del_all;
6153  if (v6_address_set)
6154    {
6155      mp->prefix.address.af = ADDRESS_IP6;
6156      clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
6157    }
6158  else
6159    {
6160      mp->prefix.address.af = ADDRESS_IP4;
6161      clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
6162    }
6163  mp->prefix.len = address_length;
6164
6165  /* send it... */
6166  S (mp);
6167
6168  /* Wait for a reply, return good/bad news  */
6169  W (ret);
6170  return ret;
6171}
6172
6173static int
6174api_sw_interface_set_mpls_enable (vat_main_t * vam)
6175{
6176  unformat_input_t *i = vam->input;
6177  vl_api_sw_interface_set_mpls_enable_t *mp;
6178  u32 sw_if_index;
6179  u8 sw_if_index_set = 0;
6180  u8 enable = 1;
6181  int ret;
6182
6183  /* Parse args required to build the message */
6184  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6185    {
6186      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6187	sw_if_index_set = 1;
6188      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6189	sw_if_index_set = 1;
6190      else if (unformat (i, "disable"))
6191	enable = 0;
6192      else if (unformat (i, "dis"))
6193	enable = 0;
6194      else
6195	break;
6196    }
6197
6198  if (sw_if_index_set == 0)
6199    {
6200      errmsg ("missing interface name or sw_if_index");
6201      return -99;
6202    }
6203
6204  /* Construct the API message */
6205  M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
6206
6207  mp->sw_if_index = ntohl (sw_if_index);
6208  mp->enable = enable;
6209
6210  /* send it... */
6211  S (mp);
6212
6213  /* Wait for a reply... */
6214  W (ret);
6215  return ret;
6216}
6217
6218static int
6219api_sw_interface_set_table (vat_main_t * vam)
6220{
6221  unformat_input_t *i = vam->input;
6222  vl_api_sw_interface_set_table_t *mp;
6223  u32 sw_if_index, vrf_id = 0;
6224  u8 sw_if_index_set = 0;
6225  u8 is_ipv6 = 0;
6226  int ret;
6227
6228  /* Parse args required to build the message */
6229  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6230    {
6231      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6232	sw_if_index_set = 1;
6233      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6234	sw_if_index_set = 1;
6235      else if (unformat (i, "vrf %d", &vrf_id))
6236	;
6237      else if (unformat (i, "ipv6"))
6238	is_ipv6 = 1;
6239      else
6240	break;
6241    }
6242
6243  if (sw_if_index_set == 0)
6244    {
6245      errmsg ("missing interface name or sw_if_index");
6246      return -99;
6247    }
6248
6249  /* Construct the API message */
6250  M (SW_INTERFACE_SET_TABLE, mp);
6251
6252  mp->sw_if_index = ntohl (sw_if_index);
6253  mp->is_ipv6 = is_ipv6;
6254  mp->vrf_id = ntohl (vrf_id);
6255
6256  /* send it... */
6257  S (mp);
6258
6259  /* Wait for a reply... */
6260  W (ret);
6261  return ret;
6262}
6263
6264static void vl_api_sw_interface_get_table_reply_t_handler
6265  (vl_api_sw_interface_get_table_reply_t * mp)
6266{
6267  vat_main_t *vam = &vat_main;
6268
6269  print (vam->ofp, "%d", ntohl (mp->vrf_id));
6270
6271  vam->retval = ntohl (mp->retval);
6272  vam->result_ready = 1;
6273
6274}
6275
6276static void vl_api_sw_interface_get_table_reply_t_handler_json
6277  (vl_api_sw_interface_get_table_reply_t * mp)
6278{
6279  vat_main_t *vam = &vat_main;
6280  vat_json_node_t node;
6281
6282  vat_json_init_object (&node);
6283  vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6284  vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6285
6286  vat_json_print (vam->ofp, &node);
6287  vat_json_free (&node);
6288
6289  vam->retval = ntohl (mp->retval);
6290  vam->result_ready = 1;
6291}
6292
6293static int
6294api_sw_interface_get_table (vat_main_t * vam)
6295{
6296  unformat_input_t *i = vam->input;
6297  vl_api_sw_interface_get_table_t *mp;
6298  u32 sw_if_index;
6299  u8 sw_if_index_set = 0;
6300  u8 is_ipv6 = 0;
6301  int ret;
6302
6303  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6304    {
6305      if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6306	sw_if_index_set = 1;
6307      else if (unformat (i, "sw_if_index %d", &sw_if_index))
6308	sw_if_index_set = 1;
6309      else if (unformat (i, "ipv6"))
6310	is_ipv6 = 1;
6311      else
6312	break;
6313    }
6314
6315  if