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