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