api: replace print functions wth format
[vpp.git] / src / plugins / lisp / lisp-cp / one_test.c
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vat/vat.h>
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vppinfra/error.h>
20
21 #include <vnet/ip/ip_format_fns.h>
22 #include <vnet/ethernet/ethernet_format_fns.h>
23 #include <vnet/ethernet/mac_address.h>
24 #include <lisp/lisp-cp/lisp_types.h>
25
26 /* define message IDs */
27 #include <lisp/lisp-cp/one.api_enum.h>
28 #include <lisp/lisp-cp/one.api_types.h>
29 #include <vlibmemory/vlib.api_types.h>
30
31 typedef struct
32 {
33   /* API message ID base */
34   u16 msg_id_base;
35   u32 ping_id;
36   vat_main_t *vat_main;
37 } one_test_main_t;
38
39 one_test_main_t one_test_main;
40
41 #define __plugin_msg_base one_test_main.msg_id_base
42 #include <vlibapi/vat_helper_macros.h>
43
44 #define FINISH                                                                \
45   vec_add1 (s, 0);                                                            \
46   vlib_cli_output (handle, (char *) s);                                       \
47   vec_free (s);                                                               \
48   return handle;
49
50 #define LISP_PING(_lm, mp_ping)                                         \
51   if (!(_lm)->ping_id)                                                  \
52     (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
53   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));          \
54   mp_ping->_vl_msg_id = htons ((_lm)->ping_id);                         \
55   mp_ping->client_index = vam->my_client_index;                         \
56   fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id);           \
57   vam->result_ready = 0;                                                \
58
59 typedef struct
60 {
61   u32 spi;
62   u8 si;
63 } __attribute__ ((__packed__)) lisp_nsh_api_t;
64
65 static uword
66 unformat_nsh_address (unformat_input_t * input, va_list * args)
67 {
68   lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
69   return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
70 }
71
72 static u8 *
73 format_nsh_address_vat (u8 * s, va_list * args)
74 {
75   nsh_t *a = va_arg (*args, nsh_t *);
76   return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
77 }
78
79 static u8 *
80 format_lisp_transport_protocol (u8 * s, va_list * args)
81 {
82   u32 proto = va_arg (*args, u32);
83
84   switch (proto)
85     {
86     case 1:
87       return format (s, "udp");
88     case 2:
89       return format (s, "api");
90     default:
91       return 0;
92     }
93   return 0;
94 }
95
96 static void
97 vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
98 {
99   vat_main_t *vam = &vat_main;
100   u8 *s = 0;
101
102   if (mp->local)
103     {
104       s = format (s, "%=16d%=16d%=16d",
105                   ntohl (mp->sw_if_index), mp->priority, mp->weight);
106     }
107   else
108     {
109       s = format (s, "%=16U%=16d%=16d",
110                   format_ip46_address,
111                   mp->ip_address, mp->priority, mp->weight);
112     }
113
114   print (vam->ofp, "%v", s);
115   vec_free (s);
116 }
117
118 static void
119 vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
120                                           mp)
121 {
122   vat_main_t *vam = &vat_main;
123   u8 *ls_name = 0;
124
125   ls_name = format (0, "%s", mp->ls_name);
126
127   print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
128          ls_name);
129   vec_free (ls_name);
130 }
131
132 static void vl_api_one_get_transport_protocol_reply_t_handler
133   (vl_api_one_get_transport_protocol_reply_t * mp)
134 {
135   vat_main_t *vam = &vat_main;
136   i32 retval = ntohl (mp->retval);
137   if (vam->async_mode)
138     {
139       vam->async_errors += (retval < 0);
140     }
141   else
142     {
143       u32 proto = mp->protocol;
144       print (vam->ofp, "Transport protocol: %U",
145              format_lisp_transport_protocol, proto);
146       vam->retval = retval;
147       vam->result_ready = 1;
148     }
149 }
150
151 static void vl_api_one_add_del_locator_set_reply_t_handler
152   (vl_api_one_add_del_locator_set_reply_t * mp)
153 {
154   vat_main_t *vam = &vat_main;
155   i32 retval = ntohl (mp->retval);
156   if (vam->async_mode)
157     {
158       vam->async_errors += (retval < 0);
159     }
160   else
161     {
162       vam->retval = retval;
163       vam->result_ready = 1;
164     }
165 }
166
167 static u8 *
168 format_lisp_flat_eid (u8 * s, va_list * args)
169 {
170   vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
171
172   switch (eid->type)
173     {
174     case EID_TYPE_API_PREFIX:
175       if (eid->address.prefix.address.af)
176         return format (s, "%U/%d", format_ip6_address,
177                        eid->address.prefix.address.un.ip6,
178                        eid->address.prefix.len);
179       return format (s, "%U/%d", format_ip4_address,
180                      eid->address.prefix.address.un.ip4,
181                      eid->address.prefix.len);
182     case EID_TYPE_API_MAC:
183       return format (s, "%U", format_ethernet_address, eid->address.mac);
184     case EID_TYPE_API_NSH:
185       return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
186     }
187   return 0;
188 }
189
190 static u8 *
191 format_lisp_eid_vat (u8 * s, va_list * args)
192 {
193   vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
194   vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
195   u8 is_src_dst = (u8) va_arg (*args, int);
196
197   if (is_src_dst)
198     s = format (s, "%U|", format_lisp_flat_eid, seid);
199
200   s = format (s, "%U", format_lisp_flat_eid, deid);
201
202   return s;
203 }
204
205 static void
206 vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
207 {
208   vat_main_t *vam = &vat_main;
209   u8 *s = 0, *eid = 0;
210
211   if (~0 == mp->locator_set_index)
212     s = format (0, "action: %d", mp->action);
213   else
214     s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
215
216   eid = format (0, "%U", format_lisp_eid_vat,
217                 &mp->deid, &mp->seid, mp->is_src_dst);
218   vec_add1 (eid, 0);
219
220   print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
221          clib_net_to_host_u32 (mp->vni),
222          eid,
223          mp->is_local ? "local" : "remote",
224          s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
225          clib_net_to_host_u16 (mp->key.id), mp->key.key);
226
227   vec_free (s);
228   vec_free (eid);
229 }
230
231 static void
232 vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
233 {
234   vat_main_t *vam = &vat_main;
235   u8 *seid = 0, *deid = 0;
236   ip46_address_t lloc, rloc;
237
238   deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0);
239
240   seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0);
241
242   vec_add1 (deid, 0);
243   vec_add1 (seid, 0);
244
245   if (mp->lloc.af)
246     {
247       clib_memcpy (&lloc.ip6, mp->lloc.un.ip6, 16);
248       clib_memcpy (&rloc.ip6, mp->rloc.un.ip6, 16);
249     }
250   else
251     {
252       clib_memcpy (&lloc.ip4, mp->lloc.un.ip4, 4);
253       clib_memcpy (&rloc.ip4, mp->rloc.un.ip4, 4);
254     }
255
256
257   print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
258          clib_net_to_host_u32 (mp->vni),
259          seid, deid,
260          format_ip46_address, lloc,
261          format_ip46_address, rloc,
262          clib_net_to_host_u32 (mp->pkt_count),
263          clib_net_to_host_u32 (mp->bytes));
264
265   vec_free (deid);
266   vec_free (seid);
267 }
268
269 static void
270   vl_api_one_eid_table_map_details_t_handler
271   (vl_api_one_eid_table_map_details_t * mp)
272 {
273   vat_main_t *vam = &vat_main;
274
275   u8 *line = format (0, "%=10d%=10d",
276                      clib_net_to_host_u32 (mp->vni),
277                      clib_net_to_host_u32 (mp->dp_table));
278   print (vam->ofp, "%v", line);
279   vec_free (line);
280 }
281
282 static void
283   vl_api_one_eid_table_vni_details_t_handler
284   (vl_api_one_eid_table_vni_details_t * mp)
285 {
286   vat_main_t *vam = &vat_main;
287
288   u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
289   print (vam->ofp, "%v", line);
290   vec_free (line);
291 }
292
293 static void
294   vl_api_show_one_map_register_fallback_threshold_reply_t_handler
295   (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
296 {
297   vat_main_t *vam = &vat_main;
298   int retval = clib_net_to_host_u32 (mp->retval);
299
300   print (vam->ofp, "fallback threshold value: %d", mp->value);
301
302   vam->retval = retval;
303   vam->result_ready = 1;
304 }
305
306 static void
307   vl_api_show_one_map_register_state_reply_t_handler
308   (vl_api_show_one_map_register_state_reply_t * mp)
309 {
310   vat_main_t *vam = &vat_main;
311   int retval = clib_net_to_host_u32 (mp->retval);
312
313   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
314
315   vam->retval = retval;
316   vam->result_ready = 1;
317 }
318
319 static void
320   vl_api_show_one_rloc_probe_state_reply_t_handler
321   (vl_api_show_one_rloc_probe_state_reply_t * mp)
322 {
323   vat_main_t *vam = &vat_main;
324   int retval = clib_net_to_host_u32 (mp->retval);
325
326   if (retval)
327     goto end;
328
329   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
330 end:
331   vam->retval = retval;
332   vam->result_ready = 1;
333 }
334
335 static void
336   vl_api_show_one_stats_enable_disable_reply_t_handler
337   (vl_api_show_one_stats_enable_disable_reply_t * mp)
338 {
339   vat_main_t *vam = &vat_main;
340   int retval = clib_net_to_host_u32 (mp->retval);
341
342   if (retval)
343     goto end;
344
345   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
346 end:
347   vam->retval = retval;
348   vam->result_ready = 1;
349 }
350
351 static void
352   vl_api_one_ndp_entries_get_reply_t_handler
353   (vl_api_one_ndp_entries_get_reply_t * mp)
354 {
355   vat_main_t *vam = &vat_main;
356   u32 i, n;
357   int retval = clib_net_to_host_u32 (mp->retval);
358
359   if (retval)
360     goto end;
361
362   n = clib_net_to_host_u32 (mp->count);
363
364   for (i = 0; i < n; i++)
365     print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
366            format_ethernet_address, mp->entries[i].mac);
367
368 end:
369   vam->retval = retval;
370   vam->result_ready = 1;
371 }
372
373 static void
374   vl_api_one_l2_arp_entries_get_reply_t_handler
375   (vl_api_one_l2_arp_entries_get_reply_t * mp)
376 {
377   vat_main_t *vam = &vat_main;
378   u32 i, n;
379   int retval = clib_net_to_host_u32 (mp->retval);
380
381   if (retval)
382     goto end;
383
384   n = clib_net_to_host_u32 (mp->count);
385
386   for (i = 0; i < n; i++)
387     print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
388            format_ethernet_address, mp->entries[i].mac);
389
390 end:
391   vam->retval = retval;
392   vam->result_ready = 1;
393 }
394
395 static void
396 vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
397 {
398   vat_main_t *vam = &vat_main;
399   u32 i, n;
400   int retval = clib_net_to_host_u32 (mp->retval);
401
402   if (retval)
403     goto end;
404
405   n = clib_net_to_host_u32 (mp->count);
406
407   for (i = 0; i < n; i++)
408     {
409       print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
410     }
411
412 end:
413   vam->retval = retval;
414   vam->result_ready = 1;
415 }
416
417 static void
418   vl_api_one_l2_arp_bd_get_reply_t_handler
419   (vl_api_one_l2_arp_bd_get_reply_t * mp)
420 {
421   vat_main_t *vam = &vat_main;
422   u32 i, n;
423   int retval = clib_net_to_host_u32 (mp->retval);
424
425   if (retval)
426     goto end;
427
428   n = clib_net_to_host_u32 (mp->count);
429
430   for (i = 0; i < n; i++)
431     {
432       print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
433     }
434
435 end:
436   vam->retval = retval;
437   vam->result_ready = 1;
438 }
439
440 static void
441   vl_api_one_adjacencies_get_reply_t_handler
442   (vl_api_one_adjacencies_get_reply_t * mp)
443 {
444   vat_main_t *vam = &vat_main;
445   u32 i, n;
446   int retval = clib_net_to_host_u32 (mp->retval);
447   vl_api_one_adjacency_t *a;
448
449   if (retval)
450     goto end;
451
452   n = clib_net_to_host_u32 (mp->count);
453
454   for (i = 0; i < n; i++)
455     {
456       a = &mp->adjacencies[i];
457       print (vam->ofp, "%U %40U",
458              format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
459     }
460
461 end:
462   vam->retval = retval;
463   vam->result_ready = 1;
464 }
465
466 static void
467 vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
468 {
469   vat_main_t *vam = &vat_main;
470
471   print (vam->ofp, "%=20U",
472          mp->ip_address.af ? format_ip6_address : format_ip4_address,
473          mp->ip_address.un);
474 }
475
476 static void
477 vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
478                                            * mp)
479 {
480   vat_main_t *vam = &vat_main;
481
482   print (vam->ofp, "%=20U",
483          mp->ip_address.af ? format_ip6_address : format_ip4_address,
484          mp->ip_address.un);
485 }
486
487 static void
488 vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
489 {
490   vat_main_t *vam = &vat_main;
491   i32 retval = ntohl (mp->retval);
492
493   if (0 <= retval)
494     {
495       print (vam->ofp, "feature: %s\ngpe: %s",
496              mp->feature_status ? "enabled" : "disabled",
497              mp->gpe_status ? "enabled" : "disabled");
498     }
499
500   vam->retval = retval;
501   vam->result_ready = 1;
502 }
503
504 static void
505   vl_api_one_get_map_request_itr_rlocs_reply_t_handler
506   (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
507 {
508   vat_main_t *vam = &vat_main;
509   i32 retval = ntohl (mp->retval);
510
511   if (retval >= 0)
512     {
513       print (vam->ofp, "%=20s", mp->locator_set_name);
514     }
515
516   vam->retval = retval;
517   vam->result_ready = 1;
518 }
519
520 static u8 *
521 format_lisp_map_request_mode (u8 * s, va_list * args)
522 {
523   u32 mode = va_arg (*args, u32);
524
525   switch (mode)
526     {
527     case 0:
528       return format (0, "dst-only");
529     case 1:
530       return format (0, "src-dst");
531     }
532   return 0;
533 }
534
535 static void
536   vl_api_show_one_map_request_mode_reply_t_handler
537   (vl_api_show_one_map_request_mode_reply_t * mp)
538 {
539   vat_main_t *vam = &vat_main;
540   i32 retval = ntohl (mp->retval);
541
542   if (0 <= retval)
543     {
544       u32 mode = mp->mode;
545       print (vam->ofp, "map_request_mode: %U",
546              format_lisp_map_request_mode, mode);
547     }
548
549   vam->retval = retval;
550   vam->result_ready = 1;
551 }
552
553 static void
554   vl_api_one_show_xtr_mode_reply_t_handler
555   (vl_api_one_show_xtr_mode_reply_t * mp)
556 {
557   vat_main_t *vam = &vat_main;
558   i32 retval = ntohl (mp->retval);
559
560   if (0 <= retval)
561     {
562       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
563     }
564
565   vam->retval = retval;
566   vam->result_ready = 1;
567 }
568
569 static void
570   vl_api_one_show_pitr_mode_reply_t_handler
571   (vl_api_one_show_pitr_mode_reply_t * mp)
572 {
573   vat_main_t *vam = &vat_main;
574   i32 retval = ntohl (mp->retval);
575
576   if (0 <= retval)
577     {
578       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
579     }
580
581   vam->retval = retval;
582   vam->result_ready = 1;
583 }
584
585 static void
586   vl_api_one_show_petr_mode_reply_t_handler
587   (vl_api_one_show_petr_mode_reply_t * mp)
588 {
589   vat_main_t *vam = &vat_main;
590   i32 retval = ntohl (mp->retval);
591
592   if (0 <= retval)
593     {
594       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
595     }
596
597   vam->retval = retval;
598   vam->result_ready = 1;
599 }
600
601 static void
602   vl_api_show_one_use_petr_reply_t_handler
603   (vl_api_show_one_use_petr_reply_t * mp)
604 {
605   vat_main_t *vam = &vat_main;
606   i32 retval = ntohl (mp->retval);
607
608   if (0 <= retval)
609     {
610       print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
611       if (mp->status)
612         {
613           print (vam->ofp, "Proxy-ETR address; %U",
614                  mp->ip_address.af ? format_ip6_address : format_ip4_address,
615                  mp->ip_address.un);
616         }
617     }
618
619   vam->retval = retval;
620   vam->result_ready = 1;
621 }
622
623 static void
624   vl_api_show_one_nsh_mapping_reply_t_handler
625   (vl_api_show_one_nsh_mapping_reply_t * mp)
626 {
627   vat_main_t *vam = &vat_main;
628   i32 retval = ntohl (mp->retval);
629
630   if (0 <= retval)
631     {
632       print (vam->ofp, "%-20s%-16s",
633              mp->is_set ? "set" : "not-set",
634              mp->is_set ? (char *) mp->locator_set_name : "");
635     }
636
637   vam->retval = retval;
638   vam->result_ready = 1;
639 }
640
641 static void
642   vl_api_show_one_map_register_ttl_reply_t_handler
643   (vl_api_show_one_map_register_ttl_reply_t * mp)
644 {
645   vat_main_t *vam = &vat_main;
646   i32 retval = ntohl (mp->retval);
647
648   if (0 <= retval)
649     {
650       print (vam->ofp, "ttl: %u", mp->ttl);
651     }
652
653   vam->retval = retval;
654   vam->result_ready = 1;
655 }
656
657 static void
658 vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
659 {
660   vat_main_t *vam = &vat_main;
661   i32 retval = ntohl (mp->retval);
662
663   if (0 <= retval)
664     {
665       print (vam->ofp, "%-20s%-16s",
666              mp->status ? "enabled" : "disabled",
667              mp->status ? (char *) mp->locator_set_name : "");
668     }
669
670   vam->retval = retval;
671   vam->result_ready = 1;
672 }
673
674 /* *INDENT-OFF* */
675 /** Used for parsing LISP eids */
676 typedef CLIB_PACKED(struct{
677   union {
678           ip46_address_t ip;
679           mac_address_t mac;
680           lisp_nsh_api_t nsh;
681   } addr;
682   u32 len;       /**< prefix length if IP */
683   u8 type;      /**< type of eid */
684 }) lisp_eid_vat_t;
685 /* *INDENT-ON* */
686
687 static uword
688 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
689 {
690   lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
691
692   clib_memset (a, 0, sizeof (a[0]));
693
694   if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
695     {
696       a->type = 0;              /* ip prefix type */
697     }
698   else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
699     {
700       a->type = 1;              /* mac type */
701     }
702   else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
703     {
704       a->type = 2;              /* NSH type */
705       a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
706     }
707   else
708     {
709       return 0;
710     }
711
712   if (a->type == 0)
713     {
714       if (ip46_address_is_ip4 (&a->addr.ip))
715         return a->len > 32 ? 1 : 0;
716       else
717         return a->len > 128 ? 1 : 0;
718     }
719
720   return 1;
721 }
722
723 static void
724 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
725 {
726   eid->type = vat_eid->type;
727   switch (eid->type)
728     {
729     case EID_TYPE_API_PREFIX:
730       if (ip46_address_is_ip4 (&vat_eid->addr.ip))
731         {
732           clib_memcpy (&eid->address.prefix.address.un.ip4,
733                        &vat_eid->addr.ip.ip4, 4);
734           eid->address.prefix.address.af = ADDRESS_IP4;
735           eid->address.prefix.len = vat_eid->len;
736         }
737       else
738         {
739           clib_memcpy (&eid->address.prefix.address.un.ip6,
740                        &vat_eid->addr.ip.ip6, 16);
741           eid->address.prefix.address.af = ADDRESS_IP6;
742           eid->address.prefix.len = vat_eid->len;
743         }
744       return;
745     case EID_TYPE_API_MAC:
746       clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
747                    sizeof (eid->address.mac));
748       return;
749     case EID_TYPE_API_NSH:
750       clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
751                    sizeof (eid->address.nsh));
752       return;
753     default:
754       ASSERT (0);
755       return;
756     }
757 }
758
759 static int
760 api_one_add_del_locator_set (vat_main_t * vam)
761 {
762   unformat_input_t *input = vam->input;
763   vl_api_one_add_del_locator_set_t *mp;
764   u8 is_add = 1;
765   u8 *locator_set_name = NULL;
766   u8 locator_set_name_set = 0;
767   vl_api_local_locator_t locator, *locators = 0;
768   u32 sw_if_index, priority, weight;
769   u32 data_len = 0;
770
771   int ret;
772   /* Parse args required to build the message */
773   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
774     {
775       if (unformat (input, "del"))
776         {
777           is_add = 0;
778         }
779       else if (unformat (input, "locator-set %s", &locator_set_name))
780         {
781           locator_set_name_set = 1;
782         }
783       else if (unformat (input, "sw_if_index %u p %u w %u",
784                          &sw_if_index, &priority, &weight))
785         {
786           locator.sw_if_index = htonl (sw_if_index);
787           locator.priority = priority;
788           locator.weight = weight;
789           vec_add1 (locators, locator);
790         }
791       else
792         if (unformat
793             (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
794              &sw_if_index, &priority, &weight))
795         {
796           locator.sw_if_index = htonl (sw_if_index);
797           locator.priority = priority;
798           locator.weight = weight;
799           vec_add1 (locators, locator);
800         }
801       else
802         break;
803     }
804
805   if (locator_set_name_set == 0)
806     {
807       errmsg ("missing locator-set name");
808       vec_free (locators);
809       return -99;
810     }
811
812   if (vec_len (locator_set_name) > 64)
813     {
814       errmsg ("locator-set name too long");
815       vec_free (locator_set_name);
816       vec_free (locators);
817       return -99;
818     }
819   vec_add1 (locator_set_name, 0);
820
821   data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
822
823   /* Construct the API message */
824   M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
825
826   mp->is_add = is_add;
827   clib_memcpy (mp->locator_set_name, locator_set_name,
828                vec_len (locator_set_name));
829   vec_free (locator_set_name);
830
831   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
832   if (locators)
833     clib_memcpy (mp->locators, locators, data_len);
834   vec_free (locators);
835
836   /* send it... */
837   S (mp);
838
839   /* Wait for a reply... */
840   W (ret);
841   return ret;
842 }
843
844 #define api_lisp_add_del_locator_set api_one_add_del_locator_set
845
846 static int
847 api_one_add_del_locator (vat_main_t * vam)
848 {
849   unformat_input_t *input = vam->input;
850   vl_api_one_add_del_locator_t *mp;
851   u32 tmp_if_index = ~0;
852   u32 sw_if_index = ~0;
853   u8 sw_if_index_set = 0;
854   u8 sw_if_index_if_name_set = 0;
855   u32 priority = ~0;
856   u8 priority_set = 0;
857   u32 weight = ~0;
858   u8 weight_set = 0;
859   u8 is_add = 1;
860   u8 *locator_set_name = NULL;
861   u8 locator_set_name_set = 0;
862   int ret;
863
864   /* Parse args required to build the message */
865   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
866     {
867       if (unformat (input, "del"))
868         {
869           is_add = 0;
870         }
871       else if (unformat (input, "locator-set %s", &locator_set_name))
872         {
873           locator_set_name_set = 1;
874         }
875       else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
876                          &tmp_if_index))
877         {
878           sw_if_index_if_name_set = 1;
879           sw_if_index = tmp_if_index;
880         }
881       else if (unformat (input, "sw_if_index %d", &tmp_if_index))
882         {
883           sw_if_index_set = 1;
884           sw_if_index = tmp_if_index;
885         }
886       else if (unformat (input, "p %d", &priority))
887         {
888           priority_set = 1;
889         }
890       else if (unformat (input, "w %d", &weight))
891         {
892           weight_set = 1;
893         }
894       else
895         break;
896     }
897
898   if (locator_set_name_set == 0)
899     {
900       errmsg ("missing locator-set name");
901       return -99;
902     }
903
904   if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
905     {
906       errmsg ("missing sw_if_index");
907       vec_free (locator_set_name);
908       return -99;
909     }
910
911   if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
912     {
913       errmsg ("cannot use both params interface name and sw_if_index");
914       vec_free (locator_set_name);
915       return -99;
916     }
917
918   if (priority_set == 0)
919     {
920       errmsg ("missing locator-set priority");
921       vec_free (locator_set_name);
922       return -99;
923     }
924
925   if (weight_set == 0)
926     {
927       errmsg ("missing locator-set weight");
928       vec_free (locator_set_name);
929       return -99;
930     }
931
932   if (vec_len (locator_set_name) > 64)
933     {
934       errmsg ("locator-set name too long");
935       vec_free (locator_set_name);
936       return -99;
937     }
938   vec_add1 (locator_set_name, 0);
939
940   /* Construct the API message */
941   M (ONE_ADD_DEL_LOCATOR, mp);
942
943   mp->is_add = is_add;
944   mp->sw_if_index = ntohl (sw_if_index);
945   mp->priority = priority;
946   mp->weight = weight;
947   clib_memcpy (mp->locator_set_name, locator_set_name,
948                vec_len (locator_set_name));
949   vec_free (locator_set_name);
950
951   /* send it... */
952   S (mp);
953
954   /* Wait for a reply... */
955   W (ret);
956   return ret;
957 }
958
959 #define api_lisp_add_del_locator api_one_add_del_locator
960
961 static int
962 api_one_add_del_local_eid (vat_main_t * vam)
963 {
964   unformat_input_t *input = vam->input;
965   vl_api_one_add_del_local_eid_t *mp;
966   u8 is_add = 1;
967   u8 eid_set = 0;
968   lisp_eid_vat_t _eid, *eid = &_eid;
969   u8 *locator_set_name = 0;
970   u8 locator_set_name_set = 0;
971   u32 vni = 0;
972   u16 key_id = 0;
973   u8 *key = 0;
974   int ret;
975
976   /* Parse args required to build the message */
977   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
978     {
979       if (unformat (input, "del"))
980         {
981           is_add = 0;
982         }
983       else if (unformat (input, "vni %d", &vni))
984         {
985           ;
986         }
987       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
988         {
989           eid_set = 1;
990         }
991       else if (unformat (input, "locator-set %s", &locator_set_name))
992         {
993           locator_set_name_set = 1;
994         }
995       else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
996         ;
997       else if (unformat (input, "secret-key %_%v%_", &key))
998         ;
999       else
1000         break;
1001     }
1002
1003   if (locator_set_name_set == 0)
1004     {
1005       errmsg ("missing locator-set name");
1006       return -99;
1007     }
1008
1009   if (0 == eid_set)
1010     {
1011       errmsg ("EID address not set!");
1012       vec_free (locator_set_name);
1013       return -99;
1014     }
1015
1016   if (key && (0 == key_id))
1017     {
1018       errmsg ("invalid key_id!");
1019       return -99;
1020     }
1021
1022   if (vec_len (key) > 64)
1023     {
1024       errmsg ("key too long");
1025       vec_free (key);
1026       return -99;
1027     }
1028
1029   if (vec_len (locator_set_name) > 64)
1030     {
1031       errmsg ("locator-set name too long");
1032       vec_free (locator_set_name);
1033       return -99;
1034     }
1035   vec_add1 (locator_set_name, 0);
1036
1037   /* Construct the API message */
1038   M (ONE_ADD_DEL_LOCAL_EID, mp);
1039
1040   mp->is_add = is_add;
1041   lisp_eid_put_vat (&mp->eid, eid);
1042   mp->vni = clib_host_to_net_u32 (vni);
1043   mp->key.id = key_id;
1044   clib_memcpy (mp->locator_set_name, locator_set_name,
1045                vec_len (locator_set_name));
1046   clib_memcpy (mp->key.key, key, vec_len (key));
1047
1048   vec_free (locator_set_name);
1049   vec_free (key);
1050
1051   /* send it... */
1052   S (mp);
1053
1054   /* Wait for a reply... */
1055   W (ret);
1056   return ret;
1057 }
1058
1059 static int
1060 api_one_add_del_map_server (vat_main_t * vam)
1061 {
1062   unformat_input_t *input = vam->input;
1063   vl_api_one_add_del_map_server_t *mp;
1064   u8 is_add = 1;
1065   u8 ipv4_set = 0;
1066   u8 ipv6_set = 0;
1067   ip4_address_t ipv4;
1068   ip6_address_t ipv6;
1069   int ret;
1070
1071   /* Parse args required to build the message */
1072   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1073     {
1074       if (unformat (input, "del"))
1075         {
1076           is_add = 0;
1077         }
1078       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1079         {
1080           ipv4_set = 1;
1081         }
1082       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1083         {
1084           ipv6_set = 1;
1085         }
1086       else
1087         break;
1088     }
1089
1090   if (ipv4_set && ipv6_set)
1091     {
1092       errmsg ("both eid v4 and v6 addresses set");
1093       return -99;
1094     }
1095
1096   if (!ipv4_set && !ipv6_set)
1097     {
1098       errmsg ("eid addresses not set");
1099       return -99;
1100     }
1101
1102   /* Construct the API message */
1103   M (ONE_ADD_DEL_MAP_SERVER, mp);
1104
1105   mp->is_add = is_add;
1106   if (ipv6_set)
1107     {
1108       mp->ip_address.af = 1;
1109       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1110     }
1111   else
1112     {
1113       mp->ip_address.af = 0;
1114       clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
1115     }
1116
1117   /* send it... */
1118   S (mp);
1119
1120   /* Wait for a reply... */
1121   W (ret);
1122   return ret;
1123 }
1124
1125 #define api_lisp_add_del_map_server api_one_add_del_map_server
1126
1127 static int
1128 api_one_add_del_map_resolver (vat_main_t * vam)
1129 {
1130   unformat_input_t *input = vam->input;
1131   vl_api_one_add_del_map_resolver_t *mp;
1132   u8 is_add = 1;
1133   u8 ipv4_set = 0;
1134   u8 ipv6_set = 0;
1135   ip4_address_t ipv4;
1136   ip6_address_t ipv6;
1137   int ret;
1138
1139   /* Parse args required to build the message */
1140   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1141     {
1142       if (unformat (input, "del"))
1143         {
1144           is_add = 0;
1145         }
1146       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1147         {
1148           ipv4_set = 1;
1149         }
1150       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1151         {
1152           ipv6_set = 1;
1153         }
1154       else
1155         break;
1156     }
1157
1158   if (ipv4_set && ipv6_set)
1159     {
1160       errmsg ("both eid v4 and v6 addresses set");
1161       return -99;
1162     }
1163
1164   if (!ipv4_set && !ipv6_set)
1165     {
1166       errmsg ("eid addresses not set");
1167       return -99;
1168     }
1169
1170   /* Construct the API message */
1171   M (ONE_ADD_DEL_MAP_RESOLVER, mp);
1172
1173   mp->is_add = is_add;
1174   if (ipv6_set)
1175     {
1176       mp->ip_address.af = 1;
1177       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1178     }
1179   else
1180     {
1181       mp->ip_address.af = 0;
1182       clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
1183     }
1184
1185   /* send it... */
1186   S (mp);
1187
1188   /* Wait for a reply... */
1189   W (ret);
1190   return ret;
1191 }
1192
1193 static int
1194 api_one_rloc_probe_enable_disable (vat_main_t * vam)
1195 {
1196   unformat_input_t *input = vam->input;
1197   vl_api_one_rloc_probe_enable_disable_t *mp;
1198   u8 is_set = 0;
1199   u8 is_enable = 0;
1200   int ret;
1201
1202   /* Parse args required to build the message */
1203   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1204     {
1205       if (unformat (input, "enable"))
1206         {
1207           is_set = 1;
1208           is_enable = 1;
1209         }
1210       else if (unformat (input, "disable"))
1211         is_set = 1;
1212       else
1213         break;
1214     }
1215
1216   if (!is_set)
1217     {
1218       errmsg ("Value not set");
1219       return -99;
1220     }
1221
1222   /* Construct the API message */
1223   M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
1224
1225   mp->is_enable = is_enable;
1226
1227   /* send it... */
1228   S (mp);
1229
1230   /* Wait for a reply... */
1231   W (ret);
1232   return ret;
1233 }
1234
1235 #define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
1236
1237 static int
1238 api_one_map_register_enable_disable (vat_main_t * vam)
1239 {
1240   unformat_input_t *input = vam->input;
1241   vl_api_one_map_register_enable_disable_t *mp;
1242   u8 is_set = 0;
1243   u8 is_enable = 0;
1244   int ret;
1245
1246   /* Parse args required to build the message */
1247   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1248     {
1249       if (unformat (input, "enable"))
1250         {
1251           is_set = 1;
1252           is_enable = 1;
1253         }
1254       else if (unformat (input, "disable"))
1255         is_set = 1;
1256       else
1257         break;
1258     }
1259
1260   if (!is_set)
1261     {
1262       errmsg ("Value not set");
1263       return -99;
1264     }
1265
1266   /* Construct the API message */
1267   M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
1268
1269   mp->is_enable = is_enable;
1270
1271   /* send it... */
1272   S (mp);
1273
1274   /* Wait for a reply... */
1275   W (ret);
1276   return ret;
1277 }
1278
1279 #define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
1280
1281 static int
1282 api_one_enable_disable (vat_main_t * vam)
1283 {
1284   unformat_input_t *input = vam->input;
1285   vl_api_one_enable_disable_t *mp;
1286   u8 is_set = 0;
1287   u8 is_enable = 0;
1288   int ret;
1289
1290   /* Parse args required to build the message */
1291   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1292     {
1293       if (unformat (input, "enable"))
1294         {
1295           is_set = 1;
1296           is_enable = 1;
1297         }
1298       else if (unformat (input, "disable"))
1299         {
1300           is_set = 1;
1301         }
1302       else
1303         break;
1304     }
1305
1306   if (!is_set)
1307     {
1308       errmsg ("Value not set");
1309       return -99;
1310     }
1311
1312   /* Construct the API message */
1313   M (ONE_ENABLE_DISABLE, mp);
1314
1315   mp->is_enable = is_enable;
1316
1317   /* send it... */
1318   S (mp);
1319
1320   /* Wait for a reply... */
1321   W (ret);
1322   return ret;
1323 }
1324
1325 #define api_lisp_enable_disable api_one_enable_disable
1326
1327 static int
1328 api_one_enable_disable_xtr_mode (vat_main_t * vam)
1329 {
1330   unformat_input_t *input = vam->input;
1331   vl_api_one_enable_disable_xtr_mode_t *mp;
1332   u8 is_set = 0;
1333   u8 is_enable = 0;
1334   int ret;
1335
1336   /* Parse args required to build the message */
1337   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1338     {
1339       if (unformat (input, "enable"))
1340         {
1341           is_set = 1;
1342           is_enable = 1;
1343         }
1344       else if (unformat (input, "disable"))
1345         {
1346           is_set = 1;
1347         }
1348       else
1349         break;
1350     }
1351
1352   if (!is_set)
1353     {
1354       errmsg ("Value not set");
1355       return -99;
1356     }
1357
1358   /* Construct the API message */
1359   M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
1360
1361   mp->is_enable = is_enable;
1362
1363   /* send it... */
1364   S (mp);
1365
1366   /* Wait for a reply... */
1367   W (ret);
1368   return ret;
1369 }
1370
1371 static int
1372 api_one_show_xtr_mode (vat_main_t * vam)
1373 {
1374   vl_api_one_show_xtr_mode_t *mp;
1375   int ret;
1376
1377   /* Construct the API message */
1378   M (ONE_SHOW_XTR_MODE, mp);
1379
1380   /* send it... */
1381   S (mp);
1382
1383   /* Wait for a reply... */
1384   W (ret);
1385   return ret;
1386 }
1387
1388 static int
1389 api_one_enable_disable_pitr_mode (vat_main_t * vam)
1390 {
1391   unformat_input_t *input = vam->input;
1392   vl_api_one_enable_disable_pitr_mode_t *mp;
1393   u8 is_set = 0;
1394   u8 is_enable = 0;
1395   int ret;
1396
1397   /* Parse args required to build the message */
1398   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1399     {
1400       if (unformat (input, "enable"))
1401         {
1402           is_set = 1;
1403           is_enable = 1;
1404         }
1405       else if (unformat (input, "disable"))
1406         {
1407           is_set = 1;
1408         }
1409       else
1410         break;
1411     }
1412
1413   if (!is_set)
1414     {
1415       errmsg ("Value not set");
1416       return -99;
1417     }
1418
1419   /* Construct the API message */
1420   M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
1421
1422   mp->is_enable = is_enable;
1423
1424   /* send it... */
1425   S (mp);
1426
1427   /* Wait for a reply... */
1428   W (ret);
1429   return ret;
1430 }
1431
1432 static int
1433 api_one_show_pitr_mode (vat_main_t * vam)
1434 {
1435   vl_api_one_show_pitr_mode_t *mp;
1436   int ret;
1437
1438   /* Construct the API message */
1439   M (ONE_SHOW_PITR_MODE, mp);
1440
1441   /* send it... */
1442   S (mp);
1443
1444   /* Wait for a reply... */
1445   W (ret);
1446   return ret;
1447 }
1448
1449 static int
1450 api_one_enable_disable_petr_mode (vat_main_t * vam)
1451 {
1452   unformat_input_t *input = vam->input;
1453   vl_api_one_enable_disable_petr_mode_t *mp;
1454   u8 is_set = 0;
1455   u8 is_enable = 0;
1456   int ret;
1457
1458   /* Parse args required to build the message */
1459   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1460     {
1461       if (unformat (input, "enable"))
1462         {
1463           is_set = 1;
1464           is_enable = 1;
1465         }
1466       else if (unformat (input, "disable"))
1467         {
1468           is_set = 1;
1469         }
1470       else
1471         break;
1472     }
1473
1474   if (!is_set)
1475     {
1476       errmsg ("Value not set");
1477       return -99;
1478     }
1479
1480   /* Construct the API message */
1481   M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
1482
1483   mp->is_enable = is_enable;
1484
1485   /* send it... */
1486   S (mp);
1487
1488   /* Wait for a reply... */
1489   W (ret);
1490   return ret;
1491 }
1492
1493 static int
1494 api_one_show_petr_mode (vat_main_t * vam)
1495 {
1496   vl_api_one_show_petr_mode_t *mp;
1497   int ret;
1498
1499   /* Construct the API message */
1500   M (ONE_SHOW_PETR_MODE, mp);
1501
1502   /* send it... */
1503   S (mp);
1504
1505   /* Wait for a reply... */
1506   W (ret);
1507   return ret;
1508 }
1509
1510 static int
1511 api_show_one_map_register_state (vat_main_t * vam)
1512 {
1513   vl_api_show_one_map_register_state_t *mp;
1514   int ret;
1515
1516   M (SHOW_ONE_MAP_REGISTER_STATE, mp);
1517
1518   /* send */
1519   S (mp);
1520
1521   /* wait for reply */
1522   W (ret);
1523   return ret;
1524 }
1525
1526 #define api_show_lisp_map_register_state api_show_one_map_register_state
1527
1528 static int
1529 api_show_one_rloc_probe_state (vat_main_t * vam)
1530 {
1531   vl_api_show_one_rloc_probe_state_t *mp;
1532   int ret;
1533
1534   M (SHOW_ONE_RLOC_PROBE_STATE, mp);
1535
1536   /* send */
1537   S (mp);
1538
1539   /* wait for reply */
1540   W (ret);
1541   return ret;
1542 }
1543
1544 #define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
1545
1546 static int
1547 api_one_add_del_ndp_entry (vat_main_t * vam)
1548 {
1549   vl_api_one_add_del_ndp_entry_t *mp;
1550   unformat_input_t *input = vam->input;
1551   u8 is_add = 1;
1552   u8 mac_set = 0;
1553   u8 bd_set = 0;
1554   u8 ip_set = 0;
1555   u8 mac[6] = { 0, };
1556   u8 ip6[16] = { 0, };
1557   u32 bd = ~0;
1558   int ret;
1559
1560   /* Parse args required to build the message */
1561   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1562     {
1563       if (unformat (input, "del"))
1564         is_add = 0;
1565       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1566         mac_set = 1;
1567       else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
1568         ip_set = 1;
1569       else if (unformat (input, "bd %d", &bd))
1570         bd_set = 1;
1571       else
1572         {
1573           errmsg ("parse error '%U'", format_unformat_error, input);
1574           return -99;
1575         }
1576     }
1577
1578   if (!bd_set || !ip_set || (!mac_set && is_add))
1579     {
1580       errmsg ("Missing BD, IP or MAC!");
1581       return -99;
1582     }
1583
1584   M (ONE_ADD_DEL_NDP_ENTRY, mp);
1585   mp->is_add = is_add;
1586   clib_memcpy (&mp->entry.mac, mac, 6);
1587   mp->bd = clib_host_to_net_u32 (bd);
1588   clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6));
1589
1590   /* send */
1591   S (mp);
1592
1593   /* wait for reply */
1594   W (ret);
1595   return ret;
1596 }
1597
1598 static int
1599 api_one_add_del_l2_arp_entry (vat_main_t * vam)
1600 {
1601   vl_api_one_add_del_l2_arp_entry_t *mp;
1602   unformat_input_t *input = vam->input;
1603   u8 is_add = 1;
1604   u8 mac_set = 0;
1605   u8 bd_set = 0;
1606   u8 ip_set = 0;
1607   u8 mac[6] = { 0, };
1608   u32 ip4 = 0, bd = ~0;
1609   int ret;
1610
1611   /* Parse args required to build the message */
1612   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1613     {
1614       if (unformat (input, "del"))
1615         is_add = 0;
1616       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1617         mac_set = 1;
1618       else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
1619         ip_set = 1;
1620       else if (unformat (input, "bd %d", &bd))
1621         bd_set = 1;
1622       else
1623         {
1624           errmsg ("parse error '%U'", format_unformat_error, input);
1625           return -99;
1626         }
1627     }
1628
1629   if (!bd_set || !ip_set || (!mac_set && is_add))
1630     {
1631       errmsg ("Missing BD, IP or MAC!");
1632       return -99;
1633     }
1634
1635   M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
1636   mp->is_add = is_add;
1637   clib_memcpy (&mp->entry.mac, mac, 6);
1638   mp->bd = clib_host_to_net_u32 (bd);
1639   clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4));
1640
1641   /* send */
1642   S (mp);
1643
1644   /* wait for reply */
1645   W (ret);
1646   return ret;
1647 }
1648
1649 static int
1650 api_one_ndp_bd_get (vat_main_t * vam)
1651 {
1652   vl_api_one_ndp_bd_get_t *mp;
1653   int ret;
1654
1655   M (ONE_NDP_BD_GET, mp);
1656
1657   /* send */
1658   S (mp);
1659
1660   /* wait for reply */
1661   W (ret);
1662   return ret;
1663 }
1664
1665 static int
1666 api_one_ndp_entries_get (vat_main_t * vam)
1667 {
1668   vl_api_one_ndp_entries_get_t *mp;
1669   unformat_input_t *input = vam->input;
1670   u8 bd_set = 0;
1671   u32 bd = ~0;
1672   int ret;
1673
1674   /* Parse args required to build the message */
1675   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1676     {
1677       if (unformat (input, "bd %d", &bd))
1678         bd_set = 1;
1679       else
1680         {
1681           errmsg ("parse error '%U'", format_unformat_error, input);
1682           return -99;
1683         }
1684     }
1685
1686   if (!bd_set)
1687     {
1688       errmsg ("Expected bridge domain!");
1689       return -99;
1690     }
1691
1692   M (ONE_NDP_ENTRIES_GET, mp);
1693   mp->bd = clib_host_to_net_u32 (bd);
1694
1695   /* send */
1696   S (mp);
1697
1698   /* wait for reply */
1699   W (ret);
1700   return ret;
1701 }
1702
1703 static int
1704 api_one_l2_arp_bd_get (vat_main_t * vam)
1705 {
1706   vl_api_one_l2_arp_bd_get_t *mp;
1707   int ret;
1708
1709   M (ONE_L2_ARP_BD_GET, mp);
1710
1711   /* send */
1712   S (mp);
1713
1714   /* wait for reply */
1715   W (ret);
1716   return ret;
1717 }
1718
1719 static int
1720 api_one_l2_arp_entries_get (vat_main_t * vam)
1721 {
1722   vl_api_one_l2_arp_entries_get_t *mp;
1723   unformat_input_t *input = vam->input;
1724   u8 bd_set = 0;
1725   u32 bd = ~0;
1726   int ret;
1727
1728   /* Parse args required to build the message */
1729   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1730     {
1731       if (unformat (input, "bd %d", &bd))
1732         bd_set = 1;
1733       else
1734         {
1735           errmsg ("parse error '%U'", format_unformat_error, input);
1736           return -99;
1737         }
1738     }
1739
1740   if (!bd_set)
1741     {
1742       errmsg ("Expected bridge domain!");
1743       return -99;
1744     }
1745
1746   M (ONE_L2_ARP_ENTRIES_GET, mp);
1747   mp->bd = clib_host_to_net_u32 (bd);
1748
1749   /* send */
1750   S (mp);
1751
1752   /* wait for reply */
1753   W (ret);
1754   return ret;
1755 }
1756
1757 static int
1758 api_one_stats_enable_disable (vat_main_t * vam)
1759 {
1760   vl_api_one_stats_enable_disable_t *mp;
1761   unformat_input_t *input = vam->input;
1762   u8 is_set = 0;
1763   u8 is_enable = 0;
1764   int ret;
1765
1766   /* Parse args required to build the message */
1767   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1768     {
1769       if (unformat (input, "enable"))
1770         {
1771           is_set = 1;
1772           is_enable = 1;
1773         }
1774       else if (unformat (input, "disable"))
1775         {
1776           is_set = 1;
1777         }
1778       else
1779         break;
1780     }
1781
1782   if (!is_set)
1783     {
1784       errmsg ("Value not set");
1785       return -99;
1786     }
1787
1788   M (ONE_STATS_ENABLE_DISABLE, mp);
1789   mp->is_enable = is_enable;
1790
1791   /* send */
1792   S (mp);
1793
1794   /* wait for reply */
1795   W (ret);
1796   return ret;
1797 }
1798
1799 static int
1800 api_show_one_stats_enable_disable (vat_main_t * vam)
1801 {
1802   vl_api_show_one_stats_enable_disable_t *mp;
1803   int ret;
1804
1805   M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
1806
1807   /* send */
1808   S (mp);
1809
1810   /* wait for reply */
1811   W (ret);
1812   return ret;
1813 }
1814
1815 static int
1816 api_show_one_map_request_mode (vat_main_t * vam)
1817 {
1818   vl_api_show_one_map_request_mode_t *mp;
1819   int ret;
1820
1821   M (SHOW_ONE_MAP_REQUEST_MODE, mp);
1822
1823   /* send */
1824   S (mp);
1825
1826   /* wait for reply */
1827   W (ret);
1828   return ret;
1829 }
1830
1831 #define api_show_lisp_map_request_mode api_show_one_map_request_mode
1832
1833 static int
1834 api_one_map_request_mode (vat_main_t * vam)
1835 {
1836   unformat_input_t *input = vam->input;
1837   vl_api_one_map_request_mode_t *mp;
1838   u8 mode = 0;
1839   int ret;
1840
1841   /* Parse args required to build the message */
1842   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1843     {
1844       if (unformat (input, "dst-only"))
1845         mode = 0;
1846       else if (unformat (input, "src-dst"))
1847         mode = 1;
1848       else
1849         {
1850           errmsg ("parse error '%U'", format_unformat_error, input);
1851           return -99;
1852         }
1853     }
1854
1855   M (ONE_MAP_REQUEST_MODE, mp);
1856
1857   mp->mode = mode;
1858
1859   /* send */
1860   S (mp);
1861
1862   /* wait for reply */
1863   W (ret);
1864   return ret;
1865 }
1866
1867 #define api_lisp_map_request_mode api_one_map_request_mode
1868
1869 /**
1870  * Enable/disable ONE proxy ITR.
1871  *
1872  * @param vam vpp API test context
1873  * @return return code
1874  */
1875 static int
1876 api_one_pitr_set_locator_set (vat_main_t * vam)
1877 {
1878   u8 ls_name_set = 0;
1879   unformat_input_t *input = vam->input;
1880   vl_api_one_pitr_set_locator_set_t *mp;
1881   u8 is_add = 1;
1882   u8 *ls_name = 0;
1883   int ret;
1884
1885   /* Parse args required to build the message */
1886   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1887     {
1888       if (unformat (input, "del"))
1889         is_add = 0;
1890       else if (unformat (input, "locator-set %s", &ls_name))
1891         ls_name_set = 1;
1892       else
1893         {
1894           errmsg ("parse error '%U'", format_unformat_error, input);
1895           return -99;
1896         }
1897     }
1898
1899   if (!ls_name_set)
1900     {
1901       errmsg ("locator-set name not set!");
1902       return -99;
1903     }
1904
1905   M (ONE_PITR_SET_LOCATOR_SET, mp);
1906
1907   mp->is_add = is_add;
1908   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1909   vec_free (ls_name);
1910
1911   /* send */
1912   S (mp);
1913
1914   /* wait for reply */
1915   W (ret);
1916   return ret;
1917 }
1918
1919 #define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
1920
1921 static int
1922 api_one_nsh_set_locator_set (vat_main_t * vam)
1923 {
1924   u8 ls_name_set = 0;
1925   unformat_input_t *input = vam->input;
1926   vl_api_one_nsh_set_locator_set_t *mp;
1927   u8 is_add = 1;
1928   u8 *ls_name = 0;
1929   int ret;
1930
1931   /* Parse args required to build the message */
1932   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1933     {
1934       if (unformat (input, "del"))
1935         is_add = 0;
1936       else if (unformat (input, "ls %s", &ls_name))
1937         ls_name_set = 1;
1938       else
1939         {
1940           errmsg ("parse error '%U'", format_unformat_error, input);
1941           return -99;
1942         }
1943     }
1944
1945   if (!ls_name_set && is_add)
1946     {
1947       errmsg ("locator-set name not set!");
1948       return -99;
1949     }
1950
1951   M (ONE_NSH_SET_LOCATOR_SET, mp);
1952
1953   mp->is_add = is_add;
1954   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1955   vec_free (ls_name);
1956
1957   /* send */
1958   S (mp);
1959
1960   /* wait for reply */
1961   W (ret);
1962   return ret;
1963 }
1964
1965 static int
1966 api_show_one_pitr (vat_main_t * vam)
1967 {
1968   vl_api_show_one_pitr_t *mp;
1969   int ret;
1970
1971   if (!vam->json_output)
1972     {
1973       print (vam->ofp, "%=20s", "lisp status:");
1974     }
1975
1976   M (SHOW_ONE_PITR, mp);
1977   /* send it... */
1978   S (mp);
1979
1980   /* Wait for a reply... */
1981   W (ret);
1982   return ret;
1983 }
1984
1985 #define api_show_lisp_pitr api_show_one_pitr
1986
1987 static int
1988 api_one_use_petr (vat_main_t * vam)
1989 {
1990   unformat_input_t *input = vam->input;
1991   vl_api_one_use_petr_t *mp;
1992   u8 is_add = 0;
1993   ip_address_t ip;
1994   int ret;
1995
1996   clib_memset (&ip, 0, sizeof (ip));
1997
1998   /* Parse args required to build the message */
1999   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2000     {
2001       if (unformat (input, "disable"))
2002         is_add = 0;
2003       else
2004         if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
2005         {
2006           is_add = 1;
2007           ip_addr_version (&ip) = AF_IP4;
2008         }
2009       else
2010         if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
2011         {
2012           is_add = 1;
2013           ip_addr_version (&ip) = AF_IP6;
2014         }
2015       else
2016         {
2017           errmsg ("parse error '%U'", format_unformat_error, input);
2018           return -99;
2019         }
2020     }
2021
2022   M (ONE_USE_PETR, mp);
2023
2024   mp->is_add = is_add;
2025   if (is_add)
2026     {
2027       mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
2028       if (mp->ip_address.af)
2029         clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
2030       else
2031         clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
2032     }
2033
2034   /* send */
2035   S (mp);
2036
2037   /* wait for reply */
2038   W (ret);
2039   return ret;
2040 }
2041
2042 #define api_lisp_use_petr api_one_use_petr
2043
2044 static int
2045 api_show_one_nsh_mapping (vat_main_t * vam)
2046 {
2047   vl_api_show_one_use_petr_t *mp;
2048   int ret;
2049
2050   if (!vam->json_output)
2051     {
2052       print (vam->ofp, "%=20s", "local ONE NSH mapping:");
2053     }
2054
2055   M (SHOW_ONE_NSH_MAPPING, mp);
2056   /* send it... */
2057   S (mp);
2058
2059   /* Wait for a reply... */
2060   W (ret);
2061   return ret;
2062 }
2063
2064 static int
2065 api_show_one_use_petr (vat_main_t * vam)
2066 {
2067   vl_api_show_one_use_petr_t *mp;
2068   int ret;
2069
2070   if (!vam->json_output)
2071     {
2072       print (vam->ofp, "%=20s", "Proxy-ETR status:");
2073     }
2074
2075   M (SHOW_ONE_USE_PETR, mp);
2076   /* send it... */
2077   S (mp);
2078
2079   /* Wait for a reply... */
2080   W (ret);
2081   return ret;
2082 }
2083
2084 #define api_show_lisp_use_petr api_show_one_use_petr
2085
2086 /**
2087  * Add/delete mapping between vni and vrf
2088  */
2089 static int
2090 api_one_eid_table_add_del_map (vat_main_t * vam)
2091 {
2092   unformat_input_t *input = vam->input;
2093   vl_api_one_eid_table_add_del_map_t *mp;
2094   u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
2095   u32 vni, vrf, bd_index;
2096   int ret;
2097
2098   /* Parse args required to build the message */
2099   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2100     {
2101       if (unformat (input, "del"))
2102         is_add = 0;
2103       else if (unformat (input, "vrf %d", &vrf))
2104         vrf_set = 1;
2105       else if (unformat (input, "bd_index %d", &bd_index))
2106         bd_index_set = 1;
2107       else if (unformat (input, "vni %d", &vni))
2108         vni_set = 1;
2109       else
2110         break;
2111     }
2112
2113   if (!vni_set || (!vrf_set && !bd_index_set))
2114     {
2115       errmsg ("missing arguments!");
2116       return -99;
2117     }
2118
2119   if (vrf_set && bd_index_set)
2120     {
2121       errmsg ("error: both vrf and bd entered!");
2122       return -99;
2123     }
2124
2125   M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
2126
2127   mp->is_add = is_add;
2128   mp->vni = htonl (vni);
2129   mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
2130   mp->is_l2 = bd_index_set;
2131
2132   /* send */
2133   S (mp);
2134
2135   /* wait for reply */
2136   W (ret);
2137   return ret;
2138 }
2139
2140 #define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
2141
2142 uword
2143 unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
2144 {
2145   u32 *action = va_arg (*args, u32 *);
2146   u8 *s = 0;
2147
2148   if (unformat (input, "%s", &s))
2149     {
2150       if (!strcmp ((char *) s, "no-action"))
2151         action[0] = 0;
2152       else if (!strcmp ((char *) s, "natively-forward"))
2153         action[0] = 1;
2154       else if (!strcmp ((char *) s, "send-map-request"))
2155         action[0] = 2;
2156       else if (!strcmp ((char *) s, "drop"))
2157         action[0] = 3;
2158       else
2159         {
2160           clib_warning ("invalid action: '%s'", s);
2161           action[0] = 3;
2162         }
2163     }
2164   else
2165     return 0;
2166
2167   vec_free (s);
2168   return 1;
2169 }
2170
2171 /**
2172  * Add/del remote mapping to/from ONE control plane
2173  *
2174  * @param vam vpp API test context
2175  * @return return code
2176  */
2177 static int
2178 api_one_add_del_remote_mapping (vat_main_t * vam)
2179 {
2180   unformat_input_t *input = vam->input;
2181   vl_api_one_add_del_remote_mapping_t *mp;
2182   u32 vni = 0;
2183   lisp_eid_vat_t _eid, *eid = &_eid;
2184   lisp_eid_vat_t _seid, *seid = &_seid;
2185   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
2186   u32 action = ~0, p, w, data_len;
2187   ip4_address_t rloc4;
2188   ip6_address_t rloc6;
2189   vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
2190   int ret;
2191
2192   clib_memset (&rloc, 0, sizeof (rloc));
2193
2194   /* Parse args required to build the message */
2195   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2196     {
2197       if (unformat (input, "del-all"))
2198         {
2199           del_all = 1;
2200         }
2201       else if (unformat (input, "del"))
2202         {
2203           is_add = 0;
2204         }
2205       else if (unformat (input, "add"))
2206         {
2207           is_add = 1;
2208         }
2209       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
2210         {
2211           eid_set = 1;
2212         }
2213       else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
2214         {
2215           seid_set = 1;
2216         }
2217       else if (unformat (input, "vni %d", &vni))
2218         {
2219           ;
2220         }
2221       else if (unformat (input, "p %d w %d", &p, &w))
2222         {
2223           if (!curr_rloc)
2224             {
2225               errmsg ("No RLOC configured for setting priority/weight!");
2226               return -99;
2227             }
2228           curr_rloc->priority = p;
2229           curr_rloc->weight = w;
2230         }
2231       else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
2232         {
2233           rloc.ip_address.af = 0;
2234           clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
2235           vec_add1 (rlocs, rloc);
2236           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2237         }
2238       else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
2239         {
2240           rloc.ip_address.af = 1;
2241           clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
2242           vec_add1 (rlocs, rloc);
2243           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2244         }
2245       else if (unformat (input, "action %U",
2246                          unformat_negative_mapping_action, &action))
2247         {
2248           ;
2249         }
2250       else
2251         {
2252           clib_warning ("parse error '%U'", format_unformat_error, input);
2253           return -99;
2254         }
2255     }
2256
2257   if (0 == eid_set)
2258     {
2259       errmsg ("missing params!");
2260       return -99;
2261     }
2262
2263   if (is_add && (~0 == action) && 0 == vec_len (rlocs))
2264     {
2265       errmsg ("no action set for negative map-reply!");
2266       return -99;
2267     }
2268
2269   data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
2270
2271   M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
2272   mp->is_add = is_add;
2273   mp->vni = htonl (vni);
2274   mp->action = (u8) action;
2275   mp->is_src_dst = seid_set;
2276   mp->del_all = del_all;
2277   lisp_eid_put_vat (&mp->deid, eid);
2278   lisp_eid_put_vat (&mp->seid, seid);
2279
2280   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
2281   clib_memcpy (mp->rlocs, rlocs, data_len);
2282   vec_free (rlocs);
2283
2284   /* send it... */
2285   S (mp);
2286
2287   /* Wait for a reply... */
2288   W (ret);
2289   return ret;
2290 }
2291
2292 #define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
2293
2294 /**
2295  * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
2296  * forwarding entries in data-plane accordingly.
2297  *
2298  * @param vam vpp API test context
2299  * @return return code
2300  */
2301 static int
2302 api_one_add_del_adjacency (vat_main_t * vam)
2303 {
2304   unformat_input_t *input = vam->input;
2305   vl_api_one_add_del_adjacency_t *mp;
2306   u32 vni = 0;
2307   u8 is_add = 1;
2308   int ret;
2309   lisp_eid_vat_t leid, reid;
2310
2311   leid.type = reid.type = (u8) ~ 0;
2312
2313   /* Parse args required to build the message */
2314   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2315     {
2316       if (unformat (input, "del"))
2317         {
2318           is_add = 0;
2319         }
2320       else if (unformat (input, "add"))
2321         {
2322           is_add = 1;
2323         }
2324       else if (unformat (input, "reid %U/%d", unformat_ip46_address,
2325                          &reid.addr.ip, &reid.len))
2326         {
2327           reid.type = 0;        /* ipv4 */
2328         }
2329       else if (unformat (input, "reid %U", unformat_ethernet_address,
2330                          &reid.addr.mac))
2331         {
2332           reid.type = 1;        /* mac */
2333         }
2334       else if (unformat (input, "leid %U/%d", unformat_ip46_address,
2335                          &leid.addr.ip, &leid.len))
2336         {
2337           leid.type = 0;        /* ipv4 */
2338         }
2339       else if (unformat (input, "leid %U", unformat_ethernet_address,
2340                          &leid.addr.mac))
2341         {
2342           leid.type = 1;        /* mac */
2343         }
2344       else if (unformat (input, "vni %d", &vni))
2345         {
2346           ;
2347         }
2348       else
2349         {
2350           errmsg ("parse error '%U'", format_unformat_error, input);
2351           return -99;
2352         }
2353     }
2354
2355   if ((u8) ~ 0 == reid.type)
2356     {
2357       errmsg ("missing params!");
2358       return -99;
2359     }
2360
2361   if (leid.type != reid.type)
2362     {
2363       errmsg ("remote and local EIDs are of different types!");
2364       return -99;
2365     }
2366
2367   M (ONE_ADD_DEL_ADJACENCY, mp);
2368   mp->is_add = is_add;
2369   mp->vni = htonl (vni);
2370   lisp_eid_put_vat (&mp->leid, &leid);
2371   lisp_eid_put_vat (&mp->reid, &reid);
2372
2373   /* send it... */
2374   S (mp);
2375
2376   /* Wait for a reply... */
2377   W (ret);
2378   return ret;
2379 }
2380
2381 #define api_lisp_add_del_adjacency api_one_add_del_adjacency
2382
2383
2384 static int
2385 api_one_map_register_fallback_threshold (vat_main_t * vam)
2386 {
2387   unformat_input_t *input = vam->input;
2388   vl_api_one_map_register_fallback_threshold_t *mp;
2389   u32 value = 0;
2390   u8 is_set = 0;
2391   int ret;
2392
2393   /* Parse args required to build the message */
2394   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2395     {
2396       if (unformat (input, "%u", &value))
2397         is_set = 1;
2398       else
2399         {
2400           clib_warning ("parse error '%U'", format_unformat_error, input);
2401           return -99;
2402         }
2403     }
2404
2405   if (!is_set)
2406     {
2407       errmsg ("fallback threshold value is missing!");
2408       return -99;
2409     }
2410
2411   M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2412   mp->value = clib_host_to_net_u32 (value);
2413
2414   /* send it... */
2415   S (mp);
2416
2417   /* Wait for a reply... */
2418   W (ret);
2419   return ret;
2420 }
2421
2422 static int
2423 api_show_one_map_register_fallback_threshold (vat_main_t * vam)
2424 {
2425   vl_api_show_one_map_register_fallback_threshold_t *mp;
2426   int ret;
2427
2428   M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2429
2430   /* send it... */
2431   S (mp);
2432
2433   /* Wait for a reply... */
2434   W (ret);
2435   return ret;
2436 }
2437
2438 uword
2439 unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
2440 {
2441   u32 *proto = va_arg (*args, u32 *);
2442
2443   if (unformat (input, "udp"))
2444     *proto = 1;
2445   else if (unformat (input, "api"))
2446     *proto = 2;
2447   else
2448     return 0;
2449
2450   return 1;
2451 }
2452
2453 static int
2454 api_one_set_transport_protocol (vat_main_t * vam)
2455 {
2456   unformat_input_t *input = vam->input;
2457   vl_api_one_set_transport_protocol_t *mp;
2458   u8 is_set = 0;
2459   u32 protocol = 0;
2460   int ret;
2461
2462   /* Parse args required to build the message */
2463   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2464     {
2465       if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
2466         is_set = 1;
2467       else
2468         {
2469           clib_warning ("parse error '%U'", format_unformat_error, input);
2470           return -99;
2471         }
2472     }
2473
2474   if (!is_set)
2475     {
2476       errmsg ("Transport protocol missing!");
2477       return -99;
2478     }
2479
2480   M (ONE_SET_TRANSPORT_PROTOCOL, mp);
2481   mp->protocol = (u8) protocol;
2482
2483   /* send it... */
2484   S (mp);
2485
2486   /* Wait for a reply... */
2487   W (ret);
2488   return ret;
2489 }
2490
2491 static int
2492 api_one_get_transport_protocol (vat_main_t * vam)
2493 {
2494   vl_api_one_get_transport_protocol_t *mp;
2495   int ret;
2496
2497   M (ONE_GET_TRANSPORT_PROTOCOL, mp);
2498
2499   /* send it... */
2500   S (mp);
2501
2502   /* Wait for a reply... */
2503   W (ret);
2504   return ret;
2505 }
2506
2507 static int
2508 api_one_map_register_set_ttl (vat_main_t * vam)
2509 {
2510   unformat_input_t *input = vam->input;
2511   vl_api_one_map_register_set_ttl_t *mp;
2512   u32 ttl = 0;
2513   u8 is_set = 0;
2514   int ret;
2515
2516   /* Parse args required to build the message */
2517   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2518     {
2519       if (unformat (input, "%u", &ttl))
2520         is_set = 1;
2521       else
2522         {
2523           clib_warning ("parse error '%U'", format_unformat_error, input);
2524           return -99;
2525         }
2526     }
2527
2528   if (!is_set)
2529     {
2530       errmsg ("TTL value missing!");
2531       return -99;
2532     }
2533
2534   M (ONE_MAP_REGISTER_SET_TTL, mp);
2535   mp->ttl = clib_host_to_net_u32 (ttl);
2536
2537   /* send it... */
2538   S (mp);
2539
2540   /* Wait for a reply... */
2541   W (ret);
2542   return ret;
2543 }
2544
2545 static int
2546 api_show_one_map_register_ttl (vat_main_t * vam)
2547 {
2548   vl_api_show_one_map_register_ttl_t *mp;
2549   int ret;
2550
2551   M (SHOW_ONE_MAP_REGISTER_TTL, mp);
2552
2553   /* send it... */
2554   S (mp);
2555
2556   /* Wait for a reply... */
2557   W (ret);
2558   return ret;
2559 }
2560
2561 /**
2562  * Add/del map request itr rlocs from ONE control plane and updates
2563  *
2564  * @param vam vpp API test context
2565  * @return return code
2566  */
2567 static int
2568 api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
2569 {
2570   unformat_input_t *input = vam->input;
2571   vl_api_one_add_del_map_request_itr_rlocs_t *mp;
2572   u8 *locator_set_name = 0;
2573   u8 locator_set_name_set = 0;
2574   u8 is_add = 1;
2575   int ret;
2576
2577   /* Parse args required to build the message */
2578   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2579     {
2580       if (unformat (input, "del"))
2581         {
2582           is_add = 0;
2583         }
2584       else if (unformat (input, "%_%v%_", &locator_set_name))
2585         {
2586           locator_set_name_set = 1;
2587         }
2588       else
2589         {
2590           clib_warning ("parse error '%U'", format_unformat_error, input);
2591           return -99;
2592         }
2593     }
2594
2595   if (is_add && !locator_set_name_set)
2596     {
2597       errmsg ("itr-rloc is not set!");
2598       return -99;
2599     }
2600
2601   if (is_add && vec_len (locator_set_name) > 64)
2602     {
2603       errmsg ("itr-rloc locator-set name too long");
2604       vec_free (locator_set_name);
2605       return -99;
2606     }
2607
2608   M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
2609   mp->is_add = is_add;
2610   if (is_add)
2611     {
2612       clib_memcpy (mp->locator_set_name, locator_set_name,
2613                    vec_len (locator_set_name));
2614     }
2615   else
2616     {
2617       clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
2618     }
2619   vec_free (locator_set_name);
2620
2621   /* send it... */
2622   S (mp);
2623
2624   /* Wait for a reply... */
2625   W (ret);
2626   return ret;
2627 }
2628
2629 #define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
2630
2631 static int
2632 api_one_locator_dump (vat_main_t * vam)
2633 {
2634   unformat_input_t *input = vam->input;
2635   vl_api_one_locator_dump_t *mp;
2636   vl_api_control_ping_t *mp_ping;
2637   u8 is_index_set = 0, is_name_set = 0;
2638   u8 *ls_name = 0;
2639   u32 ls_index = ~0;
2640   int ret;
2641
2642   /* Parse args required to build the message */
2643   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2644     {
2645       if (unformat (input, "ls_name %_%v%_", &ls_name))
2646         {
2647           is_name_set = 1;
2648         }
2649       else if (unformat (input, "ls_index %d", &ls_index))
2650         {
2651           is_index_set = 1;
2652         }
2653       else
2654         {
2655           errmsg ("parse error '%U'", format_unformat_error, input);
2656           return -99;
2657         }
2658     }
2659
2660   if (!is_index_set && !is_name_set)
2661     {
2662       errmsg ("error: expected one of index or name!");
2663       return -99;
2664     }
2665
2666   if (is_index_set && is_name_set)
2667     {
2668       errmsg ("error: only one param expected!");
2669       return -99;
2670     }
2671
2672   if (vec_len (ls_name) > 62)
2673     {
2674       errmsg ("error: locator set name too long!");
2675       return -99;
2676     }
2677
2678   if (!vam->json_output)
2679     {
2680       print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
2681     }
2682
2683   M (ONE_LOCATOR_DUMP, mp);
2684   mp->is_index_set = is_index_set;
2685
2686   if (is_index_set)
2687     mp->ls_index = clib_host_to_net_u32 (ls_index);
2688   else
2689     {
2690       vec_add1 (ls_name, 0);
2691       strncpy ((char *) mp->ls_name, (char *) ls_name,
2692                sizeof (mp->ls_name) - 1);
2693     }
2694
2695   /* send it... */
2696   S (mp);
2697
2698   /* Use a control ping for synchronization */
2699   LISP_PING (&one_test_main, mp_ping);
2700   S (mp_ping);
2701
2702   /* Wait for a reply... */
2703   W (ret);
2704   return ret;
2705 }
2706
2707 #define api_lisp_locator_dump api_one_locator_dump
2708
2709 static int
2710 api_one_locator_set_dump (vat_main_t * vam)
2711 {
2712   vl_api_one_locator_set_dump_t *mp;
2713   vl_api_control_ping_t *mp_ping;
2714   unformat_input_t *input = vam->input;
2715   u8 filter = 0;
2716   int ret;
2717
2718   /* Parse args required to build the message */
2719   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2720     {
2721       if (unformat (input, "local"))
2722         {
2723           filter = 1;
2724         }
2725       else if (unformat (input, "remote"))
2726         {
2727           filter = 2;
2728         }
2729       else
2730         {
2731           errmsg ("parse error '%U'", format_unformat_error, input);
2732           return -99;
2733         }
2734     }
2735
2736   if (!vam->json_output)
2737     {
2738       print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
2739     }
2740
2741   M (ONE_LOCATOR_SET_DUMP, mp);
2742
2743   mp->filter = filter;
2744
2745   /* send it... */
2746   S (mp);
2747
2748   /* Use a control ping for synchronization */
2749   LISP_PING (&one_test_main, mp_ping);
2750   S (mp_ping);
2751
2752   /* Wait for a reply... */
2753   W (ret);
2754   return ret;
2755 }
2756
2757 #define api_lisp_locator_set_dump api_one_locator_set_dump
2758
2759 static int
2760 api_one_eid_table_map_dump (vat_main_t * vam)
2761 {
2762   u8 is_l2 = 0;
2763   u8 mode_set = 0;
2764   unformat_input_t *input = vam->input;
2765   vl_api_one_eid_table_map_dump_t *mp;
2766   vl_api_control_ping_t *mp_ping;
2767   int ret;
2768
2769   /* Parse args required to build the message */
2770   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2771     {
2772       if (unformat (input, "l2"))
2773         {
2774           is_l2 = 1;
2775           mode_set = 1;
2776         }
2777       else if (unformat (input, "l3"))
2778         {
2779           is_l2 = 0;
2780           mode_set = 1;
2781         }
2782       else
2783         {
2784           errmsg ("parse error '%U'", format_unformat_error, input);
2785           return -99;
2786         }
2787     }
2788
2789   if (!mode_set)
2790     {
2791       errmsg ("expected one of 'l2' or 'l3' parameter!");
2792       return -99;
2793     }
2794
2795   if (!vam->json_output)
2796     {
2797       print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
2798     }
2799
2800   M (ONE_EID_TABLE_MAP_DUMP, mp);
2801   mp->is_l2 = is_l2;
2802
2803   /* send it... */
2804   S (mp);
2805
2806   /* Use a control ping for synchronization */
2807   LISP_PING (&one_test_main, mp_ping);
2808   S (mp_ping);
2809
2810   /* Wait for a reply... */
2811   W (ret);
2812   return ret;
2813 }
2814
2815 #define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
2816
2817 static int
2818 api_one_eid_table_vni_dump (vat_main_t * vam)
2819 {
2820   vl_api_one_eid_table_vni_dump_t *mp;
2821   vl_api_control_ping_t *mp_ping;
2822   int ret;
2823
2824   if (!vam->json_output)
2825     {
2826       print (vam->ofp, "VNI");
2827     }
2828
2829   M (ONE_EID_TABLE_VNI_DUMP, mp);
2830
2831   /* send it... */
2832   S (mp);
2833
2834   /* Use a control ping for synchronization */
2835   LISP_PING (&one_test_main, mp_ping);
2836   S (mp_ping);
2837
2838   /* Wait for a reply... */
2839   W (ret);
2840   return ret;
2841 }
2842
2843 #define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
2844
2845 static int
2846 api_one_eid_table_dump (vat_main_t * vam)
2847 {
2848   unformat_input_t *i = vam->input;
2849   vl_api_one_eid_table_dump_t *mp;
2850   vl_api_control_ping_t *mp_ping;
2851   u8 filter = 0;
2852   int ret;
2853   u32 vni, t = 0;
2854   lisp_eid_vat_t eid;
2855   u8 eid_set = 0;
2856
2857   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2858     {
2859       if (unformat
2860           (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
2861         {
2862           eid_set = 1;
2863           eid.type = 0;
2864         }
2865       else
2866         if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
2867         {
2868           eid_set = 1;
2869           eid.type = 1;
2870         }
2871       else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
2872         {
2873           eid_set = 1;
2874           eid.type = 2;
2875         }
2876       else if (unformat (i, "vni %d", &t))
2877         {
2878           vni = t;
2879         }
2880       else if (unformat (i, "local"))
2881         {
2882           filter = 1;
2883         }
2884       else if (unformat (i, "remote"))
2885         {
2886           filter = 2;
2887         }
2888       else
2889         {
2890           errmsg ("parse error '%U'", format_unformat_error, i);
2891           return -99;
2892         }
2893     }
2894
2895   if (!vam->json_output)
2896     {
2897       print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
2898              "type", "ls_index", "ttl", "authoritative", "key_id", "key");
2899     }
2900
2901   M (ONE_EID_TABLE_DUMP, mp);
2902
2903   mp->filter = filter;
2904   if (eid_set)
2905     {
2906       mp->eid_set = 1;
2907       mp->vni = htonl (vni);
2908       lisp_eid_put_vat (&mp->eid, &eid);
2909     }
2910
2911   /* send it... */
2912   S (mp);
2913
2914   /* Use a control ping for synchronization */
2915   LISP_PING (&one_test_main, mp_ping);
2916   S (mp_ping);
2917
2918   /* Wait for a reply... */
2919   W (ret);
2920   return ret;
2921 }
2922
2923 static int
2924 api_one_adjacencies_get (vat_main_t * vam)
2925 {
2926   unformat_input_t *i = vam->input;
2927   vl_api_one_adjacencies_get_t *mp;
2928   u8 vni_set = 0;
2929   u32 vni = ~0;
2930   int ret;
2931
2932   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2933     {
2934       if (unformat (i, "vni %d", &vni))
2935         {
2936           vni_set = 1;
2937         }
2938       else
2939         {
2940           errmsg ("parse error '%U'", format_unformat_error, i);
2941           return -99;
2942         }
2943     }
2944
2945   if (!vni_set)
2946     {
2947       errmsg ("vni not set!");
2948       return -99;
2949     }
2950
2951   if (!vam->json_output)
2952     {
2953       print (vam->ofp, "%s %40s", "leid", "reid");
2954     }
2955
2956   M (ONE_ADJACENCIES_GET, mp);
2957   mp->vni = clib_host_to_net_u32 (vni);
2958
2959   /* send it... */
2960   S (mp);
2961
2962   /* Wait for a reply... */
2963   W (ret);
2964   return ret;
2965 }
2966
2967 static int
2968 api_one_map_server_dump (vat_main_t * vam)
2969 {
2970   vl_api_one_map_server_dump_t *mp;
2971   vl_api_control_ping_t *mp_ping;
2972   int ret;
2973
2974   if (!vam->json_output)
2975     {
2976       print (vam->ofp, "%=20s", "Map server");
2977     }
2978
2979   M (ONE_MAP_SERVER_DUMP, mp);
2980   /* send it... */
2981   S (mp);
2982
2983   /* Use a control ping for synchronization */
2984   LISP_PING (&one_test_main, mp_ping);
2985   S (mp_ping);
2986
2987   /* Wait for a reply... */
2988   W (ret);
2989   return ret;
2990 }
2991
2992 #define api_lisp_map_server_dump api_one_map_server_dump
2993
2994 static int
2995 api_one_map_resolver_dump (vat_main_t * vam)
2996 {
2997   vl_api_one_map_resolver_dump_t *mp;
2998   vl_api_control_ping_t *mp_ping;
2999   int ret;
3000
3001   if (!vam->json_output)
3002     {
3003       print (vam->ofp, "%=20s", "Map resolver");
3004     }
3005
3006   M (ONE_MAP_RESOLVER_DUMP, mp);
3007   /* send it... */
3008   S (mp);
3009
3010   /* Use a control ping for synchronization */
3011   LISP_PING (&one_test_main, mp_ping);
3012   S (mp_ping);
3013
3014   /* Wait for a reply... */
3015   W (ret);
3016   return ret;
3017 }
3018
3019 #define api_lisp_map_resolver_dump api_one_map_resolver_dump
3020
3021 static int
3022 api_one_stats_flush (vat_main_t * vam)
3023 {
3024   vl_api_one_stats_flush_t *mp;
3025   int ret = 0;
3026
3027   M (ONE_STATS_FLUSH, mp);
3028   S (mp);
3029   W (ret);
3030   return ret;
3031 }
3032
3033 static int
3034 api_one_stats_dump (vat_main_t * vam)
3035 {
3036   vl_api_one_stats_dump_t *mp;
3037   vl_api_control_ping_t *mp_ping;
3038   int ret;
3039
3040   M (ONE_STATS_DUMP, mp);
3041   /* send it... */
3042   S (mp);
3043
3044   /* Use a control ping for synchronization */
3045   LISP_PING (&one_test_main, mp_ping);
3046   S (mp_ping);
3047
3048   /* Wait for a reply... */
3049   W (ret);
3050   return ret;
3051 }
3052
3053 static int
3054 api_show_one_status (vat_main_t * vam)
3055 {
3056   vl_api_show_one_status_t *mp;
3057   int ret;
3058
3059   if (!vam->json_output)
3060     {
3061       print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
3062     }
3063
3064   M (SHOW_ONE_STATUS, mp);
3065   /* send it... */
3066   S (mp);
3067   /* Wait for a reply... */
3068   W (ret);
3069   return ret;
3070 }
3071
3072 static int
3073 api_one_get_map_request_itr_rlocs (vat_main_t * vam)
3074 {
3075   vl_api_one_get_map_request_itr_rlocs_t *mp;
3076   int ret;
3077
3078   if (!vam->json_output)
3079     {
3080       print (vam->ofp, "%=20s", "itr-rlocs:");
3081     }
3082
3083   M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
3084   /* send it... */
3085   S (mp);
3086   /* Wait for a reply... */
3087   W (ret);
3088   return ret;
3089 }
3090
3091 #define vat_plugin_register vat_plugin_register_one
3092 #include <lisp/lisp-cp/one.api_test.c>
3093
3094 /*
3095  * fd.io coding-style-patch-verification: ON
3096  *
3097  * Local Variables:
3098  * eval: (c-set-style "gnu")
3099  * End:
3100  */