misc: remove GNU Indent directives
[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 /** Used for parsing LISP eids */
675 typedef CLIB_PACKED(struct{
676   union {
677           ip46_address_t ip;
678           mac_address_t mac;
679           lisp_nsh_api_t nsh;
680   } addr;
681   u32 len;       /**< prefix length if IP */
682   u8 type;      /**< type of eid */
683 }) lisp_eid_vat_t;
684
685 static uword
686 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
687 {
688   lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
689
690   clib_memset (a, 0, sizeof (a[0]));
691
692   if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
693     {
694       a->type = 0;              /* ip prefix type */
695     }
696   else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
697     {
698       a->type = 1;              /* mac type */
699     }
700   else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
701     {
702       a->type = 2;              /* NSH type */
703       a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
704     }
705   else
706     {
707       return 0;
708     }
709
710   if (a->type == 0)
711     {
712       if (ip46_address_is_ip4 (&a->addr.ip))
713         return a->len > 32 ? 1 : 0;
714       else
715         return a->len > 128 ? 1 : 0;
716     }
717
718   return 1;
719 }
720
721 static void
722 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
723 {
724   eid->type = vat_eid->type;
725   switch (eid->type)
726     {
727     case EID_TYPE_API_PREFIX:
728       if (ip46_address_is_ip4 (&vat_eid->addr.ip))
729         {
730           clib_memcpy (&eid->address.prefix.address.un.ip4,
731                        &vat_eid->addr.ip.ip4, 4);
732           eid->address.prefix.address.af = ADDRESS_IP4;
733           eid->address.prefix.len = vat_eid->len;
734         }
735       else
736         {
737           clib_memcpy (&eid->address.prefix.address.un.ip6,
738                        &vat_eid->addr.ip.ip6, 16);
739           eid->address.prefix.address.af = ADDRESS_IP6;
740           eid->address.prefix.len = vat_eid->len;
741         }
742       return;
743     case EID_TYPE_API_MAC:
744       clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
745                    sizeof (eid->address.mac));
746       return;
747     case EID_TYPE_API_NSH:
748       clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
749                    sizeof (eid->address.nsh));
750       return;
751     default:
752       ASSERT (0);
753       return;
754     }
755 }
756
757 static int
758 api_one_add_del_locator_set (vat_main_t * vam)
759 {
760   unformat_input_t *input = vam->input;
761   vl_api_one_add_del_locator_set_t *mp;
762   u8 is_add = 1;
763   u8 *locator_set_name = NULL;
764   u8 locator_set_name_set = 0;
765   vl_api_local_locator_t locator, *locators = 0;
766   u32 sw_if_index, priority, weight;
767   u32 data_len = 0;
768
769   int ret;
770   /* Parse args required to build the message */
771   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
772     {
773       if (unformat (input, "del"))
774         {
775           is_add = 0;
776         }
777       else if (unformat (input, "locator-set %s", &locator_set_name))
778         {
779           locator_set_name_set = 1;
780         }
781       else if (unformat (input, "sw_if_index %u p %u w %u",
782                          &sw_if_index, &priority, &weight))
783         {
784           locator.sw_if_index = htonl (sw_if_index);
785           locator.priority = priority;
786           locator.weight = weight;
787           vec_add1 (locators, locator);
788         }
789       else
790         if (unformat
791             (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
792              &sw_if_index, &priority, &weight))
793         {
794           locator.sw_if_index = htonl (sw_if_index);
795           locator.priority = priority;
796           locator.weight = weight;
797           vec_add1 (locators, locator);
798         }
799       else
800         break;
801     }
802
803   if (locator_set_name_set == 0)
804     {
805       errmsg ("missing locator-set name");
806       vec_free (locators);
807       return -99;
808     }
809
810   if (vec_len (locator_set_name) > 64)
811     {
812       errmsg ("locator-set name too long");
813       vec_free (locator_set_name);
814       vec_free (locators);
815       return -99;
816     }
817   vec_add1 (locator_set_name, 0);
818
819   data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
820
821   /* Construct the API message */
822   M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
823
824   mp->is_add = is_add;
825   clib_memcpy (mp->locator_set_name, locator_set_name,
826                vec_len (locator_set_name));
827   vec_free (locator_set_name);
828
829   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
830   if (locators)
831     clib_memcpy (mp->locators, locators, data_len);
832   vec_free (locators);
833
834   /* send it... */
835   S (mp);
836
837   /* Wait for a reply... */
838   W (ret);
839   return ret;
840 }
841
842 #define api_lisp_add_del_locator_set api_one_add_del_locator_set
843
844 static int
845 api_one_add_del_locator (vat_main_t * vam)
846 {
847   unformat_input_t *input = vam->input;
848   vl_api_one_add_del_locator_t *mp;
849   u32 tmp_if_index = ~0;
850   u32 sw_if_index = ~0;
851   u8 sw_if_index_set = 0;
852   u8 sw_if_index_if_name_set = 0;
853   u32 priority = ~0;
854   u8 priority_set = 0;
855   u32 weight = ~0;
856   u8 weight_set = 0;
857   u8 is_add = 1;
858   u8 *locator_set_name = NULL;
859   u8 locator_set_name_set = 0;
860   int ret;
861
862   /* Parse args required to build the message */
863   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
864     {
865       if (unformat (input, "del"))
866         {
867           is_add = 0;
868         }
869       else if (unformat (input, "locator-set %s", &locator_set_name))
870         {
871           locator_set_name_set = 1;
872         }
873       else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
874                          &tmp_if_index))
875         {
876           sw_if_index_if_name_set = 1;
877           sw_if_index = tmp_if_index;
878         }
879       else if (unformat (input, "sw_if_index %d", &tmp_if_index))
880         {
881           sw_if_index_set = 1;
882           sw_if_index = tmp_if_index;
883         }
884       else if (unformat (input, "p %d", &priority))
885         {
886           priority_set = 1;
887         }
888       else if (unformat (input, "w %d", &weight))
889         {
890           weight_set = 1;
891         }
892       else
893         break;
894     }
895
896   if (locator_set_name_set == 0)
897     {
898       errmsg ("missing locator-set name");
899       return -99;
900     }
901
902   if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
903     {
904       errmsg ("missing sw_if_index");
905       vec_free (locator_set_name);
906       return -99;
907     }
908
909   if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
910     {
911       errmsg ("cannot use both params interface name and sw_if_index");
912       vec_free (locator_set_name);
913       return -99;
914     }
915
916   if (priority_set == 0)
917     {
918       errmsg ("missing locator-set priority");
919       vec_free (locator_set_name);
920       return -99;
921     }
922
923   if (weight_set == 0)
924     {
925       errmsg ("missing locator-set weight");
926       vec_free (locator_set_name);
927       return -99;
928     }
929
930   if (vec_len (locator_set_name) > 64)
931     {
932       errmsg ("locator-set name too long");
933       vec_free (locator_set_name);
934       return -99;
935     }
936   vec_add1 (locator_set_name, 0);
937
938   /* Construct the API message */
939   M (ONE_ADD_DEL_LOCATOR, mp);
940
941   mp->is_add = is_add;
942   mp->sw_if_index = ntohl (sw_if_index);
943   mp->priority = priority;
944   mp->weight = weight;
945   clib_memcpy (mp->locator_set_name, locator_set_name,
946                vec_len (locator_set_name));
947   vec_free (locator_set_name);
948
949   /* send it... */
950   S (mp);
951
952   /* Wait for a reply... */
953   W (ret);
954   return ret;
955 }
956
957 #define api_lisp_add_del_locator api_one_add_del_locator
958
959 static int
960 api_one_add_del_local_eid (vat_main_t * vam)
961 {
962   unformat_input_t *input = vam->input;
963   vl_api_one_add_del_local_eid_t *mp;
964   u8 is_add = 1;
965   u8 eid_set = 0;
966   lisp_eid_vat_t _eid, *eid = &_eid;
967   u8 *locator_set_name = 0;
968   u8 locator_set_name_set = 0;
969   u32 vni = 0;
970   u16 key_id = 0;
971   u8 *key = 0;
972   int ret;
973
974   /* Parse args required to build the message */
975   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
976     {
977       if (unformat (input, "del"))
978         {
979           is_add = 0;
980         }
981       else if (unformat (input, "vni %d", &vni))
982         {
983           ;
984         }
985       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
986         {
987           eid_set = 1;
988         }
989       else if (unformat (input, "locator-set %s", &locator_set_name))
990         {
991           locator_set_name_set = 1;
992         }
993       else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
994         ;
995       else if (unformat (input, "secret-key %_%v%_", &key))
996         ;
997       else
998         break;
999     }
1000
1001   if (locator_set_name_set == 0)
1002     {
1003       errmsg ("missing locator-set name");
1004       return -99;
1005     }
1006
1007   if (0 == eid_set)
1008     {
1009       errmsg ("EID address not set!");
1010       vec_free (locator_set_name);
1011       return -99;
1012     }
1013
1014   if (key && (0 == key_id))
1015     {
1016       errmsg ("invalid key_id!");
1017       return -99;
1018     }
1019
1020   if (vec_len (key) > 64)
1021     {
1022       errmsg ("key too long");
1023       vec_free (key);
1024       return -99;
1025     }
1026
1027   if (vec_len (locator_set_name) > 64)
1028     {
1029       errmsg ("locator-set name too long");
1030       vec_free (locator_set_name);
1031       return -99;
1032     }
1033   vec_add1 (locator_set_name, 0);
1034
1035   /* Construct the API message */
1036   M (ONE_ADD_DEL_LOCAL_EID, mp);
1037
1038   mp->is_add = is_add;
1039   lisp_eid_put_vat (&mp->eid, eid);
1040   mp->vni = clib_host_to_net_u32 (vni);
1041   mp->key.id = key_id;
1042   clib_memcpy (mp->locator_set_name, locator_set_name,
1043                vec_len (locator_set_name));
1044   clib_memcpy (mp->key.key, key, vec_len (key));
1045
1046   vec_free (locator_set_name);
1047   vec_free (key);
1048
1049   /* send it... */
1050   S (mp);
1051
1052   /* Wait for a reply... */
1053   W (ret);
1054   return ret;
1055 }
1056
1057 static int
1058 api_one_add_del_map_server (vat_main_t * vam)
1059 {
1060   unformat_input_t *input = vam->input;
1061   vl_api_one_add_del_map_server_t *mp;
1062   u8 is_add = 1;
1063   u8 ipv4_set = 0;
1064   u8 ipv6_set = 0;
1065   ip4_address_t ipv4;
1066   ip6_address_t ipv6;
1067   int ret;
1068
1069   /* Parse args required to build the message */
1070   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1071     {
1072       if (unformat (input, "del"))
1073         {
1074           is_add = 0;
1075         }
1076       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1077         {
1078           ipv4_set = 1;
1079         }
1080       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1081         {
1082           ipv6_set = 1;
1083         }
1084       else
1085         break;
1086     }
1087
1088   if (ipv4_set && ipv6_set)
1089     {
1090       errmsg ("both eid v4 and v6 addresses set");
1091       return -99;
1092     }
1093
1094   if (!ipv4_set && !ipv6_set)
1095     {
1096       errmsg ("eid addresses not set");
1097       return -99;
1098     }
1099
1100   /* Construct the API message */
1101   M (ONE_ADD_DEL_MAP_SERVER, mp);
1102
1103   mp->is_add = is_add;
1104   if (ipv6_set)
1105     {
1106       mp->ip_address.af = 1;
1107       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1108     }
1109   else
1110     {
1111       mp->ip_address.af = 0;
1112       clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
1113     }
1114
1115   /* send it... */
1116   S (mp);
1117
1118   /* Wait for a reply... */
1119   W (ret);
1120   return ret;
1121 }
1122
1123 #define api_lisp_add_del_map_server api_one_add_del_map_server
1124
1125 static int
1126 api_one_add_del_map_resolver (vat_main_t * vam)
1127 {
1128   unformat_input_t *input = vam->input;
1129   vl_api_one_add_del_map_resolver_t *mp;
1130   u8 is_add = 1;
1131   u8 ipv4_set = 0;
1132   u8 ipv6_set = 0;
1133   ip4_address_t ipv4;
1134   ip6_address_t ipv6;
1135   int ret;
1136
1137   /* Parse args required to build the message */
1138   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1139     {
1140       if (unformat (input, "del"))
1141         {
1142           is_add = 0;
1143         }
1144       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1145         {
1146           ipv4_set = 1;
1147         }
1148       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1149         {
1150           ipv6_set = 1;
1151         }
1152       else
1153         break;
1154     }
1155
1156   if (ipv4_set && ipv6_set)
1157     {
1158       errmsg ("both eid v4 and v6 addresses set");
1159       return -99;
1160     }
1161
1162   if (!ipv4_set && !ipv6_set)
1163     {
1164       errmsg ("eid addresses not set");
1165       return -99;
1166     }
1167
1168   /* Construct the API message */
1169   M (ONE_ADD_DEL_MAP_RESOLVER, mp);
1170
1171   mp->is_add = is_add;
1172   if (ipv6_set)
1173     {
1174       mp->ip_address.af = 1;
1175       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1176     }
1177   else
1178     {
1179       mp->ip_address.af = 0;
1180       clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
1181     }
1182
1183   /* send it... */
1184   S (mp);
1185
1186   /* Wait for a reply... */
1187   W (ret);
1188   return ret;
1189 }
1190
1191 static int
1192 api_one_rloc_probe_enable_disable (vat_main_t * vam)
1193 {
1194   unformat_input_t *input = vam->input;
1195   vl_api_one_rloc_probe_enable_disable_t *mp;
1196   u8 is_set = 0;
1197   u8 is_enable = 0;
1198   int ret;
1199
1200   /* Parse args required to build the message */
1201   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1202     {
1203       if (unformat (input, "enable"))
1204         {
1205           is_set = 1;
1206           is_enable = 1;
1207         }
1208       else if (unformat (input, "disable"))
1209         is_set = 1;
1210       else
1211         break;
1212     }
1213
1214   if (!is_set)
1215     {
1216       errmsg ("Value not set");
1217       return -99;
1218     }
1219
1220   /* Construct the API message */
1221   M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
1222
1223   mp->is_enable = is_enable;
1224
1225   /* send it... */
1226   S (mp);
1227
1228   /* Wait for a reply... */
1229   W (ret);
1230   return ret;
1231 }
1232
1233 #define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
1234
1235 static int
1236 api_one_map_register_enable_disable (vat_main_t * vam)
1237 {
1238   unformat_input_t *input = vam->input;
1239   vl_api_one_map_register_enable_disable_t *mp;
1240   u8 is_set = 0;
1241   u8 is_enable = 0;
1242   int ret;
1243
1244   /* Parse args required to build the message */
1245   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1246     {
1247       if (unformat (input, "enable"))
1248         {
1249           is_set = 1;
1250           is_enable = 1;
1251         }
1252       else if (unformat (input, "disable"))
1253         is_set = 1;
1254       else
1255         break;
1256     }
1257
1258   if (!is_set)
1259     {
1260       errmsg ("Value not set");
1261       return -99;
1262     }
1263
1264   /* Construct the API message */
1265   M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
1266
1267   mp->is_enable = is_enable;
1268
1269   /* send it... */
1270   S (mp);
1271
1272   /* Wait for a reply... */
1273   W (ret);
1274   return ret;
1275 }
1276
1277 #define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
1278
1279 static int
1280 api_one_enable_disable (vat_main_t * vam)
1281 {
1282   unformat_input_t *input = vam->input;
1283   vl_api_one_enable_disable_t *mp;
1284   u8 is_set = 0;
1285   u8 is_enable = 0;
1286   int ret;
1287
1288   /* Parse args required to build the message */
1289   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1290     {
1291       if (unformat (input, "enable"))
1292         {
1293           is_set = 1;
1294           is_enable = 1;
1295         }
1296       else if (unformat (input, "disable"))
1297         {
1298           is_set = 1;
1299         }
1300       else
1301         break;
1302     }
1303
1304   if (!is_set)
1305     {
1306       errmsg ("Value not set");
1307       return -99;
1308     }
1309
1310   /* Construct the API message */
1311   M (ONE_ENABLE_DISABLE, mp);
1312
1313   mp->is_enable = is_enable;
1314
1315   /* send it... */
1316   S (mp);
1317
1318   /* Wait for a reply... */
1319   W (ret);
1320   return ret;
1321 }
1322
1323 #define api_lisp_enable_disable api_one_enable_disable
1324
1325 static int
1326 api_one_enable_disable_xtr_mode (vat_main_t * vam)
1327 {
1328   unformat_input_t *input = vam->input;
1329   vl_api_one_enable_disable_xtr_mode_t *mp;
1330   u8 is_set = 0;
1331   u8 is_enable = 0;
1332   int ret;
1333
1334   /* Parse args required to build the message */
1335   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1336     {
1337       if (unformat (input, "enable"))
1338         {
1339           is_set = 1;
1340           is_enable = 1;
1341         }
1342       else if (unformat (input, "disable"))
1343         {
1344           is_set = 1;
1345         }
1346       else
1347         break;
1348     }
1349
1350   if (!is_set)
1351     {
1352       errmsg ("Value not set");
1353       return -99;
1354     }
1355
1356   /* Construct the API message */
1357   M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
1358
1359   mp->is_enable = is_enable;
1360
1361   /* send it... */
1362   S (mp);
1363
1364   /* Wait for a reply... */
1365   W (ret);
1366   return ret;
1367 }
1368
1369 static int
1370 api_one_show_xtr_mode (vat_main_t * vam)
1371 {
1372   vl_api_one_show_xtr_mode_t *mp;
1373   int ret;
1374
1375   /* Construct the API message */
1376   M (ONE_SHOW_XTR_MODE, mp);
1377
1378   /* send it... */
1379   S (mp);
1380
1381   /* Wait for a reply... */
1382   W (ret);
1383   return ret;
1384 }
1385
1386 static int
1387 api_one_enable_disable_pitr_mode (vat_main_t * vam)
1388 {
1389   unformat_input_t *input = vam->input;
1390   vl_api_one_enable_disable_pitr_mode_t *mp;
1391   u8 is_set = 0;
1392   u8 is_enable = 0;
1393   int ret;
1394
1395   /* Parse args required to build the message */
1396   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1397     {
1398       if (unformat (input, "enable"))
1399         {
1400           is_set = 1;
1401           is_enable = 1;
1402         }
1403       else if (unformat (input, "disable"))
1404         {
1405           is_set = 1;
1406         }
1407       else
1408         break;
1409     }
1410
1411   if (!is_set)
1412     {
1413       errmsg ("Value not set");
1414       return -99;
1415     }
1416
1417   /* Construct the API message */
1418   M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
1419
1420   mp->is_enable = is_enable;
1421
1422   /* send it... */
1423   S (mp);
1424
1425   /* Wait for a reply... */
1426   W (ret);
1427   return ret;
1428 }
1429
1430 static int
1431 api_one_show_pitr_mode (vat_main_t * vam)
1432 {
1433   vl_api_one_show_pitr_mode_t *mp;
1434   int ret;
1435
1436   /* Construct the API message */
1437   M (ONE_SHOW_PITR_MODE, mp);
1438
1439   /* send it... */
1440   S (mp);
1441
1442   /* Wait for a reply... */
1443   W (ret);
1444   return ret;
1445 }
1446
1447 static int
1448 api_one_enable_disable_petr_mode (vat_main_t * vam)
1449 {
1450   unformat_input_t *input = vam->input;
1451   vl_api_one_enable_disable_petr_mode_t *mp;
1452   u8 is_set = 0;
1453   u8 is_enable = 0;
1454   int ret;
1455
1456   /* Parse args required to build the message */
1457   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1458     {
1459       if (unformat (input, "enable"))
1460         {
1461           is_set = 1;
1462           is_enable = 1;
1463         }
1464       else if (unformat (input, "disable"))
1465         {
1466           is_set = 1;
1467         }
1468       else
1469         break;
1470     }
1471
1472   if (!is_set)
1473     {
1474       errmsg ("Value not set");
1475       return -99;
1476     }
1477
1478   /* Construct the API message */
1479   M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
1480
1481   mp->is_enable = is_enable;
1482
1483   /* send it... */
1484   S (mp);
1485
1486   /* Wait for a reply... */
1487   W (ret);
1488   return ret;
1489 }
1490
1491 static int
1492 api_one_show_petr_mode (vat_main_t * vam)
1493 {
1494   vl_api_one_show_petr_mode_t *mp;
1495   int ret;
1496
1497   /* Construct the API message */
1498   M (ONE_SHOW_PETR_MODE, mp);
1499
1500   /* send it... */
1501   S (mp);
1502
1503   /* Wait for a reply... */
1504   W (ret);
1505   return ret;
1506 }
1507
1508 static int
1509 api_show_one_map_register_state (vat_main_t * vam)
1510 {
1511   vl_api_show_one_map_register_state_t *mp;
1512   int ret;
1513
1514   M (SHOW_ONE_MAP_REGISTER_STATE, mp);
1515
1516   /* send */
1517   S (mp);
1518
1519   /* wait for reply */
1520   W (ret);
1521   return ret;
1522 }
1523
1524 #define api_show_lisp_map_register_state api_show_one_map_register_state
1525
1526 static int
1527 api_show_one_rloc_probe_state (vat_main_t * vam)
1528 {
1529   vl_api_show_one_rloc_probe_state_t *mp;
1530   int ret;
1531
1532   M (SHOW_ONE_RLOC_PROBE_STATE, mp);
1533
1534   /* send */
1535   S (mp);
1536
1537   /* wait for reply */
1538   W (ret);
1539   return ret;
1540 }
1541
1542 #define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
1543
1544 static int
1545 api_one_add_del_ndp_entry (vat_main_t * vam)
1546 {
1547   vl_api_one_add_del_ndp_entry_t *mp;
1548   unformat_input_t *input = vam->input;
1549   u8 is_add = 1;
1550   u8 mac_set = 0;
1551   u8 bd_set = 0;
1552   u8 ip_set = 0;
1553   u8 mac[6] = { 0, };
1554   u8 ip6[16] = { 0, };
1555   u32 bd = ~0;
1556   int ret;
1557
1558   /* Parse args required to build the message */
1559   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1560     {
1561       if (unformat (input, "del"))
1562         is_add = 0;
1563       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1564         mac_set = 1;
1565       else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
1566         ip_set = 1;
1567       else if (unformat (input, "bd %d", &bd))
1568         bd_set = 1;
1569       else
1570         {
1571           errmsg ("parse error '%U'", format_unformat_error, input);
1572           return -99;
1573         }
1574     }
1575
1576   if (!bd_set || !ip_set || (!mac_set && is_add))
1577     {
1578       errmsg ("Missing BD, IP or MAC!");
1579       return -99;
1580     }
1581
1582   M (ONE_ADD_DEL_NDP_ENTRY, mp);
1583   mp->is_add = is_add;
1584   clib_memcpy (&mp->entry.mac, mac, 6);
1585   mp->bd = clib_host_to_net_u32 (bd);
1586   clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6));
1587
1588   /* send */
1589   S (mp);
1590
1591   /* wait for reply */
1592   W (ret);
1593   return ret;
1594 }
1595
1596 static int
1597 api_one_add_del_l2_arp_entry (vat_main_t * vam)
1598 {
1599   vl_api_one_add_del_l2_arp_entry_t *mp;
1600   unformat_input_t *input = vam->input;
1601   u8 is_add = 1;
1602   u8 mac_set = 0;
1603   u8 bd_set = 0;
1604   u8 ip_set = 0;
1605   u8 mac[6] = { 0, };
1606   u32 ip4 = 0, bd = ~0;
1607   int ret;
1608
1609   /* Parse args required to build the message */
1610   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1611     {
1612       if (unformat (input, "del"))
1613         is_add = 0;
1614       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1615         mac_set = 1;
1616       else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
1617         ip_set = 1;
1618       else if (unformat (input, "bd %d", &bd))
1619         bd_set = 1;
1620       else
1621         {
1622           errmsg ("parse error '%U'", format_unformat_error, input);
1623           return -99;
1624         }
1625     }
1626
1627   if (!bd_set || !ip_set || (!mac_set && is_add))
1628     {
1629       errmsg ("Missing BD, IP or MAC!");
1630       return -99;
1631     }
1632
1633   M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
1634   mp->is_add = is_add;
1635   clib_memcpy (&mp->entry.mac, mac, 6);
1636   mp->bd = clib_host_to_net_u32 (bd);
1637   clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4));
1638
1639   /* send */
1640   S (mp);
1641
1642   /* wait for reply */
1643   W (ret);
1644   return ret;
1645 }
1646
1647 static int
1648 api_one_ndp_bd_get (vat_main_t * vam)
1649 {
1650   vl_api_one_ndp_bd_get_t *mp;
1651   int ret;
1652
1653   M (ONE_NDP_BD_GET, mp);
1654
1655   /* send */
1656   S (mp);
1657
1658   /* wait for reply */
1659   W (ret);
1660   return ret;
1661 }
1662
1663 static int
1664 api_one_ndp_entries_get (vat_main_t * vam)
1665 {
1666   vl_api_one_ndp_entries_get_t *mp;
1667   unformat_input_t *input = vam->input;
1668   u8 bd_set = 0;
1669   u32 bd = ~0;
1670   int ret;
1671
1672   /* Parse args required to build the message */
1673   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1674     {
1675       if (unformat (input, "bd %d", &bd))
1676         bd_set = 1;
1677       else
1678         {
1679           errmsg ("parse error '%U'", format_unformat_error, input);
1680           return -99;
1681         }
1682     }
1683
1684   if (!bd_set)
1685     {
1686       errmsg ("Expected bridge domain!");
1687       return -99;
1688     }
1689
1690   M (ONE_NDP_ENTRIES_GET, mp);
1691   mp->bd = clib_host_to_net_u32 (bd);
1692
1693   /* send */
1694   S (mp);
1695
1696   /* wait for reply */
1697   W (ret);
1698   return ret;
1699 }
1700
1701 static int
1702 api_one_l2_arp_bd_get (vat_main_t * vam)
1703 {
1704   vl_api_one_l2_arp_bd_get_t *mp;
1705   int ret;
1706
1707   M (ONE_L2_ARP_BD_GET, mp);
1708
1709   /* send */
1710   S (mp);
1711
1712   /* wait for reply */
1713   W (ret);
1714   return ret;
1715 }
1716
1717 static int
1718 api_one_l2_arp_entries_get (vat_main_t * vam)
1719 {
1720   vl_api_one_l2_arp_entries_get_t *mp;
1721   unformat_input_t *input = vam->input;
1722   u8 bd_set = 0;
1723   u32 bd = ~0;
1724   int ret;
1725
1726   /* Parse args required to build the message */
1727   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1728     {
1729       if (unformat (input, "bd %d", &bd))
1730         bd_set = 1;
1731       else
1732         {
1733           errmsg ("parse error '%U'", format_unformat_error, input);
1734           return -99;
1735         }
1736     }
1737
1738   if (!bd_set)
1739     {
1740       errmsg ("Expected bridge domain!");
1741       return -99;
1742     }
1743
1744   M (ONE_L2_ARP_ENTRIES_GET, mp);
1745   mp->bd = clib_host_to_net_u32 (bd);
1746
1747   /* send */
1748   S (mp);
1749
1750   /* wait for reply */
1751   W (ret);
1752   return ret;
1753 }
1754
1755 static int
1756 api_one_stats_enable_disable (vat_main_t * vam)
1757 {
1758   vl_api_one_stats_enable_disable_t *mp;
1759   unformat_input_t *input = vam->input;
1760   u8 is_set = 0;
1761   u8 is_enable = 0;
1762   int ret;
1763
1764   /* Parse args required to build the message */
1765   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1766     {
1767       if (unformat (input, "enable"))
1768         {
1769           is_set = 1;
1770           is_enable = 1;
1771         }
1772       else if (unformat (input, "disable"))
1773         {
1774           is_set = 1;
1775         }
1776       else
1777         break;
1778     }
1779
1780   if (!is_set)
1781     {
1782       errmsg ("Value not set");
1783       return -99;
1784     }
1785
1786   M (ONE_STATS_ENABLE_DISABLE, mp);
1787   mp->is_enable = is_enable;
1788
1789   /* send */
1790   S (mp);
1791
1792   /* wait for reply */
1793   W (ret);
1794   return ret;
1795 }
1796
1797 static int
1798 api_show_one_stats_enable_disable (vat_main_t * vam)
1799 {
1800   vl_api_show_one_stats_enable_disable_t *mp;
1801   int ret;
1802
1803   M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
1804
1805   /* send */
1806   S (mp);
1807
1808   /* wait for reply */
1809   W (ret);
1810   return ret;
1811 }
1812
1813 static int
1814 api_show_one_map_request_mode (vat_main_t * vam)
1815 {
1816   vl_api_show_one_map_request_mode_t *mp;
1817   int ret;
1818
1819   M (SHOW_ONE_MAP_REQUEST_MODE, mp);
1820
1821   /* send */
1822   S (mp);
1823
1824   /* wait for reply */
1825   W (ret);
1826   return ret;
1827 }
1828
1829 #define api_show_lisp_map_request_mode api_show_one_map_request_mode
1830
1831 static int
1832 api_one_map_request_mode (vat_main_t * vam)
1833 {
1834   unformat_input_t *input = vam->input;
1835   vl_api_one_map_request_mode_t *mp;
1836   u8 mode = 0;
1837   int ret;
1838
1839   /* Parse args required to build the message */
1840   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1841     {
1842       if (unformat (input, "dst-only"))
1843         mode = 0;
1844       else if (unformat (input, "src-dst"))
1845         mode = 1;
1846       else
1847         {
1848           errmsg ("parse error '%U'", format_unformat_error, input);
1849           return -99;
1850         }
1851     }
1852
1853   M (ONE_MAP_REQUEST_MODE, mp);
1854
1855   mp->mode = mode;
1856
1857   /* send */
1858   S (mp);
1859
1860   /* wait for reply */
1861   W (ret);
1862   return ret;
1863 }
1864
1865 #define api_lisp_map_request_mode api_one_map_request_mode
1866
1867 /**
1868  * Enable/disable ONE proxy ITR.
1869  *
1870  * @param vam vpp API test context
1871  * @return return code
1872  */
1873 static int
1874 api_one_pitr_set_locator_set (vat_main_t * vam)
1875 {
1876   u8 ls_name_set = 0;
1877   unformat_input_t *input = vam->input;
1878   vl_api_one_pitr_set_locator_set_t *mp;
1879   u8 is_add = 1;
1880   u8 *ls_name = 0;
1881   int ret;
1882
1883   /* Parse args required to build the message */
1884   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1885     {
1886       if (unformat (input, "del"))
1887         is_add = 0;
1888       else if (unformat (input, "locator-set %s", &ls_name))
1889         ls_name_set = 1;
1890       else
1891         {
1892           errmsg ("parse error '%U'", format_unformat_error, input);
1893           return -99;
1894         }
1895     }
1896
1897   if (!ls_name_set)
1898     {
1899       errmsg ("locator-set name not set!");
1900       return -99;
1901     }
1902
1903   M (ONE_PITR_SET_LOCATOR_SET, mp);
1904
1905   mp->is_add = is_add;
1906   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1907   vec_free (ls_name);
1908
1909   /* send */
1910   S (mp);
1911
1912   /* wait for reply */
1913   W (ret);
1914   return ret;
1915 }
1916
1917 #define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
1918
1919 static int
1920 api_one_nsh_set_locator_set (vat_main_t * vam)
1921 {
1922   u8 ls_name_set = 0;
1923   unformat_input_t *input = vam->input;
1924   vl_api_one_nsh_set_locator_set_t *mp;
1925   u8 is_add = 1;
1926   u8 *ls_name = 0;
1927   int ret;
1928
1929   /* Parse args required to build the message */
1930   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1931     {
1932       if (unformat (input, "del"))
1933         is_add = 0;
1934       else if (unformat (input, "ls %s", &ls_name))
1935         ls_name_set = 1;
1936       else
1937         {
1938           errmsg ("parse error '%U'", format_unformat_error, input);
1939           return -99;
1940         }
1941     }
1942
1943   if (!ls_name_set && is_add)
1944     {
1945       errmsg ("locator-set name not set!");
1946       return -99;
1947     }
1948
1949   M (ONE_NSH_SET_LOCATOR_SET, mp);
1950
1951   mp->is_add = is_add;
1952   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1953   vec_free (ls_name);
1954
1955   /* send */
1956   S (mp);
1957
1958   /* wait for reply */
1959   W (ret);
1960   return ret;
1961 }
1962
1963 static int
1964 api_show_one_pitr (vat_main_t * vam)
1965 {
1966   vl_api_show_one_pitr_t *mp;
1967   int ret;
1968
1969   if (!vam->json_output)
1970     {
1971       print (vam->ofp, "%=20s", "lisp status:");
1972     }
1973
1974   M (SHOW_ONE_PITR, mp);
1975   /* send it... */
1976   S (mp);
1977
1978   /* Wait for a reply... */
1979   W (ret);
1980   return ret;
1981 }
1982
1983 #define api_show_lisp_pitr api_show_one_pitr
1984
1985 static int
1986 api_one_use_petr (vat_main_t * vam)
1987 {
1988   unformat_input_t *input = vam->input;
1989   vl_api_one_use_petr_t *mp;
1990   u8 is_add = 0;
1991   ip_address_t ip;
1992   int ret;
1993
1994   clib_memset (&ip, 0, sizeof (ip));
1995
1996   /* Parse args required to build the message */
1997   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1998     {
1999       if (unformat (input, "disable"))
2000         is_add = 0;
2001       else
2002         if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
2003         {
2004           is_add = 1;
2005           ip_addr_version (&ip) = AF_IP4;
2006         }
2007       else
2008         if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
2009         {
2010           is_add = 1;
2011           ip_addr_version (&ip) = AF_IP6;
2012         }
2013       else
2014         {
2015           errmsg ("parse error '%U'", format_unformat_error, input);
2016           return -99;
2017         }
2018     }
2019
2020   M (ONE_USE_PETR, mp);
2021
2022   mp->is_add = is_add;
2023   if (is_add)
2024     {
2025       mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
2026       if (mp->ip_address.af)
2027         clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
2028       else
2029         clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
2030     }
2031
2032   /* send */
2033   S (mp);
2034
2035   /* wait for reply */
2036   W (ret);
2037   return ret;
2038 }
2039
2040 #define api_lisp_use_petr api_one_use_petr
2041
2042 static int
2043 api_show_one_nsh_mapping (vat_main_t * vam)
2044 {
2045   vl_api_show_one_use_petr_t *mp;
2046   int ret;
2047
2048   if (!vam->json_output)
2049     {
2050       print (vam->ofp, "%=20s", "local ONE NSH mapping:");
2051     }
2052
2053   M (SHOW_ONE_NSH_MAPPING, mp);
2054   /* send it... */
2055   S (mp);
2056
2057   /* Wait for a reply... */
2058   W (ret);
2059   return ret;
2060 }
2061
2062 static int
2063 api_show_one_use_petr (vat_main_t * vam)
2064 {
2065   vl_api_show_one_use_petr_t *mp;
2066   int ret;
2067
2068   if (!vam->json_output)
2069     {
2070       print (vam->ofp, "%=20s", "Proxy-ETR status:");
2071     }
2072
2073   M (SHOW_ONE_USE_PETR, mp);
2074   /* send it... */
2075   S (mp);
2076
2077   /* Wait for a reply... */
2078   W (ret);
2079   return ret;
2080 }
2081
2082 #define api_show_lisp_use_petr api_show_one_use_petr
2083
2084 /**
2085  * Add/delete mapping between vni and vrf
2086  */
2087 static int
2088 api_one_eid_table_add_del_map (vat_main_t * vam)
2089 {
2090   unformat_input_t *input = vam->input;
2091   vl_api_one_eid_table_add_del_map_t *mp;
2092   u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
2093   u32 vni, vrf, bd_index;
2094   int ret;
2095
2096   /* Parse args required to build the message */
2097   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2098     {
2099       if (unformat (input, "del"))
2100         is_add = 0;
2101       else if (unformat (input, "vrf %d", &vrf))
2102         vrf_set = 1;
2103       else if (unformat (input, "bd_index %d", &bd_index))
2104         bd_index_set = 1;
2105       else if (unformat (input, "vni %d", &vni))
2106         vni_set = 1;
2107       else
2108         break;
2109     }
2110
2111   if (!vni_set || (!vrf_set && !bd_index_set))
2112     {
2113       errmsg ("missing arguments!");
2114       return -99;
2115     }
2116
2117   if (vrf_set && bd_index_set)
2118     {
2119       errmsg ("error: both vrf and bd entered!");
2120       return -99;
2121     }
2122
2123   M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
2124
2125   mp->is_add = is_add;
2126   mp->vni = htonl (vni);
2127   mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
2128   mp->is_l2 = bd_index_set;
2129
2130   /* send */
2131   S (mp);
2132
2133   /* wait for reply */
2134   W (ret);
2135   return ret;
2136 }
2137
2138 #define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
2139
2140 uword
2141 unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
2142 {
2143   u32 *action = va_arg (*args, u32 *);
2144   u8 *s = 0;
2145
2146   if (unformat (input, "%s", &s))
2147     {
2148       if (!strcmp ((char *) s, "no-action"))
2149         action[0] = 0;
2150       else if (!strcmp ((char *) s, "natively-forward"))
2151         action[0] = 1;
2152       else if (!strcmp ((char *) s, "send-map-request"))
2153         action[0] = 2;
2154       else if (!strcmp ((char *) s, "drop"))
2155         action[0] = 3;
2156       else
2157         {
2158           clib_warning ("invalid action: '%s'", s);
2159           action[0] = 3;
2160         }
2161     }
2162   else
2163     return 0;
2164
2165   vec_free (s);
2166   return 1;
2167 }
2168
2169 /**
2170  * Add/del remote mapping to/from ONE control plane
2171  *
2172  * @param vam vpp API test context
2173  * @return return code
2174  */
2175 static int
2176 api_one_add_del_remote_mapping (vat_main_t * vam)
2177 {
2178   unformat_input_t *input = vam->input;
2179   vl_api_one_add_del_remote_mapping_t *mp;
2180   u32 vni = 0;
2181   lisp_eid_vat_t _eid, *eid = &_eid;
2182   lisp_eid_vat_t _seid, *seid = &_seid;
2183   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
2184   u32 action = ~0, p, w, data_len;
2185   ip4_address_t rloc4;
2186   ip6_address_t rloc6;
2187   vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
2188   int ret;
2189
2190   clib_memset (&rloc, 0, sizeof (rloc));
2191
2192   /* Parse args required to build the message */
2193   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2194     {
2195       if (unformat (input, "del-all"))
2196         {
2197           del_all = 1;
2198         }
2199       else if (unformat (input, "del"))
2200         {
2201           is_add = 0;
2202         }
2203       else if (unformat (input, "add"))
2204         {
2205           is_add = 1;
2206         }
2207       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
2208         {
2209           eid_set = 1;
2210         }
2211       else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
2212         {
2213           seid_set = 1;
2214         }
2215       else if (unformat (input, "vni %d", &vni))
2216         {
2217           ;
2218         }
2219       else if (unformat (input, "p %d w %d", &p, &w))
2220         {
2221           if (!curr_rloc)
2222             {
2223               errmsg ("No RLOC configured for setting priority/weight!");
2224               return -99;
2225             }
2226           curr_rloc->priority = p;
2227           curr_rloc->weight = w;
2228         }
2229       else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
2230         {
2231           rloc.ip_address.af = 0;
2232           clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
2233           vec_add1 (rlocs, rloc);
2234           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2235         }
2236       else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
2237         {
2238           rloc.ip_address.af = 1;
2239           clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
2240           vec_add1 (rlocs, rloc);
2241           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2242         }
2243       else if (unformat (input, "action %U",
2244                          unformat_negative_mapping_action, &action))
2245         {
2246           ;
2247         }
2248       else
2249         {
2250           clib_warning ("parse error '%U'", format_unformat_error, input);
2251           return -99;
2252         }
2253     }
2254
2255   if (0 == eid_set)
2256     {
2257       errmsg ("missing params!");
2258       return -99;
2259     }
2260
2261   if (is_add && (~0 == action) && 0 == vec_len (rlocs))
2262     {
2263       errmsg ("no action set for negative map-reply!");
2264       return -99;
2265     }
2266
2267   data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
2268
2269   M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
2270   mp->is_add = is_add;
2271   mp->vni = htonl (vni);
2272   mp->action = (u8) action;
2273   mp->is_src_dst = seid_set;
2274   mp->del_all = del_all;
2275   lisp_eid_put_vat (&mp->deid, eid);
2276   lisp_eid_put_vat (&mp->seid, seid);
2277
2278   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
2279   clib_memcpy (mp->rlocs, rlocs, data_len);
2280   vec_free (rlocs);
2281
2282   /* send it... */
2283   S (mp);
2284
2285   /* Wait for a reply... */
2286   W (ret);
2287   return ret;
2288 }
2289
2290 #define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
2291
2292 /**
2293  * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
2294  * forwarding entries in data-plane accordingly.
2295  *
2296  * @param vam vpp API test context
2297  * @return return code
2298  */
2299 static int
2300 api_one_add_del_adjacency (vat_main_t * vam)
2301 {
2302   unformat_input_t *input = vam->input;
2303   vl_api_one_add_del_adjacency_t *mp;
2304   u32 vni = 0;
2305   u8 is_add = 1;
2306   int ret;
2307   lisp_eid_vat_t leid, reid;
2308
2309   leid.type = reid.type = (u8) ~ 0;
2310
2311   /* Parse args required to build the message */
2312   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2313     {
2314       if (unformat (input, "del"))
2315         {
2316           is_add = 0;
2317         }
2318       else if (unformat (input, "add"))
2319         {
2320           is_add = 1;
2321         }
2322       else if (unformat (input, "reid %U/%d", unformat_ip46_address,
2323                          &reid.addr.ip, &reid.len))
2324         {
2325           reid.type = 0;        /* ipv4 */
2326         }
2327       else if (unformat (input, "reid %U", unformat_ethernet_address,
2328                          &reid.addr.mac))
2329         {
2330           reid.type = 1;        /* mac */
2331         }
2332       else if (unformat (input, "leid %U/%d", unformat_ip46_address,
2333                          &leid.addr.ip, &leid.len))
2334         {
2335           leid.type = 0;        /* ipv4 */
2336         }
2337       else if (unformat (input, "leid %U", unformat_ethernet_address,
2338                          &leid.addr.mac))
2339         {
2340           leid.type = 1;        /* mac */
2341         }
2342       else if (unformat (input, "vni %d", &vni))
2343         {
2344           ;
2345         }
2346       else
2347         {
2348           errmsg ("parse error '%U'", format_unformat_error, input);
2349           return -99;
2350         }
2351     }
2352
2353   if ((u8) ~ 0 == reid.type)
2354     {
2355       errmsg ("missing params!");
2356       return -99;
2357     }
2358
2359   if (leid.type != reid.type)
2360     {
2361       errmsg ("remote and local EIDs are of different types!");
2362       return -99;
2363     }
2364
2365   M (ONE_ADD_DEL_ADJACENCY, mp);
2366   mp->is_add = is_add;
2367   mp->vni = htonl (vni);
2368   lisp_eid_put_vat (&mp->leid, &leid);
2369   lisp_eid_put_vat (&mp->reid, &reid);
2370
2371   /* send it... */
2372   S (mp);
2373
2374   /* Wait for a reply... */
2375   W (ret);
2376   return ret;
2377 }
2378
2379 #define api_lisp_add_del_adjacency api_one_add_del_adjacency
2380
2381
2382 static int
2383 api_one_map_register_fallback_threshold (vat_main_t * vam)
2384 {
2385   unformat_input_t *input = vam->input;
2386   vl_api_one_map_register_fallback_threshold_t *mp;
2387   u32 value = 0;
2388   u8 is_set = 0;
2389   int ret;
2390
2391   /* Parse args required to build the message */
2392   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2393     {
2394       if (unformat (input, "%u", &value))
2395         is_set = 1;
2396       else
2397         {
2398           clib_warning ("parse error '%U'", format_unformat_error, input);
2399           return -99;
2400         }
2401     }
2402
2403   if (!is_set)
2404     {
2405       errmsg ("fallback threshold value is missing!");
2406       return -99;
2407     }
2408
2409   M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2410   mp->value = clib_host_to_net_u32 (value);
2411
2412   /* send it... */
2413   S (mp);
2414
2415   /* Wait for a reply... */
2416   W (ret);
2417   return ret;
2418 }
2419
2420 static int
2421 api_show_one_map_register_fallback_threshold (vat_main_t * vam)
2422 {
2423   vl_api_show_one_map_register_fallback_threshold_t *mp;
2424   int ret;
2425
2426   M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2427
2428   /* send it... */
2429   S (mp);
2430
2431   /* Wait for a reply... */
2432   W (ret);
2433   return ret;
2434 }
2435
2436 uword
2437 unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
2438 {
2439   u32 *proto = va_arg (*args, u32 *);
2440
2441   if (unformat (input, "udp"))
2442     *proto = 1;
2443   else if (unformat (input, "api"))
2444     *proto = 2;
2445   else
2446     return 0;
2447
2448   return 1;
2449 }
2450
2451 static int
2452 api_one_set_transport_protocol (vat_main_t * vam)
2453 {
2454   unformat_input_t *input = vam->input;
2455   vl_api_one_set_transport_protocol_t *mp;
2456   u8 is_set = 0;
2457   u32 protocol = 0;
2458   int ret;
2459
2460   /* Parse args required to build the message */
2461   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2462     {
2463       if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
2464         is_set = 1;
2465       else
2466         {
2467           clib_warning ("parse error '%U'", format_unformat_error, input);
2468           return -99;
2469         }
2470     }
2471
2472   if (!is_set)
2473     {
2474       errmsg ("Transport protocol missing!");
2475       return -99;
2476     }
2477
2478   M (ONE_SET_TRANSPORT_PROTOCOL, mp);
2479   mp->protocol = (u8) protocol;
2480
2481   /* send it... */
2482   S (mp);
2483
2484   /* Wait for a reply... */
2485   W (ret);
2486   return ret;
2487 }
2488
2489 static int
2490 api_one_get_transport_protocol (vat_main_t * vam)
2491 {
2492   vl_api_one_get_transport_protocol_t *mp;
2493   int ret;
2494
2495   M (ONE_GET_TRANSPORT_PROTOCOL, mp);
2496
2497   /* send it... */
2498   S (mp);
2499
2500   /* Wait for a reply... */
2501   W (ret);
2502   return ret;
2503 }
2504
2505 static int
2506 api_one_map_register_set_ttl (vat_main_t * vam)
2507 {
2508   unformat_input_t *input = vam->input;
2509   vl_api_one_map_register_set_ttl_t *mp;
2510   u32 ttl = 0;
2511   u8 is_set = 0;
2512   int ret;
2513
2514   /* Parse args required to build the message */
2515   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2516     {
2517       if (unformat (input, "%u", &ttl))
2518         is_set = 1;
2519       else
2520         {
2521           clib_warning ("parse error '%U'", format_unformat_error, input);
2522           return -99;
2523         }
2524     }
2525
2526   if (!is_set)
2527     {
2528       errmsg ("TTL value missing!");
2529       return -99;
2530     }
2531
2532   M (ONE_MAP_REGISTER_SET_TTL, mp);
2533   mp->ttl = clib_host_to_net_u32 (ttl);
2534
2535   /* send it... */
2536   S (mp);
2537
2538   /* Wait for a reply... */
2539   W (ret);
2540   return ret;
2541 }
2542
2543 static int
2544 api_show_one_map_register_ttl (vat_main_t * vam)
2545 {
2546   vl_api_show_one_map_register_ttl_t *mp;
2547   int ret;
2548
2549   M (SHOW_ONE_MAP_REGISTER_TTL, mp);
2550
2551   /* send it... */
2552   S (mp);
2553
2554   /* Wait for a reply... */
2555   W (ret);
2556   return ret;
2557 }
2558
2559 /**
2560  * Add/del map request itr rlocs from ONE control plane and updates
2561  *
2562  * @param vam vpp API test context
2563  * @return return code
2564  */
2565 static int
2566 api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
2567 {
2568   unformat_input_t *input = vam->input;
2569   vl_api_one_add_del_map_request_itr_rlocs_t *mp;
2570   u8 *locator_set_name = 0;
2571   u8 locator_set_name_set = 0;
2572   u8 is_add = 1;
2573   int ret;
2574
2575   /* Parse args required to build the message */
2576   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2577     {
2578       if (unformat (input, "del"))
2579         {
2580           is_add = 0;
2581         }
2582       else if (unformat (input, "%_%v%_", &locator_set_name))
2583         {
2584           locator_set_name_set = 1;
2585         }
2586       else
2587         {
2588           clib_warning ("parse error '%U'", format_unformat_error, input);
2589           return -99;
2590         }
2591     }
2592
2593   if (is_add && !locator_set_name_set)
2594     {
2595       errmsg ("itr-rloc is not set!");
2596       return -99;
2597     }
2598
2599   if (is_add && vec_len (locator_set_name) > 64)
2600     {
2601       errmsg ("itr-rloc locator-set name too long");
2602       vec_free (locator_set_name);
2603       return -99;
2604     }
2605
2606   M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
2607   mp->is_add = is_add;
2608   if (is_add)
2609     {
2610       clib_memcpy (mp->locator_set_name, locator_set_name,
2611                    vec_len (locator_set_name));
2612     }
2613   else
2614     {
2615       clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
2616     }
2617   vec_free (locator_set_name);
2618
2619   /* send it... */
2620   S (mp);
2621
2622   /* Wait for a reply... */
2623   W (ret);
2624   return ret;
2625 }
2626
2627 #define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
2628
2629 static int
2630 api_one_locator_dump (vat_main_t * vam)
2631 {
2632   unformat_input_t *input = vam->input;
2633   vl_api_one_locator_dump_t *mp;
2634   vl_api_control_ping_t *mp_ping;
2635   u8 is_index_set = 0, is_name_set = 0;
2636   u8 *ls_name = 0;
2637   u32 ls_index = ~0;
2638   int ret;
2639
2640   /* Parse args required to build the message */
2641   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2642     {
2643       if (unformat (input, "ls_name %_%v%_", &ls_name))
2644         {
2645           is_name_set = 1;
2646         }
2647       else if (unformat (input, "ls_index %d", &ls_index))
2648         {
2649           is_index_set = 1;
2650         }
2651       else
2652         {
2653           errmsg ("parse error '%U'", format_unformat_error, input);
2654           return -99;
2655         }
2656     }
2657
2658   if (!is_index_set && !is_name_set)
2659     {
2660       errmsg ("error: expected one of index or name!");
2661       return -99;
2662     }
2663
2664   if (is_index_set && is_name_set)
2665     {
2666       errmsg ("error: only one param expected!");
2667       return -99;
2668     }
2669
2670   if (vec_len (ls_name) > 62)
2671     {
2672       errmsg ("error: locator set name too long!");
2673       return -99;
2674     }
2675
2676   if (!vam->json_output)
2677     {
2678       print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
2679     }
2680
2681   M (ONE_LOCATOR_DUMP, mp);
2682   mp->is_index_set = is_index_set;
2683
2684   if (is_index_set)
2685     mp->ls_index = clib_host_to_net_u32 (ls_index);
2686   else
2687     {
2688       vec_add1 (ls_name, 0);
2689       strncpy ((char *) mp->ls_name, (char *) ls_name,
2690                sizeof (mp->ls_name) - 1);
2691     }
2692
2693   /* send it... */
2694   S (mp);
2695
2696   /* Use a control ping for synchronization */
2697   LISP_PING (&one_test_main, mp_ping);
2698   S (mp_ping);
2699
2700   /* Wait for a reply... */
2701   W (ret);
2702   return ret;
2703 }
2704
2705 #define api_lisp_locator_dump api_one_locator_dump
2706
2707 static int
2708 api_one_locator_set_dump (vat_main_t * vam)
2709 {
2710   vl_api_one_locator_set_dump_t *mp;
2711   vl_api_control_ping_t *mp_ping;
2712   unformat_input_t *input = vam->input;
2713   u8 filter = 0;
2714   int ret;
2715
2716   /* Parse args required to build the message */
2717   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2718     {
2719       if (unformat (input, "local"))
2720         {
2721           filter = 1;
2722         }
2723       else if (unformat (input, "remote"))
2724         {
2725           filter = 2;
2726         }
2727       else
2728         {
2729           errmsg ("parse error '%U'", format_unformat_error, input);
2730           return -99;
2731         }
2732     }
2733
2734   if (!vam->json_output)
2735     {
2736       print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
2737     }
2738
2739   M (ONE_LOCATOR_SET_DUMP, mp);
2740
2741   mp->filter = filter;
2742
2743   /* send it... */
2744   S (mp);
2745
2746   /* Use a control ping for synchronization */
2747   LISP_PING (&one_test_main, mp_ping);
2748   S (mp_ping);
2749
2750   /* Wait for a reply... */
2751   W (ret);
2752   return ret;
2753 }
2754
2755 #define api_lisp_locator_set_dump api_one_locator_set_dump
2756
2757 static int
2758 api_one_eid_table_map_dump (vat_main_t * vam)
2759 {
2760   u8 is_l2 = 0;
2761   u8 mode_set = 0;
2762   unformat_input_t *input = vam->input;
2763   vl_api_one_eid_table_map_dump_t *mp;
2764   vl_api_control_ping_t *mp_ping;
2765   int ret;
2766
2767   /* Parse args required to build the message */
2768   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2769     {
2770       if (unformat (input, "l2"))
2771         {
2772           is_l2 = 1;
2773           mode_set = 1;
2774         }
2775       else if (unformat (input, "l3"))
2776         {
2777           is_l2 = 0;
2778           mode_set = 1;
2779         }
2780       else
2781         {
2782           errmsg ("parse error '%U'", format_unformat_error, input);
2783           return -99;
2784         }
2785     }
2786
2787   if (!mode_set)
2788     {
2789       errmsg ("expected one of 'l2' or 'l3' parameter!");
2790       return -99;
2791     }
2792
2793   if (!vam->json_output)
2794     {
2795       print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
2796     }
2797
2798   M (ONE_EID_TABLE_MAP_DUMP, mp);
2799   mp->is_l2 = is_l2;
2800
2801   /* send it... */
2802   S (mp);
2803
2804   /* Use a control ping for synchronization */
2805   LISP_PING (&one_test_main, mp_ping);
2806   S (mp_ping);
2807
2808   /* Wait for a reply... */
2809   W (ret);
2810   return ret;
2811 }
2812
2813 #define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
2814
2815 static int
2816 api_one_eid_table_vni_dump (vat_main_t * vam)
2817 {
2818   vl_api_one_eid_table_vni_dump_t *mp;
2819   vl_api_control_ping_t *mp_ping;
2820   int ret;
2821
2822   if (!vam->json_output)
2823     {
2824       print (vam->ofp, "VNI");
2825     }
2826
2827   M (ONE_EID_TABLE_VNI_DUMP, mp);
2828
2829   /* send it... */
2830   S (mp);
2831
2832   /* Use a control ping for synchronization */
2833   LISP_PING (&one_test_main, mp_ping);
2834   S (mp_ping);
2835
2836   /* Wait for a reply... */
2837   W (ret);
2838   return ret;
2839 }
2840
2841 #define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
2842
2843 static int
2844 api_one_eid_table_dump (vat_main_t * vam)
2845 {
2846   unformat_input_t *i = vam->input;
2847   vl_api_one_eid_table_dump_t *mp;
2848   vl_api_control_ping_t *mp_ping;
2849   u8 filter = 0;
2850   int ret;
2851   u32 vni, t = 0;
2852   lisp_eid_vat_t eid;
2853   u8 eid_set = 0;
2854
2855   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2856     {
2857       if (unformat
2858           (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
2859         {
2860           eid_set = 1;
2861           eid.type = 0;
2862         }
2863       else
2864         if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
2865         {
2866           eid_set = 1;
2867           eid.type = 1;
2868         }
2869       else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
2870         {
2871           eid_set = 1;
2872           eid.type = 2;
2873         }
2874       else if (unformat (i, "vni %d", &t))
2875         {
2876           vni = t;
2877         }
2878       else if (unformat (i, "local"))
2879         {
2880           filter = 1;
2881         }
2882       else if (unformat (i, "remote"))
2883         {
2884           filter = 2;
2885         }
2886       else
2887         {
2888           errmsg ("parse error '%U'", format_unformat_error, i);
2889           return -99;
2890         }
2891     }
2892
2893   if (!vam->json_output)
2894     {
2895       print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
2896              "type", "ls_index", "ttl", "authoritative", "key_id", "key");
2897     }
2898
2899   M (ONE_EID_TABLE_DUMP, mp);
2900
2901   mp->filter = filter;
2902   if (eid_set)
2903     {
2904       mp->eid_set = 1;
2905       mp->vni = htonl (vni);
2906       lisp_eid_put_vat (&mp->eid, &eid);
2907     }
2908
2909   /* send it... */
2910   S (mp);
2911
2912   /* Use a control ping for synchronization */
2913   LISP_PING (&one_test_main, mp_ping);
2914   S (mp_ping);
2915
2916   /* Wait for a reply... */
2917   W (ret);
2918   return ret;
2919 }
2920
2921 static int
2922 api_one_adjacencies_get (vat_main_t * vam)
2923 {
2924   unformat_input_t *i = vam->input;
2925   vl_api_one_adjacencies_get_t *mp;
2926   u8 vni_set = 0;
2927   u32 vni = ~0;
2928   int ret;
2929
2930   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2931     {
2932       if (unformat (i, "vni %d", &vni))
2933         {
2934           vni_set = 1;
2935         }
2936       else
2937         {
2938           errmsg ("parse error '%U'", format_unformat_error, i);
2939           return -99;
2940         }
2941     }
2942
2943   if (!vni_set)
2944     {
2945       errmsg ("vni not set!");
2946       return -99;
2947     }
2948
2949   if (!vam->json_output)
2950     {
2951       print (vam->ofp, "%s %40s", "leid", "reid");
2952     }
2953
2954   M (ONE_ADJACENCIES_GET, mp);
2955   mp->vni = clib_host_to_net_u32 (vni);
2956
2957   /* send it... */
2958   S (mp);
2959
2960   /* Wait for a reply... */
2961   W (ret);
2962   return ret;
2963 }
2964
2965 static int
2966 api_one_map_server_dump (vat_main_t * vam)
2967 {
2968   vl_api_one_map_server_dump_t *mp;
2969   vl_api_control_ping_t *mp_ping;
2970   int ret;
2971
2972   if (!vam->json_output)
2973     {
2974       print (vam->ofp, "%=20s", "Map server");
2975     }
2976
2977   M (ONE_MAP_SERVER_DUMP, mp);
2978   /* send it... */
2979   S (mp);
2980
2981   /* Use a control ping for synchronization */
2982   LISP_PING (&one_test_main, mp_ping);
2983   S (mp_ping);
2984
2985   /* Wait for a reply... */
2986   W (ret);
2987   return ret;
2988 }
2989
2990 #define api_lisp_map_server_dump api_one_map_server_dump
2991
2992 static int
2993 api_one_map_resolver_dump (vat_main_t * vam)
2994 {
2995   vl_api_one_map_resolver_dump_t *mp;
2996   vl_api_control_ping_t *mp_ping;
2997   int ret;
2998
2999   if (!vam->json_output)
3000     {
3001       print (vam->ofp, "%=20s", "Map resolver");
3002     }
3003
3004   M (ONE_MAP_RESOLVER_DUMP, mp);
3005   /* send it... */
3006   S (mp);
3007
3008   /* Use a control ping for synchronization */
3009   LISP_PING (&one_test_main, mp_ping);
3010   S (mp_ping);
3011
3012   /* Wait for a reply... */
3013   W (ret);
3014   return ret;
3015 }
3016
3017 #define api_lisp_map_resolver_dump api_one_map_resolver_dump
3018
3019 static int
3020 api_one_stats_flush (vat_main_t * vam)
3021 {
3022   vl_api_one_stats_flush_t *mp;
3023   int ret = 0;
3024
3025   M (ONE_STATS_FLUSH, mp);
3026   S (mp);
3027   W (ret);
3028   return ret;
3029 }
3030
3031 static int
3032 api_one_stats_dump (vat_main_t * vam)
3033 {
3034   vl_api_one_stats_dump_t *mp;
3035   vl_api_control_ping_t *mp_ping;
3036   int ret;
3037
3038   M (ONE_STATS_DUMP, mp);
3039   /* send it... */
3040   S (mp);
3041
3042   /* Use a control ping for synchronization */
3043   LISP_PING (&one_test_main, mp_ping);
3044   S (mp_ping);
3045
3046   /* Wait for a reply... */
3047   W (ret);
3048   return ret;
3049 }
3050
3051 static int
3052 api_show_one_status (vat_main_t * vam)
3053 {
3054   vl_api_show_one_status_t *mp;
3055   int ret;
3056
3057   if (!vam->json_output)
3058     {
3059       print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
3060     }
3061
3062   M (SHOW_ONE_STATUS, mp);
3063   /* send it... */
3064   S (mp);
3065   /* Wait for a reply... */
3066   W (ret);
3067   return ret;
3068 }
3069
3070 static int
3071 api_one_get_map_request_itr_rlocs (vat_main_t * vam)
3072 {
3073   vl_api_one_get_map_request_itr_rlocs_t *mp;
3074   int ret;
3075
3076   if (!vam->json_output)
3077     {
3078       print (vam->ofp, "%=20s", "itr-rlocs:");
3079     }
3080
3081   M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
3082   /* send it... */
3083   S (mp);
3084   /* Wait for a reply... */
3085   W (ret);
3086   return ret;
3087 }
3088
3089 #define vat_plugin_register vat_plugin_register_one
3090 #include <lisp/lisp-cp/one.api_test.c>
3091
3092 /*
3093  * fd.io coding-style-patch-verification: ON
3094  *
3095  * Local Variables:
3096  * eval: (c-set-style "gnu")
3097  * End:
3098  */